Skip to content

Add groundwork for GLSL_EXT_structured_descriptor_heap in glslang#4272

Open
Guang-035 wants to merge 10 commits into
KhronosGroup:mainfrom
Guang-035:structured_descriptor_heap
Open

Add groundwork for GLSL_EXT_structured_descriptor_heap in glslang#4272
Guang-035 wants to merge 10 commits into
KhronosGroup:mainfrom
Guang-035:structured_descriptor_heap

Conversation

@Guang-035

@Guang-035 Guang-035 commented May 13, 2026

Copy link
Copy Markdown
Contributor

This PR implements GLSL_EXT_structured_descriptor_heap support in glslang.

It builds on the existing GL_EXT_descriptor_heap lowering and extends the frontend/backend metadata model so structured heap layout can distinguish ordinary POD members from real descriptor payloads.

Spec reference: https://github.com/KhronosGroup/GLSL/pull/299/changes

Task Breakdown

  • Refine existing descriptor heap lowering
  • Implement structured descriptor heap support
    • Support buffer_type layout qualifier on uniform / buffer blocks
    • Support descriptor_size = on resourceheap / samplerheap block members
    • Support heap_offset = on resourceheap / samplerheap blocks
    • Support buffer_reference and buffer_reference = on buffer block members used by resourceheap / samplerheap
    • Support row_major / column_major on matrix block members in resourceheap / samplerheap
    • Support offset = on resourceheap / samplerheap block members
    • Support std140, std430, and scalar on buffer/uniform blocks used by resourceheap / samplerheap
    • Add structured descriptor heap success/error tests and baseResults

@Guang-035 Guang-035 changed the title Refine descriptor heap type metadata and SPIR-V layout generation Add groundwork for GLSL_EXT_structured_descriptor_heap in glslang May 13, 2026
@Guang-035 Guang-035 force-pushed the structured_descriptor_heap branch 3 times, most recently from 64b6b98 to 284dd8c Compare May 15, 2026 07:55
Comment thread Test/spv.structuredDescriptorHeap.Buffer.comp
@Guang-035 Guang-035 force-pushed the structured_descriptor_heap branch 4 times, most recently from ad639fd to 5262583 Compare May 19, 2026 08:58
@Guang-035

Guang-035 commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

NOTE: These validation failures are expected for now and should be fixed in SPIRV-Tools validation.

  • spv.structuredDescriptorHeap.Buffer.comp.out:
    The shader has a struct member containing a buffer descriptor:
    struct Material {
    vec4 data0;
    DataBuffer dataBuffer;
    };
    Current validation incorrectly treats Material as a non-descriptor resource and rejects the structured descriptor heap decorations. This should be accepted for structs that contain descriptor members.

Fix is available here [Merged].

@Guang-035 Guang-035 force-pushed the structured_descriptor_heap branch from 5262583 to 658e0cf Compare May 19, 2026 09:51
@Guang-035

Copy link
Copy Markdown
Contributor Author

ping for review

@spencer-lunarg spencer-lunarg added the Descriptor Heaps GL_EXT_descriptor_heap label May 20, 2026
Guang-035 added 7 commits May 21, 2026 17:29
Apply heap_offset as an access-time descriptor heap base offset for literal, spec-constant, and push-constant values, with tests covering buffer, image, texture, and sampler heap access.
Allow inline buffer_reference blocks in structured descriptor heap declarations and reduce duplicate shifted heap base generation.
Add SPIR-V coverage for buffer reference heap members and update affected baselines.
Cover acceleration structure, matrix layout, and heap buffer layout qualifier cases for structured descriptor heaps.
Emit matrix layout decorations for descriptor heap structs that use OffsetIdEXT.
@Guang-035 Guang-035 force-pushed the structured_descriptor_heap branch from 5f25599 to dce6815 Compare May 21, 2026 09:36
@Guang-035

Guang-035 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebase Guang-035:structured_descriptor_heap branch.

@ShchchowAMD ShchchowAMD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just some small points I don't fully understand.
Thanks very much for helping refining those codes!

Comment thread glslang/Include/Types.h Outdated
Comment thread glslang/MachineIndependent/glslang.y
Comment thread glslang/MachineIndependent/glslang.y Outdated
Comment thread glslang/MachineIndependent/ParseHelper.cpp Outdated
Comment thread glslang/MachineIndependent/Versions.cpp
Comment thread SPIRV/SpvBuilder.cpp Outdated
Comment thread SPIRV/SpvBuilder.cpp Outdated
Comment thread SPIRV/SpvBuilder.h
Guang-035 added 2 commits June 1, 2026 16:41
Issue: KhronosGroup#4238
Propagate readonly/writeonly qualifiers for descriptor heap resources to valid SPIR-V decoration targets.
1. For buffer descriptors, preserve the qualifiers on OpBufferPointerEXT results using NonWritable for readonly buffers and NonReadable for writeonly buffers.
2. For direct descriptor heap image arrays, synthesize one-member wrapper block types so NonReadable/NonWritable can be emitted as member decorations instead of decorating OpLoad results, which is not valid SPIR-V.
3. Add regression coverage for descriptor heap buffer and image qualifier lowering.
@Guang-035

Copy link
Copy Markdown
Contributor Author

The new commit handles readonly / writeonly qualifiers for resources loaded from descriptor heaps. Issue reported here .

extensionBehavior[E_GL_EXT_texture_cube_map_array] = EBhDisable;
extensionBehavior[E_GL_EXT_null_initializer] = EBhDisable;
extensionBehavior[E_GL_EXT_descriptor_heap] = EBhDisable;
extensionBehavior[E_GL_EXT_structured_descriptor_heap] = EBhDisable;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the GLSL spec stable already? Or is this PR blocked until the spec is merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The GLSL spec is stable, but it has not been merged yet. This PR is intended to track the current implementation and gather review feedback. I will keep it open and not merge it until the spec lands.

parseContext.setLayoutQualifier($1.loc, $$, *$1.string);
}
| IDENTIFIER EQUAL constant_expression {
| IDENTIFIER EQUAL assignment_expression {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Related to the previous comment here. Could you add a test that produces a diagnostic if the expression is not constant? (not sure if you have one already).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I missed adding coverage for this when resolving the previous comment. I added spv.layoutQualifierExpression.error.comp to verify that non-constant expressions used with regular layout qualifiers still produce the expected constant expression required diagnostic.

Comment thread SPIRV/SpvBuilder.h Outdated
StorageClass descHeapStorageClass; // for descriptor heap, record its basic storage class.
uint32_t descHeapBaseArrayStride; // for descriptor heap, record its explicit array stride.
Id descHeapBaseOffset; // byte offset applied to the heap base before descriptor lookup.
std::vector<Id> descHeapindexChain;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

spelling nit: descHeapIndexChain is more consistent with the spelling of other fields (capital I in index).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Descriptor Heaps GL_EXT_descriptor_heap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants