Skip to content

[Migrated] Array init with 0i32 uses 0u32 instead. #85

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

Closed
rust-gpu-bot opened this issue Nov 13, 2024 · 4 comments · Fixed by #227
Closed

[Migrated] Array init with 0i32 uses 0u32 instead. #85

rust-gpu-bot opened this issue Nov 13, 2024 · 4 comments · Fixed by #227

Comments

@rust-gpu-bot
Copy link

Issue automatically imported from old repo: EmbarkStudios/rust-gpu#1061
Old labels: t: bug
Originally creatd by charles-r-earp on 2023-05-21T05:56:49Z


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]
@149segolte
Copy link

What is the state of this issue? I am able to replicate it on latest main commit.
There seems to be an unmerged PR on the original repo: EmbarkStudios/rust-gpu#1143. Is that still applicable here?

@LegNeato
Copy link
Collaborator

LegNeato commented Apr 8, 2025

Oh, looks like that PR got lost in the old repo to new repo shuffle!

LegNeato pushed a commit to LegNeato/rust-gpu that referenced this issue Apr 9, 2025
@LegNeato
Copy link
Collaborator

LegNeato commented Apr 9, 2025

@149segolte can you try with the PR / branch I just put up?

@LegNeato
Copy link
Collaborator

@charles-r-earp thanks for the original bug report and repros 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants