summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorDavid <25727384+ogniK5377@users.noreply.github.com>2019-09-22 15:13:02 +0200
committerGitHub <noreply@github.com>2019-09-22 15:13:02 +0200
commit9d69206cd00982e02f90845c98d7d6c9887645c3 (patch)
tree51ec8f19f2e91f49a1f77baaffecd4cb7677e911 /src/video_core/renderer_opengl
parentMerge pull request #2891 from FearlessTobi/rod-tex (diff)
parentMaxwell3D: Corrections and refactors to MME instance refactor (diff)
downloadyuzu-9d69206cd00982e02f90845c98d7d6c9887645c3.tar
yuzu-9d69206cd00982e02f90845c98d7d6c9887645c3.tar.gz
yuzu-9d69206cd00982e02f90845c98d7d6c9887645c3.tar.bz2
yuzu-9d69206cd00982e02f90845c98d7d6c9887645c3.tar.lz
yuzu-9d69206cd00982e02f90845c98d7d6c9887645c3.tar.xz
yuzu-9d69206cd00982e02f90845c98d7d6c9887645c3.tar.zst
yuzu-9d69206cd00982e02f90845c98d7d6c9887645c3.zip
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp181
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h9
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp10
3 files changed, 117 insertions, 83 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index a2c1473db..6a17bed72 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -49,40 +49,6 @@ MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(128, 128, 192));
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
MICROPROFILE_DEFINE(OpenGL_PrimitiveAssembly, "OpenGL", "Prim Asmbl", MP_RGB(255, 100, 100));
-struct DrawParameters {
- GLenum primitive_mode;
- GLsizei count;
- GLint current_instance;
- bool use_indexed;
-
- GLint vertex_first;
-
- GLenum index_format;
- GLint base_vertex;
- GLintptr index_buffer_offset;
-
- void DispatchDraw() const {
- if (use_indexed) {
- const auto index_buffer_ptr = reinterpret_cast<const void*>(index_buffer_offset);
- if (current_instance > 0) {
- glDrawElementsInstancedBaseVertexBaseInstance(primitive_mode, count, index_format,
- index_buffer_ptr, 1, base_vertex,
- current_instance);
- } else {
- glDrawElementsBaseVertex(primitive_mode, count, index_format, index_buffer_ptr,
- base_vertex);
- }
- } else {
- if (current_instance > 0) {
- glDrawArraysInstancedBaseInstance(primitive_mode, vertex_first, count, 1,
- current_instance);
- } else {
- glDrawArrays(primitive_mode, vertex_first, count);
- }
- }
- }
-};
-
static std::size_t GetConstBufferSize(const Tegra::Engines::ConstBufferInfo& buffer,
const GLShader::ConstBufferEntry& entry) {
if (!entry.IsIndirect()) {
@@ -270,29 +236,6 @@ GLintptr RasterizerOpenGL::SetupIndexBuffer() {
return offset;
}
-DrawParameters RasterizerOpenGL::SetupDraw(GLintptr index_buffer_offset) {
- const auto& gpu = system.GPU().Maxwell3D();
- const auto& regs = gpu.regs;
- const bool is_indexed = accelerate_draw == AccelDraw::Indexed;
-
- DrawParameters params{};
- params.current_instance = gpu.state.current_instance;
-
- params.use_indexed = is_indexed;
- params.primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology);
-
- if (is_indexed) {
- params.index_format = MaxwellToGL::IndexFormat(regs.index_array.format);
- params.count = regs.index_array.count;
- params.index_buffer_offset = index_buffer_offset;
- params.base_vertex = static_cast<GLint>(regs.vb_element_base);
- } else {
- params.count = regs.vertex_buffer.count;
- params.vertex_first = regs.vertex_buffer.first;
- }
- return params;
-}
-
void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) {
MICROPROFILE_SCOPE(OpenGL_Shader);
auto& gpu = system.GPU().Maxwell3D();
@@ -399,12 +342,6 @@ std::size_t RasterizerOpenGL::CalculateIndexBufferSize() const {
static_cast<std::size_t>(regs.index_array.FormatSizeInBytes());
}
-bool RasterizerOpenGL::AccelerateDrawBatch(bool is_indexed) {
- accelerate_draw = is_indexed ? AccelDraw::Indexed : AccelDraw::Arrays;
- DrawArrays();
- return true;
-}
-
template <typename Map, typename Interval>
static constexpr auto RangeFromInterval(Map& map, const Interval& interval) {
return boost::make_iterator_range(map.equal_range(interval));
@@ -640,17 +577,9 @@ void RasterizerOpenGL::Clear() {
}
}
-void RasterizerOpenGL::DrawArrays() {
- if (accelerate_draw == AccelDraw::Disabled)
- return;
-
- MICROPROFILE_SCOPE(OpenGL_Drawing);
+void RasterizerOpenGL::DrawPrelude() {
auto& gpu = system.GPU().Maxwell3D();
- if (!gpu.ShouldExecute()) {
- return;
- }
-
SyncColorMask();
SyncFragmentColorClampState();
SyncMultiSampleState();
@@ -695,10 +624,7 @@ void RasterizerOpenGL::DrawArrays() {
// Upload vertex and index data.
SetupVertexBuffer(vao);
SetupVertexInstances(vao);
- const GLintptr index_buffer_offset = SetupIndexBuffer();
-
- // Setup draw parameters. It will automatically choose what glDraw* method to use.
- const DrawParameters params = SetupDraw(index_buffer_offset);
+ index_buffer_offset = SetupIndexBuffer();
// Prepare packed bindings.
bind_ubo_pushbuffer.Setup(0);
@@ -706,7 +632,8 @@ void RasterizerOpenGL::DrawArrays() {
// Setup shaders and their used resources.
texture_cache.GuardSamplers(true);
- SetupShaders(params.primitive_mode);
+ const auto primitive_mode = MaxwellToGL::PrimitiveTopology(gpu.regs.draw.topology);
+ SetupShaders(primitive_mode);
texture_cache.GuardSamplers(false);
ConfigureFramebuffers();
@@ -730,11 +657,107 @@ void RasterizerOpenGL::DrawArrays() {
if (texture_cache.TextureBarrier()) {
glTextureBarrier();
}
+}
+
+struct DrawParams {
+ bool is_indexed{};
+ bool is_instanced{};
+ GLenum primitive_mode{};
+ GLint count{};
+ GLint base_vertex{};
+
+ // Indexed settings
+ GLenum index_format{};
+ GLintptr index_buffer_offset{};
+
+ // Instanced setting
+ GLint num_instances{};
+ GLint base_instance{};
+
+ void DispatchDraw() {
+ if (is_indexed) {
+ const auto index_buffer_ptr = reinterpret_cast<const void*>(index_buffer_offset);
+ if (is_instanced) {
+ glDrawElementsInstancedBaseVertexBaseInstance(primitive_mode, count, index_format,
+ index_buffer_ptr, num_instances,
+ base_vertex, base_instance);
+ } else {
+ glDrawElementsBaseVertex(primitive_mode, count, index_format, index_buffer_ptr,
+ base_vertex);
+ }
+ } else {
+ if (is_instanced) {
+ glDrawArraysInstancedBaseInstance(primitive_mode, base_vertex, count, num_instances,
+ base_instance);
+ } else {
+ glDrawArrays(primitive_mode, base_vertex, count);
+ }
+ }
+ }
+};
- params.DispatchDraw();
+bool RasterizerOpenGL::DrawBatch(bool is_indexed) {
+ accelerate_draw = is_indexed ? AccelDraw::Indexed : AccelDraw::Arrays;
+
+ MICROPROFILE_SCOPE(OpenGL_Drawing);
+ DrawPrelude();
+
+ auto& maxwell3d = system.GPU().Maxwell3D();
+ const auto& regs = maxwell3d.regs;
+ const auto current_instance = maxwell3d.state.current_instance;
+ DrawParams draw_call{};
+ draw_call.is_indexed = is_indexed;
+ draw_call.num_instances = static_cast<GLint>(1);
+ draw_call.base_instance = static_cast<GLint>(current_instance);
+ draw_call.is_instanced = current_instance > 0;
+ draw_call.primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology);
+ if (draw_call.is_indexed) {
+ draw_call.count = static_cast<GLint>(regs.index_array.count);
+ draw_call.base_vertex = static_cast<GLint>(regs.vb_element_base);
+ draw_call.index_format = MaxwellToGL::IndexFormat(regs.index_array.format);
+ draw_call.index_buffer_offset = index_buffer_offset;
+ } else {
+ draw_call.count = static_cast<GLint>(regs.vertex_buffer.count);
+ draw_call.base_vertex = static_cast<GLint>(regs.vertex_buffer.first);
+ }
+ draw_call.DispatchDraw();
+
+ maxwell3d.dirty.memory_general = false;
accelerate_draw = AccelDraw::Disabled;
- gpu.dirty.memory_general = false;
+ return true;
+}
+
+bool RasterizerOpenGL::DrawMultiBatch(bool is_indexed) {
+ accelerate_draw = is_indexed ? AccelDraw::Indexed : AccelDraw::Arrays;
+
+ MICROPROFILE_SCOPE(OpenGL_Drawing);
+
+ DrawPrelude();
+
+ auto& maxwell3d = system.GPU().Maxwell3D();
+ const auto& regs = maxwell3d.regs;
+ const auto& draw_setup = maxwell3d.mme_draw;
+ DrawParams draw_call{};
+ draw_call.is_indexed = is_indexed;
+ draw_call.num_instances = static_cast<GLint>(draw_setup.instance_count);
+ draw_call.base_instance = static_cast<GLint>(regs.vb_base_instance);
+ draw_call.is_instanced = draw_setup.instance_count > 1;
+ draw_call.primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology);
+ if (draw_call.is_indexed) {
+ draw_call.count = static_cast<GLint>(regs.index_array.count);
+ draw_call.base_vertex = static_cast<GLint>(regs.vb_element_base);
+ draw_call.index_format = MaxwellToGL::IndexFormat(regs.index_array.format);
+ draw_call.index_buffer_offset = index_buffer_offset;
+ } else {
+ draw_call.count = static_cast<GLint>(regs.vertex_buffer.count);
+ draw_call.base_vertex = static_cast<GLint>(regs.vertex_buffer.first);
+ }
+ draw_call.DispatchDraw();
+
+ maxwell3d.dirty.memory_general = false;
+ accelerate_draw = AccelDraw::Disabled;
+ return true;
}
void RasterizerOpenGL::DispatchCompute(GPUVAddr code_addr) {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 4f5c7f864..9c10ebda3 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -57,7 +57,8 @@ public:
ScreenInfo& info);
~RasterizerOpenGL() override;
- void DrawArrays() override;
+ bool DrawBatch(bool is_indexed) override;
+ bool DrawMultiBatch(bool is_indexed) override;
void Clear() override;
void DispatchCompute(GPUVAddr code_addr) override;
void FlushAll() override;
@@ -71,7 +72,6 @@ public:
const Tegra::Engines::Fermi2D::Config& copy_config) override;
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
u32 pixel_stride) override;
- bool AccelerateDrawBatch(bool is_indexed) override;
void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) override;
void LoadDiskResources(const std::atomic_bool& stop_loading,
const VideoCore::DiskResourceLoadCallback& callback) override;
@@ -105,6 +105,9 @@ private:
void SetupGlobalMemory(const GLShader::GlobalMemoryEntry& entry, GPUVAddr gpu_addr,
std::size_t size);
+ /// Syncs all the state, shaders, render targets and textures setting before a draw call.
+ void DrawPrelude();
+
/// Configures the current textures to use for the draw command. Returns shaders texture buffer
/// usage.
TextureBufferUsage SetupDrawTextures(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
@@ -216,7 +219,7 @@ private:
GLintptr SetupIndexBuffer();
- DrawParameters SetupDraw(GLintptr index_buffer_offset);
+ GLintptr index_buffer_offset;
void SetupShaders(GLenum primitive_mode);
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 76439e7ab..74cb59bc1 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -462,6 +462,14 @@ private:
code.AddLine("float gl_PointSize;");
}
+ if (ir.UsesInstanceId()) {
+ code.AddLine("int gl_InstanceID;");
+ }
+
+ if (ir.UsesVertexId()) {
+ code.AddLine("int gl_VertexID;");
+ }
+
--code.scope;
code.AddLine("}};");
code.AddNewLine();
@@ -964,7 +972,7 @@ private:
switch (element) {
case 2:
// Config pack's first value is instance_id.
- return {"config_pack[0]", Type::Uint};
+ return {"gl_InstanceID", Type::Int};
case 3:
return {"gl_VertexID", Type::Int};
}