diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 3190a25965..4aef75d328 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -113,10 +113,10 @@ std::unique_ptr Renderer::CreateFramebuffer(AbstractTexture } std::unique_ptr Renderer::CreateShaderFromSource(ShaderStage stage, - const char* source, size_t length) + std::string_view source) { DXShader::BinaryData bytecode; - if (!DXShader::CompileShader(D3D::feature_level, &bytecode, stage, source, length)) + if (!DXShader::CompileShader(D3D::feature_level, &bytecode, stage, source)) return nullptr; return DXShader::CreateFromBytecode(stage, std::move(bytecode)); diff --git a/Source/Core/VideoBackends/D3D/Render.h b/Source/Core/VideoBackends/D3D/Render.h index 277cd4f19f..235963834a 100644 --- a/Source/Core/VideoBackends/D3D/Render.h +++ b/Source/Core/VideoBackends/D3D/Render.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include "VideoBackends/D3D/D3DState.h" #include "VideoCommon/RenderBase.h" @@ -28,8 +28,8 @@ public: std::unique_ptr CreateTexture(const TextureConfig& config) override; std::unique_ptr CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override; - std::unique_ptr CreateShaderFromSource(ShaderStage stage, const char* source, - size_t length) override; + std::unique_ptr CreateShaderFromSource(ShaderStage stage, + std::string_view source) override; std::unique_ptr CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) override; std::unique_ptr diff --git a/Source/Core/VideoBackends/D3D12/DXShader.cpp b/Source/Core/VideoBackends/D3D12/DXShader.cpp index e82d2bfc3a..bd06559152 100644 --- a/Source/Core/VideoBackends/D3D12/DXShader.cpp +++ b/Source/Core/VideoBackends/D3D12/DXShader.cpp @@ -24,11 +24,10 @@ std::unique_ptr DXShader::CreateFromBytecode(ShaderStage stage, Binary return shader; } -std::unique_ptr DXShader::CreateFromSource(ShaderStage stage, const char* source, - size_t length) +std::unique_ptr DXShader::CreateFromSource(ShaderStage stage, std::string_view source) { BinaryData bytecode; - if (!CompileShader(g_dx_context->GetFeatureLevel(), &bytecode, stage, source, length)) + if (!CompileShader(g_dx_context->GetFeatureLevel(), &bytecode, stage, source)) return nullptr; return CreateFromBytecode(stage, std::move(bytecode)); diff --git a/Source/Core/VideoBackends/D3D12/DXShader.h b/Source/Core/VideoBackends/D3D12/DXShader.h index cfc9d466de..3fd457d9b8 100644 --- a/Source/Core/VideoBackends/D3D12/DXShader.h +++ b/Source/Core/VideoBackends/D3D12/DXShader.h @@ -3,7 +3,9 @@ // Refer to the license.txt file included. #pragma once + #include +#include #include "VideoBackends/D3D12/Common.h" #include "VideoBackends/D3DCommon/Shader.h" @@ -18,8 +20,7 @@ public: D3D12_SHADER_BYTECODE GetD3DByteCode() const; static std::unique_ptr CreateFromBytecode(ShaderStage stage, BinaryData bytecode); - static std::unique_ptr CreateFromSource(ShaderStage stage, const char* source, - size_t length); + static std::unique_ptr CreateFromSource(ShaderStage stage, std::string_view source); private: DXShader(ShaderStage stage, BinaryData bytecode); diff --git a/Source/Core/VideoBackends/D3D12/Renderer.cpp b/Source/Core/VideoBackends/D3D12/Renderer.cpp index a61a3f40a6..225057dc7a 100644 --- a/Source/Core/VideoBackends/D3D12/Renderer.cpp +++ b/Source/Core/VideoBackends/D3D12/Renderer.cpp @@ -82,9 +82,9 @@ std::unique_ptr Renderer::CreateFramebuffer(AbstractTexture } std::unique_ptr Renderer::CreateShaderFromSource(ShaderStage stage, - const char* source, size_t length) + std::string_view source) { - return DXShader::CreateFromSource(stage, source, length); + return DXShader::CreateFromSource(stage, source); } std::unique_ptr Renderer::CreateShaderFromBinary(ShaderStage stage, diff --git a/Source/Core/VideoBackends/D3D12/Renderer.h b/Source/Core/VideoBackends/D3D12/Renderer.h index f660f5f817..fe985b7df5 100644 --- a/Source/Core/VideoBackends/D3D12/Renderer.h +++ b/Source/Core/VideoBackends/D3D12/Renderer.h @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #pragma once + #include #include "VideoBackends/D3D12/DescriptorHeapManager.h" #include "VideoCommon/RenderBase.h" @@ -35,8 +36,8 @@ public: std::unique_ptr CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override; - std::unique_ptr CreateShaderFromSource(ShaderStage stage, const char* source, - size_t length) override; + std::unique_ptr CreateShaderFromSource(ShaderStage stage, + std::string_view source) override; std::unique_ptr CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) override; std::unique_ptr diff --git a/Source/Core/VideoBackends/D3DCommon/Shader.cpp b/Source/Core/VideoBackends/D3DCommon/Shader.cpp index 12091806e1..268f75370c 100644 --- a/Source/Core/VideoBackends/D3DCommon/Shader.cpp +++ b/Source/Core/VideoBackends/D3DCommon/Shader.cpp @@ -90,7 +90,7 @@ static const char* GetCompileTarget(D3D_FEATURE_LEVEL feature_level, ShaderStage } bool Shader::CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_bytecode, - ShaderStage stage, const char* source, size_t length) + ShaderStage stage, std::string_view source) { static constexpr D3D_SHADER_MACRO macros[] = {{"API_D3D", "1"}, {nullptr, nullptr}}; const UINT flags = g_ActiveConfig.bEnableValidationLayer ? @@ -100,8 +100,8 @@ bool Shader::CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_byte Microsoft::WRL::ComPtr code; Microsoft::WRL::ComPtr errors; - HRESULT hr = d3d_compile(source, length, nullptr, macros, nullptr, "main", target, flags, 0, - &code, &errors); + HRESULT hr = d3d_compile(source.data(), source.size(), nullptr, macros, nullptr, "main", target, + flags, 0, &code, &errors); if (FAILED(hr)) { static int num_failures = 0; @@ -109,7 +109,7 @@ bool Shader::CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_byte "%sbad_%s_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), target, num_failures++); std::ofstream file; File::OpenFStream(file, filename, std::ios_base::out); - file.write(source, length); + file.write(source.data(), source.size()); file << "\n"; file.write(static_cast(errors->GetBufferPointer()), errors->GetBufferSize()); file.close(); diff --git a/Source/Core/VideoBackends/D3DCommon/Shader.h b/Source/Core/VideoBackends/D3DCommon/Shader.h index c3dd94b279..2f179c9b0d 100644 --- a/Source/Core/VideoBackends/D3DCommon/Shader.h +++ b/Source/Core/VideoBackends/D3DCommon/Shader.h @@ -3,7 +3,8 @@ // Refer to the license.txt file included. #pragma once -#include + +#include #include "VideoBackends/D3DCommon/Common.h" #include "VideoCommon/AbstractShader.h" @@ -19,7 +20,7 @@ public: BinaryData GetBinary() const override; static bool CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_bytecode, - ShaderStage stage, const char* source, size_t length); + ShaderStage stage, std::string_view source); static BinaryData CreateByteCode(const void* data, size_t length); diff --git a/Source/Core/VideoBackends/Null/Render.cpp b/Source/Core/VideoBackends/Null/Render.cpp index b4730e4ac4..312844afe0 100644 --- a/Source/Core/VideoBackends/Null/Render.cpp +++ b/Source/Core/VideoBackends/Null/Render.cpp @@ -48,8 +48,8 @@ public: ~NullShader() = default; }; -std::unique_ptr Renderer::CreateShaderFromSource(ShaderStage stage, - const char* source, size_t length) +std::unique_ptr +Renderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source) { return std::make_unique(stage); } diff --git a/Source/Core/VideoBackends/Null/Render.h b/Source/Core/VideoBackends/Null/Render.h index 4070db20fe..03f08e850d 100644 --- a/Source/Core/VideoBackends/Null/Render.h +++ b/Source/Core/VideoBackends/Null/Render.h @@ -22,8 +22,8 @@ public: std::unique_ptr CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override; - std::unique_ptr CreateShaderFromSource(ShaderStage stage, const char* source, - size_t length) override; + std::unique_ptr CreateShaderFromSource(ShaderStage stage, + std::string_view source) override; std::unique_ptr CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) override; std::unique_ptr diff --git a/Source/Core/VideoBackends/OGL/OGLShader.cpp b/Source/Core/VideoBackends/OGL/OGLShader.cpp index ee96f1c352..b538612409 100644 --- a/Source/Core/VideoBackends/OGL/OGLShader.cpp +++ b/Source/Core/VideoBackends/OGL/OGLShader.cpp @@ -45,10 +45,9 @@ OGLShader::~OGLShader() glDeleteProgram(m_gl_compute_program_id); } -std::unique_ptr OGLShader::CreateFromSource(ShaderStage stage, const char* source, - size_t length) +std::unique_ptr OGLShader::CreateFromSource(ShaderStage stage, std::string_view source) { - std::string source_str(source, length); + std::string source_str(source); if (stage != ShaderStage::Compute) { GLenum shader_type = GetGLShaderTypeForStage(stage); diff --git a/Source/Core/VideoBackends/OGL/OGLShader.h b/Source/Core/VideoBackends/OGL/OGLShader.h index 5289e1933f..b71f972c6b 100644 --- a/Source/Core/VideoBackends/OGL/OGLShader.h +++ b/Source/Core/VideoBackends/OGL/OGLShader.h @@ -6,6 +6,7 @@ #include #include +#include #include "Common/CommonTypes.h" #include "Common/GL/GLUtil.h" @@ -26,8 +27,7 @@ public: GLuint GetGLComputeProgramID() const { return m_gl_compute_program_id; } const std::string& GetSource() const { return m_source; } - static std::unique_ptr CreateFromSource(ShaderStage stage, const char* source, - size_t length); + static std::unique_ptr CreateFromSource(ShaderStage stage, std::string_view source); private: u64 m_id; diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 546556c440..452d27f39a 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -832,9 +832,9 @@ std::unique_ptr Renderer::CreateFramebuffer(AbstractTexture } std::unique_ptr Renderer::CreateShaderFromSource(ShaderStage stage, - const char* source, size_t length) + std::string_view source) { - return OGLShader::CreateFromSource(stage, source, length); + return OGLShader::CreateFromSource(stage, source); } std::unique_ptr Renderer::CreateShaderFromBinary(ShaderStage stage, diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index 1cd2aa2e2d..11d4582d04 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -95,8 +95,8 @@ public: std::unique_ptr CreateTexture(const TextureConfig& config) override; std::unique_ptr CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override; - std::unique_ptr CreateShaderFromSource(ShaderStage stage, const char* source, - size_t length) override; + std::unique_ptr CreateShaderFromSource(ShaderStage stage, + std::string_view source) override; std::unique_ptr CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) override; std::unique_ptr diff --git a/Source/Core/VideoBackends/Software/SWRenderer.cpp b/Source/Core/VideoBackends/Software/SWRenderer.cpp index 2eff9a2f0d..c933f5f496 100644 --- a/Source/Core/VideoBackends/Software/SWRenderer.cpp +++ b/Source/Core/VideoBackends/Software/SWRenderer.cpp @@ -68,7 +68,7 @@ public: }; std::unique_ptr -SWRenderer::CreateShaderFromSource(ShaderStage stage, const char* source, size_t length) +SWRenderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source) { return std::make_unique(stage); } diff --git a/Source/Core/VideoBackends/Software/SWRenderer.h b/Source/Core/VideoBackends/Software/SWRenderer.h index 9e478b0f50..81d6e4178e 100644 --- a/Source/Core/VideoBackends/Software/SWRenderer.h +++ b/Source/Core/VideoBackends/Software/SWRenderer.h @@ -27,8 +27,8 @@ public: std::unique_ptr CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override; - std::unique_ptr CreateShaderFromSource(ShaderStage stage, const char* source, - size_t length) override; + std::unique_ptr CreateShaderFromSource(ShaderStage stage, + std::string_view source) override; std::unique_ptr CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) override; std::unique_ptr diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index ac3dbe4c2a..648b019971 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -95,9 +95,9 @@ std::unique_ptr Renderer::CreateStagingTexture(StagingTe } std::unique_ptr Renderer::CreateShaderFromSource(ShaderStage stage, - const char* source, size_t length) + std::string_view source) { - return VKShader::CreateFromSource(stage, source, length); + return VKShader::CreateFromSource(stage, source); } std::unique_ptr Renderer::CreateShaderFromBinary(ShaderStage stage, diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.h b/Source/Core/VideoBackends/Vulkan/Renderer.h index bcc416af88..245ad777ec 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.h +++ b/Source/Core/VideoBackends/Vulkan/Renderer.h @@ -42,8 +42,8 @@ public: std::unique_ptr CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override; - std::unique_ptr CreateShaderFromSource(ShaderStage stage, const char* source, - size_t length) override; + std::unique_ptr CreateShaderFromSource(ShaderStage stage, + std::string_view source) override; std::unique_ptr CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) override; std::unique_ptr diff --git a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp index a9c1fa2c19..e526ed2924 100644 --- a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp +++ b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp @@ -35,11 +35,6 @@ bool InitializeGlslang(); // Resource limits used when compiling shaders static const TBuiltInResource* GetCompilerResourceLimits(); -// Compile a shader to SPIR-V via glslang -static bool CompileShaderToSPV(SPIRVCodeVector* out_code, EShLanguage stage, - const char* stage_filename, const char* source_code, - size_t source_code_length, const char* header, size_t header_length); - // Regarding the UBO bind points, we subtract one from the binding index because // the OpenGL backend requires UBO #0 for non-block uniforms (at least on NV). // This allows us to share the same shaders but use bind point #0 in the Vulkan @@ -114,8 +109,7 @@ static const char SUBGROUP_HELPER_HEADER[] = R"( )"; bool CompileShaderToSPV(SPIRVCodeVector* out_code, EShLanguage stage, const char* stage_filename, - const char* source_code, size_t source_code_length, const char* header, - size_t header_length) + std::string_view source, std::string_view header) { if (!InitializeGlslang()) return false; @@ -129,16 +123,16 @@ bool CompileShaderToSPV(SPIRVCodeVector* out_code, EShLanguage stage, const char int default_version = 450; std::string full_source_code; - const char* pass_source_code = source_code; - int pass_source_code_length = static_cast(source_code_length); - if (header_length > 0) + const char* pass_source_code = source.data(); + int pass_source_code_length = static_cast(source.size()); + if (!header.empty()) { constexpr size_t subgroup_helper_header_length = ArraySize(SUBGROUP_HELPER_HEADER) - 1; - full_source_code.reserve(header_length + subgroup_helper_header_length + source_code_length); - full_source_code.append(header, header_length); + full_source_code.reserve(header.size() + subgroup_helper_header_length + source.size()); + full_source_code.append(header); if (g_vulkan_context->SupportsShaderSubgroupOperations()) full_source_code.append(SUBGROUP_HELPER_HEADER, subgroup_helper_header_length); - full_source_code.append(source_code, source_code_length); + full_source_code.append(source); pass_source_code = full_source_code.c_str(); pass_source_code_length = static_cast(full_source_code.length()); } @@ -362,32 +356,24 @@ const TBuiltInResource* GetCompilerResourceLimits() return &limits; } -bool CompileVertexShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length) +bool CompileVertexShader(SPIRVCodeVector* out_code, std::string_view source_code) { - return CompileShaderToSPV(out_code, EShLangVertex, "vs", source_code, source_code_length, - SHADER_HEADER, sizeof(SHADER_HEADER) - 1); + return CompileShaderToSPV(out_code, EShLangVertex, "vs", source_code, SHADER_HEADER); } -bool CompileGeometryShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length) +bool CompileGeometryShader(SPIRVCodeVector* out_code, std::string_view source_code) { - return CompileShaderToSPV(out_code, EShLangGeometry, "gs", source_code, source_code_length, - SHADER_HEADER, sizeof(SHADER_HEADER) - 1); + return CompileShaderToSPV(out_code, EShLangGeometry, "gs", source_code, SHADER_HEADER); } -bool CompileFragmentShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length) +bool CompileFragmentShader(SPIRVCodeVector* out_code, std::string_view source_code) { - return CompileShaderToSPV(out_code, EShLangFragment, "ps", source_code, source_code_length, - SHADER_HEADER, sizeof(SHADER_HEADER) - 1); + return CompileShaderToSPV(out_code, EShLangFragment, "ps", source_code, SHADER_HEADER); } -bool CompileComputeShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length) +bool CompileComputeShader(SPIRVCodeVector* out_code, std::string_view source_code) { - return CompileShaderToSPV(out_code, EShLangCompute, "cs", source_code, source_code_length, - COMPUTE_SHADER_HEADER, sizeof(COMPUTE_SHADER_HEADER) - 1); + return CompileShaderToSPV(out_code, EShLangCompute, "cs", source_code, COMPUTE_SHADER_HEADER); } } // namespace ShaderCompiler diff --git a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.h b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.h index 84434b1ad6..2c6e20c394 100644 --- a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.h +++ b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "Common/CommonTypes.h" @@ -18,20 +19,16 @@ using SPIRVCodeType = u32; using SPIRVCodeVector = std::vector; // Compile a vertex shader to SPIR-V. -bool CompileVertexShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length); +bool CompileVertexShader(SPIRVCodeVector* out_code, std::string_view source_code); // Compile a geometry shader to SPIR-V. -bool CompileGeometryShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length); +bool CompileGeometryShader(SPIRVCodeVector* out_code, std::string_view source_code); // Compile a fragment shader to SPIR-V. -bool CompileFragmentShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length); +bool CompileFragmentShader(SPIRVCodeVector* out_code, std::string_view source_code); // Compile a compute shader to SPIR-V. -bool CompileComputeShader(SPIRVCodeVector* out_code, const char* source_code, - size_t source_code_length); +bool CompileComputeShader(SPIRVCodeVector* out_code, std::string_view source_code); } // namespace ShaderCompiler } // namespace Vulkan diff --git a/Source/Core/VideoBackends/Vulkan/VKShader.cpp b/Source/Core/VideoBackends/Vulkan/VKShader.cpp index 4308660ae6..15fc90f61f 100644 --- a/Source/Core/VideoBackends/Vulkan/VKShader.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKShader.cpp @@ -86,24 +86,23 @@ static std::unique_ptr CreateShaderObject(ShaderStage stage, return std::make_unique(std::move(spv), pipeline); } -std::unique_ptr VKShader::CreateFromSource(ShaderStage stage, const char* source, - size_t length) +std::unique_ptr VKShader::CreateFromSource(ShaderStage stage, std::string_view source) { ShaderCompiler::SPIRVCodeVector spv; bool result; switch (stage) { case ShaderStage::Vertex: - result = ShaderCompiler::CompileVertexShader(&spv, source, length); + result = ShaderCompiler::CompileVertexShader(&spv, source); break; case ShaderStage::Geometry: - result = ShaderCompiler::CompileGeometryShader(&spv, source, length); + result = ShaderCompiler::CompileGeometryShader(&spv, source); break; case ShaderStage::Pixel: - result = ShaderCompiler::CompileFragmentShader(&spv, source, length); + result = ShaderCompiler::CompileFragmentShader(&spv, source); break; case ShaderStage::Compute: - result = ShaderCompiler::CompileComputeShader(&spv, source, length); + result = ShaderCompiler::CompileComputeShader(&spv, source); break; default: result = false; diff --git a/Source/Core/VideoBackends/Vulkan/VKShader.h b/Source/Core/VideoBackends/Vulkan/VKShader.h index 21194127a7..7e4efefc6f 100644 --- a/Source/Core/VideoBackends/Vulkan/VKShader.h +++ b/Source/Core/VideoBackends/Vulkan/VKShader.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "Common/CommonTypes.h" @@ -25,8 +26,7 @@ public: VkPipeline GetComputePipeline() const { return m_compute_pipeline; } BinaryData GetBinary() const override; - static std::unique_ptr CreateFromSource(ShaderStage stage, const char* source, - size_t length); + static std::unique_ptr CreateFromSource(ShaderStage stage, std::string_view source); static std::unique_ptr CreateFromBinary(ShaderStage stage, const void* data, size_t length); diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 222b1ba9ab..8c3f89de57 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -148,12 +148,6 @@ void Renderer::SetAndClearFramebuffer(AbstractFramebuffer* framebuffer, m_current_framebuffer = framebuffer; } -std::unique_ptr Renderer::CreateShaderFromSource(ShaderStage stage, - const std::string& source) -{ - return CreateShaderFromSource(stage, source.c_str(), source.size()); -} - bool Renderer::EFBHasAlphaChannel() const { return m_prev_efb_format == PEControl::RGBA6_Z24; @@ -980,10 +974,10 @@ bool Renderer::InitializeImGui() const std::string vertex_shader_source = GenerateImGuiVertexShader(); const std::string pixel_shader_source = GenerateImGuiPixelShader(); - std::unique_ptr vertex_shader = CreateShaderFromSource( - ShaderStage::Vertex, vertex_shader_source.c_str(), vertex_shader_source.size()); - std::unique_ptr pixel_shader = CreateShaderFromSource( - ShaderStage::Pixel, pixel_shader_source.c_str(), pixel_shader_source.size()); + std::unique_ptr vertex_shader = + CreateShaderFromSource(ShaderStage::Vertex, vertex_shader_source); + std::unique_ptr pixel_shader = + CreateShaderFromSource(ShaderStage::Pixel, pixel_shader_source); if (!vertex_shader || !pixel_shader) { PanicAlert("Failed to compile imgui shaders"); diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index c10d8d155b..b9eab7f331 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -123,8 +124,8 @@ public: virtual void PresentBackbuffer() {} // Shader modules/objects. - virtual std::unique_ptr - CreateShaderFromSource(ShaderStage stage, const char* source, size_t length) = 0; + virtual std::unique_ptr CreateShaderFromSource(ShaderStage stage, + std::string_view source) = 0; virtual std::unique_ptr CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) = 0; virtual std::unique_ptr @@ -132,8 +133,6 @@ public: virtual std::unique_ptr CreatePipeline(const AbstractPipelineConfig& config, const void* cache_data = nullptr, size_t cache_data_length = 0) = 0; - std::unique_ptr CreateShaderFromSource(ShaderStage stage, - const std::string& source); AbstractFramebuffer* GetCurrentFramebuffer() const { return m_current_framebuffer; } diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index 6ac4827165..6da702d057 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -392,32 +392,32 @@ void ShaderCache::CompileMissingPipelines() std::unique_ptr ShaderCache::CompileVertexShader(const VertexShaderUid& uid) const { - ShaderCode source_code = GenerateVertexShaderCode(m_api_type, m_host_config, uid.GetUidData()); - return g_renderer->CreateShaderFromSource(ShaderStage::Vertex, source_code.GetBuffer().c_str(), - source_code.GetBuffer().size()); + const ShaderCode source_code = + GenerateVertexShaderCode(m_api_type, m_host_config, uid.GetUidData()); + return g_renderer->CreateShaderFromSource(ShaderStage::Vertex, source_code.GetBuffer()); } std::unique_ptr ShaderCache::CompileVertexUberShader(const UberShader::VertexShaderUid& uid) const { - ShaderCode source_code = UberShader::GenVertexShader(m_api_type, m_host_config, uid.GetUidData()); - return g_renderer->CreateShaderFromSource(ShaderStage::Vertex, source_code.GetBuffer().c_str(), - source_code.GetBuffer().size()); + const ShaderCode source_code = + UberShader::GenVertexShader(m_api_type, m_host_config, uid.GetUidData()); + return g_renderer->CreateShaderFromSource(ShaderStage::Vertex, source_code.GetBuffer()); } std::unique_ptr ShaderCache::CompilePixelShader(const PixelShaderUid& uid) const { - ShaderCode source_code = GeneratePixelShaderCode(m_api_type, m_host_config, uid.GetUidData()); - return g_renderer->CreateShaderFromSource(ShaderStage::Pixel, source_code.GetBuffer().c_str(), - source_code.GetBuffer().size()); + const ShaderCode source_code = + GeneratePixelShaderCode(m_api_type, m_host_config, uid.GetUidData()); + return g_renderer->CreateShaderFromSource(ShaderStage::Pixel, source_code.GetBuffer()); } std::unique_ptr ShaderCache::CompilePixelUberShader(const UberShader::PixelShaderUid& uid) const { - ShaderCode source_code = UberShader::GenPixelShader(m_api_type, m_host_config, uid.GetUidData()); - return g_renderer->CreateShaderFromSource(ShaderStage::Pixel, source_code.GetBuffer().c_str(), - source_code.GetBuffer().size()); + const ShaderCode source_code = + UberShader::GenPixelShader(m_api_type, m_host_config, uid.GetUidData()); + return g_renderer->CreateShaderFromSource(ShaderStage::Pixel, source_code.GetBuffer()); } const AbstractShader* ShaderCache::InsertVertexShader(const VertexShaderUid& uid, @@ -510,9 +510,10 @@ const AbstractShader* ShaderCache::InsertPixelUberShader(const UberShader::Pixel const AbstractShader* ShaderCache::CreateGeometryShader(const GeometryShaderUid& uid) { - ShaderCode source_code = GenerateGeometryShaderCode(m_api_type, m_host_config, uid.GetUidData()); - std::unique_ptr shader = g_renderer->CreateShaderFromSource( - ShaderStage::Geometry, source_code.GetBuffer().c_str(), source_code.GetBuffer().size()); + const ShaderCode source_code = + GenerateGeometryShaderCode(m_api_type, m_host_config, uid.GetUidData()); + std::unique_ptr shader = + g_renderer->CreateShaderFromSource(ShaderStage::Geometry, source_code.GetBuffer()); auto& entry = m_gs_cache.shader_map[uid]; entry.pending = false; @@ -1150,9 +1151,9 @@ const AbstractPipeline* ShaderCache::GetEFBCopyToRAMPipeline(const EFBCopyParams if (iter != m_efb_copy_to_ram_pipelines.end()) return iter->second.get(); - auto shader_code = TextureConversionShaderTiled::GenerateEncodingShader(uid, m_api_type); - auto shader = - g_renderer->CreateShaderFromSource(ShaderStage::Pixel, shader_code, std::strlen(shader_code)); + const char* const shader_code = + TextureConversionShaderTiled::GenerateEncodingShader(uid, m_api_type); + const auto shader = g_renderer->CreateShaderFromSource(ShaderStage::Pixel, shader_code); if (!shader) { m_efb_copy_to_ram_pipelines.emplace(uid, nullptr);