diff options
| author | 2018-04-17 21:45:36 -0400 | |
|---|---|---|
| committer | 2018-04-17 21:45:36 -0400 | |
| commit | 9dc0d13ba5cb9003df735b6bd67064f6b0419c00 (patch) | |
| tree | 4e53136b745e4e31ee8ce17de70e408357816730 | |
| parent | Merge pull request #341 from shinyquagsire23/pfs-hfs-impl (diff) | |
| parent | renderer_opengl: Implement BlendEquation and BlendFunc. (diff) | |
| download | yuzu-9dc0d13ba5cb9003df735b6bd67064f6b0419c00.tar.gz yuzu-9dc0d13ba5cb9003df735b6bd67064f6b0419c00.tar.xz yuzu-9dc0d13ba5cb9003df735b6bd67064f6b0419c00.zip | |
Merge pull request #345 from bunnei/blending
renderer_opengl: Implement BlendEquation and BlendFunc.
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.h | 48 | ||||
| -rw-r--r-- | src/video_core/rasterizer_interface.h | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 27 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/maxwell_to_gl.h | 64 |
6 files changed, 140 insertions, 7 deletions
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 0e1d6d785..41f0e5c9b 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -74,8 +74,6 @@ void Maxwell3D::WriteReg(u32 method, u32 value, u32 remaining_params) { | |||
| 74 | 74 | ||
| 75 | regs.reg_array[method] = value; | 75 | regs.reg_array[method] = value; |
| 76 | 76 | ||
| 77 | #define MAXWELL3D_REG_INDEX(field_name) (offsetof(Regs, field_name) / sizeof(u32)) | ||
| 78 | |||
| 79 | switch (method) { | 77 | switch (method) { |
| 80 | case MAXWELL3D_REG_INDEX(code_address.code_address_high): | 78 | case MAXWELL3D_REG_INDEX(code_address.code_address_high): |
| 81 | case MAXWELL3D_REG_INDEX(code_address.code_address_low): { | 79 | case MAXWELL3D_REG_INDEX(code_address.code_address_low): { |
| @@ -136,7 +134,7 @@ void Maxwell3D::WriteReg(u32 method, u32 value, u32 remaining_params) { | |||
| 136 | break; | 134 | break; |
| 137 | } | 135 | } |
| 138 | 136 | ||
| 139 | #undef MAXWELL3D_REG_INDEX | 137 | VideoCore::g_renderer->Rasterizer()->NotifyMaxwellRegisterChanged(method); |
| 140 | 138 | ||
| 141 | if (debug_context) { | 139 | if (debug_context) { |
| 142 | debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandProcessed, nullptr); | 140 | debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandProcessed, nullptr); |
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 2b45ffed7..b379d8057 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -20,6 +20,9 @@ | |||
| 20 | namespace Tegra { | 20 | namespace Tegra { |
| 21 | namespace Engines { | 21 | namespace Engines { |
| 22 | 22 | ||
| 23 | #define MAXWELL3D_REG_INDEX(field_name) \ | ||
| 24 | (offsetof(Tegra::Engines::Maxwell3D::Regs, field_name) / sizeof(u32)) | ||
| 25 | |||
| 23 | class Maxwell3D final { | 26 | class Maxwell3D final { |
| 24 | public: | 27 | public: |
| 25 | explicit Maxwell3D(MemoryManager& memory_manager); | 28 | explicit Maxwell3D(MemoryManager& memory_manager); |
| @@ -254,6 +257,46 @@ public: | |||
| 254 | UnsignedInt = 0x2, | 257 | UnsignedInt = 0x2, |
| 255 | }; | 258 | }; |
| 256 | 259 | ||
| 260 | struct Blend { | ||
| 261 | enum class Equation : u32 { | ||
| 262 | Add = 1, | ||
| 263 | Subtract = 2, | ||
| 264 | ReverseSubtract = 3, | ||
| 265 | Min = 4, | ||
| 266 | Max = 5, | ||
| 267 | }; | ||
| 268 | |||
| 269 | enum class Factor : u32 { | ||
| 270 | Zero = 0x1, | ||
| 271 | One = 0x2, | ||
| 272 | SourceColor = 0x3, | ||
| 273 | OneMinusSourceColor = 0x4, | ||
| 274 | SourceAlpha = 0x5, | ||
| 275 | OneMinusSourceAlpha = 0x6, | ||
| 276 | DestAlpha = 0x7, | ||
| 277 | OneMinusDestAlpha = 0x8, | ||
| 278 | DestColor = 0x9, | ||
| 279 | OneMinusDestColor = 0xa, | ||
| 280 | SourceAlphaSaturate = 0xb, | ||
| 281 | Source1Color = 0x10, | ||
| 282 | OneMinusSource1Color = 0x11, | ||
| 283 | Source1Alpha = 0x12, | ||
| 284 | OneMinusSource1Alpha = 0x13, | ||
| 285 | ConstantColor = 0x61, | ||
| 286 | OneMinusConstantColor = 0x62, | ||
| 287 | ConstantAlpha = 0x63, | ||
| 288 | OneMinusConstantAlpha = 0x64, | ||
| 289 | }; | ||
| 290 | |||
| 291 | u32 separate_alpha; | ||
| 292 | Equation equation_rgb; | ||
| 293 | Factor factor_source_rgb; | ||
| 294 | Factor factor_dest_rgb; | ||
| 295 | Equation equation_a; | ||
| 296 | Factor factor_source_a; | ||
| 297 | Factor factor_dest_a; | ||
| 298 | }; | ||
| 299 | |||
| 257 | union { | 300 | union { |
| 258 | struct { | 301 | struct { |
| 259 | INSERT_PADDING_WORDS(0x200); | 302 | INSERT_PADDING_WORDS(0x200); |
| @@ -451,7 +494,9 @@ public: | |||
| 451 | } | 494 | } |
| 452 | } vertex_array[NumVertexArrays]; | 495 | } vertex_array[NumVertexArrays]; |
| 453 | 496 | ||
| 454 | INSERT_PADDING_WORDS(0x40); | 497 | Blend blend; |
| 498 | |||
| 499 | INSERT_PADDING_WORDS(0x39); | ||
| 455 | 500 | ||
| 456 | struct { | 501 | struct { |
| 457 | u32 limit_high; | 502 | u32 limit_high; |
| @@ -616,6 +661,7 @@ ASSERT_REG_POSITION(draw, 0x585); | |||
| 616 | ASSERT_REG_POSITION(index_array, 0x5F2); | 661 | ASSERT_REG_POSITION(index_array, 0x5F2); |
| 617 | ASSERT_REG_POSITION(query, 0x6C0); | 662 | ASSERT_REG_POSITION(query, 0x6C0); |
| 618 | ASSERT_REG_POSITION(vertex_array[0], 0x700); | 663 | ASSERT_REG_POSITION(vertex_array[0], 0x700); |
| 664 | ASSERT_REG_POSITION(blend, 0x780); | ||
| 619 | ASSERT_REG_POSITION(vertex_array_limit[0], 0x7C0); | 665 | ASSERT_REG_POSITION(vertex_array_limit[0], 0x7C0); |
| 620 | ASSERT_REG_POSITION(shader_config[0], 0x800); | 666 | ASSERT_REG_POSITION(shader_config[0], 0x800); |
| 621 | ASSERT_REG_POSITION(const_buffer, 0x8E0); | 667 | ASSERT_REG_POSITION(const_buffer, 0x8E0); |
diff --git a/src/video_core/rasterizer_interface.h b/src/video_core/rasterizer_interface.h index 35d262189..36629dd11 100644 --- a/src/video_core/rasterizer_interface.h +++ b/src/video_core/rasterizer_interface.h | |||
| @@ -19,7 +19,7 @@ public: | |||
| 19 | virtual void DrawArrays() = 0; | 19 | virtual void DrawArrays() = 0; |
| 20 | 20 | ||
| 21 | /// Notify rasterizer that the specified Maxwell register has been changed | 21 | /// Notify rasterizer that the specified Maxwell register has been changed |
| 22 | virtual void NotifyMaxwellRegisterChanged(u32 id) = 0; | 22 | virtual void NotifyMaxwellRegisterChanged(u32 method) = 0; |
| 23 | 23 | ||
| 24 | /// Notify rasterizer that all caches should be flushed to Switch memory | 24 | /// Notify rasterizer that all caches should be flushed to Switch memory |
| 25 | virtual void FlushAll() = 0; | 25 | virtual void FlushAll() = 0; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 75b4031a7..7b6240e65 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -446,7 +446,32 @@ void RasterizerOpenGL::BindTextures() { | |||
| 446 | } | 446 | } |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | void RasterizerOpenGL::NotifyMaxwellRegisterChanged(u32 id) {} | 449 | void RasterizerOpenGL::NotifyMaxwellRegisterChanged(u32 method) { |
| 450 | const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; | ||
| 451 | switch (method) { | ||
| 452 | case MAXWELL3D_REG_INDEX(blend.separate_alpha): | ||
| 453 | ASSERT_MSG(false, "unimplemented"); | ||
| 454 | break; | ||
| 455 | case MAXWELL3D_REG_INDEX(blend.equation_rgb): | ||
| 456 | state.blend.rgb_equation = MaxwellToGL::BlendEquation(regs.blend.equation_rgb); | ||
| 457 | break; | ||
| 458 | case MAXWELL3D_REG_INDEX(blend.factor_source_rgb): | ||
| 459 | state.blend.src_rgb_func = MaxwellToGL::BlendFunc(regs.blend.factor_source_rgb); | ||
| 460 | break; | ||
| 461 | case MAXWELL3D_REG_INDEX(blend.factor_dest_rgb): | ||
| 462 | state.blend.dst_rgb_func = MaxwellToGL::BlendFunc(regs.blend.factor_dest_rgb); | ||
| 463 | break; | ||
| 464 | case MAXWELL3D_REG_INDEX(blend.equation_a): | ||
| 465 | state.blend.a_equation = MaxwellToGL::BlendEquation(regs.blend.equation_a); | ||
| 466 | break; | ||
| 467 | case MAXWELL3D_REG_INDEX(blend.factor_source_a): | ||
| 468 | state.blend.src_a_func = MaxwellToGL::BlendFunc(regs.blend.factor_source_a); | ||
| 469 | break; | ||
| 470 | case MAXWELL3D_REG_INDEX(blend.factor_dest_a): | ||
| 471 | state.blend.dst_a_func = MaxwellToGL::BlendFunc(regs.blend.factor_dest_a); | ||
| 472 | break; | ||
| 473 | } | ||
| 474 | } | ||
| 450 | 475 | ||
| 451 | void RasterizerOpenGL::FlushAll() { | 476 | void RasterizerOpenGL::FlushAll() { |
| 452 | MICROPROFILE_SCOPE(OpenGL_CacheManagement); | 477 | MICROPROFILE_SCOPE(OpenGL_CacheManagement); |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index fb5d99ba2..9ece415f7 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -32,7 +32,7 @@ public: | |||
| 32 | ~RasterizerOpenGL() override; | 32 | ~RasterizerOpenGL() override; |
| 33 | 33 | ||
| 34 | void DrawArrays() override; | 34 | void DrawArrays() override; |
| 35 | void NotifyMaxwellRegisterChanged(u32 id) override; | 35 | void NotifyMaxwellRegisterChanged(u32 method) override; |
| 36 | void FlushAll() override; | 36 | void FlushAll() override; |
| 37 | void FlushRegion(VAddr addr, u64 size) override; | 37 | void FlushRegion(VAddr addr, u64 size) override; |
| 38 | void InvalidateRegion(VAddr addr, u64 size) override; | 38 | void InvalidateRegion(VAddr addr, u64 size) override; |
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h index aa5026cce..a49265b38 100644 --- a/src/video_core/renderer_opengl/maxwell_to_gl.h +++ b/src/video_core/renderer_opengl/maxwell_to_gl.h | |||
| @@ -102,4 +102,68 @@ inline GLenum WrapMode(Tegra::Texture::WrapMode wrap_mode) { | |||
| 102 | return {}; | 102 | return {}; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | inline GLenum BlendEquation(Maxwell::Blend::Equation equation) { | ||
| 106 | switch (equation) { | ||
| 107 | case Maxwell::Blend::Equation::Add: | ||
| 108 | return GL_FUNC_ADD; | ||
| 109 | case Maxwell::Blend::Equation::Subtract: | ||
| 110 | return GL_FUNC_SUBTRACT; | ||
| 111 | case Maxwell::Blend::Equation::ReverseSubtract: | ||
| 112 | return GL_FUNC_REVERSE_SUBTRACT; | ||
| 113 | case Maxwell::Blend::Equation::Min: | ||
| 114 | return GL_MIN; | ||
| 115 | case Maxwell::Blend::Equation::Max: | ||
| 116 | return GL_MAX; | ||
| 117 | } | ||
| 118 | NGLOG_CRITICAL(Render_OpenGL, "Unimplemented blend equation={}", static_cast<u32>(equation)); | ||
| 119 | UNREACHABLE(); | ||
| 120 | return {}; | ||
| 121 | } | ||
| 122 | |||
| 123 | inline GLenum BlendFunc(Maxwell::Blend::Factor factor) { | ||
| 124 | switch (factor) { | ||
| 125 | case Maxwell::Blend::Factor::Zero: | ||
| 126 | return GL_ZERO; | ||
| 127 | case Maxwell::Blend::Factor::One: | ||
| 128 | return GL_ONE; | ||
| 129 | case Maxwell::Blend::Factor::SourceColor: | ||
| 130 | return GL_SRC_COLOR; | ||
| 131 | case Maxwell::Blend::Factor::OneMinusSourceColor: | ||
| 132 | return GL_ONE_MINUS_SRC_COLOR; | ||
| 133 | case Maxwell::Blend::Factor::SourceAlpha: | ||
| 134 | return GL_SRC_ALPHA; | ||
| 135 | case Maxwell::Blend::Factor::OneMinusSourceAlpha: | ||
| 136 | return GL_ONE_MINUS_SRC_ALPHA; | ||
| 137 | case Maxwell::Blend::Factor::DestAlpha: | ||
| 138 | return GL_DST_ALPHA; | ||
| 139 | case Maxwell::Blend::Factor::OneMinusDestAlpha: | ||
| 140 | return GL_ONE_MINUS_DST_ALPHA; | ||
| 141 | case Maxwell::Blend::Factor::DestColor: | ||
| 142 | return GL_DST_COLOR; | ||
| 143 | case Maxwell::Blend::Factor::OneMinusDestColor: | ||
| 144 | return GL_ONE_MINUS_DST_COLOR; | ||
| 145 | case Maxwell::Blend::Factor::SourceAlphaSaturate: | ||
| 146 | return GL_SRC_ALPHA_SATURATE; | ||
| 147 | case Maxwell::Blend::Factor::Source1Color: | ||
| 148 | return GL_SRC1_COLOR; | ||
| 149 | case Maxwell::Blend::Factor::OneMinusSource1Color: | ||
| 150 | return GL_ONE_MINUS_SRC1_COLOR; | ||
| 151 | case Maxwell::Blend::Factor::Source1Alpha: | ||
| 152 | return GL_SRC1_ALPHA; | ||
| 153 | case Maxwell::Blend::Factor::OneMinusSource1Alpha: | ||
| 154 | return GL_ONE_MINUS_SRC1_ALPHA; | ||
| 155 | case Maxwell::Blend::Factor::ConstantColor: | ||
| 156 | return GL_CONSTANT_COLOR; | ||
| 157 | case Maxwell::Blend::Factor::OneMinusConstantColor: | ||
| 158 | return GL_ONE_MINUS_CONSTANT_COLOR; | ||
| 159 | case Maxwell::Blend::Factor::ConstantAlpha: | ||
| 160 | return GL_CONSTANT_ALPHA; | ||
| 161 | case Maxwell::Blend::Factor::OneMinusConstantAlpha: | ||
| 162 | return GL_ONE_MINUS_CONSTANT_ALPHA; | ||
| 163 | } | ||
| 164 | NGLOG_CRITICAL(Render_OpenGL, "Unimplemented blend factor={}", static_cast<u32>(factor)); | ||
| 165 | UNREACHABLE(); | ||
| 166 | return {}; | ||
| 167 | } | ||
| 168 | |||
| 105 | } // namespace MaxwellToGL | 169 | } // namespace MaxwellToGL |