|
|
@@ -3,6 +3,7 @@
|
|
|
#include <DX12Buffer.h>
|
|
|
#include <DX12CommandQueue.h>
|
|
|
#include <DX12Shader.h>
|
|
|
+#include <DX12Texture.h>
|
|
|
#include <DX12TLAS.h>
|
|
|
|
|
|
#include "CustomChunkAnyHitShader.h"
|
|
|
@@ -16,40 +17,76 @@
|
|
|
#include "CustomSimpleBlocksClosestHitShader.h"
|
|
|
#include "Dimension.h"
|
|
|
#include "DX12ChunkData.h"
|
|
|
+#include "World.h"
|
|
|
|
|
|
using namespace Framework;
|
|
|
|
|
|
CustomDX12API::CustomDX12API()
|
|
|
- : DirectX12()
|
|
|
+ : DirectX12(),
|
|
|
+ lightInfoBuffer(0)
|
|
|
{}
|
|
|
|
|
|
-CustomDX12API::~CustomDX12API() {}
|
|
|
+CustomDX12API::~CustomDX12API()
|
|
|
+{
|
|
|
+ if (lightInfoBuffer)
|
|
|
+ {
|
|
|
+ lightInfoBuffer->release();
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void CustomDX12API::initializePipeline()
|
|
|
{
|
|
|
+ if (!lightInfoBuffer)
|
|
|
+ {
|
|
|
+ lightInfoBuffer = new DX12Buffer(sizeof(DX12ShaderLightInfo),
|
|
|
+ device,
|
|
|
+ dynamic_cast<DX12CommandQueue*>(directCommandQueue->getThis()),
|
|
|
+ D3D12_RESOURCE_FLAG_NONE);
|
|
|
+ lightInfoBuffer->setData(&lightInfo, 1);
|
|
|
+ lightInfoBuffer->setLength(sizeof(DX12ShaderLightInfo));
|
|
|
+ }
|
|
|
if (pipeline->getShaders().getEntryCount() == 0)
|
|
|
{ // add default shaders
|
|
|
pipeline->zGlobalSignature()->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
0, DX12_SHADER_REGISTER_S_SAMPLER, 0, 0, SAMPLER_DESCRIPTOR_HEAP);
|
|
|
- pipeline->zGlobalSignature()->addRegisterUsageLinkedToDescriptorHeap(0,
|
|
|
+ pipeline->zGlobalSignature()->addRegisterUsageLinkedToDescriptorHeap(2,
|
|
|
DX12_SHADER_REGISTER_T_SHADER_RESOURCE,
|
|
|
0,
|
|
|
1,
|
|
|
TEXTURE_DESCRIPTOR_HEAP,
|
|
|
1);
|
|
|
+ globalLightBufferOffset
|
|
|
+ = pipeline->zGlobalSignature()
|
|
|
+ ->addRegisterUsageLinkedToShaderBindingTable(
|
|
|
+ DX12_SHADER_REGISTER_B_CONST_BUFFER, 0, 1);
|
|
|
+ globalTLASoffset = pipeline->zGlobalSignature()
|
|
|
+ ->addRegisterUsageLinkedToShaderBindingTable(
|
|
|
+ DX12_SHADER_REGISTER_T_SHADER_RESOURCE, 0);
|
|
|
+ pipeline->zGlobalSignature()->addRegisterUsageLinkedToDescriptorHeap(0,
|
|
|
+ DX12_SHADER_REGISTER_U_UNORDERED_ACCESS,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ TEXTURE_DESCRIPTOR_HEAP);
|
|
|
+ pipeline->zGlobalSignature()->addRegisterUsageLinkedToDescriptorHeap(1,
|
|
|
+ DX12_SHADER_REGISTER_U_UNORDERED_ACCESS,
|
|
|
+ 1,
|
|
|
+ 0,
|
|
|
+ TEXTURE_DESCRIPTOR_HEAP);
|
|
|
+ globalRayGenerationSettingsOffset
|
|
|
+ = pipeline->zGlobalSignature()
|
|
|
+ ->addRegisterUsageLinkedToShaderBindingTable(
|
|
|
+ DX12_SHADER_REGISTER_B_CONST_BUFFER, 0);
|
|
|
|
|
|
DX12Shader* rayGenShader = new DX12Shader(
|
|
|
CustomCustomRayGenShader, sizeof(CustomCustomRayGenShader));
|
|
|
// RayGen from RayGen.hlsl
|
|
|
DX12ShaderSignature* rayGenSignature = new DX12ShaderSignature();
|
|
|
- rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
- 0, DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, 0);
|
|
|
- rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
- 1, DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, 1);
|
|
|
- rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
- 2, DX12_SHADER_REGISTER_B_CONST_BUFFER, 0);
|
|
|
- rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
- 3, DX12_SHADER_REGISTER_T_SHADER_RESOURCE, 0);
|
|
|
+ // rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
+ // 0, DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, 0);
|
|
|
+ // rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
+ // 1, DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, 1);
|
|
|
+ // rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
|
|
|
+ // 2, DX12_SHADER_REGISTER_B_CONST_BUFFER, 0);
|
|
|
defaultRayGenerationShaderFunction = new DX12ShaderFunction(
|
|
|
"RayGen", rayGenSignature, DX12_SHADER_FUNCTION_TYPE_RAY_GEN);
|
|
|
rayGenShader->addFunction(defaultRayGenerationShaderFunction);
|
|
|
@@ -208,11 +245,6 @@ void CustomDX12API::initializePipeline()
|
|
|
pipeline->createPipelineState(device, pfnD3D12SerializeRootSignature);
|
|
|
}
|
|
|
|
|
|
-void CustomDX12API::initializeGlobalDescriptorHeap()
|
|
|
-{
|
|
|
- DirectX12::initializeGlobalDescriptorHeap();
|
|
|
-}
|
|
|
-
|
|
|
void CustomDX12API::fillShaderBindingTable(
|
|
|
Framework::DX12ShaderBindingTable* zShaderBindingTable,
|
|
|
Framework::Model3D* zModel,
|
|
|
@@ -224,6 +256,35 @@ void CustomDX12API::fillShaderBindingTable(
|
|
|
zShaderBindingTable, zModel, objectIndex, zBLAS, lastHitGroupIndex);
|
|
|
}
|
|
|
|
|
|
+int CustomDX12API::fillGlobalShaderParams(
|
|
|
+ Cam3D* zCam, DX12TLAS* zTLAS, DX12Texture* zTarget, int startIndex)
|
|
|
+{
|
|
|
+ if (World::INSTANCE)
|
|
|
+ {
|
|
|
+ lightInfo.dayLightFactor = World::INSTANCE->getDayLightFactor();
|
|
|
+ lightInfo.dayLightDirection = World::INSTANCE->getDayLightDirection();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lightInfo.dayLightFactor = Vec3<float>(1.f, 1.f, 1.f);
|
|
|
+ lightInfo.dayLightDirection = Vec3<float>(0.f, 0.f, -1.f);
|
|
|
+ }
|
|
|
+ lightInfoBuffer->setChanged();
|
|
|
+ lightInfoBuffer->copyToGPU();
|
|
|
+ int result
|
|
|
+ = DirectX12::fillGlobalShaderParams(zCam, zTLAS, zTarget, startIndex);
|
|
|
+ directCommandQueue->zCommandList()->SetComputeRootConstantBufferView(
|
|
|
+ *globalLightBufferOffset,
|
|
|
+ lightInfoBuffer->zBuffer()->GetGPUVirtualAddress());
|
|
|
+ directCommandQueue->zCommandList()->SetComputeRootShaderResourceView(
|
|
|
+ *globalTLASoffset,
|
|
|
+ zTLAS->zResultBuffer()->zBuffer()->GetGPUVirtualAddress());
|
|
|
+ directCommandQueue->zCommandList()->SetComputeRootConstantBufferView(
|
|
|
+ *globalRayGenerationSettingsOffset,
|
|
|
+ rayGenSettingsBuffer->zBuffer()->GetGPUVirtualAddress());
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
void CustomDX12API::renderWorld(Framework::World3D* zWorld,
|
|
|
DX12TLAS* zTLAS,
|
|
|
DX12ShaderBindingTable* zSBT,
|
|
|
@@ -353,3 +414,12 @@ void CustomDX12API::renderWorld(Framework::World3D* zWorld,
|
|
|
}
|
|
|
DirectX12::renderWorld(zWorld, zTLAS, zSBT, objectIndex);
|
|
|
}
|
|
|
+
|
|
|
+void CustomDX12API::initializeTextureDescriptorHeap()
|
|
|
+{
|
|
|
+ textureDescriptorHeap->addTextureInput(
|
|
|
+ DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, defaultRenderTarget);
|
|
|
+ textureDescriptorHeap->addTextureInput(
|
|
|
+ DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, uiTexture);
|
|
|
+ DirectX12::initializeTextureDescriptorHeap();
|
|
|
+}
|