mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 07:06:11 +00:00
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:
committed by
Tint LUCI CQ
parent
230295dea4
commit
5ea0fe00bf
@@ -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)});
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user