From 52043be00489d6dedb08c36bb97d018d11cb1e13 Mon Sep 17 00:00:00 2001 From: PyryM Date: Thu, 30 Mar 2023 10:02:54 -0400 Subject: [PATCH] [spv-out] Fix invalid spirv being generated from integer dot products (#2291) * Fix invalid spirv generation in int dotprod constants cannot be declared inside of a function block, so instead use `write_constant_null` to produce a correctly-declared constant 0. * autogenerated test snapshots --- src/back/spv/block.rs | 7 +------ tests/out/spv/functions.spvasm | 2 +- tests/out/spv/math-functions.spvasm | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/back/spv/block.rs b/src/back/spv/block.rs index b28b94fe91..8366df415a 100644 --- a/src/back/spv/block.rs +++ b/src/back/spv/block.rs @@ -1627,12 +1627,7 @@ impl<'w> BlockContext<'w> { size: u32, block: &mut Block, ) { - let const_null = self.gen_id(); - block - .body - .push(Instruction::constant_null(result_type_id, const_null)); - - let mut partial_sum = const_null; + let mut partial_sum = self.writer.write_constant_null(result_type_id); let last_component = size - 1; for index in 0..=last_component { // compute the product of the current components diff --git a/tests/out/spv/functions.spvasm b/tests/out/spv/functions.spvasm index bfebd09f84..ef3a2cd235 100644 --- a/tests/out/spv/functions.spvasm +++ b/tests/out/spv/functions.spvasm @@ -23,10 +23,10 @@ OpExecutionMode %74 LocalSize 1 1 1 %15 = OpTypeVector %7 4 %18 = OpTypeFunction %12 %26 = OpTypeFunction %7 -%75 = OpTypeFunction %2 %31 = OpConstantNull %7 %42 = OpConstantNull %9 %57 = OpConstantNull %7 +%75 = OpTypeFunction %2 %17 = OpFunction %12 None %18 %16 = OpLabel OpBranch %19 diff --git a/tests/out/spv/math-functions.spvasm b/tests/out/spv/math-functions.spvasm index 9dbde7ddf0..bee60f29e8 100644 --- a/tests/out/spv/math-functions.spvasm +++ b/tests/out/spv/math-functions.spvasm @@ -24,12 +24,12 @@ OpEntryPoint Vertex %18 "main" %19 = OpTypeFunction %2 %27 = OpConstantComposite %14 %5 %5 %5 %5 %28 = OpConstantComposite %14 %3 %3 %3 %3 +%31 = OpConstantNull %7 %42 = OpConstant %9 32 %50 = OpTypeVector %9 2 %53 = OpConstantComposite %50 %42 %42 %65 = OpConstant %7 31 %71 = OpConstantComposite %15 %65 %65 -%31 = OpConstantNull %7 %18 = OpFunction %2 None %19 %17 = OpLabel OpBranch %20