[SPIR-V] Add support for RWTexture2DMS and RWTexture2DMSArray - #8947
Open
Diego Novillo (dnovillo) wants to merge 1 commit into
Open
Diego Novillo (dnovillo) wants to merge 1 commit into
Diego Novillo (dnovillo) wants to merge 1 commit into
Conversation
Lower both types to a multisampled storage image and carry the sample index through every read, write and query path.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Copilot started reviewing on behalf of
Diego Novillo (dnovillo)
September 22, 2026 18:49
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Two expression-evaluation bugs can produce incorrect coordinates, samples, and side effects.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds SPIR-V support for RWTexture2DMS and RWTexture2DMSArray.
Changes:
- Lowers writable multisampled textures to SPIR-V storage images with required capabilities.
- Supports sample-indexed reads, writes, queries, reflection, and sample-zero subscripting.
- Adds documentation and regression tests.
Required fixes:
- Cache coordinate and sample expressions during component/swizzle read-modify-write operations to avoid duplicate evaluation.
- Evaluate sample expressions before coordinate expressions on writes, matching source order and read behavior.
| File | Description |
|---|---|
tools/clang/test/CodeGenSPIRV/vk.subpass-input.hlsl |
Guards subpass-input capability behavior. |
tools/clang/test/CodeGenSPIRV/type.rwtexture2dmsarray.hlsl |
Tests arrayed type lowering and capabilities. |
tools/clang/test/CodeGenSPIRV/type.rwtexture2dms.hlsl |
Tests non-arrayed type lowering. |
tools/clang/test/CodeGenSPIRV/op.rwtexture2dms.ps.hlsl |
Tests validated pixel-shader output. |
tools/clang/test/CodeGenSPIRV/op.rwtexture2dms.access.hlsl |
Tests access forms and dimension queries. |
tools/clang/test/CodeGenSPIRV/decoration.user-type.hlsl |
Tests reflection metadata. |
tools/clang/lib/SPIRV/SpirvEmitter.cpp |
Implements multisampled access; contains the expression-evaluation issues above. |
tools/clang/lib/SPIRV/SpirvBuilder.cpp |
Adds sample operands to image writes. |
tools/clang/lib/SPIRV/LowerTypeVisitor.cpp |
Lowers writable multisampled texture types. |
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp |
Classifies the resources as UAVs. |
tools/clang/lib/SPIRV/CapabilityVisitor.cpp |
Infers required SPIR-V capabilities. |
tools/clang/lib/SPIRV/AstTypeProbe.cpp |
Recognizes writable multisampled textures. |
tools/clang/include/clang/SPIRV/SpirvBuilder.h |
Updates the image-write API. |
tools/clang/include/clang/SPIRV/AstTypeProbe.h |
Declares the new type probe. |
docs/SPIR-V.rst |
Documents resource lowering and operations. |
docs/ReleaseNotes.md |
Announces the new support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
8480
to
+8489
| auto *loc = doExpr(indexExpr, range); | ||
| const QualType imageType = baseExpr->getType(); | ||
| // A plain <object>[coord] write to RWTexture2DMS(Array) targets sample 0, | ||
| // matching the DXIL path. | ||
| SpirvInstruction *sample = nullptr; | ||
| if (isMSWrite) | ||
| sample = doExpr(sampleExpr, range); | ||
| else if (isRWTextureMS(imageType)) | ||
| sample = spvBuilder.getConstantInt(astContext.UnsignedIntTy, | ||
| llvm::APInt(32, 0)); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

RWTexture2DMS<T>andRWTexture2DMSArray<T>do not compile when targeting SPIR-V.LowerTypeVisitor::lowerResourceTypelists neither name, so the type falls through to generic struct lowering.SPIR-V expresses a writable multisampled image as
OpTypeImagewithMSof 1 andSampledof 2, gated byStorageImageMultisample. Every access to one carries a sample index, and both HLSL access forms have to supply it.This change:
RWTexture2DMSandRWTexture2DMSArrayto a multisampled storage image, and infersStorageImageMultisample, plusImageMSArrayfor the arrayed variant, from the lowered type rather than from the HLSL name.Dim::SubpassDatais excluded, since the validator's requirement does not reach it andStorageImageMultisamplemaps to an optional Vulkan device feature.isRWTextureMS(QualType)toAstTypeProbeand applies it at each emitter dispatch point that has to tell a sample index from a mip level, and adds the two names to the resource lists behind-fspv-reflectand theRelaxedPrecisiondecoration.SpirvBuilder::createImageWriteasampleparameter and composes the image operands mask from it, soOpImageWritecarriesSample.<obj>.sample[idx][coord], and sample 0 on the plain<obj>[coord]subscript. Sample 0 is what the DXIL path emits for the same source, pertools/clang/test/HLSLFileCheck/hlsl/objects/RWTexture/rwtexture2dms.hlsl.Tests:
type.rwtexture2dms.hlslandtype.rwtexture2dmsarray.hlsl: the loweredOpTypeImageoperands and the capabilities. Separate files because capabilities are module-global.op.rwtexture2dms.access.hlsl: every access form, scalar and vector sampled types, and bothGetDimensionsoverloads.op.rwtexture2dms.ps.hlsl: the shader from the issue. The one test without-fcgl, so capability trimming and validation cover its output.decoration.user-type.hlsl: the two-fspv-reflectstrings.vk.subpass-input.hlsl: that aSubpassInputMSdoes not acquireStorageImageMultisample.Fixes #5244