Rewrite host GPU abstraction
- Don't have to repeat the same thing for 4 renderers. - Add native Metal renderer.
This commit is contained in:
@ -1,24 +1,28 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/rectangle.h"
|
||||
#include "core/types.h"
|
||||
#include "common/timer.h"
|
||||
#include "common/types.h"
|
||||
#include "gpu_device.h"
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace FrontendCommon {
|
||||
class GPUPipeline;
|
||||
class GPUTexture;
|
||||
|
||||
class PostProcessingChain;
|
||||
|
||||
class PostProcessingShader
|
||||
{
|
||||
public:
|
||||
enum : u32
|
||||
{
|
||||
PUSH_CONSTANT_SIZE_THRESHOLD = 128
|
||||
};
|
||||
friend PostProcessingChain;
|
||||
|
||||
public:
|
||||
struct Option
|
||||
{
|
||||
enum : u32
|
||||
@ -49,6 +53,8 @@ public:
|
||||
std::string dependent_option;
|
||||
Type type;
|
||||
u32 vector_size;
|
||||
u32 buffer_size;
|
||||
u32 buffer_offset;
|
||||
ValueVector default_value;
|
||||
ValueVector min_value;
|
||||
ValueVector max_value;
|
||||
@ -57,21 +63,15 @@ public:
|
||||
};
|
||||
|
||||
PostProcessingShader();
|
||||
PostProcessingShader(std::string name, std::string code);
|
||||
PostProcessingShader(const PostProcessingShader& copy);
|
||||
PostProcessingShader(PostProcessingShader& move);
|
||||
~PostProcessingShader();
|
||||
|
||||
PostProcessingShader& operator=(const PostProcessingShader& copy);
|
||||
PostProcessingShader& operator=(PostProcessingShader& move);
|
||||
PostProcessingShader(std::string name);
|
||||
virtual ~PostProcessingShader();
|
||||
|
||||
ALWAYS_INLINE const std::string& GetName() const { return m_name; }
|
||||
ALWAYS_INLINE const std::string& GetCode() const { return m_code; }
|
||||
ALWAYS_INLINE const std::vector<Option>& GetOptions() const { return m_options; }
|
||||
ALWAYS_INLINE std::vector<Option>& GetOptions() { return m_options; }
|
||||
ALWAYS_INLINE bool HasOptions() const { return !m_options.empty(); }
|
||||
|
||||
bool IsValid() const;
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
const Option* GetOptionByName(const std::string_view& name) const;
|
||||
Option* GetOptionByName(const std::string_view& name);
|
||||
@ -79,35 +79,21 @@ public:
|
||||
std::string GetConfigString() const;
|
||||
void SetConfigString(const std::string_view& str);
|
||||
|
||||
bool LoadFromFile(std::string name, const char* filename);
|
||||
bool LoadFromString(std::string name, std::string code);
|
||||
virtual bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height) = 0;
|
||||
|
||||
bool UsePushConstants() const;
|
||||
u32 GetUniformsSize() const;
|
||||
void FillUniformBuffer(void* buffer, u32 texture_width, s32 texture_height, s32 texture_view_x, s32 texture_view_y,
|
||||
s32 texture_view_width, s32 texture_view_height, u32 window_width, u32 window_height,
|
||||
s32 original_width, s32 original_height, float time) const;
|
||||
virtual bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height) = 0;
|
||||
|
||||
private:
|
||||
struct CommonUniforms
|
||||
{
|
||||
float src_rect[4];
|
||||
float src_size[2];
|
||||
float resolution[2];
|
||||
float rcp_resolution[2];
|
||||
float window_resolution[2];
|
||||
float rcp_window_resolution[2];
|
||||
float original_size[2];
|
||||
float padded_original_size[2];
|
||||
float time;
|
||||
float padding;
|
||||
};
|
||||
virtual bool Apply(GPUTexture* input, GPUFramebuffer* final_target, s32 final_left, s32 final_top, s32 final_width,
|
||||
s32 final_height, s32 orig_width, s32 orig_height, u32 target_width, u32 target_height) = 0;
|
||||
|
||||
void LoadOptions();
|
||||
protected:
|
||||
static void ParseKeyValue(const std::string_view& line, std::string_view* key, std::string_view* value);
|
||||
|
||||
template<typename T>
|
||||
static u32 ParseVector(const std::string_view& line, PostProcessingShader::Option::ValueVector* values);
|
||||
|
||||
std::string m_name;
|
||||
std::string m_code;
|
||||
std::vector<Option> m_options;
|
||||
};
|
||||
|
||||
} // namespace FrontendCommon
|
||||
Common::Timer m_timer;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user