|
@@ -1,6 +1,7 @@
|
|
|
#include "DX12Shader.h"
|
|
#include "DX12Shader.h"
|
|
|
|
|
|
|
|
#include "DX12CommandQueue.h"
|
|
#include "DX12CommandQueue.h"
|
|
|
|
|
+#include "DX12SamplerState.h"
|
|
|
#include "DX12Texture.h"
|
|
#include "DX12Texture.h"
|
|
|
#include "DX12TLAS.h"
|
|
#include "DX12TLAS.h"
|
|
|
#include "Logging.h"
|
|
#include "Logging.h"
|
|
@@ -33,6 +34,13 @@ Framework::DX12ShaderSignature::~DX12ShaderSignature()
|
|
|
int* Framework::DX12ShaderSignature::addRegisterUsageLinkedToShaderBindingTable(
|
|
int* Framework::DX12ShaderSignature::addRegisterUsageLinkedToShaderBindingTable(
|
|
|
DX12ShaderRegister registerType, int registerIndex, int spaceIndex)
|
|
DX12ShaderRegister registerType, int registerIndex, int spaceIndex)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (registerType == DX12_SHADER_REGISTER_S_SAMPLER)
|
|
|
|
|
+ {
|
|
|
|
|
+ Logging::error() << "Sampler register usage can not be linked to "
|
|
|
|
|
+ "shader binding table";
|
|
|
|
|
+ throw std::logic_error(
|
|
|
|
|
+ "Sampler register usage can not be linked to shader binding table");
|
|
|
|
|
+ }
|
|
|
for (DX12ShaderRegisterUsage* usage : descriptorHeapBindings)
|
|
for (DX12ShaderRegisterUsage* usage : descriptorHeapBindings)
|
|
|
{
|
|
{
|
|
|
if (usage->registerType == registerType
|
|
if (usage->registerType == registerType
|
|
@@ -59,8 +67,14 @@ int* Framework::DX12ShaderSignature::addRegisterUsageLinkedToShaderBindingTable(
|
|
|
"Duplicate register usage in root signature");
|
|
"Duplicate register usage in root signature");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- DX12ShaderRegisterUsage* usage = new DX12ShaderRegisterUsage{
|
|
|
|
|
- registerType, registerIndex, spaceIndex, -1, 0};
|
|
|
|
|
|
|
+ DX12ShaderRegisterUsage* usage = new DX12ShaderRegisterUsage{registerType,
|
|
|
|
|
+ GLOBAL_DESCRIPTOR_HEAP,
|
|
|
|
|
+ registerIndex,
|
|
|
|
|
+ spaceIndex,
|
|
|
|
|
+ -1,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ -1};
|
|
|
bindingTableBindings.add(usage);
|
|
bindingTableBindings.add(usage);
|
|
|
changed = 1;
|
|
changed = 1;
|
|
|
return &usage->bindingTableIndex;
|
|
return &usage->bindingTableIndex;
|
|
@@ -70,8 +84,21 @@ void Framework::DX12ShaderSignature::addRegisterUsageLinkedToDescriptorHeap(
|
|
|
int descriptorHeapIndex,
|
|
int descriptorHeapIndex,
|
|
|
DX12ShaderRegister registerType,
|
|
DX12ShaderRegister registerType,
|
|
|
int registerIndex,
|
|
int registerIndex,
|
|
|
- int spaceIndex)
|
|
|
|
|
|
|
+ int spaceIndex,
|
|
|
|
|
+ DX12DescriptorHeapType descriptorHeapType,
|
|
|
|
|
+ bool array,
|
|
|
|
|
+ int arraySize)
|
|
|
{
|
|
{
|
|
|
|
|
+ if ((registerType == DX12_SHADER_REGISTER_S_SAMPLER)
|
|
|
|
|
+ != (descriptorHeapType == SAMPLER_DESCRIPTOR_HEAP))
|
|
|
|
|
+ {
|
|
|
|
|
+ Logging::error()
|
|
|
|
|
+ << "Sampler register usage must be linked to sampler descriptor "
|
|
|
|
|
+ "heap and vice versa";
|
|
|
|
|
+ throw std::logic_error(
|
|
|
|
|
+ "Sampler register usage must be linked to sampler descriptor "
|
|
|
|
|
+ "heap and vice versa");
|
|
|
|
|
+ }
|
|
|
if (descriptorHeapIndex < 0)
|
|
if (descriptorHeapIndex < 0)
|
|
|
{
|
|
{
|
|
|
Logging::error() << "descriptorHeapIndex can not be below 0";
|
|
Logging::error() << "descriptorHeapIndex can not be below 0";
|
|
@@ -90,31 +117,39 @@ void Framework::DX12ShaderSignature::addRegisterUsageLinkedToDescriptorHeap(
|
|
|
"Duplicate register usage in root signature");
|
|
"Duplicate register usage in root signature");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // descriptor heap bindings sould be sorted by registerType -> spaceIndex ->
|
|
|
|
|
- // registerIndex
|
|
|
|
|
|
|
+ // descriptor heap bindings sould be sorted by descriptorHeapType ->
|
|
|
|
|
+ // registerType -> spaceIndex -> registerIndex
|
|
|
ArrayIterator<DX12ShaderRegisterUsage*> it = descriptorHeapBindings.begin();
|
|
ArrayIterator<DX12ShaderRegisterUsage*> it = descriptorHeapBindings.begin();
|
|
|
bool found = 0;
|
|
bool found = 0;
|
|
|
while (it)
|
|
while (it)
|
|
|
{
|
|
{
|
|
|
- if (it->registerType > registerType)
|
|
|
|
|
|
|
+ if (it->descriptorHeapType > descriptorHeapType)
|
|
|
{
|
|
{
|
|
|
found = 1;
|
|
found = 1;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- if (it->registerType == registerType)
|
|
|
|
|
|
|
+ if (it->descriptorHeapType == descriptorHeapType)
|
|
|
{
|
|
{
|
|
|
- if (it->spaceIndex > spaceIndex)
|
|
|
|
|
|
|
+ if (it->registerType > registerType)
|
|
|
{
|
|
{
|
|
|
found = 1;
|
|
found = 1;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- if (it->spaceIndex == spaceIndex)
|
|
|
|
|
|
|
+ if (it->registerType == registerType)
|
|
|
{
|
|
{
|
|
|
- if (it->registerIndex >= registerIndex)
|
|
|
|
|
|
|
+ if (it->spaceIndex > spaceIndex)
|
|
|
{
|
|
{
|
|
|
found = 1;
|
|
found = 1;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (it->spaceIndex == spaceIndex)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (it->registerIndex >= registerIndex)
|
|
|
|
|
+ {
|
|
|
|
|
+ found = 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
++it;
|
|
++it;
|
|
@@ -130,13 +165,25 @@ void Framework::DX12ShaderSignature::addRegisterUsageLinkedToDescriptorHeap(
|
|
|
throw std::invalid_argument(
|
|
throw std::invalid_argument(
|
|
|
"Duplicate register usage in root signature");
|
|
"Duplicate register usage in root signature");
|
|
|
}
|
|
}
|
|
|
- it.addBefore(new DX12ShaderRegisterUsage{
|
|
|
|
|
- registerType, registerIndex, spaceIndex, descriptorHeapIndex, 0});
|
|
|
|
|
|
|
+ it.addBefore(new DX12ShaderRegisterUsage{registerType,
|
|
|
|
|
+ descriptorHeapType,
|
|
|
|
|
+ registerIndex,
|
|
|
|
|
+ spaceIndex,
|
|
|
|
|
+ descriptorHeapIndex,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ array,
|
|
|
|
|
+ arraySize});
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- descriptorHeapBindings.add(new DX12ShaderRegisterUsage{
|
|
|
|
|
- registerType, registerIndex, spaceIndex, descriptorHeapIndex, 0});
|
|
|
|
|
|
|
+ descriptorHeapBindings.add(new DX12ShaderRegisterUsage{registerType,
|
|
|
|
|
+ descriptorHeapType,
|
|
|
|
|
+ registerIndex,
|
|
|
|
|
+ spaceIndex,
|
|
|
|
|
+ descriptorHeapIndex,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ array,
|
|
|
|
|
+ arraySize});
|
|
|
}
|
|
}
|
|
|
changed = 1;
|
|
changed = 1;
|
|
|
}
|
|
}
|
|
@@ -154,25 +201,42 @@ void Framework::DX12ShaderSignature::createSignature(ID3D12Device5* zDevice,
|
|
|
signature->Release();
|
|
signature->Release();
|
|
|
signature = 0;
|
|
signature = 0;
|
|
|
}
|
|
}
|
|
|
- int paramCount = (descriptorHeapBindings.getEntryCount() > 0 ? 1 : 0)
|
|
|
|
|
|
|
+ int paramCount = (descriptorHeapBindings.getEntryCount() > 0
|
|
|
|
|
+ ? __DESCRIPTOR_HEAP_TYPE_COUNT__
|
|
|
|
|
+ : 0)
|
|
|
+ bindingTableBindings.getEntryCount();
|
|
+ bindingTableBindings.getEntryCount();
|
|
|
D3D12_ROOT_PARAMETER* descriptorTable
|
|
D3D12_ROOT_PARAMETER* descriptorTable
|
|
|
= new D3D12_ROOT_PARAMETER[paramCount];
|
|
= new D3D12_ROOT_PARAMETER[paramCount];
|
|
|
int index = 0;
|
|
int index = 0;
|
|
|
- D3D12_DESCRIPTOR_RANGE* descriptorRanges = 0;
|
|
|
|
|
- if (descriptorHeapBindings.getEntryCount())
|
|
|
|
|
|
|
+ D3D12_DESCRIPTOR_RANGE** descriptorRanges
|
|
|
|
|
+ = new D3D12_DESCRIPTOR_RANGE*[__DESCRIPTOR_HEAP_TYPE_COUNT__];
|
|
|
|
|
+ int rangeCount = 0;
|
|
|
|
|
+ ArrayIterator<DX12ShaderRegisterUsage*> it = descriptorHeapBindings.begin();
|
|
|
|
|
+ DX12DescriptorHeapType currentDescriptorHeapType;
|
|
|
|
|
+ useGlobalDescriptorHeap = 0;
|
|
|
|
|
+ useTextureDescriptorHeap = 0;
|
|
|
|
|
+ while (it)
|
|
|
{
|
|
{
|
|
|
- descriptorTable[0].ParameterType
|
|
|
|
|
|
|
+ descriptorTable[index].ParameterType
|
|
|
= D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
|
|
= D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
|
|
|
- descriptorTable[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
|
|
|
|
|
- descriptorRanges = new D3D12_DESCRIPTOR_RANGE[descriptorHeapBindings
|
|
|
|
|
- .getEntryCount()];
|
|
|
|
|
- ArrayIterator<DX12ShaderRegisterUsage*> it
|
|
|
|
|
- = descriptorHeapBindings.begin();
|
|
|
|
|
- while (it)
|
|
|
|
|
|
|
+ descriptorTable[index].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
|
|
|
|
|
+ descriptorRanges[index]
|
|
|
|
|
+ = new D3D12_DESCRIPTOR_RANGE[descriptorHeapBindings
|
|
|
|
|
+ .getEntryCount()];
|
|
|
|
|
+ currentDescriptorHeapType = it->descriptorHeapType;
|
|
|
|
|
+ if (currentDescriptorHeapType == GLOBAL_DESCRIPTOR_HEAP)
|
|
|
|
|
+ {
|
|
|
|
|
+ useGlobalDescriptorHeap = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (currentDescriptorHeapType == TEXTURE_DESCRIPTOR_HEAP)
|
|
|
|
|
+ {
|
|
|
|
|
+ useTextureDescriptorHeap = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ rangeCount = 0;
|
|
|
|
|
+ while (it && it->descriptorHeapType == currentDescriptorHeapType)
|
|
|
{
|
|
{
|
|
|
it->bindingTableIndex = 0;
|
|
it->bindingTableIndex = 0;
|
|
|
- D3D12_DESCRIPTOR_RANGE& range = descriptorRanges[index];
|
|
|
|
|
|
|
+ D3D12_DESCRIPTOR_RANGE& range = descriptorRanges[index][rangeCount];
|
|
|
switch (it->registerType)
|
|
switch (it->registerType)
|
|
|
{
|
|
{
|
|
|
case DX12_SHADER_REGISTER_B_CONST_BUFFER:
|
|
case DX12_SHADER_REGISTER_B_CONST_BUFFER:
|
|
@@ -184,30 +248,42 @@ void Framework::DX12ShaderSignature::createSignature(ID3D12Device5* zDevice,
|
|
|
case DX12_SHADER_REGISTER_U_UNORDERED_ACCESS:
|
|
case DX12_SHADER_REGISTER_U_UNORDERED_ACCESS:
|
|
|
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
|
|
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case DX12_SHADER_REGISTER_S_SAMPLER:
|
|
|
|
|
+ range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
range.BaseShaderRegister = it->registerIndex;
|
|
range.BaseShaderRegister = it->registerIndex;
|
|
|
range.OffsetInDescriptorsFromTableStart = it->descriptorHeapIndex;
|
|
range.OffsetInDescriptorsFromTableStart = it->descriptorHeapIndex;
|
|
|
range.RegisterSpace = it->spaceIndex;
|
|
range.RegisterSpace = it->spaceIndex;
|
|
|
- ArrayIterator<DX12ShaderRegisterUsage*> next = it.next();
|
|
|
|
|
- int size = 1;
|
|
|
|
|
- while (
|
|
|
|
|
- next && next->registerType == it->registerType
|
|
|
|
|
- && next->spaceIndex == it->spaceIndex
|
|
|
|
|
- && next->registerIndex == it->registerIndex + size
|
|
|
|
|
- && next->descriptorHeapIndex == it->descriptorHeapIndex + size)
|
|
|
|
|
|
|
+ if (it->array)
|
|
|
{
|
|
{
|
|
|
- ++size;
|
|
|
|
|
- it = next;
|
|
|
|
|
- it->bindingTableIndex = 0;
|
|
|
|
|
- ++next;
|
|
|
|
|
|
|
+ range.NumDescriptors = it->arraySize;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ ArrayIterator<DX12ShaderRegisterUsage*> next = it.next();
|
|
|
|
|
+ int size = 1;
|
|
|
|
|
+ while (next && next->registerType == it->registerType
|
|
|
|
|
+ && next->spaceIndex == it->spaceIndex
|
|
|
|
|
+ && next->registerIndex == it->registerIndex + size
|
|
|
|
|
+ && next->descriptorHeapIndex
|
|
|
|
|
+ == it->descriptorHeapIndex + size
|
|
|
|
|
+ && it->descriptorHeapType == currentDescriptorHeapType)
|
|
|
|
|
+ {
|
|
|
|
|
+ ++size;
|
|
|
|
|
+ it = next;
|
|
|
|
|
+ it->bindingTableIndex = 0;
|
|
|
|
|
+ ++next;
|
|
|
|
|
+ }
|
|
|
|
|
+ range.NumDescriptors = size;
|
|
|
}
|
|
}
|
|
|
- range.NumDescriptors = size;
|
|
|
|
|
++it;
|
|
++it;
|
|
|
- ++index;
|
|
|
|
|
|
|
+ ++rangeCount;
|
|
|
}
|
|
}
|
|
|
- descriptorTable[0].DescriptorTable.pDescriptorRanges = descriptorRanges;
|
|
|
|
|
- descriptorTable[0].DescriptorTable.NumDescriptorRanges = index;
|
|
|
|
|
- index = 1;
|
|
|
|
|
|
|
+ descriptorTable[index].DescriptorTable.pDescriptorRanges
|
|
|
|
|
+ = descriptorRanges[index];
|
|
|
|
|
+ descriptorTable[index].DescriptorTable.NumDescriptorRanges = rangeCount;
|
|
|
|
|
+ index++;
|
|
|
}
|
|
}
|
|
|
for (DX12ShaderRegisterUsage* usage : bindingTableBindings)
|
|
for (DX12ShaderRegisterUsage* usage : bindingTableBindings)
|
|
|
{
|
|
{
|
|
@@ -279,6 +355,21 @@ int Framework::DX12ShaderSignature::gerShaderBindingTableParamCount() const
|
|
|
return shaderBindingTableParamCount;
|
|
return shaderBindingTableParamCount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+bool Framework::DX12ShaderSignature::doesUseGlobalDescriptorHeap() const
|
|
|
|
|
+{
|
|
|
|
|
+ return useGlobalDescriptorHeap;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool Framework::DX12ShaderSignature::doesUseTextureDescriptorHeap() const
|
|
|
|
|
+{
|
|
|
|
|
+ return useTextureDescriptorHeap;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool Framework::DX12ShaderSignature::doesUseSamplerDescriptorHeap() const
|
|
|
|
|
+{
|
|
|
|
|
+ return useSamplerDescriptorHeap;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
Framework::DX12ShaderFunction::DX12ShaderFunction(const Text& functionName,
|
|
Framework::DX12ShaderFunction::DX12ShaderFunction(const Text& functionName,
|
|
|
DX12ShaderSignature* signature,
|
|
DX12ShaderSignature* signature,
|
|
|
DX12ShaderFunctionType functionType)
|
|
DX12ShaderFunctionType functionType)
|
|
@@ -978,9 +1069,11 @@ DX12ShaderBindingTable* Framework::DX12Pipeline::createShaderBindingTable()
|
|
|
return new DX12ShaderBindingTable(dynamic_cast<DX12Pipeline*>(getThis()));
|
|
return new DX12ShaderBindingTable(dynamic_cast<DX12Pipeline*>(getThis()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-DX12GlobalDescriptorHeap* Framework::DX12Pipeline::createGlobalDescriptorHeap()
|
|
|
|
|
|
|
+DX12GlobalDescriptorHeap* Framework::DX12Pipeline::createGlobalDescriptorHeap(
|
|
|
|
|
+ DX12DescriptorHeapType type)
|
|
|
{
|
|
{
|
|
|
- return new DX12GlobalDescriptorHeap(dynamic_cast<DX12Pipeline*>(getThis()));
|
|
|
|
|
|
|
+ return new DX12GlobalDescriptorHeap(
|
|
|
|
|
+ dynamic_cast<DX12Pipeline*>(getThis()), type);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const RCArray<DX12Shader>& Framework::DX12Pipeline::getShaders() const
|
|
const RCArray<DX12Shader>& Framework::DX12Pipeline::getShaders() const
|
|
@@ -1000,12 +1093,13 @@ const RCArray<DX12ShaderHitGroup>& Framework::DX12Pipeline::getHitGroups() const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Framework::DX12GlobalDescriptorHeap::DX12GlobalDescriptorHeap(
|
|
Framework::DX12GlobalDescriptorHeap::DX12GlobalDescriptorHeap(
|
|
|
- DX12Pipeline* pipeline)
|
|
|
|
|
|
|
+ DX12Pipeline* pipeline, DX12DescriptorHeapType type)
|
|
|
: ReferenceCounter(),
|
|
: ReferenceCounter(),
|
|
|
pipeline(pipeline),
|
|
pipeline(pipeline),
|
|
|
descriptorHeap(0),
|
|
descriptorHeap(0),
|
|
|
lastDescriptorHeapSize(0),
|
|
lastDescriptorHeapSize(0),
|
|
|
- zDevice(0)
|
|
|
|
|
|
|
+ zDevice(0),
|
|
|
|
|
+ type(type)
|
|
|
{}
|
|
{}
|
|
|
|
|
|
|
|
Framework::DX12GlobalDescriptorHeap::~DX12GlobalDescriptorHeap()
|
|
Framework::DX12GlobalDescriptorHeap::~DX12GlobalDescriptorHeap()
|
|
@@ -1033,8 +1127,8 @@ void Framework::DX12GlobalDescriptorHeap::addInput(
|
|
|
for (const DX12ShaderRegisterUsage* usage :
|
|
for (const DX12ShaderRegisterUsage* usage :
|
|
|
function->zSignature()->getDescriptorHeapBindings())
|
|
function->zSignature()->getDescriptorHeapBindings())
|
|
|
{
|
|
{
|
|
|
- if (usage->descriptorHeapIndex
|
|
|
|
|
- == registerInputs.getEntryCount())
|
|
|
|
|
|
|
+ if (usage->descriptorHeapIndex == registerInputs.getEntryCount()
|
|
|
|
|
+ && usage->descriptorHeapType == this->type)
|
|
|
{
|
|
{
|
|
|
if (usage->registerType != type)
|
|
if (usage->registerType != type)
|
|
|
{
|
|
{
|
|
@@ -1209,6 +1303,12 @@ void Framework::DX12GlobalDescriptorHeap::updateTLASInput(
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void Framework::DX12GlobalDescriptorHeap::addSamplerInput(
|
|
|
|
|
+ DX12SamplerState* zSampler)
|
|
|
|
|
+{
|
|
|
|
|
+ addInput(DX12_SHADER_REGISTER_S_SAMPLER, zSampler);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
|
|
void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
|
|
|
ID3D12Device5* zDevice)
|
|
ID3D12Device5* zDevice)
|
|
|
{
|
|
{
|
|
@@ -1222,7 +1322,9 @@ void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
|
|
|
}
|
|
}
|
|
|
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
|
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
|
|
desc.NumDescriptors = registerInputs.getEntryCount();
|
|
desc.NumDescriptors = registerInputs.getEntryCount();
|
|
|
- desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
|
|
|
|
|
|
+ desc.Type = type == SAMPLER_DESCRIPTOR_HEAP
|
|
|
|
|
+ ? D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER :
|
|
|
|
|
+ D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
|
|
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
|
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
|
|
desc.NodeMask = 0;
|
|
desc.NodeMask = 0;
|
|
|
|
|
|
|
@@ -1239,6 +1341,8 @@ void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
|
|
|
DX12Texture* zTexture
|
|
DX12Texture* zTexture
|
|
|
= dynamic_cast<DX12Texture*>(input->inputResource);
|
|
= dynamic_cast<DX12Texture*>(input->inputResource);
|
|
|
DX12Buffer* zBuffer = dynamic_cast<DX12Buffer*>(input->inputResource);
|
|
DX12Buffer* zBuffer = dynamic_cast<DX12Buffer*>(input->inputResource);
|
|
|
|
|
+ DX12SamplerState* zSampler
|
|
|
|
|
+ = dynamic_cast<DX12SamplerState*>(input->inputResource);
|
|
|
switch (input->registerType)
|
|
switch (input->registerType)
|
|
|
{
|
|
{
|
|
|
case DX12_SHADER_REGISTER_B_CONST_BUFFER:
|
|
case DX12_SHADER_REGISTER_B_CONST_BUFFER:
|
|
@@ -1278,7 +1382,7 @@ void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
|
|
|
else if (zTexture)
|
|
else if (zTexture)
|
|
|
{
|
|
{
|
|
|
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
|
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
|
|
- srvDesc.Texture2D.MipLevels = 0;
|
|
|
|
|
|
|
+ srvDesc.Texture2D.MipLevels = 1;
|
|
|
srvDesc.Texture2D.MostDetailedMip = 0;
|
|
srvDesc.Texture2D.MostDetailedMip = 0;
|
|
|
srvDesc.Texture2D.PlaneSlice = 0;
|
|
srvDesc.Texture2D.PlaneSlice = 0;
|
|
|
srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;
|
|
srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;
|
|
@@ -1349,6 +1453,21 @@ void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
|
|
|
descriptorHeapHandle);
|
|
descriptorHeapHandle);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+ case DX12_SHADER_REGISTER_S_SAMPLER:
|
|
|
|
|
+ if (zSampler)
|
|
|
|
|
+ {
|
|
|
|
|
+ zDevice->CreateSampler(
|
|
|
|
|
+ zSampler->zSamplerDesc(), descriptorHeapHandle);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ Logging::error()
|
|
|
|
|
+ << "Expected a sampler resource for register type "
|
|
|
|
|
+ << input->registerType;
|
|
|
|
|
+ throw std::logic_error(
|
|
|
|
|
+ "Expected a sampler resource for register type "
|
|
|
|
|
+ + std::to_string(input->registerType));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
descriptorHeapHandle.ptr += zDevice->GetDescriptorHandleIncrementSize(
|
|
descriptorHeapHandle.ptr += zDevice->GetDescriptorHandleIncrementSize(
|
|
|
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
|
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
|
@@ -1372,6 +1491,8 @@ Framework::DX12ShaderBindingTable::DX12ShaderBindingTable(
|
|
|
pipeline(pipeline),
|
|
pipeline(pipeline),
|
|
|
shaderBindingTableBuffer(0),
|
|
shaderBindingTableBuffer(0),
|
|
|
globalDescriptorHeap(0),
|
|
globalDescriptorHeap(0),
|
|
|
|
|
+ textureDescriptorHeap(0),
|
|
|
|
|
+ samplerDescriptorHeap(0),
|
|
|
rayGenRecordSize(0),
|
|
rayGenRecordSize(0),
|
|
|
rayGenCount(0),
|
|
rayGenCount(0),
|
|
|
missRecordSize(0),
|
|
missRecordSize(0),
|
|
@@ -1404,6 +1525,14 @@ Framework::DX12ShaderBindingTable::~DX12ShaderBindingTable()
|
|
|
{
|
|
{
|
|
|
globalDescriptorHeap->release();
|
|
globalDescriptorHeap->release();
|
|
|
}
|
|
}
|
|
|
|
|
+ if (textureDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ textureDescriptorHeap->release();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (samplerDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ samplerDescriptorHeap->release();
|
|
|
|
|
+ }
|
|
|
for (const char* buffer : tempBuffers)
|
|
for (const char* buffer : tempBuffers)
|
|
|
{
|
|
{
|
|
|
delete[] buffer;
|
|
delete[] buffer;
|
|
@@ -1427,6 +1556,40 @@ void Framework::DX12ShaderBindingTable::setGlobalDescriptorHeap(
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void Framework::DX12ShaderBindingTable::setTextureDescriptorHeap(
|
|
|
|
|
+ DX12GlobalDescriptorHeap* zTextureDescriptorHeap)
|
|
|
|
|
+{
|
|
|
|
|
+ if (this->textureDescriptorHeap != zTextureDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (this->textureDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ this->textureDescriptorHeap->release();
|
|
|
|
|
+ }
|
|
|
|
|
+ this->textureDescriptorHeap = zTextureDescriptorHeap;
|
|
|
|
|
+ if (this->textureDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ this->textureDescriptorHeap->getThis();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void Framework::DX12ShaderBindingTable::setSamplerDescriptorHeap(
|
|
|
|
|
+ DX12GlobalDescriptorHeap* zSamplerDescriptorHeap)
|
|
|
|
|
+{
|
|
|
|
|
+ if (this->samplerDescriptorHeap != zSamplerDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (this->samplerDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ this->samplerDescriptorHeap->release();
|
|
|
|
|
+ }
|
|
|
|
|
+ this->samplerDescriptorHeap = zSamplerDescriptorHeap;
|
|
|
|
|
+ if (this->samplerDescriptorHeap)
|
|
|
|
|
+ {
|
|
|
|
|
+ this->samplerDescriptorHeap->getThis();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void Framework::DX12ShaderBindingTable::startUpdate()
|
|
void Framework::DX12ShaderBindingTable::startUpdate()
|
|
|
{
|
|
{
|
|
|
if (shaderBindingTableBuffer)
|
|
if (shaderBindingTableBuffer)
|
|
@@ -1595,19 +1758,35 @@ int Framework::DX12ShaderBindingTable::addHitGroup(
|
|
|
stateObjectProperties->GetShaderIdentifier(
|
|
stateObjectProperties->GetShaderIdentifier(
|
|
|
zHitGroup->zHitGroupDesc()->HitGroupExport),
|
|
zHitGroup->zHitGroupDesc()->HitGroupExport),
|
|
|
D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT);
|
|
D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT);
|
|
|
- if (zHitGroup->zSignature()->getDescriptorHeapBindings().getEntryCount()
|
|
|
|
|
- > 0)
|
|
|
|
|
|
|
+ index += D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT;
|
|
|
|
|
+ if (zHitGroup->zSignature()->doesUseGlobalDescriptorHeap())
|
|
|
{
|
|
{
|
|
|
D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
|
= globalDescriptorHeap->zDescriptorHeap()
|
|
= globalDescriptorHeap->zDescriptorHeap()
|
|
|
->GetGPUDescriptorHandleForHeapStart();
|
|
->GetGPUDescriptorHandleForHeapStart();
|
|
|
- set(index + D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT,
|
|
|
|
|
- &gpuAddress.ptr,
|
|
|
|
|
- sizeof(__int64));
|
|
|
|
|
|
|
+ set(index, &gpuAddress.ptr, sizeof(__int64));
|
|
|
|
|
+ index += sizeof(__int64);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (zHitGroup->zSignature()->doesUseTextureDescriptorHeap())
|
|
|
|
|
+ {
|
|
|
|
|
+ D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
|
|
|
+ = textureDescriptorHeap->zDescriptorHeap()
|
|
|
|
|
+ ->GetGPUDescriptorHandleForHeapStart();
|
|
|
|
|
+ set(index, &gpuAddress.ptr, sizeof(__int64));
|
|
|
|
|
+ index += sizeof(__int64);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (zHitGroup->zSignature()->doesUseSamplerDescriptorHeap())
|
|
|
|
|
+ {
|
|
|
|
|
+ D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
|
|
|
+ = samplerDescriptorHeap->zDescriptorHeap()
|
|
|
|
|
+ ->GetGPUDescriptorHandleForHeapStart();
|
|
|
|
|
+ set(index, &gpuAddress.ptr, sizeof(__int64));
|
|
|
|
|
+ index += sizeof(__int64);
|
|
|
}
|
|
}
|
|
|
hitGroupCount++;
|
|
hitGroupCount++;
|
|
|
nextHitGroupOffset += hitGroupRecordSize;
|
|
nextHitGroupOffset += hitGroupRecordSize;
|
|
|
- return index + D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT;
|
|
|
|
|
|
|
+ return nextHitGroupOffset - hitGroupRecordSize
|
|
|
|
|
+ + D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Framework::DX12ShaderBindingTable::setHitGroupShaderInput(
|
|
void Framework::DX12ShaderBindingTable::setHitGroupShaderInput(
|
|
@@ -1653,17 +1832,30 @@ void Framework::DX12ShaderBindingTable::endUpdate(
|
|
|
stateObjectProperties->GetShaderIdentifier(
|
|
stateObjectProperties->GetShaderIdentifier(
|
|
|
function->zExportDesc()->Name),
|
|
function->zExportDesc()->Name),
|
|
|
D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT);
|
|
D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT);
|
|
|
- if (function->zSignature()
|
|
|
|
|
- ->getDescriptorHeapBindings()
|
|
|
|
|
- .getEntryCount()
|
|
|
|
|
- > 0)
|
|
|
|
|
|
|
+ offset += D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT;
|
|
|
|
|
+ if (function->zSignature()->doesUseGlobalDescriptorHeap())
|
|
|
{
|
|
{
|
|
|
D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
|
= globalDescriptorHeap->zDescriptorHeap()
|
|
= globalDescriptorHeap->zDescriptorHeap()
|
|
|
->GetGPUDescriptorHandleForHeapStart();
|
|
->GetGPUDescriptorHandleForHeapStart();
|
|
|
- set(offset + D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT,
|
|
|
|
|
- &gpuAddress.ptr,
|
|
|
|
|
- sizeof(__int64));
|
|
|
|
|
|
|
+ set(offset, &gpuAddress.ptr, sizeof(__int64));
|
|
|
|
|
+ offset += sizeof(__int64);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (function->zSignature()->doesUseTextureDescriptorHeap())
|
|
|
|
|
+ {
|
|
|
|
|
+ D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
|
|
|
+ = textureDescriptorHeap->zDescriptorHeap()
|
|
|
|
|
+ ->GetGPUDescriptorHandleForHeapStart();
|
|
|
|
|
+ set(offset, &gpuAddress.ptr, sizeof(__int64));
|
|
|
|
|
+ offset += sizeof(__int64);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (function->zSignature()->doesUseSamplerDescriptorHeap())
|
|
|
|
|
+ {
|
|
|
|
|
+ D3D12_GPU_DESCRIPTOR_HANDLE gpuAddress
|
|
|
|
|
+ = samplerDescriptorHeap->zDescriptorHeap()
|
|
|
|
|
+ ->GetGPUDescriptorHandleForHeapStart();
|
|
|
|
|
+ set(offset, &gpuAddress.ptr, sizeof(__int64));
|
|
|
|
|
+ offset += sizeof(__int64);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|