From aa0c0068ce5ed79d2000b97979350c589b3209a8 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 19 Oct 2024 18:25:40 +1000 Subject: [PATCH] GPU/HW: Move shadergen parameters to functions --- src/core/gpu_hw.cpp | 57 ++++++----- src/core/gpu_hw_shadergen.cpp | 160 +++++++++++++++--------------- src/core/gpu_hw_shadergen.h | 65 ++++++------ src/core/gpu_hw_texture_cache.cpp | 4 +- src/core/gpu_shadergen.cpp | 18 ++-- src/core/gpu_shadergen.h | 18 ++-- src/util/shadergen.cpp | 33 +++--- src/util/shadergen.h | 34 +++---- 8 files changed, 198 insertions(+), 191 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 67a480cd8..cf31c3e41 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -987,10 +987,14 @@ void GPU_HW::DestroyBuffers() bool GPU_HW::CompilePipelines(Error* error) { const GPUDevice::Features features = g_gpu_device->GetFeatures(); - const bool per_sample_shading = g_settings.gpu_per_sample_shading && features.per_sample_shading; - const bool force_round_texcoords = (m_resolution_scale > 1 && m_texture_filtering == GPUTextureFilter::Nearest && - g_settings.gpu_force_round_texcoords); + const bool upscaled = (m_resolution_scale > 1); + const bool msaa = (m_multisamples > 1); + const bool per_sample_shading = (msaa && g_settings.gpu_per_sample_shading && features.per_sample_shading); + const bool force_round_texcoords = + (upscaled && m_texture_filtering == GPUTextureFilter::Nearest && g_settings.gpu_force_round_texcoords); const bool true_color = g_settings.gpu_true_color; + const bool scaled_dithering = (!m_true_color && upscaled && g_settings.gpu_scaled_dithering); + const bool disable_color_perspective = ShouldDisableColorPerspective(); // Determine when to use shader blending. // FBFetch is free, we need it for filtering without DSB, or when accurate blending is forced. @@ -1029,10 +1033,8 @@ bool GPU_HW::CompilePipelines(Error* error) INFO_LOG("Using feedback loops: {}", needs_feedback_loop ? "YES" : "NO"); // Start generating shaders. - GPU_HW_ShaderGen shadergen(g_gpu_device->GetRenderAPI(), m_resolution_scale, m_multisamples, per_sample_shading, - m_true_color, (m_resolution_scale > 1 && g_settings.gpu_scaled_dithering), - m_write_mask_as_depth, ShouldDisableColorPerspective(), m_supports_dual_source_blend, - m_supports_framebuffer_fetch); + const GPU_HW_ShaderGen shadergen(g_gpu_device->GetRenderAPI(), m_supports_dual_source_blend, + m_supports_framebuffer_fetch); const u32 active_texture_modes = m_allow_sprite_mode ? NUM_TEXTURE_MODES : @@ -1085,7 +1087,8 @@ bool GPU_HW::CompilePipelines(Error* error) const bool uv_limits = ShouldClampUVs(sprite ? m_sprite_texture_filtering : m_texture_filtering); const std::string vs = shadergen.GenerateBatchVertexShader( - textured != 0, palette == 1, palette == 2, uv_limits, !sprite && force_round_texcoords, m_pgxp_depth_buffer); + upscaled, msaa, per_sample_shading, textured != 0, palette == 1, palette == 2, uv_limits, + !sprite && force_round_texcoords, m_pgxp_depth_buffer, disable_color_perspective); if (!(batch_vertex_shaders[textured][palette][sprite] = g_gpu_device->CreateShader(GPUShaderStage::Vertex, shadergen.GetLanguage(), vs, error))) { @@ -1157,10 +1160,11 @@ bool GPU_HW::CompilePipelines(Error* error) (render_mode == static_cast(BatchRenderMode::ShaderBlend) && m_use_rov_for_shader_blend); const std::string fs = shadergen.GenerateBatchFragmentShader( static_cast(render_mode), static_cast(transparency_mode), - shader_texmode, sprite ? m_sprite_texture_filtering : m_texture_filtering, uv_limits, - !sprite && force_round_texcoords, ConvertToBoolUnchecked(dithering), - ConvertToBoolUnchecked(interlacing), ConvertToBoolUnchecked(check_mask), use_rov, needs_rov_depth, - (depth_test != 0)); + shader_texmode, sprite ? m_sprite_texture_filtering : m_texture_filtering, upscaled, msaa, + per_sample_shading, uv_limits, !sprite && force_round_texcoords, true_color, + ConvertToBoolUnchecked(dithering), scaled_dithering, disable_color_perspective, + ConvertToBoolUnchecked(interlacing), ConvertToBoolUnchecked(check_mask), m_write_mask_as_depth, + use_rov, needs_rov_depth, (depth_test != 0)); if (!(batch_fragment_shaders[depth_test][render_mode][transparency_mode][texture_mode][check_mask] [dithering][interlacing] = g_gpu_device->CreateShader( @@ -1433,7 +1437,8 @@ bool GPU_HW::CompilePipelines(Error* error) { std::unique_ptr fs = g_gpu_device->CreateShader( GPUShaderStage::Fragment, shadergen.GetLanguage(), - shadergen.GenerateVRAMFillFragmentShader(ConvertToBoolUnchecked(wrapped), ConvertToBoolUnchecked(interlaced)), + shadergen.GenerateVRAMFillFragmentShader(ConvertToBoolUnchecked(wrapped), ConvertToBoolUnchecked(interlaced), + m_write_mask_as_depth), error); if (!fs) return false; @@ -1451,8 +1456,9 @@ bool GPU_HW::CompilePipelines(Error* error) // VRAM copy { - std::unique_ptr fs = g_gpu_device->CreateShader(GPUShaderStage::Fragment, shadergen.GetLanguage(), - shadergen.GenerateVRAMCopyFragmentShader(), error); + std::unique_ptr fs = g_gpu_device->CreateShader( + GPUShaderStage::Fragment, shadergen.GetLanguage(), + shadergen.GenerateVRAMCopyFragmentShader(m_resolution_scale, m_write_mask_as_depth), error); if (!fs) return false; @@ -1479,9 +1485,10 @@ bool GPU_HW::CompilePipelines(Error* error) { const bool use_buffer = features.supports_texture_buffers; const bool use_ssbo = features.texture_buffers_emulated_with_ssbo; - std::unique_ptr fs = - g_gpu_device->CreateShader(GPUShaderStage::Fragment, shadergen.GetLanguage(), - shadergen.GenerateVRAMWriteFragmentShader(use_buffer, use_ssbo), error); + std::unique_ptr fs = g_gpu_device->CreateShader( + GPUShaderStage::Fragment, shadergen.GetLanguage(), + shadergen.GenerateVRAMWriteFragmentShader(m_resolution_scale, use_buffer, use_ssbo, m_write_mask_as_depth), + error); if (!fs) return false; @@ -1527,7 +1534,7 @@ bool GPU_HW::CompilePipelines(Error* error) if (m_write_mask_as_depth) { std::unique_ptr fs = g_gpu_device->CreateShader( - GPUShaderStage::Fragment, shadergen.GetLanguage(), shadergen.GenerateVRAMUpdateDepthFragmentShader(), error); + GPUShaderStage::Fragment, shadergen.GetLanguage(), shadergen.GenerateVRAMUpdateDepthFragmentShader(msaa), error); if (!fs) return false; @@ -1553,8 +1560,9 @@ bool GPU_HW::CompilePipelines(Error* error) // VRAM read { - std::unique_ptr fs = g_gpu_device->CreateShader(GPUShaderStage::Fragment, shadergen.GetLanguage(), - shadergen.GenerateVRAMReadFragmentShader(), error); + std::unique_ptr fs = + g_gpu_device->CreateShader(GPUShaderStage::Fragment, shadergen.GetLanguage(), + shadergen.GenerateVRAMReadFragmentShader(m_resolution_scale, m_multisamples), error); if (!fs) return false; @@ -1577,9 +1585,10 @@ bool GPU_HW::CompilePipelines(Error* error) if (depth_extract && !m_pgxp_depth_buffer) continue; - std::unique_ptr fs = - g_gpu_device->CreateShader(GPUShaderStage::Fragment, shadergen.GetLanguage(), - shadergen.GenerateVRAMExtractFragmentShader(color_24bit, depth_extract), error); + std::unique_ptr fs = g_gpu_device->CreateShader( + GPUShaderStage::Fragment, shadergen.GetLanguage(), + shadergen.GenerateVRAMExtractFragmentShader(m_resolution_scale, m_multisamples, color_24bit, depth_extract), + error); if (!fs) return false; diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index 4b00f482b..8c52bada8 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -8,20 +8,15 @@ #include "common/assert.h" -GPU_HW_ShaderGen::GPU_HW_ShaderGen(RenderAPI render_api, u32 resolution_scale, u32 multisamples, - bool per_sample_shading, bool true_color, bool scaled_dithering, - bool write_mask_as_depth, bool disable_color_perspective, - bool supports_dual_source_blend, bool supports_framebuffer_fetch) - : ShaderGen(render_api, GetShaderLanguageForAPI(render_api), supports_dual_source_blend, supports_framebuffer_fetch), - m_resolution_scale(resolution_scale), m_multisamples(multisamples), m_per_sample_shading(per_sample_shading), - m_true_color(true_color), m_scaled_dithering(scaled_dithering), m_write_mask_as_depth(write_mask_as_depth), - m_disable_color_perspective(disable_color_perspective) +GPU_HW_ShaderGen::GPU_HW_ShaderGen(RenderAPI render_api, bool supports_dual_source_blend, + bool supports_framebuffer_fetch) + : ShaderGen(render_api, GetShaderLanguageForAPI(render_api), supports_dual_source_blend, supports_framebuffer_fetch) { } GPU_HW_ShaderGen::~GPU_HW_ShaderGen() = default; -void GPU_HW_ShaderGen::WriteColorConversionFunctions(std::stringstream& ss) +void GPU_HW_ShaderGen::WriteColorConversionFunctions(std::stringstream& ss) const { ss << R"( uint RGBA8ToRGBA5551(float4 v) @@ -45,7 +40,7 @@ float4 RGBA5551ToRGBA8(uint v) )"; } -void GPU_HW_ShaderGen::WriteBatchUniformBuffer(std::stringstream& ss) +void GPU_HW_ShaderGen::WriteBatchUniformBuffer(std::stringstream& ss) const { DeclareUniformBuffer(ss, {"uint2 u_texture_window_and", "uint2 u_texture_window_or", "float u_src_alpha_factor", @@ -55,8 +50,10 @@ void GPU_HW_ShaderGen::WriteBatchUniformBuffer(std::stringstream& ss) false); } -std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured, bool palette, bool page_texture, bool uv_limits, - bool force_round_texcoords, bool pgxp_depth) +std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool upscaled, bool msaa, bool per_sample_shading, + bool textured, bool palette, bool page_texture, bool uv_limits, + bool force_round_texcoords, bool pgxp_depth, + bool disable_color_perspective) const { std::stringstream ss; WriteHeader(ss); @@ -66,7 +63,7 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured, bool pale DefineMacro(ss, "UV_LIMITS", uv_limits); DefineMacro(ss, "FORCE_ROUND_TEXCOORDS", force_round_texcoords); DefineMacro(ss, "PGXP_DEPTH", pgxp_depth); - DefineMacro(ss, "UPSCALED", m_resolution_scale > 1); + DefineMacro(ss, "UPSCALED", upscaled); WriteBatchUniformBuffer(ss); @@ -76,13 +73,12 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured, bool pale { DeclareVertexEntryPoint( ss, {"float4 a_pos", "float4 a_col0", "uint a_texcoord", "uint a_texpage", "float4 a_uv_limits"}, 1, 1, - {{"nointerpolation", "float4 v_uv_limits"}}, false, "", UsingMSAA(), UsingPerSampleShading(), - m_disable_color_perspective); + {{"nointerpolation", "float4 v_uv_limits"}}, false, "", msaa, per_sample_shading, disable_color_perspective); } else { DeclareVertexEntryPoint(ss, {"float4 a_pos", "float4 a_col0", "uint a_texcoord", "uint a_texpage"}, 1, 1, {}, - false, "", UsingMSAA(), UsingPerSampleShading(), m_disable_color_perspective); + false, "", msaa, per_sample_shading, disable_color_perspective); } } else if (textured) @@ -93,19 +89,19 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured, bool pale ss, {"float4 a_pos", "float4 a_col0", "uint a_texcoord", "uint a_texpage", "float4 a_uv_limits"}, 1, 1, {{"nointerpolation", palette ? "uint4 v_texpage" : "uint2 v_texpage"}, {"nointerpolation", "float4 v_uv_limits"}}, - false, "", UsingMSAA(), UsingPerSampleShading(), m_disable_color_perspective); + false, "", msaa, per_sample_shading, disable_color_perspective); } else { DeclareVertexEntryPoint(ss, {"float4 a_pos", "float4 a_col0", "uint a_texcoord", "uint a_texpage"}, 1, 1, - {{"nointerpolation", palette ? "uint4 v_texpage" : "uint2 v_texpage"}}, false, "", - UsingMSAA(), UsingPerSampleShading(), m_disable_color_perspective); + {{"nointerpolation", palette ? "uint4 v_texpage" : "uint2 v_texpage"}}, false, "", msaa, + per_sample_shading, disable_color_perspective); } } else { - DeclareVertexEntryPoint(ss, {"float4 a_pos", "float4 a_col0"}, 1, 0, {}, false, "", UsingMSAA(), - UsingPerSampleShading(), m_disable_color_perspective); + DeclareVertexEntryPoint(ss, {"float4 a_pos", "float4 a_col0"}, 1, 0, {}, false, "", msaa, per_sample_shading, + disable_color_perspective); } ss << R"( @@ -179,7 +175,7 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured, bool pale return ss.str(); } -void GPU_HW_ShaderGen::WriteBatchTextureFilter(std::stringstream& ss, GPUTextureFilter texture_filter) +void GPU_HW_ShaderGen::WriteBatchTextureFilter(std::stringstream& ss, GPUTextureFilter texture_filter) const { // JINC2 and xBRZ shaders originally from beetle-psx, modified to support filtering mask channel. if (texture_filter == GPUTextureFilter::Bilinear || texture_filter == GPUTextureFilter::BilinearBinAlpha) @@ -713,10 +709,12 @@ void FilteredSampleFromVRAM(TEXPAGE_VALUE texpage, float2 coords, float4 uv_limi std::string GPU_HW_ShaderGen::GenerateBatchFragmentShader( GPU_HW::BatchRenderMode render_mode, GPUTransparencyMode transparency, GPU_HW::BatchTextureMode texture_mode, - GPUTextureFilter texture_filtering, bool uv_limits, bool force_round_texcoords, bool dithering, bool interlacing, - bool check_mask, bool use_rov, bool use_rov_depth, bool rov_depth_test) + GPUTextureFilter texture_filtering, bool upscaled, bool msaa, bool per_sample_shading, bool uv_limits, + bool force_round_texcoords, bool true_color, bool dithering, bool scaled_dithering, bool disable_color_perspective, + bool interlacing, bool check_mask, bool write_mask_as_depth, bool use_rov, bool use_rov_depth, + bool rov_depth_test) const { - DebugAssert(!m_true_color || !dithering); // Should not be doing dithering+true color. + DebugAssert(!true_color || !dithering); // Should not be doing dithering+true color. // TODO: don't write depth for shader blend DebugAssert(transparency == GPUTransparencyMode::Disabled || render_mode == GPU_HW::BatchRenderMode::ShaderBlend); @@ -746,18 +744,18 @@ std::string GPU_HW_ShaderGen::GenerateBatchFragmentShader( DefineMacro(ss, "PALETTE_8_BIT", texture_mode == GPU_HW::BatchTextureMode::Palette8Bit); DefineMacro(ss, "PAGE_TEXTURE", page_texture); DefineMacro(ss, "DITHERING", dithering); - DefineMacro(ss, "DITHERING_SCALED", m_scaled_dithering); + DefineMacro(ss, "DITHERING_SCALED", dithering && scaled_dithering); DefineMacro(ss, "INTERLACING", interlacing); - DefineMacro(ss, "TRUE_COLOR", m_true_color); + DefineMacro(ss, "TRUE_COLOR", true_color); DefineMacro(ss, "TEXTURE_FILTERING", texture_filtering != GPUTextureFilter::Nearest); DefineMacro(ss, "UV_LIMITS", uv_limits); DefineMacro(ss, "USE_ROV", use_rov); DefineMacro(ss, "USE_ROV_DEPTH", use_rov_depth); DefineMacro(ss, "ROV_DEPTH_TEST", rov_depth_test); DefineMacro(ss, "USE_DUAL_SOURCE", use_dual_source); - DefineMacro(ss, "WRITE_MASK_AS_DEPTH", m_write_mask_as_depth); + DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth); DefineMacro(ss, "FORCE_ROUND_TEXCOORDS", force_round_texcoords); - DefineMacro(ss, "UPSCALED", m_resolution_scale > 1); + DefineMacro(ss, "UPSCALED", upscaled); // Used for converting to normalized coordinates for sampling. ss << "CONSTANT float2 RCP_VRAM_SIZE = float2(1.0 / float(" << VRAM_WIDTH << "), 1.0 / float(" << VRAM_HEIGHT @@ -903,14 +901,14 @@ float4 SampleFromPageTexture(float2 coords) if (uv_limits) { DeclareFragmentEntryPoint(ss, 1, 1, {{"nointerpolation", "float4 v_uv_limits"}}, true, num_fragment_outputs, - use_dual_source, m_write_mask_as_depth, UsingMSAA(), UsingPerSampleShading(), false, - m_disable_color_perspective, shader_blending && !use_rov, use_rov); + use_dual_source, write_mask_as_depth, msaa, per_sample_shading, false, + disable_color_perspective, shader_blending && !use_rov, use_rov); } else { - DeclareFragmentEntryPoint(ss, 1, 1, {}, true, num_fragment_outputs, use_dual_source, m_write_mask_as_depth, - UsingMSAA(), UsingPerSampleShading(), false, m_disable_color_perspective, - shader_blending && !use_rov, use_rov); + DeclareFragmentEntryPoint(ss, 1, 1, {}, true, num_fragment_outputs, use_dual_source, write_mask_as_depth, msaa, + per_sample_shading, false, disable_color_perspective, shader_blending && !use_rov, + use_rov); } } else if (textured) @@ -923,23 +921,22 @@ float4 SampleFromPageTexture(float2 coords) DeclareFragmentEntryPoint(ss, 1, 1, {{"nointerpolation", palette ? "uint4 v_texpage" : "uint2 v_texpage"}, {"nointerpolation", "float4 v_uv_limits"}}, - true, num_fragment_outputs, use_dual_source, m_write_mask_as_depth, UsingMSAA(), - UsingPerSampleShading(), false, m_disable_color_perspective, - shader_blending && !use_rov, use_rov); + true, num_fragment_outputs, use_dual_source, write_mask_as_depth, msaa, + per_sample_shading, false, disable_color_perspective, shader_blending && !use_rov, + use_rov); } else { DeclareFragmentEntryPoint(ss, 1, 1, {{"nointerpolation", palette ? "uint4 v_texpage" : "uint2 v_texpage"}}, true, - num_fragment_outputs, use_dual_source, m_write_mask_as_depth, UsingMSAA(), - UsingPerSampleShading(), false, m_disable_color_perspective, - shader_blending && !use_rov, use_rov); + num_fragment_outputs, use_dual_source, write_mask_as_depth, msaa, per_sample_shading, + false, disable_color_perspective, shader_blending && !use_rov, use_rov); } } else { - DeclareFragmentEntryPoint(ss, 1, 0, {}, true, num_fragment_outputs, use_dual_source, m_write_mask_as_depth, - UsingMSAA(), UsingPerSampleShading(), false, m_disable_color_perspective, - shader_blending && !use_rov, use_rov); + DeclareFragmentEntryPoint(ss, 1, 0, {}, true, num_fragment_outputs, use_dual_source, write_mask_as_depth, msaa, + per_sample_shading, false, disable_color_perspective, shader_blending && !use_rov, + use_rov); } ss << R"( @@ -1181,23 +1178,26 @@ float4 SampleFromPageTexture(float2 coords) return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateVRAMExtractFragmentShader(bool color_24bit, bool depth_buffer) +std::string GPU_HW_ShaderGen::GenerateVRAMExtractFragmentShader(u32 resolution_scale, u32 multisamples, + bool color_24bit, bool depth_buffer) const { + const bool msaa = (multisamples > 1); + std::stringstream ss; WriteHeader(ss); WriteColorConversionFunctions(ss); DefineMacro(ss, "COLOR_24BIT", color_24bit); DefineMacro(ss, "DEPTH_BUFFER", depth_buffer); - DefineMacro(ss, "MULTISAMPLING", UsingMSAA()); - ss << "CONSTANT uint RESOLUTION_SCALE = " << m_resolution_scale << "u;\n"; + DefineMacro(ss, "MULTISAMPLING", msaa); + ss << "CONSTANT uint RESOLUTION_SCALE = " << resolution_scale << "u;\n"; ss << "CONSTANT uint2 VRAM_SIZE = uint2(" << VRAM_WIDTH << ", " << VRAM_HEIGHT << ") * RESOLUTION_SCALE;\n"; - ss << "CONSTANT uint MULTISAMPLES = " << m_multisamples << "u;\n"; + ss << "CONSTANT uint MULTISAMPLES = " << multisamples << "u;\n"; DeclareUniformBuffer(ss, {"uint2 u_vram_offset", "uint u_skip_x", "uint u_line_skip"}, true); - DeclareTexture(ss, "samp0", 0, UsingMSAA()); + DeclareTexture(ss, "samp0", 0, msaa); if (depth_buffer) - DeclareTexture(ss, "samp1", 1, UsingMSAA()); + DeclareTexture(ss, "samp1", 1, msaa); ss << R"( float4 LoadVRAM(int2 coords) @@ -1269,7 +1269,7 @@ float3 SampleVRAM24(uint2 icoords) return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateWireframeGeometryShader() +std::string GPU_HW_ShaderGen::GenerateWireframeGeometryShader() const { std::stringstream ss; WriteHeader(ss); @@ -1342,7 +1342,7 @@ void main(triangle GSInput input[3], inout LineStream output) return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateWireframeFragmentShader() +std::string GPU_HW_ShaderGen::GenerateWireframeFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -1357,18 +1357,20 @@ std::string GPU_HW_ShaderGen::GenerateWireframeFragmentShader() return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateVRAMReadFragmentShader() +std::string GPU_HW_ShaderGen::GenerateVRAMReadFragmentShader(u32 resolution_scale, u32 multisamples) const { + const bool msaa = (multisamples > 1); + std::stringstream ss; WriteHeader(ss); WriteColorConversionFunctions(ss); - DefineMacro(ss, "MULTISAMPLING", UsingMSAA()); - ss << "CONSTANT uint RESOLUTION_SCALE = " << m_resolution_scale << "u;\n"; - ss << "CONSTANT uint MULTISAMPLES = " << m_multisamples << "u;\n"; + DefineMacro(ss, "MULTISAMPLING", msaa); + ss << "CONSTANT uint RESOLUTION_SCALE = " << resolution_scale << "u;\n"; + ss << "CONSTANT uint MULTISAMPLES = " << multisamples << "u;\n"; DeclareUniformBuffer(ss, {"uint2 u_base_coords", "uint2 u_size"}, true); - DeclareTexture(ss, "samp0", 0, UsingMSAA()); + DeclareTexture(ss, "samp0", 0, msaa); ss << R"( float4 LoadVRAM(int2 coords) @@ -1420,16 +1422,17 @@ uint SampleVRAM(uint2 coords) return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_buffer, bool use_ssbo) +std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(u32 resolution_scale, bool use_buffer, bool use_ssbo, + bool write_mask_as_depth) const { std::stringstream ss; WriteHeader(ss); WriteColorConversionFunctions(ss); - DefineMacro(ss, "WRITE_MASK_AS_DEPTH", m_write_mask_as_depth); + DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth); DefineMacro(ss, "USE_BUFFER", use_buffer); - ss << "CONSTANT uint RESOLUTION_SCALE = " << m_resolution_scale << "u;\n"; + ss << "CONSTANT uint RESOLUTION_SCALE = " << resolution_scale << "u;\n"; ss << "CONSTANT uint2 VRAM_SIZE = uint2(" << VRAM_WIDTH << ", " << VRAM_HEIGHT << ");\n"; DeclareUniformBuffer(ss, @@ -1463,7 +1466,7 @@ std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_buffer, b ss << "#define GET_VALUE(buffer_offset) (LOAD_TEXTURE_BUFFER(samp0, int(buffer_offset)).r)\n\n"; } - DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, false, m_write_mask_as_depth); + DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, false, write_mask_as_depth); ss << R"( { uint2 coords = uint2(v_pos.xy) / uint2(RESOLUTION_SCALE, RESOLUTION_SCALE); @@ -1496,17 +1499,17 @@ std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_buffer, b return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader() +std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader(u32 resolution_scale, bool write_mask_as_depth) const { // TODO: This won't currently work because we can't bind the texture to both the shader and framebuffer. const bool msaa = false; std::stringstream ss; WriteHeader(ss); - DefineMacro(ss, "WRITE_MASK_AS_DEPTH", m_write_mask_as_depth); + DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth); DefineMacro(ss, "MSAA_COPY", msaa); - ss << "CONSTANT uint RESOLUTION_SCALE = " << m_resolution_scale << "u;\n"; + ss << "CONSTANT uint RESOLUTION_SCALE = " << resolution_scale << "u;\n"; ss << "CONSTANT uint2 VRAM_SIZE = uint2(" << VRAM_WIDTH << ", " << VRAM_HEIGHT << ") * RESOLUTION_SCALE;\n"; DeclareUniformBuffer(ss, @@ -1515,7 +1518,7 @@ std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader() true); DeclareTexture(ss, "samp0", 0, msaa); - DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, false, m_write_mask_as_depth, false, false, msaa); + DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, false, write_mask_as_depth, false, false, msaa); ss << R"( { uint2 dst_coords = uint2(v_pos.xy); @@ -1550,18 +1553,19 @@ std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader() return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced) +std::string GPU_HW_ShaderGen::GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced, + bool write_mask_as_depth) const { std::stringstream ss; WriteHeader(ss); - DefineMacro(ss, "WRITE_MASK_AS_DEPTH", m_write_mask_as_depth); + DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth); DefineMacro(ss, "WRAPPED", wrapped); DefineMacro(ss, "INTERLACED", interlaced); DeclareUniformBuffer( ss, {"uint2 u_dst_coords", "uint2 u_end_coords", "float4 u_fill_color", "uint u_interlaced_displayed_field"}, true); - DeclareFragmentEntryPoint(ss, 0, 1, {}, interlaced || wrapped, 1, false, m_write_mask_as_depth, false, false, false); + DeclareFragmentEntryPoint(ss, 0, 1, {}, interlaced || wrapped, 1, false, write_mask_as_depth, false, false, false); ss << R"( { #if INTERLACED || WRAPPED @@ -1591,13 +1595,13 @@ std::string GPU_HW_ShaderGen::GenerateVRAMFillFragmentShader(bool wrapped, bool return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateVRAMUpdateDepthFragmentShader() +std::string GPU_HW_ShaderGen::GenerateVRAMUpdateDepthFragmentShader(bool msaa) const { std::stringstream ss; WriteHeader(ss); - DefineMacro(ss, "MULTISAMPLING", UsingMSAA()); - DeclareTexture(ss, "samp0", 0, UsingMSAA()); - DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 0, false, true, false, false, UsingMSAA()); + DefineMacro(ss, "MULTISAMPLING", msaa); + DeclareTexture(ss, "samp0", 0, msaa); + DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 0, false, true, false, false, msaa); ss << R"( { @@ -1612,12 +1616,12 @@ std::string GPU_HW_ShaderGen::GenerateVRAMUpdateDepthFragmentShader() return ss.str(); } -void GPU_HW_ShaderGen::WriteAdaptiveDownsampleUniformBuffer(std::stringstream& ss) +void GPU_HW_ShaderGen::WriteAdaptiveDownsampleUniformBuffer(std::stringstream& ss) const { DeclareUniformBuffer(ss, {"float2 u_uv_min", "float2 u_uv_max", "float2 u_pixel_size", "float u_lod"}, true); } -std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleVertexShader() +std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleVertexShader() const { std::stringstream ss; WriteHeader(ss); @@ -1636,7 +1640,7 @@ std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleVertexShader() return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleMipFragmentShader() +std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleMipFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -1670,7 +1674,7 @@ std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleMipFragmentShader() return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleBlurFragmentShader() +std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleBlurFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -1707,7 +1711,7 @@ std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleBlurFragmentShader() return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleCompositeFragmentShader() +std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleCompositeFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -1725,7 +1729,7 @@ std::string GPU_HW_ShaderGen::GenerateAdaptiveDownsampleCompositeFragmentShader( return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateBoxSampleDownsampleFragmentShader(u32 factor) +std::string GPU_HW_ShaderGen::GenerateBoxSampleDownsampleFragmentShader(u32 factor) const { std::stringstream ss; WriteHeader(ss); @@ -1752,7 +1756,7 @@ std::string GPU_HW_ShaderGen::GenerateBoxSampleDownsampleFragmentShader(u32 fact return ss.str(); } -std::string GPU_HW_ShaderGen::GenerateReplacementMergeFragmentShader(bool semitransparent, bool bilinear_filter) +std::string GPU_HW_ShaderGen::GenerateReplacementMergeFragmentShader(bool semitransparent, bool bilinear_filter) const { std::stringstream ss; WriteHeader(ss); diff --git a/src/core/gpu_hw_shadergen.h b/src/core/gpu_hw_shadergen.h index 9cba042c9..c9001f77b 100644 --- a/src/core/gpu_hw_shadergen.h +++ b/src/core/gpu_hw_shadergen.h @@ -10,48 +10,41 @@ class GPU_HW_ShaderGen : public ShaderGen { public: - GPU_HW_ShaderGen(RenderAPI render_api, u32 resolution_scale, u32 multisamples, bool per_sample_shading, - bool true_color, bool scaled_dithering, bool write_mask_as_depth, bool disable_color_perspective, - bool supports_dual_source_blend, bool supports_framebuffer_fetch); + GPU_HW_ShaderGen(RenderAPI render_api, bool supports_dual_source_blend, bool supports_framebuffer_fetch); ~GPU_HW_ShaderGen(); - std::string GenerateBatchVertexShader(bool textured, bool palette, bool page_texture, bool uv_limits, - bool force_round_texcoords, bool pgxp_depth); + std::string GenerateBatchVertexShader(bool upscaled, bool msaa, bool per_sample_shading, bool textured, bool palette, + bool page_texture, bool uv_limits, bool force_round_texcoords, bool pgxp_depth, + bool disable_color_perspective) const; std::string GenerateBatchFragmentShader(GPU_HW::BatchRenderMode render_mode, GPUTransparencyMode transparency, GPU_HW::BatchTextureMode texture_mode, GPUTextureFilter texture_filtering, - bool uv_limits, bool force_round_texcoords, bool dithering, bool interlacing, - bool check_mask, bool use_rov, bool use_rov_depth, bool rov_depth_test); - std::string GenerateWireframeGeometryShader(); - std::string GenerateWireframeFragmentShader(); - std::string GenerateVRAMReadFragmentShader(); - std::string GenerateVRAMWriteFragmentShader(bool use_buffer, bool use_ssbo); - std::string GenerateVRAMCopyFragmentShader(); - std::string GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced); - std::string GenerateVRAMUpdateDepthFragmentShader(); - std::string GenerateVRAMExtractFragmentShader(bool color_24bit, bool depth_buffer); + bool upscaled, bool msaa, bool per_sample_shading, bool uv_limits, + bool force_round_texcoords, bool true_color, bool dithering, + bool scaled_dithering, bool disable_color_perspective, bool interlacing, + bool check_mask, bool write_mask_as_depth, bool use_rov, bool use_rov_depth, + bool rov_depth_test) const; + std::string GenerateWireframeGeometryShader() const; + std::string GenerateWireframeFragmentShader() const; + std::string GenerateVRAMReadFragmentShader(u32 resolution_scale, u32 multisamples) const; + std::string GenerateVRAMWriteFragmentShader(u32 resolution_scale, bool use_buffer, bool use_ssbo, + bool write_mask_as_depth) const; + std::string GenerateVRAMCopyFragmentShader(u32 resolution_scale, bool write_mask_as_depth) const; + std::string GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced, bool write_mask_as_depth) const; + std::string GenerateVRAMUpdateDepthFragmentShader(bool msaa) const; + std::string GenerateVRAMExtractFragmentShader(u32 resolution_scale, u32 multisamples, bool color_24bit, + bool depth_buffer) const; - std::string GenerateAdaptiveDownsampleVertexShader(); - std::string GenerateAdaptiveDownsampleMipFragmentShader(); - std::string GenerateAdaptiveDownsampleBlurFragmentShader(); - std::string GenerateAdaptiveDownsampleCompositeFragmentShader(); - std::string GenerateBoxSampleDownsampleFragmentShader(u32 factor); + std::string GenerateAdaptiveDownsampleVertexShader() const; + std::string GenerateAdaptiveDownsampleMipFragmentShader() const; + std::string GenerateAdaptiveDownsampleBlurFragmentShader() const; + std::string GenerateAdaptiveDownsampleCompositeFragmentShader() const; + std::string GenerateBoxSampleDownsampleFragmentShader(u32 factor) const; - std::string GenerateReplacementMergeFragmentShader(bool semitransparent, bool bilinear_filter); + std::string GenerateReplacementMergeFragmentShader(bool semitransparent, bool bilinear_filter) const; private: - ALWAYS_INLINE bool UsingMSAA() const { return m_multisamples > 1; } - ALWAYS_INLINE bool UsingPerSampleShading() const { return m_multisamples > 1 && m_per_sample_shading; } - - void WriteColorConversionFunctions(std::stringstream& ss); - void WriteBatchUniformBuffer(std::stringstream& ss); - void WriteBatchTextureFilter(std::stringstream& ss, GPUTextureFilter texture_filter); - void WriteAdaptiveDownsampleUniformBuffer(std::stringstream& ss); - - u32 m_resolution_scale; - u32 m_multisamples; - bool m_per_sample_shading; - bool m_true_color; - bool m_scaled_dithering; - bool m_write_mask_as_depth; - bool m_disable_color_perspective; + void WriteColorConversionFunctions(std::stringstream& ss) const; + void WriteBatchUniformBuffer(std::stringstream& ss) const; + void WriteBatchTextureFilter(std::stringstream& ss, GPUTextureFilter texture_filter) const; + void WriteAdaptiveDownsampleUniformBuffer(std::stringstream& ss) const; }; diff --git a/src/core/gpu_hw_texture_cache.cpp b/src/core/gpu_hw_texture_cache.cpp index 29d8f6a9e..630456b78 100644 --- a/src/core/gpu_hw_texture_cache.cpp +++ b/src/core/gpu_hw_texture_cache.cpp @@ -765,8 +765,8 @@ bool GPUTextureCache::CompilePipelines() // Most flags don't matter here. const GPUDevice::Features features = g_gpu_device->GetFeatures(); - GPU_HW_ShaderGen shadergen(g_gpu_device->GetRenderAPI(), 1, 1, false, false, false, false, false, - features.dual_source_blend, features.framebuffer_fetch); + const GPU_HW_ShaderGen shadergen(g_gpu_device->GetRenderAPI(), features.dual_source_blend, + features.framebuffer_fetch); std::unique_ptr fullscreen_quad_vertex_shader = g_gpu_device->CreateShader( GPUShaderStage::Vertex, shadergen.GetLanguage(), shadergen.GenerateScreenQuadVertexShader()); if (!fullscreen_quad_vertex_shader) diff --git a/src/core/gpu_shadergen.cpp b/src/core/gpu_shadergen.cpp index dfe544d2e..6f43c3ee4 100644 --- a/src/core/gpu_shadergen.cpp +++ b/src/core/gpu_shadergen.cpp @@ -10,7 +10,7 @@ GPUShaderGen::GPUShaderGen(RenderAPI render_api, bool supports_dual_source_blend GPUShaderGen::~GPUShaderGen() = default; -void GPUShaderGen::WriteDisplayUniformBuffer(std::stringstream& ss) +void GPUShaderGen::WriteDisplayUniformBuffer(std::stringstream& ss) const { // Rotation matrix split into rows to avoid padding in HLSL. DeclareUniformBuffer(ss, @@ -24,7 +24,7 @@ float2 ClampUV(float2 uv) { })"; } -std::string GPUShaderGen::GenerateDisplayVertexShader() +std::string GPUShaderGen::GenerateDisplayVertexShader() const { std::stringstream ss; WriteHeader(ss); @@ -48,7 +48,7 @@ std::string GPUShaderGen::GenerateDisplayVertexShader() return ss.str(); } -std::string GPUShaderGen::GenerateDisplayFragmentShader(bool clamp_uv, bool nearest) +std::string GPUShaderGen::GenerateDisplayFragmentShader(bool clamp_uv, bool nearest) const { std::stringstream ss; WriteHeader(ss); @@ -73,7 +73,7 @@ std::string GPUShaderGen::GenerateDisplayFragmentShader(bool clamp_uv, bool near return ss.str(); } -std::string GPUShaderGen::GenerateDisplaySharpBilinearFragmentShader() +std::string GPUShaderGen::GenerateDisplaySharpBilinearFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -102,7 +102,7 @@ std::string GPUShaderGen::GenerateDisplaySharpBilinearFragmentShader() return ss.str(); } -std::string GPUShaderGen::GenerateInterleavedFieldExtractFragmentShader() +std::string GPUShaderGen::GenerateInterleavedFieldExtractFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -120,7 +120,7 @@ std::string GPUShaderGen::GenerateInterleavedFieldExtractFragmentShader() return ss.str(); } -std::string GPUShaderGen::GenerateDeinterlaceWeaveFragmentShader() +std::string GPUShaderGen::GenerateDeinterlaceWeaveFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -141,7 +141,7 @@ std::string GPUShaderGen::GenerateDeinterlaceWeaveFragmentShader() return ss.str(); } -std::string GPUShaderGen::GenerateDeinterlaceBlendFragmentShader() +std::string GPUShaderGen::GenerateDeinterlaceBlendFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -161,7 +161,7 @@ std::string GPUShaderGen::GenerateDeinterlaceBlendFragmentShader() return ss.str(); } -std::string GPUShaderGen::GenerateFastMADReconstructFragmentShader() +std::string GPUShaderGen::GenerateFastMADReconstructFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -220,7 +220,7 @@ CONSTANT float3 SENSITIVITY = float3(0.08f, 0.08f, 0.08f); return ss.str(); } -std::string GPUShaderGen::GenerateChromaSmoothingFragmentShader() +std::string GPUShaderGen::GenerateChromaSmoothingFragmentShader() const { std::stringstream ss; WriteHeader(ss); diff --git a/src/core/gpu_shadergen.h b/src/core/gpu_shadergen.h index 525de29c2..5a912ed68 100644 --- a/src/core/gpu_shadergen.h +++ b/src/core/gpu_shadergen.h @@ -11,17 +11,17 @@ public: GPUShaderGen(RenderAPI render_api, bool supports_dual_source_blend, bool supports_framebuffer_fetch); ~GPUShaderGen(); - std::string GenerateDisplayVertexShader(); - std::string GenerateDisplayFragmentShader(bool clamp_uv, bool nearest); - std::string GenerateDisplaySharpBilinearFragmentShader(); + std::string GenerateDisplayVertexShader() const; + std::string GenerateDisplayFragmentShader(bool clamp_uv, bool nearest) const; + std::string GenerateDisplaySharpBilinearFragmentShader() const; - std::string GenerateInterleavedFieldExtractFragmentShader(); - std::string GenerateDeinterlaceWeaveFragmentShader(); - std::string GenerateDeinterlaceBlendFragmentShader(); - std::string GenerateFastMADReconstructFragmentShader(); + std::string GenerateInterleavedFieldExtractFragmentShader() const; + std::string GenerateDeinterlaceWeaveFragmentShader() const; + std::string GenerateDeinterlaceBlendFragmentShader() const; + std::string GenerateFastMADReconstructFragmentShader() const; - std::string GenerateChromaSmoothingFragmentShader(); + std::string GenerateChromaSmoothingFragmentShader() const; private: - void WriteDisplayUniformBuffer(std::stringstream& ss); + void WriteDisplayUniformBuffer(std::stringstream& ss) const; }; diff --git a/src/util/shadergen.cpp b/src/util/shadergen.cpp index 10cd29129..dacd9185e 100644 --- a/src/util/shadergen.cpp +++ b/src/util/shadergen.cpp @@ -88,12 +88,12 @@ bool ShaderGen::UseGLSLBindingLayout() #endif } -void ShaderGen::DefineMacro(std::stringstream& ss, const char* name, bool enabled) +void ShaderGen::DefineMacro(std::stringstream& ss, const char* name, bool enabled) const { ss << "#define " << name << " " << BoolToUInt32(enabled) << "\n"; } -void ShaderGen::DefineMacro(std::stringstream& ss, const char* name, s32 value) +void ShaderGen::DefineMacro(std::stringstream& ss, const char* name, s32 value) const { ss << "#define " << name << " " << value << "\n"; } @@ -151,7 +151,7 @@ TinyString ShaderGen::GetGLSLVersionString(RenderAPI render_api, u32 version) (glsl_es && major_version >= 3) ? " es" : ""); } -void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */) +void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */) const { if (m_shader_language == GPUShaderLanguage::GLSL || m_shader_language == GPUShaderLanguage::GLSLES) ss << m_glsl_version_string << "\n\n"; @@ -340,7 +340,7 @@ void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */ m_has_uniform_buffer = false; } -void ShaderGen::WriteUniformBufferDeclaration(std::stringstream& ss, bool push_constant_on_vulkan) +void ShaderGen::WriteUniformBufferDeclaration(std::stringstream& ss, bool push_constant_on_vulkan) const { if (m_shader_language == GPUShaderLanguage::GLSLVK) { @@ -371,7 +371,7 @@ void ShaderGen::WriteUniformBufferDeclaration(std::stringstream& ss, bool push_c } void ShaderGen::DeclareUniformBuffer(std::stringstream& ss, const std::initializer_list& members, - bool push_constant_on_vulkan) + bool push_constant_on_vulkan) const { WriteUniformBufferDeclaration(ss, push_constant_on_vulkan); @@ -382,7 +382,7 @@ void ShaderGen::DeclareUniformBuffer(std::stringstream& ss, const std::initializ } void ShaderGen::DeclareTexture(std::stringstream& ss, const char* name, u32 index, bool multisampled /* = false */, - bool is_int /* = false */, bool is_unsigned /* = false */) + bool is_int /* = false */, bool is_unsigned /* = false */) const { if (m_glsl) { @@ -402,7 +402,8 @@ void ShaderGen::DeclareTexture(std::stringstream& ss, const char* name, u32 inde } } -void ShaderGen::DeclareTextureBuffer(std::stringstream& ss, const char* name, u32 index, bool is_int, bool is_unsigned) +void ShaderGen::DeclareTextureBuffer(std::stringstream& ss, const char* name, u32 index, bool is_int, + bool is_unsigned) const { if (m_glsl) { @@ -421,7 +422,7 @@ void ShaderGen::DeclareTextureBuffer(std::stringstream& ss, const char* name, u3 } void ShaderGen::DeclareImage(std::stringstream& ss, const char* name, u32 index, bool is_float /* = false */, - bool is_int /* = false */, bool is_unsigned /* = false */) + bool is_int /* = false */, bool is_unsigned /* = false */) const { if (m_glsl) { @@ -464,7 +465,7 @@ void ShaderGen::DeclareVertexEntryPoint( std::stringstream& ss, const std::initializer_list& attributes, u32 num_color_outputs, u32 num_texcoord_outputs, const std::initializer_list>& additional_outputs, bool declare_vertex_id /* = false */, const char* output_block_suffix /* = "" */, bool msaa /* = false */, - bool ssaa /* = false */, bool noperspective_color /* = false */) + bool ssaa /* = false */, bool noperspective_color /* = false */) const { if (m_glsl) { @@ -574,7 +575,7 @@ void ShaderGen::DeclareFragmentEntryPoint( bool declare_fragcoord /* = false */, u32 num_color_outputs /* = 1 */, bool dual_source_output /* = false */, bool depth_output /* = false */, bool msaa /* = false */, bool ssaa /* = false */, bool declare_sample_id /* = false */, bool noperspective_color /* = false */, bool feedback_loop /* = false */, - bool rov /* = false */) + bool rov /* = false */) const { if (m_glsl) { @@ -779,7 +780,7 @@ void ShaderGen::DeclareFragmentEntryPoint( } } -std::string ShaderGen::GenerateScreenQuadVertexShader(float z /* = 0.0f */) +std::string ShaderGen::GenerateScreenQuadVertexShader(float z /* = 0.0f */) const { std::stringstream ss; WriteHeader(ss); @@ -795,7 +796,7 @@ std::string ShaderGen::GenerateScreenQuadVertexShader(float z /* = 0.0f */) return ss.str(); } -std::string ShaderGen::GenerateUVQuadVertexShader() +std::string ShaderGen::GenerateUVQuadVertexShader() const { std::stringstream ss; WriteHeader(ss); @@ -815,7 +816,7 @@ std::string ShaderGen::GenerateUVQuadVertexShader() return ss.str(); } -std::string ShaderGen::GenerateFillFragmentShader() +std::string ShaderGen::GenerateFillFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -831,7 +832,7 @@ std::string ShaderGen::GenerateFillFragmentShader() return ss.str(); } -std::string ShaderGen::GenerateCopyFragmentShader() +std::string ShaderGen::GenerateCopyFragmentShader() const { std::stringstream ss; WriteHeader(ss); @@ -849,7 +850,7 @@ std::string ShaderGen::GenerateCopyFragmentShader() return ss.str(); } -std::string ShaderGen::GenerateImGuiVertexShader() +std::string ShaderGen::GenerateImGuiVertexShader() const { std::stringstream ss; WriteHeader(ss); @@ -869,7 +870,7 @@ std::string ShaderGen::GenerateImGuiVertexShader() return ss.str(); } -std::string ShaderGen::GenerateImGuiFragmentShader() +std::string ShaderGen::GenerateImGuiFragmentShader() const { std::stringstream ss; WriteHeader(ss); diff --git a/src/util/shadergen.h b/src/util/shadergen.h index dff89af49..50c823535 100644 --- a/src/util/shadergen.h +++ b/src/util/shadergen.h @@ -25,13 +25,13 @@ public: ALWAYS_INLINE GPUShaderLanguage GetLanguage() const { return m_shader_language; } - std::string GenerateScreenQuadVertexShader(float z = 0.0f); - std::string GenerateUVQuadVertexShader(); - std::string GenerateFillFragmentShader(); - std::string GenerateCopyFragmentShader(); + std::string GenerateScreenQuadVertexShader(float z = 0.0f) const; + std::string GenerateUVQuadVertexShader() const; + std::string GenerateFillFragmentShader() const; + std::string GenerateCopyFragmentShader() const; - std::string GenerateImGuiVertexShader(); - std::string GenerateImGuiFragmentShader(); + std::string GenerateImGuiVertexShader() const; + std::string GenerateImGuiFragmentShader() const; protected: ALWAYS_INLINE bool IsVulkan() const { return (m_render_api == RenderAPI::Vulkan); } @@ -40,29 +40,29 @@ protected: const char* GetInterpolationQualifier(bool interface_block, bool centroid_interpolation, bool sample_interpolation, bool is_out) const; - void DefineMacro(std::stringstream& ss, const char* name, bool enabled); - void DefineMacro(std::stringstream& ss, const char* name, s32 value); - void WriteHeader(std::stringstream& ss, bool enable_rov = false); - void WriteUniformBufferDeclaration(std::stringstream& ss, bool push_constant_on_vulkan); + void DefineMacro(std::stringstream& ss, const char* name, bool enabled) const; + void DefineMacro(std::stringstream& ss, const char* name, s32 value) const; + void WriteHeader(std::stringstream& ss, bool enable_rov = false) const; + void WriteUniformBufferDeclaration(std::stringstream& ss, bool push_constant_on_vulkan) const; void DeclareUniformBuffer(std::stringstream& ss, const std::initializer_list& members, - bool push_constant_on_vulkan); + bool push_constant_on_vulkan) const; void DeclareTexture(std::stringstream& ss, const char* name, u32 index, bool multisampled = false, - bool is_int = false, bool is_unsigned = false); - void DeclareTextureBuffer(std::stringstream& ss, const char* name, u32 index, bool is_int, bool is_unsigned); + bool is_int = false, bool is_unsigned = false) const; + void DeclareTextureBuffer(std::stringstream& ss, const char* name, u32 index, bool is_int, bool is_unsigned) const; void DeclareImage(std::stringstream& ss, const char* name, u32 index, bool is_float = false, bool is_int = false, - bool is_unsigned = false); + bool is_unsigned = false) const; void DeclareVertexEntryPoint(std::stringstream& ss, const std::initializer_list& attributes, u32 num_color_outputs, u32 num_texcoord_outputs, const std::initializer_list>& additional_outputs, bool declare_vertex_id = false, const char* output_block_suffix = "", bool msaa = false, - bool ssaa = false, bool noperspective_color = false); + bool ssaa = false, bool noperspective_color = false) const; void DeclareFragmentEntryPoint(std::stringstream& ss, u32 num_color_inputs, u32 num_texcoord_inputs, const std::initializer_list>& additional_inputs = {}, bool declare_fragcoord = false, u32 num_color_outputs = 1, bool dual_source_output = false, bool depth_output = false, bool msaa = false, bool ssaa = false, bool declare_sample_id = false, bool noperspective_color = false, - bool feedback_loop = false, bool rov = false); + bool feedback_loop = false, bool rov = false) const; RenderAPI m_render_api; GPUShaderLanguage m_shader_language; @@ -72,7 +72,7 @@ protected: bool m_supports_framebuffer_fetch; bool m_use_glsl_interface_blocks = false; bool m_use_glsl_binding_layout = false; - bool m_has_uniform_buffer = false; + mutable bool m_has_uniform_buffer = false; TinyString m_glsl_version_string; };