writer/spirv: Add Flat decoration to integers

Vulkan requires that shader inputs/outputs that are integers must be
decorated with Flat.

Bug: tint:746, dawn:956
Change-Id: I648451b9aa559d08415bada904dee5f9d1e4e60f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56400
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2021-06-29 13:36:05 +00:00 committed by Tint LUCI CQ
parent 230295dea4
commit 5ea0fe00bf
20 changed files with 265 additions and 8 deletions

View File

@ -848,8 +848,14 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
push_annot(spv::Op::OpDecorate,
{Operand::Int(var_id), Operand::Int(SpvDecorationLocation),
Operand::Int(location->value())});
if (type->is_integer_scalar_or_vector()) {
// Vulkan requires that integers are always decorated with `Flat`.
AddInterpolationDecorations(var_id, ast::InterpolationType::kFlat,
ast::InterpolationSampling::kNone);
}
} else if (auto* interpolate = deco->As<ast::InterpolateDecoration>()) {
AddInterpolationDecorations(var_id, interpolate);
AddInterpolationDecorations(var_id, interpolate->type(),
interpolate->sampling());
} else if (auto* binding = deco->As<ast::BindingDecoration>()) {
push_annot(spv::Op::OpDecorate,
{Operand::Int(var_id), Operand::Int(SpvDecorationBinding),
@ -4011,10 +4017,10 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::Builtin builtin,
return SpvBuiltInMax;
}
void Builder::AddInterpolationDecorations(
uint32_t id,
ast::InterpolateDecoration* interpolate) {
switch (interpolate->type()) {
void Builder::AddInterpolationDecorations(uint32_t id,
ast::InterpolationType type,
ast::InterpolationSampling sampling) {
switch (type) {
case ast::InterpolationType::kLinear:
push_annot(spv::Op::OpDecorate,
{Operand::Int(id), Operand::Int(SpvDecorationNoPerspective)});
@ -4026,7 +4032,7 @@ void Builder::AddInterpolationDecorations(
case ast::InterpolationType::kPerspective:
break;
}
switch (interpolate->sampling()) {
switch (sampling) {
case ast::InterpolationSampling::kCentroid:
push_annot(spv::Op::OpDecorate,
{Operand::Int(id), Operand::Int(SpvDecorationCentroid)});

View File

@ -212,9 +212,11 @@ class Builder {
/// Converts an interpolate attribute to SPIR-V decorations and pushes a
/// capability if needed.
/// @param id the id to decorate
/// @param interpolate the interpolation attribute to convert
/// @param type the interpolation type
/// @param sampling the interpolation sampling
void AddInterpolationDecorations(uint32_t id,
ast::InterpolateDecoration* interpolate);
ast::InterpolationType type,
ast::InterpolationSampling sampling);
/// Generates a label for the given id. Emits an error and returns false if
/// we're currently outside a function.

View File

@ -133,6 +133,7 @@ OpName %10 "tint_symbol_3"
OpName %11 "tint_symbol_1"
OpName %14 "frag_main"
OpDecorate %1 Location 0
OpDecorate %1 Flat
OpDecorate %4 Location 0
%3 = OpTypeInt 32 0
%2 = OpTypePointer Input %3

View File

@ -13,7 +13,9 @@
OpName %tint_symbol_3 "tint_symbol_3"
OpName %main "main"
OpDecorate %tint_symbol Location 0
OpDecorate %tint_symbol Flat
OpDecorate %tint_symbol_1 Location 1
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 2
OpDecorate %tint_symbol_3 Location 3
%int = OpTypeInt 32 1

View File

@ -18,7 +18,9 @@
OpMemberName %FragmentInputs 2 "loc2"
OpMemberName %FragmentInputs 3 "loc3"
OpDecorate %tint_symbol Location 0
OpDecorate %tint_symbol Flat
OpDecorate %tint_symbol_1 Location 1
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 2
OpDecorate %tint_symbol_3 Location 3
OpMemberDecorate %FragmentInputs 0 Offset 0

View File

@ -25,8 +25,10 @@
OpMemberName %FragmentInputs1 1 "sample_mask"
OpDecorate %tint_symbol BuiltIn FragCoord
OpDecorate %tint_symbol_1 Location 0
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_3 BuiltIn FrontFacing
OpDecorate %tint_symbol_4 Location 1
OpDecorate %tint_symbol_4 Flat
OpDecorate %tint_symbol_5 BuiltIn SampleId
OpDecorate %tint_symbol_6 Location 3
OpDecorate %_arr_uint_uint_1 ArrayStride 4

View File

@ -30,7 +30,9 @@
OpName %tint_symbol_9 "tint_symbol_9"
OpName %main3 "main3"
OpDecorate %tint_symbol_1 Location 0
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_4 Location 1
OpDecorate %tint_symbol_4 Flat
OpDecorate %tint_symbol_7 Location 2
OpDecorate %tint_symbol_10 Location 3
%int = OpTypeInt 32 1

View File

@ -20,7 +20,9 @@
OpName %tint_symbol "tint_symbol"
OpName %main "main"
OpDecorate %tint_symbol_1 Location 0
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 1
OpDecorate %tint_symbol_2 Flat
OpDecorate %tint_symbol_3 Location 2
OpDecorate %tint_symbol_4 Location 3
OpMemberDecorate %FragmentOutputs 0 Offset 0

View File

@ -25,8 +25,10 @@
OpName %tint_symbol "tint_symbol"
OpName %main "main"
OpDecorate %tint_symbol_1 Location 0
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 BuiltIn FragDepth
OpDecorate %tint_symbol_3 Location 1
OpDecorate %tint_symbol_3 Flat
OpDecorate %tint_symbol_4 Location 2
OpDecorate %_arr_uint_uint_1 ArrayStride 4
OpDecorate %tint_symbol_5 BuiltIn SampleMask

View File

@ -0,0 +1,16 @@
struct Interface {
[[location(0)]] i : i32;
[[location(1)]] u : u32;
[[location(2)]] vi : vec4<i32>;
[[location(3)]] vu : vec4<u32>;
[[builtin(position)]] pos : vec4<f32>;
};
[[stage(vertex)]]
fn vert_main() -> Interface {
return Interface();
}
[[stage(fragment)]]
fn frag_main(inputs : Interface) {
}

View File

@ -0,0 +1,33 @@
struct Interface {
int i;
uint u;
int4 vi;
uint4 vu;
float4 pos;
};
struct tint_symbol {
int i : TEXCOORD0;
uint u : TEXCOORD1;
int4 vi : TEXCOORD2;
uint4 vu : TEXCOORD3;
float4 pos : SV_Position;
};
tint_symbol vert_main() {
const Interface tint_symbol_1 = {0, 0u, int4(0, 0, 0, 0), uint4(0u, 0u, 0u, 0u), float4(0.0f, 0.0f, 0.0f, 0.0f)};
const tint_symbol tint_symbol_4 = {tint_symbol_1.i, tint_symbol_1.u, tint_symbol_1.vi, tint_symbol_1.vu, tint_symbol_1.pos};
return tint_symbol_4;
}
struct tint_symbol_3 {
int i : TEXCOORD0;
uint u : TEXCOORD1;
int4 vi : TEXCOORD2;
uint4 vu : TEXCOORD3;
float4 pos : SV_Position;
};
void frag_main(tint_symbol_3 tint_symbol_2) {
const Interface inputs = {tint_symbol_2.i, tint_symbol_2.u, tint_symbol_2.vi, tint_symbol_2.vu, tint_symbol_2.pos};
return;
}

View File

@ -0,0 +1,35 @@
#include <metal_stdlib>
using namespace metal;
struct Interface {
int i;
uint u;
int4 vi;
uint4 vu;
float4 pos;
};
struct tint_symbol {
int i [[user(locn0)]];
uint u [[user(locn1)]];
int4 vi [[user(locn2)]];
uint4 vu [[user(locn3)]];
float4 pos [[position]];
};
struct tint_symbol_4 {
int i [[user(locn0)]];
uint u [[user(locn1)]];
int4 vi [[user(locn2)]];
uint4 vu [[user(locn3)]];
};
vertex tint_symbol vert_main() {
Interface const tint_symbol_1 = {};
tint_symbol const tint_symbol_5 = {.i=tint_symbol_1.i, .u=tint_symbol_1.u, .vi=tint_symbol_1.vi, .vu=tint_symbol_1.vu, .pos=tint_symbol_1.pos};
return tint_symbol_5;
}
fragment void frag_main(float4 tint_symbol_3 [[position]], tint_symbol_4 tint_symbol_2 [[stage_in]]) {
Interface const inputs = {.i=tint_symbol_2.i, .u=tint_symbol_2.u, .vi=tint_symbol_2.vi, .vu=tint_symbol_2.vu, .pos=tint_symbol_3};
return;
}

View File

@ -0,0 +1,120 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 54
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %vert_main "vert_main" %tint_pointsize %tint_symbol_1 %tint_symbol_2 %tint_symbol_3 %tint_symbol_4 %tint_symbol_5
OpEntryPoint Fragment %frag_main "frag_main"
OpExecutionMode %frag_main OriginUpperLeft
OpName %tint_pointsize "tint_pointsize"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %tint_symbol_3 "tint_symbol_3"
OpName %tint_symbol_4 "tint_symbol_4"
OpName %tint_symbol_5 "tint_symbol_5"
OpName %tint_symbol_7 "tint_symbol_7"
OpName %tint_symbol_8 "tint_symbol_8"
OpName %tint_symbol_9 "tint_symbol_9"
OpName %tint_symbol_10 "tint_symbol_10"
OpName %tint_symbol_11 "tint_symbol_11"
OpName %Interface "Interface"
OpMemberName %Interface 0 "i"
OpMemberName %Interface 1 "u"
OpMemberName %Interface 2 "vi"
OpMemberName %Interface 3 "vu"
OpMemberName %Interface 4 "pos"
OpName %tint_symbol_6 "tint_symbol_6"
OpName %tint_symbol "tint_symbol"
OpName %vert_main "vert_main"
OpName %frag_main "frag_main"
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol_1 Location 0
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 1
OpDecorate %tint_symbol_2 Flat
OpDecorate %tint_symbol_3 Location 2
OpDecorate %tint_symbol_3 Flat
OpDecorate %tint_symbol_4 Location 3
OpDecorate %tint_symbol_4 Flat
OpDecorate %tint_symbol_5 BuiltIn Position
OpDecorate %tint_symbol_7 Location 0
OpDecorate %tint_symbol_7 Flat
OpDecorate %tint_symbol_8 Location 1
OpDecorate %tint_symbol_8 Flat
OpDecorate %tint_symbol_9 Location 2
OpDecorate %tint_symbol_9 Flat
OpDecorate %tint_symbol_10 Location 3
OpDecorate %tint_symbol_10 Flat
OpDecorate %tint_symbol_11 BuiltIn FragCoord
OpMemberDecorate %Interface 0 Offset 0
OpMemberDecorate %Interface 1 Offset 4
OpMemberDecorate %Interface 2 Offset 16
OpMemberDecorate %Interface 3 Offset 32
OpMemberDecorate %Interface 4 Offset 48
%float = OpTypeFloat 32
%_ptr_Output_float = OpTypePointer Output %float
%4 = OpConstantNull %float
%tint_pointsize = OpVariable %_ptr_Output_float Output %4
%int = OpTypeInt 32 1
%_ptr_Output_int = OpTypePointer Output %int
%8 = OpConstantNull %int
%tint_symbol_1 = OpVariable %_ptr_Output_int Output %8
%uint = OpTypeInt 32 0
%_ptr_Output_uint = OpTypePointer Output %uint
%12 = OpConstantNull %uint
%tint_symbol_2 = OpVariable %_ptr_Output_uint Output %12
%v4int = OpTypeVector %int 4
%_ptr_Output_v4int = OpTypePointer Output %v4int
%16 = OpConstantNull %v4int
%tint_symbol_3 = OpVariable %_ptr_Output_v4int Output %16
%v4uint = OpTypeVector %uint 4
%_ptr_Output_v4uint = OpTypePointer Output %v4uint
%20 = OpConstantNull %v4uint
%tint_symbol_4 = OpVariable %_ptr_Output_v4uint Output %20
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%24 = OpConstantNull %v4float
%tint_symbol_5 = OpVariable %_ptr_Output_v4float Output %24
%_ptr_Input_int = OpTypePointer Input %int
%tint_symbol_7 = OpVariable %_ptr_Input_int Input
%_ptr_Input_uint = OpTypePointer Input %uint
%tint_symbol_8 = OpVariable %_ptr_Input_uint Input
%_ptr_Input_v4int = OpTypePointer Input %v4int
%tint_symbol_9 = OpVariable %_ptr_Input_v4int Input
%_ptr_Input_v4uint = OpTypePointer Input %v4uint
%tint_symbol_10 = OpVariable %_ptr_Input_v4uint Input
%_ptr_Input_v4float = OpTypePointer Input %v4float
%tint_symbol_11 = OpVariable %_ptr_Input_v4float Input
%void = OpTypeVoid
%Interface = OpTypeStruct %int %uint %v4int %v4uint %v4float
%35 = OpTypeFunction %void %Interface
%46 = OpTypeFunction %void
%float_1 = OpConstant %float 1
%51 = OpConstantNull %Interface
%tint_symbol_6 = OpFunction %void None %35
%tint_symbol = OpFunctionParameter %Interface
%40 = OpLabel
%41 = OpCompositeExtract %int %tint_symbol 0
OpStore %tint_symbol_1 %41
%42 = OpCompositeExtract %uint %tint_symbol 1
OpStore %tint_symbol_2 %42
%43 = OpCompositeExtract %v4int %tint_symbol 2
OpStore %tint_symbol_3 %43
%44 = OpCompositeExtract %v4uint %tint_symbol 3
OpStore %tint_symbol_4 %44
%45 = OpCompositeExtract %v4float %tint_symbol 4
OpStore %tint_symbol_5 %45
OpReturn
OpFunctionEnd
%vert_main = OpFunction %void None %46
%48 = OpLabel
OpStore %tint_pointsize %float_1
%50 = OpFunctionCall %void %tint_symbol_6 %51
OpReturn
OpFunctionEnd
%frag_main = OpFunction %void None %46
%53 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,21 @@
struct Interface {
[[location(0)]]
i : i32;
[[location(1)]]
u : u32;
[[location(2)]]
vi : vec4<i32>;
[[location(3)]]
vu : vec4<u32>;
[[builtin(position)]]
pos : vec4<f32>;
};
[[stage(vertex)]]
fn vert_main() -> Interface {
return Interface();
}
[[stage(fragment)]]
fn frag_main(inputs : Interface) {
}

View File

@ -26,8 +26,10 @@
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol_1 BuiltIn Position
OpDecorate %tint_symbol_2 Location 0
OpDecorate %tint_symbol_2 Flat
OpDecorate %tint_symbol_5 BuiltIn Position
OpDecorate %tint_symbol_6 Location 0
OpDecorate %tint_symbol_6 Flat
OpMemberDecorate %VertexOutput 0 Offset 0
OpMemberDecorate %VertexOutput 1 Offset 16
%float = OpTypeFloat 32

View File

@ -25,6 +25,7 @@
OpDecorate %output Binding 0
OpDecorate %tint_symbol Location 0
OpDecorate %tint_symbol_1 Location 1
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 BuiltIn FragCoord
%float = OpTypeFloat 32
%uint = OpTypeInt 32 0

View File

@ -17,7 +17,9 @@
OpName %main "main"
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol Location 0
OpDecorate %tint_symbol Flat
OpDecorate %tint_symbol_1 Location 1
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 2
OpDecorate %tint_symbol_3 Location 3
OpDecorate %tint_symbol_5 BuiltIn Position

View File

@ -22,7 +22,9 @@
OpMemberName %VertexInputs 3 "loc3"
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol Location 0
OpDecorate %tint_symbol Flat
OpDecorate %tint_symbol_1 Location 1
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 2
OpDecorate %tint_symbol_3 Location 3
OpDecorate %tint_symbol_6 BuiltIn Position

View File

@ -26,7 +26,9 @@
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol BuiltIn VertexIndex
OpDecorate %tint_symbol_1 Location 0
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_3 Location 1
OpDecorate %tint_symbol_3 Flat
OpDecorate %tint_symbol_4 BuiltIn InstanceIndex
OpDecorate %tint_symbol_5 Location 2
OpDecorate %tint_symbol_6 Location 3

View File

@ -23,7 +23,9 @@
OpName %main "main"
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol_1 Location 0
OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 1
OpDecorate %tint_symbol_2 Flat
OpDecorate %tint_symbol_3 Location 2
OpDecorate %tint_symbol_4 Location 3
OpDecorate %tint_symbol_5 BuiltIn Position