Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
e577c14
Add CLI argument to specify additional include directories for the sh…
filipppavlov Sep 22, 2026
6d8ff08
Add some shader includes
filipppavlov Sep 22, 2026
8e81884
Capitalize filenames
filipppavlov Sep 23, 2026
9065129
Populating shaders; dummy cmake project for shaders
filipppavlov Sep 24, 2026
e93c2e3
Add support for TextureCube.GetDimensions override for Metal
filipppavlov Oct 2, 2026
78c6d4a
More shaders
filipppavlov Oct 2, 2026
ce978c5
Rename carbon shader include directory
filipppavlov Oct 2, 2026
4be94b0
Update path
filipppavlov Oct 2, 2026
fc6ec1c
More shaders
filipppavlov Oct 2, 2026
9f20d8f
Booster shader headers
filipppavlov Oct 5, 2026
efe911b
Decal header
filipppavlov Oct 5, 2026
819d204
More shader includes
filipppavlov Oct 5, 2026
b1eff77
Lensflare shaders
filipppavlov Oct 6, 2026
fcb6cd1
More shaders
filipppavlov Oct 6, 2026
680489e
GPU particle shaders
filipppavlov Oct 7, 2026
cf4c6e8
More shaders
filipppavlov Oct 7, 2026
95affb1
Fog shaders
filipppavlov Oct 7, 2026
7378593
Cloud shaders
filipppavlov Oct 7, 2026
f17f853
More vfx shaders
filipppavlov Oct 7, 2026
2c5f030
Raytracing helpers
filipppavlov Oct 8, 2026
eb95f65
Fixed a crash in the shader compiler when failing to compile a RT shader
filipppavlov Oct 8, 2026
cd03887
Raytracing header
filipppavlov Oct 8, 2026
b101215
SkinVertices shader
filipppavlov Oct 8, 2026
024c834
System shaders
filipppavlov Oct 8, 2026
5379f20
Fix "static const" variables getting into the "globals" constant buff…
filipppavlov Oct 8, 2026
efd3f50
Turret data
filipppavlov Oct 8, 2026
0a494a0
Add attribution
filipppavlov Oct 9, 2026
db0a655
EveSpherePin header
filipppavlov Oct 9, 2026
162f153
Morph target helpers
filipppavlov Oct 9, 2026
3b6c4a3
Utility shaders
filipppavlov Oct 9, 2026
0218243
UI shader include
filipppavlov Oct 9, 2026
218fb5e
Utility shaders
filipppavlov Oct 9, 2026
569e9f8
Interior includes
filipppavlov Oct 9, 2026
dd15d4f
Moved shaders into src directory
filipppavlov Oct 9, 2026
4f0c05f
Sparate CMakeLists.txt for shaders
filipppavlov Oct 9, 2026
faa72ee
Fix the build and address some PR comments
filipppavlov Oct 12, 2026
f47af71
Formatting
filipppavlov Oct 12, 2026
6f4c172
Move "src" files back up the directory so that local includes are sti…
filipppavlov Oct 12, 2026
55f4824
Update shader paths
filipppavlov Oct 12, 2026
ce8de02
Address PR comments
filipppavlov Oct 13, 2026
1c8aa77
Add CLI argument to specify additional include directories for the sh…
filipppavlov Sep 22, 2026
89abc92
Add some shader includes
filipppavlov Sep 22, 2026
627f6db
Capitalize filenames
filipppavlov Sep 23, 2026
141b46a
Populating shaders; dummy cmake project for shaders
filipppavlov Sep 24, 2026
6e17b0b
Add support for TextureCube.GetDimensions override for Metal
filipppavlov Oct 2, 2026
4dd5e0e
More shaders
filipppavlov Oct 2, 2026
feb9848
Rename carbon shader include directory
filipppavlov Oct 2, 2026
87cdc0c
Update path
filipppavlov Oct 2, 2026
c6b2e30
More shaders
filipppavlov Oct 2, 2026
1820eb0
Booster shader headers
filipppavlov Oct 5, 2026
4716dfa
Decal header
filipppavlov Oct 5, 2026
dddee0c
More shader includes
filipppavlov Oct 5, 2026
8a231fc
Lensflare shaders
filipppavlov Oct 6, 2026
27bc248
More shaders
filipppavlov Oct 6, 2026
ae9484d
GPU particle shaders
filipppavlov Oct 7, 2026
a5d32f3
More shaders
filipppavlov Oct 7, 2026
19e825a
Fog shaders
filipppavlov Oct 7, 2026
2e98a8c
Cloud shaders
filipppavlov Oct 7, 2026
46059f1
More vfx shaders
filipppavlov Oct 7, 2026
9a97bd4
Raytracing helpers
filipppavlov Oct 8, 2026
53d432a
Fixed a crash in the shader compiler when failing to compile a RT shader
filipppavlov Oct 8, 2026
4992972
Raytracing header
filipppavlov Oct 8, 2026
186a4e8
SkinVertices shader
filipppavlov Oct 8, 2026
6b6cb0f
System shaders
filipppavlov Oct 8, 2026
fee1f86
Fix "static const" variables getting into the "globals" constant buff…
filipppavlov Oct 8, 2026
bf3358d
Turret data
filipppavlov Oct 8, 2026
5c2ebff
Add attribution
filipppavlov Oct 9, 2026
abf32ef
EveSpherePin header
filipppavlov Oct 9, 2026
f56b582
Morph target helpers
filipppavlov Oct 9, 2026
97e7441
Utility shaders
filipppavlov Oct 9, 2026
a14c591
UI shader include
filipppavlov Oct 9, 2026
4a31f41
Utility shaders
filipppavlov Oct 9, 2026
87a5165
Interior includes
filipppavlov Oct 9, 2026
6a14aa8
Moved shaders into src directory
filipppavlov Oct 9, 2026
3e04b30
Sparate CMakeLists.txt for shaders
filipppavlov Oct 9, 2026
0471a41
Fix the build and address some PR comments
filipppavlov Oct 12, 2026
1367e6b
Formatting
filipppavlov Oct 12, 2026
e60df2d
Move "src" files back up the directory so that local includes are sti…
filipppavlov Oct 12, 2026
635bfbc
Update shader paths
filipppavlov Oct 12, 2026
77ee004
Address PR comments
filipppavlov Oct 13, 2026
13b77ea
Merge branch 'shader-source' of https://github.com/carbonengine/trini…
filipppavlov Oct 13, 2026
5129962
Emit an error if the compiler cannot deduce a texture from the sample…
filipppavlov Oct 13, 2026
71cc9d2
Absorb new changes to shaders: picking and fog
filipppavlov Oct 15, 2026
f6deb2f
Remove unused defines
filipppavlov Oct 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ endif ()

add_subdirectory(trinityal)
add_subdirectory(trinity)
add_subdirectory(shaders)

if(CMAKE_PROJECT_NAME STREQUAL carbon-trinity AND NOT BUILD_FOR_PYTHON_2)
# Determine if/when to generate/build documentation. The rules are as follows:
Expand Down Expand Up @@ -139,3 +140,4 @@ if(CMAKE_PROJECT_NAME STREQUAL carbon-trinity AND NOT BUILD_FOR_PYTHON_2)
)
endif()
endif()

83 changes: 67 additions & 16 deletions shadercompiler/CachingIncludeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ std::optional<std::string> JoinPath( const char* path1, const char* path2 )
#endif
}

std::optional<std::string> JoinPathAndCheckExists( const char* path1, const char* path2 )
{
if( auto joined = JoinPath( path1, path2 ) )
{
#if _WIN32
if( PathFileExists( joined->c_str() ) )
{
return joined;
}
#else
struct stat buffer;
if( stat( joined->c_str(), &buffer ) == 0 )
{
return joined;
}
#endif
}
return std::nullopt;
}

}


Expand All @@ -85,37 +105,62 @@ CachingIncludeHandler::~CachingIncludeHandler()
// used for resolving relative paths
// rootPath - Custom root path for resolving relative paths
// --------------------------------------------------------------------------------------
std::optional<CachingIncludeHandler::IncludedFile> CachingIncludeHandler::Open( const char* fileName, const char* parentData, const char* rootPath )
std::optional<CachingIncludeHandler::IncludedFile> CachingIncludeHandler::Open( const char* fileName, IncludeType includeType, const char* parentData, const char* rootPath )
{
std::lock_guard scope( m_cs );

std::string fullPath;
if( PathIsRelative( fileName ) )
{
std::string parentPath;
if( parentData == nullptr )
{
parentPath = rootPath ? rootPath : m_rootPath;
}
else
{
auto parent = m_pathFromFile.find( parentData - 1 );
if( parent != m_pathFromFile.end() )
auto FindLocalPath = [&]() -> bool {
std::string parentPath;
if( parentData == nullptr )
{
parentPath = parent->second;
parentPath = rootPath ? rootPath : m_rootPath;
}
else
{
parentPath = "";
auto parent = m_pathFromFile.find( parentData - 1 );
if( parent != m_pathFromFile.end() )
{
parentPath = parent->second;
}
else
{
parentPath = "";
}
}
}
if( auto joined = JoinPath( parentPath.c_str(), fileName ) )
if( auto joined = JoinPathAndCheckExists( parentPath.c_str(), fileName ) )
{
fullPath = *joined;
return true;
}
return false;
};
auto FindSystemPath = [&]() -> bool {
for( auto it = m_systemIncludePaths.begin(); it != m_systemIncludePaths.end(); ++it )
{
if( auto joined = JoinPathAndCheckExists( it->c_str(), fileName ) )
{
fullPath = *joined;
return true;
}
}
return false;
};
if( includeType == IncludeLocal )
{
fullPath = *joined;
if( !FindLocalPath() && !FindSystemPath() )
{
return std::nullopt;
}
}
else
{
return std::nullopt;
if( !FindSystemPath() && !FindLocalPath() )
{
return std::nullopt;
}
}
}
else
Expand Down Expand Up @@ -221,6 +266,12 @@ std::optional<CachingIncludeHandler::IncludedFile> CachingIncludeHandler::AddPre
return info;
}

void CachingIncludeHandler::AddSystemIncludePath( const char* path )
{
std::lock_guard scope( m_cs );
m_systemIncludePaths.push_back( path );
}

// --------------------------------------------------------------------------------------
// Description:
// Assigns path to the "root", entry point file.
Expand Down
11 changes: 10 additions & 1 deletion shadercompiler/CachingIncludeHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ class CachingIncludeHandler
time_t modifiedTime;
};

std::optional<IncludedFile> Open( const char* fileName, const char* parentData = nullptr, const char* rootPath = nullptr );
enum IncludeType
{
IncludeLocal,
IncludeSystem
};

std::optional<IncludedFile> Open( const char* fileName, IncludeType includeType, const char* parentData = nullptr, const char* rootPath = nullptr );

void SetRootPath( const char* shaderPath );

std::optional<IncludedFile> AddPrefix( const char* fileName, const char* prefix );

void AddSystemIncludePath( const char* path );

private:
typedef std::map<const void*, std::string> PathFromFile;
typedef std::map<std::string, IncludedFile> FileFromPath;
Expand All @@ -38,6 +46,7 @@ class CachingIncludeHandler
FileFromPath m_fileFromPath;
// Path of the entry point file
std::string m_rootPath;
std::vector<std::string> m_systemIncludePaths;

std::mutex m_cs;
};
7 changes: 7 additions & 0 deletions shadercompiler/EffectCompilerDX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,13 @@ bool EffectCompilerDX11::CompileEffect( const char* source, size_t sourceLength,

CComPtr<IDxcResult> pCompileResult;
HRESULT hrCompilation = compiler->Compile( &sourceBuffer, arguments, argumentsSize, nullptr, IID_PPV_ARGS( &pCompileResult ) );
if( SUCCEEDED( hrCompilation ) )
{
if( FAILED( pCompileResult->GetStatus( &hrCompilation ) ) )
{
hrCompilation = E_FAIL;
}
}

if( FAILED( hrCompilation ) )
{
Expand Down
19 changes: 10 additions & 9 deletions shadercompiler/HLSLScanner.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ ID = LETTER(LETTER|DECIMAL)*;
#define YYMARKER (marker)
#define YYCTXMARKER (ctxMarker)

bool GetIncludePath( ParserState &state, InlineString& path )
bool GetIncludePath( ParserState &state, InlineString& path, CachingIncludeHandler::IncludeType& includeType )
{
bool local;
includeType = CachingIncludeHandler::IncludeLocal;
if( *YYCURSOR == '"' )
{
local = true;
includeType = CachingIncludeHandler::IncludeLocal;
}
else if( *YYCURSOR == '<' )
{
local = false;
includeType = CachingIncludeHandler::IncludeSystem;
}
else
{
Expand All @@ -61,15 +61,15 @@ bool GetIncludePath( ParserState &state, InlineString& path )
{
if( *YYCURSOR == '"' )
{
if( local )
if( includeType == CachingIncludeHandler::IncludeLocal )
{
path.end = ++YYCURSOR;
return true;
}
}
else if( *YYCURSOR == '>' )
{
if( !local )
if( includeType == CachingIncludeHandler::IncludeSystem )
{
path.end = ++YYCURSOR;
return true;
Expand Down Expand Up @@ -141,14 +141,15 @@ std:
{
state.GetCurrentLocation().lineNumber++;
InlineString path;
if( !GetIncludePath( state, path ) )
CachingIncludeHandler::IncludeType includeType;
if( !GetIncludePath( state, path, includeType ) )
{
state.ShowMessage( EC_INVALID_INCLUDE_PATH );
return PPSR_ERROR;
}
if( !state.InSkipMode() )
{
state.IncludeFile( path );
state.IncludeFile( path, includeType );
}
start = YYCURSOR;
continue;
Expand Down Expand Up @@ -566,7 +567,7 @@ std:
++YYCURSOR;
}

if( !state.InSkipMode() )
if( !state.InSkipMode() && !state.InDiscoverMode() )
{
state.ShowMessage( EC_USER_ERROR, std::string( start, YYCURSOR ).c_str() );
return PPSR_ERROR;
Expand Down
11 changes: 11 additions & 0 deletions shadercompiler/MSLInclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ void GetDimensions( texturecube<T> tex, thread W& w, thread H& h )
h = H( tex.get_height() );
}

template <typename T, typename W, typename H, typename M>
void GetDimensions( texturecube<T> tex, uint mip, thread W& w, thread H& h, thread M& m )
{
w = W( tex.get_width( mip ) );
h = H( tex.get_height( mip ) );
m = M( tex.get_num_mip_levels() );
}

)MSL"
R"MSL(

template <typename T, typename W, typename H, typename D>
void GetDimensions( texture3d<T> tex, thread W& w, thread H& h, thread D& d )
{
Expand Down
11 changes: 6 additions & 5 deletions shadercompiler/ModifiedTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct HashCheckArguments
std::mutex s_modifiedOutputsCS;
std::set<std::string> s_modifiedOutputs;

const std::regex s_include( "#[[:space:]]*include[[:space:]]*[<\"]([^>\"]*)" );
const std::regex s_include( "#[[:space:]]*include[[:space:]]*([<\"])([^>\"]*)" );

bool IsOutputUpToDate( const char* path, const std::string& sourceHash )
{
Expand Down Expand Up @@ -112,22 +112,23 @@ bool CheckHash( const HashCheckArguments& query )
return true;
}

void GetSourceHash( const char* sourcePath, const char* parentData, const char* rootPath, std::set<std::string>& visited, MD5& md5 )
void GetSourceHash( const char* sourcePath, const char* parentData, const char* rootPath, CachingIncludeHandler::IncludeType includeType, std::set<std::string>& visited, MD5& md5 )
{
if( visited.find( sourcePath ) != end( visited ) )
{
return;
}
visited.insert( sourcePath );
if( auto opened = s_includeHandler.Open( sourcePath, parentData, rootPath ) )
if( auto opened = s_includeHandler.Open( sourcePath, includeType, parentData, rootPath ) )
{
md5.add( opened->data, opened->size );

std::cmatch match;
auto begin = opened->data;
while( std::regex_search( begin, opened->data + opened->size, match, s_include ) )
{
GetSourceHash( match[1].str().c_str(), opened->data, rootPath, visited, md5 );
CachingIncludeHandler::IncludeType it = match[1].str() == "<" ? CachingIncludeHandler::IncludeSystem : CachingIncludeHandler::IncludeLocal;
GetSourceHash( match[2].str().c_str(), opened->data, rootPath, it, visited, md5 );
begin += match.position() + match.length();
}
}
Expand Down Expand Up @@ -159,7 +160,7 @@ std::string GetSourceHash( const char* sourcePath, const std::vector<Macro>& def
md5.add( &g_generatePDB, sizeof( g_generatePDB ) );
md5.add( &g_skipOptimization, sizeof( g_skipOptimization ) );

GetSourceHash( sourcePath, nullptr, sourcePath, visited, md5 );
GetSourceHash( sourcePath, nullptr, sourcePath, CachingIncludeHandler::IncludeLocal, visited, md5 );
return md5.getHash();
}

Expand Down
4 changes: 2 additions & 2 deletions shadercompiler/ParserState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,12 +988,12 @@ bool ParserState::InMacro() const
return m_fileStack.back().isMacro;
}

void ParserState::IncludeFile( const InlineString& fileName )
void ParserState::IncludeFile( const InlineString& fileName, CachingIncludeHandler::IncludeType includeType )
{
extern CachingIncludeHandler g_includeHandler;

std::string path( fileName.start + 1, fileName.end - 1 );
if( auto file = g_includeHandler.Open( path.c_str(), m_fileStack.back().code.start + 1 ) )
if( auto file = g_includeHandler.Open( path.c_str(), includeType, m_fileStack.back().code.start + 1 ) )
{
FileContents fileContents;

Expand Down
3 changes: 2 additions & 1 deletion shadercompiler/ParserState.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "InlineString.h"
#include "CachingIncludeHandler.h"

class SymbolTable;
class ASTNode;
Expand Down Expand Up @@ -234,7 +235,7 @@ class ParserState
bool InDiscoverMode() const;
PreprocessorScanResult GetPreprocessorToken( PreprocessorToken& token );

void IncludeFile( const InlineString& fileName );
void IncludeFile( const InlineString& fileName, CachingIncludeHandler::IncludeType includeType );
void ParseDefine( const PreprocessorDefine& define, const FileLocation& location, const std::vector<InlineString>& arguments );
PreprocessorDefine* FindDefine( const InlineString& name );

Expand Down
14 changes: 9 additions & 5 deletions shadercompiler/ParserUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,23 +905,27 @@ int GetNodeOrder( ASTNode* t )
{
if( child->GetNodeType() == NT_CBUFFER )
{
return 2;
return 3;
}
}
if( auto child = t->GetChildOrNull( 1 ) )
{
if( child->GetNodeType() == NT_CBUFFER )
{
return 2;
return 3;
}
}
if( GetRegisterType( t->GetType() ) )
{
return 2;
return 3;
}
else
{
return 1;
if( t->GetType().modifier == OP_CONST && t->GetType().storageClass == OP_STATIC )
{
return 1;
}
return 2;
}
case NT_TECHNIQUE:
return 12;
Expand Down Expand Up @@ -985,7 +989,7 @@ void CreateGlobalsCB( ParserState& state )
continue;
}
}
if( !GetRegisterType( child->GetType() ) )
if( !GetRegisterType( child->GetType() ) && !( child->GetType().modifier == OP_CONST && child->GetType().storageClass == OP_STATIC ) )
{
varStart = std::min( varStart, i );
varEnd = std::max( varEnd, i );
Expand Down
Loading
Loading