Refactor draw calls drawing to use single objects buffer and better materials batching

This commit is contained in:
Wojtek Figat
2024-07-02 00:52:22 +02:00
parent 78f3248ac9
commit 08ef7c93ea
35 changed files with 491 additions and 442 deletions

View File

@@ -38,31 +38,21 @@ GPU_CB_STRUCT(MaterialShaderDataPerView {
IMaterial::BindParameters::BindParameters(::GPUContext* context, const ::RenderContext& renderContext)
: GPUContext(context)
, RenderContext(renderContext)
, FirstDrawCall(nullptr)
, DrawCallsCount(0)
, TimeParam(Time::Draw.UnscaledTime.GetTotalSeconds())
{
}
IMaterial::BindParameters::BindParameters(::GPUContext* context, const ::RenderContext& renderContext, const DrawCall& drawCall)
IMaterial::BindParameters::BindParameters(::GPUContext* context, const ::RenderContext& renderContext, const ::DrawCall& drawCall, bool instanced)
: GPUContext(context)
, RenderContext(renderContext)
, FirstDrawCall(&drawCall)
, DrawCallsCount(1)
, TimeParam(Time::Draw.UnscaledTime.GetTotalSeconds())
{
}
IMaterial::BindParameters::BindParameters(::GPUContext* context, const ::RenderContext& renderContext, const DrawCall* firstDrawCall, int32 drawCallsCount)
: GPUContext(context)
, RenderContext(renderContext)
, FirstDrawCall(firstDrawCall)
, DrawCallsCount(drawCallsCount)
, DrawCall(&drawCall)
, TimeParam(Time::Draw.UnscaledTime.GetTotalSeconds())
, Instanced(instanced)
{
}
GPUConstantBuffer* IMaterial::BindParameters::PerViewConstants = nullptr;
GPUConstantBuffer* IMaterial::BindParameters::PerDrawConstants = nullptr;
void IMaterial::BindParameters::BindViewData()
{
@@ -70,6 +60,7 @@ void IMaterial::BindParameters::BindViewData()
if (!PerViewConstants)
{
PerViewConstants = GPUDevice::Instance->CreateConstantBuffer(sizeof(MaterialShaderDataPerView), TEXT("PerViewConstants"));
PerDrawConstants = GPUDevice::Instance->CreateConstantBuffer(sizeof(MaterialShaderDataPerDraw), TEXT("PerDrawConstants"));
}
// Setup data