mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
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:
@@ -842,6 +842,8 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
||||
push_annot(spv::Op::OpDecorate,
|
||||
{Operand::Int(var_id), Operand::Int(SpvDecorationLocation),
|
||||
Operand::Int(location->value())});
|
||||
} else if (auto* interpolate = deco->As<ast::InterpolateDecoration>()) {
|
||||
AddInterpolationDecorations(var_id, interpolate);
|
||||
} else if (auto* binding = deco->As<ast::BindingDecoration>()) {
|
||||
push_annot(spv::Op::OpDecorate,
|
||||
{Operand::Int(var_id), Operand::Int(SpvDecorationBinding),
|
||||
@@ -3986,6 +3988,37 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::Builtin builtin,
|
||||
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(
|
||||
const ast::ImageFormat format) {
|
||||
switch (format) {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "src/ast/continue_statement.h"
|
||||
#include "src/ast/discard_statement.h"
|
||||
#include "src/ast/if_statement.h"
|
||||
#include "src/ast/interpolate_decoration.h"
|
||||
#include "src/ast/loop_statement.h"
|
||||
#include "src/ast/return_statement.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
@@ -208,6 +209,13 @@ class Builder {
|
||||
/// @returns the SPIR-V builtin or SpvBuiltInMax on error.
|
||||
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
|
||||
/// we're currently outside a function.
|
||||
/// @param id the id to use for the label
|
||||
|
||||
Reference in New Issue
Block a user