diff --git a/src/wgpu/wgpu-device.cpp b/src/wgpu/wgpu-device.cpp index 2fc6c51..cc03c87 100644 --- a/src/wgpu/wgpu-device.cpp +++ b/src/wgpu/wgpu-device.cpp @@ -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) diff --git a/src/wgpu/wgpu-device.h b/src/wgpu/wgpu-device.h index d52c821..731dea3 100644 --- a/src/wgpu/wgpu-device.h +++ b/src/wgpu/wgpu-device.h @@ -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; @@ -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 diff --git a/src/wgpu/wgpu-shader-program.cpp b/src/wgpu/wgpu-shader-program.cpp index abc8e08..57b65d9 100644 --- a/src/wgpu/wgpu-shader-program.cpp +++ b/src/wgpu/wgpu-shader-program.cpp @@ -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; }