From a286b61f75f1b166c34079e6b8f85688bd522ca3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 29 Apr 2016 10:57:06 -0400 Subject: [PATCH 1/6] vertex_loader: Correct header ordering --- src/video_core/vertex_loader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/vertex_loader.cpp b/src/video_core/vertex_loader.cpp index 21ae52949..ce1c8da59 100644 --- a/src/video_core/vertex_loader.cpp +++ b/src/video_core/vertex_loader.cpp @@ -2,8 +2,8 @@ #include -#include "common/assert.h" #include "common/alignment.h" +#include "common/assert.h" #include "common/bit_field.h" #include "common/common_types.h" #include "common/logging/log.h" From 8ea5e7dfb57ebda2ad2229e4e94dfd5e2c24c091 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 29 Apr 2016 11:06:03 -0400 Subject: [PATCH 2/6] vertex_loader: Use std::array instead of raw C arrays --- src/video_core/vertex_loader.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/video_core/vertex_loader.h b/src/video_core/vertex_loader.h index becf5a403..3b511945a 100644 --- a/src/video_core/vertex_loader.h +++ b/src/video_core/vertex_loader.h @@ -1,7 +1,8 @@ #pragma once -#include "common/common_types.h" +#include +#include "common/common_types.h" #include "video_core/pica.h" namespace Pica { @@ -22,11 +23,11 @@ public: int GetNumTotalAttributes() const { return num_total_attributes; } private: - u32 vertex_attribute_sources[16]; - u32 vertex_attribute_strides[16] = {}; - Regs::VertexAttributeFormat vertex_attribute_formats[16] = {}; - u32 vertex_attribute_elements[16] = {}; - bool vertex_attribute_is_default[16]; + std::array vertex_attribute_sources; + std::array vertex_attribute_strides{}; + std::array vertex_attribute_formats; + std::array vertex_attribute_elements{}; + std::array vertex_attribute_is_default; int num_total_attributes; }; From 769f4a7018e170448f7f1c307f2bcfa26f59ecba Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 29 Apr 2016 11:16:52 -0400 Subject: [PATCH 3/6] vertex_loader: initialize_num_total_attributes. Keeps the public API sane. --- src/video_core/vertex_loader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/vertex_loader.h b/src/video_core/vertex_loader.h index 3b511945a..4ed8cd3fd 100644 --- a/src/video_core/vertex_loader.h +++ b/src/video_core/vertex_loader.h @@ -28,7 +28,7 @@ private: std::array vertex_attribute_formats; std::array vertex_attribute_elements{}; std::array vertex_attribute_is_default; - int num_total_attributes; + int num_total_attributes = 0; }; } // namespace Pica From 1357724cd946f3a9f31dbe3ace55a9588f3c6f2f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 29 Apr 2016 11:23:40 -0400 Subject: [PATCH 4/6] vertex_loader: Add constructors to facilitate immediate and two-step initialization --- src/video_core/command_processor.cpp | 3 +-- src/video_core/vertex_loader.h | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index dd1379503..941c5af9f 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -199,9 +199,8 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { // Processes information about internal vertex attributes to figure out how a vertex is loaded. // Later, these can be compiled and cached. - VertexLoader loader; const u32 base_address = regs.vertex_attributes.GetPhysicalBaseAddress(); - loader.Setup(regs); + VertexLoader loader(regs); // Load vertices bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed)); diff --git a/src/video_core/vertex_loader.h b/src/video_core/vertex_loader.h index 4ed8cd3fd..2a97b97c8 100644 --- a/src/video_core/vertex_loader.h +++ b/src/video_core/vertex_loader.h @@ -17,6 +17,11 @@ class InputVertex; class VertexLoader { public: + VertexLoader() = default; + explicit VertexLoader(const Pica::Regs& regs) { + Setup(regs); + } + void Setup(const Pica::Regs& regs); void LoadVertex(u32 base_address, int index, int vertex, Shader::InputVertex& input, DebugUtils::MemoryAccessTracker& memory_accesses); From 5587383eb72b02af79526d6fe5e662b281b4b32b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 29 Apr 2016 11:27:15 -0400 Subject: [PATCH 5/6] vertex_loader: Provide an assertion for ensuring the loader has been setup Also adds an assert to ensure that Setup is not called more than once during a VertexLoader's lifetime. --- src/video_core/vertex_loader.cpp | 6 ++++++ src/video_core/vertex_loader.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/video_core/vertex_loader.cpp b/src/video_core/vertex_loader.cpp index ce1c8da59..18a7cf144 100644 --- a/src/video_core/vertex_loader.cpp +++ b/src/video_core/vertex_loader.cpp @@ -21,6 +21,8 @@ namespace Pica { void VertexLoader::Setup(const Pica::Regs& regs) { + ASSERT_MSG(!is_setup, "VertexLoader is not intended to be setup more than once."); + const auto& attribute_config = regs.vertex_attributes; num_total_attributes = attribute_config.GetNumTotalAttributes(); @@ -60,9 +62,13 @@ void VertexLoader::Setup(const Pica::Regs& regs) { } } } + + is_setup = true; } void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, Shader::InputVertex& input, DebugUtils::MemoryAccessTracker& memory_accesses) { + ASSERT_MSG(is_setup, "A VertexLoader needs to be setup before loading vertices."); + for (int i = 0; i < num_total_attributes; ++i) { if (vertex_attribute_elements[i] != 0) { // Load per-vertex data from the loader arrays diff --git a/src/video_core/vertex_loader.h b/src/video_core/vertex_loader.h index 2a97b97c8..7192120a5 100644 --- a/src/video_core/vertex_loader.h +++ b/src/video_core/vertex_loader.h @@ -34,6 +34,7 @@ private: std::array vertex_attribute_elements{}; std::array vertex_attribute_is_default; int num_total_attributes = 0; + bool is_setup = false; }; } // namespace Pica From 6d5f2a3cff519ca2811033d8381fac2515a74af8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 May 2016 23:04:42 -0400 Subject: [PATCH 6/6] vertex_loader: Correct forward declaration of InputVertex It's actually a struct, not a class. --- src/video_core/vertex_loader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/vertex_loader.h b/src/video_core/vertex_loader.h index 7192120a5..ac162c254 100644 --- a/src/video_core/vertex_loader.h +++ b/src/video_core/vertex_loader.h @@ -12,7 +12,7 @@ class MemoryAccessTracker; } namespace Shader { -class InputVertex; +struct InputVertex; } class VertexLoader {