diff --git a/src/xenia/gpu/d3d12/d3d12_texture_cache.cc b/src/xenia/gpu/d3d12/d3d12_texture_cache.cc index ce38c1cba..72233c79f 100644 --- a/src/xenia/gpu/d3d12/d3d12_texture_cache.cc +++ b/src/xenia/gpu/d3d12/d3d12_texture_cache.cc @@ -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 = diff --git a/src/xenia/gpu/d3d12/d3d12_texture_cache.h b/src/xenia/gpu/d3d12/d3d12_texture_cache.h index a398cd941..2dd418fbd 100644 --- a/src/xenia/gpu/d3d12/d3d12_texture_cache.h +++ b/src/xenia/gpu/d3d12/d3d12_texture_cache.h @@ -11,6 +11,7 @@ #define XENIA_GPU_D3D12_D3D12_TEXTURE_CACHE_H_ #include +#include #include #include #include @@ -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{}(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 srv_descriptors_; + std::unordered_map + srv_descriptors_; }; static constexpr uint32_t kSRVDescriptorCachePageSize = 65536;