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

Validate vertex entry point returns the position built-in #2264

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub enum VaryingError {
pub enum EntryPointError {
#[error("Multiple conflicting entry points")]
Conflict,
#[error("Vertex shaders must return a `@builtin(position)` output value")]
MissingVertexOutputPosition,
#[error("Early depth test is not applicable")]
UnexpectedEarlyDepthTest,
#[error("Workgroup size is not applicable")]
Expand Down Expand Up @@ -353,7 +355,6 @@ impl VaryingContext<'_> {
.map_err(|e| e.with_span_context(span_context)),
None => {
match self.types[ty].inner {
//TODO: check the member types
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
crate::TypeInner::Struct { ref members, .. } => {
for (index, member) in members.iter().enumerate() {
let span_context = self.types.get_span_context(ty);
Expand All @@ -369,7 +370,6 @@ impl VaryingContext<'_> {
#[cfg(not(feature = "validate"))]
let _ = index;
}
// TODO: shouldn't this be validate?
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
Some(ref binding) => self
.validate_impl(member.ty, binding)
.map_err(|e| e.with_span_context(span_context))?,
Expand Down Expand Up @@ -601,6 +601,16 @@ impl super::Validator {
};
ctx.validate(fr.ty, fr.binding.as_ref())
.map_err_inner(|e| EntryPointError::Result(e).with_span())?;

#[cfg(feature = "validate")]
if ep.stage == crate::ShaderStage::Vertex
&& !result_built_ins.contains(&crate::BuiltIn::Position { invariant: false })
{
return Err(EntryPointError::MissingVertexOutputPosition.with_span());
}
} else if ep.stage == crate::ShaderStage::Vertex {
#[cfg(feature = "validate")]
return Err(EntryPointError::MissingVertexOutputPosition.with_span());
}

for bg in self.bind_group_masks.iter_mut() {
Expand Down
2 changes: 1 addition & 1 deletion tests/in/functions-webgl.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn test_fma() -> vec2<f32> {
}


@vertex
@fragment
fn main() {
let a = test_fma();
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/in/math-functions.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@vertex
@fragment
fn main() {
let f = 1.0;
let v = vec4<f32>(0.0);
Expand Down
2 changes: 1 addition & 1 deletion tests/in/multiview.wgsl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@vertex
@fragment
fn main(@builtin(view_index) view_index: i32) {}
2 changes: 1 addition & 1 deletion tests/in/multiview_webgl.wgsl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@vertex
@fragment
fn main(@builtin(view_index) view_index: i32) {}
Binary file modified tests/in/spv/degrees.spv
Binary file not shown.
47 changes: 47 additions & 0 deletions tests/in/spv/degrees.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 27
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %colour
OpSource GLSL 450
OpName %main "main"
OpName %deg "deg"
OpName %rad "rad"
OpName %deg_again "deg_again"
OpName %colour "colour"
OpDecorate %colour Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Function_float = OpTypePointer Function %float
%float_15 = OpConstant %float 15
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%colour = OpVariable %_ptr_Output_v4float Output
%v3float = OpTypeVector %float 3
%float_1 = OpConstant %float 1
%main = OpFunction %void None %3
%5 = OpLabel
%deg = OpVariable %_ptr_Function_float Function
%rad = OpVariable %_ptr_Function_float Function
%deg_again = OpVariable %_ptr_Function_float Function
OpStore %deg %float_15
%11 = OpLoad %float %deg
%12 = OpExtInst %float %1 Radians %11
OpStore %rad %12
%14 = OpLoad %float %rad
%15 = OpExtInst %float %1 Degrees %14
OpStore %deg_again %15
%19 = OpLoad %float %deg_again
%21 = OpCompositeConstruct %v3float %19 %19 %19
%23 = OpCompositeExtract %float %21 0
%24 = OpCompositeExtract %float %21 1
%25 = OpCompositeExtract %float %21 2
%26 = OpCompositeConstruct %v4float %23 %24 %25 %float_1
OpStore %colour %26
OpReturn
OpFunctionEnd
Binary file modified tests/in/spv/inv-hyperbolic-trig-functions.spv
Binary file not shown.
37 changes: 37 additions & 0 deletions tests/in/spv/inv-hyperbolic-trig-functions.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 19
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpSource GLSL 450
OpName %main "main"
OpName %b "b"
OpName %a "a"
OpName %c "c"
OpName %d "d"
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Function_float = OpTypePointer Function %float
%_ptr_Private_float = OpTypePointer Private %float
%a = OpVariable %_ptr_Private_float Private
%main = OpFunction %void None %3
%5 = OpLabel
%b = OpVariable %_ptr_Function_float Function
%c = OpVariable %_ptr_Function_float Function
%d = OpVariable %_ptr_Function_float Function
%11 = OpLoad %float %a
%12 = OpExtInst %float %1 Asinh %11
OpStore %b %12
%14 = OpLoad %float %a
%15 = OpExtInst %float %1 Acosh %14
OpStore %c %15
%17 = OpLoad %float %a
%18 = OpExtInst %float %1 Atanh %17
OpStore %d %18
OpReturn
OpFunctionEnd
61 changes: 61 additions & 0 deletions tests/in/spv/quad-vert.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 31
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main" %v_uv %a_uv %_ %a_pos
OpSource GLSL 460
OpName %main "main"
OpName %v_uv "v_uv"
OpName %a_uv "a_uv"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %_ ""
OpName %a_pos "a_pos"
OpDecorate %v_uv Location 0
OpDecorate %a_uv Location 1
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %a_pos Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%_ptr_Output_v2float = OpTypePointer Output %v2float
%v_uv = OpVariable %_ptr_Output_v2float Output
%_ptr_Input_v2float = OpTypePointer Input %v2float
%a_uv = OpVariable %_ptr_Input_v2float Input
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
%_ = OpVariable %_ptr_Output_gl_PerVertex Output
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%a_pos = OpVariable %_ptr_Input_v2float Input
%float_0 = OpConstant %float 0
%float_1 = OpConstant %float 1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%main = OpFunction %void None %3
%5 = OpLabel
%12 = OpLoad %v2float %a_uv
OpStore %v_uv %12
%23 = OpLoad %v2float %a_pos
%26 = OpCompositeExtract %float %23 0
%27 = OpCompositeExtract %float %23 1
%28 = OpCompositeConstruct %v4float %26 %27 %float_0 %float_1
%30 = OpAccessChain %_ptr_Output_v4float %_ %int_0
OpStore %30 %28
OpReturn
OpFunctionEnd
Loading