Open jzm-intel opened 2 years ago
So how would you express packoffset at 2 bytes? If that is not possible, I don't see what I can do.
Thanks for your kindly reply.
I am not sure, but this case only occurs in SM6.2 which required dxc, and it provides a Vulkan-specific attribute, [[vk:offset()]]
(Please see [1](https://github.com/Microsoft/DirectXShaderCompiler/blob/master/docs/SPIR-V.rst#memory-layout-rules:~:text=The%20Vulkan-specific%20%5B%5Bvk%3A%3Aoffset()%5D%5D%20attribute%3A%20applies%20to%20all%20resources.), 2), although I think it only effect the SPIRV codegen in dxc. On the other hand, is it possible that some layout attributes can be omitted if identical to default layouts? In this way some cases that doesn't fit in packoffset
may just work with default layout.
Thanks and sorry for troubling you.
When using
half
in constant buffer in HLSL, SPIRV-Cross may failed to translate the spirv generated by dxc back to HLSL, but throwing an exception readCannot pack on tighter bounds than 4 bytes in HLSL
.For example, I use the simple HLSL shader:
under SM 6.2 with native fp16 enabled. I use dxc to generate the SPIRV code like
dxc -T ps_6_2 -E PSMain -enable-16bit-types -spirv -fspv-target-env="vulkan1.2" .\test0.hlsl -Fo test0.spv
. The generated SPIRV (assembly) is something likeThen I use SPIRV-Cross to translate the generated SIPRV back to HLSL using
.\spirv-cross.exe PATH\TO\test0.spv --hlsl --shader-model 62 --hlsl-enable-16bit-types
, and I get the exceptionOn the other hand, when I comment out the
Scalar0
in HLSL source, SPIRV-Cross works well, resulting in the following HLSLIt seems that SPIRV-Cross will use
packoffset
in the generated HLSL to describe to constant buffer layout, but it can only describe an offset aligned to 4 bytes (like c1.y referred to offset 16+4=20 bytes), while in HLSL SM 6.2 with native 16 bits type such 16 bits data can be packed into a single 16 bytes row in constant buffer, and multiple half (or vector of half) in such a row can align to 2 bytes rather than 4 bytes, which makepackoffset
invalid, and result in the exception.