8000 Latest from internal main by Atrix256 · Pull Request #31 · electronicarts/gigi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Latest from internal main #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion GigiCompilerLib/Backends/DX12/Backend_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct BackendDX12 : public BackendBase
case DataFieldType::Float3: return "DXGI_FORMAT_R32G32B32_FLOAT";
case DataFieldType::Uint: return "DXGI_FORMAT_R32_UINT";
case DataFieldType::Uint_16: return "DXGI_FORMAT_R16_UINT";
case DataFieldType::Int_64: return "DXGI_FORMAT_RG32_INT";
case DataFieldType::Uint_64: return "DXGI_FORMAT_RG32_UINT";
default:
{
Assert(false, "Unhandled DataFieldType: %i", (int)type);
Expand Down Expand Up @@ -438,6 +440,8 @@ struct BackendDX12 : public BackendBase
case DataFieldType::Float4: return "float4";
case DataFieldType::Bool: return "bool";
case DataFieldType::Float4x4: return "float4x4";
case DataFieldType::Int_64: return "int64_t";
case DataFieldType::Uint_64: return "uint64_t";
default:
{
Assert(false, "Unhandled data field type: %s (%i)", EnumToString(type), type);
Expand Down Expand Up @@ -802,6 +806,8 @@ struct BackendDX12 : public BackendBase
case DataFieldType::Bool: varSymbols = "b"; break;
case DataFieldType::Float4x4: varSymbols = "ffffffffffffffff"; varRefs = "&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7], &value[8], &value[9], &value[10], &value[11], &value[12], &value[13], &value[14], &value[15]"; break;
case DataFieldType::Uint_16: varSymbols = "I"; break;
case DataFieldType::Int_64: varSymbols = "I"; break;
case DataFieldType::Uint_64: varSymbols = "I"; break;
default: Assert(false, "Unhandled Variable Type: %i", variable.type); break;
}

Expand Down Expand Up @@ -2055,7 +2061,7 @@ void CopyShaderFileDX12(const Shader& shader, const std::unordered_map<std::stri

std::string workingDirectory = (std::filesystem::path(outFolder) / "shaders" / "").string();
std::string slangErrorMessage;
if (!ProcessWithSlang(shaderFileContents, shader.fileName.c_str(), stage, shader.entryPoint.c_str(), shaderModel, slangErrorMessage, workingDirectory.c_str()))
if (!ProcessWithSlang(shaderFileContents, shader.fileName.c_str(), stage, shader.entryPoint.c_str(), shaderModel, slangErrorMessage, workingDirectory.c_str(), shader.slangOptions))
{
ShowErrorMessage("Slang:%s\n%s\n", shader.fileName.c_str(), slangErrorMessage.c_str());
}
Expand Down
10 changes: 10 additions & 0 deletions GigiCompilerLib/Backends/Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ inline size_t DataFieldTypeToSize(DataFieldType type)
case DataFieldType::Bool: return 4;
case DataFieldType::Float4x4: return 4 * 4 * 4;
case DataFieldType::Uint_16: return 2;
case DataFieldType::Int_64: return 8;
case DataFieldType::Uint_64: return 8;
default:
{
Assert(false, "Unknown data field type: %i", type);
Expand Down Expand Up @@ -570,6 +572,8 @@ inline size_t DataFieldTypeComponentCount(DataFieldType type)
case DataFieldType::Bool: return 1;
case DataFieldType::Float4x4: return 16;
case DataFieldType::Uint_16: return 1;
case DataFieldType::Int_64: return 1;
case DataFieldType::Uint_64: return 1;
default:
{
Assert(false, "Unknown data field type: %i (%s)", type, EnumToString(type));
Expand Down Expand Up @@ -685,6 +689,8 @@ static std::string DataFieldTypeToShaderType(DataFieldType type)
case DataFieldType::Bool: return "uint";
case DataFieldType::Float4x4: return "float4x4";
case DataFieldType::Uint_16: return "uint";
case DataFieldType::Int_64: return "int64";
case DataFieldType::Uint_64: return "uint64";
case DataFieldType::Count:
{
Assert(false, "Invalid data field type: Count");
Expand Down Expand Up @@ -791,6 +797,8 @@ enum class DataFieldComponentType
_int,
_uint16_t,
_uint32_t,
_int64_t,
_uint64_t,
_float,
};

Expand Down Expand Up @@ -835,6 +843,8 @@ inline DataFieldTypeInfoStruct DataFieldTypeInfo(DataFieldType type)
case DataFieldType::Bool: return DATA_FIELD_TYPE_INFO(uint32_t, 1, DataFieldType::Bool);
case DataFieldType::Float4x4: return DATA_FIELD_TYPE_INFO(float, 16, DataFieldType::Float);
case DataFieldType::Uint_16: return DATA_FIELD_TYPE_INFO(uint16_t, 1, DataFieldType::Uint_16);
case DataFieldType::Int_64: return DATA_FIELD_TYPE_INFO(int64_t, 1, DataFieldType::Int_64);
case DataFieldType::Uint_64: return DATA_FIELD_TYPE_INFO(uint64_t, 1, DataFieldType::Uint_64);
default:
{
Assert(false, "Unknown data field type: %i (%s)", type, EnumToString(type));
Expand Down
4 changes: 2 additions & 2 deletions GigiCompilerLib/GigiCompilerLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<AdditionalDependencies>slang.lib</AdditionalDependencies>
</Lib>
<Lib>
<AdditionalLibraryDirectories>$(SolutionDir)External\slang\bin\windows-x64\release\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(SolutionDir)External\slang\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<PreBuildEvent>
<Command>
Expand Down Expand Up @@ -98,7 +98,7 @@
<AdditionalDependencies>slang.lib</AdditionalDependencies>
</Lib>
<Lib>
<AdditionalLibraryDirectories>$(SolutionDir)External\slang\bin\windows-x64\release\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(SolutionDir)External\slang\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<PreBuildEvent>
<Command>
Expand Down
37 changes: 33 additions & 4 deletions GigiCompilerLib/ProcessSlang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "ProcessSlang.h"

#include "external/slang/slang.h"
#include "external/slang/slang-com-helper.h"
#include "external/slang/include/slang.h"
#include "external/slang/include/slang-com-helper.h"

#include <filesystem>
#include <vector>
Expand Down Expand Up @@ -156,8 +156,8 @@ class SlangIncludeHandler : public ISlangFileSystem
};
#endif

// https://github.com/shader-slang/slang/blob/master/docs/api-users-guide.md
bool ProcessWithSlang(std::string& source, const char* fileName, const char* stage, const char* entryPoint, const char* profile, std::string& errorMessage, const char* workingDirectory)
// https://github.com/shader-slang/slang/tree/master/docs#readme
bool ProcessWithSlang(std::string& source, const char* fileName, const char* stage, const char* entryPoint, const char* profile, std::string& errorMessage, const char* workingDirectory, const SlangOptions& options)
{
bool ret = true;
char errorBuffer[1024];
Expand All @@ -166,9 +166,38 @@ bool ProcessWithSlang(std::string& source, const char* fileName, const char* sta
SlangSession* session = spCreateSession(NULL);
SlangCompileRequest* request = spCreateCompileRequest(session);

if (options.noNameMangling)
request->setCompileFlags(SLANG_COMPILE_FLAG_NO_MANGLING);

switch (options.optimizationLevel)
{
case GigiSlangOptimizationLevel::None: request->setOptimizationLevel(SLANG_OPTIMIZATION_LEVEL_NONE); break;
case GigiSlangOptimizationLevel::Default: request->setOptimizationLevel(SLANG_OPTIMIZATION_LEVEL_DEFAULT); break;
case GigiSlangOptimizationLevel::High: request->setOptimizationLevel(SLANG_OPTIMIZATION_LEVEL_HIGH); break;
case GigiSlangOptimizationLevel::Maximum: request->setOptimizationLevel(SLANG_OPTIMIZATION_LEVEL_MAXIMAL); break;
}

request->setLineDirectiveMode(options.lineDirectives ? SLANG_LINE_DIRECTIVE_MODE_STANDARD : SLANG_LINE_DIRECTIVE_MODE_NONE);

{
unsigned int diagnosticsFlags = 0;
if (options.warningsAsErrors)
diagnosticsFlags |= SLANG_DIAGNOSTIC_FLAG_TREAT_WARNINGS_AS_ERRORS;
if (options.verbosePaths)
diagnosticsFlags |= SLANG_DIAGNOSTIC_FLAG_VERBOSE_PATHS;
request->setDiagnosticFlags(diagnosticsFlags);
}

// Set what type of thing we want to come out of the slang compiler
spSetCodeGenTarget(request, SlangCompileTarget::SLANG_HLSL);

switch (options.floatingPointMode)
{
case GigiSlangFloatingPointMode::Default: request->setTargetFloatingPointMode(0, SLANG_FLOATING_POINT_MODE_DEFAULT); break;
case GigiSlangFloatingPointMode::Fast: request->setTargetFloatingPointMode(0, SLANG_FLOATING_POINT_MODE_FAST); break;
case GigiSlangFloatingPointMode::Precise: request->setTargetFloatingPointMode(0, SLANG_FLOATING_POINT_MODE_PRECISE); break;
}

spAddSearchPath(request, workingDirectory);

int translationUnitIndex = spAddTranslationUnit(request, SLANG_SOURCE_LANGUAGE_SLANG, "");
Expand Down
4 changes: 3 additions & 1 deletion GigiCompilerLib/ProcessSlang.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

#include <string>

bool ProcessWithSlang(std::string& source, const char* fileName, const char* stage, const char* entryPoint, const char* profile, std::string& errorMessage, const char* workingDirectory);
struct SlangOptions;

bool ProcessWithSlang(std::string& source, const char* fileName, const char* stage, const char* entryPoint, const char* profile, std::string& errorMessage, const char* workingDirectory, const SlangOptions& options);
6 changes: 5 additions & 1 deletion GigiCompilerLib/SubGraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ struct RenameReferencesVisitor

bool Visit(SetVariable& setVariable, const std::string& path)
{
m_renameData.UpdateNodeName(setVariable.ANode.name);
m_renameData.UpdateNodeName(setVariable.BNode.name);

m_renameData.UpdateVariableName(setVariable.destination.name);
m_renameData.UpdateVariableName(setVariable.AVar.name);
m_renameData.UpdateVariableName(setVariable.BVar.name);
Expand Down Expand Up @@ -522,7 +525,8 @@ struct RenameChildVisitor
// Need to handle the subgraph possibly being in a parent directory etc.
if (s.destFileName.empty())
s.destFileName = s.fileName;
s.destFileName = (std::filesystem::path(m_subGraphNode.fileName).filename().replace_extension() / s.destFileName).string();
std::string destFolder = std::filesystem::path(m_subGraphNode.fileName).filename().replace_extension().string() + "_" + m_subGraphNode.name;
s.destFileName = (std::filesystem::path(destFolder) / s.destFileName).string();
StringReplaceAll(s.destFileName, "\\", "/");

// Update where the file lives on disk
Expand Down
2 changes: 2 additions & 0 deletions GigiCompilerLib/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ inline std::string DataFieldTypeToHLSLType(DataFieldType type)
case DataFieldType::Bool: return "uint";
case DataFieldType::Float4x4: return "float4x4";
case DataFieldType::Uint_16: return "uint";
case DataFieldType::Int_64: return "uint64_t";
case DataFieldType::Uint_64: return "uint64_t";
case DataFieldType::Count:
{
Assert(false, "Invalid data field type: Count");
Expand Down
63 changes: 62 additions & 1 deletion GigiCompilerLib/gigiinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@ void VariableStorage::SetFromString(const char* text, size_t count, uint16_t* va
);
}

void VariableStorage::SetFromString(const char* text, size_t count, int64_t* value)
{
ParseCSV::ForEachValue(text, false,
[&](int tokenIndex, const char* token)
{
if (tokenIndex < count)
{
int64_t temp;
sscanf_s(token, "%lli", &temp);
value[tokenIndex] = temp;
}
return true;
}
);
}

void VariableStorage::SetFromString(const char* text, size_t count, uint64_t* value)
{
ParseCSV::ForEachValue(text, false,
[&](int tokenIndex, const char* token)
{
if (tokenIndex < count)
{
uint64_t temp;
sscanf_s(token, "%llu", &temp);
value[tokenIndex] = temp;
}
return true;
}
);
}

std::string VariableStorage::GetAsString(size_t count, int* value)
{
std::string ret;
Expand Down Expand Up @@ -145,4 +177,33 @@ std::string VariableStorage::GetAsString(size_t count, uint16_t* value)
}

return ret;
}
}

std::string VariableStorage::GetAsString(size_t count, int64_t* value)
{
std::string ret;

char buffer[256];
for (size_t i = 0; i < count; ++i)
{
sprintf_s(buffer, "%s%lli", ((i > 0) ? "," : ""), (int64_t)value[i]);
ret += std::string(buffer);
}

return ret;
}

std::string VariableStorage::GetAsString(size_t count, uint64_t* value)
{
std::string ret;

char buffer[256];
for (size_t i = 0; i < count; ++i)
{
sprintf_s(buffer, "%s%llu", ((i > 0) ? "," : ""), (uint64_t)value[i]);
ret += std::string(buffer);
}

return ret;
}

Loading
0