Skip to content

Fix spurious StorageImageReadWithoutFormat capability for write-only textures#10023

Open
jhelferty-nv wants to merge 4 commits intoshader-slang:masterfrom
jhelferty-nv:fix-gh-9997
Open

Fix spurious StorageImageReadWithoutFormat capability for write-only textures#10023
jhelferty-nv wants to merge 4 commits intoshader-slang:masterfrom
jhelferty-nv:fix-gh-9997

Conversation

@jhelferty-nv
Copy link
Contributor

@jhelferty-nv jhelferty-nv commented Feb 14, 2026

Fixes #9997

WTexture* types with unknown format were emitting both StorageImageReadWithoutFormat and StorageImageWriteWithoutFormat SPIR-V capabilities, even though write-only textures cannot be read. This caused pipeline rejection on hardware that doesn't support unformatted storage image reads (e.g. pre-Xe Intel GPUs).

Check the texture access mode when deciding which capabilities to emit: write-only textures now only emit StorageImageWriteWithoutFormat.

Add tests for both write-only (WTexture2D) and read-write (RWTexture2D) capability emission to prevent regressions.

…textures

Fixes shader-slang#9997

WTexture* types with unknown format were emitting both
StorageImageReadWithoutFormat and StorageImageWriteWithoutFormat
SPIR-V capabilities, even though write-only textures cannot be read.
This caused pipeline rejection on hardware that doesn't support
unformatted storage image reads (e.g. pre-Xe Intel GPUs).

Check the texture access mode when deciding which capabilities to emit:
write-only textures now only emit StorageImageWriteWithoutFormat.

Add tests for both write-only (WTexture2D) and read-write (RWTexture2D)
capability emission to prevent regressions.
@jhelferty-nv jhelferty-nv requested a review from a team as a code owner February 14, 2026 01:29
Copilot AI review requested due to automatic review settings February 14, 2026 01:29
@jhelferty-nv jhelferty-nv self-assigned this Feb 14, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 78c5a92e-dca1-44f6-9261-cc53a073f5af

📥 Commits

Reviewing files that changed from the base of the PR and between ca1b13d and 0b952ee.

📒 Files selected for processing (1)
  • source/slang/slang-emit-spirv.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/slang/slang-emit-spirv.cpp

📝 Walkthrough

Walkthrough

Adjusts SPIR‑V capability emission for storage images with unknown format: require StorageImageReadWithoutFormat only when the texture access permits reads; write-only textures require only StorageImageWriteWithoutFormat. Adds tests for RWTexture2D (both capabilities) and WTexture2D (write-only capability, NonReadable decoration).

Changes

Cohort / File(s) Summary
SPIR-V capability logic
source/slang/slang-emit-spirv.cpp
Modified conditional so StorageImageReadWithoutFormat is required only when texture access includes reads; StorageImageWriteWithoutFormat remains required for writes. Updated explanatory comments.
Tests: read/write image capability
tests/spirv/read-write-image-capability.slang
Added test asserting an RWTexture2D without format emits both StorageImageReadWithoutFormat and StorageImageWriteWithoutFormat.
Tests: write-only image capability
tests/spirv/write-only-image-capability.slang
Added test asserting a WTexture2D without format emits StorageImageWriteWithoutFormat, omits StorageImageReadWithoutFormat, and includes NonReadable decoration where applicable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

"I nibble bits of SPIR‑V code by night,
Moved a check so reads only come to light,
Write‑only carrots now taste just right,
No extra hops, the pipeline's tight,
— Rabbit 🥕"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing spurious StorageImageReadWithoutFormat capability emission for write-only textures, which is the primary change in the PR.
Description check ✅ Passed The description clearly explains the bug fix, the root cause, the solution approach, and references the related issue #9997 with details about added tests.
Linked Issues check ✅ Passed The PR fully addresses issue #9997 by fixing the spurious capability emission for write-only textures and adding comprehensive tests for both write-only and read-write texture scenarios.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the StorageImageReadWithoutFormat capability issue: the core logic fix in slang-emit-spirv.cpp and two targeted test files for capability validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where write-only textures (WTexture2D) were incorrectly emitting the StorageImageReadWithoutFormat SPIR-V capability, even though they only support write operations. This caused pipeline rejection on hardware that doesn't support unformatted storage image reads (e.g., pre-Xe Intel GPUs). The fix adds a conditional check to only emit the read capability for non-write-only textures.

Changes:

  • Modified SPIR-V emission logic to check texture access mode before emitting StorageImageReadWithoutFormat capability
  • Added regression test for write-only textures (WTexture2D) to ensure only write capability is emitted
  • Added companion test for read-write textures (RWTexture2D) to ensure both capabilities are still emitted correctly

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
source/slang/slang-emit-spirv.cpp Added access mode check to conditionally emit StorageImageReadWithoutFormat capability only for non-write-only textures
tests/spirv/write-only-image-capability.slang Test verifying WTexture2D only emits StorageImageWriteWithoutFormat and NonReadable decoration
tests/spirv/read-write-image-capability.slang Test verifying RWTexture2D emits both read and write capabilities

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/spirv/write-only-image-capability.slang`:
- Line 13: The test declares a write-only texture without an explicit type
parameter; update the declaration from WTexture2D to WTexture2D<float4> so it
matches the companion read-write test and the Store call writing float4; locate
the WTexture2D declaration in write-only-image-capability.slang and add the
<float4> type parameter to the WTexture2D symbol.

@jhelferty-nv jhelferty-nv enabled auto-merge March 11, 2026 02:30
@github-actions
Copy link
Contributor

Code Review: Fix spurious StorageImageReadWithoutFormat capability for write-only textures

Summary

Clean, well-targeted fix that resolves #9997WTexture* types with unknown format were incorrectly requesting the StorageImageReadWithoutFormat SPIR-V capability, which caused pipeline rejection on hardware lacking that capability (e.g., pre-Xe Intel GPUs).

Correctness ✅

The fix is correct and directly addresses the existing TODO comment in the code:

  1. Access mode routing: At line ~2962, SLANG_RESOURCE_ACCESS_WRITE, SLANG_RESOURCE_ACCESS_READ_WRITE, and SLANG_RESOURCE_ACCESS_RASTER_ORDERED all set sampled = readWriteImage, which causes all three to enter the capability block at line 3074. The new inst->getAccess() != SLANG_RESOURCE_ACCESS_WRITE guard correctly distinguishes write-only from the other two modes.

  2. SPIR-V spec alignment: Per the SPIR-V spec, StorageImageReadWithoutFormat is required only when reading an image with Unknown format. Write-only textures (decorated with NonReadable) will never issue OpImageRead, so they should not declare this capability.

  3. Consistency with existing code: The fix is consistent with maybeEmitWriteOnlyImageDecoration() (line ~7190) which already emits SpvDecorationNonReadable for write-only textures, and with the GLSL emitter (line ~1889) which emits writeonly for SLANG_RESOURCE_ACCESS_WRITE. The capability emission now matches these existing access-mode checks.

  4. No other code paths affected: The only other place that emits StorageImageReadWithoutFormat is for subpass inputs (line ~2913), which is a completely separate path.

Test Coverage ✅

Good regression tests:

  • write-only-image-capability.slang: Verifies WTexture2D only emits StorageImageWriteWithoutFormat (not StorageImageReadWithoutFormat), and confirms NonReadable decoration. The CHECK-NOT/CHECK/CHECK-NOT sandwich pattern correctly ensures absence throughout the output.
  • read-write-image-capability.slang: Verifies RWTexture2D still emits both capabilities. Uses CHECK-DAG appropriately since capability order is not guaranteed.

Nit (non-blocking)

A test for RasterizerOrderedTexture2D<float4> with unknown format would fully cover the third access mode that enters this code path, but it is not strictly necessary since it follows the same != WRITE branch as RWTexture2D.

LGTM — minimal, well-scoped fix with good test coverage.

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

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StorageImageReadWithoutFormat SPIR-V capability is enabled when using WTexture2D

2 participants