From 34d581f2dcffa9f54e96af230a56cb01e8e2fccd Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 16 Dec 2016 21:41:38 -0800 Subject: VideoCore/Shader: Extract input vertex loading code into function --- src/video_core/shader/shader.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 2b07759b9..c5d23e0ea 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -142,6 +142,14 @@ struct UnitState { return 0; } } + + /** + * Loads the unit state with an input vertex. + * + * @param input Input vertex into the shader + * @param num_attributes The number of vertex shader attributes to load + */ + void LoadInputVertex(const InputVertex& input, int num_attributes); }; /// Clears the shader cache @@ -182,10 +190,8 @@ struct ShaderSetup { /** * Runs the currently setup shader * @param state Shader unit state, must be setup per shader and per shader unit - * @param input Input vertex into the shader - * @param num_attributes The number of vertex shader attributes */ - void Run(UnitState& state, const InputVertex& input, int num_attributes); + void Run(UnitState& state); /** * Produce debug information based on the given shader and input vertex -- cgit v1.2.3 From e3caf669b05bc0727053885ee7e6e5c78d655df4 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 16 Dec 2016 21:48:36 -0800 Subject: VideoCore/Shader: Use self instead of g_state.vs in ShaderSetup --- src/video_core/shader/shader.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index c5d23e0ea..61becb6e5 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -198,11 +198,10 @@ struct ShaderSetup { * @param input Input vertex into the shader * @param num_attributes The number of vertex shader attributes * @param config Configuration object for the shader pipeline - * @param setup Setup object for the shader pipeline * @return Debug information for this shader with regards to the given vertex */ DebugData ProduceDebugInfo(const InputVertex& input, int num_attributes, - const Regs::ShaderConfig& config, const ShaderSetup& setup); + const Regs::ShaderConfig& config); }; } // namespace Shader -- cgit v1.2.3 From 1e1f9398176e4f1ec608f31f22a576c749a0a723 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 16 Dec 2016 22:30:00 -0800 Subject: VideoCore/Shader: Use only entry_point as ShaderSetup param This removes all implicit dependency of ShaderState on global PICA state. --- src/video_core/shader/shader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 61becb6e5..d21f481ab 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -191,7 +191,7 @@ struct ShaderSetup { * Runs the currently setup shader * @param state Shader unit state, must be setup per shader and per shader unit */ - void Run(UnitState& state); + void Run(UnitState& state, unsigned int entry_point); /** * Produce debug information based on the given shader and input vertex @@ -201,7 +201,7 @@ struct ShaderSetup { * @return Debug information for this shader with regards to the given vertex */ DebugData ProduceDebugInfo(const InputVertex& input, int num_attributes, - const Regs::ShaderConfig& config); + unsigned int entry_point); }; } // namespace Shader -- cgit v1.2.3 From bd82cffd0bf5d61eab8c7c856bcc284b1a77e33b Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 16 Dec 2016 22:32:35 -0800 Subject: VideoCore/Shader: Add constness to methods --- src/video_core/shader/shader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index d21f481ab..44b9861e9 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -191,7 +191,7 @@ struct ShaderSetup { * Runs the currently setup shader * @param state Shader unit state, must be setup per shader and per shader unit */ - void Run(UnitState& state, unsigned int entry_point); + void Run(UnitState& state, unsigned int entry_point) const; /** * Produce debug information based on the given shader and input vertex @@ -201,7 +201,7 @@ struct ShaderSetup { * @return Debug information for this shader with regards to the given vertex */ DebugData ProduceDebugInfo(const InputVertex& input, int num_attributes, - unsigned int entry_point); + unsigned int entry_point) const; }; } // namespace Shader -- cgit v1.2.3 From dd4a1672a77830a53de61cf0554b34e9e17a2905 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 16 Dec 2016 23:21:26 -0800 Subject: VideoCore/Shader: Split shader uniform state and shader engine Currently there's only a single dummy implementation, which will be split in a following commit. --- src/video_core/shader/shader.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 44b9861e9..899fb2607 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -156,7 +156,6 @@ struct UnitState { void ClearCache(); struct ShaderSetup { - struct { // The float uniforms are accessed by the shader JIT using SSE instructions, and are // therefore required to be 16-byte aligned. @@ -180,18 +179,23 @@ struct ShaderSetup { std::array program_code; std::array swizzle_data; +}; + +class ShaderEngine { +public: + virtual ~ShaderEngine() = default; /** * Performs any shader unit setup that only needs to happen once per shader (as opposed to once * per vertex, which would happen within the `Run` function). */ - void Setup(); + virtual void SetupBatch(const ShaderSetup* setup) = 0; /** * Runs the currently setup shader * @param state Shader unit state, must be setup per shader and per shader unit */ - void Run(UnitState& state, unsigned int entry_point) const; + virtual void Run(UnitState& state, unsigned int entry_point) const = 0; /** * Produce debug information based on the given shader and input vertex @@ -200,10 +204,13 @@ struct ShaderSetup { * @param config Configuration object for the shader pipeline * @return Debug information for this shader with regards to the given vertex */ - DebugData ProduceDebugInfo(const InputVertex& input, int num_attributes, - unsigned int entry_point) const; + virtual DebugData ProduceDebugInfo(const InputVertex& input, int num_attributes, + unsigned int entry_point) const = 0; }; +// TODO(yuriks): Remove and make it non-global state somewhere +ShaderEngine* GetEngine(); + } // namespace Shader } // namespace Pica -- cgit v1.2.3 From 114d6b2f97eb62c7d8c958ebb391b70b026130f9 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 01:21:16 -0800 Subject: VideoCore/Shader: Split interpreter and JIT into separate ShaderEngines --- src/video_core/shader/shader.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 899fb2607..2afd1024f 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include "common/assert.h" @@ -152,9 +151,6 @@ struct UnitState { void LoadInputVertex(const InputVertex& input, int num_attributes); }; -/// Clears the shader cache -void ClearCache(); - struct ShaderSetup { struct { // The float uniforms are accessed by the shader JIT using SSE instructions, and are @@ -210,6 +206,7 @@ public: // TODO(yuriks): Remove and make it non-global state somewhere ShaderEngine* GetEngine(); +void Shutdown(); } // namespace Shader -- cgit v1.2.3 From ade7ed7c5fd383e77c4d6949e652e1fd83844233 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 01:30:55 -0800 Subject: VideoCore/Shader: Move ProduceDebugInfo to InterpreterEngine --- src/video_core/shader/shader.h | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 2afd1024f..9d2410487 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -14,7 +14,6 @@ #include "common/vector_math.h" #include "video_core/pica.h" #include "video_core/pica_types.h" -#include "video_core/shader/debug_data.h" using nihstro::RegisterType; using nihstro::SourceRegister; @@ -192,16 +191,6 @@ public: * @param state Shader unit state, must be setup per shader and per shader unit */ virtual void Run(UnitState& state, unsigned int entry_point) const = 0; - - /** - * Produce debug information based on the given shader and input vertex - * @param input Input vertex into the shader - * @param num_attributes The number of vertex shader attributes - * @param config Configuration object for the shader pipeline - * @return Debug information for this shader with regards to the given vertex - */ - virtual DebugData ProduceDebugInfo(const InputVertex& input, int num_attributes, - unsigned int entry_point) const = 0; }; // TODO(yuriks): Remove and make it non-global state somewhere -- cgit v1.2.3 From 6fa3687afc97685101f9ee5c65cf98f505980695 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 14:38:03 -0800 Subject: Shader: Remove OutputRegisters struct --- src/video_core/shader/shader.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 9d2410487..7d51d0044 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -73,19 +73,13 @@ struct OutputVertex { ret.Lerp(factor, v1); return ret; } + + static OutputVertex FromRegisters(Math::Vec4 output_regs[16], const Regs& regs, + u32 output_mask); }; static_assert(std::is_pod::value, "Structure is not POD"); static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size"); -struct OutputRegisters { - OutputRegisters() = default; - - alignas(16) Math::Vec4 value[16]; - - OutputVertex ToVertex(const Regs::ShaderConfig& config) const; -}; -static_assert(std::is_pod::value, "Structure is not POD"); - /** * This structure contains the state information that needs to be unique for a shader unit. The 3DS * has four shader units that process shaders in parallel. At the present, Citra only implements a @@ -98,11 +92,10 @@ struct UnitState { // required to be 16-byte aligned. alignas(16) Math::Vec4 input[16]; alignas(16) Math::Vec4 temporary[16]; + alignas(16) Math::Vec4 output[16]; } registers; static_assert(std::is_pod::value, "Structure is not POD"); - OutputRegisters output_registers; - bool conditional_code[2]; // Two Address registers and one loop counter @@ -128,7 +121,7 @@ struct UnitState { static size_t OutputOffset(const DestRegister& reg) { switch (reg.GetRegisterType()) { case RegisterType::Output: - return offsetof(UnitState, output_registers.value) + + return offsetof(UnitState, registers.output) + reg.GetIndex() * sizeof(Math::Vec4); case RegisterType::Temporary: -- cgit v1.2.3 From 0f642741451e3f75c2f1d64ae9beccaf1437f12c Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 16:06:04 -0800 Subject: VideoCore/Shader: Move per-batch ShaderEngine state into ShaderSetup --- src/video_core/shader/shader.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 7d51d0044..f26d2ba4f 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -167,6 +167,12 @@ struct ShaderSetup { std::array program_code; std::array swizzle_data; + + /// Data private to ShaderEngines + struct EngineData { + /// Used by the JIT, points to a compiled shader object. + const void* cached_shader = nullptr; + } engine_data; }; class ShaderEngine { @@ -177,13 +183,16 @@ public: * Performs any shader unit setup that only needs to happen once per shader (as opposed to once * per vertex, which would happen within the `Run` function). */ - virtual void SetupBatch(const ShaderSetup* setup) = 0; + virtual void SetupBatch(ShaderSetup& setup) = 0; /** - * Runs the currently setup shader - * @param state Shader unit state, must be setup per shader and per shader unit + * Runs the currently setup shader. + * + * @param setup Shader engine state, must be setup with SetupBatch on each shader change. + * @param state Shader unit state, must be setup with input data before each shader invocation. */ - virtual void Run(UnitState& state, unsigned int entry_point) const = 0; + virtual void Run(const ShaderSetup& setup, UnitState& state, + unsigned int entry_point) const = 0; }; // TODO(yuriks): Remove and make it non-global state somewhere -- cgit v1.2.3 From 0e9081b97348c65029c96697443acb0dbbc58756 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 16:16:02 -0800 Subject: VideoCore/Shader: Move entry_point to SetupBatch --- src/video_core/shader/shader.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/video_core/shader/shader.h') diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index f26d2ba4f..44d9f76c3 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -170,6 +170,7 @@ struct ShaderSetup { /// Data private to ShaderEngines struct EngineData { + unsigned int entry_point; /// Used by the JIT, points to a compiled shader object. const void* cached_shader = nullptr; } engine_data; @@ -183,7 +184,7 @@ public: * Performs any shader unit setup that only needs to happen once per shader (as opposed to once * per vertex, which would happen within the `Run` function). */ - virtual void SetupBatch(ShaderSetup& setup) = 0; + virtual void SetupBatch(ShaderSetup& setup, unsigned int entry_point) = 0; /** * Runs the currently setup shader. @@ -191,8 +192,7 @@ public: * @param setup Shader engine state, must be setup with SetupBatch on each shader change. * @param state Shader unit state, must be setup with input data before each shader invocation. */ - virtual void Run(const ShaderSetup& setup, UnitState& state, - unsigned int entry_point) const = 0; + virtual void Run(const ShaderSetup& setup, UnitState& state) const = 0; }; // TODO(yuriks): Remove and make it non-global state somewhere -- cgit v1.2.3