Remove unused uniforms and restrict push constants to only control offsets into buffers

This commit is contained in:
Magnus Norddahl 2023-04-24 22:10:17 +02:00 committed by Christoph Oelckers
parent 6d3cb20699
commit f80807d26a
5 changed files with 63 additions and 90 deletions

View file

@ -200,7 +200,19 @@ struct StreamData
FVector4 uDetailParms; FVector4 uDetailParms;
FVector4 uNpotEmulation; FVector4 uNpotEmulation;
FVector4 padding1, padding2, padding3;
FVector2 uClipSplit;
FVector2 uSpecularMaterial;
float uLightLevel;
float uFogDensity;
float uLightFactor;
float uLightDist;
float uAlphaThreshold;
float padding1;
float padding2;
float padding3;
}; };
class FRenderState class FRenderState

View file

@ -35,28 +35,10 @@ struct StreamUBO
struct PushConstants struct PushConstants
{ {
int uTextureMode; int uDataIndex; // streamdata index
float uAlphaThreshold; int uLightIndex; // dynamic lights
FVector2 uClipSplit; int uBoneIndexBase; // bone animation
int padding;
// Lighting + Fog
float uLightLevel;
float uFogDensity;
float uLightFactor;
float uLightDist;
int uFogEnabled;
// dynamic lights
int uLightIndex;
// Blinn glossiness and specular level
FVector2 uSpecularMaterial;
// bone animation
int uBoneIndexBase;
int uDataIndex;
int padding1, padding2, padding3;
}; };
class VkShaderKey class VkShaderKey

View file

@ -395,6 +395,19 @@ void VkRenderState::ApplyStreamData()
else else
mStreamData.timer = 0.0f; mStreamData.timer = 0.0f;
mStreamData.uLightDist = mLightParms[0];
mStreamData.uLightFactor = mLightParms[1];
mStreamData.uFogDensity = mLightParms[2];
mStreamData.uLightLevel = mLightParms[3];
mStreamData.uAlphaThreshold = mAlphaThreshold;
mStreamData.uClipSplit = { mClipSplit[0], mClipSplit[1] };
if (mMaterial.mMaterial)
{
auto source = mMaterial.mMaterial->Source();
mStreamData.uSpecularMaterial = { source->GetGlossiness(), source->GetSpecularLevel() };
}
if (!mStreamBufferWriter.Write(mStreamData)) if (!mStreamBufferWriter.Write(mStreamData))
{ {
WaitForStreamBuffers(); WaitForStreamBuffers();
@ -404,40 +417,9 @@ void VkRenderState::ApplyStreamData()
void VkRenderState::ApplyPushConstants() void VkRenderState::ApplyPushConstants()
{ {
int fogset = 0; mPushConstants.uDataIndex = mStreamBufferWriter.DataIndex();
if (mFogEnabled)
{
if (mFogEnabled == 2)
{
fogset = -3; // 2D rendering with 'foggy' overlay.
}
else if ((GetFogColor() & 0xffffff) == 0)
{
fogset = gl_fogmode;
}
else
{
fogset = -gl_fogmode;
}
}
mPushConstants.uFogEnabled = fogset;
mPushConstants.uLightDist = mLightParms[0];
mPushConstants.uLightFactor = mLightParms[1];
mPushConstants.uFogDensity = mLightParms[2];
mPushConstants.uLightLevel = mLightParms[3];
mPushConstants.uAlphaThreshold = mAlphaThreshold;
mPushConstants.uClipSplit = { mClipSplit[0], mClipSplit[1] };
if (mMaterial.mMaterial)
{
auto source = mMaterial.mMaterial->Source();
mPushConstants.uSpecularMaterial = { source->GetGlossiness(), source->GetSpecularLevel() };
}
mPushConstants.uLightIndex = mLightIndex; mPushConstants.uLightIndex = mLightIndex;
mPushConstants.uBoneIndexBase = mBoneIndexBase; mPushConstants.uBoneIndexBase = mBoneIndexBase;
mPushConstants.uDataIndex = mStreamBufferWriter.DataIndex();
auto passManager = fb->GetRenderPassManager(); auto passManager = fb->GetRenderPassManager();
mCommandBuffer->pushConstants(passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, (uint32_t)sizeof(PushConstants), &mPushConstants); mCommandBuffer->pushConstants(passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, (uint32_t)sizeof(PushConstants), &mPushConstants);

View file

@ -1,21 +1,17 @@
void main() void main()
{ {
float fogdist;
float fogfactor;
// //
// calculate fog factor // calculate fog factor
// //
if (uFogEnabled == -1)
{ #if defined(FOG_RADIAL)
fogdist = pixelpos.w; float fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz));
} #else
else float fogdist = max(16.0, pixelpos.w);
{ #endif
fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); float fogfactor = exp2 (uFogDensity * fogdist);
}
fogfactor = exp2 (uFogDensity * fogdist);
FragColor = vec4(uFogColor.rgb, 1.0 - fogfactor); FragColor = vec4(uFogColor.rgb, 1.0 - fogfactor);
#ifdef GBUFFER_PASS #ifdef GBUFFER_PASS
FragFog = vec4(0.0, 0.0, 0.0, 1.0); FragFog = vec4(0.0, 0.0, 0.0, 1.0);

View file

@ -87,7 +87,19 @@ struct StreamData
vec4 uDetailParms; vec4 uDetailParms;
vec4 uNpotEmulation; vec4 uNpotEmulation;
vec4 padding1, padding2, padding3;
vec2 uClipSplit;
vec2 uSpecularMaterial;
float uLightLevel;
float uFogDensity;
float uLightFactor;
float uLightDist;
float uAlphaThreshold;
float padding1;
float padding2;
float padding3;
}; };
layout(set = 1, binding = 2, std140) uniform StreamUBO layout(set = 1, binding = 2, std140) uniform StreamUBO
@ -123,28 +135,10 @@ layout(set = 2, binding = 10) uniform sampler2D texture11;
// This must match the PushConstants struct // This must match the PushConstants struct
layout(push_constant) uniform PushConstants layout(push_constant) uniform PushConstants
{ {
int padding0; // was uTextureMode; int uDataIndex; // streamdata index
float uAlphaThreshold; int uLightIndex; // dynamic lights
vec2 uClipSplit; int uBoneIndexBase; // bone animation
int padding;
// Lighting + Fog
float uLightLevel;
float uFogDensity;
float uLightFactor;
float uLightDist;
int uFogEnabled;
// dynamic lights
int uLightIndex;
// Blinn glossiness and specular level
vec2 uSpecularMaterial;
// bone animation
int uBoneIndexBase;
int uDataIndex;
int padding2, padding3;
}; };
// material types // material types
@ -192,6 +186,13 @@ layout(push_constant) uniform PushConstants
#define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane #define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane
#define uDetailParms data[uDataIndex].uDetailParms #define uDetailParms data[uDataIndex].uDetailParms
#define uNpotEmulation data[uDataIndex].uNpotEmulation #define uNpotEmulation data[uDataIndex].uNpotEmulation
#define uClipSplit data[uDataIndex].uClipSplit
#define uSpecularMaterial data[uDataIndex].uSpecularMaterial
#define uLightLevel data[uDataIndex].uLightLevel
#define uFogDensity data[uDataIndex].uFogDensity
#define uLightFactor data[uDataIndex].uLightFactor
#define uLightDist data[uDataIndex].uLightDist
#define uAlphaThreshold data[uDataIndex].uAlphaThreshold
#define VULKAN_COORDINATE_SYSTEM #define VULKAN_COORDINATE_SYSTEM
#define HAS_UNIFORM_VERTEX_DATA #define HAS_UNIFORM_VERTEX_DATA