Skip to content

opt: Fix invalid OpSelect folding in spirv-opt - #6827

Merged
s-perron merged 1 commit into
KhronosGroup:mainfrom
s-perron:wt/i8603_bad_select
Aug 5, 2026
Merged

s-perron merged 1 commit into
KhronosGroup:mainfrom
s-perron:wt/i8603_bad_select

Conversation

@s-perron

@s-perron s-perron commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

MergeBinaryOpSelect rule was folding binary operations with select
instructions even when the result was a vector and the condition was
scalar, which is only valid in SPIR-V 1.4+. This change restricts
this folding in SPIR-V versions prior to 1.4.

Assisted by: Antigravity

Fixes microsoft/DirectXShaderCompiler#8603

MergeBinaryOpSelect rule was folding binary operations with select
instructions even when the result was a vector and the condition was
scalar, which is only valid in SPIR-V 1.4+. This change restricts
this folding in SPIR-V versions prior to 1.4.

Assisted by: Antigravity

Fixes #8603
@s-perron
s-perron requested a review from sudonatalie August 5, 2026 17:23
@s-perron
s-perron enabled auto-merge (squash) August 5, 2026 17:42
@s-perron
s-perron merged commit 1c33617 into KhronosGroup:main Aug 5, 2026
4 checks passed
damyanp added a commit to damyanp/DirectXShaderCompiler that referenced this pull request Aug 5, 2026
…#8603)

Advances external/SPIRV-Tools from b707790a to 1c336172, which includes
KhronosGroup/SPIRV-Tools#6827 "opt: Fix invalid OpSelect folding in
spirv-opt".

The MergeBinaryOpSelect folding rule was merging a binary op with an
OpSelect even when the result type was a vector and the select's
condition was a scalar bool. That form of OpSelect is only legal from
SPIR-V 1.4 onwards, so targeting vulkan1.1 (SPIR-V 1.3) produced a
module that failed validation:

  fatal error: generated SPIR-V is invalid: Expected vector sizes of
  Result Type and the condition to be equal: Select
    %91 = OpSelect %v3float %87 %38 %39

The upstream fix skips the fold in that case for SPIR-V versions before
1.4. DXC always constructs spvtools::Optimizer with the target env from
-fspv-target-env, so the guard applies to all DXC SPIR-V codegen.

b707790a is an ancestor of 1c336172, so this keeps the loop-unrolling
duplicate decoration fix that resolves microsoft#8609. SPIRV-Headers needs no
change: 1c336172 pins 29981f65, which is what this branch already uses.

Fixes microsoft#8603

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5
@s-perron
s-perron deleted the wt/i8603_bad_select branch August 5, 2026 18:25
@damyanp

damyanp commented Aug 5, 2026

Copy link
Copy Markdown

@s-perron - in the future, could you please avoid putting a "fixes xxxx" note in PRs here for issues that are in the DXC repo? It auto-closes those issues, which isn't really the desired behavior since we still have work to do to integrate the fix into DXC.

damyanp added a commit to microsoft/DirectXShaderCompiler that referenced this pull request Aug 6, 2026
Fixes two SPIR-V validation failures under -O3:

- #8609: loop unrolling duplicated RelaxedPrecision decorations
  (KhronosGroup/SPIRV-Tools#6690)
- #8603: MergeBinaryOpSelect produced an OpSelect with a vector result
  type and a scalar condition, only legal in SPIR-V 1.4+
  (KhronosGroup/SPIRV-Tools#6827)

SPIRV-Headers moves to 29981f65 to match; SPIRV-Tools 1c336172 does not
build against the older headers.

XFAIL resource-heap-ext-texture: the validator now requires explicit
layout for UniformConstant when SPV_EXT_descriptor_heap is used
(KhronosGroup/SPIRV-Tools#6792).

Assisted-by: copilot
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5
damyanp added a commit to microsoft/DirectXShaderCompiler that referenced this pull request Aug 6, 2026
Fixes #8603: MergeBinaryOpSelect produced an OpSelect with a vector
result type and a scalar condition, which is only legal in SPIR-V 1.4+
(KhronosGroup/SPIRV-Tools#6827).

This exposes #8740 where the resource-heap-ext-texture.hlsl test fails
validation - for now this is worked around by disabling the test, since
#8517 looks like it is reworking it anyway.

Assisted-by: copilot

---------

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5
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.

[SPIR-V] Env Vulkan 1.1 Validation error: Bad OpSelect instruction produced with optimizations enabled.

3 participants