[D3D12] Don't create SRVs if textures not changed

This commit is contained in:
Triang3l
2018-10-04 14:36:48 +03:00
parent b77ffe3df6
commit 131525e44d
4 changed files with 108 additions and 44 deletions

View File

@@ -9,6 +9,8 @@
#include "xenia/gpu/d3d12/texture_cache.h"
#include "third_party/xxhash/xxhash.h"
#include <algorithm>
#include <cstring>
@@ -292,7 +294,11 @@ TextureCache::TextureCache(D3D12CommandProcessor* command_processor,
SharedMemory* shared_memory)
: command_processor_(command_processor),
register_file_(register_file),
shared_memory_(shared_memory) {}
shared_memory_(shared_memory) {
XXH64_state_t hash_state;
XXH64_reset(&hash_state, 0);
texture_bindings_empty_hash_ = XXH64_digest(&hash_state);
}
TextureCache::~TextureCache() { Shutdown(); }
@@ -427,7 +433,9 @@ void TextureCache::EndFrame() {
}
void TextureCache::RequestTextures(uint32_t used_vertex_texture_mask,
uint32_t used_pixel_texture_mask) {
uint32_t used_pixel_texture_mask,
uint64_t& descriptor_layout_vertex_hash_out,
uint64_t& descriptor_layout_pixel_hash_out) {
auto command_list = command_processor_->GetCurrentCommandList();
if (command_list == nullptr) {
return;
@@ -498,6 +506,31 @@ void TextureCache::RequestTextures(uint32_t used_vertex_texture_mask,
state);
texture->state = state;
}
// Compute descriptor layout hashes so descriptors don't have to be written
// again if the bindings are the same. The hash is computed from indices, keys
// and swizzles.
XXH64_state_t hash_state;
XXH64_reset(&hash_state, 0);
used_texture_mask = used_vertex_texture_mask;
while (xe::bit_scan_forward(used_texture_mask, &index)) {
used_texture_mask &= ~(1u << index);
XXH64_update(&hash_state, &index, sizeof(index));
const TextureBinding& binding = texture_bindings_[index];
XXH64_update(&hash_state, &binding.key, sizeof(binding.key));
XXH64_update(&hash_state, &binding.swizzle, sizeof(binding.swizzle));
}
descriptor_layout_vertex_hash_out = XXH64_digest(&hash_state);
XXH64_reset(&hash_state, 0);
used_texture_mask = used_pixel_texture_mask;
while (xe::bit_scan_forward(used_texture_mask, &index)) {
used_texture_mask &= ~(1u << index);
XXH64_update(&hash_state, &index, sizeof(index));
const TextureBinding& binding = texture_bindings_[index];
XXH64_update(&hash_state, &binding.key, sizeof(binding.key));
XXH64_update(&hash_state, &binding.swizzle, sizeof(binding.swizzle));
}
descriptor_layout_pixel_hash_out = XXH64_digest(&hash_state);
}
void TextureCache::WriteTextureSRV(uint32_t fetch_constant,