简体   繁体   中英

GLSL produced by SPIRV-cross from SPIR-V breaks std140 rules?

I've put my snippet HLSL code here: https://shader-playground.timjones.io/d9011ef7826a68ed93394792c2edb732

I compile HLSL with DXC to SPIR-V and then use SPIRV-Cross to get the GLSL code. The GLSL constant buffer is tagged with std140 and it contains vec3 and float. This according to my knowledge will not work. Shouldn't the GL_EXT_scalar_block_layout be used here? The constant block should be tagged with scalar instead of std140. Am I missing something obvious here? Thanks.

For an arbitrary input buffer, there isn't a generic OpenGL memory layout that is exactly equivalent to the DX constant buffer layout.

DX constant buffers will add padding needed to stop single variables spanning 16 byte boundaries.

GL std140 uniform buffers will always pad vec3 to vec4 in terms of storage. This has no equivalent in DX.

GL std430 uniform buffers (if supported via this extension) will always pad vec3 to vec4 in terms of storage. This has no equivalent in DX.

GL scalar uniform buffers (if supported via this extension) will only pad to component element size, and don't care about 16 byte boundaries. This has no equivalent in DX.

Things get even more fun if you start throwing around struct and array types...

TLDR, if you want a fixed binary memory layout that is portable between DX and GL/GLES and Vulkan you take some responsibility for designing a portable memory layout for your constant buffers. You can't throw arbitrary layouts around and expect it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM