mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
VideoCommon: add constant value to set the allowed maximum number of pixel samplers
This commit is contained in:
@ -33,8 +33,7 @@ Gfx::Gfx(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale)
|
||||
{
|
||||
m_state.root_signature = g_dx_context->GetGXRootSignature();
|
||||
|
||||
// Textures must be populated with null descriptors, since we copy directly from this array.
|
||||
for (u32 i = 0; i < MAX_TEXTURES; i++)
|
||||
for (u32 i = 0; i < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; i++)
|
||||
{
|
||||
m_state.textures[i].ptr = g_dx_context->GetNullSRVDescriptor().cpu_handle.ptr;
|
||||
m_state.samplers.states[i] = RenderState::GetPointSamplerState();
|
||||
@ -301,7 +300,7 @@ void Gfx::UnbindTexture(const AbstractTexture* texture)
|
||||
{
|
||||
const auto srv_shadow_descriptor =
|
||||
static_cast<const DXTexture*>(texture)->GetSRVDescriptor().cpu_handle;
|
||||
for (u32 i = 0; i < MAX_TEXTURES; i++)
|
||||
for (u32 i = 0; i < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; i++)
|
||||
{
|
||||
if (m_state.textures[i].ptr == srv_shadow_descriptor.ptr)
|
||||
{
|
||||
@ -666,15 +665,17 @@ void Gfx::UpdateDescriptorTables()
|
||||
|
||||
bool Gfx::UpdateSRVDescriptorTable()
|
||||
{
|
||||
static constexpr std::array<UINT, MAX_TEXTURES> src_sizes = {1, 1, 1, 1, 1, 1, 1, 1};
|
||||
static constexpr std::array<UINT, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> src_sizes = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1};
|
||||
DescriptorHandle dst_base_handle;
|
||||
const UINT dst_handle_sizes = 8;
|
||||
if (!g_dx_context->GetDescriptorAllocator()->Allocate(MAX_TEXTURES, &dst_base_handle))
|
||||
if (!g_dx_context->GetDescriptorAllocator()->Allocate(VideoCommon::MAX_PIXEL_SHADER_SAMPLERS,
|
||||
&dst_base_handle))
|
||||
return false;
|
||||
|
||||
g_dx_context->GetDevice()->CopyDescriptors(
|
||||
1, &dst_base_handle.cpu_handle, &dst_handle_sizes, MAX_TEXTURES, m_state.textures.data(),
|
||||
src_sizes.data(), D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
1, &dst_base_handle.cpu_handle, &dst_handle_sizes, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS,
|
||||
m_state.textures.data(), src_sizes.data(), D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
m_state.srv_descriptor_base = dst_base_handle.gpu_handle;
|
||||
m_dirty_bits = (m_dirty_bits & ~DirtyState_Textures) | DirtyState_SRV_Descriptor;
|
||||
return true;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "VideoBackends/D3D12/DescriptorAllocator.h"
|
||||
#include "VideoBackends/D3D12/DescriptorHeapManager.h"
|
||||
#include "VideoCommon/AbstractGfx.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
|
||||
namespace DX12
|
||||
{
|
||||
@ -96,7 +97,6 @@ protected:
|
||||
void OnConfigChanged(u32 bits) override;
|
||||
|
||||
private:
|
||||
static const u32 MAX_TEXTURES = 8;
|
||||
static const u32 NUM_CONSTANT_BUFFERS = 3;
|
||||
|
||||
// Dirty bits
|
||||
@ -158,7 +158,7 @@ private:
|
||||
ID3D12RootSignature* root_signature = nullptr;
|
||||
DXShader* compute_shader = nullptr;
|
||||
std::array<D3D12_GPU_VIRTUAL_ADDRESS, 3> constant_buffers = {};
|
||||
std::array<D3D12_CPU_DESCRIPTOR_HANDLE, MAX_TEXTURES> textures = {};
|
||||
std::array<D3D12_CPU_DESCRIPTOR_HANDLE, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> textures = {};
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE vs_srv = {};
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE ps_uav = {};
|
||||
SamplerStateSet samplers = {};
|
||||
|
@ -334,8 +334,8 @@ bool DXContext::CreateGXRootSignature()
|
||||
{
|
||||
// GX:
|
||||
// - 3 constant buffers (bindings 0-2), 0/1 visible in PS, 2 visible in VS, 1 visible in GS.
|
||||
// - 8 textures (visible in PS).
|
||||
// - 8 samplers (visible in PS).
|
||||
// - VideoCommon::MAX_PIXEL_SHADER_SAMPLERS textures (visible in PS).
|
||||
// - VideoCommon::MAX_PIXEL_SHADER_SAMPLERS samplers (visible in PS).
|
||||
// - 1 UAV (visible in PS).
|
||||
|
||||
std::array<D3D12_ROOT_PARAMETER, NUM_ROOT_PARAMETERS> params;
|
||||
@ -344,10 +344,10 @@ bool DXContext::CreateGXRootSignature()
|
||||
SetRootParamCBV(¶ms[param_count], 0, D3D12_SHADER_VISIBILITY_PIXEL);
|
||||
param_count++;
|
||||
SetRootParamTable(¶ms[param_count], &ranges[param_count], D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 0,
|
||||
8, D3D12_SHADER_VISIBILITY_PIXEL);
|
||||
VideoCommon::MAX_PIXEL_SHADER_SAMPLERS, D3D12_SHADER_VISIBILITY_PIXEL);
|
||||
param_count++;
|
||||
SetRootParamTable(¶ms[param_count], &ranges[param_count], D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER,
|
||||
0, 8, D3D12_SHADER_VISIBILITY_PIXEL);
|
||||
0, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS, D3D12_SHADER_VISIBILITY_PIXEL);
|
||||
param_count++;
|
||||
SetRootParamCBV(¶ms[param_count], 0, D3D12_SHADER_VISIBILITY_VERTEX);
|
||||
param_count++;
|
||||
|
@ -86,23 +86,23 @@ bool SamplerAllocator::GetGroupHandle(const SamplerStateSet& sss,
|
||||
|
||||
// Allocate a group of descriptors.
|
||||
DescriptorHandle allocation;
|
||||
if (!Allocate(SamplerStateSet::NUM_SAMPLERS_PER_GROUP, &allocation))
|
||||
if (!Allocate(VideoCommon::MAX_PIXEL_SHADER_SAMPLERS, &allocation))
|
||||
return false;
|
||||
|
||||
// Lookup sampler handles from global cache.
|
||||
std::array<D3D12_CPU_DESCRIPTOR_HANDLE, SamplerStateSet::NUM_SAMPLERS_PER_GROUP> source_handles;
|
||||
for (u32 i = 0; i < SamplerStateSet::NUM_SAMPLERS_PER_GROUP; i++)
|
||||
std::array<D3D12_CPU_DESCRIPTOR_HANDLE, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> source_handles;
|
||||
for (u32 i = 0; i < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; i++)
|
||||
{
|
||||
if (!g_dx_context->GetSamplerHeapManager().Lookup(sss.states[i], &source_handles[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy samplers from the sampler heap.
|
||||
static constexpr std::array<UINT, SamplerStateSet::NUM_SAMPLERS_PER_GROUP> source_sizes = {
|
||||
static constexpr std::array<UINT, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> source_sizes = {
|
||||
{1, 1, 1, 1, 1, 1, 1, 1}};
|
||||
g_dx_context->GetDevice()->CopyDescriptors(
|
||||
1, &allocation.cpu_handle, &SamplerStateSet::NUM_SAMPLERS_PER_GROUP,
|
||||
SamplerStateSet::NUM_SAMPLERS_PER_GROUP, source_handles.data(), source_sizes.data(),
|
||||
1, &allocation.cpu_handle, &VideoCommon::MAX_PIXEL_SHADER_SAMPLERS,
|
||||
VideoCommon::MAX_PIXEL_SHADER_SAMPLERS, source_handles.data(), source_sizes.data(),
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
*handle = allocation.gpu_handle;
|
||||
m_sampler_map.emplace(sss, allocation.gpu_handle);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <map>
|
||||
#include "VideoBackends/D3D12/DescriptorHeapManager.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
|
||||
namespace DX12
|
||||
{
|
||||
@ -34,8 +35,7 @@ protected:
|
||||
|
||||
struct SamplerStateSet final
|
||||
{
|
||||
static const u32 NUM_SAMPLERS_PER_GROUP = 8;
|
||||
SamplerState states[NUM_SAMPLERS_PER_GROUP];
|
||||
SamplerState states[VideoCommon::MAX_PIXEL_SHADER_SAMPLERS];
|
||||
};
|
||||
|
||||
bool operator==(const SamplerStateSet& lhs, const SamplerStateSet& rhs);
|
||||
|
Reference in New Issue
Block a user