Skip to content

Commit

Permalink
Merge pull request #9 from IvarPD/add-globallycoherent
Browse files Browse the repository at this point in the history
Added support for globallycoherent keyword.
  • Loading branch information
Atrix256 authored Dec 2, 2024
2 parents 38a3ca4 + 8fb4421 commit 071d06e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 9 additions & 5 deletions GigiCompilerLib/Backends/DX12/Backend_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,8 @@ void CopyShaderFileDX12(const Shader& shader, const std::unordered_map<std::stri
{
case ShaderResourceType::Texture:
{
const char* variablePrefix = (resource.access == ShaderResourceAccessType::UAV && resource.texture.globallyCoherent) ? "globallycoherent " : "";

const char* textureType = "";
switch (resource.texture.dimension)
{
Expand All @@ -1574,34 +1576,36 @@ void CopyShaderFileDX12(const Shader& shader, const std::unordered_map<std::stri
}

shaderSpecificStringReplacementMap["/*$(ShaderResources)*/"] <<
"\n" << typePrefix << textureType << "<" << BackendDX12::DataFieldTypeToCPPType(viewDataFieldType) << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");";
"\n" << variablePrefix << typePrefix << textureType << "<" << BackendDX12::DataFieldTypeToCPPType(viewDataFieldType) << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");";
break;
}
case ShaderResourceType::Buffer:
{
const char* variablePrefix = (resource.access == ShaderResourceAccessType::UAV && resource.buffer.globallyCoherent) ? "globallycoherent " : "";

if (resource.buffer.raw)
{
shaderSpecificStringReplacementMap["/*$(ShaderResources)*/"] <<
"\n" << typePrefix << "ByteAddressBuffer " << resource.name << " : register(" << registerType << resource.registerIndex << ");"
"\n" << variablePrefix << typePrefix << "ByteAddressBuffer " << resource.name << " : register(" << registerType << resource.registerIndex << ");"
;
}
else if (resource.buffer.typeStruct.structIndex != -1)
{
shaderSpecificStringReplacementMap["/*$(ShaderResources)*/"] <<
"\n" << typePrefix << "StructuredBuffer<Struct_" << renderGraph.structs[resource.buffer.typeStruct.structIndex].name << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");"
"\n" << variablePrefix << typePrefix << "StructuredBuffer<Struct_" << renderGraph.structs[resource.buffer.typeStruct.structIndex].name << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");"
;
}
else
{
if (DataFieldTypeIsPOD(resource.buffer.type) && !resource.buffer.PODAsStructuredBuffer)
{
shaderSpecificStringReplacementMap["/*$(ShaderResources)*/"] <<
"\n" << typePrefix << "Buffer<" << DataFieldTypeToShaderType(resource.buffer.type) << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");";
"\n" << variablePrefix << typePrefix << "Buffer<" << DataFieldTypeToShaderType(resource.buffer.type) << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");";
}
else
{
shaderSpecificStringReplacementMap["/*$(ShaderResources)*/"] <<
"\n" << typePrefix << "StructuredBuffer<" << DataFieldTypeToShaderType(resource.buffer.type) << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");";
"\n" << variablePrefix << typePrefix << "StructuredBuffer<" << DataFieldTypeToShaderType(resource.buffer.type) << "> " << resource.name << " : register(" << registerType << resource.registerIndex << ");";
}
}
break;
Expand Down
2 changes: 2 additions & 0 deletions Schemas/SchemasShaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,13 @@ STRUCT_BEGIN(ShaderResourceBuffer, "Data specific to buffers")
STRUCT_FIELD(StructReference, typeStruct, {}, "The data type of the buffer if a struct type", 0)
STRUCT_FIELD(bool, raw, false, "If true, will be viewed raw in the shader (E.g. DX12 ByteAddressBuffer)", 0)
STRUCT_FIELD(bool, PODAsStructuredBuffer, true, "Set this to true if you want it to be StructuredBuffer instead of a Buffer, for non structure typed buffers.", 0)
STRUCT_FIELD(bool, globallyCoherent, false, "Set this to true if you want the resource to be declared as globallycoherent.", 0)
STRUCT_END()

STRUCT_BEGIN(ShaderResourceTexture, "Data specific to textures")
STRUCT_FIELD(TextureDimensionType, dimension, TextureDimensionType::Texture2D, "The dimensionality of the texture", 0)
STRUCT_FIELD(TextureViewType, viewType, TextureViewType::Float4, "The dimensionality of the texture", 0)
STRUCT_FIELD(bool, globallyCoherent, false, "Set this to true if you want the resource to be declared as globallycoherent.", 0)
STRUCT_END()

STRUCT_BEGIN(ShaderSampler, "Data specific to samplers")
Expand Down

0 comments on commit 071d06e

Please sign in to comment.