Skip to content

Commit

Permalink
wgpu: Add the use_dxc toggle in order to make ShaderF16 available (#115)
Browse files Browse the repository at this point in the history
This enables the tests in shader-slang/slang#5605 to run, where
supported.
  • Loading branch information
aleino-nv authored Nov 28, 2024
1 parent c3f1da8 commit 539322d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/wgpu/wgpu-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ Result DeviceImpl::initialize(const DeviceDesc& desc)
std::array{slang::PreprocessorMacroDesc{"__WGPU__", "1"}}
));

std::vector<char const*> 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 =
Expand All @@ -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)
{
Expand All @@ -122,9 +130,6 @@ Result DeviceImpl::initialize(const DeviceDesc& desc)
std::vector<WGPUFeatureName> 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)
{
Expand All @@ -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)
{
Expand All @@ -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);

Expand Down

0 comments on commit 539322d

Please sign in to comment.