Loading Spirv shaders

27 views
Skip to first unread message

Matt Weichselbaum

unread,
Jul 11, 2024, 12:14:33 PMJul 11
to Dawn Graphics
Hello, I'm following https://eliemichel.github.io/LearnWebGPU/ and now going back to convert shaders to hlsl instead of wgsl. I'm using dxc to compile the shaders to spir-v and when using the wgpu backend this works just fine to load the shaders: 

std::vector<uint32_t> vertex = ReadSPIRV("../vert.spv");
std::vector<uint32_t> fragment = ReadSPIRV("../frag.spv");

WGPUShaderModuleSPIRVDescriptor vsDesc = {};
WGPUShaderModuleSPIRVDescriptor fsDesc = {};
vsDesc.code = vertex.data();
vsDesc.codeSize = vertex.size();
vsDesc.chain.sType = WGPUSType_ShaderModuleSPIRVDescriptor;

fsDesc.code = fragment.data();
fsDesc.codeSize = fragment.size();
fsDesc.chain.sType = WGPUSType_ShaderModuleSPIRVDescriptor;

vsModuleDesc.nextInChain = (WGPUChainedStruct*)&vsDesc;
fsModuleDesc.nextInChain = (WGPUChainedStruct*)&fsDesc;

ShaderModule vsModule = device.createShaderModule(vsModuleDesc);
ShaderModule fsModule = device.createShaderModule(fsModuleDesc);

but when the backend is Dawn, I'm getting the following error:

Uncaptured device error: type 2 (Expected chain root to match one of the following branch types with optional extensions:
  - [ SType::ShaderModuleWGSLDescriptor -> (SType::ShaderModuleCompilationOptions) ]
Instead found: ( SType::ShaderModuleSPIRVDescriptor,  )
 - While validating [ShaderModuleDescriptor]
 - While calling [Device "My Device"].CreateShaderModule([ShaderModuleDescriptor]).
)

I suspect there is flag I'm not setting since I've seen other repos where basically identical code has worked. Can someone please provide me with some guidance on how to load spir-v with Dawn?

Thanks,
Matt

Austin Eng

unread,
Jul 11, 2024, 2:28:00 PMJul 11
to Matt Weichselbaum, Dawn Graphics
Hi Matt, taking a look at the code, I think it's because you probably built Dawn without the TINT_BUILD_SPV_READER #define.
If you define that, then I believe it should work.

Cheers,
Austin

--
You received this message because you are subscribed to the Google Groups "Dawn Graphics" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dawn-graphic...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dawn-graphics/502d577a-e68c-4571-8bff-01f16f0720c2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages