Skip to content

Commit

Permalink
added indirect rendering support to DX12 (same passes as on DX11: Gbu…
Browse files Browse the repository at this point in the history
…ffer, Shadow, Forward for now):

- implemented ER_RHI_DX12::DrawIndexedInstancedIndirect with ExecuteIndirect()
- added missing root signatures in ER_GPUCuller.cpp
- added SRV descriptor split for vertex and pixel tables (in Gbuffer, Shadow, Forward root signatures)
- added root constant for LOD index retrieval (added rhi->SetRootConstant(); ER_Material::SetRootConstantForMaterial() with overrides in some materials)
- removed lod index from ObjectCB (replaced with aforementioned root constant); this probably breaks DX11 a bit
- added fixes in ER_RHI_DX12_GPUBuffer.cpp for making indirect args buffer work without errors
  • Loading branch information
steaklive committed Jul 2, 2023
1 parent 8c3ceef commit b78824a
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 37 deletions.
1 change: 0 additions & 1 deletion content/shaders/Common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ cbuffer ObjectCBuffer : register(b1)
float CustomRoughness;
float CustomMetalness;
float OriginalInstanceCount;
float CurrentLod;
float IsIndirectlyRendered;
};

Expand Down
7 changes: 6 additions & 1 deletion content/shaders/ForwardLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ cbuffer LightProbesCBuffer : register(b2)
float DistanceBetweenSpecularProbes;
}

cbuffer RootConstant : register(b3)
{
uint CurrentLod;
}

struct VS_INPUT
{
float4 Position : POSITION;
Expand Down Expand Up @@ -138,7 +143,7 @@ VS_OUTPUT VSMain_instancing(VS_INPUT_INSTANCING IN)
VS_OUTPUT OUT = (VS_OUTPUT) 0;

float4x4 World = IsIndirectlyRendered > 0.0 ?
transpose(IndirectInstanceData[(int)OriginalInstanceCount * (int)CurrentLod + IN.InstanceID].WorldMat) : IN.World;
transpose(IndirectInstanceData[(int)OriginalInstanceCount * CurrentLod + IN.InstanceID].WorldMat) : IN.World;

OUT.WorldPos = mul(IN.Position, World).xyz;
OUT.Position = mul(float4(OUT.WorldPos, 1.0f), ViewProjection);
Expand Down
7 changes: 6 additions & 1 deletion content/shaders/GBuffer.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ cbuffer GBufferCBuffer : register(b0)
}
// register(b1) is objects cbuffer from Common.hlsli

cbuffer RootConstant : register(b2)
{
uint CurrentLod;
}

SamplerState Sampler : register(s0);

struct VS_INPUT
Expand Down Expand Up @@ -75,7 +80,7 @@ VS_OUTPUT VSMain_instancing(VS_INPUT_INSTANCING IN)
VS_OUTPUT OUT = (VS_OUTPUT) 0;

float4x4 World = IsIndirectlyRendered > 0.0 ?
transpose(IndirectInstanceData[(int)OriginalInstanceCount * (int)CurrentLod + IN.InstanceID].WorldMat) : IN.World;
transpose(IndirectInstanceData[(int)OriginalInstanceCount * CurrentLod + IN.InstanceID].WorldMat) : IN.World;
OUT.WorldPos = mul(IN.ObjectPosition, World).xyz;
OUT.Position = mul(float4(OUT.WorldPos, 1.0f), ViewProjection);
OUT.Normal = normalize(mul(float4(IN.Normal, 0), World).xyz);
Expand Down
7 changes: 6 additions & 1 deletion content/shaders/ShadowMap.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ cbuffer ShadowMapCBuffer : register(b0)
}
// register(b1) is objects cbuffer from Common.hlsli

cbuffer RootConstant : register(b2)
{
uint CurrentLod;
}

struct VS_INPUT
{
float4 Position : POSITION;
Expand Down Expand Up @@ -64,7 +69,7 @@ VS_OUTPUT VSMain_instancing(VS_INPUT_INSTANCING IN)
VS_OUTPUT OUT = (VS_OUTPUT) 0;

float4x4 World = IsIndirectlyRendered > 0.0 ?
transpose(IndirectInstanceData[(int)OriginalInstanceCount * (int)CurrentLod + IN.InstanceID].WorldMat) : IN.World;
transpose(IndirectInstanceData[(int)OriginalInstanceCount * CurrentLod + IN.InstanceID].WorldMat) : IN.World;
float3 WorldPos = mul(IN.Position, World).xyz;
OUT.Position = mul(float4(WorldPos, 1.0f), LightViewProjection);
OUT.Depth = OUT.Position.zw;
Expand Down
6 changes: 4 additions & 2 deletions source/EveryRay_Core/ER_GBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ namespace EveryRay_Core {
mDepthBuffer = rhi->CreateGPUTexture(L"ER_RHI_GPUTexture: GBuffer Depth");
mDepthBuffer->CreateGPUTextureResource(rhi, mWidth, mHeight, 1, ER_FORMAT_D24_UNORM_S8_UINT, ER_BIND_SHADER_RESOURCE | ER_BIND_DEPTH_STENCIL);

mRootSignature = rhi->CreateRootSignature(2, 1);
mRootSignature = rhi->CreateRootSignature(4, 1);
if (mRootSignature)
{
mRootSignature->InitStaticSampler(rhi, 0, ER_RHI_SAMPLER_STATE::ER_TRILINEAR_WRAP, ER_RHI_SHADER_VISIBILITY_PIXEL);
mRootSignature->InitDescriptorTable(rhi, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 0 }, { 7 }, ER_RHI_SHADER_VISIBILITY_ALL);
mRootSignature->InitDescriptorTable(rhi, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 0 }, { 6 }, ER_RHI_SHADER_VISIBILITY_PIXEL);
mRootSignature->InitDescriptorTable(rhi, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 6 }, { 1 }, ER_RHI_SHADER_VISIBILITY_VERTEX);
mRootSignature->InitDescriptorTable(rhi, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_CBV }, { 0 }, { 2 }, ER_RHI_SHADER_VISIBILITY_ALL);
mRootSignature->InitConstant(rhi, GBUFFER_MAT_ROOT_CONSTANT_INDEX, 2 /*we already use 2 slots for CBVs*/, 1 /* only 1 constant for LOD index*/, ER_RHI_SHADER_VISIBILITY_ALL);
mRootSignature->Finalize(rhi, "ER_RHI_GPURootSignature: GBufferMaterial Pass", true);
}
}
Expand Down
10 changes: 8 additions & 2 deletions source/EveryRay_Core/ER_GBufferMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,24 @@ namespace EveryRay_Core
resources.push_back(aObj->GetTextureData(meshIndex).MetallicMap);
resources.push_back(aObj->GetTextureData(meshIndex).HeightMap);
resources.push_back(aObj->GetTextureData(meshIndex).ReflectionMaskMap);
rhi->SetShaderResources(ER_PIXEL, resources, 0, rs, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetShaderResources(ER_PIXEL, resources, 0, rs, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX);
rhi->SetSamplers(ER_PIXEL, { ER_RHI_SAMPLER_STATE::ER_TRILINEAR_WRAP }, 0, rs);

if (aObj->IsIndirectlyRendered())
rhi->SetShaderResources(ER_VERTEX, { aObj->GetIndirectNewInstanceBuffer() }, static_cast<int>(resources.size()), rs, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetShaderResources(ER_VERTEX, { aObj->GetIndirectNewInstanceBuffer() }, static_cast<int>(resources.size()), rs, GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX);
}

void ER_GBufferMaterial::PrepareResourcesForStandardMaterial(ER_MaterialSystems neededSystems, ER_RenderingObject* aObj, int meshIndex, ER_RHI_GPURootSignature* rs)
{
//not used because this material is not standard
}

void ER_GBufferMaterial::SetRootConstantForMaterial(UINT a32BitConstant)
{
auto rhi = ER_Material::GetCore()->GetRHI();
rhi->SetRootConstant(a32BitConstant, GBUFFER_MAT_ROOT_CONSTANT_INDEX);
}

void ER_GBufferMaterial::CreateVertexBuffer(const ER_Mesh& mesh, ER_RHI_GPUBuffer* vertexBuffer)
{
mesh.CreateVertexBuffer_PositionUvNormalTangent(vertexBuffer);
Expand Down
7 changes: 5 additions & 2 deletions source/EveryRay_Core/ER_GBufferMaterial.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once
#include "ER_Material.h"

#define GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX 0
#define GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 1
#define GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX 0
#define GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX 1
#define GBUFFER_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 2
#define GBUFFER_MAT_ROOT_CONSTANT_INDEX 3

namespace EveryRay_Core
{
Expand All @@ -26,6 +28,7 @@ namespace EveryRay_Core

void PrepareForRendering(ER_MaterialSystems neededSystems, ER_RenderingObject* aObj, int meshIndex, ER_RHI_GPURootSignature* rs);
virtual void PrepareResourcesForStandardMaterial(ER_MaterialSystems neededSystems, ER_RenderingObject* aObj, int meshIndex, ER_RHI_GPURootSignature* rs) override;
virtual void SetRootConstantForMaterial(UINT a32BitConstant) override; // We use root constant for LOD index in this material
virtual void CreateVertexBuffer(const ER_Mesh& mesh, ER_RHI_GPUBuffer* vertexBuffer) override;
virtual int VertexSize() override;

Expand Down
20 changes: 19 additions & 1 deletion source/EveryRay_Core/ER_GPUCuller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#define GPU_CULL_CLEAR_PASS_ROOT_DESCRIPTOR_TABLE_UAV_INDEX 0
#define GPU_CULL_CLEAR_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 1

namespace EveryRay_Core
{

Expand All @@ -31,6 +32,7 @@ namespace EveryRay_Core
DeleteObject(mIndirectCullingCS);
DeleteObject(mIndirectCullingRS);
DeleteObject(mIndirectCullingClearCS);
DeleteObject(mIndirectCullingClearRS);

mMeshConstantBuffer.Release();
mCameraConstantBuffer.Release();
Expand All @@ -45,7 +47,23 @@ namespace EveryRay_Core
mIndirectCullingClearCS = rhi->CreateGPUShader();
mIndirectCullingClearCS->CompileShader(rhi, "content\\shaders\\IndirectCullingClear.hlsl", "CSMain", ER_COMPUTE);

//TODO root signature
//root signatures
mIndirectCullingRS = rhi->CreateRootSignature(3, 0);
if (mIndirectCullingRS)
{
mIndirectCullingRS->InitDescriptorTable(rhi, GPU_CULL_PASS_ROOT_DESCRIPTOR_TABLE_UAV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_UAV }, { 0 }, { 2 });
mIndirectCullingRS->InitDescriptorTable(rhi, GPU_CULL_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 0 }, { 1 });
mIndirectCullingRS->InitDescriptorTable(rhi, GPU_CULL_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_CBV }, { 0 }, { 2 });
mIndirectCullingRS->Finalize(rhi, "ER_RHI_GPURootSignature: Indirect Culling Main");
}

mIndirectCullingClearRS = rhi->CreateRootSignature(2, 0);
if (mIndirectCullingClearRS)
{
mIndirectCullingClearRS->InitDescriptorTable(rhi, GPU_CULL_CLEAR_PASS_ROOT_DESCRIPTOR_TABLE_UAV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_UAV }, { 0 }, { 1 });
mIndirectCullingClearRS->InitDescriptorTable(rhi, GPU_CULL_CLEAR_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_CBV }, { 0 }, { 1 });
mIndirectCullingClearRS->Finalize(rhi, "ER_RHI_GPURootSignature: Indirect Culling Clear");
}

//cbuffers
mMeshConstantBuffer.Initialize(rhi, "ER_RHI_GPUBuffer: GPU Culler Mesh CB");
Expand Down
18 changes: 12 additions & 6 deletions source/EveryRay_Core/ER_Illumination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ static const std::string voxelizationPSONames[NUM_VOXEL_GI_CASCADES] =
#define DEFERRED_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_UAV_INDEX 1
#define DEFERRED_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 2

#define FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX 0
#define FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 1
#define FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX 0
#define FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX 1
#define FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 2
#define FORWARD_LIGHTING_PASS_ROOT_CONSTANT_INDEX 3

#define COMPOSITE_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX 0
#define COMPOSITE_PASS_ROOT_DESCRIPTOR_TABLE_UAV_INDEX 1
Expand Down Expand Up @@ -318,14 +320,16 @@ namespace EveryRay_Core {
mDeferredLightingRS->Finalize(rhi, "ER_RHI_GPURootSignature: Deferred Lighting Pass");
}

mForwardLightingRS = rhi->CreateRootSignature(2, 3);
mForwardLightingRS = rhi->CreateRootSignature(4, 3);
if (mForwardLightingRS)
{
mForwardLightingRS->InitStaticSampler(rhi, 0, ER_RHI_SAMPLER_STATE::ER_TRILINEAR_WRAP, ER_RHI_SHADER_VISIBILITY_PIXEL);
mForwardLightingRS->InitStaticSampler(rhi, 1, ER_RHI_SAMPLER_STATE::ER_SHADOW_SS, ER_RHI_SHADER_VISIBILITY_PIXEL);
mForwardLightingRS->InitStaticSampler(rhi, 2, ER_RHI_SAMPLER_STATE::ER_TRILINEAR_CLAMP, ER_RHI_SHADER_VISIBILITY_PIXEL);
mForwardLightingRS->InitDescriptorTable(rhi, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 0 }, { 19 }, ER_RHI_SHADER_VISIBILITY_ALL);
mForwardLightingRS->InitDescriptorTable(rhi, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 0 }, { 18 }, ER_RHI_SHADER_VISIBILITY_PIXEL);
mForwardLightingRS->InitDescriptorTable(rhi, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 18 }, { 1 }, ER_RHI_SHADER_VISIBILITY_VERTEX);
mForwardLightingRS->InitDescriptorTable(rhi, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_CBV }, { 0 }, { 3 }, ER_RHI_SHADER_VISIBILITY_ALL);
mForwardLightingRS->InitConstant(rhi, FORWARD_LIGHTING_PASS_ROOT_CONSTANT_INDEX, 3 /*we already use 3 slots for CBVs*/, 1 /* only 1 constant for LOD index*/, ER_RHI_SHADER_VISIBILITY_ALL);
mForwardLightingRS->Finalize(rhi, "ER_RHI_GPURootSignature: Forward Lighting Pass", true);
}

Expand Down Expand Up @@ -983,11 +987,13 @@ namespace EveryRay_Core {
resources[15] = mProbesManager->IsEnabled() ? mProbesManager->GetSpecularProbesTexArrayIndicesBuffer() : nullptr;
resources[16] = mProbesManager->IsEnabled() ? mProbesManager->GetSpecularProbesPositionsBuffer() : nullptr;
resources[17] = mProbesManager->GetIntegrationMap();
rhi->SetShaderResources(ER_PIXEL, resources, 0, mForwardLightingRS, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetShaderResources(ER_PIXEL, resources, 0, mForwardLightingRS, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX);
}

if (aObj->IsIndirectlyRendered())
rhi->SetShaderResources(ER_VERTEX, { aObj->GetIndirectNewInstanceBuffer() }, static_cast<int>(resources.size()), mForwardLightingRS, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetShaderResources(ER_VERTEX, { aObj->GetIndirectNewInstanceBuffer() }, static_cast<int>(resources.size()), mForwardLightingRS, FORWARD_LIGHTING_PASS_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX);

rhi->SetRootConstant(static_cast<UINT>(lod), FORWARD_LIGHTING_PASS_ROOT_CONSTANT_INDEX);

// we unset PSO after all objects are rendered
}
Expand Down
1 change: 1 addition & 0 deletions source/EveryRay_Core/ER_Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace EveryRay_Core

// This method has to be overriden in standard material classes (not special like shadow map material, etc.) and can be used as a callback if bound to ER_RenderingObject
virtual void PrepareResourcesForStandardMaterial(ER_MaterialSystems neededSystems, ER_RenderingObject* aObj, int meshIndex, ER_RHI_GPURootSignature* rs) = 0;
virtual void SetRootConstantForMaterial(UINT a32BitRootConstant) { }; // nothing here, override in specific materials
virtual void CreateVertexBuffer(const ER_Mesh& mesh, ER_RHI_GPUBuffer* vertexBuffer) = 0;
virtual int VertexSize() = 0;

Expand Down
8 changes: 5 additions & 3 deletions source/EveryRay_Core/ER_RenderingObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ namespace EveryRay_Core
mObjectConstantBuffer.Data.CustomRoughness = mCustomRoughness;
mObjectConstantBuffer.Data.CustomMetalness = mCustomMetalness;
mObjectConstantBuffer.Data.OriginalInstanceCount = mInstanceCount;
mObjectConstantBuffer.Data.CurrentLod = lod;
mObjectConstantBuffer.Data.IsIndirectlyRendered = mIsIndirectlyRendered ? 1.0f : 0.0f;
mObjectConstantBuffer.ApplyChanges(rhi);

Expand All @@ -460,7 +459,7 @@ namespace EveryRay_Core
rhi->SetVertexBuffers({ mMeshRenderBuffers[lod][meshI]->VertexBuffer });
rhi->SetIndexBuffer(mMeshRenderBuffers[lod][meshI]->IndexBuffer);

// run prepare callbacks for standard materials (specials are, i.e., shadow mapping, which are processed in their own systems)
// run prepare callbacks for standard materials (specials, i.e., shadow mapping, are processed in their own systems)
if (!isForwardPass && mMaterials[materialName]->IsStandard())
{
auto prepareMaterialBeforeRendering = MeshMaterialVariablesUpdateEvent->GetListener(materialName);
Expand All @@ -474,7 +473,10 @@ namespace EveryRay_Core
{
if (mIsIndirectlyRendered)
{
int offset = (MAX_MESH_COUNT * lod + meshI) * 5 * sizeof(UINT); //5 is args count of DrawIndexedInstanced()
if (!isForwardPass)
mMaterials[materialName]->SetRootConstantForMaterial(static_cast<UINT>(lod));

const int offset = (MAX_MESH_COUNT * lod + meshI) * 5 * sizeof(UINT); //5 is args count of DrawIndexedInstanced()
rhi->DrawIndexedInstancedIndirect(mIndirectArgsBuffer, offset);
}
else
Expand Down
6 changes: 5 additions & 1 deletion source/EveryRay_Core/ER_RenderingObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ namespace EveryRay_Core
float CustomRoughness;
float CustomMetalness;
float OriginalInstanceCount;
float CurrentLod;
float IsIndirectlyRendered;
};

//struct ER_ALIGN_GPU_BUFFER ObjectCB
//{
// UINT CurrentLOD;
//};

struct TextureData
{
ER_RHI_GPUTexture* AlbedoMap = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions source/EveryRay_Core/ER_Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ namespace EveryRay_Core {

#pragma region GPU_CULLING
rhi->BeginEventTag("EveryRay: GPU Culling");
#if ER_PLATFORM_WIN64_DX11 // TODO remove once fixed on DX12
mGPUCuller->PerformCull(mScene);
#endif
rhi->EndEventTag();
#pragma endregion

Expand Down
12 changes: 9 additions & 3 deletions source/EveryRay_Core/ER_ShadowMapMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ namespace EveryRay_Core
mConstantBuffer.Data.LightViewProjection = XMMatrixTranspose(lvp);
mConstantBuffer.ApplyChanges(rhi);
rhi->SetConstantBuffers(ER_VERTEX, { mConstantBuffer.Buffer(), aObj->GetObjectsConstantBuffer().Buffer() }, 0, rs, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX);
rhi->SetConstantBuffers(ER_PIXEL, { mConstantBuffer.Buffer() }, 0, rs, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX);
rhi->SetConstantBuffers(ER_PIXEL, { mConstantBuffer.Buffer(), aObj->GetObjectsConstantBuffer().Buffer() }, 0, rs, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX);

if (aObj->GetTextureData(meshIndex).AlbedoMap)
rhi->SetShaderResources(ER_PIXEL, { aObj->GetTextureData(meshIndex).AlbedoMap }, 0, rs, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetShaderResources(ER_PIXEL, { aObj->GetTextureData(meshIndex).AlbedoMap }, 0, rs, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX);
if (aObj->IsIndirectlyRendered())
rhi->SetShaderResources(ER_VERTEX, { aObj->GetIndirectNewInstanceBuffer() }, 1, rs, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetShaderResources(ER_VERTEX, { aObj->GetIndirectNewInstanceBuffer() }, 1, rs, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX);
rhi->SetSamplers(ER_PIXEL, { ER_RHI_SAMPLER_STATE::ER_TRILINEAR_WRAP });
}

Expand All @@ -86,6 +86,12 @@ namespace EveryRay_Core
//not used because this material is not standard
}

void ER_ShadowMapMaterial::SetRootConstantForMaterial(UINT a32BitConstant)
{
auto rhi = ER_Material::GetCore()->GetRHI();
rhi->SetRootConstant(a32BitConstant, SHADOWMAP_MAT_ROOT_ROOT_CONSTANT_INDEX);
}

void ER_ShadowMapMaterial::CreateVertexBuffer(const ER_Mesh& mesh, ER_RHI_GPUBuffer* vertexBuffer)
{
mesh.CreateVertexBuffer_PositionUvNormalTangent(vertexBuffer);
Expand Down
7 changes: 5 additions & 2 deletions source/EveryRay_Core/ER_ShadowMapMaterial.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once
#include "ER_Material.h"

#define SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX 0
#define SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 1
#define SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX 0
#define SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX 1
#define SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX 2
#define SHADOWMAP_MAT_ROOT_ROOT_CONSTANT_INDEX 3

namespace EveryRay_Core
{
Expand All @@ -24,6 +26,7 @@ namespace EveryRay_Core

void PrepareForRendering(ER_MaterialSystems neededSystems, ER_RenderingObject* aObj, int meshIndex, int cascadeIndex, ER_RHI_GPURootSignature* rs);
virtual void PrepareResourcesForStandardMaterial(ER_MaterialSystems neededSystems, ER_RenderingObject* aObj, int meshIndex, ER_RHI_GPURootSignature* rs) override;
virtual void SetRootConstantForMaterial(UINT a32BitConstant) override; // We use root constant for LOD index in this material
virtual void CreateVertexBuffer(const ER_Mesh& mesh, ER_RHI_GPUBuffer* vertexBuffer) override;
virtual int VertexSize() override;

Expand Down
6 changes: 4 additions & 2 deletions source/EveryRay_Core/ER_ShadowMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ namespace EveryRay_Core
//mLightProjectors[i]->ApplyRotation(mDirectionalLight.GetTransform());
}

mRootSignature = rhi->CreateRootSignature(2, 1);
mRootSignature = rhi->CreateRootSignature(4, 1);
if (mRootSignature)
{
mRootSignature->InitStaticSampler(rhi, 0, ER_RHI_SAMPLER_STATE::ER_TRILINEAR_WRAP, ER_RHI_SHADER_VISIBILITY_PIXEL);
mRootSignature->InitDescriptorTable(rhi, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 0 }, { 2 }, ER_RHI_SHADER_VISIBILITY_ALL);
mRootSignature->InitDescriptorTable(rhi, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_PIXEL_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 0 }, { 1 }, ER_RHI_SHADER_VISIBILITY_PIXEL);
mRootSignature->InitDescriptorTable(rhi, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_VERTEX_SRV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_SRV }, { 1 }, { 1 }, ER_RHI_SHADER_VISIBILITY_VERTEX);
mRootSignature->InitDescriptorTable(rhi, SHADOWMAP_MAT_ROOT_DESCRIPTOR_TABLE_CBV_INDEX, { ER_RHI_DESCRIPTOR_RANGE_TYPE::ER_RHI_DESCRIPTOR_RANGE_TYPE_CBV }, { 0 }, { 2 }, ER_RHI_SHADER_VISIBILITY_ALL);
mRootSignature->InitConstant(rhi, SHADOWMAP_MAT_ROOT_ROOT_CONSTANT_INDEX, 2 /*we already use 2 slots for CBVs*/, 1 /* only 1 constant for LOD index*/, ER_RHI_SHADER_VISIBILITY_ALL);
mRootSignature->Finalize(rhi, "ER_RHI_GPURootSignature: ShadowMapMaterial Pass", true);
}
}
Expand Down
Loading

0 comments on commit b78824a

Please sign in to comment.