Add test case to naga/spv-in for an unnamed glPerVertex struct

This commit is contained in:
Imbris 2024-02-11 13:48:46 -05:00 committed by Teodor Tanasoaia
parent 4554f852c1
commit ae22743326
8 changed files with 227 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,73 @@
;; Make sure that we don't have a validation error due to lacking capabilities
;; for bulltins such as ClipDistance when those builtin are not actually used.
;;
;; This specifically doesn't name the gl_PerVertex struct to make sure we don't
;; rely on checks for this name.
;;
;; See https://github.com/gfx-rs/wgpu/issues/4915
;;
;; Generated via `glslc -O` on this glsl code (taken from https://github.com/gfx-rs/wgpu/issues/4915):
;;
;; ```glsl
;; #version 450
;;
;; void main()
;; {
;; gl_Position = vec4(
;; (gl_VertexIndex == 0) ? -4.0 : 1.0,
;; (gl_VertexIndex == 2) ? 4.0 : -1.0,
;; 0.0,
;; 1.0
;; );
;; }
;; ```
;;
; SPIR-V
; Version: 1.0
; Generator: Google Shaderc over Glslang; 11
; Bound: 34
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %4 "main" %13 %gl_VertexIndex
OpMemberDecorate %_struct_11 0 BuiltIn Position
OpMemberDecorate %_struct_11 1 BuiltIn PointSize
OpMemberDecorate %_struct_11 2 BuiltIn ClipDistance
OpMemberDecorate %_struct_11 3 BuiltIn CullDistance
OpDecorate %_struct_11 Block
OpDecorate %gl_VertexIndex BuiltIn VertexIndex
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%_struct_11 = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%_ptr_Output__struct_11 = OpTypePointer Output %_struct_11
%13 = OpVariable %_ptr_Output__struct_11 Output
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Input_int = OpTypePointer Input %int
%gl_VertexIndex = OpVariable %_ptr_Input_int Input
%bool = OpTypeBool
%float_n4 = OpConstant %float -4
%float_1 = OpConstant %float 1
%int_2 = OpConstant %int 2
%float_4 = OpConstant %float 4
%float_n1 = OpConstant %float -1
%float_0 = OpConstant %float 0
%_ptr_Output_v4float = OpTypePointer Output %v4float
%4 = OpFunction %void None %3
%5 = OpLabel
%18 = OpLoad %int %gl_VertexIndex
%20 = OpIEqual %bool %18 %int_0
%23 = OpSelect %float %20 %float_n4 %float_1
%26 = OpIEqual %bool %18 %int_2
%29 = OpSelect %float %26 %float_4 %float_n1
%31 = OpCompositeConstruct %v4float %23 %29 %float_0 %float_1
%33 = OpAccessChain %_ptr_Output_v4float %13 %int_0
OpStore %33 %31
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,34 @@
#version 310 es
precision highp float;
precision highp int;
struct type_4 {
vec4 member;
float member_1;
float member_2[1];
float member_3[1];
};
type_4 global = type_4(vec4(0.0, 0.0, 0.0, 1.0), 1.0, float[1](0.0), float[1](0.0));
int global_1 = 0;
void function() {
int _e9 = global_1;
global.member = vec4(((_e9 == 0) ? -4.0 : 1.0), ((_e9 == 2) ? 4.0 : -1.0), 0.0, 1.0);
return;
}
void main() {
uint param = uint(gl_VertexID);
global_1 = int(param);
function();
float _e6 = global.member.y;
global.member.y = -(_e6);
vec4 _e8 = global.member;
gl_Position = _e8;
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
}

View File

@ -0,0 +1,36 @@
struct type_4 {
float4 member : SV_Position;
float member_1;
float member_2[1];
float member_3[1];
int _end_pad_0;
};
type_4 Constructtype_4(float4 arg0, float arg1, float arg2[1], float arg3[1]) {
type_4 ret = (type_4)0;
ret.member = arg0;
ret.member_1 = arg1;
ret.member_2 = arg2;
ret.member_3 = arg3;
return ret;
}
static type_4 global = Constructtype_4(float4(0.0, 0.0, 0.0, 1.0), 1.0, (float[1])0, (float[1])0);
static int global_1 = (int)0;
void function()
{
int _expr9 = global_1;
global.member = float4(((_expr9 == 0) ? -4.0 : 1.0), ((_expr9 == 2) ? 4.0 : -1.0), 0.0, 1.0);
return;
}
float4 main(uint param : SV_VertexID) : SV_Position
{
global_1 = int(param);
function();
float _expr6 = global.member.y;
global.member.y = -(_expr6);
float4 _expr8 = global.member;
return _expr8;
}

View File

@ -0,0 +1,12 @@
(
vertex:[
(
entry_point:"main",
target_profile:"vs_5_1",
),
],
fragment:[
],
compute:[
],
)

View File

@ -0,0 +1,42 @@
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>
using metal::uint;
struct type_3 {
float inner[1];
};
struct type_4 {
metal::float4 member;
float member_1;
type_3 member_2;
type_3 member_3;
};
void function(
thread type_4& global,
thread int& global_1
) {
int _e9 = global_1;
global.member = metal::float4((_e9 == 0) ? -4.0 : 1.0, (_e9 == 2) ? 4.0 : -1.0, 0.0, 1.0);
return;
}
struct main_Input {
};
struct main_Output {
metal::float4 member [[position]];
};
vertex main_Output main_(
uint param [[vertex_id]]
) {
type_4 global = type_4 {metal::float4(0.0, 0.0, 0.0, 1.0), 1.0, type_3 {}, type_3 {}};
int global_1 = {};
global_1 = static_cast<int>(param);
function(global, global_1);
float _e6 = global.member.y;
global.member.y = -(_e6);
metal::float4 _e8 = global.member;
return main_Output { _e8 };
}

View File

@ -0,0 +1,25 @@
struct type_4 {
@builtin(position) member: vec4<f32>,
member_1: f32,
member_2: array<f32, 1>,
member_3: array<f32, 1>,
}
var<private> global: type_4 = type_4(vec4<f32>(0f, 0f, 0f, 1f), 1f, array<f32, 1>(), array<f32, 1>());
var<private> global_1: i32;
fn function() {
let _e9 = global_1;
global.member = vec4<f32>(select(1f, -4f, (_e9 == 0i)), select(-1f, 4f, (_e9 == 2i)), 0f, 1f);
return;
}
@vertex
fn main(@builtin(vertex_index) param: u32) -> @builtin(position) vec4<f32> {
global_1 = i32(param);
function();
let _e6 = global.member.y;
global.member.y = -(_e6);
let _e8 = global.member;
return _e8;
}

View File

@ -886,6 +886,11 @@ fn convert_spv_all() {
true,
Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL,
);
convert_spv(
"unnamed-gl-per-vertex",
true,
Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL,
);
}
#[cfg(feature = "glsl-in")]