Skip to content

Commit

Permalink
ShaderReflection now stores information about Image dimension etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRichards-Code committed May 13, 2023
1 parent 4080154 commit 15b28ca
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 14 deletions.
7 changes: 7 additions & 0 deletions MIRU_CORE/src/base/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ namespace base
uint32_t descriptorCount; //Number of descriptor in a single binding, accessed as an array.
Shader::StageBit stage;
std::string name;

size_t structSize;

uint32_t dimension;
bool cubemap;
bool array_;
bool multisample;
bool readwrite;
};

//See MSCDocumentation.h for correct usage.
Expand Down
95 changes: 85 additions & 10 deletions MIRU_CORE/src/d3d12/D3D12Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ void Shader::D3D12ShaderReflection(
MIRU_WARN(res, "WARN: D3D12: ID3D12ShaderReflection::GetResourceBindingDesc failed.");
if (res == S_OK)
{
size_t structSize = 0;

base::DescriptorType descType = D3D_SHADER_INPUT_TYPE_to_miru_base_DescriptorType(bindingDesc.Type, bindingDesc.Dimension);

size_t structSize = 0;
if (descType == base::DescriptorType::UNIFORM_BUFFER)
{
ID3D12ShaderReflectionConstantBuffer* shader_reflection_constant_buffer = shader_reflection->GetConstantBufferByName(bindingDesc.Name); //No need to release.
Expand All @@ -321,6 +321,39 @@ void Shader::D3D12ShaderReflection(
}
}

uint32_t dimension = 0;
bool cubemap = false;
bool array_ = false;
bool multisample = false;
bool readwrite = false;
if (descType == base::DescriptorType::COMBINED_IMAGE_SAMPLER || descType == base::DescriptorType::SAMPLED_IMAGE || descType == base::DescriptorType::STORAGE_IMAGE)
{
switch (bindingDesc.Dimension)
{
case D3D_SRV_DIMENSION_TEXTURE1D:
dimension = 1; break;
case D3D_SRV_DIMENSION_TEXTURE1DARRAY:
dimension = 1; array_ = true; break;
case D3D_SRV_DIMENSION_TEXTURE2D:
dimension = 2; break;
case D3D_SRV_DIMENSION_TEXTURE2DARRAY:
dimension = 2; array_ = true; break;
case D3D_SRV_DIMENSION_TEXTURE2DMS:
dimension = 2; multisample = true; break;
case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY:
dimension = 2; array_ = true; multisample = true; break;
case D3D_SRV_DIMENSION_TEXTURE3D:
dimension = 3; break;
case D3D_SRV_DIMENSION_TEXTURECUBE:
dimension = 2; cubemap = true; break;
case D3D_SRV_DIMENSION_TEXTURECUBEARRAY:
dimension = 2; cubemap = true; array_ = true; break;
default:
break;
}
readwrite = descType == base::DescriptorType::STORAGE_IMAGE ? true : false;
}

std::string name = bindingDesc.Name;
if (name.find("CIS") != std::string::npos)
{
Expand All @@ -333,23 +366,27 @@ void Shader::D3D12ShaderReflection(
break;
}
}

if (found)
{
continue;
}
else
cis_list.push_back(name.substr(0, name.find_last_of('_')));

descType = base::DescriptorType::COMBINED_IMAGE_SAMPLER;
}

Shader::ResourceBindingDescription rbd;
Shader::ResourceBindingDescription& rbd = RBDs[bindingDesc.Space][bindingDesc.BindPoint];
rbd.binding = bindingDesc.BindPoint;
rbd.type = descType;
rbd.descriptorCount = bindingDesc.BindCount;
rbd.stage = get_shader_stage(stage);
rbd.name = name;
rbd.structSize = structSize;
RBDs[bindingDesc.Space][bindingDesc.BindPoint] = rbd;
rbd.dimension = dimension;
rbd.cubemap = cubemap;
rbd.array_ = array_;
rbd.multisample = multisample;
rbd.readwrite = readwrite;
}
}
}
Expand Down Expand Up @@ -396,9 +433,9 @@ void Shader::D3D12ShaderReflection(
MIRU_WARN(res, "WARN: D3D12: ID3D12FunctionReflection::GetResourceBindingDesc failed.");
if (res == S_OK)
{
size_t structSize = 0;

base::DescriptorType descType = D3D_SHADER_INPUT_TYPE_to_miru_base_DescriptorType(bindingDesc.Type, bindingDesc.Dimension);

size_t structSize = 0;
if (descType == base::DescriptorType::UNIFORM_BUFFER)
{
ID3D12ShaderReflectionConstantBuffer* shader_reflection_constant_buffer = function_reflection->GetConstantBufferByName(bindingDesc.Name); //No need to release.
Expand All @@ -416,6 +453,39 @@ void Shader::D3D12ShaderReflection(
}
}

uint32_t dimension = 0;
bool cubemap = false;
bool array_ = false;
bool multisample = false;
bool readwrite = false;
if (descType == base::DescriptorType::COMBINED_IMAGE_SAMPLER || descType == base::DescriptorType::SAMPLED_IMAGE || descType == base::DescriptorType::STORAGE_IMAGE)
{
switch (bindingDesc.Dimension)
{
case D3D_SRV_DIMENSION_TEXTURE1D:
dimension = 1; break;
case D3D_SRV_DIMENSION_TEXTURE1DARRAY:
dimension = 1; array_ = true; break;
case D3D_SRV_DIMENSION_TEXTURE2D:
dimension = 2; break;
case D3D_SRV_DIMENSION_TEXTURE2DARRAY:
dimension = 2; array_ = true; break;
case D3D_SRV_DIMENSION_TEXTURE2DMS:
dimension = 2; multisample = true; break;
case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY:
dimension = 2; array_ = true; multisample = true; break;
case D3D_SRV_DIMENSION_TEXTURE3D:
dimension = 3; break;
case D3D_SRV_DIMENSION_TEXTURECUBE:
dimension = 2; cubemap = true; break;
case D3D_SRV_DIMENSION_TEXTURECUBEARRAY:
dimension = 2; cubemap = true; array_ = true; break;
default:
break;
}
readwrite = descType == base::DescriptorType::STORAGE_IMAGE ? true : false;
}

std::string name = bindingDesc.Name;
if (name.find("CIS") != std::string::npos)
{
Expand All @@ -428,12 +498,12 @@ void Shader::D3D12ShaderReflection(
break;
}
}

if (found)
{
continue;
}
else
cis_list.push_back(name.substr(0, name.find_last_of('_')));

descType = base::DescriptorType::COMBINED_IMAGE_SAMPLER;
}

Expand All @@ -444,6 +514,11 @@ void Shader::D3D12ShaderReflection(
rbd.stage |= get_shader_stage(stage);
rbd.name = name;
rbd.structSize = structSize;
rbd.dimension = dimension;
rbd.cubemap = cubemap;
rbd.array_ = array_;
rbd.multisample = multisample;
rbd.readwrite = readwrite;
}
}
}
Expand Down
38 changes: 34 additions & 4 deletions MIRU_CORE/src/vulkan/VKShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,32 @@ void Shader::VulkanShaderReflection(
structSize = compiled_bin.get_declared_struct_size(type);
}

uint32_t dimension = 0;
bool cubemap = false;
bool array_ = false;
bool multisample = false;
bool readwrite = false;
if (descType == base::DescriptorType::COMBINED_IMAGE_SAMPLER || descType == base::DescriptorType::SAMPLED_IMAGE || descType == base::DescriptorType::STORAGE_IMAGE)
{
const spirv_cross::SPIRType::ImageType& image = type.image;
switch (image.dim)
{
case spv::Dim::Dim1D:
dimension = 1; break;
case spv::Dim::Dim2D:
dimension = 2; break;
case spv::Dim::Dim3D:
dimension = 3; break;
case spv::Dim::DimCube:
dimension = 2; cubemap = true; break;
default:
break;
}
array_ = image.arrayed;
multisample = image.ms;
readwrite = descType == base::DescriptorType::STORAGE_IMAGE ? true : false;
}

uint32_t set = compiled_bin.get_decoration(res.id, spv::DecorationDescriptorSet);
uint32_t binding = compiled_bin.get_decoration(res.id, spv::DecorationBinding);
uint32_t descCount = !type.array.empty() ? type.array[0] : 1;
Expand All @@ -261,23 +287,27 @@ void Shader::VulkanShaderReflection(
break;
}
}

if (found)
{
continue;
}
else
cis_list.push_back(res.name.substr(0, res.name.find_last_of('_')));

descType = base::DescriptorType::COMBINED_IMAGE_SAMPLER;
}

Shader::ResourceBindingDescription rbd;
Shader::ResourceBindingDescription& rbd = RBDs[set][binding];
rbd.binding = binding;
rbd.type = descType;
rbd.descriptorCount = descCount;
rbd.stage = stageBit;
rbd.name = name;
rbd.structSize = structSize;
RBDs[set][binding] = rbd;
rbd.dimension = dimension;
rbd.cubemap = cubemap;
rbd.array_ = array_;
rbd.multisample = multisample;
rbd.readwrite = readwrite;
}
};

Expand Down

0 comments on commit 15b28ca

Please sign in to comment.