From 21db0165178eb0c8a2f90a715b87ba646cf071dd Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Thu, 28 Nov 2024 11:13:41 +0200 Subject: [PATCH] wgpu: Add the use_dxc toggle in order to make ShaderF16 available This enables the tests in https://github.com/shader-slang/slang/issues/5605 to run, where supported. --- src/wgpu/wgpu-device.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wgpu/wgpu-device.cpp b/src/wgpu/wgpu-device.cpp index 3f56e7b..c97809e 100644 --- a/src/wgpu/wgpu-device.cpp +++ b/src/wgpu/wgpu-device.cpp @@ -86,8 +86,15 @@ Result DeviceImpl::initialize(const DeviceDesc& desc) std::array{slang::PreprocessorMacroDesc{"__WGPU__", "1"}} )); + std::vector const enabledToggles = {"use_dxc"}; + WGPUDawnTogglesDescriptor togglesDesc = {}; + togglesDesc.chain.sType = WGPUSType_DawnTogglesDescriptor; + togglesDesc.enabledToggleCount = enabledToggles.size(); + togglesDesc.enabledToggles = enabledToggles.data(); + WGPUInstanceDescriptor instanceDesc = {}; instanceDesc.features.timedWaitAnyEnable = WGPUBool(true); + instanceDesc.nextInChain = &togglesDesc.chain; m_ctx.instance = api.wgpuCreateInstance(&instanceDesc); auto requestAdapterCallback = @@ -107,6 +114,7 @@ Result DeviceImpl::initialize(const DeviceDesc& desc) #elif SLANG_LINUX_FAMILY options.backendType = WGPUBackendType_Vulkan; #endif + options.nextInChain = &togglesDesc.chain; api.wgpuInstanceRequestAdapter(m_ctx.instance, &options, requestAdapterCallback, &m_ctx); if (!m_ctx.adapter) { @@ -122,9 +130,6 @@ Result DeviceImpl::initialize(const DeviceDesc& desc) std::vector adapterFeatures(adapterFeatureCount); api.wgpuAdapterEnumerateFeatures(m_ctx.adapter, adapterFeatures.data()); - if (api.wgpuAdapterHasFeature(m_ctx.adapter, WGPUFeatureName_ShaderF16)) - m_features.push_back("half"); - auto requestDeviceCallback = [](WGPURequestDeviceStatus status, WGPUDevice device, char const* message, void* userdata) { @@ -144,6 +149,7 @@ Result DeviceImpl::initialize(const DeviceDesc& desc) deviceDesc.requiredLimits = &requiredLimits; deviceDesc.uncapturedErrorCallbackInfo.callback = errorCallback; deviceDesc.uncapturedErrorCallbackInfo.userdata = this; + deviceDesc.nextInChain = &togglesDesc.chain; api.wgpuAdapterRequestDevice(m_ctx.adapter, &deviceDesc, requestDeviceCallback, &m_ctx); if (!m_ctx.device) { @@ -163,6 +169,9 @@ Result DeviceImpl::initialize(const DeviceDesc& desc) api.wgpuDeviceEnumerateFeatures(m_ctx.device, deviceFeatures.data()); m_ctx.features.insert(deviceFeatures.begin(), deviceFeatures.end()); + if (api.wgpuDeviceHasFeature(m_ctx.device, WGPUFeatureName_ShaderF16)) + m_features.push_back("half"); + // Create queue. m_queue = new CommandQueueImpl(this, QueueType::Graphics);