summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2018-04-07 23:45:09 -0400
committerGravatar bunnei2018-04-13 23:48:28 -0400
commit51f37f5061eec2d9a0a872aebd6b50e21bee19a6 (patch)
tree9419d0758e5df2e94af38e95443dd1563a7ee969
parentmaxwell_3d: Make memory_manager public. (diff)
downloadyuzu-51f37f5061eec2d9a0a872aebd6b50e21bee19a6.tar.gz
yuzu-51f37f5061eec2d9a0a872aebd6b50e21bee19a6.tar.xz
yuzu-51f37f5061eec2d9a0a872aebd6b50e21bee19a6.zip
gl_shader_manager: Cleanup and consolidate uniform handling.
-rw-r--r--src/video_core/renderer_opengl/gl_shader_manager.cpp19
-rw-r--r--src/video_core/renderer_opengl/gl_shader_manager.h31
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 @@
10namespace GLShader { 10namespace GLShader {
11 11
12namespace Impl { 12namespace Impl {
13void SetShaderUniformBlockBinding(GLuint shader, const char* name, UniformBindings binding, 13void 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
26void SetShaderUniformBlockBindings(GLuint shader) { 26void 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
30void SetShaderSamplerBindings(GLuint shader) { 35void SetShaderSamplerBindings(GLuint shader) {
@@ -40,7 +45,13 @@ void SetShaderSamplerBindings(GLuint shader) {
40 45
41} // namespace Impl 46} // namespace Impl
42 47
43void MaxwellUniformData::SetFromRegs() { 48void 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
15namespace GLShader { 15namespace GLShader {
16 16
17using Tegra::Engines::Maxwell3D;
18
17namespace Impl { 19namespace Impl {
18void SetShaderUniformBlockBindings(GLuint shader); 20void SetShaderUniformBlockBindings(GLuint shader);
19void SetShaderSamplerBindings(GLuint shader); 21void SetShaderSamplerBindings(GLuint shader);
20} // namespace Impl 22} // namespace Impl
21 23
22enum 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.
28struct MaxwellUniformData { 28struct 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};
34static_assert(sizeof(MaxwellUniformData) == 1024, "MaxwellUniformData structure size is incorrect");
36static_assert(sizeof(MaxwellUniformData) < 16384, 35static_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
39struct VSUniformData {
40 MaxwellUniformData uniforms;
41};
42static_assert(sizeof(VSUniformData) < 16384,
43 "VSUniformData structure must be less than 16kb as per the OpenGL spec");
44
45struct FSUniformData {
46 MaxwellUniformData uniforms;
47};
48static_assert(sizeof(FSUniformData) < 16384,
49 "VSUniformData structure must be less than 16kb as per the OpenGL spec");
50
51class OGLShaderStage { 38class OGLShaderStage {
52public: 39public:
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,