Skip to content
Permalink
Browse files

Merge pull request #8000 from stenzek/more-videocommon-cleanup

Additional cleanup/fixes from VideoCommon merge
  • Loading branch information...
stenzek committed Apr 22, 2019
2 parents 93be178 + 356ebdf commit 59c0e51f5b84874dca2cbecfe750e3f1de66405d
Showing with 163 additions and 218 deletions.
  1. +1 −1 Source/Core/VideoBackends/D3D/Render.cpp
  2. +2 −1 Source/Core/VideoBackends/D3D/Render.h
  3. +1 −1 Source/Core/VideoBackends/D3D12/Renderer.cpp
  4. +2 −2 Source/Core/VideoBackends/D3D12/Renderer.h
  5. +2 −2 Source/Core/VideoBackends/Null/Render.h
  6. +8 −6 Source/Core/VideoBackends/Null/TextureCache.h
  7. +1 −0 Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp
  8. +10 −9 Source/Core/VideoBackends/OGL/OGLShader.cpp
  9. +4 −2 Source/Core/VideoBackends/OGL/OGLShader.h
  10. +32 −74 Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
  11. +3 −4 Source/Core/VideoBackends/OGL/ProgramShaderCache.h
  12. +7 −7 Source/Core/VideoBackends/OGL/Render.cpp
  13. +4 −3 Source/Core/VideoBackends/OGL/Render.h
  14. +5 −4 Source/Core/VideoBackends/Software/EfbInterface.cpp
  15. +2 −2 Source/Core/VideoBackends/Software/EfbInterface.h
  16. +2 −1 Source/Core/VideoBackends/Software/SWOGLWindow.cpp
  17. +1 −1 Source/Core/VideoBackends/Software/SWOGLWindow.h
  18. +3 −2 Source/Core/VideoBackends/Software/SWRenderer.cpp
  19. +4 −3 Source/Core/VideoBackends/Software/SWRenderer.h
  20. +8 −6 Source/Core/VideoBackends/Software/TextureCache.h
  21. +4 −3 Source/Core/VideoBackends/Software/TextureEncoder.cpp
  22. +3 −2 Source/Core/VideoBackends/Software/TextureEncoder.h
  23. +2 −2 Source/Core/VideoBackends/Vulkan/Renderer.cpp
  24. +2 −2 Source/Core/VideoBackends/Vulkan/Renderer.h
  25. +3 −3 Source/Core/VideoCommon/BPFunctions.cpp
  26. +1 −1 Source/Core/VideoCommon/BPFunctions.h
  27. +1 −1 Source/Core/VideoCommon/BPStructs.cpp
  28. +13 −13 Source/Core/VideoCommon/RenderBase.cpp
  29. +11 −10 Source/Core/VideoCommon/RenderBase.h
  30. +3 −1 Source/Core/VideoCommon/ShaderCache.cpp
  31. +10 −9 Source/Core/VideoCommon/TextureCacheBase.cpp
  32. +8 −7 Source/Core/VideoCommon/TextureCacheBase.h
  33. +0 −33 Source/Core/VideoCommon/VideoCommon.h
@@ -327,7 +327,7 @@ void Renderer::WaitForGPUIdle()
D3D::context->Flush();
}

void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const EFBRectangle& rc)
void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const MathUtil::Rectangle<int>& rc)
{
if (g_ActiveConfig.stereo_mode != StereoMode::Nvidia3DVision)
return ::Renderer::RenderXFBToScreen(texture, rc);
@@ -67,7 +67,8 @@ class Renderer : public ::Renderer
void Flush() override;
void WaitForGPUIdle() override;

void RenderXFBToScreen(const AbstractTexture* texture, const EFBRectangle& rc) override;
void RenderXFBToScreen(const AbstractTexture* texture,
const MathUtil::Rectangle<int>& rc) override;
void OnConfigChanged(u32 bits) override;

private:
@@ -132,7 +132,7 @@ void Renderer::WaitForGPUIdle()
ExecuteCommandList(true);
}

void Renderer::ClearScreen(const EFBRectangle& rc, bool color_enable, bool alpha_enable,
void Renderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool color_enable, bool alpha_enable,
bool z_enable, u32 color, u32 z)
{
// Use a fast path without the shader if both color/alpha are enabled.
@@ -52,8 +52,8 @@ class Renderer final : public ::Renderer
void Flush() override;
void WaitForGPUIdle() override;

void ClearScreen(const EFBRectangle& rc, bool color_enable, bool alpha_enable, bool z_enable,
u32 color, u32 z) override;
void ClearScreen(const MathUtil::Rectangle<int>& rc, bool color_enable, bool alpha_enable,
bool z_enable, u32 color, u32 z) override;

void SetPipeline(const AbstractPipeline* pipeline) override;
void SetFramebuffer(AbstractFramebuffer* framebuffer) override;
@@ -37,8 +37,8 @@ class Renderer : public ::Renderer
u16 BBoxRead(int index) override { return 0; }
void BBoxWrite(int index, u16 value) override {}

void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
u32 color, u32 z) override
void ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
bool zEnable, u32 color, u32 z) override
{
}

@@ -21,15 +21,17 @@ class TextureCache : public TextureCacheBase

protected:
void CopyEFB(AbstractStagingTexture* dst, const EFBCopyParams& params, u32 native_width,
u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, const EFBRectangle& src_rect,
bool scale_by_half, bool linear_filter, float y_scale, float gamma, bool clamp_top,
bool clamp_bottom, const EFBCopyFilterCoefficients& filter_coefficients) override
u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
const MathUtil::Rectangle<int>& src_rect, bool scale_by_half, bool linear_filter,
float y_scale, float gamma, bool clamp_top, bool clamp_bottom,
const EFBCopyFilterCoefficients& filter_coefficients) override
{
}

void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, const EFBRectangle& src_rect,
bool scale_by_half, bool linear_filter, EFBCopyFormat dst_format,
bool is_intensity, float gamma, bool clamp_top, bool clamp_bottom,
void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy,
const MathUtil::Rectangle<int>& src_rect, bool scale_by_half,
bool linear_filter, EFBCopyFormat dst_format, bool is_intensity,
float gamma, bool clamp_top, bool clamp_bottom,
const EFBCopyFilterCoefficients& filter_coefficients) override
{
}
@@ -80,6 +80,7 @@ GLVertexFormat::GLVertexFormat(const PortableVertexDeclaration& vtx_decl)

GLVertexFormat::~GLVertexFormat()
{
ProgramShaderCache::InvalidateVertexFormatIfBound(VAO);
glDeleteVertexArrays(1, &VAO);
}
} // namespace OGL
@@ -24,15 +24,16 @@ static GLenum GetGLShaderTypeForStage(ShaderStage stage)
}
}

OGLShader::OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id)
OGLShader::OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id, std::string source)
: AbstractShader(stage), m_id(ProgramShaderCache::GenerateShaderID()), m_type(gl_type),
m_gl_id(gl_id)
m_gl_id(gl_id), m_source(std::move(source))
{
}

OGLShader::OGLShader(GLuint gl_compute_program_id)
OGLShader::OGLShader(GLuint gl_compute_program_id, std::string source)
: AbstractShader(ShaderStage::Compute), m_id(ProgramShaderCache::GenerateShaderID()),
m_type(GL_COMPUTE_SHADER), m_gl_compute_program_id(gl_compute_program_id)
m_type(GL_COMPUTE_SHADER), m_gl_compute_program_id(gl_compute_program_id),
m_source(std::move(source))
{
}

@@ -47,22 +48,22 @@ OGLShader::~OGLShader()
std::unique_ptr<OGLShader> OGLShader::CreateFromSource(ShaderStage stage, const char* source,
size_t length)
{
std::string source_str(source, length);
if (stage != ShaderStage::Compute)
{
GLenum shader_type = GetGLShaderTypeForStage(stage);
GLuint shader_id =
ProgramShaderCache::CompileSingleShader(shader_type, std::string(source, length));
GLuint shader_id = ProgramShaderCache::CompileSingleShader(shader_type, source_str);
if (!shader_id)
return nullptr;

return std::make_unique<OGLShader>(stage, shader_type, shader_id);
return std::make_unique<OGLShader>(stage, shader_type, shader_id, std::move(source_str));
}

// Compute shaders.
SHADER prog;
if (!ProgramShaderCache::CompileComputeShader(prog, std::string(source, length)))
if (!ProgramShaderCache::CompileComputeShader(prog, source_str))
return nullptr;
return std::make_unique<OGLShader>(prog.glprogid);
return std::make_unique<OGLShader>(prog.glprogid, std::move(source_str));
}

} // namespace OGL
@@ -16,14 +16,15 @@ namespace OGL
class OGLShader final : public AbstractShader
{
public:
explicit OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id);
explicit OGLShader(GLuint gl_compute_program_id);
explicit OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id, std::string source);
explicit OGLShader(GLuint gl_compute_program_id, std::string source);
~OGLShader() override;

u64 GetID() const { return m_id; }
GLenum GetGLShaderType() const { return m_type; }
GLuint GetGLShaderID() const { return m_gl_id; }
GLuint GetGLComputeProgramID() const { return m_gl_compute_program_id; }
const std::string& GetSource() const { return m_source; }

static std::unique_ptr<OGLShader> CreateFromSource(ShaderStage stage, const char* source,
size_t length);
@@ -33,6 +34,7 @@ class OGLShader final : public AbstractShader
GLenum m_type;
GLuint m_gl_id = 0;
GLuint m_gl_compute_program_id = 0;
std::string m_source;
};

} // namespace OGL
@@ -267,73 +267,6 @@ void ProgramShaderCache::UploadConstants(const void* data, u32 data_size)
ADDSTAT(stats.thisFrame.bytesUniformStreamed, data_size);
}

bool ProgramShaderCache::CompileShader(SHADER& shader, const std::string& vcode,
const std::string& pcode, const std::string& gcode)
{
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
{
static int counter = 0;
std::string filename =
StringFromFormat("%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(filename, vcode.c_str());

filename = StringFromFormat("%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(filename, pcode.c_str());

if (!gcode.empty())
{
filename =
StringFromFormat("%sgs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(filename, gcode.c_str());
}
}
#endif

shader.vsid = CompileSingleShader(GL_VERTEX_SHADER, vcode);
shader.psid = CompileSingleShader(GL_FRAGMENT_SHADER, pcode);

// Optional geometry shader
shader.gsid = 0;
if (!gcode.empty())
shader.gsid = CompileSingleShader(GL_GEOMETRY_SHADER, gcode);

if (!shader.vsid || !shader.psid || (!gcode.empty() && !shader.gsid))
{
shader.Destroy();
return false;
}

// Create and link the program.
shader.glprogid = glCreateProgram();

glAttachShader(shader.glprogid, shader.vsid);
glAttachShader(shader.glprogid, shader.psid);
if (shader.gsid)
glAttachShader(shader.glprogid, shader.gsid);

if (g_ActiveConfig.backend_info.bSupportsPipelineCacheData)
glProgramParameteri(shader.glprogid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);

shader.SetProgramBindings(false);

glLinkProgram(shader.glprogid);

if (!CheckProgramLinkResult(shader.glprogid, vcode, pcode, gcode))
{
// Don't try to use this shader
shader.Destroy();
return false;
}

// For drivers that don't support binding layout, we need to bind it here.
shader.SetProgramVariables();

// Original shaders aren't needed any more.
shader.DestroyShaders();
return true;
}

bool ProgramShaderCache::CompileComputeShader(SHADER& shader, const std::string& code)
{
// We need to enable GL_ARB_compute_shader for drivers that support the extension,
@@ -358,7 +291,7 @@ bool ProgramShaderCache::CompileComputeShader(SHADER& shader, const std::string&
// original shaders aren't needed any more
glDeleteShader(shader_id);

if (!CheckProgramLinkResult(shader.glprogid, full_code, "", ""))
if (!CheckProgramLinkResult(shader.glprogid, &full_code, nullptr, nullptr))
{
shader.Destroy();
return false;
@@ -441,8 +374,8 @@ bool ProgramShaderCache::CheckShaderCompileResult(GLuint id, GLenum type, const
return true;
}

bool ProgramShaderCache::CheckProgramLinkResult(GLuint id, const std::string& vcode,
const std::string& pcode, const std::string& gcode)
bool ProgramShaderCache::CheckProgramLinkResult(GLuint id, const std::string* vcode,
const std::string* pcode, const std::string* gcode)
{
GLint linkStatus;
glGetProgramiv(id, GL_LINK_STATUS, &linkStatus);
@@ -460,9 +393,13 @@ bool ProgramShaderCache::CheckProgramLinkResult(GLuint id, const std::string& vc
StringFromFormat("%sbad_p_%d.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
std::ofstream file;
File::OpenFStream(file, filename, std::ios_base::out);
file << s_glsl_header << vcode << s_glsl_header << pcode;
if (!gcode.empty())
file << s_glsl_header << gcode;
if (vcode)
file << s_glsl_header << *vcode << '\n';
if (gcode)
file << s_glsl_header << *gcode << '\n';
if (pcode)
file << s_glsl_header << *pcode << '\n';

file << info_log;
file.close();

@@ -557,6 +494,12 @@ void ProgramShaderCache::InvalidateVertexFormat()
s_last_VAO = 0;
}

void ProgramShaderCache::InvalidateVertexFormatIfBound(GLuint vao)
{
if (s_last_VAO == vao)
s_last_VAO = 0;
}

void ProgramShaderCache::InvalidateLastProgram()
{
CurrentProgram = 0;
@@ -640,7 +583,10 @@ PipelineProgram* ProgramShaderCache::GetPipelineProgram(const GLVertexFormat* ve
if (!s_is_shared_context && vao != s_last_VAO)
glBindVertexArray(s_last_VAO);

if (!ProgramShaderCache::CheckProgramLinkResult(prog->shader.glprogid, {}, {}, {}))
if (!ProgramShaderCache::CheckProgramLinkResult(
prog->shader.glprogid, vertex_shader ? &vertex_shader->GetSource() : nullptr,
geometry_shader ? &geometry_shader->GetSource() : nullptr,
pixel_shader ? &pixel_shader->GetSource() : nullptr))
{
prog->shader.Destroy();
return nullptr;
@@ -906,6 +852,18 @@ bool SharedContextAsyncShaderCompiler::WorkerThreadInitWorkerThread(void* param)
return false;

s_is_shared_context = true;

// Make the state match the main context to have a better chance of avoiding recompiles.
if (!context->IsGLES())
glEnable(GL_PROGRAM_POINT_SIZE);
if (g_ActiveConfig.backend_info.bSupportsClipControl)
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
{
glEnable(GL_CLIP_DISTANCE0);
glEnable(GL_CLIP_DISTANCE1);
glEnable(GL_DEPTH_CLAMP);
}
if (g_ActiveConfig.backend_info.bSupportsPrimitiveRestart)
GLUtil::EnablePrimitiveRestart(context);

@@ -72,15 +72,14 @@ class ProgramShaderCache
static void BindVertexFormat(const GLVertexFormat* vertex_format);
static bool IsValidVertexFormatBound();
static void InvalidateVertexFormat();
static void InvalidateVertexFormatIfBound(GLuint vao);
static void InvalidateLastProgram();

static bool CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode,
const std::string& gcode = "");
static bool CompileComputeShader(SHADER& shader, const std::string& code);
static GLuint CompileSingleShader(GLenum type, const std::string& code);
static bool CheckShaderCompileResult(GLuint id, GLenum type, const std::string& code);
static bool CheckProgramLinkResult(GLuint id, const std::string& vcode, const std::string& pcode,
const std::string& gcode);
static bool CheckProgramLinkResult(GLuint id, const std::string* vcode, const std::string* pcode,
const std::string* gcode);
static StreamBuffer* GetUniformBuffer();
static u32 GetUniformBufferAlignment();
static void UploadConstants();
@@ -652,6 +652,10 @@ Renderer::Renderer(std::unique_ptr<GLContext> main_gl_context, float backbuffer_

// Desktop OpenGL can't have the Android Extension Pack
g_ogl_config.bSupportsAEP = false;

// Desktop GL requires GL_PROGRAM_POINT_SIZE set to use gl_PointSize in shaders.
// It is implicitly enabled in GLES.
glEnable(GL_PROGRAM_POINT_SIZE);
}

// Either method can do early-z tests. See PixelShaderGen for details.
@@ -932,8 +936,8 @@ void Renderer::DispatchComputeShader(const AbstractShader* shader, u32 groups_x,
glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
}

void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
u32 color, u32 z)
void Renderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
bool zEnable, u32 color, u32 z)
{
g_framebuffer_manager->FlushEFBPokes();
g_framebuffer_manager->FlagPeekCacheAsOutOfDate();
@@ -974,7 +978,7 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
BPFunctions::SetScissor();
}

void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const EFBRectangle& rc)
void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const MathUtil::Rectangle<int>& rc)
{
// Quad-buffered stereo is annoying on GL.
if (g_ActiveConfig.stereo_mode != StereoMode::QuadBuffer)
@@ -1108,8 +1112,6 @@ void Renderer::CheckForSurfaceResize()
void Renderer::BeginUtilityDrawing()
{
::Renderer::BeginUtilityDrawing();

glEnable(GL_PROGRAM_POINT_SIZE);
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
{
glDisable(GL_CLIP_DISTANCE0);
@@ -1120,8 +1122,6 @@ void Renderer::BeginUtilityDrawing()
void Renderer::EndUtilityDrawing()
{
::Renderer::EndUtilityDrawing();

glDisable(GL_PROGRAM_POINT_SIZE);
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
{
glEnable(GL_CLIP_DISTANCE0);
@@ -134,11 +134,12 @@ class Renderer : public ::Renderer

void Flush() override;
void WaitForGPUIdle() override;
void RenderXFBToScreen(const AbstractTexture* texture, const EFBRectangle& rc) override;
void RenderXFBToScreen(const AbstractTexture* texture,
const MathUtil::Rectangle<int>& rc) override;
void OnConfigChanged(u32 bits) override;

void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
u32 color, u32 z) override;
void ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
bool zEnable, u32 color, u32 z) override;

std::unique_ptr<VideoCommon::AsyncShaderCompiler> CreateAsyncShaderCompiler() override;

0 comments on commit 59c0e51

Please sign in to comment.
You can’t perform that action at this time.