summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2018-09-08 04:49:24 -0400
committerGravatar GitHub2018-09-08 04:49:24 -0400
commit9cd79c25ed04bb1bf67192d810791ab39e09ee96 (patch)
tree2bb26606f2723dc863e8be3c4a161b2adfd189cb
parentMerge pull request #1259 from lioncash/relocate (diff)
parentgl_rasterizer: Use baseInstance instead of moving the buffer points. (diff)
downloadyuzu-9cd79c25ed04bb1bf67192d810791ab39e09ee96.tar.gz
yuzu-9cd79c25ed04bb1bf67192d810791ab39e09ee96.tar.xz
yuzu-9cd79c25ed04bb1bf67192d810791ab39e09ee96.zip
Merge pull request #1246 from degasus/instanced_rendering
gl_rasterizer: Use baseInstance instead of moving the buffer points.
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp46
-rw-r--r--src/yuzu/main.cpp2
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp2
3 files changed, 29 insertions, 21 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 19399fab8..0c3bbc475 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -151,11 +151,6 @@ void RasterizerOpenGL::SetupVertexArrays() {
151 Tegra::GPUVAddr start = vertex_array.StartAddress(); 151 Tegra::GPUVAddr start = vertex_array.StartAddress();
152 const Tegra::GPUVAddr end = regs.vertex_array_limit[index].LimitAddress(); 152 const Tegra::GPUVAddr end = regs.vertex_array_limit[index].LimitAddress();
153 153
154 if (regs.instanced_arrays.IsInstancingEnabled(index) && vertex_array.divisor != 0) {
155 start += static_cast<Tegra::GPUVAddr>(vertex_array.stride) *
156 (gpu.state.current_instance / vertex_array.divisor);
157 }
158
159 ASSERT(end > start); 154 ASSERT(end > start);
160 const u64 size = end - start + 1; 155 const u64 size = end - start + 1;
161 const GLintptr vertex_buffer_offset = buffer_cache.UploadMemory(start, size); 156 const GLintptr vertex_buffer_offset = buffer_cache.UploadMemory(start, size);
@@ -165,10 +160,8 @@ void RasterizerOpenGL::SetupVertexArrays() {
165 vertex_array.stride); 160 vertex_array.stride);
166 161
167 if (regs.instanced_arrays.IsInstancingEnabled(index) && vertex_array.divisor != 0) { 162 if (regs.instanced_arrays.IsInstancingEnabled(index) && vertex_array.divisor != 0) {
168 // Tell OpenGL that this is an instanced vertex buffer to prevent accessing different 163 // Enable vertex buffer instancing with the specified divisor.
169 // indexes on each vertex. We do the instance indexing manually by incrementing the 164 glVertexBindingDivisor(index, vertex_array.divisor);
170 // start address of the vertex buffer.
171 glVertexBindingDivisor(index, 1);
172 } else { 165 } else {
173 // Disable the vertex buffer instancing. 166 // Disable the vertex buffer instancing.
174 glVertexBindingDivisor(index, 0); 167 glVertexBindingDivisor(index, 0);
@@ -432,7 +425,8 @@ void RasterizerOpenGL::DrawArrays() {
432 return; 425 return;
433 426
434 MICROPROFILE_SCOPE(OpenGL_Drawing); 427 MICROPROFILE_SCOPE(OpenGL_Drawing);
435 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; 428 const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
429 const auto& regs = gpu.regs;
436 430
437 ScopeAcquireGLContext acquire_context{emu_window}; 431 ScopeAcquireGLContext acquire_context{emu_window};
438 432
@@ -497,11 +491,26 @@ void RasterizerOpenGL::DrawArrays() {
497 index_buffer_offset += static_cast<GLintptr>(regs.index_array.first) * 491 index_buffer_offset += static_cast<GLintptr>(regs.index_array.first) *
498 static_cast<GLintptr>(regs.index_array.FormatSizeInBytes()); 492 static_cast<GLintptr>(regs.index_array.FormatSizeInBytes());
499 493
500 glDrawElementsBaseVertex(primitive_mode, regs.index_array.count, 494 if (gpu.state.current_instance > 0) {
501 MaxwellToGL::IndexFormat(regs.index_array.format), 495 glDrawElementsInstancedBaseVertexBaseInstance(
502 reinterpret_cast<const void*>(index_buffer_offset), base_vertex); 496 primitive_mode, regs.index_array.count,
497 MaxwellToGL::IndexFormat(regs.index_array.format),
498 reinterpret_cast<const void*>(index_buffer_offset), 1, base_vertex,
499 gpu.state.current_instance);
500 } else {
501 glDrawElementsBaseVertex(primitive_mode, regs.index_array.count,
502 MaxwellToGL::IndexFormat(regs.index_array.format),
503 reinterpret_cast<const void*>(index_buffer_offset),
504 base_vertex);
505 }
503 } else { 506 } else {
504 glDrawArrays(primitive_mode, regs.vertex_buffer.first, regs.vertex_buffer.count); 507 if (gpu.state.current_instance > 0) {
508 glDrawArraysInstancedBaseInstance(primitive_mode, regs.vertex_buffer.first,
509 regs.vertex_buffer.count, 1,
510 gpu.state.current_instance);
511 } else {
512 glDrawArrays(primitive_mode, regs.vertex_buffer.first, regs.vertex_buffer.count);
513 }
505 } 514 }
506 515
507 // Disable scissor test 516 // Disable scissor test
@@ -518,13 +527,9 @@ void RasterizerOpenGL::DrawArrays() {
518 527
519void RasterizerOpenGL::NotifyMaxwellRegisterChanged(u32 method) {} 528void RasterizerOpenGL::NotifyMaxwellRegisterChanged(u32 method) {}
520 529
521void RasterizerOpenGL::FlushAll() { 530void RasterizerOpenGL::FlushAll() {}
522 MICROPROFILE_SCOPE(OpenGL_CacheManagement);
523}
524 531
525void RasterizerOpenGL::FlushRegion(VAddr addr, u64 size) { 532void RasterizerOpenGL::FlushRegion(VAddr addr, u64 size) {}
526 MICROPROFILE_SCOPE(OpenGL_CacheManagement);
527}
528 533
529void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) { 534void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) {
530 MICROPROFILE_SCOPE(OpenGL_CacheManagement); 535 MICROPROFILE_SCOPE(OpenGL_CacheManagement);
@@ -534,7 +539,6 @@ void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) {
534} 539}
535 540
536void RasterizerOpenGL::FlushAndInvalidateRegion(VAddr addr, u64 size) { 541void RasterizerOpenGL::FlushAndInvalidateRegion(VAddr addr, u64 size) {
537 MICROPROFILE_SCOPE(OpenGL_CacheManagement);
538 InvalidateRegion(addr, size); 542 InvalidateRegion(addr, size);
539} 543}
540 544
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index cb8135c42..2cd282a51 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -444,6 +444,8 @@ QStringList GMainWindow::GetUnsupportedGLExtensions() {
444 unsupported_ext.append("ARB_vertex_type_10f_11f_11f_rev"); 444 unsupported_ext.append("ARB_vertex_type_10f_11f_11f_rev");
445 if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge) 445 if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
446 unsupported_ext.append("ARB_texture_mirror_clamp_to_edge"); 446 unsupported_ext.append("ARB_texture_mirror_clamp_to_edge");
447 if (!GLAD_GL_ARB_base_instance)
448 unsupported_ext.append("ARB_base_instance");
447 449
448 // Extensions required to support some texture formats. 450 // Extensions required to support some texture formats.
449 if (!GLAD_GL_EXT_texture_compression_s3tc) 451 if (!GLAD_GL_EXT_texture_compression_s3tc)
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index c87e96b2d..2f7916256 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -91,6 +91,8 @@ bool EmuWindow_SDL2::SupportsRequiredGLExtensions() {
91 unsupported_ext.push_back("ARB_vertex_type_10f_11f_11f_rev"); 91 unsupported_ext.push_back("ARB_vertex_type_10f_11f_11f_rev");
92 if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge) 92 if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
93 unsupported_ext.push_back("ARB_texture_mirror_clamp_to_edge"); 93 unsupported_ext.push_back("ARB_texture_mirror_clamp_to_edge");
94 if (!GLAD_GL_ARB_base_instance)
95 unsupported_ext.push_back("ARB_base_instance");
94 96
95 // Extensions required to support some texture formats. 97 // Extensions required to support some texture formats.
96 if (!GLAD_GL_EXT_texture_compression_s3tc) 98 if (!GLAD_GL_EXT_texture_compression_s3tc)