summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp39
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h11
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp9
-rw-r--r--src/video_core/renderer_opengl/gl_state.h2
4 files changed, 32 insertions, 29 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 5a0e337a5..fd4731d80 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -44,14 +44,6 @@ RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window)
44 state.texture_units[i].sampler = texture_samplers[i].sampler.handle; 44 state.texture_units[i].sampler = texture_samplers[i].sampler.handle;
45 } 45 }
46 46
47 // Create SSBOs
48 for (size_t stage = 0; stage < ssbos.size(); ++stage) {
49 for (size_t buffer = 0; buffer < ssbos[stage].size(); ++buffer) {
50 ssbos[stage][buffer].Create();
51 state.draw.const_buffers[stage][buffer].ssbo = ssbos[stage][buffer].handle;
52 }
53 }
54
55 GLint ext_num; 47 GLint ext_num;
56 glGetIntegerv(GL_NUM_EXTENSIONS, &ext_num); 48 glGetIntegerv(GL_NUM_EXTENSIONS, &ext_num);
57 for (GLint i = 0; i < ext_num; i++) { 49 for (GLint i = 0; i < ext_num; i++) {
@@ -255,9 +247,9 @@ std::pair<u8*, GLintptr> RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr
255 static_cast<Maxwell::ShaderStage>(stage)); 247 static_cast<Maxwell::ShaderStage>(stage));
256 248
257 // Configure the const buffers for this shader stage. 249 // Configure the const buffers for this shader stage.
258 current_constbuffer_bindpoint = 250 std::tie(buffer_ptr, buffer_offset, current_constbuffer_bindpoint) = SetupConstBuffers(
259 SetupConstBuffers(static_cast<Maxwell::ShaderStage>(stage), gl_stage_program, 251 buffer_ptr, buffer_offset, static_cast<Maxwell::ShaderStage>(stage), gl_stage_program,
260 current_constbuffer_bindpoint, shader_resources.const_buffer_entries); 252 current_constbuffer_bindpoint, shader_resources.const_buffer_entries);
261 253
262 // Configure the textures for this shader stage. 254 // Configure the textures for this shader stage.
263 current_texture_bindpoint = 255 current_texture_bindpoint =
@@ -453,6 +445,9 @@ void RasterizerOpenGL::DrawArrays() {
453 Common::AlignUp<size_t>(buffer_size, 4) + 445 Common::AlignUp<size_t>(buffer_size, 4) +
454 (sizeof(GLShader::MaxwellUniformData) + uniform_buffer_alignment) * Maxwell::MaxShaderStage; 446 (sizeof(GLShader::MaxwellUniformData) + uniform_buffer_alignment) * Maxwell::MaxShaderStage;
455 447
448 // Add space for at least 18 constant buffers
449 buffer_size += Maxwell::MaxConstBuffers * (MaxConstbufferSize + uniform_buffer_alignment);
450
456 u8* buffer_ptr; 451 u8* buffer_ptr;
457 GLintptr buffer_offset; 452 GLintptr buffer_offset;
458 std::tie(buffer_ptr, buffer_offset, std::ignore) = 453 std::tie(buffer_ptr, buffer_offset, std::ignore) =
@@ -627,9 +622,9 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr
627 } 622 }
628} 623}
629 624
630u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint program, 625std::tuple<u8*, GLintptr, u32> RasterizerOpenGL::SetupConstBuffers(
631 u32 current_bindpoint, 626 u8* buffer_ptr, GLintptr buffer_offset, Maxwell::ShaderStage stage, GLuint program,
632 const std::vector<GLShader::ConstBufferEntry>& entries) { 627 u32 current_bindpoint, const std::vector<GLShader::ConstBufferEntry>& entries) {
633 const auto& gpu = Core::System::GetInstance().GPU(); 628 const auto& gpu = Core::System::GetInstance().GPU();
634 const auto& maxwell3d = gpu.Maxwell3D(); 629 const auto& maxwell3d = gpu.Maxwell3D();
635 630
@@ -678,12 +673,16 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr
678 size = Common::AlignUp(size, sizeof(GLvec4)); 673 size = Common::AlignUp(size, sizeof(GLvec4));
679 ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big"); 674 ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big");
680 675
681 std::vector<u8> data(size); 676 std::tie(buffer_ptr, buffer_offset) =
682 Memory::ReadBlock(*addr, data.data(), data.size()); 677 AlignBuffer(buffer_ptr, buffer_offset, static_cast<size_t>(uniform_buffer_alignment));
683 678
684 glBindBuffer(GL_UNIFORM_BUFFER, buffer_draw_state.ssbo); 679 buffer_draw_state.size = size;
685 glBufferData(GL_UNIFORM_BUFFER, data.size(), data.data(), GL_DYNAMIC_DRAW); 680 buffer_draw_state.offset = buffer_offset;
686 glBindBuffer(GL_UNIFORM_BUFFER, 0); 681 buffer_draw_state.ssbo = stream_buffer.GetHandle();
682
683 Memory::ReadBlock(*addr, buffer_ptr, size);
684 buffer_ptr += size;
685 buffer_offset += size;
687 686
688 // Now configure the bindpoint of the buffer inside the shader 687 // Now configure the bindpoint of the buffer inside the shader
689 const std::string buffer_name = used_buffer.GetName(); 688 const std::string buffer_name = used_buffer.GetName();
@@ -696,7 +695,7 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr
696 695
697 state.Apply(); 696 state.Apply();
698 697
699 return current_bindpoint + static_cast<u32>(entries.size()); 698 return {buffer_ptr, buffer_offset, current_bindpoint + static_cast<u32>(entries.size())};
700} 699}
701 700
702u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, GLuint program, u32 current_unit, 701u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, GLuint program, u32 current_unit,
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 6f8503703..aa6afc1de 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -7,6 +7,7 @@
7#include <array> 7#include <array>
8#include <cstddef> 8#include <cstddef>
9#include <memory> 9#include <memory>
10#include <tuple>
10#include <utility> 11#include <utility>
11#include <vector> 12#include <vector>
12#include <glad/glad.h> 13#include <glad/glad.h>
@@ -100,9 +101,10 @@ private:
100 * @param entries Vector describing the buffers that are actually used in the guest shader. 101 * @param entries Vector describing the buffers that are actually used in the guest shader.
101 * @returns The next available bindpoint for use in the next shader stage. 102 * @returns The next available bindpoint for use in the next shader stage.
102 */ 103 */
103 u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, GLuint program, 104 std::tuple<u8*, GLintptr, u32> SetupConstBuffers(
104 u32 current_bindpoint, 105 u8* buffer_ptr, GLintptr buffer_offset, Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
105 const std::vector<GLShader::ConstBufferEntry>& entries); 106 GLuint program, u32 current_bindpoint,
107 const std::vector<GLShader::ConstBufferEntry>& entries);
106 108
107 /* 109 /*
108 * Configures the current textures to use for the draw command. 110 * Configures the current textures to use for the draw command.
@@ -154,9 +156,6 @@ private:
154 OGLVertexArray hw_vao; 156 OGLVertexArray hw_vao;
155 157
156 std::array<SamplerInfo, GLShader::NumTextureSamplers> texture_samplers; 158 std::array<SamplerInfo, GLShader::NumTextureSamplers> texture_samplers;
157 std::array<std::array<OGLBuffer, Tegra::Engines::Maxwell3D::Regs::MaxConstBuffers>,
158 Tegra::Engines::Maxwell3D::Regs::MaxShaderStage>
159 ssbos;
160 159
161 static constexpr size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024; 160 static constexpr size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024;
162 OGLStreamBuffer stream_buffer; 161 OGLStreamBuffer stream_buffer;
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index 68bacd4c5..212c87e0c 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -209,10 +209,13 @@ void OpenGLState::Apply() const {
209 const auto& current = cur_state.draw.const_buffers[stage][buffer_id]; 209 const auto& current = cur_state.draw.const_buffers[stage][buffer_id];
210 const auto& new_state = draw.const_buffers[stage][buffer_id]; 210 const auto& new_state = draw.const_buffers[stage][buffer_id];
211 211
212 if (current.enabled != new_state.enabled || current.bindpoint != new_state.bindpoint || 212 if (std::tie(current.enabled, current.bindpoint, current.ssbo, current.size,
213 current.ssbo != new_state.ssbo) { 213 current.offset) != std::tie(new_state.enabled, new_state.bindpoint,
214 new_state.ssbo, new_state.size,
215 new_state.offset)) {
214 if (new_state.enabled) { 216 if (new_state.enabled) {
215 glBindBufferBase(GL_UNIFORM_BUFFER, new_state.bindpoint, new_state.ssbo); 217 glBindBufferRange(GL_UNIFORM_BUFFER, new_state.bindpoint, new_state.ssbo,
218 new_state.offset, new_state.size);
216 } 219 }
217 } 220 }
218 } 221 }
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index 5c7b636e4..26e5460e5 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -123,6 +123,8 @@ public:
123 bool enabled = false; 123 bool enabled = false;
124 GLuint bindpoint; 124 GLuint bindpoint;
125 GLuint ssbo; 125 GLuint ssbo;
126 GLsizeiptr size;
127 GLintptr offset;
126 }; 128 };
127 std::array<std::array<ConstBufferConfig, Regs::MaxConstBuffers>, 5> const_buffers; 129 std::array<std::array<ConstBufferConfig, Regs::MaxConstBuffers>, 5> const_buffers;
128 } draw; 130 } draw;