mirror of
https://github.com/stenzek/duckstation.git
synced 2026-05-21 07:26:42 +00:00
GPUDevice: Reduce GraphicsConfig struct size
This commit is contained in:
@@ -1093,8 +1093,6 @@ bool FullscreenUI::LoadBackgroundShader(const std::string& path, Error* error)
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.geometry_shader = nullptr;
|
||||
plconfig.depth_format = GPUTexture::Format::Unknown;
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.layout = GPUPipeline::Layout::SingleTextureAndPushConstants;
|
||||
plconfig.SetTargetFormats(g_gpu_device->HasMainSwapChain() ? g_gpu_device->GetMainSwapChain()->GetFormat() :
|
||||
|
||||
@@ -782,8 +782,6 @@ bool FullscreenUI::CompileTransitionPipelines(Error* error)
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.SetTargetFormats(swap_chain ? swap_chain->GetFormat() : GPUTexture::Format::RGBA8);
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.vertex_shader = vs.get();
|
||||
plconfig.geometry_shader = nullptr;
|
||||
|
||||
@@ -1355,11 +1355,9 @@ bool GPU_HW::CompilePipelines(Error* error)
|
||||
GPUPipeline::GraphicsConfig plconfig = {};
|
||||
plconfig.layout = GPUPipeline::Layout::SingleTextureAndUBO;
|
||||
plconfig.input_layout.vertex_stride = sizeof(BatchVertex);
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, per_sample_shading);
|
||||
plconfig.primitive = GPUPipeline::Primitive::Triangles;
|
||||
plconfig.geometry_shader = nullptr;
|
||||
plconfig.samples = m_multisamples;
|
||||
plconfig.per_sample_shading = per_sample_shading;
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
|
||||
// [depth_test][transparency_mode][render_mode][texture_mode][dithering][interlacing][check_mask]
|
||||
@@ -1585,7 +1583,7 @@ bool GPU_HW::CompilePipelines(Error* error)
|
||||
SetScreenQuadInputLayout(plconfig);
|
||||
plconfig.vertex_shader = m_screen_quad_vertex_shader.get();
|
||||
plconfig.layout = GPUPipeline::Layout::SingleTextureAndPushConstants;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, false);
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.color_formats[1] = needs_rov_depth ? VRAM_DS_COLOR_FORMAT : GPUTexture::Format::Unknown;
|
||||
|
||||
@@ -1729,8 +1727,7 @@ bool GPU_HW::CompilePipelines(Error* error)
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.samples = m_multisamples;
|
||||
plconfig.per_sample_shading = true;
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, true);
|
||||
plconfig.SetTargetFormats(VRAM_DS_COLOR_FORMAT);
|
||||
if (!(m_copy_depth_pipeline = g_gpu_device->CreatePipeline(plconfig, error)))
|
||||
return false;
|
||||
@@ -1743,7 +1740,7 @@ bool GPU_HW::CompilePipelines(Error* error)
|
||||
SetScreenQuadInputLayout(plconfig);
|
||||
plconfig.vertex_shader = m_screen_quad_vertex_shader.get();
|
||||
plconfig.fragment_shader = fs.get();
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, false);
|
||||
if (!m_use_rov_for_shader_blend)
|
||||
{
|
||||
plconfig.SetTargetFormats(VRAM_RT_FORMAT, depth_buffer_format);
|
||||
@@ -1791,8 +1788,6 @@ bool GPU_HW::CompileResolutionDependentPipelines(Error* error)
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
|
||||
plconfig.primitive = GPUPipeline::Primitive::Triangles;
|
||||
plconfig.geometry_shader = nullptr;
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
@@ -1871,8 +1866,6 @@ bool GPU_HW::CompileDownsamplePipelines(Error* error)
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
|
||||
plconfig.primitive = GPUPipeline::Primitive::Triangles;
|
||||
plconfig.geometry_shader = nullptr;
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.vertex_shader = m_fullscreen_quad_vertex_shader.get();
|
||||
|
||||
@@ -871,8 +871,6 @@ bool GPUTextureCache::CompilePipelines(Error* error)
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.primitive = GPUPipeline::Primitive::Triangles;
|
||||
plconfig.geometry_shader = nullptr;
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.SetTargetFormats(REPLACEMENT_TEXTURE_FORMAT);
|
||||
|
||||
|
||||
@@ -105,8 +105,6 @@ bool GPUPresenter::CompileDisplayPipelines(bool display, bool deinterlace, bool
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.geometry_shader = nullptr;
|
||||
plconfig.depth_format = GPUTexture::Format::Unknown;
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
|
||||
if (display)
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
inline constexpr u32 SHADER_CACHE_VERSION = 35;
|
||||
inline constexpr u32 SHADER_CACHE_VERSION = 36;
|
||||
|
||||
@@ -132,7 +132,7 @@ private:
|
||||
{
|
||||
size_t operator()(const BlendStateMapKey& key) const;
|
||||
};
|
||||
using RasterizationStateMap = std::unordered_map<u8, ComPtr<ID3D11RasterizerState>>;
|
||||
using RasterizationStateMap = std::unordered_map<u16, ComPtr<ID3D11RasterizerState>>;
|
||||
using DepthStateMap = std::unordered_map<u8, ComPtr<ID3D11DepthStencilState>>;
|
||||
using BlendStateMap = std::unordered_map<BlendStateMapKey, ComPtr<ID3D11BlendState>, BlendStateMapHash>;
|
||||
using InputLayoutMap =
|
||||
|
||||
@@ -109,8 +109,7 @@ std::string D3D12Pipeline::GetPipelineName(const GraphicsConfig& config)
|
||||
hash.Update(shader->GetBytecodeData(), shader->GetBytecodeSize());
|
||||
hash.Update(&config.color_formats, sizeof(config.color_formats));
|
||||
hash.Update(&config.depth_format, sizeof(config.depth_format));
|
||||
hash.Update(&config.samples, sizeof(config.samples));
|
||||
hash.Update(&config.per_sample_shading, sizeof(config.per_sample_shading));
|
||||
hash.Update(&config.render_pass_flags, sizeof(config.render_pass_flags));
|
||||
|
||||
u8 digest[SHA1Digest::DIGEST_SIZE];
|
||||
hash.Final(digest);
|
||||
@@ -238,8 +237,8 @@ std::unique_ptr<GPUPipeline> D3D12Device::CreatePipeline(const GPUPipeline::Grap
|
||||
|
||||
gpb.SetRasterizationState(D3D12_FILL_MODE_SOLID,
|
||||
cull_mapping[static_cast<u8>(config.rasterization.cull_mode.GetValue())], false);
|
||||
if (config.samples > 1)
|
||||
gpb.SetMultisamples(config.samples);
|
||||
if (config.rasterization.multisamples > 1)
|
||||
gpb.SetMultisamples(config.rasterization.multisamples);
|
||||
gpb.SetDepthState(config.depth.depth_test != GPUPipeline::DepthFunc::Always || config.depth.depth_write,
|
||||
config.depth.depth_write, compare_mapping[static_cast<u8>(config.depth.depth_test.GetValue())]);
|
||||
gpb.SetNoStencilState();
|
||||
|
||||
@@ -121,10 +121,13 @@ bool GPUPipeline::InputLayout::operator!=(const InputLayout& rhs) const
|
||||
sizeof(VertexAttribute) * rhs.vertex_attributes.size()) != 0);
|
||||
}
|
||||
|
||||
GPUPipeline::RasterizationState GPUPipeline::RasterizationState::GetNoCullState()
|
||||
GPUPipeline::RasterizationState GPUPipeline::RasterizationState::GetNoCullState(u8 multisamples /* = 1 */,
|
||||
bool per_sample_shading /* = false */)
|
||||
{
|
||||
RasterizationState ret = {};
|
||||
ret.cull_mode = CullMode::None;
|
||||
ret.multisamples = multisamples;
|
||||
ret.per_sample_shading = per_sample_shading;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1310,7 +1313,10 @@ void GPUDevice::SetDriverType(GPUDriverType type)
|
||||
{
|
||||
m_driver_type = type;
|
||||
|
||||
#define NTENTRY(n) {GPUDriverType::n, #n}
|
||||
#define NTENTRY(n) \
|
||||
{ \
|
||||
GPUDriverType::n, #n \
|
||||
}
|
||||
static constexpr const std::pair<GPUDriverType, const char*> name_table[] = {
|
||||
NTENTRY(Unknown),
|
||||
NTENTRY(AMDProprietary),
|
||||
|
||||
@@ -370,12 +370,13 @@ public:
|
||||
MaxCount
|
||||
};
|
||||
|
||||
// TODO: purge this?
|
||||
union RasterizationState
|
||||
{
|
||||
u8 key;
|
||||
u16 key;
|
||||
|
||||
BitField<u8, CullMode, 0, 2> cull_mode;
|
||||
BitField<u16, CullMode, 0, 2> cull_mode;
|
||||
BitField<u16, u8, 2, 6> multisamples;
|
||||
BitField<u16, bool, 8, 1> per_sample_shading;
|
||||
|
||||
// clang-format off
|
||||
ALWAYS_INLINE bool operator==(const RasterizationState& rhs) const { return key == rhs.key; }
|
||||
@@ -383,7 +384,7 @@ public:
|
||||
ALWAYS_INLINE bool operator<(const RasterizationState& rhs) const { return key < rhs.key; }
|
||||
// clang-format on
|
||||
|
||||
static RasterizationState GetNoCullState();
|
||||
static RasterizationState GetNoCullState(u8 multisamples = 1, bool per_sample_shading = false);
|
||||
};
|
||||
|
||||
union DepthState
|
||||
@@ -447,23 +448,20 @@ public:
|
||||
|
||||
struct GraphicsConfig
|
||||
{
|
||||
Layout layout;
|
||||
|
||||
Primitive primitive;
|
||||
InputLayout input_layout;
|
||||
|
||||
RasterizationState rasterization;
|
||||
DepthState depth;
|
||||
BlendState blend;
|
||||
|
||||
GPUShader* vertex_shader;
|
||||
GPUShader* geometry_shader;
|
||||
GPUShader* fragment_shader;
|
||||
|
||||
BlendState blend;
|
||||
RasterizationState rasterization;
|
||||
DepthState depth;
|
||||
|
||||
Layout layout;
|
||||
Primitive primitive;
|
||||
|
||||
GPUTexture::Format color_formats[4];
|
||||
GPUTexture::Format depth_format;
|
||||
u8 samples;
|
||||
bool per_sample_shading;
|
||||
RenderPassFlag render_pass_flags;
|
||||
|
||||
void SetTargetFormats(GPUTexture::Format color_format,
|
||||
|
||||
@@ -406,8 +406,6 @@ bool ImGuiManager::CompilePipelines(Error* error)
|
||||
plconfig.blend = GPUPipeline::BlendState::GetAlphaBlendingState();
|
||||
plconfig.blend.write_mask = 0x7;
|
||||
plconfig.SetTargetFormats(s_state.window_format);
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.vertex_shader = imgui_vs.get();
|
||||
plconfig.geometry_shader = nullptr;
|
||||
|
||||
@@ -872,7 +872,7 @@ std::unique_ptr<GPUPipeline> MetalDevice::CreatePipeline(const GPUPipeline::Grap
|
||||
|
||||
// General
|
||||
const MTLPrimitiveType primitive = primitives[static_cast<u8>(config.primitive)];
|
||||
desc.rasterSampleCount = config.samples;
|
||||
desc.rasterSampleCount = config.rasterization.multisamples;
|
||||
|
||||
// Metal-specific stuff
|
||||
desc.vertexBuffers[0].mutability = MTLMutabilityImmutable;
|
||||
|
||||
@@ -1482,8 +1482,6 @@ bool PostProcessing::ReShadeFXShader::CompilePipeline(GPUTexture::Format format,
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
|
||||
GPUPipeline::ComputeConfig cplconfig;
|
||||
|
||||
@@ -137,8 +137,6 @@ bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.vertex_shader = vs.get();
|
||||
plconfig.fragment_shader = fs.get();
|
||||
|
||||
@@ -1482,8 +1482,6 @@ bool PostProcessing::SlangShader::CompilePass(Pass& pass, Error* error)
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.vertex_shader = vs.get();
|
||||
plconfig.fragment_shader = fs.get();
|
||||
@@ -1779,8 +1777,6 @@ std::unique_ptr<GPUPipeline> PostProcessing::SlangShader::CreateBlitPipeline(GPU
|
||||
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
|
||||
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
|
||||
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
|
||||
plconfig.samples = 1;
|
||||
plconfig.per_sample_shading = false;
|
||||
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
|
||||
plconfig.vertex_shader = vs.get();
|
||||
plconfig.fragment_shader = fs.get();
|
||||
|
||||
@@ -1214,7 +1214,7 @@ VkRenderPass VulkanDevice::GetRenderPass(const GPUPipeline::GraphicsConfig& conf
|
||||
key.stencil_store_op = stencil ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
}
|
||||
|
||||
key.samples = static_cast<u8>(config.samples);
|
||||
key.samples = config.rasterization.multisamples;
|
||||
key.feedback_loop = config.render_pass_flags;
|
||||
|
||||
const auto it = m_render_pass_cache.find(key);
|
||||
|
||||
@@ -215,8 +215,8 @@ std::unique_ptr<GPUPipeline> VulkanDevice::CreatePipeline(const GPUPipeline::Gra
|
||||
gpb.SetRasterizationState(VK_POLYGON_MODE_FILL,
|
||||
cull_mapping[static_cast<u8>(config.rasterization.cull_mode.GetValue())],
|
||||
VK_FRONT_FACE_CLOCKWISE);
|
||||
if (config.samples > 1)
|
||||
gpb.SetMultisamples(config.samples, config.per_sample_shading);
|
||||
if (config.rasterization.multisamples > 1)
|
||||
gpb.SetMultisamples(config.rasterization.multisamples, config.rasterization.per_sample_shading);
|
||||
gpb.SetDepthState(config.depth.depth_test != GPUPipeline::DepthFunc::Always || config.depth.depth_write,
|
||||
config.depth.depth_write, compare_mapping[static_cast<u8>(config.depth.depth_test.GetValue())]);
|
||||
gpb.SetNoStencilState();
|
||||
|
||||
Reference in New Issue
Block a user