mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
VideoBackends: Add AbstractShader and AbstractPipeline classes
This commit is contained in:
95
Source/Core/VideoCommon/AbstractPipeline.h
Normal file
95
Source/Core/VideoCommon/AbstractPipeline.h
Normal file
@ -0,0 +1,95 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoCommon/RenderState.h"
|
||||
#include "VideoCommon/TextureConfig.h"
|
||||
|
||||
class AbstractShader;
|
||||
class NativeVertexFormat;
|
||||
|
||||
// We use three pipeline usages:
|
||||
// - GX
|
||||
// - Per-stage UBO (VS/GS/PS, VS constants accessible from PS)
|
||||
// - 8 combined image samplers (accessible from PS)
|
||||
// - 1 SSBO, accessible from PS if bounding box is enabled
|
||||
// - Utility
|
||||
// - Single UBO, accessible from all stages [set=0, binding=1]
|
||||
// - 8 combined image samplers (accessible from PS) [set=1, binding=0-7]
|
||||
// - 1 texel buffer, accessible from PS [set=2, binding=0]
|
||||
// - Compute
|
||||
// - 1 uniform buffer [set=0, binding=1]
|
||||
// - 8 combined image samplers [set=1, binding=0-7]
|
||||
// - 1 texel buffer [set=2, binding=0]
|
||||
// - 1 storage image [set=3, binding=0]
|
||||
enum class AbstractPipelineUsage
|
||||
{
|
||||
GX,
|
||||
Utility
|
||||
};
|
||||
|
||||
struct AbstractPipelineConfig
|
||||
{
|
||||
const NativeVertexFormat* vertex_format;
|
||||
const AbstractShader* vertex_shader;
|
||||
const AbstractShader* geometry_shader;
|
||||
const AbstractShader* pixel_shader;
|
||||
RasterizationState rasterization_state;
|
||||
DepthState depth_state;
|
||||
BlendingState blending_state;
|
||||
|
||||
union FramebufferState
|
||||
{
|
||||
BitField<0, 8, AbstractTextureFormat> color_texture_format;
|
||||
BitField<8, 8, AbstractTextureFormat> depth_texture_format;
|
||||
BitField<16, 8, u32> samples;
|
||||
BitField<24, 1, u32> per_sample_shading;
|
||||
|
||||
bool operator==(const FramebufferState& rhs) const { return hex == rhs.hex; }
|
||||
bool operator!=(const FramebufferState& rhs) const { return hex != rhs.hex; }
|
||||
FramebufferState& operator=(const FramebufferState& rhs)
|
||||
{
|
||||
hex = rhs.hex;
|
||||
return *this;
|
||||
}
|
||||
|
||||
u32 hex;
|
||||
} framebuffer_state;
|
||||
|
||||
AbstractPipelineUsage usage;
|
||||
|
||||
bool operator==(const AbstractPipelineConfig& rhs) const
|
||||
{
|
||||
return std::tie(vertex_format, vertex_shader, geometry_shader, pixel_shader,
|
||||
rasterization_state.hex, depth_state.hex, blending_state.hex,
|
||||
framebuffer_state.hex, usage) ==
|
||||
std::tie(rhs.vertex_format, rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader,
|
||||
rhs.rasterization_state.hex, rhs.depth_state.hex, rhs.blending_state.hex,
|
||||
rhs.framebuffer_state.hex, rhs.usage);
|
||||
}
|
||||
bool operator!=(const AbstractPipelineConfig& rhs) const { return !operator==(rhs); }
|
||||
bool operator<(const AbstractPipelineConfig& rhs) const
|
||||
{
|
||||
return std::tie(vertex_format, vertex_shader, geometry_shader, pixel_shader,
|
||||
rasterization_state.hex, depth_state.hex, blending_state.hex,
|
||||
framebuffer_state.hex, usage) <
|
||||
std::tie(rhs.vertex_format, rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader,
|
||||
rhs.rasterization_state.hex, rhs.depth_state.hex, rhs.blending_state.hex,
|
||||
rhs.framebuffer_state.hex, rhs.usage);
|
||||
}
|
||||
};
|
||||
|
||||
class AbstractPipeline
|
||||
{
|
||||
public:
|
||||
AbstractPipeline() = default;
|
||||
virtual ~AbstractPipeline() = default;
|
||||
};
|
34
Source/Core/VideoCommon/AbstractShader.h
Normal file
34
Source/Core/VideoCommon/AbstractShader.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
enum class ShaderStage
|
||||
{
|
||||
Vertex,
|
||||
Geometry,
|
||||
Pixel,
|
||||
Compute
|
||||
};
|
||||
|
||||
class AbstractShader
|
||||
{
|
||||
public:
|
||||
explicit AbstractShader(ShaderStage stage) : m_stage(stage) {}
|
||||
virtual ~AbstractShader() = default;
|
||||
|
||||
ShaderStage GetStage() const { return m_stage; }
|
||||
using BinaryData = std::vector<u8>;
|
||||
virtual bool HasBinary() const = 0;
|
||||
virtual BinaryData GetBinary() const = 0;
|
||||
|
||||
protected:
|
||||
ShaderStage m_stage;
|
||||
};
|
@ -33,10 +33,15 @@
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
class AbstractRawTexture;
|
||||
class AbstractPipeline;
|
||||
class AbstractShader;
|
||||
class AbstractTexture;
|
||||
class AbstractStagingTexture;
|
||||
class PostProcessingShaderImplementation;
|
||||
struct TextureConfig;
|
||||
struct ComputePipelineConfig;
|
||||
struct AbstractPipelineConfig;
|
||||
enum class ShaderStage;
|
||||
enum class EFBAccessType;
|
||||
enum class StagingTextureType;
|
||||
|
||||
@ -69,6 +74,7 @@ public:
|
||||
PP_EFB_COPY_CLOCKS
|
||||
};
|
||||
|
||||
virtual void SetPipeline(const AbstractPipeline* pipeline) {}
|
||||
virtual void SetBlendingState(const BlendingState& state) {}
|
||||
virtual void SetScissorRect(const MathUtil::Rectangle<int>& rc) {}
|
||||
virtual void SetRasterizationState(const RasterizationState& state) {}
|
||||
@ -91,6 +97,14 @@ public:
|
||||
virtual std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) = 0;
|
||||
|
||||
// Shader modules/objects.
|
||||
virtual std::unique_ptr<AbstractShader>
|
||||
CreateShaderFromSource(ShaderStage stage, const char* source, size_t length) = 0;
|
||||
virtual std::unique_ptr<AbstractShader>
|
||||
CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) = 0;
|
||||
virtual std::unique_ptr<AbstractPipeline>
|
||||
CreatePipeline(const AbstractPipelineConfig& config) = 0;
|
||||
|
||||
// Ideal internal resolution - multiple of the native EFB resolution
|
||||
int GetTargetWidth() const { return m_target_width; }
|
||||
int GetTargetHeight() const { return m_target_height; }
|
||||
@ -160,6 +174,16 @@ public:
|
||||
|
||||
virtual void Shutdown();
|
||||
|
||||
// Drawing utility shaders.
|
||||
virtual void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
}
|
||||
virtual void DispatchComputeShader(const AbstractShader* shader, const void* uniforms,
|
||||
u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
std::tuple<int, int> CalculateTargetScale(int x, int y) const;
|
||||
bool CalculateTargetSize();
|
||||
|
@ -99,6 +99,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AbstractStagingTexture.h" />
|
||||
<ClInclude Include="AbstractPipeline.h" />
|
||||
<ClInclude Include="AbstractShader.h" />
|
||||
<ClInclude Include="AbstractTexture.h" />
|
||||
<ClInclude Include="AsyncRequests.h" />
|
||||
<ClInclude Include="AsyncShaderCompiler.h" />
|
||||
|
@ -374,8 +374,14 @@
|
||||
<ClInclude Include="AbstractStagingTexture.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AbstractShader.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AbstractPipeline.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user