mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 06:45:16 +00:00
GLSL: add location layout qualifier before in/out variables.
Bug: tint:1398 Change-Id: I89c985d01d539ed166661ee5e858247cde4702b3 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/78080 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
committed by
Tint LUCI CQ
parent
fc792989e1
commit
8e01c45e54
@@ -1877,6 +1877,25 @@ std::string GeneratorImpl::interpolation_to_modifiers(
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitDecorations(std::ostream& out,
|
||||
const ast::DecorationList& decorations) {
|
||||
if (decorations.empty()) {
|
||||
return true;
|
||||
}
|
||||
bool first = true;
|
||||
for (auto* deco : decorations) {
|
||||
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||
out << (first ? "layout(" : ", ");
|
||||
out << "location = " << std::to_string(location->value);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
if (!first) {
|
||||
out << ") ";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
|
||||
auto* func_sem = builder_.Sem().Get(func);
|
||||
|
||||
@@ -1962,10 +1981,13 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
|
||||
auto* sem = builder_.Sem().Get(var);
|
||||
auto* str = sem->Type()->As<sem::Struct>();
|
||||
for (auto* member : str->Members()) {
|
||||
if (ast::HasDecoration<ast::BuiltinDecoration>(
|
||||
member->Declaration()->decorations)) {
|
||||
auto decorations = member->Declaration()->decorations;
|
||||
if (ast::HasDecoration<ast::BuiltinDecoration>(decorations)) {
|
||||
continue;
|
||||
}
|
||||
if (!EmitDecorations(out, decorations)) {
|
||||
return false;
|
||||
}
|
||||
if (!EmitTypeAndName(
|
||||
out, member->Type(), ast::StorageClass::kInput,
|
||||
ast::Access::kReadWrite,
|
||||
@@ -1980,10 +2002,13 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
|
||||
auto* return_type = func_sem->ReturnType()->As<sem::Struct>();
|
||||
if (return_type) {
|
||||
for (auto* member : return_type->Members()) {
|
||||
if (ast::HasDecoration<ast::BuiltinDecoration>(
|
||||
member->Declaration()->decorations)) {
|
||||
auto decorations = member->Declaration()->decorations;
|
||||
if (ast::HasDecoration<ast::BuiltinDecoration>(decorations)) {
|
||||
continue;
|
||||
}
|
||||
if (!EmitDecorations(out, decorations)) {
|
||||
return false;
|
||||
}
|
||||
if (!EmitTypeAndName(
|
||||
out, member->Type(), ast::StorageClass::kOutput,
|
||||
ast::Access::kReadWrite,
|
||||
|
||||
@@ -292,6 +292,11 @@ class GeneratorImpl : public TextGenerator {
|
||||
/// @returns true on success
|
||||
bool EmitWorkgroupVariable(const sem::Variable* var);
|
||||
|
||||
/// Handles emitting decorations
|
||||
/// @param out the output of the expression stream
|
||||
/// @param decos the decorations
|
||||
/// @returns true if the decorations were emitted
|
||||
bool EmitDecorations(std::ostream& out, const ast::DecorationList& decos);
|
||||
/// Handles emitting the entry point function
|
||||
/// @param func the entry point
|
||||
/// @returns true if the entry point function was emitted
|
||||
@@ -316,7 +321,7 @@ class GeneratorImpl : public TextGenerator {
|
||||
/// Handles generating an identifier expression
|
||||
/// @param out the output of the expression stream
|
||||
/// @param expr the identifier expression
|
||||
/// @returns true if the identifeir was emitted
|
||||
/// @returns true if the identifier was emitted
|
||||
bool EmitIdentifier(std::ostream& out, const ast::IdentifierExpression* expr);
|
||||
/// Handles a member accessor expression
|
||||
/// @param out the output of the expression stream
|
||||
|
||||
@@ -157,8 +157,8 @@ tint_symbol_2 frag_main(tint_symbol_1 tint_symbol) {
|
||||
wrapper_result.value = inner_result;
|
||||
return wrapper_result;
|
||||
}
|
||||
in float foo;
|
||||
out float value;
|
||||
layout(location = 0) in float foo;
|
||||
layout(location = 1) out float value;
|
||||
void main() {
|
||||
tint_symbol_1 inputs;
|
||||
inputs.foo = foo;
|
||||
@@ -284,8 +284,8 @@ tint_symbol vert_main() {
|
||||
wrapper_result.col2 = inner_result.col2;
|
||||
return wrapper_result;
|
||||
}
|
||||
out float col1;
|
||||
out float col2;
|
||||
layout(location = 1) out float col1;
|
||||
layout(location = 2) out float col2;
|
||||
void main() {
|
||||
tint_symbol outputs;
|
||||
outputs = vert_main();
|
||||
@@ -314,8 +314,8 @@ void frag_main(tint_symbol_2 tint_symbol_1) {
|
||||
frag_main_inner(tint_symbol_4);
|
||||
return;
|
||||
}
|
||||
in float col1;
|
||||
in float col2;
|
||||
layout(location = 1) in float col1;
|
||||
layout(location = 2) in float col2;
|
||||
void main() {
|
||||
tint_symbol_2 inputs;
|
||||
inputs.col1 = col1;
|
||||
|
||||
Reference in New Issue
Block a user