Commit 64ca25f1 by Shahbaz Youssefi Committed by Angle LUCI CQ

Vulkan: SPIR-V Gen: Unary operators

The line raster emulation coded uses round() which was previously not translated. This change implements all operations supported by TIntermUnary nodes. Bresenham line emulation is now allowed. Bug: angleproject:4889 Change-Id: I1ffbe3f9bf0299f7efa2c6d1e8f011fefdbb2ddb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2951624 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 0297779c
...@@ -57,6 +57,18 @@ spirv::IdRef SPIRVBuilder::getNewId(const SpirvDecorations &decorations) ...@@ -57,6 +57,18 @@ spirv::IdRef SPIRVBuilder::getNewId(const SpirvDecorations &decorations)
return newId; return newId;
} }
TLayoutBlockStorage SPIRVBuilder::getBlockStorage(const TType &type) const
{
// Default to std140.
TLayoutBlockStorage blockStorage = type.getLayoutQualifier().blockStorage;
if (!IsShaderIoBlock(type.getQualifier()) && blockStorage != EbsStd430)
{
blockStorage = EbsStd140;
}
return blockStorage;
}
SpirvType SPIRVBuilder::getSpirvType(const TType &type, TLayoutBlockStorage blockStorage) const SpirvType SPIRVBuilder::getSpirvType(const TType &type, TLayoutBlockStorage blockStorage) const
{ {
SpirvType spirvType; SpirvType spirvType;
...@@ -84,14 +96,10 @@ SpirvType SPIRVBuilder::getSpirvType(const TType &type, TLayoutBlockStorage bloc ...@@ -84,14 +96,10 @@ SpirvType SPIRVBuilder::getSpirvType(const TType &type, TLayoutBlockStorage bloc
spirvType.block = type.getInterfaceBlock(); spirvType.block = type.getInterfaceBlock();
// Calculate the block storage from the interface block automatically. The fields inherit // Calculate the block storage from the interface block automatically. The fields inherit
// from this. Default to std140. // from this.
if (spirvType.blockStorage == EbsUnspecified) if (spirvType.blockStorage == EbsUnspecified)
{ {
spirvType.blockStorage = type.getLayoutQualifier().blockStorage; spirvType.blockStorage = getBlockStorage(type);
if (!IsShaderIoBlock(type.getQualifier()) && spirvType.blockStorage != EbsStd430)
{
spirvType.blockStorage = EbsStd140;
}
} }
} }
else if (spirvType.arraySizes.empty()) else if (spirvType.arraySizes.empty())
...@@ -188,6 +196,15 @@ SpirvDecorations SPIRVBuilder::getDecorations(const TType &type) ...@@ -188,6 +196,15 @@ SpirvDecorations SPIRVBuilder::getDecorations(const TType &type)
return decorations; return decorations;
} }
spirv::IdRef SPIRVBuilder::getExtInstImportIdStd()
{
if (!mExtInstImportIdStd.valid())
{
mExtInstImportIdStd = getNewId({});
}
return mExtInstImportIdStd;
}
SpirvTypeData SPIRVBuilder::declareType(const SpirvType &type, const char *blockName) SpirvTypeData SPIRVBuilder::declareType(const SpirvType &type, const char *blockName)
{ {
// Recursively declare the type. Type id is allocated afterwards purely for better id order in // Recursively declare the type. Type id is allocated afterwards purely for better id order in
...@@ -1409,9 +1426,6 @@ spirv::Blob SPIRVBuilder::getSpirv() ...@@ -1409,9 +1426,6 @@ spirv::Blob SPIRVBuilder::getSpirv()
mSpirvFunctionTypeDecls.size() + mSpirvVariableDecls.size() + mSpirvFunctionTypeDecls.size() + mSpirvVariableDecls.size() +
mSpirvFunctions.size()); mSpirvFunctions.size());
// Generate any necessary id before writing the id bound in header.
const spirv::IdRef extInstImportId = getNewId({});
// Generate the SPIR-V header. // Generate the SPIR-V header.
spirv::WriteSpirvHeader(&result, mNextAvailableId); spirv::WriteSpirvHeader(&result, mNextAvailableId);
...@@ -1427,7 +1441,10 @@ spirv::Blob SPIRVBuilder::getSpirv() ...@@ -1427,7 +1441,10 @@ spirv::Blob SPIRVBuilder::getSpirv()
// - OpExtension instructions (TODO: http://anglebug.com/4889) // - OpExtension instructions (TODO: http://anglebug.com/4889)
// - OpExtInstImport // - OpExtInstImport
spirv::WriteExtInstImport(&result, extInstImportId, "GLSL.std.450"); if (mExtInstImportIdStd.valid())
{
spirv::WriteExtInstImport(&result, mExtInstImportIdStd, "GLSL.std.450");
}
// - OpMemoryModel // - OpMemoryModel
spirv::WriteMemoryModel(&result, spv::AddressingModelLogical, spv::MemoryModelGLSL450); spirv::WriteMemoryModel(&result, spv::AddressingModelLogical, spv::MemoryModelGLSL450);
......
...@@ -253,6 +253,7 @@ class SPIRVBuilder : angle::NonCopyable ...@@ -253,6 +253,7 @@ class SPIRVBuilder : angle::NonCopyable
{} {}
spirv::IdRef getNewId(const SpirvDecorations &decorations); spirv::IdRef getNewId(const SpirvDecorations &decorations);
TLayoutBlockStorage getBlockStorage(const TType &type) const;
SpirvType getSpirvType(const TType &type, TLayoutBlockStorage blockStorage) const; SpirvType getSpirvType(const TType &type, TLayoutBlockStorage blockStorage) const;
const SpirvTypeData &getTypeData(const TType &type, TLayoutBlockStorage blockStorage); const SpirvTypeData &getTypeData(const TType &type, TLayoutBlockStorage blockStorage);
const SpirvTypeData &getSpirvTypeData(const SpirvType &type, const char *blockName); const SpirvTypeData &getSpirvTypeData(const SpirvType &type, const char *blockName);
...@@ -262,6 +263,9 @@ class SPIRVBuilder : angle::NonCopyable ...@@ -262,6 +263,9 @@ class SPIRVBuilder : angle::NonCopyable
// Decorations that may apply to intermediate instructions (in addition to variables). // Decorations that may apply to intermediate instructions (in addition to variables).
SpirvDecorations getDecorations(const TType &type); SpirvDecorations getDecorations(const TType &type);
// Extended instructions
spirv::IdRef getExtInstImportIdStd();
spirv::Blob *getSpirvDebug() { return &mSpirvDebug; } spirv::Blob *getSpirvDebug() { return &mSpirvDebug; }
spirv::Blob *getSpirvDecorations() { return &mSpirvDecorations; } spirv::Blob *getSpirvDecorations() { return &mSpirvDecorations; }
spirv::Blob *getSpirvTypeAndConstantDecls() { return &mSpirvTypeAndConstantDecls; } spirv::Blob *getSpirvTypeAndConstantDecls() { return &mSpirvTypeAndConstantDecls; }
...@@ -375,6 +379,9 @@ class SPIRVBuilder : angle::NonCopyable ...@@ -375,6 +379,9 @@ class SPIRVBuilder : angle::NonCopyable
spirv::IdRefList mEntryPointInterfaceList; spirv::IdRefList mEntryPointInterfaceList;
spirv::IdRef mEntryPointId; spirv::IdRef mEntryPointId;
// Id of imported instructions, if used.
spirv::IdRef mExtInstImportIdStd;
// Current ID bound, used to allocate new ids. // Current ID bound, used to allocate new ids.
spirv::IdRef mNextAvailableId; spirv::IdRef mNextAvailableId;
......
...@@ -239,7 +239,7 @@ ANGLE_NO_DISCARD bool RotateAndFlipBuiltinVariable(TCompiler *compiler, ...@@ -239,7 +239,7 @@ ANGLE_NO_DISCARD bool RotateAndFlipBuiltinVariable(TCompiler *compiler,
sequence.push_back(builtinRef->deepCopy()); sequence.push_back(builtinRef->deepCopy());
TIntermAggregate *aggregate = TIntermAggregate *aggregate =
TIntermAggregate::CreateConstructor(builtin->getType(), &sequence); TIntermAggregate::CreateConstructor(builtin->getType(), &sequence);
TIntermBinary *assignment = new TIntermBinary(EOpInitialize, flippedBuiltinRef, aggregate); TIntermBinary *assignment = new TIntermBinary(EOpAssign, flippedBuiltinRef, aggregate);
// Create an assignment to the replaced variable's .xy. // Create an assignment to the replaced variable's .xy.
TIntermSwizzle *correctedXY = TIntermSwizzle *correctedXY =
...@@ -1300,7 +1300,7 @@ bool TranslatorVulkan::translate(TIntermBlock *root, ...@@ -1300,7 +1300,7 @@ bool TranslatorVulkan::translate(TIntermBlock *root,
} }
#if defined(ANGLE_ENABLE_DIRECT_SPIRV_GENERATION) #if defined(ANGLE_ENABLE_DIRECT_SPIRV_GENERATION)
constexpr ShCompileOptions kUnsupportedTransformations = SH_ADD_BRESENHAM_LINE_RASTER_EMULATION; constexpr ShCompileOptions kUnsupportedTransformations = SH_CLAMP_POINT_SIZE;
if ((compileOptions & SH_GENERATE_SPIRV_DIRECTLY) != 0 && if ((compileOptions & SH_GENERATE_SPIRV_DIRECTLY) != 0 &&
((getShaderType() == GL_VERTEX_SHADER && ((getShaderType() == GL_VERTEX_SHADER &&
(compileOptions & kUnsupportedTransformations) == 0) || (compileOptions & kUnsupportedTransformations) == 0) ||
......
...@@ -354,7 +354,7 @@ void ValidateAST::visitSymbol(TIntermSymbol *node) ...@@ -354,7 +354,7 @@ void ValidateAST::visitSymbol(TIntermSymbol *node)
if (mNamelessInterfaceBlocks.count(interfaceBlock) == 0) if (mNamelessInterfaceBlocks.count(interfaceBlock) == 0)
{ {
mDiagnostics->error(node->getLine(), mDiagnostics->error(node->getLine(),
"Found reference to undeclared or inconsistenly redeclared " "Found reference to undeclared or inconsistenly transformed "
"nameless interface block <validateVariableReferences>", "nameless interface block <validateVariableReferences>",
node->getName().data()); node->getName().data());
mVariableReferencesFailed = true; mVariableReferencesFailed = true;
...@@ -363,7 +363,7 @@ void ValidateAST::visitSymbol(TIntermSymbol *node) ...@@ -363,7 +363,7 @@ void ValidateAST::visitSymbol(TIntermSymbol *node)
node->getName() != fieldList[fieldIndex]->name()) node->getName() != fieldList[fieldIndex]->name())
{ {
mDiagnostics->error(node->getLine(), mDiagnostics->error(node->getLine(),
"Found reference to inconsistenly redeclared nameless " "Found reference to inconsistenly transformed nameless "
"interface block field <validateVariableReferences>", "interface block field <validateVariableReferences>",
node->getName().data()); node->getName().data());
mVariableReferencesFailed = true; mVariableReferencesFailed = true;
...@@ -377,7 +377,7 @@ void ValidateAST::visitSymbol(TIntermSymbol *node) ...@@ -377,7 +377,7 @@ void ValidateAST::visitSymbol(TIntermSymbol *node)
if (!isStructDeclaration && !isVariableDeclared(variable)) if (!isStructDeclaration && !isVariableDeclared(variable))
{ {
mDiagnostics->error(node->getLine(), mDiagnostics->error(node->getLine(),
"Found reference to undeclared or inconsistently redeclared " "Found reference to undeclared or inconsistently transformed "
"variable <validateVariableReferences>", "variable <validateVariableReferences>",
node->getName().data()); node->getName().data());
mVariableReferencesFailed = true; mVariableReferencesFailed = true;
...@@ -496,7 +496,7 @@ bool ValidateAST::visitGlobalQualifierDeclaration(Visit visit, ...@@ -496,7 +496,7 @@ bool ValidateAST::visitGlobalQualifierDeclaration(Visit visit,
if (!isVariableDeclared(variable)) if (!isVariableDeclared(variable))
{ {
mDiagnostics->error(node->getLine(), mDiagnostics->error(node->getLine(),
"Found reference to undeclared or inconsistently redeclared " "Found reference to undeclared or inconsistently transformed "
"variable <validateVariableReferences>", "variable <validateVariableReferences>",
variable->name().data()); variable->name().data());
mVariableReferencesFailed = true; mVariableReferencesFailed = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment