From e60268bd4274de510f5214d6eedafba30a253984 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 May 2019 03:07:40 -0400 Subject: VideoCommon/RenderBase: Use a std::string_view with CreateShaderFromSource() Greatly simplifies the overall interface when it comes to compiling shaders. Also allows getting rid of a std::string overload of the same name. Now std::string and const char* both go through the same function. --- Source/Core/VideoCommon/ShaderCache.cpp | 37 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'Source/Core/VideoCommon/ShaderCache.cpp') 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); -- cgit v1.2.3