GLSL: fix Position built-in variable.
Position maps to gl_Position in vertex shaders, and gl_FragCoord in fragment shaders. Bug: tint:1296 Change-Id: I22069af2c82bb03521f2721d16c29ba98c85f3f2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69280 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:
parent
4cfa725fb3
commit
e1761d5852
|
@ -1758,10 +1758,20 @@ sem::Type* GeneratorImpl::builtin_type(ast::Builtin builtin) {
|
|||
}
|
||||
}
|
||||
|
||||
const char* GeneratorImpl::builtin_to_string(ast::Builtin builtin) const {
|
||||
const char* GeneratorImpl::builtin_to_string(ast::Builtin builtin,
|
||||
ast::PipelineStage stage) {
|
||||
switch (builtin) {
|
||||
case ast::Builtin::kPosition:
|
||||
return "gl_Position";
|
||||
switch (stage) {
|
||||
case ast::PipelineStage::kVertex:
|
||||
return "gl_Position";
|
||||
case ast::PipelineStage::kFragment:
|
||||
return "gl_FragCoord";
|
||||
default:
|
||||
TINT_ICE(Writer, builder_.Diagnostics())
|
||||
<< "position builtin unexpected in this pipeline stage";
|
||||
return "";
|
||||
}
|
||||
case ast::Builtin::kVertexIndex:
|
||||
return "gl_VertexID";
|
||||
case ast::Builtin::kInstanceIndex:
|
||||
|
@ -1959,10 +1969,10 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
|
|||
return false;
|
||||
}
|
||||
out << "(";
|
||||
out << builtin_to_string(builtin->builtin);
|
||||
out << builtin_to_string(builtin->builtin, func->PipelineStage());
|
||||
out << ")";
|
||||
} else {
|
||||
out << builtin_to_string(builtin->builtin);
|
||||
out << builtin_to_string(builtin->builtin, func->PipelineStage());
|
||||
}
|
||||
} else {
|
||||
out << name;
|
||||
|
@ -1992,7 +2002,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
|
|||
out << " ";
|
||||
if (auto* builtin = ast::GetDecoration<ast::BuiltinDecoration>(
|
||||
member->Declaration()->decorations)) {
|
||||
out << builtin_to_string(builtin->builtin);
|
||||
out << builtin_to_string(builtin->builtin, func->PipelineStage());
|
||||
} else {
|
||||
out << name;
|
||||
}
|
||||
|
|
|
@ -347,8 +347,9 @@ class GeneratorImpl : public TextGenerator {
|
|||
std::string generate_builtin_name(const sem::Intrinsic* intrinsic);
|
||||
/// Converts a builtin to a gl_ string
|
||||
/// @param builtin the builtin to convert
|
||||
/// @param stage pipeline stage in which this builtin is used
|
||||
/// @returns the string name of the builtin or blank on error
|
||||
const char* builtin_to_string(ast::Builtin builtin) const;
|
||||
const char* builtin_to_string(ast::Builtin builtin, ast::PipelineStage stage);
|
||||
/// Converts a builtin to a sem::Type appropriate for GLSL.
|
||||
/// @param builtin the builtin to convert
|
||||
/// @returns the appropriate semantic type or null on error.
|
||||
|
|
|
@ -208,7 +208,7 @@ tint_symbol_2 frag_main(tint_symbol_1 tint_symbol) {
|
|||
}
|
||||
void main() {
|
||||
tint_symbol_1 inputs;
|
||||
inputs.coord = gl_Position;
|
||||
inputs.coord = gl_FragCoord;
|
||||
tint_symbol_2 outputs;
|
||||
outputs = frag_main(inputs);
|
||||
gl_FragDepth = outputs.value;
|
||||
|
@ -320,7 +320,7 @@ void main() {
|
|||
tint_symbol_2 inputs;
|
||||
inputs.col1 = col1;
|
||||
inputs.col2 = col2;
|
||||
inputs.pos = gl_Position;
|
||||
inputs.pos = gl_FragCoord;
|
||||
frag_main(inputs);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ TEST_P(GlslBuiltinConversionTest, Emit) {
|
|||
auto params = GetParam();
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
EXPECT_EQ(gen.builtin_to_string(params.builtin),
|
||||
EXPECT_EQ(gen.builtin_to_string(params.builtin, ast::PipelineStage::kVertex),
|
||||
std::string(params.attribute_name));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
|
Loading…
Reference in New Issue