From 981f302051c4fa27acbf9719e00e7be6b1d78c70 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Thu, 26 Dec 2024 11:04:08 +0300 Subject: [PATCH] Fix stage variants upload Also removed some now useless code. --- src/engine/renderer/Material.cpp | 57 +++++--------------------------- src/engine/renderer/tr_local.h | 1 - 2 files changed, 9 insertions(+), 49 deletions(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index 8176bf33d1..47fa852ba7 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -145,12 +145,6 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, Material& material, shader const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - gl_genericShaderMaterial->BindProgram( material.deformIndex ); // u_AlphaThreshold @@ -181,12 +175,6 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, Material& material, sha const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - gl_lightMappingShaderMaterial->BindProgram( material.deformIndex ); // u_ColorModulate @@ -246,12 +234,6 @@ void UpdateSurfaceDataReflection( uint32_t* materials, Material& /* material */, const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - // bind u_ColorMap vec3_t position; if ( backEnd.currentEntity && ( backEnd.currentEntity != &tr.worldEntity ) ) { @@ -294,12 +276,6 @@ void UpdateSurfaceDataSkybox( uint32_t* materials, Material& material, shaderSta const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - gl_skyboxShaderMaterial->BindProgram( material.deformIndex ); // u_AlphaThreshold @@ -314,12 +290,6 @@ void UpdateSurfaceDataScreen( uint32_t* materials, Material& /* material */, sha const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - gl_screenShaderMaterial->BindProgram( pStage->deformIndex ); // bind u_CurrentMap @@ -336,12 +306,6 @@ void UpdateSurfaceDataHeatHaze( uint32_t* materials, Material& /* material */, s const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - float deformMagnitude = RB_EvalExpression( &pStage->deformMagnitudeExp, 1.0 ); gl_heatHazeShaderMaterial->SetUniform_DeformMagnitude( deformMagnitude ); @@ -362,12 +326,6 @@ void UpdateSurfaceDataLiquid( uint32_t* materials, Material& /* material */, sha const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->colorDynamic || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - float fogDensity = RB_EvalExpression( &pStage->fogDensityExp, 0.001 ); vec4_t fogColor; Tess_ComputeColor( pStage ); @@ -421,12 +379,6 @@ void UpdateSurfaceDataFog( uint32_t* materials, Material& material, shaderStage_ const uint32_t paddedOffset = pStage->bufferOffset; materials += paddedOffset; - bool updated = !pStage->bufferInitialized || pStage->dynamic; - if ( !updated ) { - return; - } - pStage->bufferInitialized = true; - const fog_t* fog = material.fog; // u_Color @@ -569,7 +521,11 @@ void MaterialSystem::GenerateMaterialsBuffer( std::vector& stage pStage->vertexLit = i & Util::ordinal( ShaderStageVariant::VERTEX_LIT ); pStage->fullbright = i & Util::ordinal( ShaderStageVariant::FULLBRIGHT ); pStage->currentOffset = pStage->variantOffsets[i]; + + const uint32_t variantOffset = pStage->variantOffsets[i] * material.shader->GetPaddedSize(); + pStage->bufferOffset += variantOffset; pStage->surfaceDataUpdater( materialsData, material, pStage ); + pStage->bufferOffset -= variantOffset; variants++; } } @@ -1403,6 +1359,11 @@ void MaterialSystem::AddStage( drawSurf_t* drawSurf, shaderStage_t* pStage, uint pStage->materialRemappedStage = pStage2; + if ( pStage2->variantOffsets[variant] == -1 ) { + pStage2->variantOffsets[variant] = pStage2->variantOffset; + pStage2->variantOffset++; + } + return; } diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index 757db16c68..3dcb579018 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -1224,7 +1224,6 @@ enum class shaderProfilerRenderSubGroupsMode { uint32_t dynamicBufferOffset = 0; bool initialized = false; - bool bufferInitialized = false; uint materialPackID = 0; uint materialID = 0;