Skip to content

Commit 7a539ba

Browse files
committed
GPUDevice: Reduce GraphicsConfig struct size
1 parent b10eba4 commit 7a539ba

17 files changed

+32
-54
lines changed

src/core/fullscreenui.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,6 @@ bool FullscreenUI::LoadBackgroundShader(const std::string& path, Error* error)
10931093
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
10941094
plconfig.geometry_shader = nullptr;
10951095
plconfig.depth_format = GPUTexture::Format::Unknown;
1096-
plconfig.samples = 1;
1097-
plconfig.per_sample_shading = false;
10981096
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
10991097
plconfig.layout = GPUPipeline::Layout::SingleTextureAndPushConstants;
11001098
plconfig.SetTargetFormats(g_gpu_device->HasMainSwapChain() ? g_gpu_device->GetMainSwapChain()->GetFormat() :

src/core/fullscreenui_widgets.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,6 @@ bool FullscreenUI::CompileTransitionPipelines(Error* error)
782782
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
783783
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
784784
plconfig.SetTargetFormats(swap_chain ? swap_chain->GetFormat() : GPUTexture::Format::RGBA8);
785-
plconfig.samples = 1;
786-
plconfig.per_sample_shading = false;
787785
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
788786
plconfig.vertex_shader = vs.get();
789787
plconfig.geometry_shader = nullptr;

src/core/gpu_hw.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,9 @@ bool GPU_HW::CompilePipelines(Error* error)
13551355
GPUPipeline::GraphicsConfig plconfig = {};
13561356
plconfig.layout = GPUPipeline::Layout::SingleTextureAndUBO;
13571357
plconfig.input_layout.vertex_stride = sizeof(BatchVertex);
1358-
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
1358+
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, per_sample_shading);
13591359
plconfig.primitive = GPUPipeline::Primitive::Triangles;
13601360
plconfig.geometry_shader = nullptr;
1361-
plconfig.samples = m_multisamples;
1362-
plconfig.per_sample_shading = per_sample_shading;
13631361
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
13641362

13651363
// [depth_test][transparency_mode][render_mode][texture_mode][dithering][interlacing][check_mask]
@@ -1585,7 +1583,7 @@ bool GPU_HW::CompilePipelines(Error* error)
15851583
SetScreenQuadInputLayout(plconfig);
15861584
plconfig.vertex_shader = m_screen_quad_vertex_shader.get();
15871585
plconfig.layout = GPUPipeline::Layout::SingleTextureAndPushConstants;
1588-
plconfig.per_sample_shading = false;
1586+
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, false);
15891587
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
15901588
plconfig.color_formats[1] = needs_rov_depth ? VRAM_DS_COLOR_FORMAT : GPUTexture::Format::Unknown;
15911589

@@ -1729,8 +1727,7 @@ bool GPU_HW::CompilePipelines(Error* error)
17291727
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
17301728
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
17311729
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
1732-
plconfig.samples = m_multisamples;
1733-
plconfig.per_sample_shading = true;
1730+
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, true);
17341731
plconfig.SetTargetFormats(VRAM_DS_COLOR_FORMAT);
17351732
if (!(m_copy_depth_pipeline = g_gpu_device->CreatePipeline(plconfig, error)))
17361733
return false;
@@ -1743,7 +1740,7 @@ bool GPU_HW::CompilePipelines(Error* error)
17431740
SetScreenQuadInputLayout(plconfig);
17441741
plconfig.vertex_shader = m_screen_quad_vertex_shader.get();
17451742
plconfig.fragment_shader = fs.get();
1746-
plconfig.per_sample_shading = false;
1743+
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState(m_multisamples, false);
17471744
if (!m_use_rov_for_shader_blend)
17481745
{
17491746
plconfig.SetTargetFormats(VRAM_RT_FORMAT, depth_buffer_format);
@@ -1791,8 +1788,6 @@ bool GPU_HW::CompileResolutionDependentPipelines(Error* error)
17911788
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
17921789
plconfig.primitive = GPUPipeline::Primitive::Triangles;
17931790
plconfig.geometry_shader = nullptr;
1794-
plconfig.samples = 1;
1795-
plconfig.per_sample_shading = false;
17961791
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
17971792
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
17981793
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
@@ -1871,8 +1866,6 @@ bool GPU_HW::CompileDownsamplePipelines(Error* error)
18711866
plconfig.rasterization = GPUPipeline::RasterizationState::GetNoCullState();
18721867
plconfig.primitive = GPUPipeline::Primitive::Triangles;
18731868
plconfig.geometry_shader = nullptr;
1874-
plconfig.samples = 1;
1875-
plconfig.per_sample_shading = false;
18761869
plconfig.depth = GPUPipeline::DepthState::GetNoTestsState();
18771870
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
18781871
plconfig.vertex_shader = m_fullscreen_quad_vertex_shader.get();

src/core/gpu_hw_texture_cache.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,6 @@ bool GPUTextureCache::CompilePipelines(Error* error)
871871
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
872872
plconfig.primitive = GPUPipeline::Primitive::Triangles;
873873
plconfig.geometry_shader = nullptr;
874-
plconfig.samples = 1;
875-
plconfig.per_sample_shading = false;
876874
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
877875
plconfig.SetTargetFormats(REPLACEMENT_TEXTURE_FORMAT);
878876

src/core/gpu_presenter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ bool GPUPresenter::CompileDisplayPipelines(bool display, bool deinterlace, bool
105105
plconfig.blend = GPUPipeline::BlendState::GetNoBlendingState();
106106
plconfig.geometry_shader = nullptr;
107107
plconfig.depth_format = GPUTexture::Format::Unknown;
108-
plconfig.samples = 1;
109-
plconfig.per_sample_shading = false;
110108
plconfig.render_pass_flags = GPUPipeline::NoRenderPassFlags;
111109

112110
if (display)

src/core/shader_cache_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
#include "common/types.h"
77

8-
inline constexpr u32 SHADER_CACHE_VERSION = 35;
8+
inline constexpr u32 SHADER_CACHE_VERSION = 36;

src/util/d3d11_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class D3D11Device final : public GPUDevice
132132
{
133133
size_t operator()(const BlendStateMapKey& key) const;
134134
};
135-
using RasterizationStateMap = std::unordered_map<u8, ComPtr<ID3D11RasterizerState>>;
135+
using RasterizationStateMap = std::unordered_map<u16, ComPtr<ID3D11RasterizerState>>;
136136
using DepthStateMap = std::unordered_map<u8, ComPtr<ID3D11DepthStencilState>>;
137137
using BlendStateMap = std::unordered_map<BlendStateMapKey, ComPtr<ID3D11BlendState>, BlendStateMapHash>;
138138
using InputLayoutMap =

src/util/d3d12_pipeline.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ std::string D3D12Pipeline::GetPipelineName(const GraphicsConfig& config)
109109
hash.Update(shader->GetBytecodeData(), shader->GetBytecodeSize());
110110
hash.Update(&config.color_formats, sizeof(config.color_formats));
111111
hash.Update(&config.depth_format, sizeof(config.depth_format));
112-
hash.Update(&config.samples, sizeof(config.samples));
113-
hash.Update(&config.per_sample_shading, sizeof(config.per_sample_shading));
112+
hash.Update(&config.render_pass_flags, sizeof(config.render_pass_flags));
114113

115114
u8 digest[SHA1Digest::DIGEST_SIZE];
116115
hash.Final(digest);
@@ -238,8 +237,8 @@ std::unique_ptr<GPUPipeline> D3D12Device::CreatePipeline(const GPUPipeline::Grap
238237

239238
gpb.SetRasterizationState(D3D12_FILL_MODE_SOLID,
240239
cull_mapping[static_cast<u8>(config.rasterization.cull_mode.GetValue())], false);
241-
if (config.samples > 1)
242-
gpb.SetMultisamples(config.samples);
240+
if (config.rasterization.multisamples > 1)
241+
gpb.SetMultisamples(config.rasterization.multisamples);
243242
gpb.SetDepthState(config.depth.depth_test != GPUPipeline::DepthFunc::Always || config.depth.depth_write,
244243
config.depth.depth_write, compare_mapping[static_cast<u8>(config.depth.depth_test.GetValue())]);
245244
gpb.SetNoStencilState();

src/util/gpu_device.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ bool GPUPipeline::InputLayout::operator!=(const InputLayout& rhs) const
121121
sizeof(VertexAttribute) * rhs.vertex_attributes.size()) != 0);
122122
}
123123

124-
GPUPipeline::RasterizationState GPUPipeline::RasterizationState::GetNoCullState()
124+
GPUPipeline::RasterizationState GPUPipeline::RasterizationState::GetNoCullState(u8 multisamples /* = 1 */,
125+
bool per_sample_shading /* = false */)
125126
{
126127
RasterizationState ret = {};
127128
ret.cull_mode = CullMode::None;
129+
ret.multisamples = multisamples;
130+
ret.per_sample_shading = per_sample_shading;
128131
return ret;
129132
}
130133

@@ -1310,7 +1313,10 @@ void GPUDevice::SetDriverType(GPUDriverType type)
13101313
{
13111314
m_driver_type = type;
13121315

1313-
#define NTENTRY(n) {GPUDriverType::n, #n}
1316+
#define NTENTRY(n) \
1317+
{ \
1318+
GPUDriverType::n, #n \
1319+
}
13141320
static constexpr const std::pair<GPUDriverType, const char*> name_table[] = {
13151321
NTENTRY(Unknown),
13161322
NTENTRY(AMDProprietary),

src/util/gpu_device.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -370,20 +370,21 @@ class GPUPipeline
370370
MaxCount
371371
};
372372

373-
// TODO: purge this?
374373
union RasterizationState
375374
{
376-
u8 key;
375+
u16 key;
377376

378-
BitField<u8, CullMode, 0, 2> cull_mode;
377+
BitField<u16, CullMode, 0, 2> cull_mode;
378+
BitField<u16, u8, 2, 6> multisamples;
379+
BitField<u16, bool, 8, 1> per_sample_shading;
379380

380381
// clang-format off
381382
ALWAYS_INLINE bool operator==(const RasterizationState& rhs) const { return key == rhs.key; }
382383
ALWAYS_INLINE bool operator!=(const RasterizationState& rhs) const { return key != rhs.key; }
383384
ALWAYS_INLINE bool operator<(const RasterizationState& rhs) const { return key < rhs.key; }
384385
// clang-format on
385386

386-
static RasterizationState GetNoCullState();
387+
static RasterizationState GetNoCullState(u8 multisamples = 1, bool per_sample_shading = false);
387388
};
388389

389390
union DepthState
@@ -447,23 +448,20 @@ class GPUPipeline
447448

448449
struct GraphicsConfig
449450
{
450-
Layout layout;
451-
452-
Primitive primitive;
453451
InputLayout input_layout;
452+
GPUShader* vertex_shader;
453+
GPUShader* geometry_shader;
454+
GPUShader* fragment_shader;
454455

456+
BlendState blend;
455457
RasterizationState rasterization;
456458
DepthState depth;
457-
BlendState blend;
458459

459-
GPUShader* vertex_shader;
460-
GPUShader* geometry_shader;
461-
GPUShader* fragment_shader;
460+
Layout layout;
461+
Primitive primitive;
462462

463463
GPUTexture::Format color_formats[4];
464464
GPUTexture::Format depth_format;
465-
u8 samples;
466-
bool per_sample_shading;
467465
RenderPassFlag render_pass_flags;
468466

469467
void SetTargetFormats(GPUTexture::Format color_format,

0 commit comments

Comments
 (0)