diff options
| author | 2018-04-07 23:45:09 -0400 | |
|---|---|---|
| committer | 2018-04-13 23:48:28 -0400 | |
| commit | 51f37f5061eec2d9a0a872aebd6b50e21bee19a6 (patch) | |
| tree | 9419d0758e5df2e94af38e95443dd1563a7ee969 /src/video_core | |
| parent | maxwell_3d: Make memory_manager public. (diff) | |
| download | yuzu-51f37f5061eec2d9a0a872aebd6b50e21bee19a6.tar.gz yuzu-51f37f5061eec2d9a0a872aebd6b50e21bee19a6.tar.xz yuzu-51f37f5061eec2d9a0a872aebd6b50e21bee19a6.zip | |
gl_shader_manager: Cleanup and consolidate uniform handling.
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_manager.cpp | 19 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_manager.h | 31 |
2 files changed, 24 insertions, 26 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index 0da78bc65..a5835f2b1 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp | |||
| @@ -10,8 +10,8 @@ | |||
| 10 | namespace GLShader { | 10 | namespace GLShader { |
| 11 | 11 | ||
| 12 | namespace Impl { | 12 | namespace Impl { |
| 13 | void SetShaderUniformBlockBinding(GLuint shader, const char* name, UniformBindings binding, | 13 | void SetShaderUniformBlockBinding(GLuint shader, const char* name, |
| 14 | size_t expected_size) { | 14 | Maxwell3D::Regs::ShaderStage binding, size_t expected_size) { |
| 15 | GLuint ub_index = glGetUniformBlockIndex(shader, name); | 15 | GLuint ub_index = glGetUniformBlockIndex(shader, name); |
| 16 | if (ub_index != GL_INVALID_INDEX) { | 16 | if (ub_index != GL_INVALID_INDEX) { |
| 17 | GLint ub_size = 0; | 17 | GLint ub_size = 0; |
| @@ -24,7 +24,12 @@ void SetShaderUniformBlockBinding(GLuint shader, const char* name, UniformBindin | |||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | void SetShaderUniformBlockBindings(GLuint shader) { | 26 | void SetShaderUniformBlockBindings(GLuint shader) { |
| 27 | SetShaderUniformBlockBinding(shader, "vs_config", UniformBindings::VS, sizeof(VSUniformData)); | 27 | SetShaderUniformBlockBinding(shader, "vs_config", Maxwell3D::Regs::ShaderStage::Vertex, |
| 28 | sizeof(MaxwellUniformData)); | ||
| 29 | SetShaderUniformBlockBinding(shader, "gs_config", Maxwell3D::Regs::ShaderStage::Geometry, | ||
| 30 | sizeof(MaxwellUniformData)); | ||
| 31 | SetShaderUniformBlockBinding(shader, "fs_config", Maxwell3D::Regs::ShaderStage::Fragment, | ||
| 32 | sizeof(MaxwellUniformData)); | ||
| 28 | } | 33 | } |
| 29 | 34 | ||
| 30 | void SetShaderSamplerBindings(GLuint shader) { | 35 | void SetShaderSamplerBindings(GLuint shader) { |
| @@ -40,7 +45,13 @@ void SetShaderSamplerBindings(GLuint shader) { | |||
| 40 | 45 | ||
| 41 | } // namespace Impl | 46 | } // namespace Impl |
| 42 | 47 | ||
| 43 | void MaxwellUniformData::SetFromRegs() { | 48 | void MaxwellUniformData::SetFromRegs(const Maxwell3D::State::ShaderStageInfo& shader_stage) { |
| 49 | const auto& memory_manager = Core::System().GetInstance().GPU().memory_manager; | ||
| 50 | for (unsigned index = 0; index < shader_stage.const_buffers.size(); ++index) { | ||
| 51 | const auto& const_buffer = shader_stage.const_buffers[index]; | ||
| 52 | const VAddr vaddr = memory_manager->PhysicalToVirtualAddress(const_buffer.address); | ||
| 53 | Memory::ReadBlock(vaddr, const_buffers[index].data(), sizeof(ConstBuffer)); | ||
| 54 | } | ||
| 44 | } | 55 | } |
| 45 | 56 | ||
| 46 | } // namespace GLShader | 57 | } // namespace GLShader |
diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index 10e8b8b3a..b5a7b2a18 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h | |||
| @@ -14,40 +14,27 @@ | |||
| 14 | 14 | ||
| 15 | namespace GLShader { | 15 | namespace GLShader { |
| 16 | 16 | ||
| 17 | using Tegra::Engines::Maxwell3D; | ||
| 18 | |||
| 17 | namespace Impl { | 19 | namespace Impl { |
| 18 | void SetShaderUniformBlockBindings(GLuint shader); | 20 | void SetShaderUniformBlockBindings(GLuint shader); |
| 19 | void SetShaderSamplerBindings(GLuint shader); | 21 | void SetShaderSamplerBindings(GLuint shader); |
| 20 | } // namespace Impl | 22 | } // namespace Impl |
| 21 | 23 | ||
| 22 | enum class UniformBindings : GLuint { Common, VS, GS, FS }; | ||
| 23 | |||
| 24 | /// Uniform structure for the Uniform Buffer Object, all vectors must be 16-byte aligned | 24 | /// Uniform structure for the Uniform Buffer Object, all vectors must be 16-byte aligned |
| 25 | // NOTE: Always keep a vec4 at the end. The GL spec is not clear wether the alignment at | 25 | // NOTE: Always keep a vec4 at the end. The GL spec is not clear wether the alignment at |
| 26 | // the end of a uniform block is included in UNIFORM_BLOCK_DATA_SIZE or not. | 26 | // the end of a uniform block is included in UNIFORM_BLOCK_DATA_SIZE or not. |
| 27 | // Not following that rule will cause problems on some AMD drivers. | 27 | // Not following that rule will cause problems on some AMD drivers. |
| 28 | struct MaxwellUniformData { | 28 | struct MaxwellUniformData { |
| 29 | void SetFromRegs(); | 29 | void SetFromRegs(const Maxwell3D::State::ShaderStageInfo& shader_stage); |
| 30 | 30 | ||
| 31 | using ConstBuffer = std::array<GLvec4, 4>; | 31 | using ConstBuffer = std::array<GLvec4, 4>; |
| 32 | using Regs = Tegra::Engines::Maxwell3D::Regs; | 32 | alignas(16) std::array<ConstBuffer, Maxwell3D::Regs::MaxConstBuffers> const_buffers; |
| 33 | |||
| 34 | alignas(16) std::array<ConstBuffer, Regs::MaxConstBuffers> const_buffers; | ||
| 35 | }; | 33 | }; |
| 34 | static_assert(sizeof(MaxwellUniformData) == 1024, "MaxwellUniformData structure size is incorrect"); | ||
| 36 | static_assert(sizeof(MaxwellUniformData) < 16384, | 35 | static_assert(sizeof(MaxwellUniformData) < 16384, |
| 37 | "MaxwellUniformData structure must be less than 16kb as per the OpenGL spec"); | 36 | "MaxwellUniformData structure must be less than 16kb as per the OpenGL spec"); |
| 38 | 37 | ||
| 39 | struct VSUniformData { | ||
| 40 | MaxwellUniformData uniforms; | ||
| 41 | }; | ||
| 42 | static_assert(sizeof(VSUniformData) < 16384, | ||
| 43 | "VSUniformData structure must be less than 16kb as per the OpenGL spec"); | ||
| 44 | |||
| 45 | struct FSUniformData { | ||
| 46 | MaxwellUniformData uniforms; | ||
| 47 | }; | ||
| 48 | static_assert(sizeof(FSUniformData) < 16384, | ||
| 49 | "VSUniformData structure must be less than 16kb as per the OpenGL spec"); | ||
| 50 | |||
| 51 | class OGLShaderStage { | 38 | class OGLShaderStage { |
| 52 | public: | 39 | public: |
| 53 | OGLShaderStage() = default; | 40 | OGLShaderStage() = default; |
| @@ -113,14 +100,14 @@ public: | |||
| 113 | current.vs = vertex_shaders.Get(config, setup); | 100 | current.vs = vertex_shaders.Get(config, setup); |
| 114 | } | 101 | } |
| 115 | 102 | ||
| 116 | void UseTrivialGeometryShader() { | ||
| 117 | current.gs = 0; | ||
| 118 | } | ||
| 119 | |||
| 120 | void UseProgrammableFragmentShader(const MaxwellFSConfig& config, const ShaderSetup setup) { | 103 | void UseProgrammableFragmentShader(const MaxwellFSConfig& config, const ShaderSetup setup) { |
| 121 | current.fs = fragment_shaders.Get(config, setup); | 104 | current.fs = fragment_shaders.Get(config, setup); |
| 122 | } | 105 | } |
| 123 | 106 | ||
| 107 | void UseTrivialGeometryShader() { | ||
| 108 | current.gs = 0; | ||
| 109 | } | ||
| 110 | |||
| 124 | void ApplyTo(OpenGLState& state) { | 111 | void ApplyTo(OpenGLState& state) { |
| 125 | // Workaround for AMD bug | 112 | // Workaround for AMD bug |
| 126 | glUseProgramStages(pipeline.handle, | 113 | glUseProgramStages(pipeline.handle, |