summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-05-31 17:33:21 -0300
committerGravatar ReinUsesLisp2019-06-07 19:47:15 -0300
commit2f2a61887a2830cf8a1d5c40302fa0c199c6e317 (patch)
tree17bb8b94a9f889d4163ae90b99600aea71a2738d /src
parentMerge pull request #2514 from ReinUsesLisp/opengl-compat (diff)
downloadyuzu-2f2a61887a2830cf8a1d5c40302fa0c199c6e317.tar.gz
yuzu-2f2a61887a2830cf8a1d5c40302fa0c199c6e317.tar.xz
yuzu-2f2a61887a2830cf8a1d5c40302fa0c199c6e317.zip
video_core/engines: Move ConstBufferInfo out of Maxwell3D
Diffstat (limited to 'src')
-rw-r--r--src/video_core/CMakeLists.txt1
-rw-r--r--src/video_core/engines/const_buffer_info.h17
-rw-r--r--src/video_core/engines/maxwell_3d.cpp4
-rw-r--r--src/video_core/engines/maxwell_3d.h8
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp73
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h10
6 files changed, 64 insertions, 49 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 2d4caa08d..f8b67cbe1 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -3,6 +3,7 @@ add_library(video_core STATIC
3 dma_pusher.h 3 dma_pusher.h
4 debug_utils/debug_utils.cpp 4 debug_utils/debug_utils.cpp
5 debug_utils/debug_utils.h 5 debug_utils/debug_utils.h
6 engines/const_buffer_info.h
6 engines/engine_upload.cpp 7 engines/engine_upload.cpp
7 engines/engine_upload.h 8 engines/engine_upload.h
8 engines/fermi_2d.cpp 9 engines/fermi_2d.cpp
diff --git a/src/video_core/engines/const_buffer_info.h b/src/video_core/engines/const_buffer_info.h
new file mode 100644
index 000000000..d8f672462
--- /dev/null
+++ b/src/video_core/engines/const_buffer_info.h
@@ -0,0 +1,17 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Tegra::Engines {
10
11struct ConstBufferInfo {
12 GPUVAddr address;
13 u32 size;
14 bool enabled;
15};
16
17} // namespace Tegra::Engines
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index 39968d403..08d553696 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -396,12 +396,10 @@ void Maxwell3D::ProcessCBBind(Regs::ShaderStage stage) {
396 auto& shader = state.shader_stages[static_cast<std::size_t>(stage)]; 396 auto& shader = state.shader_stages[static_cast<std::size_t>(stage)];
397 auto& bind_data = regs.cb_bind[static_cast<std::size_t>(stage)]; 397 auto& bind_data = regs.cb_bind[static_cast<std::size_t>(stage)];
398 398
399 auto& buffer = shader.const_buffers[bind_data.index];
400
401 ASSERT(bind_data.index < Regs::MaxConstBuffers); 399 ASSERT(bind_data.index < Regs::MaxConstBuffers);
400 auto& buffer = shader.const_buffers[bind_data.index];
402 401
403 buffer.enabled = bind_data.valid.Value() != 0; 402 buffer.enabled = bind_data.valid.Value() != 0;
404 buffer.index = bind_data.index;
405 buffer.address = regs.const_buffer.BufferAddress(); 403 buffer.address = regs.const_buffer.BufferAddress();
406 buffer.size = regs.const_buffer.cb_size; 404 buffer.size = regs.const_buffer.cb_size;
407} 405}
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index f342c78e6..13e314944 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -15,6 +15,7 @@
15#include "common/common_funcs.h" 15#include "common/common_funcs.h"
16#include "common/common_types.h" 16#include "common/common_types.h"
17#include "common/math_util.h" 17#include "common/math_util.h"
18#include "video_core/engines/const_buffer_info.h"
18#include "video_core/engines/engine_upload.h" 19#include "video_core/engines/engine_upload.h"
19#include "video_core/gpu.h" 20#include "video_core/gpu.h"
20#include "video_core/macro_interpreter.h" 21#include "video_core/macro_interpreter.h"
@@ -1112,13 +1113,6 @@ public:
1112 static_assert(std::is_trivially_copyable_v<Regs>, "Maxwell3D Regs must be trivially copyable"); 1113 static_assert(std::is_trivially_copyable_v<Regs>, "Maxwell3D Regs must be trivially copyable");
1113 1114
1114 struct State { 1115 struct State {
1115 struct ConstBufferInfo {
1116 GPUVAddr address;
1117 u32 index;
1118 u32 size;
1119 bool enabled;
1120 };
1121
1122 struct ShaderStageInfo { 1116 struct ShaderStageInfo {
1123 std::array<ConstBufferInfo, Regs::MaxConstBuffers> const_buffers; 1117 std::array<ConstBufferInfo, Regs::MaxConstBuffers> const_buffers;
1124 }; 1118 };
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index ca410287a..f3b84781c 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -322,8 +322,8 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) {
322 } 322 }
323 323
324 const auto stage_enum = static_cast<Maxwell::ShaderStage>(stage); 324 const auto stage_enum = static_cast<Maxwell::ShaderStage>(stage);
325 SetupConstBuffers(stage_enum, shader, program_handle, base_bindings); 325 SetupDrawConstBuffers(stage_enum, shader);
326 SetupGlobalRegions(stage_enum, shader, program_handle, base_bindings); 326 SetupGlobalRegions(stage_enum, shader, primitive_mode, base_bindings);
327 SetupTextures(stage_enum, shader, program_handle, base_bindings); 327 SetupTextures(stage_enum, shader, program_handle, base_bindings);
328 328
329 // Workaround for Intel drivers. 329 // Workaround for Intel drivers.
@@ -776,52 +776,51 @@ bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
776 return true; 776 return true;
777} 777}
778 778
779void RasterizerOpenGL::SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, 779void RasterizerOpenGL::SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
780 const Shader& shader, GLuint program_handle, 780 const Shader& shader) {
781 BaseBindings base_bindings) {
782 MICROPROFILE_SCOPE(OpenGL_UBO); 781 MICROPROFILE_SCOPE(OpenGL_UBO);
783 const auto& gpu = system.GPU(); 782 const auto stage_index = static_cast<std::size_t>(stage);
784 const auto& maxwell3d = gpu.Maxwell3D(); 783 const auto& shader_stage = system.GPU().Maxwell3D().state.shader_stages[stage_index];
785 const auto& shader_stage = maxwell3d.state.shader_stages[static_cast<std::size_t>(stage)];
786 const auto& entries = shader->GetShaderEntries().const_buffers; 784 const auto& entries = shader->GetShaderEntries().const_buffers;
787 785
788 // Upload only the enabled buffers from the 16 constbuffers of each shader stage 786 // Upload only the enabled buffers from the 16 constbuffers of each shader stage
789 for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { 787 for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) {
790 const auto& used_buffer = entries[bindpoint]; 788 const auto& entry = entries[bindpoint];
791 const auto& buffer = shader_stage.const_buffers[used_buffer.GetIndex()]; 789 SetupConstBuffer(shader_stage.const_buffers[entry.GetIndex()], entry);
792 790 }
793 if (!buffer.enabled) { 791}
794 // Set values to zero to unbind buffers
795 bind_ubo_pushbuffer.Push(0, 0, 0);
796 continue;
797 }
798 792
799 std::size_t size = 0; 793void RasterizerOpenGL::SetupConstBuffer(const Tegra::Engines::ConstBufferInfo& buffer,
794 const GLShader::ConstBufferEntry& entry) {
795 if (!buffer.enabled) {
796 // Set values to zero to unbind buffers
797 bind_ubo_pushbuffer.Push(0, 0, 0);
798 return;
799 }
800 800
801 if (used_buffer.IsIndirect()) { 801 std::size_t size;
802 // Buffer is accessed indirectly, so upload the entire thing 802 if (entry.IsIndirect()) {
803 size = buffer.size; 803 // Buffer is accessed indirectly, so upload the entire thing
804 size = buffer.size;
804 805
805 if (size > MaxConstbufferSize) { 806 if (size > MaxConstbufferSize) {
806 LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", size, 807 LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", size,
807 MaxConstbufferSize); 808 MaxConstbufferSize);
808 size = MaxConstbufferSize; 809 size = MaxConstbufferSize;
809 }
810 } else {
811 // Buffer is accessed directly, upload just what we use
812 size = used_buffer.GetSize();
813 } 810 }
811 } else {
812 // Buffer is accessed directly, upload just what we use
813 size = entry.GetSize();
814 }
814 815
815 // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140 816 // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140
816 // UBO alignment requirements. 817 // UBO alignment requirements.
817 size = Common::AlignUp(size, sizeof(GLvec4)); 818 size = Common::AlignUp(size, sizeof(GLvec4));
818 ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big"); 819 ASSERT_MSG(size <= MaxConstbufferSize, "Constant buffer is too big");
819
820 const GLintptr const_buffer_offset =
821 buffer_cache.UploadMemory(buffer.address, size, device.GetUniformBufferAlignment());
822 820
823 bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), const_buffer_offset, size); 821 const std::size_t alignment = device.GetUniformBufferAlignment();
824 } 822 const GLintptr offset = buffer_cache.UploadMemory(buffer.address, size, alignment);
823 bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), offset, size);
825} 824}
826 825
827void RasterizerOpenGL::SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, 826void RasterizerOpenGL::SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 2817f65c9..dab08656f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -17,6 +17,7 @@
17#include <glad/glad.h> 17#include <glad/glad.h>
18 18
19#include "common/common_types.h" 19#include "common/common_types.h"
20#include "video_core/engines/const_buffer_info.h"
20#include "video_core/engines/maxwell_3d.h" 21#include "video_core/engines/maxwell_3d.h"
21#include "video_core/rasterizer_cache.h" 22#include "video_core/rasterizer_cache.h"
22#include "video_core/rasterizer_interface.h" 23#include "video_core/rasterizer_interface.h"
@@ -27,6 +28,7 @@
27#include "video_core/renderer_opengl/gl_resource_manager.h" 28#include "video_core/renderer_opengl/gl_resource_manager.h"
28#include "video_core/renderer_opengl/gl_sampler_cache.h" 29#include "video_core/renderer_opengl/gl_sampler_cache.h"
29#include "video_core/renderer_opengl/gl_shader_cache.h" 30#include "video_core/renderer_opengl/gl_shader_cache.h"
31#include "video_core/renderer_opengl/gl_shader_decompiler.h"
30#include "video_core/renderer_opengl/gl_shader_manager.h" 32#include "video_core/renderer_opengl/gl_shader_manager.h"
31#include "video_core/renderer_opengl/gl_state.h" 33#include "video_core/renderer_opengl/gl_state.h"
32#include "video_core/renderer_opengl/utils.h" 34#include "video_core/renderer_opengl/utils.h"
@@ -105,8 +107,12 @@ private:
105 bool preserve_contents = true, std::optional<std::size_t> single_color_target = {}); 107 bool preserve_contents = true, std::optional<std::size_t> single_color_target = {});
106 108
107 /// Configures the current constbuffers to use for the draw command. 109 /// Configures the current constbuffers to use for the draw command.
108 void SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, const Shader& shader, 110 void SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
109 GLuint program_handle, BaseBindings base_bindings); 111 const Shader& shader);
112
113 /// Configures a constant buffer.
114 void SetupConstBuffer(const Tegra::Engines::ConstBufferInfo& buffer,
115 const GLShader::ConstBufferEntry& entry);
110 116
111 /// Configures the current global memory entries to use for the draw command. 117 /// Configures the current global memory entries to use for the draw command.
112 void SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, 118 void SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,