Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array init with 0i32 uses 0u32 instead. #1061

Open
charles-r-earp opened this issue May 21, 2023 · 0 comments · May be fixed by #1143
Open

Array init with 0i32 uses 0u32 instead. #1061

charles-r-earp opened this issue May 21, 2023 · 0 comments · May be fixed by #1143
Labels
t: bug Something isn't working

Comments

@charles-r-earp
Copy link
Contributor

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 charles-r-earp added the t: bug Something isn't working label May 21, 2023
JulianKnodt added a commit to JulianKnodt/rust-gpu that referenced this issue Apr 12, 2024
@JulianKnodt JulianKnodt linked a pull request Apr 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant