{"record":{"id":"99afedbe9a2650de","repo":"gfx-rs/wgpu","slug":"unexpected-selector","errorCode":null,"errorMessage":"Unexpected selector {:?}","messagePattern":"Unexpected selector (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"naga/src/front/spv/next_block.rs","lineNumber":2166,"sourceCode":"                        crate::TypeInner::Scalar(crate::Scalar {\n                            kind: crate::ScalarKind::Uint,\n                            width: _,\n                        }) => {\n                            // IR expects a signed integer, so do a bitcast\n                            ctx.expressions.append(\n                                crate::Expression::As {\n                                    kind: crate::ScalarKind::Sint,\n                                    expr: selector_handle,\n                                    convert: None,\n                                },\n                                span,\n                            )\n                        }\n                        crate::TypeInner::Scalar(crate::Scalar {\n                            kind: crate::ScalarKind::Sint,\n                            width: _,\n                        }) => selector_handle,\n                        ref other => unimplemented!(\"Unexpected selector {:?}\", other),\n                    };\n\n                    // Clear past switch cases to prevent them from entering this one\n                    self.switch_cases.clear();\n\n                    for _ in 0..(inst.wc - 3) / 2 {\n                        let literal = self.next()?;\n                        let target = self.next()?;\n\n                        let case_body_idx = ctx.bodies.len();\n\n                        // Check if any previous case already used this target block id, if so\n                        // group them together to reorder them later so that no weird\n                        // fallthrough cases happen.\n                        if let Some(&mut (_, ref mut literals)) = self.switch_cases.get_mut(&target)\n                        {\n                            literals.push(literal as i32);\n                            continue;","sourceCodeStart":2148,"sourceCodeEnd":2184,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/naga/src/front/spv/next_block.rs#L2148-L2184","documentation":"The SPIR-V frontend (parser) only knows how to build a switch when the OpSwitch selector is an integer scalar (Sint/Uint). If the selector expression has any other type after loading (e.g. a vector or bool), the block builder panics with 'Unexpected selector'.","triggerScenarios":"Parsing a SPIR-V binary whose OpSwitch selector id resolves to a non-scalar-integer type — malformed or non-conformant SPIR-V, or output of a tool that produced an unexpected selector type.","commonSituations":"Loading shaders generated by custom/buggy compilers, fuzzed or hand-edited SPIR-V binaries, or SPIR-V produced after unusual constant folding that leaves a bool/vector selector.","solutions":["Fix or regenerate the SPIR-V binary so the OpSwitch selector is a scalar integer (Sint/Uint) as the SPIR-V spec requires","Run spirv-val (spirv-tools) on the binary to find the invalid OpSwitch and identify the producing tool","If the source shader is yours, ensure the switch condition is a plain i32/u32 value in the source language","Upgrade naga in case selector handling was extended"],"exampleFix":"// before (SPIR-V): %sel = op producing bool/vectors; OpSwitch %sel ...\n// after: %sel_i32 = ... i32 selector; OpSwitch %sel_i32 %default %case0 %block0 ...","handlingStrategy":"validation","validationCode":"// validate SPIR-V before parsing with naga:\n// spirv-val module.spv  (rejects non-int OpSwitch selectors per spec)\nif !spirv_val_ok(&bytes) { return Err(\"invalid SPIR-V: bad OpSwitch selector\"); }","typeGuard":null,"tryCatchPattern":"// naga frontend returns Err for most malformed input, but this case panics; validate with spirv-val first\nmatch naga::front::spv::parse_u8_slice(&bytes, &options) { Ok(m) => ..., Err(e) => ... }","preventionTips":["Always spirv-validate binaries before feeding them to naga","Ensure upstream compilers emit i32/u32 OpSwitch selectors","Avoid hand-editing SPIR-V"],"tags":["naga","spirv","parser","switch"],"backgroundTag":"unsupported-shader-construct","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}