summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader
diff options
context:
space:
mode:
authorYuri Kunde Schlesner <yuriks@yuriks.net>2016-12-17 08:21:26 +0100
committerYuri Kunde Schlesner <yuriks@yuriks.net>2017-01-26 03:53:23 +0100
commitdd4a1672a77830a53de61cf0554b34e9e17a2905 (patch)
tree63b1b64e3858aca34c0828dbd9fec6f5ebc1f887 /src/video_core/shader
parentVideoCore/Shader: Add constness to methods (diff)
downloadyuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar
yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar.gz
yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar.bz2
yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar.lz
yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar.xz
yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.tar.zst
yuzu-dd4a1672a77830a53de61cf0554b34e9e17a2905.zip
Diffstat (limited to 'src/video_core/shader')
-rw-r--r--src/video_core/shader/shader.cpp44
-rw-r--r--src/video_core/shader/shader.h17
-rw-r--r--src/video_core/shader/shader_interpreter.h1
3 files changed, 46 insertions, 16 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) {
conditional_code[1] = false;
}
+class MergedShaderEngine : public ShaderEngine {
+public:
+ void SetupBatch(const ShaderSetup* setup) override;
+ void Run(UnitState& state, unsigned int entry_point) const override;
+ DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes,
+ unsigned int entry_point) const override;
+
+private:
+ const ShaderSetup* setup = nullptr;
+};
+
#ifdef ARCHITECTURE_x86_64
static std::unordered_map<u64, std::unique_ptr<JitShader>> shader_map;
static const JitShader* jit_shader;
@@ -98,13 +109,17 @@ void ClearCache() {
#endif // ARCHITECTURE_x86_64
}
-void ShaderSetup::Setup() {
+void MergedShaderEngine::SetupBatch(const ShaderSetup* setup_) {
+ setup = setup_;
+ if (setup == nullptr)
+ return;
+
#ifdef ARCHITECTURE_x86_64
if (VideoCore::g_shader_jit_enabled) {
- u64 cache_key =
- Common::ComputeHash64(&program_code, sizeof(program_code)) ^
- Common::ComputeHash64(&swizzle_data, sizeof(swizzle_data));
+ u64 code_hash = Common::ComputeHash64(&setup->program_code, sizeof(setup->program_code));
+ u64 swizzle_hash = Common::ComputeHash64(&setup->swizzle_data, sizeof(setup->swizzle_data));
+ u64 cache_key = code_hash ^ swizzle_hash;
auto iter = shader_map.find(cache_key);
if (iter != shader_map.end()) {
jit_shader = iter->second.get();
@@ -120,26 +135,28 @@ void ShaderSetup::Setup() {
MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240));
-void ShaderSetup::Run(UnitState& state, unsigned int entry_point) const {
+void MergedShaderEngine::Run(UnitState& state, unsigned int entry_point) const {
+ ASSERT(setup != nullptr);
ASSERT(entry_point < 1024);
MICROPROFILE_SCOPE(GPU_Shader);
#ifdef ARCHITECTURE_x86_64
if (VideoCore::g_shader_jit_enabled) {
- jit_shader->Run(*this, state, entry_point);
+ jit_shader->Run(*setup, state, entry_point);
} else {
DebugData<false> dummy_debug_data;
- RunInterpreter(*this, state, dummy_debug_data, entry_point);
+ RunInterpreter(*setup, state, dummy_debug_data, entry_point);
}
#else
DebugData<false> dummy_debug_data;
- RunInterpreter(*this, state, dummy_debug_data, entry_point);
+ RunInterpreter(*setup, state, dummy_debug_data, entry_point);
#endif // ARCHITECTURE_x86_64
}
-DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_attributes,
- unsigned int entry_point) const {
+DebugData<true> MergedShaderEngine::ProduceDebugInfo(const InputVertex& input, int num_attributes,
+ unsigned int entry_point) const {
+ ASSERT(setup != nullptr);
ASSERT(entry_point < 1024);
UnitState state;
@@ -148,10 +165,15 @@ DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_
// Setup input register table
boost::fill(state.registers.input, Math::Vec4<float24>::AssignToAll(float24::Zero()));
state.LoadInputVertex(input, num_attributes);
- RunInterpreter(*this, state, debug_data, entry_point);
+ RunInterpreter(*setup, state, debug_data, entry_point);
return debug_data;
}
+ShaderEngine* GetEngine() {
+ static MergedShaderEngine merged_engine;
+ return &merged_engine;
+}
+
} // namespace Shader
} // namespace Pica
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<u32, 1024> program_code;
std::array<u32, 1024> 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<true> ProduceDebugInfo(const InputVertex& input, int num_attributes,
- unsigned int entry_point) const;
+ virtual DebugData<true> 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
diff --git a/src/video_core/shader/shader_interpreter.h b/src/video_core/shader/shader_interpreter.h
index d31dcd7a6..3237b50b3 100644
--- a/src/video_core/shader/shader_interpreter.h
+++ b/src/video_core/shader/shader_interpreter.h
@@ -8,6 +8,7 @@ namespace Pica {
namespace Shader {
+struct ShaderSetup;
struct UnitState;
template <bool Debug>