mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 06:39:46 -06:00
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.
This commit is contained in:
@ -148,12 +148,6 @@ void Renderer::SetAndClearFramebuffer(AbstractFramebuffer* framebuffer,
|
||||
m_current_framebuffer = framebuffer;
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> 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<AbstractShader> vertex_shader = CreateShaderFromSource(
|
||||
ShaderStage::Vertex, vertex_shader_source.c_str(), vertex_shader_source.size());
|
||||
std::unique_ptr<AbstractShader> pixel_shader = CreateShaderFromSource(
|
||||
ShaderStage::Pixel, pixel_shader_source.c_str(), pixel_shader_source.size());
|
||||
std::unique_ptr<AbstractShader> vertex_shader =
|
||||
CreateShaderFromSource(ShaderStage::Vertex, vertex_shader_source);
|
||||
std::unique_ptr<AbstractShader> pixel_shader =
|
||||
CreateShaderFromSource(ShaderStage::Pixel, pixel_shader_source);
|
||||
if (!vertex_shader || !pixel_shader)
|
||||
{
|
||||
PanicAlert("Failed to compile imgui shaders");
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
@ -123,8 +124,8 @@ public:
|
||||
virtual void PresentBackbuffer() {}
|
||||
|
||||
// Shader modules/objects.
|
||||
virtual std::unique_ptr<AbstractShader>
|
||||
CreateShaderFromSource(ShaderStage stage, const char* source, size_t length) = 0;
|
||||
virtual std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage,
|
||||
std::string_view source) = 0;
|
||||
virtual std::unique_ptr<AbstractShader>
|
||||
CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) = 0;
|
||||
virtual std::unique_ptr<NativeVertexFormat>
|
||||
@ -132,8 +133,6 @@ public:
|
||||
virtual std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) = 0;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage,
|
||||
const std::string& source);
|
||||
|
||||
AbstractFramebuffer* GetCurrentFramebuffer() const { return m_current_framebuffer; }
|
||||
|
||||
|
@ -392,32 +392,32 @@ void ShaderCache::CompileMissingPipelines()
|
||||
|
||||
std::unique_ptr<AbstractShader> 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<AbstractShader>
|
||||
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<AbstractShader> 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<AbstractShader>
|
||||
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<AbstractShader> 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<AbstractShader> 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);
|
||||
|
Reference in New Issue
Block a user