diff options
Diffstat (limited to 'src/video_core/shader')
| -rw-r--r-- | src/video_core/shader/shader.cpp | 22 | ||||
| -rw-r--r-- | src/video_core/shader/shader.h | 83 |
2 files changed, 53 insertions, 52 deletions
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 | ||