Improve shader performance significantly by only including raytracing or shadowmaps in the shader if enabled

This commit is contained in:
Magnus Norddahl 2023-04-07 04:22:43 +02:00
commit caefc09549
6 changed files with 15 additions and 17 deletions

View file

@ -255,6 +255,8 @@ void VkRenderState::ApplyRenderPass(int dt)
pipelineKey.ShaderKey.Detailmap = (uTextureMode & TEXF_Detailmap) != 0;
pipelineKey.ShaderKey.Glowmap = (uTextureMode & TEXF_Glowmap) != 0;
pipelineKey.ShaderKey.Simple2D = (mFogEnabled == 2);
pipelineKey.ShaderKey.UseShadowmap = gl_light_shadowmap;
pipelineKey.ShaderKey.UseRaytrace = gl_light_raytrace;
// Is this the one we already have?
bool inRenderPass = mCommandBuffer;

View file

@ -165,8 +165,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char* mateffect_lump, const char *light_lump, const char *defines, const VkShaderKey& key)
{
FString definesBlock;
definesBlock << defines << "\n";
if (fb->device->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME)) definesBlock << "\n#define SUPPORTS_RAYTRACING\n";
if (fb->device->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME)) definesBlock << "\n#define SUPPORTS_RAYQUERY\n";
definesBlock << defines;
definesBlock << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n";
#ifdef NPOT_EMULATION
@ -182,6 +181,9 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
if (key.Detailmap) definesBlock << "#define TEXF_Detailmap\n";
if (key.Glowmap) definesBlock << "#define TEXF_Glowmap\n";
if (key.UseRaytrace) definesBlock << "\n#define USE_RAYTRACE\n";
if (key.UseShadowmap) definesBlock << "\n#define USE_SHADOWMAP\n";
switch (key.TextureMode)
{
case TM_STENCIL: definesBlock << "#define TM_STENCIL\n"; break;

View file

@ -74,7 +74,9 @@ public:
uint64_t Detailmap : 1; // uTextureMode & TEXF_Detailmap
uint64_t Glowmap : 1; // uTextureMode & TEXF_Glowmap
uint64_t GBufferPass : 1; // GBUFFER_PASS
uint64_t Unused : 54;
uint64_t UseShadowmap : 1; // USE_SHADOWMAPS
uint64_t UseRaytrace : 1; // USE_RAYTRACE
uint64_t Unused : 52;
};
uint64_t AsQWORD = 0;
};