Skip to content

Commit

Permalink
Propagate wsgl compilation errors
Browse files Browse the repository at this point in the history
wgpuDeviceCreateShaderModule reports
errors via a callback. Previously, the callback
only printed the error, but now, the error
can be read back and used to report SLANG_FAIL from createShaderModule.

Work on Issue 5291
  • Loading branch information
cheneym2 committed Nov 4, 2024
1 parent eaed14f commit 315fcdf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/wgpu/wgpu-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ Result DeviceImpl::getNativeDeviceHandles(DeviceNativeHandles* outHandles)
void DeviceImpl::handleError(WGPUErrorType type, char const* message)
{
fprintf(stderr, "WGPU error: %s\n", message);
this->m_lastError = type;
}

WGPUErrorType DeviceImpl::getAndClearLastError()
{
WGPUErrorType lastError = this->m_lastError;
this->m_lastError = WGPUErrorType_NoError;
return lastError;
}

Result DeviceImpl::initialize(const DeviceDesc& desc)
Expand Down
4 changes: 4 additions & 0 deletions src/wgpu/wgpu-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class DeviceImpl : public Device
virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const DeviceDesc& desc) override;

void handleError(WGPUErrorType type, char const* message);
WGPUErrorType getAndClearLastError();

// IDevice implementation
virtual SLANG_NO_THROW Result SLANG_MCALL getFormatSupport(Format format, FormatSupport* outFormatSupport) override;
Expand Down Expand Up @@ -99,6 +100,9 @@ class DeviceImpl : public Device
// void waitForGpu();
virtual SLANG_NO_THROW const DeviceInfo& SLANG_MCALL getDeviceInfo() const override;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeDeviceHandles(DeviceNativeHandles* outHandles) override;

private:
WGPUErrorType m_lastError = WGPUErrorType_NoError;
};

} // namespace rhi::wgpu
5 changes: 5 additions & 0 deletions src/wgpu/wgpu-shader-program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Result ShaderProgramImpl::createShaderModule(slang::EntryPointReflection* entryP
return SLANG_FAIL;
}

if (m_device->getAndClearLastError() != WGPUErrorType_NoError)
{
return SLANG_FAIL;
}

m_modules.push_back(module);
return SLANG_OK;
}
Expand Down

0 comments on commit 315fcdf

Please sign in to comment.