diff options
| author | 2016-03-30 02:45:18 +0200 | |
|---|---|---|
| committer | 2016-05-11 23:48:24 +0200 | |
| commit | ae7a82fa1c65b4efc9e7bf9863fa229778a72d1c (patch) | |
| tree | 5a2da227058d4f22b3e3e0d21a1f13a02f7e5e37 /src | |
| parent | Merge pull request #1621 from JayFoxRox/w-buffer (diff) | |
| download | yuzu-ae7a82fa1c65b4efc9e7bf9863fa229778a72d1c.tar.gz yuzu-ae7a82fa1c65b4efc9e7bf9863fa229778a72d1c.tar.xz yuzu-ae7a82fa1c65b4efc9e7bf9863fa229778a72d1c.zip | |
Turn ShaderSetup into struct
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra_qt/debugger/graphics_vertex_shader.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/command_processor.cpp | 8 | ||||
| -rw-r--r-- | src/video_core/pica.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/shader/shader.cpp | 22 | ||||
| -rw-r--r-- | src/video_core/shader/shader.h | 83 |
5 files changed, 59 insertions, 58 deletions
diff --git a/src/citra_qt/debugger/graphics_vertex_shader.cpp b/src/citra_qt/debugger/graphics_vertex_shader.cpp index 854f6ff16..391666d35 100644 --- a/src/citra_qt/debugger/graphics_vertex_shader.cpp +++ b/src/citra_qt/debugger/graphics_vertex_shader.cpp | |||
| @@ -501,7 +501,7 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d | |||
| 501 | info.labels.insert({ entry_point, "main" }); | 501 | info.labels.insert({ entry_point, "main" }); |
| 502 | 502 | ||
| 503 | // Generate debug information | 503 | // Generate debug information |
| 504 | debug_data = Pica::Shader::ProduceDebugInfo(input_vertex, num_attributes, shader_config, shader_setup); | 504 | debug_data = Pica::g_state.vs.ProduceDebugInfo(input_vertex, num_attributes, shader_config, shader_setup); |
| 505 | 505 | ||
| 506 | // Reload widget state | 506 | // Reload widget state |
| 507 | for (int attr = 0; attr < num_attributes; ++attr) { | 507 | for (int attr = 0; attr < num_attributes; ++attr) { |
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index dd1379503..e7dc5ddac 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp | |||
| @@ -144,12 +144,12 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { | |||
| 144 | immediate_attribute_id = 0; | 144 | immediate_attribute_id = 0; |
| 145 | 145 | ||
| 146 | Shader::UnitState<false> shader_unit; | 146 | Shader::UnitState<false> shader_unit; |
| 147 | Shader::Setup(); | 147 | g_state.vs.Setup(); |
| 148 | 148 | ||
| 149 | // Send to vertex shader | 149 | // Send to vertex shader |
| 150 | if (g_debug_context) | 150 | if (g_debug_context) |
| 151 | g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, static_cast<void*>(&immediate_input)); | 151 | g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, static_cast<void*>(&immediate_input)); |
| 152 | Shader::OutputVertex output = Shader::Run(shader_unit, immediate_input, regs.vs.num_input_attributes+1); | 152 | Shader::OutputVertex output = g_state.vs.Run(shader_unit, immediate_input, regs.vs.num_input_attributes+1); |
| 153 | 153 | ||
| 154 | // Send to renderer | 154 | // Send to renderer |
| 155 | using Pica::Shader::OutputVertex; | 155 | using Pica::Shader::OutputVertex; |
| @@ -237,7 +237,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { | |||
| 237 | vertex_cache_ids.fill(-1); | 237 | vertex_cache_ids.fill(-1); |
| 238 | 238 | ||
| 239 | Shader::UnitState<false> shader_unit; | 239 | Shader::UnitState<false> shader_unit; |
| 240 | Shader::Setup(); | 240 | g_state.vs.Setup(); |
| 241 | 241 | ||
| 242 | for (unsigned int index = 0; index < regs.num_vertices; ++index) | 242 | for (unsigned int index = 0; index < regs.num_vertices; ++index) |
| 243 | { | 243 | { |
| @@ -274,7 +274,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { | |||
| 274 | // Send to vertex shader | 274 | // Send to vertex shader |
| 275 | if (g_debug_context) | 275 | if (g_debug_context) |
| 276 | g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, (void*)&input); | 276 | g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, (void*)&input); |
| 277 | output = Shader::Run(shader_unit, input, loader.GetNumTotalAttributes()); | 277 | output = g_state.vs.Run(shader_unit, input, loader.GetNumTotalAttributes()); |
| 278 | 278 | ||
| 279 | if (is_indexed) { | 279 | if (is_indexed) { |
| 280 | vertex_cache[vertex_cache_pos] = output; | 280 | vertex_cache[vertex_cache_pos] = output; |
diff --git a/src/video_core/pica.cpp b/src/video_core/pica.cpp index be82cf4b5..ec78f9593 100644 --- a/src/video_core/pica.cpp +++ b/src/video_core/pica.cpp | |||
| @@ -500,7 +500,7 @@ void Init() { | |||
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | void Shutdown() { | 502 | void Shutdown() { |
| 503 | Shader::Shutdown(); | 503 | Shader::ClearCache(); |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | template <typename T> | 506 | template <typename T> |
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp index 65dcc9156..449fc703f 100644 --- a/src/video_core/shader/shader.cpp +++ b/src/video_core/shader/shader.cpp | |||
| @@ -35,7 +35,13 @@ static std::unordered_map<u64, std::unique_ptr<JitShader>> shader_map; | |||
| 35 | static const JitShader* jit_shader; | 35 | static const JitShader* jit_shader; |
| 36 | #endif // ARCHITECTURE_x86_64 | 36 | #endif // ARCHITECTURE_x86_64 |
| 37 | 37 | ||
| 38 | void Setup() { | 38 | void ClearCache() { |
| 39 | #ifdef ARCHITECTURE_x86_64 | ||
| 40 | shader_map.clear(); | ||
| 41 | #endif // ARCHITECTURE_x86_64 | ||
| 42 | } | ||
| 43 | |||
| 44 | void ShaderSetup::Setup() { | ||
| 39 | #ifdef ARCHITECTURE_x86_64 | 45 | #ifdef ARCHITECTURE_x86_64 |
| 40 | if (VideoCore::g_shader_jit_enabled) { | 46 | if (VideoCore::g_shader_jit_enabled) { |
| 41 | u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^ | 47 | u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^ |
| @@ -54,18 +60,12 @@ void Setup() { | |||
| 54 | #endif // ARCHITECTURE_x86_64 | 60 | #endif // ARCHITECTURE_x86_64 |
| 55 | } | 61 | } |
| 56 | 62 | ||
| 57 | void Shutdown() { | 63 | MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240)); |
| 58 | #ifdef ARCHITECTURE_x86_64 | ||
| 59 | shader_map.clear(); | ||
| 60 | #endif // ARCHITECTURE_x86_64 | ||
| 61 | } | ||
| 62 | |||
| 63 | MICROPROFILE_DEFINE(GPU_VertexShader, "GPU", "Vertex Shader", MP_RGB(50, 50, 240)); | ||
| 64 | 64 | ||
| 65 | OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attributes) { | 65 | OutputVertex ShaderSetup::Run(UnitState<false>& state, const InputVertex& input, int num_attributes) { |
| 66 | auto& config = g_state.regs.vs; | 66 | auto& config = g_state.regs.vs; |
| 67 | 67 | ||
| 68 | MICROPROFILE_SCOPE(GPU_VertexShader); | 68 | MICROPROFILE_SCOPE(GPU_Shader); |
| 69 | 69 | ||
| 70 | state.program_counter = config.main_offset; | 70 | state.program_counter = config.main_offset; |
| 71 | state.debug.max_offset = 0; | 71 | state.debug.max_offset = 0; |
| @@ -140,7 +140,7 @@ OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attr | |||
| 140 | return ret; | 140 | return ret; |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup) { | 143 | DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup) { |
| 144 | UnitState<true> state; | 144 | UnitState<true> state; |
| 145 | 145 | ||
| 146 | state.program_counter = config.main_offset; | 146 | state.program_counter = config.main_offset; |
diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 56b83bfeb..cfbb7f2ee 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h | |||
| @@ -83,23 +83,6 @@ struct OutputVertex { | |||
| 83 | static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD"); | 83 | static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD"); |
| 84 | static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size"); | 84 | static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size"); |
| 85 | 85 | ||
| 86 | /// Vertex shader memory | ||
| 87 | struct ShaderSetup { | ||
| 88 | struct { | ||
| 89 | // The float uniforms are accessed by the shader JIT using SSE instructions, and are | ||
| 90 | // therefore required to be 16-byte aligned. | ||
| 91 | alignas(16) Math::Vec4<float24> f[96]; | ||
| 92 | |||
| 93 | std::array<bool, 16> b; | ||
| 94 | std::array<Math::Vec4<u8>, 4> i; | ||
| 95 | } uniforms; | ||
| 96 | |||
| 97 | Math::Vec4<float24> default_attributes[16]; | ||
| 98 | |||
| 99 | std::array<u32, 1024> program_code; | ||
| 100 | std::array<u32, 1024> swizzle_data; | ||
| 101 | }; | ||
| 102 | |||
| 103 | // Helper structure used to keep track of data useful for inspection of shader emulation | 86 | // Helper structure used to keep track of data useful for inspection of shader emulation |
| 104 | template<bool full_debugging> | 87 | template<bool full_debugging> |
| 105 | struct DebugData; | 88 | struct DebugData; |
| @@ -342,33 +325,51 @@ struct UnitState { | |||
| 342 | } | 325 | } |
| 343 | }; | 326 | }; |
| 344 | 327 | ||
| 345 | /** | 328 | /// Clears the shader cache |
| 346 | * Performs any shader unit setup that only needs to happen once per shader (as opposed to once per | 329 | void ClearCache(); |
| 347 | * vertex, which would happen within the `Run` function). | 330 | |
| 348 | */ | 331 | struct ShaderSetup { |
| 349 | void Setup(); | ||
| 350 | 332 | ||
| 351 | /// Performs any cleanup when the emulator is shutdown | 333 | struct { |
| 352 | void Shutdown(); | 334 | // The float uniforms are accessed by the shader JIT using SSE instructions, and are |
| 335 | // therefore required to be 16-byte aligned. | ||
| 336 | alignas(16) Math::Vec4<float24> f[96]; | ||
| 353 | 337 | ||
| 354 | /** | 338 | std::array<bool, 16> b; |
| 355 | * Runs the currently setup shader | 339 | std::array<Math::Vec4<u8>, 4> i; |
| 356 | * @param state Shader unit state, must be setup per shader and per shader unit | 340 | } uniforms; |
| 357 | * @param input Input vertex into the shader | ||
| 358 | * @param num_attributes The number of vertex shader attributes | ||
| 359 | * @return The output vertex, after having been processed by the vertex shader | ||
| 360 | */ | ||
| 361 | OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attributes); | ||
| 362 | 341 | ||
| 363 | /** | 342 | Math::Vec4<float24> default_attributes[16]; |
| 364 | * Produce debug information based on the given shader and input vertex | 343 | |
| 365 | * @param input Input vertex into the shader | 344 | std::array<u32, 1024> program_code; |
| 366 | * @param num_attributes The number of vertex shader attributes | 345 | std::array<u32, 1024> swizzle_data; |
| 367 | * @param config Configuration object for the shader pipeline | 346 | |
| 368 | * @param setup Setup object for the shader pipeline | 347 | /** |
| 369 | * @return Debug information for this shader with regards to the given vertex | 348 | * Performs any shader unit setup that only needs to happen once per shader (as opposed to once per |
| 370 | */ | 349 | * vertex, which would happen within the `Run` function). |
| 371 | DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup); | 350 | */ |
| 351 | void Setup(); | ||
| 352 | |||
| 353 | /** | ||
| 354 | * Runs the currently setup shader | ||
| 355 | * @param state Shader unit state, must be setup per shader and per shader unit | ||
| 356 | * @param input Input vertex into the shader | ||
| 357 | * @param num_attributes The number of vertex shader attributes | ||
| 358 | * @return The output vertex, after having been processed by the vertex shader | ||
| 359 | */ | ||
| 360 | OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attributes); | ||
| 361 | |||
| 362 | /** | ||
| 363 | * Produce debug information based on the given shader and input vertex | ||
| 364 | * @param input Input vertex into the shader | ||
| 365 | * @param num_attributes The number of vertex shader attributes | ||
| 366 | * @param config Configuration object for the shader pipeline | ||
| 367 | * @param setup Setup object for the shader pipeline | ||
| 368 | * @return Debug information for this shader with regards to the given vertex | ||
| 369 | */ | ||
| 370 | DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup); | ||
| 371 | |||
| 372 | }; | ||
| 372 | 373 | ||
| 373 | } // namespace Shader | 374 | } // namespace Shader |
| 374 | 375 | ||