Synthesize SPIR-V fake vars with private, user-inaccessible names.

If user code created global variables named `__device_FragCoords` or
`__device_Clockwise`, SPIR-V code generation would fail when trying
to synthesize fake variables with those names. Use private names
instead, beginning with `$device_` instead of `__device_`.

Change-Id: I167aaa6680426f9c5f0c7687b6c72500b246423f
Bug: skia:12855, oss-fuzz:43970
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/498116
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-01-22 15:59:32 -05:00 committed by SkCQ
parent 9f681e6df8
commit ac41603023

View File

@ -2113,10 +2113,10 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O
this->addRTFlipUniform(ref.fLine);
// Use sk_RTAdjust to compute the flipped coordinate
using namespace dsl;
const char* DEVICE_COORDS_NAME = "__device_FragCoords";
const char* DEVICE_COORDS_NAME = "$device_FragCoords";
SymbolTable& symbols = *ThreadContext::SymbolTable();
// Use a uniform to flip the Y coordinate. The new expression will be written in
// terms of __device_FragCoords, which is a fake variable that means "access the
// terms of $device_FragCoords, which is a fake variable that means "access the
// underlying fragcoords directly without flipping it".
DSLExpression rtFlip(ThreadContext::Compiler().convertIdentifier(/*line=*/-1,
SKSL_RTFLIP_NAME));
@ -2128,7 +2128,7 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O
fContext.fModifiersPool->add(modifiers),
DEVICE_COORDS_NAME,
fContext.fTypes.fFloat4.get(),
true,
/*builtin=*/true,
Variable::Storage::kGlobal);
fSPIRVBonusVariables.insert(coordsVar.get());
symbols.add(std::move(coordsVar));
@ -2148,10 +2148,10 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O
if (variable->modifiers().fLayout.fBuiltin == SK_CLOCKWISE_BUILTIN) {
this->addRTFlipUniform(ref.fLine);
using namespace dsl;
const char* DEVICE_CLOCKWISE_NAME = "__device_Clockwise";
const char* DEVICE_CLOCKWISE_NAME = "$device_Clockwise";
SymbolTable& symbols = *ThreadContext::SymbolTable();
// Use a uniform to flip the Y coordinate. The new expression will be written in
// terms of __device_Clockwise, which is a fake variable that means "access the
// terms of $device_Clockwise, which is a fake variable that means "access the
// underlying FrontFacing directly".
DSLExpression rtFlip(ThreadContext::Compiler().convertIdentifier(/*line=*/-1,
SKSL_RTFLIP_NAME));
@ -2163,7 +2163,7 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O
fContext.fModifiersPool->add(modifiers),
DEVICE_CLOCKWISE_NAME,
fContext.fTypes.fBool.get(),
true,
/*builtin=*/true,
Variable::Storage::kGlobal);
fSPIRVBonusVariables.insert(clockwiseVar.get());
symbols.add(std::move(clockwiseVar));