google / shaderc

A collection of tools, libraries, and tests for Vulkan shader compilation.
Other
1.85k stars 362 forks source link

HLSL descriptor mapping doc ? #280

Open vlj opened 7 years ago

vlj commented 7 years ago

glslc is able to build hlsl shader but it's not obvious how to describe descriptor layout. I'm not sure if it's possible to embed a root signature and how it maps to vulkan layouts.

dneto0 commented 7 years ago

glslc's HLSL support is not yet complete.

glslc inherits the behaviours of Glslang. Glslang's dialect of HLSL allows layout(set= , binding=) and layout(push_constant), similar to how Vulkan bindings are supported for GLSL. For the Vulkan GLSL rules see https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt

For Glslang's test case see https://github.com/KhronosGroup/glslang/blob/master/Test/hlsl.layout.frag and corresponding AST intermediate and SPIR-V assembly: https://github.com/KhronosGroup/glslang/blob/master/Test/baseResults/hlsl.layout.frag.out

Note that glslangValidator supports several options to automatically map bindings, and to "shift" binding numbers for UBOs, images, textures, and samplers. I plan to add those options to glslc as well.

ajaybedi commented 7 years ago

@dneto0 Are there any plans to add support of RootSignature in GLSLC for converting bindings. In HLSL bindings are taken from the RootSignature. Can we add this option in GLSLC to support it.

dneto0 commented 7 years ago

We rely on Glslang for HLSL compilation. So if Glslang exposes RootSignature support then Shaderc would get it. However, I don't think anybody else has asked for that.

ajaybedi commented 7 years ago

@dneto0 Ok .thanks for the info. For now, I have added my own preprocessing step, where I read the rootSignature myself and parse the bindings and then change the register numbers before getting it converted to SPIRV through GLSLC.

I am seeing another issue though if you can comment on that: I had a simple HLSL shader having separate texture2d and sampler ... I converter this to SPIRV through glslc. It works fine on Windows but Android fails to createpipeline for this... (strange that its same code on windows)... Can this be due to driver issue ? Any clues ?

dneto0 commented 7 years ago

I'm no expert in the API. Could it just be driver differences? For example, make sure that the selected image format is supported on both.