Skip to content

Commit

Permalink
SpirV: Added support for NonWritable decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonJoker committed Oct 13, 2024
1 parent 849f60a commit 67dcb92
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 10 deletions.
69 changes: 69 additions & 0 deletions source/CompilerSpirV/SpirVFillConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ See LICENSE file in root folder
#include <ShaderAST/Stmt/StmtVisitor.hpp>
#include <ShaderAST/Type/TypeCombinedImage.hpp>
#include <ShaderAST/Type/TypeImage.hpp>
#include <ShaderAST/Visitors/GetExprName.hpp>

#include <stdexcept>

Expand Down Expand Up @@ -222,6 +223,16 @@ namespace spirv
doSubmit( *expr->getRHS() );
}

void visitAssignmentExpr( ast::expr::Binary const * expr )override
{
visitBinaryExpr( expr );

if ( auto ident = ast::findIdentifier( *expr->getLHS() ) )
{
m_config.makeWritable( ident->getVariable() );
}
}

void visitAggrInitExpr( ast::expr::AggrInit const * expr )override
{
helpers::checkType( *expr, m_config );
Expand Down Expand Up @@ -320,6 +331,12 @@ namespace spirv
{
m_config.registerCapability( spv::CapabilityAtomicFloat32AddEXT );
}

if ( expr->getImageAccess() >= ast::expr::StorageImageAccess::eImageStore1DF
&& expr->getImageAccess() <= ast::expr::StorageImageAccess::eImageAtomicCompSwap2DMSArrayI )
{
m_config.makeWritable( ast::findIdentifier( *expr->getArgList()[0] )->getVariable() );
}
}

void visitIntrinsicCallExpr( ast::expr::IntrinsicCall const * expr )override
Expand All @@ -330,6 +347,15 @@ namespace spirv
{
doSubmit( *arg );
}

if ( expr->getIntrinsic() >= ast::expr::Intrinsic::eAtomicAddI
&& expr->getIntrinsic() <= ast::expr::Intrinsic::eAtomicCompSwapU )
{
if ( auto ident = ast::findIdentifier( *expr->getArgList()[0] ) )
{
m_config.makeWritable( ident->getVariable() );
}
}
}

void visitCombinedImageAccessCallExpr( ast::expr::CombinedImageAccessCall const * expr )override
Expand Down Expand Up @@ -435,6 +461,46 @@ namespace spirv
doSubmit( *expr->getOuterExpr() );
}

void visitPostDecrementExpr( ast::expr::PostDecrement const * expr )override
{
visitUnaryExpr( expr );

if ( auto ident = ast::findIdentifier( *expr ) )
{
m_config.makeWritable( ident->getVariable() );
}
}

void visitPostIncrementExpr( ast::expr::PostIncrement const * expr )override
{
visitUnaryExpr( expr );

if ( auto ident = ast::findIdentifier( *expr ) )
{
m_config.makeWritable( ident->getVariable() );
}
}

void visitPreDecrementExpr( ast::expr::PreDecrement const * expr )override
{
visitUnaryExpr( expr );

if ( auto ident = ast::findIdentifier( *expr ) )
{
m_config.makeWritable( ident->getVariable() );
}
}

void visitPreIncrementExpr( ast::expr::PreIncrement const * expr )override
{
visitUnaryExpr( expr );

if ( auto ident = ast::findIdentifier( *expr ) )
{
m_config.makeWritable( ident->getVariable() );
}
}

private:
ModuleConfig & m_config;
};
Expand Down Expand Up @@ -677,6 +743,7 @@ namespace spirv

void visitImageDeclStmt( ast::stmt::ImageDecl const * stmt )override
{
m_result.addStorage( stmt->getVariable() );
auto imgType = std::static_pointer_cast< ast::type::Image >( ast::type::getNonArrayType( stmt->getVariable()->getType() ) );

if ( imgType->getConfig().dimension == ast::type::ImageDim::e1D )
Expand Down Expand Up @@ -837,11 +904,13 @@ namespace spirv
void visitShaderBufferDeclStmt( ast::stmt::ShaderBufferDecl const * stmt )override
{
visitContainerStmt( stmt );
m_result.addStorage( stmt->getVariable() );
}

void visitShaderStructBufferDeclStmt( ast::stmt::ShaderStructBufferDecl const * stmt )override
{
doTraverseType( stmt->getSsboInstance()->getType() );
m_result.addStorage( stmt->getSsboInstance() );
}

void visitSimpleStmt( ast::stmt::Simple const * stmt )override
Expand Down
32 changes: 27 additions & 5 deletions source/CompilerSpirV/SpirVGenerateStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ namespace spirv
static DebugId submit( ast::expr::ExprCache & exprCache
, ast::expr::Expr const & expr
, PreprocContext const & context
, ModuleConfig const & moduleConfig
, Block & currentBlock
, Module & shaderModule
, glsl::Statement * currentDebugStatement )
Expand All @@ -377,6 +378,7 @@ namespace spirv
return submit( exprCache
, expr
, context
, moduleConfig
, currentBlock
, shaderModule
, allLiterals
Expand All @@ -386,6 +388,7 @@ namespace spirv
static DebugId submit( ast::expr::ExprCache & exprCache
, ast::expr::Expr const & expr
, PreprocContext const & context
, ModuleConfig const & moduleConfig
, Block & currentBlock
, Module & shaderModule
, DebugId initialiser
Expand All @@ -396,6 +399,7 @@ namespace spirv
return submit( exprCache
, expr
, context
, moduleConfig
, currentBlock
, shaderModule
, allLiterals
Expand All @@ -407,6 +411,7 @@ namespace spirv
static DebugId submit( ast::expr::ExprCache & exprCache
, ast::expr::Expr const & expr
, PreprocContext const & context
, ModuleConfig const & moduleConfig
, Block & currentBlock
, Module & shaderModule
, bool & allLiterals
Expand All @@ -416,6 +421,7 @@ namespace spirv
ExprVisitor vis{ result
, exprCache
, context
, moduleConfig
, currentBlock
, shaderModule
, allLiterals
Expand All @@ -433,6 +439,7 @@ namespace spirv
static DebugId submit( ast::expr::ExprCache & exprCache
, ast::expr::Expr const & expr
, PreprocContext const & context
, ModuleConfig const & moduleConfig
, Block & currentBlock
, Module & shaderModule
, bool & allLiterals
Expand All @@ -444,6 +451,7 @@ namespace spirv
ExprVisitor vis{ result
, exprCache
, context
, moduleConfig
, currentBlock
, shaderModule
, allLiterals
Expand All @@ -458,12 +466,14 @@ namespace spirv
ExprVisitor( DebugId & result
, ast::expr::ExprCache & exprCache
, PreprocContext const & context
, ModuleConfig const & moduleConfig
, Block & currentBlock
, Module & shaderModule
, bool & allLiterals
, glsl::Statement * currentDebugStatement )
: m_exprCache{ exprCache }
, m_context{ context }
, m_moduleConfig{ moduleConfig }
, m_typesCache{ shaderModule.getTypesCache() }
, m_currentDebugStatement{ currentDebugStatement }
, m_result{ result }
Expand All @@ -478,6 +488,7 @@ namespace spirv
ExprVisitor( DebugId & result
, ast::expr::ExprCache & exprCache
, PreprocContext const & context
, ModuleConfig const & moduleConfig
, Block & currentBlock
, Module & shaderModule
, bool & allLiterals
Expand All @@ -486,6 +497,7 @@ namespace spirv
, glsl::Statement * currentDebugStatement )
: m_exprCache{ exprCache }
, m_context{ context }
, m_moduleConfig{ moduleConfig }
, m_typesCache{ shaderModule.getTypesCache() }
, m_currentDebugStatement{ currentDebugStatement }
, m_result{ result }
Expand All @@ -500,20 +512,20 @@ namespace spirv

DebugId doSubmit( ast::expr::Expr const & expr )
{
return submit( m_exprCache, expr, m_context, m_currentBlock, m_module, m_currentDebugStatement );
return submit( m_exprCache, expr, m_context, m_moduleConfig, m_currentBlock, m_module, m_currentDebugStatement );
}

DebugId doSubmit( ast::expr::Expr const & expr
, DebugId initialiser
, bool hasFuncInit )
{
return submit( m_exprCache, expr, m_context, m_currentBlock, m_module, std::move( initialiser ), hasFuncInit, m_currentDebugStatement );
return submit( m_exprCache, expr, m_context, m_moduleConfig, m_currentBlock, m_module, std::move( initialiser ), hasFuncInit, m_currentDebugStatement );
}

DebugId doSubmit( ast::expr::Expr const & expr
, bool & allLiterals )
{
return submit( m_exprCache, expr, m_context, m_currentBlock, m_module, allLiterals, m_currentDebugStatement );
return submit( m_exprCache, expr, m_context, m_moduleConfig, m_currentBlock, m_module, allLiterals, m_currentDebugStatement );
}

glsl::RangeInfo getColumnData( ast::expr::Expr const & expr )const
Expand Down Expand Up @@ -916,6 +928,7 @@ namespace spirv
m_result = makeAccessChain( m_exprCache
, *expr
, m_context
, m_moduleConfig
, m_module
, m_currentBlock
, m_currentDebugStatement );
Expand All @@ -928,6 +941,7 @@ namespace spirv
m_result = makeAccessChain( m_exprCache
, *expr
, m_context
, m_moduleConfig
, m_module
, m_currentBlock
, m_currentDebugStatement );
Expand Down Expand Up @@ -1090,6 +1104,7 @@ namespace spirv
m_result = makeAccessChain( m_exprCache
, *expr
, m_context
, m_moduleConfig
, m_module
, m_currentBlock
, m_currentDebugStatement );
Expand Down Expand Up @@ -1383,6 +1398,7 @@ namespace spirv
m_result = loadVariable( makeAccessChain( m_exprCache
, *expr
, m_context
, m_moduleConfig
, m_module
, m_currentBlock
, m_currentDebugStatement )
Expand All @@ -1393,6 +1409,7 @@ namespace spirv
m_result = loadVariable( makeVectorShuffle( m_exprCache
, *expr
, m_context
, m_moduleConfig
, m_module
, m_currentBlock
, m_currentDebugStatement )
Expand Down Expand Up @@ -1480,6 +1497,7 @@ namespace spirv
m_result = submit( m_exprCache
, *expr->getAliasedExpr()
, m_context
, m_moduleConfig
, m_currentBlock
, m_module
, m_currentDebugStatement );
Expand Down Expand Up @@ -2129,6 +2147,7 @@ namespace spirv
private:
ast::expr::ExprCache & m_exprCache;
spirv::PreprocContext const & m_context;
ModuleConfig const & m_moduleConfig;
ast::type::TypesCache & m_typesCache;
glsl::Statement * m_currentDebugStatement;
DebugId & m_result;
Expand Down Expand Up @@ -2253,6 +2272,7 @@ namespace spirv
return ExprVisitor::submit( m_exprCache
, expr
, m_context
, m_moduleConfig
, block
, m_result
, getCurrentDebugStatement() );
Expand Down Expand Up @@ -3141,7 +3161,7 @@ namespace spirv
void visitSimpleStmt( ast::stmt::Simple const * stmt )override
{
TraceFunc;
ExprVisitor::submit( m_exprCache, *stmt->getExpr(), m_context, m_currentBlock, m_result, getCurrentDebugStatement() );
ExprVisitor::submit( m_exprCache, *stmt->getExpr(), m_context, m_moduleConfig, m_currentBlock, m_result, getCurrentDebugStatement() );

if ( stmt->getExpr()->getKind() != ast::expr::Kind::eAlias
&& stmt->getExpr()->getKind() != ast::expr::Kind::eIdentifier )
Expand Down Expand Up @@ -3386,7 +3406,7 @@ namespace spirv
, getCurrentDebugStatement() ).id;
}

decorateVar( *var, result, m_result );
decorateVar( var, result, m_moduleConfig, m_result );
return result;
}

Expand Down Expand Up @@ -3474,13 +3494,15 @@ namespace spirv

DebugId generateModuleExpr( ast::expr::ExprCache & exprCache
, ast::expr::Expr const & expr
, ModuleConfig const & moduleConfig
, PreprocContext const & context
, Block & currentBlock
, Module & shaderModule )
{
return vis::ExprVisitor::submit( exprCache
, expr
, context
, moduleConfig
, currentBlock
, shaderModule
, nullptr );
Expand Down
1 change: 1 addition & 0 deletions source/CompilerSpirV/SpirVGenerateStatements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace spirv
, glsl::Statements debugStatements );
DebugId generateModuleExpr( ast::expr::ExprCache & exprCache
, ast::expr::Expr const & expr
, ModuleConfig const & moduleConfig
, PreprocContext const & context
, Block & currentBlock
, Module & shaderModule );
Expand Down
Loading

0 comments on commit 67dcb92

Please sign in to comment.