mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
ShaderGen: Pass host config to shader generation functions
Also moves the host config checks to common.
This commit is contained in:
@ -164,8 +164,7 @@ void GeometryShaderCache::Init()
|
||||
void GeometryShaderCache::LoadShaderCache()
|
||||
{
|
||||
GeometryShaderCacheInserter inserter;
|
||||
g_gs_disk_cache.OpenAndRead(g_ActiveConfig.GetDiskCacheFileName(APIType::D3D, "GS", true, true),
|
||||
inserter);
|
||||
g_gs_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "GS", true, true), inserter);
|
||||
}
|
||||
|
||||
void GeometryShaderCache::Reload()
|
||||
@ -237,7 +236,8 @@ bool GeometryShaderCache::SetShader(u32 primitive_type)
|
||||
}
|
||||
|
||||
// Need to compile a new shader
|
||||
ShaderCode code = GenerateGeometryShaderCode(APIType::D3D, uid.GetUidData());
|
||||
ShaderCode code =
|
||||
GenerateGeometryShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
|
||||
D3DBlob* pbytecode;
|
||||
if (!D3D::CompileGeometryShader(code.GetBuffer(), &pbytecode))
|
||||
|
@ -504,8 +504,7 @@ void PixelShaderCache::Init()
|
||||
void PixelShaderCache::LoadShaderCache()
|
||||
{
|
||||
PixelShaderCacheInserter inserter;
|
||||
g_ps_disk_cache.OpenAndRead(g_ActiveConfig.GetDiskCacheFileName(APIType::D3D, "PS", true, true),
|
||||
inserter);
|
||||
g_ps_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "PS", true, true), inserter);
|
||||
}
|
||||
|
||||
void PixelShaderCache::Reload()
|
||||
@ -590,7 +589,8 @@ bool PixelShaderCache::SetShader()
|
||||
}
|
||||
|
||||
// Need to compile a new shader
|
||||
ShaderCode code = GeneratePixelShaderCode(APIType::D3D, uid.GetUidData());
|
||||
ShaderCode code =
|
||||
GeneratePixelShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
|
||||
D3DBlob* pbytecode;
|
||||
if (!D3D::CompilePixelShader(code.GetBuffer(), &pbytecode))
|
||||
|
@ -242,7 +242,6 @@ Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferH
|
||||
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
|
||||
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
|
||||
s_last_fullscreen_mode = D3D::GetFullscreenState();
|
||||
m_last_host_config_bits = g_ActiveConfig.GetHostConfigBits();
|
||||
|
||||
g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
|
||||
SetupDeviceObjects();
|
||||
@ -895,14 +894,11 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
|
||||
D3D11_CLEAR_DEPTH, 0.f, 0);
|
||||
}
|
||||
|
||||
u32 new_host_config_bits = g_ActiveConfig.GetHostConfigBits();
|
||||
if (new_host_config_bits != m_last_host_config_bits)
|
||||
if (CheckForHostConfigChanges())
|
||||
{
|
||||
OSD::AddMessage("Video config changed, reloading shaders.", OSD::Duration::NORMAL);
|
||||
VertexShaderCache::Reload();
|
||||
GeometryShaderCache::Reload();
|
||||
PixelShaderCache::Reload();
|
||||
m_last_host_config_bits = new_host_config_bits;
|
||||
}
|
||||
|
||||
// begin next frame
|
||||
|
@ -64,7 +64,5 @@ public:
|
||||
private:
|
||||
void BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D* src_texture,
|
||||
u32 src_width, u32 src_height, float Gamma);
|
||||
|
||||
u32 m_last_host_config_bits = 0;
|
||||
};
|
||||
}
|
||||
|
@ -165,8 +165,7 @@ void VertexShaderCache::Init()
|
||||
void VertexShaderCache::LoadShaderCache()
|
||||
{
|
||||
VertexShaderCacheInserter inserter;
|
||||
g_vs_disk_cache.OpenAndRead(g_ActiveConfig.GetDiskCacheFileName(APIType::D3D, "VS", true, true),
|
||||
inserter);
|
||||
g_vs_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "VS", true, true), inserter);
|
||||
}
|
||||
|
||||
void VertexShaderCache::Reload()
|
||||
@ -229,7 +228,8 @@ bool VertexShaderCache::SetShader()
|
||||
return (entry.shader != nullptr);
|
||||
}
|
||||
|
||||
ShaderCode code = GenerateVertexShaderCode(APIType::D3D, uid.GetUidData());
|
||||
ShaderCode code =
|
||||
GenerateVertexShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
|
||||
D3DBlob* pbytecode = nullptr;
|
||||
D3D::CompileVertexShader(code.GetBuffer(), &pbytecode);
|
||||
|
@ -46,7 +46,7 @@ protected:
|
||||
}
|
||||
ShaderCode GenerateCode(APIType api_type, VertexShaderUid uid) override
|
||||
{
|
||||
return GenerateVertexShaderCode(api_type, uid.GetUidData());
|
||||
return GenerateVertexShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
}
|
||||
};
|
||||
|
||||
@ -62,7 +62,7 @@ protected:
|
||||
}
|
||||
ShaderCode GenerateCode(APIType api_type, GeometryShaderUid uid) override
|
||||
{
|
||||
return GenerateGeometryShaderCode(api_type, uid.GetUidData());
|
||||
return GenerateGeometryShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
}
|
||||
};
|
||||
|
||||
@ -78,7 +78,7 @@ protected:
|
||||
}
|
||||
ShaderCode GenerateCode(APIType api_type, PixelShaderUid uid) override
|
||||
{
|
||||
return GeneratePixelShaderCode(api_type, uid.GetUidData());
|
||||
return GeneratePixelShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -217,12 +217,13 @@ SHADER* ProgramShaderCache::SetShader(u32 primitive_type)
|
||||
last_entry = &newentry;
|
||||
newentry.in_cache = 0;
|
||||
|
||||
ShaderCode vcode = GenerateVertexShaderCode(APIType::OpenGL, uid.vuid.GetUidData());
|
||||
ShaderCode pcode = GeneratePixelShaderCode(APIType::OpenGL, uid.puid.GetUidData());
|
||||
ShaderHostConfig host_config = ShaderHostConfig::GetCurrent();
|
||||
ShaderCode vcode = GenerateVertexShaderCode(APIType::OpenGL, host_config, uid.vuid.GetUidData());
|
||||
ShaderCode pcode = GeneratePixelShaderCode(APIType::OpenGL, host_config, uid.puid.GetUidData());
|
||||
ShaderCode gcode;
|
||||
if (g_ActiveConfig.backend_info.bSupportsGeometryShaders &&
|
||||
!uid.guid.GetUidData()->IsPassthrough())
|
||||
gcode = GenerateGeometryShaderCode(APIType::OpenGL, uid.guid.GetUidData());
|
||||
gcode = GenerateGeometryShaderCode(APIType::OpenGL, host_config, uid.guid.GetUidData());
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
|
||||
@ -553,7 +554,7 @@ void ProgramShaderCache::LoadProgramBinaries()
|
||||
else
|
||||
{
|
||||
std::string cache_filename =
|
||||
g_ActiveConfig.GetDiskCacheFileName(APIType::OpenGL, "ProgramBinaries", true, true);
|
||||
GetDiskShaderCacheFileName(APIType::OpenGL, "ProgramBinaries", true, true);
|
||||
ProgramShaderCacheInserter inserter;
|
||||
g_program_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "VideoCommon/PixelEngine.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/RenderState.h"
|
||||
#include "VideoCommon/ShaderGenCommon.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
#include "VideoCommon/VideoBackendBase.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
@ -664,6 +665,9 @@ Renderer::Renderer()
|
||||
g_Config.VerifyValidity();
|
||||
UpdateActiveConfig();
|
||||
|
||||
// Since we modify the config here, we need to update the last host bits, it may have changed.
|
||||
m_last_host_config_bits = ShaderHostConfig::GetCurrent().bits;
|
||||
|
||||
OSD::AddMessage(StringFromFormat("Video Info: %s, %s, %s", g_ogl_config.gl_vendor,
|
||||
g_ogl_config.gl_renderer, g_ogl_config.gl_version),
|
||||
5000);
|
||||
@ -688,7 +692,6 @@ Renderer::Renderer()
|
||||
|
||||
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
|
||||
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
|
||||
m_last_host_config_bits = g_ActiveConfig.GetHostConfigBits();
|
||||
|
||||
// Handle VSync on/off
|
||||
s_vsync = g_ActiveConfig.IsVSync();
|
||||
@ -1471,13 +1474,8 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
|
||||
g_texture_cache->OnConfigChanged(g_ActiveConfig);
|
||||
|
||||
// Invalidate shader cache when the host config changes.
|
||||
u32 new_host_config_bits = g_ActiveConfig.GetHostConfigBits();
|
||||
if (new_host_config_bits != m_last_host_config_bits)
|
||||
{
|
||||
OSD::AddMessage("Video config changed, reloading shaders.", OSD::Duration::NORMAL);
|
||||
if (CheckForHostConfigChanges())
|
||||
ProgramShaderCache::Reload();
|
||||
m_last_host_config_bits = new_host_config_bits;
|
||||
}
|
||||
|
||||
// For testing zbuffer targets.
|
||||
// Renderer::SetZBufferRender();
|
||||
|
@ -148,8 +148,5 @@ private:
|
||||
std::array<int, 2> m_last_frame_height = {};
|
||||
bool m_last_frame_exported = false;
|
||||
AVIDump::Frame m_last_frame_state;
|
||||
|
||||
// last host config state
|
||||
u32 m_last_host_config_bits = 0;
|
||||
};
|
||||
}
|
||||
|
@ -472,8 +472,7 @@ bool ObjectCache::CreatePipelineCache()
|
||||
// Vulkan pipeline caches can be shared between games for shader compile time reduction.
|
||||
// This assumes that drivers don't create all pipelines in the cache on load time, only
|
||||
// when a lookup occurs that matches a pipeline (or pipeline data) in the cache.
|
||||
m_pipeline_cache_filename =
|
||||
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "Pipeline", false, true);
|
||||
m_pipeline_cache_filename = GetDiskShaderCacheFileName(APIType::Vulkan, "Pipeline", false, true);
|
||||
|
||||
VkPipelineCacheCreateInfo info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType
|
||||
@ -496,8 +495,7 @@ bool ObjectCache::LoadPipelineCache()
|
||||
{
|
||||
// We have to keep the pipeline cache file name around since when we save it
|
||||
// we delete the old one, by which time the game's unique ID is already cleared.
|
||||
m_pipeline_cache_filename =
|
||||
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "Pipeline", false, true);
|
||||
m_pipeline_cache_filename = GetDiskShaderCacheFileName(APIType::Vulkan, "Pipeline", false, true);
|
||||
|
||||
std::vector<u8> disk_data;
|
||||
LinearDiskCache<u32, u8> disk_cache;
|
||||
@ -663,18 +661,18 @@ struct ShaderCacheReader : public LinearDiskCacheReader<Uid, u32>
|
||||
void ObjectCache::LoadShaderCaches()
|
||||
{
|
||||
ShaderCacheReader<VertexShaderUid> vs_reader(m_vs_cache.shader_map);
|
||||
m_vs_cache.disk_cache.OpenAndRead(
|
||||
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "VS", true, true), vs_reader);
|
||||
m_vs_cache.disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::Vulkan, "VS", true, true),
|
||||
vs_reader);
|
||||
|
||||
ShaderCacheReader<PixelShaderUid> ps_reader(m_ps_cache.shader_map);
|
||||
m_ps_cache.disk_cache.OpenAndRead(
|
||||
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "PS", true, true), ps_reader);
|
||||
m_ps_cache.disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::Vulkan, "PS", true, true),
|
||||
ps_reader);
|
||||
|
||||
if (g_vulkan_context->SupportsGeometryShaders())
|
||||
{
|
||||
ShaderCacheReader<GeometryShaderUid> gs_reader(m_gs_cache.shader_map);
|
||||
m_gs_cache.disk_cache.OpenAndRead(
|
||||
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "GS", true, true), gs_reader);
|
||||
m_gs_cache.disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::Vulkan, "GS", true, true),
|
||||
gs_reader);
|
||||
}
|
||||
|
||||
SETSTAT(stats.numPixelShadersCreated, static_cast<int>(m_ps_cache.shader_map.size()));
|
||||
@ -719,7 +717,8 @@ VkShaderModule ObjectCache::GetVertexShaderForUid(const VertexShaderUid& uid)
|
||||
// Not in the cache, so compile the shader.
|
||||
ShaderCompiler::SPIRVCodeVector spv;
|
||||
VkShaderModule module = VK_NULL_HANDLE;
|
||||
ShaderCode source_code = GenerateVertexShaderCode(APIType::Vulkan, uid.GetUidData());
|
||||
ShaderCode source_code =
|
||||
GenerateVertexShaderCode(APIType::Vulkan, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
if (ShaderCompiler::CompileVertexShader(&spv, source_code.GetBuffer().c_str(),
|
||||
source_code.GetBuffer().length()))
|
||||
{
|
||||
@ -749,7 +748,8 @@ VkShaderModule ObjectCache::GetGeometryShaderForUid(const GeometryShaderUid& uid
|
||||
// Not in the cache, so compile the shader.
|
||||
ShaderCompiler::SPIRVCodeVector spv;
|
||||
VkShaderModule module = VK_NULL_HANDLE;
|
||||
ShaderCode source_code = GenerateGeometryShaderCode(APIType::Vulkan, uid.GetUidData());
|
||||
ShaderCode source_code =
|
||||
GenerateGeometryShaderCode(APIType::Vulkan, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
if (ShaderCompiler::CompileGeometryShader(&spv, source_code.GetBuffer().c_str(),
|
||||
source_code.GetBuffer().length()))
|
||||
{
|
||||
@ -774,7 +774,8 @@ VkShaderModule ObjectCache::GetPixelShaderForUid(const PixelShaderUid& uid)
|
||||
// Not in the cache, so compile the shader.
|
||||
ShaderCompiler::SPIRVCodeVector spv;
|
||||
VkShaderModule module = VK_NULL_HANDLE;
|
||||
ShaderCode source_code = GeneratePixelShaderCode(APIType::Vulkan, uid.GetUidData());
|
||||
ShaderCode source_code =
|
||||
GeneratePixelShaderCode(APIType::Vulkan, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
if (ShaderCompiler::CompileFragmentShader(&spv, source_code.GetBuffer().c_str(),
|
||||
source_code.GetBuffer().length()))
|
||||
{
|
||||
|
@ -1126,7 +1126,6 @@ void Renderer::CheckForSurfaceChange()
|
||||
void Renderer::CheckForConfigChanges()
|
||||
{
|
||||
// Save the video config so we can compare against to determine which settings have changed.
|
||||
u32 old_host_bits = g_ActiveConfig.GetHostConfigBits();
|
||||
int old_anisotropy = g_ActiveConfig.iMaxAnisotropy;
|
||||
int old_aspect_ratio = g_ActiveConfig.iAspectRatio;
|
||||
int old_efb_scale = g_ActiveConfig.iEFBScale;
|
||||
@ -1140,7 +1139,6 @@ void Renderer::CheckForConfigChanges()
|
||||
UpdateActiveConfig();
|
||||
|
||||
// Determine which (if any) settings have changed.
|
||||
bool host_bits_changed = old_host_bits != g_ActiveConfig.GetHostConfigBits();
|
||||
bool anisotropy_changed = old_anisotropy != g_ActiveConfig.iMaxAnisotropy;
|
||||
bool force_texture_filtering_changed = old_force_filtering != g_ActiveConfig.bForceFiltering;
|
||||
bool efb_scale_changed = old_efb_scale != g_ActiveConfig.iEFBScale;
|
||||
@ -1162,9 +1160,8 @@ void Renderer::CheckForConfigChanges()
|
||||
// If the stereoscopy mode changed, we need to recreate the buffers as well.
|
||||
// SSAA changed on/off, we have to recompile shaders.
|
||||
// Changing stereoscopy from off<->on also requires shaders to be recompiled.
|
||||
if (host_bits_changed)
|
||||
if (CheckForHostConfigChanges())
|
||||
{
|
||||
OSD::AddMessage("Video config changed, reloading shaders.", OSD::Duration::NORMAL);
|
||||
g_command_buffer_mgr->WaitForGPUIdle();
|
||||
FramebufferManager::GetInstance()->RecreateRenderPass();
|
||||
FramebufferManager::GetInstance()->ResizeEFBTextures();
|
||||
|
@ -147,8 +147,7 @@ void StateTracker::ReloadPipelineUIDCache()
|
||||
m_uid_cache.Close();
|
||||
|
||||
// UID caches don't contain any host state, so use a single uid cache per gameid.
|
||||
std::string filename =
|
||||
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "PipelineUID", true, false);
|
||||
std::string filename = GetDiskShaderCacheFileName(APIType::Vulkan, "PipelineUID", true, false);
|
||||
if (g_ActiveConfig.bShaderCache)
|
||||
{
|
||||
PipelineInserter inserter(this);
|
||||
|
Reference in New Issue
Block a user