diff options
| author | 2016-12-16 23:21:26 -0800 | |
|---|---|---|
| committer | 2017-01-25 18:53:23 -0800 | |
| commit | dd4a1672a77830a53de61cf0554b34e9e17a2905 (patch) | |
| tree | 63b1b64e3858aca34c0828dbd9fec6f5ebc1f887 /src/video_core/shader/shader.cpp | |
| parent | VideoCore/Shader: Add constness to methods (diff) | |
| download | yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar.gz yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar.xz yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.zip | |
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.
Diffstat (limited to 'src/video_core/shader/shader.cpp')
| -rw-r--r-- | src/video_core/shader/shader.cpp | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp index ae696533f..d276a1221 100644 --- a/src/video_core/shader/shader.cpp +++ b/src/video_core/shader/shader.cpp | |||
| @@ -87,6 +87,17 @@ void UnitState::LoadInputVertex(const InputVertex& input, int num_attributes) { | |||
| 87 | conditional_code[1] = false; | 87 | conditional_code[1] = false; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | class MergedShaderEngine : public ShaderEngine { | ||
| 91 | public: | ||
| 92 | void SetupBatch(const ShaderSetup* setup) override; | ||
| 93 | void Run(UnitState& state, unsigned int entry_point) const override; | ||
| 94 | DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes, | ||
| 95 | unsigned int entry_point) const override; | ||
| 96 | |||
| 97 | private: | ||
| 98 | const ShaderSetup* setup = nullptr; | ||
| 99 | }; | ||
| 100 | |||
| 90 | #ifdef ARCHITECTURE_x86_64 | 101 | #ifdef ARCHITECTURE_x86_64 |
| 91 | static std::unordered_map<u64, std::unique_ptr<JitShader>> shader_map; | 102 | static std::unordered_map<u64, std::unique_ptr<JitShader>> shader_map; |
| 92 | static const JitShader* jit_shader; | 103 | static const JitShader* jit_shader; |
| @@ -98,13 +109,17 @@ void ClearCache() { | |||
| 98 | #endif // ARCHITECTURE_x86_64 | 109 | #endif // ARCHITECTURE_x86_64 |
| 99 | } | 110 | } |
| 100 | 111 | ||
| 101 | void ShaderSetup::Setup() { | 112 | void MergedShaderEngine::SetupBatch(const ShaderSetup* setup_) { |
| 113 | setup = setup_; | ||
| 114 | if (setup == nullptr) | ||
| 115 | return; | ||
| 116 | |||
| 102 | #ifdef ARCHITECTURE_x86_64 | 117 | #ifdef ARCHITECTURE_x86_64 |
| 103 | if (VideoCore::g_shader_jit_enabled) { | 118 | if (VideoCore::g_shader_jit_enabled) { |
| 104 | u64 cache_key = | 119 | u64 code_hash = Common::ComputeHash64(&setup->program_code, sizeof(setup->program_code)); |
| 105 | Common::ComputeHash64(&program_code, sizeof(program_code)) ^ | 120 | u64 swizzle_hash = Common::ComputeHash64(&setup->swizzle_data, sizeof(setup->swizzle_data)); |
| 106 | Common::ComputeHash64(&swizzle_data, sizeof(swizzle_data)); | ||
| 107 | 121 | ||
| 122 | u64 cache_key = code_hash ^ swizzle_hash; | ||
| 108 | auto iter = shader_map.find(cache_key); | 123 | auto iter = shader_map.find(cache_key); |
| 109 | if (iter != shader_map.end()) { | 124 | if (iter != shader_map.end()) { |
| 110 | jit_shader = iter->second.get(); | 125 | jit_shader = iter->second.get(); |
| @@ -120,26 +135,28 @@ void ShaderSetup::Setup() { | |||
| 120 | 135 | ||
| 121 | MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240)); | 136 | MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240)); |
| 122 | 137 | ||
| 123 | void ShaderSetup::Run(UnitState& state, unsigned int entry_point) const { | 138 | void MergedShaderEngine::Run(UnitState& state, unsigned int entry_point) const { |
| 139 | ASSERT(setup != nullptr); | ||
| 124 | ASSERT(entry_point < 1024); | 140 | ASSERT(entry_point < 1024); |
| 125 | 141 | ||
| 126 | MICROPROFILE_SCOPE(GPU_Shader); | 142 | MICROPROFILE_SCOPE(GPU_Shader); |
| 127 | 143 | ||
| 128 | #ifdef ARCHITECTURE_x86_64 | 144 | #ifdef ARCHITECTURE_x86_64 |
| 129 | if (VideoCore::g_shader_jit_enabled) { | 145 | if (VideoCore::g_shader_jit_enabled) { |
| 130 | jit_shader->Run(*this, state, entry_point); | 146 | jit_shader->Run(*setup, state, entry_point); |
| 131 | } else { | 147 | } else { |
| 132 | DebugData<false> dummy_debug_data; | 148 | DebugData<false> dummy_debug_data; |
| 133 | RunInterpreter(*this, state, dummy_debug_data, entry_point); | 149 | RunInterpreter(*setup, state, dummy_debug_data, entry_point); |
| 134 | } | 150 | } |
| 135 | #else | 151 | #else |
| 136 | DebugData<false> dummy_debug_data; | 152 | DebugData<false> dummy_debug_data; |
| 137 | RunInterpreter(*this, state, dummy_debug_data, entry_point); | 153 | RunInterpreter(*setup, state, dummy_debug_data, entry_point); |
| 138 | #endif // ARCHITECTURE_x86_64 | 154 | #endif // ARCHITECTURE_x86_64 |
| 139 | } | 155 | } |
| 140 | 156 | ||
| 141 | DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_attributes, | 157 | DebugData<true> MergedShaderEngine::ProduceDebugInfo(const InputVertex& input, int num_attributes, |
| 142 | unsigned int entry_point) const { | 158 | unsigned int entry_point) const { |
| 159 | ASSERT(setup != nullptr); | ||
| 143 | ASSERT(entry_point < 1024); | 160 | ASSERT(entry_point < 1024); |
| 144 | 161 | ||
| 145 | UnitState state; | 162 | UnitState state; |
| @@ -148,10 +165,15 @@ DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_ | |||
| 148 | // Setup input register table | 165 | // Setup input register table |
| 149 | boost::fill(state.registers.input, Math::Vec4<float24>::AssignToAll(float24::Zero())); | 166 | boost::fill(state.registers.input, Math::Vec4<float24>::AssignToAll(float24::Zero())); |
| 150 | state.LoadInputVertex(input, num_attributes); | 167 | state.LoadInputVertex(input, num_attributes); |
| 151 | RunInterpreter(*this, state, debug_data, entry_point); | 168 | RunInterpreter(*setup, state, debug_data, entry_point); |
| 152 | return debug_data; | 169 | return debug_data; |
| 153 | } | 170 | } |
| 154 | 171 | ||
| 172 | ShaderEngine* GetEngine() { | ||
| 173 | static MergedShaderEngine merged_engine; | ||
| 174 | return &merged_engine; | ||
| 175 | } | ||
| 176 | |||
| 155 | } // namespace Shader | 177 | } // namespace Shader |
| 156 | 178 | ||
| 157 | } // namespace Pica | 179 | } // namespace Pica |