|
|
@@ -1,5 +1,6 @@
|
|
|
#include "DX12Shader.h"
|
|
|
|
|
|
+#include "DX12CommandQueue.h"
|
|
|
#include "DX12Texture.h"
|
|
|
#include "DX12TLAS.h"
|
|
|
#include "Logging.h"
|
|
|
@@ -160,9 +161,9 @@ void Framework::DX12ShaderSignature::createSignature(ID3D12Device5* zDevice,
|
|
|
D3D12_DESCRIPTOR_RANGE* descriptorRanges = 0;
|
|
|
if (descriptorHeapBindings.getEntryCount())
|
|
|
{
|
|
|
- descriptorTable[index].ParameterType
|
|
|
+ descriptorTable[0].ParameterType
|
|
|
= D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
|
|
|
- descriptorTable[index].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
|
|
|
+ descriptorTable[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
|
|
|
descriptorRanges = new D3D12_DESCRIPTOR_RANGE[descriptorHeapBindings
|
|
|
.getEntryCount()];
|
|
|
ArrayIterator<DX12ShaderRegisterUsage*> it
|
|
|
@@ -183,6 +184,9 @@ void Framework::DX12ShaderSignature::createSignature(ID3D12Device5* zDevice,
|
|
|
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
|
|
|
break;
|
|
|
}
|
|
|
+ range.BaseShaderRegister = it->registerIndex;
|
|
|
+ range.OffsetInDescriptorsFromTableStart = it->descriptorHeapIndex;
|
|
|
+ range.RegisterSpace = it->spaceIndex;
|
|
|
ArrayIterator<DX12ShaderRegisterUsage*> next = it.next();
|
|
|
int size = 1;
|
|
|
while (
|
|
|
@@ -197,15 +201,11 @@ void Framework::DX12ShaderSignature::createSignature(ID3D12Device5* zDevice,
|
|
|
++next;
|
|
|
}
|
|
|
range.NumDescriptors = size;
|
|
|
- range.BaseShaderRegister = it->registerIndex;
|
|
|
- range.RegisterSpace = it->spaceIndex;
|
|
|
- range.OffsetInDescriptorsFromTableStart = it->descriptorHeapIndex;
|
|
|
++it;
|
|
|
++index;
|
|
|
}
|
|
|
- descriptorTable[index].DescriptorTable.pDescriptorRanges
|
|
|
- = descriptorRanges;
|
|
|
- descriptorTable[index].DescriptorTable.NumDescriptorRanges = index;
|
|
|
+ descriptorTable[0].DescriptorTable.pDescriptorRanges = descriptorRanges;
|
|
|
+ descriptorTable[0].DescriptorTable.NumDescriptorRanges = index;
|
|
|
index = 1;
|
|
|
}
|
|
|
for (DX12ShaderRegisterUsage* usage : bindingTableBindings)
|
|
|
@@ -288,7 +288,11 @@ Framework::DX12ShaderFunction::DX12ShaderFunction(const Text& functionName,
|
|
|
exportDesc(new D3D12_EXPORT_DESC())
|
|
|
{
|
|
|
wchar_t* wc = new wchar_t[functionName.getLength() + 1];
|
|
|
- mbtowc(wc, functionName.getText(), functionName.getLength() + 1);
|
|
|
+ mbstowcs_s(0,
|
|
|
+ wc,
|
|
|
+ functionName.getLength() + 1,
|
|
|
+ functionName.getText(),
|
|
|
+ functionName.getLength() + 1);
|
|
|
wc[functionName.getLength()] = 0;
|
|
|
exportDesc->Name = wc;
|
|
|
exportDesc->ExportToRename = 0;
|
|
|
@@ -393,7 +397,8 @@ Framework::DX12ShaderHitGroup::DX12ShaderHitGroup(const Text name)
|
|
|
hitGroupDesc(new D3D12_HIT_GROUP_DESC())
|
|
|
{
|
|
|
wchar_t* wc = new wchar_t[name.getLength() + 1];
|
|
|
- mbtowc(wc, name.getText(), name.getLength() + 1);
|
|
|
+ mbstowcs_s(
|
|
|
+ 0, wc, name.getLength() + 1, name.getText(), name.getLength() + 1);
|
|
|
wc[name.getLength()] = 0;
|
|
|
hitGroupDesc->HitGroupExport = wc;
|
|
|
hitGroupDesc->IntersectionShaderImport = 0;
|
|
|
@@ -714,7 +719,7 @@ void Framework::DX12Pipeline::createPipelineState(ID3D12Device5* zDevice,
|
|
|
pSigBlob->GetBufferPointer(),
|
|
|
pSigBlob->GetBufferSize(),
|
|
|
__uuidof(ID3D12RootSignature),
|
|
|
- (void**)&emptyGlobalRootSignature);
|
|
|
+ (void**)&emptyLocalRootSignature);
|
|
|
pSigBlob->Release();
|
|
|
}
|
|
|
if (pErrorBlob)
|
|
|
@@ -996,8 +1001,10 @@ const RCArray<DX12ShaderHitGroup>& Framework::DX12Pipeline::getHitGroups() const
|
|
|
Framework::DX12GlobalDescriptorHeap::DX12GlobalDescriptorHeap(
|
|
|
DX12Pipeline* pipeline)
|
|
|
: ReferenceCounter(),
|
|
|
+ pipeline(pipeline),
|
|
|
descriptorHeap(0),
|
|
|
- lastDescriptorHeapSize(0)
|
|
|
+ lastDescriptorHeapSize(0),
|
|
|
+ zDevice(0)
|
|
|
{}
|
|
|
|
|
|
Framework::DX12GlobalDescriptorHeap::~DX12GlobalDescriptorHeap()
|
|
|
@@ -1069,6 +1076,70 @@ void Framework::DX12GlobalDescriptorHeap::addTextureInput(
|
|
|
addInput(type, zTexture);
|
|
|
}
|
|
|
|
|
|
+void Framework::DX12GlobalDescriptorHeap::updateTextureInput(
|
|
|
+ int heapIndex, DX12ShaderRegister type, Texture* zTexture)
|
|
|
+{
|
|
|
+ DX12ShaderRegisterInput* input = registerInputs.get(heapIndex);
|
|
|
+ if (registerInputs.get(heapIndex)->inputResource
|
|
|
+ != dynamic_cast<ReferenceCounter*>(zTexture))
|
|
|
+ {
|
|
|
+ if (input->registerType != type)
|
|
|
+ {
|
|
|
+ Logging::error()
|
|
|
+ << "Register type mismatch for descriptor heap index "
|
|
|
+ << heapIndex
|
|
|
+ << ". Expected register type: " << input->registerType
|
|
|
+ << ", given register type: " << type << ".";
|
|
|
+ throw std::logic_error("Register type mismatch in descriptor heap");
|
|
|
+ }
|
|
|
+ registerInputs.get(heapIndex)->inputResource->release();
|
|
|
+ registerInputs.get(heapIndex)->inputResource = zTexture->getThis();
|
|
|
+ if (descriptorHeap)
|
|
|
+ {
|
|
|
+ D3D12_CPU_DESCRIPTOR_HANDLE descriptorHeapHandle
|
|
|
+ = descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
|
|
+ descriptorHeapHandle.ptr
|
|
|
+ += zDevice->GetDescriptorHandleIncrementSize(
|
|
|
+ D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV)
|
|
|
+ * heapIndex;
|
|
|
+ switch (input->registerType)
|
|
|
+ {
|
|
|
+ case DX12_SHADER_REGISTER_T_SHADER_RESOURCE:
|
|
|
+ {
|
|
|
+ D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
|
|
+ srvDesc.Format = DXGI_FORMAT_UNKNOWN;
|
|
|
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
|
|
+ srvDesc.Texture2D.MipLevels = 0;
|
|
|
+ srvDesc.Texture2D.MostDetailedMip = 0;
|
|
|
+ srvDesc.Texture2D.PlaneSlice = 0;
|
|
|
+ srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;
|
|
|
+ srvDesc.Shader4ComponentMapping
|
|
|
+ = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
|
|
+ zDevice->CreateShaderResourceView(
|
|
|
+ ((DX12Texture*)zTexture)->zResource(),
|
|
|
+ &srvDesc,
|
|
|
+ descriptorHeapHandle);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case DX12_SHADER_REGISTER_U_UNORDERED_ACCESS:
|
|
|
+ {
|
|
|
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
|
|
|
+ uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
|
|
|
+ uavDesc.Format = DXGI_FORMAT_UNKNOWN;
|
|
|
+ uavDesc.Texture2D.MipSlice = 0;
|
|
|
+ uavDesc.Texture2D.PlaneSlice = 0;
|
|
|
+ zDevice->CreateUnorderedAccessView(
|
|
|
+ ((DX12Texture*)zTexture)->zResource(),
|
|
|
+ 0,
|
|
|
+ &uavDesc,
|
|
|
+ descriptorHeapHandle);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void Framework::DX12GlobalDescriptorHeap::addBufferInput(
|
|
|
DX12ShaderRegister type, DXBuffer* zBuffer)
|
|
|
{
|
|
|
@@ -1084,6 +1155,7 @@ void Framework::DX12GlobalDescriptorHeap::addTLASInput(
|
|
|
void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
|
|
|
ID3D12Device5* zDevice)
|
|
|
{
|
|
|
+ this->zDevice = zDevice;
|
|
|
if (!descriptorHeap
|
|
|
|| lastDescriptorHeapSize != registerInputs.getEntryCount())
|
|
|
{
|
|
|
@@ -1360,8 +1432,10 @@ void Framework::DX12ShaderBindingTable::startUpdate()
|
|
|
hitGroupRecordSize = ROUND_UP_POWER_OF_2(
|
|
|
D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT + hitGroupRecordSize * 8,
|
|
|
D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT);
|
|
|
- nextHitGroupOffset
|
|
|
- = rayGenRecordSize * rayGenCount + missRecordSize * missCount;
|
|
|
+ nextHitGroupOffset = ROUND_UP_POWER_OF_2(
|
|
|
+ rayGenRecordSize * rayGenCount + missRecordSize * missCount
|
|
|
+ + callableRecordSize * callableCount,
|
|
|
+ 64);
|
|
|
}
|
|
|
|
|
|
void Framework::DX12ShaderBindingTable::set(int index, void* data, int size)
|
|
|
@@ -1374,12 +1448,12 @@ void Framework::DX12ShaderBindingTable::set(int index, void* data, int size)
|
|
|
{
|
|
|
index -= tableBufferSize;
|
|
|
ArrayIterator<char*> it = tempBuffers.begin();
|
|
|
- while (it && 2048 >= index + size)
|
|
|
+ while (it && 2048 < index + size)
|
|
|
{
|
|
|
index -= 2048;
|
|
|
it++;
|
|
|
}
|
|
|
- while (2048 >= index + size)
|
|
|
+ while (2048 < index + size)
|
|
|
{
|
|
|
char* newBuffer = new char[2048];
|
|
|
memset(newBuffer, 0, 2048);
|
|
|
@@ -1475,7 +1549,8 @@ void Framework::DX12ShaderBindingTable::setHitGroupShaderInput(
|
|
|
sizeof(__int64));
|
|
|
}
|
|
|
|
|
|
-void Framework::DX12ShaderBindingTable::endUpdate(ID3D12Device5* zDevice)
|
|
|
+void Framework::DX12ShaderBindingTable::endUpdate(
|
|
|
+ ID3D12Device5* zDevice, DX12CommandQueue* zQueue)
|
|
|
{
|
|
|
int rayTracingIndex = 0;
|
|
|
int missIndex = 0;
|
|
|
@@ -1525,8 +1600,10 @@ void Framework::DX12ShaderBindingTable::endUpdate(ID3D12Device5* zDevice)
|
|
|
}
|
|
|
if (nextHitGroupOffset > tableBufferSize)
|
|
|
{
|
|
|
- DX12Buffer* newBuffer
|
|
|
- = new DX12Buffer(1, zDevice, D3D12_RESOURCE_FLAG_NONE);
|
|
|
+ DX12Buffer* newBuffer = new DX12Buffer(1,
|
|
|
+ zDevice,
|
|
|
+ dynamic_cast<DX12CommandQueue*>(zQueue->getThis()),
|
|
|
+ D3D12_RESOURCE_FLAG_NONE);
|
|
|
newBuffer->setLength(ROUND_UP_POWER_OF_2(nextHitGroupOffset, 256));
|
|
|
newBuffer->createBufferWithoutData(
|
|
|
D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_HEAP_TYPE_UPLOAD);
|
|
|
@@ -1584,16 +1661,20 @@ void Framework::DX12ShaderBindingTable::fillDispatchRaysDesc(
|
|
|
= hitGroupCount * hitGroupRecordSize;
|
|
|
dispatchRaysDesc->HitGroupTable.StartAddress
|
|
|
= shaderBindingTableBuffer->zBuffer()->GetGPUVirtualAddress()
|
|
|
- + rayGenCount * rayGenRecordSize + missCount * missRecordSize;
|
|
|
+ + ROUND_UP_POWER_OF_2(rayGenCount * rayGenRecordSize
|
|
|
+ + missCount * missRecordSize
|
|
|
+ + callableCount * callableRecordSize,
|
|
|
+ 64);
|
|
|
dispatchRaysDesc->HitGroupTable.StrideInBytes = hitGroupRecordSize;
|
|
|
|
|
|
dispatchRaysDesc->CallableShaderTable.SizeInBytes
|
|
|
= callableCount * callableRecordSize;
|
|
|
dispatchRaysDesc->CallableShaderTable.StartAddress
|
|
|
- = shaderBindingTableBuffer->zBuffer()->GetGPUVirtualAddress()
|
|
|
- + rayGenCount * rayGenRecordSize + missCount * missRecordSize
|
|
|
- + hitGroupCount * hitGroupRecordSize;
|
|
|
- dispatchRaysDesc->CallableShaderTable.StrideInBytes = callableRecordSize;
|
|
|
+ = callableCount > 0 ? shaderBindingTableBuffer->zBuffer()
|
|
|
+ ->GetGPUVirtualAddress()
|
|
|
+ + rayGenCount * rayGenRecordSize + missCount * missRecordSize : 0;
|
|
|
+ dispatchRaysDesc->CallableShaderTable.StrideInBytes
|
|
|
+ = callableCount > 0 ? callableRecordSize : 0;
|
|
|
}
|
|
|
|
|
|
DX12Pipeline* Framework::DX12ShaderBindingTable::zPipeline() const
|