Skip to content

spirv-opt --convert-relaxed-to-half pass introducing bugs in shader #6476

@danginsburg

Description

@danginsburg

I am facing a number of issues attempting to use --convert-relaxed-to-half to convert shaders with RelaxedPrecision into using true float16. Some of them fail in the NVIDIA driver with vkCreateGraphicsPipelines returning VK_ERROR_UNKNOWN, crash in the AMD Windows driver, and assert on RADV. In most cases, I do not get spirv-val errors. Although I was able to find a case that produced a spirv-val error attached in this bug to maybe narrow down the issues.

>spirv-opt --version
SPIRV-Tools v2025.4 v2025.4-0-g7f2d9ee9
>spirv-opt --convert-relaxed-to-half --simplify-instructions --redundancy-elimination --eliminate-dead-code-aggressive relaxed_precision.spv -o half.spv 
>spirv-val relaxed_precision.spv --target-env vulkan1.4

>spirv-val half.spv --target-env vulkan1.4
error: line 388: Result type (OpTypeVector) does not match the type that results from indexing into the composite (OpTypeVector).
  %19019 = OpCompositeExtract %v4half %14911 0

As shown above, you can produce a spirv-val error by running the input shader (relaxed_precision.spv) through spirv-opt --convert-relaxed-to-half --simplify-instructions --redundancy-elimination --eliminate-dead-code-aggressive relaxed_precision.spv -o half.spv and it will produce a shader with:

error: line 388: Result type (OpTypeVector) does not match the type that results from indexing into the composite (OpTypeVector).
  %19019 = OpCompositeExtract %v4half %14911 0

Often, I find it is producing pixel shaders that do not have spirv-val errors, but fail in the driver, such as the other shader pair attached (vr_simple.vfx_vs_34.spv and vr_simple.vfx_ps_34.spv). I unfortunately don't easily have access to the exact inputs that produced the output pixel shader here. Converting those shaders into a foz file with

fossilize-synth --vert vr_simple.vfx_vs_34.spv --frag vr_simple.vfx_ps_34.spv --output vr_simple.foz

and replaying on RADV give an assert:

> fossilize-replay: ../src/amd/compiler/instruction_selection/aco_select_nir.cpp:145: void aco::(anonymous namespace)::visit_tex(isel_context *, nir_tex_instr *): Assertion `instr->src[i].src.ssa->bit_size == (a16 ? 16 : 32)' failed.

relaxed_precision.zip

vr_simple.vfx_ps_34.zip

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions