[spv-out] fix countLeadingZeros impl (#2258)

This commit is contained in:
Teodor Tanasoaia
2023-02-20 21:40:26 +01:00
committed by GitHub
parent 810e9d26fc
commit cde457cedd
2 changed files with 19 additions and 32 deletions

View File

@@ -951,33 +951,22 @@ impl<'w> BlockContext<'w> {
_ => unreachable!(),
};
let msb_id = self.gen_id();
block.body.push(Instruction::ext_inst(
self.writer.gl450_ext_inst_id,
spirv::GLOp::FindUMsb,
int_type_id,
id,
msb_id,
&[arg0_id],
));
let sub_id = self.gen_id();
block.body.push(Instruction::binary(
MathOp::Custom(Instruction::binary(
spirv::Op::ISub,
int_type_id,
sub_id,
int_id,
result_type_id,
id,
));
if let Some(crate::ScalarKind::Uint) = arg_scalar_kind {
block.body.push(Instruction::unary(
spirv::Op::Bitcast,
result_type_id,
self.gen_id(),
sub_id,
));
}
return Ok(());
int_id,
msb_id,
))
}
Mf::CountOneBits => MathOp::Custom(Instruction::unary(
spirv::Op::BitCount,

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 78
; Bound: 76
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
@@ -28,7 +28,7 @@ OpEntryPoint Vertex %18 "main"
%50 = OpTypeVector %9 2
%53 = OpConstantComposite %50 %42 %42
%65 = OpConstant %7 31
%72 = OpConstantComposite %15 %65 %65
%71 = OpConstantComposite %15 %65 %65
%31 = OpConstantNull %7
%18 = OpFunction %2 None %19
%17 = OpLabel
@@ -71,17 +71,15 @@ OpBranch %20
%61 = OpCompositeConstruct %15 %13 %13
%63 = OpExtInst %15 %1 FindILsb %61
%62 = OpExtInst %15 %1 UMin %53 %63
%64 = OpExtInst %7 %1 FindUMsb %11
%66 = OpISub %7 %65 %64
%67 = OpExtInst %7 %1 FindUMsb %12
%68 = OpISub %7 %65 %67
%69 = OpBitcast %9 %68
%70 = OpCompositeConstruct %15 %11 %11
%71 = OpExtInst %15 %1 FindUMsb %70
%73 = OpISub %15 %72 %71
%74 = OpCompositeConstruct %50 %12 %12
%75 = OpExtInst %15 %1 FindUMsb %74
%76 = OpISub %15 %72 %75
%77 = OpBitcast %50 %76
%66 = OpExtInst %7 %1 FindUMsb %11
%64 = OpISub %7 %65 %66
%68 = OpExtInst %7 %1 FindUMsb %12
%67 = OpISub %9 %65 %68
%69 = OpCompositeConstruct %15 %11 %11
%72 = OpExtInst %15 %1 FindUMsb %69
%70 = OpISub %15 %71 %72
%73 = OpCompositeConstruct %50 %12 %12
%75 = OpExtInst %15 %1 FindUMsb %73
%74 = OpISub %50 %71 %75
OpReturn
OpFunctionEnd