mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 04:22:34 +00:00
Improve shader performance significantly by only including raytracing or shadowmaps in the shader if enabled
This commit is contained in:
parent
cfa3f8ecc4
commit
c23a109105
6 changed files with 15 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -166,8 +166,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
|
||||
|
@ -183,6 +182,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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -165,7 +165,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
|
|||
VPUniforms.mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8) | ((int)lightmode << 16);
|
||||
}
|
||||
VPUniforms.mClipLine.X = -10000000.0f;
|
||||
VPUniforms.mShadowmapFilter = gl_light_raytrace ? -1 - static_cast<int>(gl_shadowmap_filter) : static_cast<int>(gl_shadowmap_filter);
|
||||
VPUniforms.mShadowmapFilter = static_cast<int>(gl_shadowmap_filter);
|
||||
VPUniforms.mLightBlendMode = (level.info ? (int)level.info->lightblendmode : 0);
|
||||
}
|
||||
mClipper->SetViewpoint(Viewpoint);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
layout(set = 0, binding = 0) uniform sampler2D ShadowMap;
|
||||
layout(set = 0, binding = 1) uniform sampler2DArray LightMap;
|
||||
#ifdef SUPPORTS_RAYTRACING
|
||||
#if defined(USE_RAYTRACE) && defined(SUPPORTS_RAYQUERY)
|
||||
layout(set = 0, binding = 2) uniform accelerationStructureEXT TopLevelAS;
|
||||
#endif
|
||||
|
||||
|
@ -169,7 +169,6 @@ layout(push_constant) uniform PushConstants
|
|||
#define uDetailParms data[uDataIndex].uDetailParms
|
||||
#define uNpotEmulation data[uDataIndex].uNpotEmulation
|
||||
|
||||
#define SUPPORTS_SHADOWMAPS
|
||||
#define VULKAN_COORDINATE_SYSTEM
|
||||
#define HAS_UNIFORM_VERTEX_DATA
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
// Check if light is in shadow
|
||||
|
||||
#ifdef SUPPORTS_RAYTRACING
|
||||
#if defined(USE_RAYTRACE) && defined(SUPPORTS_RAYQUERY)
|
||||
|
||||
bool traceHit(vec3 origin, vec3 direction, float dist)
|
||||
{
|
||||
|
@ -72,16 +72,12 @@ float traceShadow(vec4 lightpos, int quality)
|
|||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
float traceShadow(vec4 lightpos, int quality)
|
||||
float shadowAttenuation(vec4 lightpos, float lightcolorA)
|
||||
{
|
||||
return 1.0;
|
||||
return traceShadow(lightpos, uShadowmapFilter);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORTS_SHADOWMAPS
|
||||
#elif defined(USE_SHADOWMAP)
|
||||
|
||||
float shadowDirToU(vec2 dir)
|
||||
{
|
||||
|
@ -214,9 +210,6 @@ float shadowAttenuation(vec4 lightpos, float lightcolorA)
|
|||
if (shadowIndex >= 1024.0)
|
||||
return 1.0; // No shadowmap available for this light
|
||||
|
||||
if (uShadowmapFilter < 0)
|
||||
return traceShadow(lightpos, 1 - uShadowmapFilter);
|
||||
|
||||
return shadowmapAttenuation(lightpos, shadowIndex);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue