Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 10, 2025

The layout(std430) cbuffer syntax was not working correctly in .slang files, causing incorrect ArrayStride values in generated SPIR-V. Arrays of int2 were getting ArrayStride 16 (std140 layout) instead of ArrayStride 8 (std430 layout).

The issue occurred because the parseHLSLCBufferDecl function only processed GLSL layout qualifiers when allowGLSLInput was enabled, but layout parsing itself is always available. This meant that while layout(std430) was parsed and attached as a modifier, it was ignored during cbuffer processing in .slang files.

Before:

OpDecorate %_arr_v2int_int_2 ArrayStride 16  // Wrong - using std140
OpName %SLANG_ParameterGroup_CBlock_std140 "SLANG_ParameterGroup_CBlock_std140"

After:

OpDecorate %_arr_v2int_int_2 ArrayStride 8   // Correct - using std430
OpName %SLANG_ParameterGroup_CBlock_std430 "SLANG_ParameterGroup_CBlock_std430"

This fix ensures that layout(std430) cbuffer declarations work consistently whether using .slang or .glsl files, and that the generated SPIR-V uses the correct layout rules for buffer members.

Fixes #8373.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] [SPIRV] wrong ArrayStride inside layout(std430) cbuffer Fix std430 layout support for cbuffers in .slang files Sep 11, 2025
@Copilot Copilot AI requested a review from bmillsNV September 11, 2025 00:06
Copilot finished work on behalf of bmillsNV September 11, 2025 00:06
@davli-nv
Copy link
Contributor

Copilot, I think it needs to warn when layout (std430) etc are used when compiling for other targets (warn instead of error to make it a non-breaking PR), and accept these layout modifiers when compiling for GLSL/SPIRV without requiring -allow-glsl

// Check for GLSL layout qualifiers when GLSL input is allowed
if (parser->options.allowGLSLInput && parser->pendingModifiers)
// Check for GLSL layout qualifiers (layout modifiers can be used even without allowGLSLInput)
if (parser->pendingModifiers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot, I think it needs to warn when layout (std430) etc are used when compiling for other targets (warn instead of error to make it a non-breaking PR), and accept these layout modifiers when compiling for GLSL/SPIRV without requiring -allow-glsl

int2 a[2];
};

ConstantBuffer<B, Std430DataLayout> c;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot, for simplicity this ConstantBuffer can be dropped

@davli-nv davli-nv self-assigned this Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SPIRV] wrong ArrayStride inside layout(std430) cbuffer
3 participants