rust-gpu icon indicating copy to clipboard operation
rust-gpu copied to clipboard

Array init with 0i32 uses 0u32 instead.

Open charles-r-earp opened this issue 1 year ago • 0 comments

Initializing arrays seems to replace 0i32 with 0u32 when using [0i32; N].

Example (see https://github.com/charles-r-earp/rust-gpu/tree/array-init for compiletests).

; SPIR-V
; Version: 1.3
; Generator: Google rspirv; 0
; Bound: 11
; Schema: 0
               OpCapability Shader
               OpCapability Float64
               OpCapability Int64
               OpCapability Int16
               OpCapability Int8
               OpCapability ShaderClockKHR
               OpExtension "SPV_KHR_shader_clock"
               OpMemoryModel Logical Simple
               OpEntryPoint Fragment %1 "main" %o
               OpExecutionMode %1 OriginUpperLeft
          %3 = OpString "/home/charles/Documents/rust/rust-gpu/tests/ui/lang/core/array/init_array_i32.rs"
               OpSource Unknown 0 %3 "// Test creating an array.
// build-pass

use spirv_std::macros::spirv;

#[spirv(fragment)]
pub fn main(o: &mut i32) {
    let array = [0i32; 4];
    *o = array[0];
}
"
               OpName %o "o"
               OpDecorate %o Location 0
        %int = OpTypeInt 32 1
%_ptr_Output_int = OpTypePointer Output %int
       %void = OpTypeVoid
          %7 = OpTypeFunction %void
          %o = OpVariable %_ptr_Output_int Output
       %uint = OpTypeInt 32 0
     %uint_0 = OpConstant %uint 0
          %1 = OpFunction %void None %7
         %10 = OpLabel
               OpLine %3 9 4
               OpStore %o %uint_0
               OpNoLine
               OpReturn
               OpFunctionEnd

A 0u32 is stored to o instead of the expected 0i32, which fails to compile.

What works:

  • f32, this seems to be an issue with signed integers
  • <[T; N]>::default()
  • An explicit list, [0i32, 0i32, ..]
  • Using 1 instead of 0, [1i32; 1]

charles-r-earp avatar May 21 '23 05:05 charles-r-earp