writer/spirv: Implement interpolate attributes

Add the SampleRateShading capability if the sampling type is `sample`.

Bug: tint:746
Change-Id: I20fb25913f5c0919b6d16a9d0e9fc8b1551ff7ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56247
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2021-06-28 23:04:43 +00:00
parent 0dd41c62cf
commit c7aa21e265
5 changed files with 253 additions and 114 deletions

View File

@ -842,6 +842,8 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
push_annot(spv::Op::OpDecorate, push_annot(spv::Op::OpDecorate,
{Operand::Int(var_id), Operand::Int(SpvDecorationLocation), {Operand::Int(var_id), Operand::Int(SpvDecorationLocation),
Operand::Int(location->value())}); Operand::Int(location->value())});
} else if (auto* interpolate = deco->As<ast::InterpolateDecoration>()) {
AddInterpolationDecorations(var_id, interpolate);
} else if (auto* binding = deco->As<ast::BindingDecoration>()) { } else if (auto* binding = deco->As<ast::BindingDecoration>()) {
push_annot(spv::Op::OpDecorate, push_annot(spv::Op::OpDecorate,
{Operand::Int(var_id), Operand::Int(SpvDecorationBinding), {Operand::Int(var_id), Operand::Int(SpvDecorationBinding),
@ -3986,6 +3988,37 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::Builtin builtin,
return SpvBuiltInMax; return SpvBuiltInMax;
} }
void Builder::AddInterpolationDecorations(
uint32_t id,
ast::InterpolateDecoration* interpolate) {
switch (interpolate->type()) {
case ast::InterpolationType::kLinear:
push_annot(spv::Op::OpDecorate,
{Operand::Int(id), Operand::Int(SpvDecorationNoPerspective)});
break;
case ast::InterpolationType::kFlat:
push_annot(spv::Op::OpDecorate,
{Operand::Int(id), Operand::Int(SpvDecorationFlat)});
break;
case ast::InterpolationType::kPerspective:
break;
}
switch (interpolate->sampling()) {
case ast::InterpolationSampling::kCentroid:
push_annot(spv::Op::OpDecorate,
{Operand::Int(id), Operand::Int(SpvDecorationCentroid)});
break;
case ast::InterpolationSampling::kSample:
push_capability(SpvCapabilitySampleRateShading);
push_annot(spv::Op::OpDecorate,
{Operand::Int(id), Operand::Int(SpvDecorationSample)});
break;
case ast::InterpolationSampling::kCenter:
case ast::InterpolationSampling::kNone:
break;
}
}
SpvImageFormat Builder::convert_image_format_to_spv( SpvImageFormat Builder::convert_image_format_to_spv(
const ast::ImageFormat format) { const ast::ImageFormat format) {
switch (format) { switch (format) {

View File

@ -27,6 +27,7 @@
#include "src/ast/continue_statement.h" #include "src/ast/continue_statement.h"
#include "src/ast/discard_statement.h" #include "src/ast/discard_statement.h"
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/interpolate_decoration.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/switch_statement.h" #include "src/ast/switch_statement.h"
@ -208,6 +209,13 @@ class Builder {
/// @returns the SPIR-V builtin or SpvBuiltInMax on error. /// @returns the SPIR-V builtin or SpvBuiltInMax on error.
SpvBuiltIn ConvertBuiltin(ast::Builtin builtin, ast::StorageClass storage); SpvBuiltIn ConvertBuiltin(ast::Builtin builtin, ast::StorageClass storage);
/// 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
void AddInterpolationDecorations(uint32_t id,
ast::InterpolateDecoration* interpolate);
/// Generates a label for the given id. Emits an error and returns false if /// Generates a label for the given id. Emits an error and returns false if
/// we're currently outside a function. /// we're currently outside a function.
/// @param id the id to use for the label /// @param id the id to use for the label

View File

@ -1,24 +1,51 @@
SKIP: FAILED ; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
[[location(0), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol : f32; ; Bound: 15
; Schema: 0
[[location(1), interpolate(flat), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_1 : f32; OpCapability Shader
OpCapability SampleRateShading
[[location(2), interpolate(perspective, center), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_2 : f32; OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
[[location(3), interpolate(perspective, centroid), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_3 : f32; OpExecutionMode %main OriginUpperLeft
OpName %tint_symbol "tint_symbol"
[[location(4), interpolate(perspective, sample), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_4 : f32; OpName %tint_symbol_1 "tint_symbol_1"
OpName %tint_symbol_2 "tint_symbol_2"
[[location(5), interpolate(linear, center), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_5 : f32; OpName %tint_symbol_3 "tint_symbol_3"
OpName %tint_symbol_4 "tint_symbol_4"
[[location(6), interpolate(linear, centroid), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_6 : f32; OpName %tint_symbol_5 "tint_symbol_5"
OpName %tint_symbol_6 "tint_symbol_6"
[[location(7), interpolate(linear, sample), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_7 : f32; OpName %tint_symbol_7 "tint_symbol_7"
OpName %main "main"
[[stage(fragment)]] OpDecorate %tint_symbol Location 0
fn main() { OpDecorate %tint_symbol_1 Location 1
} OpDecorate %tint_symbol_1 Flat
OpDecorate %tint_symbol_2 Location 2
Failed to generate: unknown decoration OpDecorate %tint_symbol_3 Location 3
OpDecorate %tint_symbol_3 Centroid
OpDecorate %tint_symbol_4 Location 4
OpDecorate %tint_symbol_4 Sample
OpDecorate %tint_symbol_5 Location 5
OpDecorate %tint_symbol_5 NoPerspective
OpDecorate %tint_symbol_6 Location 6
OpDecorate %tint_symbol_6 NoPerspective
OpDecorate %tint_symbol_6 Centroid
OpDecorate %tint_symbol_7 Location 7
OpDecorate %tint_symbol_7 NoPerspective
OpDecorate %tint_symbol_7 Sample
%float = OpTypeFloat 32
%_ptr_Input_float = OpTypePointer Input %float
%tint_symbol = OpVariable %_ptr_Input_float Input
%tint_symbol_1 = OpVariable %_ptr_Input_float Input
%tint_symbol_2 = OpVariable %_ptr_Input_float Input
%tint_symbol_3 = OpVariable %_ptr_Input_float Input
%tint_symbol_4 = OpVariable %_ptr_Input_float Input
%tint_symbol_5 = OpVariable %_ptr_Input_float Input
%tint_symbol_6 = OpVariable %_ptr_Input_float Input
%tint_symbol_7 = OpVariable %_ptr_Input_float Input
%void = OpTypeVoid
%11 = OpTypeFunction %void
%main = OpFunction %void None %11
%14 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -1,35 +1,51 @@
SKIP: FAILED ; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
struct In { ; Bound: 15
none : f32; ; Schema: 0
flat : f32; OpCapability Shader
perspective_center : f32; OpCapability SampleRateShading
perspective_centroid : f32; OpMemoryModel Logical GLSL450
perspective_sample : f32; OpEntryPoint Fragment %main "main"
linear_center : f32; OpExecutionMode %main OriginUpperLeft
linear_centroid : f32; OpName %tint_symbol "tint_symbol"
linear_sample : f32; OpName %tint_symbol_1 "tint_symbol_1"
}; OpName %tint_symbol_2 "tint_symbol_2"
OpName %tint_symbol_3 "tint_symbol_3"
[[location(0), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol : f32; OpName %tint_symbol_4 "tint_symbol_4"
OpName %tint_symbol_5 "tint_symbol_5"
[[location(1), interpolate(flat), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_1 : f32; OpName %tint_symbol_6 "tint_symbol_6"
OpName %tint_symbol_7 "tint_symbol_7"
[[location(2), interpolate(perspective, center), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_2 : f32; OpName %main "main"
OpDecorate %tint_symbol Location 0
[[location(3), interpolate(perspective, centroid), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_3 : f32; OpDecorate %tint_symbol_1 Location 1
OpDecorate %tint_symbol_1 Flat
[[location(4), interpolate(perspective, sample), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_4 : f32; OpDecorate %tint_symbol_2 Location 2
OpDecorate %tint_symbol_3 Location 3
[[location(5), interpolate(linear, center), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_5 : f32; OpDecorate %tint_symbol_3 Centroid
OpDecorate %tint_symbol_4 Location 4
[[location(6), interpolate(linear, centroid), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_6 : f32; OpDecorate %tint_symbol_4 Sample
OpDecorate %tint_symbol_5 Location 5
[[location(7), interpolate(linear, sample), internal(disable_validation__ignore_storage_class)]] var<in> tint_symbol_7 : f32; OpDecorate %tint_symbol_5 NoPerspective
OpDecorate %tint_symbol_6 Location 6
[[stage(fragment)]] OpDecorate %tint_symbol_6 NoPerspective
fn main() { OpDecorate %tint_symbol_6 Centroid
} OpDecorate %tint_symbol_7 Location 7
OpDecorate %tint_symbol_7 NoPerspective
Failed to generate: unknown decoration OpDecorate %tint_symbol_7 Sample
%float = OpTypeFloat 32
%_ptr_Input_float = OpTypePointer Input %float
%tint_symbol = OpVariable %_ptr_Input_float Input
%tint_symbol_1 = OpVariable %_ptr_Input_float Input
%tint_symbol_2 = OpVariable %_ptr_Input_float Input
%tint_symbol_3 = OpVariable %_ptr_Input_float Input
%tint_symbol_4 = OpVariable %_ptr_Input_float Input
%tint_symbol_5 = OpVariable %_ptr_Input_float Input
%tint_symbol_6 = OpVariable %_ptr_Input_float Input
%tint_symbol_7 = OpVariable %_ptr_Input_float Input
%void = OpTypeVoid
%11 = OpTypeFunction %void
%main = OpFunction %void None %11
%14 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -1,55 +1,110 @@
SKIP: FAILED ; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
[[builtin(pointsize), internal(disable_validation__ignore_storage_class)]] var<out> tint_pointsize : f32; ; Bound: 38
; Schema: 0
struct Out { OpCapability Shader
pos : vec4<f32>; OpCapability SampleRateShading
none : f32; OpMemoryModel Logical GLSL450
flat : f32; OpEntryPoint Vertex %main "main" %tint_pointsize %tint_symbol_1 %tint_symbol_2 %tint_symbol_3 %tint_symbol_4 %tint_symbol_5 %tint_symbol_6 %tint_symbol_7 %tint_symbol_8 %tint_symbol_9
perspective_center : f32; OpName %tint_pointsize "tint_pointsize"
perspective_centroid : f32; OpName %tint_symbol_1 "tint_symbol_1"
perspective_sample : f32; OpName %tint_symbol_2 "tint_symbol_2"
linear_center : f32; OpName %tint_symbol_3 "tint_symbol_3"
linear_centroid : f32; OpName %tint_symbol_4 "tint_symbol_4"
linear_sample : f32; OpName %tint_symbol_5 "tint_symbol_5"
}; OpName %tint_symbol_6 "tint_symbol_6"
OpName %tint_symbol_7 "tint_symbol_7"
[[builtin(position), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_1 : vec4<f32>; OpName %tint_symbol_8 "tint_symbol_8"
OpName %tint_symbol_9 "tint_symbol_9"
[[location(0), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_2 : f32; OpName %Out "Out"
OpMemberName %Out 0 "pos"
[[location(1), interpolate(flat), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_3 : f32; OpMemberName %Out 1 "none"
OpMemberName %Out 2 "flat"
[[location(2), interpolate(perspective, center), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_4 : f32; OpMemberName %Out 3 "perspective_center"
OpMemberName %Out 4 "perspective_centroid"
[[location(3), interpolate(perspective, centroid), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_5 : f32; OpMemberName %Out 5 "perspective_sample"
OpMemberName %Out 6 "linear_center"
[[location(4), interpolate(perspective, sample), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_6 : f32; OpMemberName %Out 7 "linear_centroid"
OpMemberName %Out 8 "linear_sample"
[[location(5), interpolate(linear, center), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_7 : f32; OpName %tint_symbol_10 "tint_symbol_10"
OpName %tint_symbol "tint_symbol"
[[location(6), interpolate(linear, centroid), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_8 : f32; OpName %main "main"
OpDecorate %tint_pointsize BuiltIn PointSize
[[location(7), interpolate(linear, sample), internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_9 : f32; OpDecorate %tint_symbol_1 BuiltIn Position
OpDecorate %tint_symbol_2 Location 0
fn tint_symbol_10(tint_symbol : Out) { OpDecorate %tint_symbol_3 Location 1
tint_symbol_1 = tint_symbol.pos; OpDecorate %tint_symbol_3 Flat
tint_symbol_2 = tint_symbol.none; OpDecorate %tint_symbol_4 Location 2
tint_symbol_3 = tint_symbol.flat; OpDecorate %tint_symbol_5 Location 3
tint_symbol_4 = tint_symbol.perspective_center; OpDecorate %tint_symbol_5 Centroid
tint_symbol_5 = tint_symbol.perspective_centroid; OpDecorate %tint_symbol_6 Location 4
tint_symbol_6 = tint_symbol.perspective_sample; OpDecorate %tint_symbol_6 Sample
tint_symbol_7 = tint_symbol.linear_center; OpDecorate %tint_symbol_7 Location 5
tint_symbol_8 = tint_symbol.linear_centroid; OpDecorate %tint_symbol_7 NoPerspective
tint_symbol_9 = tint_symbol.linear_sample; OpDecorate %tint_symbol_8 Location 6
} OpDecorate %tint_symbol_8 NoPerspective
OpDecorate %tint_symbol_8 Centroid
[[stage(vertex)]] OpDecorate %tint_symbol_9 Location 7
fn main() { OpDecorate %tint_symbol_9 NoPerspective
tint_pointsize = 1.0; OpDecorate %tint_symbol_9 Sample
tint_symbol_10(Out()); OpMemberDecorate %Out 0 Offset 0
return; OpMemberDecorate %Out 1 Offset 16
} OpMemberDecorate %Out 2 Offset 20
OpMemberDecorate %Out 3 Offset 24
Failed to generate: unknown decoration OpMemberDecorate %Out 4 Offset 28
OpMemberDecorate %Out 5 Offset 32
OpMemberDecorate %Out 6 Offset 36
OpMemberDecorate %Out 7 Offset 40
OpMemberDecorate %Out 8 Offset 44
%float = OpTypeFloat 32
%_ptr_Output_float = OpTypePointer Output %float
%4 = OpConstantNull %float
%tint_pointsize = OpVariable %_ptr_Output_float Output %4
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%8 = OpConstantNull %v4float
%tint_symbol_1 = OpVariable %_ptr_Output_v4float Output %8
%tint_symbol_2 = OpVariable %_ptr_Output_float Output %4
%tint_symbol_3 = OpVariable %_ptr_Output_float Output %4
%tint_symbol_4 = OpVariable %_ptr_Output_float Output %4
%tint_symbol_5 = OpVariable %_ptr_Output_float Output %4
%tint_symbol_6 = OpVariable %_ptr_Output_float Output %4
%tint_symbol_7 = OpVariable %_ptr_Output_float Output %4
%tint_symbol_8 = OpVariable %_ptr_Output_float Output %4
%tint_symbol_9 = OpVariable %_ptr_Output_float Output %4
%void = OpTypeVoid
%Out = OpTypeStruct %v4float %float %float %float %float %float %float %float %float
%17 = OpTypeFunction %void %Out
%32 = OpTypeFunction %void
%float_1 = OpConstant %float 1
%37 = OpConstantNull %Out
%tint_symbol_10 = OpFunction %void None %17
%tint_symbol = OpFunctionParameter %Out
%22 = OpLabel
%23 = OpCompositeExtract %v4float %tint_symbol 0
OpStore %tint_symbol_1 %23
%24 = OpCompositeExtract %float %tint_symbol 1
OpStore %tint_symbol_2 %24
%25 = OpCompositeExtract %float %tint_symbol 2
OpStore %tint_symbol_3 %25
%26 = OpCompositeExtract %float %tint_symbol 3
OpStore %tint_symbol_4 %26
%27 = OpCompositeExtract %float %tint_symbol 4
OpStore %tint_symbol_5 %27
%28 = OpCompositeExtract %float %tint_symbol 5
OpStore %tint_symbol_6 %28
%29 = OpCompositeExtract %float %tint_symbol 6
OpStore %tint_symbol_7 %29
%30 = OpCompositeExtract %float %tint_symbol 7
OpStore %tint_symbol_8 %30
%31 = OpCompositeExtract %float %tint_symbol 8
OpStore %tint_symbol_9 %31
OpReturn
OpFunctionEnd
%main = OpFunction %void None %32
%34 = OpLabel
OpStore %tint_pointsize %float_1
%36 = OpFunctionCall %void %tint_symbol_10 %37
OpReturn
OpFunctionEnd