mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
VideoCommon: add constant value to set the allowed maximum number of pixel samplers
This commit is contained in:
parent
a88e5ef390
commit
af313f8419
@ -635,6 +635,7 @@
|
||||
<ClInclude Include="VideoCommon\BPStructs.h" />
|
||||
<ClInclude Include="VideoCommon\CommandProcessor.h" />
|
||||
<ClInclude Include="VideoCommon\ConstantManager.h" />
|
||||
<ClInclude Include="VideoCommon\Constants.h" />
|
||||
<ClInclude Include="VideoCommon\CPMemory.h" />
|
||||
<ClInclude Include="VideoCommon\CPUCull.h" />
|
||||
<ClInclude Include="VideoCommon\CPUCullImpl.h" />
|
||||
|
@ -205,7 +205,7 @@ u32 StateManager::UnsetTexture(ID3D11ShaderResourceView* srv)
|
||||
{
|
||||
u32 mask = 0;
|
||||
|
||||
for (u32 index = 0; index < 8; ++index)
|
||||
for (u32 index = 0; index < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; ++index)
|
||||
{
|
||||
if (m_current.textures[index] == srv)
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "Common/BitField.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
#include "VideoCommon/RenderState.h"
|
||||
|
||||
namespace DX11
|
||||
@ -263,8 +264,8 @@ private:
|
||||
|
||||
struct Resources
|
||||
{
|
||||
std::array<ID3D11ShaderResourceView*, 8> textures;
|
||||
std::array<ID3D11SamplerState*, 8> samplers;
|
||||
std::array<ID3D11ShaderResourceView*, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> textures;
|
||||
std::array<ID3D11SamplerState*, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> samplers;
|
||||
std::array<ID3D11Buffer*, 2> pixelConstants;
|
||||
ID3D11Buffer* vertexConstants;
|
||||
ID3D11Buffer* geometryConstants;
|
||||
|
@ -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);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "VideoCommon/AbstractGfx.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
|
||||
class GLContext;
|
||||
|
||||
@ -100,7 +101,7 @@ private:
|
||||
|
||||
std::unique_ptr<GLContext> m_main_gl_context;
|
||||
std::unique_ptr<OGLFramebuffer> m_system_framebuffer;
|
||||
std::array<const OGLTexture*, 8> m_bound_textures{};
|
||||
std::array<const OGLTexture*, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> m_bound_textures{};
|
||||
AbstractTexture* m_bound_image_texture = nullptr;
|
||||
RasterizationState m_current_rasterization_state;
|
||||
DepthState m_current_depth_state;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/GL/GLUtil.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
#include "VideoCommon/RenderState.h"
|
||||
|
||||
namespace OGL
|
||||
@ -35,7 +36,8 @@ private:
|
||||
static void SetParameters(GLuint sampler_id, const SamplerState& params);
|
||||
|
||||
std::map<SamplerState, GLuint> m_cache;
|
||||
std::array<std::pair<SamplerState, GLuint>, 8> m_active_samplers{};
|
||||
std::array<std::pair<SamplerState, GLuint>, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS>
|
||||
m_active_samplers{};
|
||||
|
||||
GLuint m_point_sampler;
|
||||
GLuint m_linear_sampler;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "Common/Thread.h"
|
||||
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
@ -148,14 +149,17 @@ VkDescriptorPool CommandBufferManager::CreateDescriptorPool(u32 max_descriptor_s
|
||||
/*
|
||||
* Worst case descriptor counts according to the descriptor layout created in ObjectCache.cpp:
|
||||
* UNIFORM_BUFFER_DYNAMIC: 3
|
||||
* COMBINED_IMAGE_SAMPLER: 18
|
||||
* COMBINED_IMAGE_SAMPLER: NUM_UTILITY_PIXEL_SAMPLERS + NUM_COMPUTE_SHADER_SAMPLERS +
|
||||
* VideoCommon::MAX_PIXEL_SHADER_SAMPLERS
|
||||
* STORAGE_BUFFER: 2
|
||||
* UNIFORM_TEXEL_BUFFER: 3
|
||||
* STORAGE_IMAGE: 1
|
||||
*/
|
||||
const std::array<VkDescriptorPoolSize, 5> pool_sizes{{
|
||||
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, max_descriptor_sets * 3},
|
||||
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, max_descriptor_sets * 18},
|
||||
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
max_descriptor_sets * (VideoCommon::MAX_PIXEL_SHADER_SAMPLERS + NUM_COMPUTE_SHADER_SAMPLERS +
|
||||
NUM_UTILITY_PIXEL_SAMPLERS)},
|
||||
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, max_descriptor_sets * 2},
|
||||
{VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, max_descriptor_sets * 3},
|
||||
{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, max_descriptor_sets * 1},
|
||||
|
@ -78,8 +78,8 @@ enum UNIFORM_BUFFER_DESCRIPTOR_SET_BINDING
|
||||
constexpr u32 MAX_VERTEX_ATTRIBUTES = 16;
|
||||
|
||||
// Number of pixel shader texture slots
|
||||
constexpr u32 NUM_PIXEL_SHADER_SAMPLERS = 8;
|
||||
constexpr u32 NUM_COMPUTE_SHADER_SAMPLERS = 2;
|
||||
constexpr u32 NUM_UTILITY_PIXEL_SAMPLERS = 8;
|
||||
|
||||
// Number of texel buffer binding points.
|
||||
constexpr u32 NUM_COMPUTE_TEXEL_BUFFERS = 2;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "VideoBackends/Vulkan/VKTexture.h"
|
||||
#include "VideoBackends/Vulkan/VKVertexFormat.h"
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
namespace Vulkan
|
||||
@ -119,8 +120,8 @@ bool ObjectCache::CreateDescriptorSetLayouts()
|
||||
}};
|
||||
|
||||
static const std::array<VkDescriptorSetLayoutBinding, 1> standard_sampler_bindings{{
|
||||
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, static_cast<u32>(NUM_PIXEL_SHADER_SAMPLERS),
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT},
|
||||
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
static_cast<u32>(VideoCommon::MAX_PIXEL_SHADER_SAMPLERS), VK_SHADER_STAGE_FRAGMENT_BIT},
|
||||
}};
|
||||
|
||||
// The dynamic veretex loader's vertex buffer must be last here, for similar reasons
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "VideoBackends/Vulkan/VKTexture.h"
|
||||
#include "VideoBackends/Vulkan/VKVertexFormat.h"
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
@ -65,7 +66,7 @@ bool StateTracker::Initialize()
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
|
||||
// Initialize all samplers to point by default
|
||||
for (size_t i = 0; i < NUM_PIXEL_SHADER_SAMPLERS; i++)
|
||||
for (size_t i = 0; i < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; i++)
|
||||
{
|
||||
m_bindings.samplers[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
m_bindings.samplers[i].imageView = m_dummy_texture->GetView();
|
||||
@ -498,7 +499,7 @@ void StateTracker::UpdateGXDescriptorSet()
|
||||
m_gx_descriptor_sets[1],
|
||||
0,
|
||||
0,
|
||||
static_cast<u32>(NUM_PIXEL_SHADER_SAMPLERS),
|
||||
static_cast<u32>(VideoCommon::MAX_PIXEL_SHADER_SAMPLERS),
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
m_bindings.samplers.data(),
|
||||
nullptr,
|
||||
@ -602,7 +603,7 @@ void StateTracker::UpdateUtilityDescriptorSet()
|
||||
m_utility_descriptor_sets[1],
|
||||
0,
|
||||
0,
|
||||
NUM_PIXEL_SHADER_SAMPLERS,
|
||||
NUM_UTILITY_PIXEL_SAMPLERS,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
m_bindings.samplers.data(),
|
||||
nullptr,
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoBackends/Vulkan/Constants.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
@ -141,7 +142,7 @@ private:
|
||||
std::array<u32, NUM_UBO_DESCRIPTOR_SET_BINDINGS> gx_ubo_offsets;
|
||||
VkDescriptorBufferInfo utility_ubo_binding;
|
||||
u32 utility_ubo_offset;
|
||||
std::array<VkDescriptorImageInfo, NUM_PIXEL_SHADER_SAMPLERS> samplers;
|
||||
std::array<VkDescriptorImageInfo, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> samplers;
|
||||
std::array<VkBufferView, NUM_COMPUTE_TEXEL_BUFFERS> texel_buffers;
|
||||
VkDescriptorBufferInfo ssbo;
|
||||
VkDescriptorBufferInfo gx_uber_vertex_ssbo;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoBackends/Vulkan/Constants.h"
|
||||
#include "VideoCommon/AbstractGfx.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
@ -96,6 +97,6 @@ private:
|
||||
float m_backbuffer_scale;
|
||||
|
||||
// Keep a copy of sampler states to avoid cache lookups every draw
|
||||
std::array<SamplerState, NUM_PIXEL_SHADER_SAMPLERS> m_sampler_states = {};
|
||||
std::array<SamplerState, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> m_sampler_states = {};
|
||||
};
|
||||
} // namespace Vulkan
|
||||
|
@ -23,6 +23,7 @@ add_library(videocommon
|
||||
CommandProcessor.cpp
|
||||
CommandProcessor.h
|
||||
ConstantManager.h
|
||||
Constants.h
|
||||
CPMemory.cpp
|
||||
CPMemory.h
|
||||
CPUCull.cpp
|
||||
|
11
Source/Core/VideoCommon/Constants.h
Normal file
11
Source/Core/VideoCommon/Constants.h
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2023 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
namespace VideoCommon
|
||||
{
|
||||
constexpr u32 MAX_PIXEL_SHADER_SAMPLERS = 8;
|
||||
}
|
Loading…
Reference in New Issue
Block a user