[D3D12] D3D12Texture::SRVDescriptorKey structure

This commit is contained in:
Triang3l 2022-05-14 18:41:15 +03:00
parent 26cf717394
commit d6a9056952
2 changed files with 30 additions and 4 deletions

View File

@ -1955,7 +1955,9 @@ void D3D12TextureCache::UpdateTextureBindingsImpl(
uint32_t D3D12TextureCache::FindOrCreateTextureDescriptor(
D3D12Texture& texture, bool is_signed, uint32_t host_swizzle) {
uint32_t descriptor_key = uint32_t(is_signed) | (host_swizzle << 1);
D3D12Texture::SRVDescriptorKey descriptor_key;
descriptor_key.is_signed = uint32_t(is_signed);
descriptor_key.host_swizzle = host_swizzle;
// Try to find an existing descriptor.
uint32_t existing_descriptor_index =

View File

@ -11,6 +11,7 @@
#define XENIA_GPU_D3D12_D3D12_TEXTURE_CACHE_H_
#include <array>
#include <functional>
#include <memory>
#include <unordered_map>
#include <utility>
@ -268,6 +269,28 @@ class D3D12TextureCache final : public TextureCache {
class D3D12Texture final : public Texture {
public:
union SRVDescriptorKey {
uint32_t key;
struct {
uint32_t is_signed : 1;
uint32_t host_swizzle : 12;
};
SRVDescriptorKey() : key(0) { static_assert_size(*this, sizeof(key)); }
struct Hasher {
size_t operator()(const SRVDescriptorKey& key) const {
return std::hash<decltype(key.key)>{}(key.key);
}
};
bool operator==(const SRVDescriptorKey& other_key) const {
return key == other_key.key;
}
bool operator!=(const SRVDescriptorKey& other_key) const {
return !(*this == other_key);
}
};
explicit D3D12Texture(D3D12TextureCache& texture_cache,
const TextureKey& key, ID3D12Resource* resource,
D3D12_RESOURCE_STATES resource_state);
@ -281,12 +304,12 @@ class D3D12TextureCache final : public TextureCache {
return old_state;
}
uint32_t GetSRVDescriptorIndex(uint32_t descriptor_key) const {
uint32_t GetSRVDescriptorIndex(SRVDescriptorKey descriptor_key) const {
auto it = srv_descriptors_.find(descriptor_key);
return it != srv_descriptors_.cend() ? it->second : UINT32_MAX;
}
void AddSRVDescriptorIndex(uint32_t descriptor_key,
void AddSRVDescriptorIndex(SRVDescriptorKey descriptor_key,
uint32_t descriptor_index) {
srv_descriptors_.emplace(descriptor_key, descriptor_index);
}
@ -299,7 +322,8 @@ class D3D12TextureCache final : public TextureCache {
// copying to the shader-visible heap (much faster than recreating, which,
// according to profiling, was often a bottleneck in many games).
// For bindless - indices in the global shader-visible descriptor heap.
std::unordered_map<uint32_t, uint32_t> srv_descriptors_;
std::unordered_map<SRVDescriptorKey, uint32_t, SRVDescriptorKey::Hasher>
srv_descriptors_;
};
static constexpr uint32_t kSRVDescriptorCachePageSize = 65536;