Skip to content

Commit d432a42

Browse files
Temp
1 parent 2fe2dd1 commit d432a42

13 files changed

+83
-46
lines changed

Diff for: externals/dynarmic

Diff for: externals/teakra

Submodule teakra updated 77 files

Diff for: externals/teakra_interp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 01db7cdd00aabcce559a8dddce8798dabb71949b

Diff for: src/video_core/renderer_vulkan/renderer_vulkan.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void RendererVulkan::PrepareRendertarget() {
127127

128128
void RendererVulkan::PrepareDraw(Frame* frame, const Layout::FramebufferLayout& layout) {
129129
const auto sampler = present_samplers[!Settings::values.filter_mode.GetValue()];
130-
const auto present_set = present_heap.Commit();
130+
const auto [present_set, _] = present_heap.Commit();
131131
for (u32 index = 0; index < screen_infos.size(); index++) {
132132
update_queue.AddImageSampler(present_set, 0, index, screen_infos[index].image_view,
133133
sampler);

Diff for: src/video_core/renderer_vulkan/vk_blit_helper.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ bool BlitHelper::BlitDepthStencil(Surface& source, Surface& dest,
284284
.extent = {dest.GetScaledWidth(), dest.GetScaledHeight()},
285285
};
286286

287-
const auto descriptor_set = two_textures_provider.Commit();
287+
const auto [descriptor_set, _] = two_textures_provider.Commit();
288288
update_queue.AddImageSampler(descriptor_set, 0, 0, source.DepthView(), nearest_sampler);
289289
update_queue.AddImageSampler(descriptor_set, 1, 0, source.StencilView(), nearest_sampler);
290290

@@ -309,7 +309,7 @@ bool BlitHelper::BlitDepthStencil(Surface& source, Surface& dest,
309309

310310
bool BlitHelper::ConvertDS24S8ToRGBA8(Surface& source, Surface& dest,
311311
const VideoCore::TextureCopy& copy) {
312-
const auto descriptor_set = compute_provider.Commit();
312+
const auto [descriptor_set, _] = compute_provider.Commit();
313313
update_queue.AddImageSampler(descriptor_set, 0, 0, source.DepthView(), VK_NULL_HANDLE,
314314
vk::ImageLayout::eDepthStencilReadOnlyOptimal);
315315
update_queue.AddImageSampler(descriptor_set, 1, 0, source.StencilView(), VK_NULL_HANDLE,
@@ -420,7 +420,7 @@ bool BlitHelper::ConvertDS24S8ToRGBA8(Surface& source, Surface& dest,
420420

421421
bool BlitHelper::DepthToBuffer(Surface& source, vk::Buffer buffer,
422422
const VideoCore::BufferTextureCopy& copy) {
423-
const auto descriptor_set = compute_buffer_provider.Commit();
423+
const auto [descriptor_set, _] = compute_buffer_provider.Commit();
424424
update_queue.AddImageSampler(descriptor_set, 0, 0, source.DepthView(), nearest_sampler,
425425
vk::ImageLayout::eDepthStencilReadOnlyOptimal);
426426
update_queue.AddImageSampler(descriptor_set, 1, 0, source.StencilView(), nearest_sampler,

Diff for: src/video_core/renderer_vulkan/vk_pipeline_cache.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class PipelineCache {
4545
~PipelineCache();
4646

4747
/// Acquires and binds a free descriptor set from the appropriate heap.
48-
vk::DescriptorSet Acquire(DescriptorHeapType type) {
48+
vk::DescriptorSet Acquire(DescriptorHeapType type, std::size_t hash = 0) {
4949
const u32 index = static_cast<u32>(type);
50-
const auto descriptor_set = descriptor_heaps[index].Commit();
50+
const auto [descriptor_set, requires_update] = descriptor_heaps[index].Commit(hash);
5151
bound_descriptor_sets[index] = descriptor_set;
52-
return descriptor_set;
52+
return requires_update ? descriptor_set : VK_NULL_HANDLE;
5353
}
5454

5555
/// Sets the dynamic offset for the uniform buffer at binding

Diff for: src/video_core/renderer_vulkan/vk_rasterizer.cpp

+41-27
Original file line numberDiff line numberDiff line change
@@ -559,20 +559,17 @@ void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
559559
using TextureType = Pica::TexturingRegs::TextureConfig::TextureType;
560560

561561
const auto pica_textures = regs.texturing.GetTextures();
562-
const bool use_cube_heap =
563-
pica_textures[0].enabled && pica_textures[0].config.type == TextureType::ShadowCube;
564-
const auto texture_set = pipeline_cache.Acquire(use_cube_heap ? DescriptorHeapType::Texture
565-
: DescriptorHeapType::Texture);
566-
567562
for (u32 texture_index = 0; texture_index < pica_textures.size(); ++texture_index) {
568563
const auto& texture = pica_textures[texture_index];
569564

570565
// If the texture unit is disabled bind a null surface to it
571566
if (!texture.enabled) {
572567
const Surface& null_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_ID);
573568
const Sampler& null_sampler = res_cache.GetSampler(VideoCore::NULL_SAMPLER_ID);
574-
update_queue.AddImageSampler(texture_set, texture_index, 0, null_surface.ImageView(),
575-
null_sampler.Handle());
569+
images[texture_index] = {
570+
.sampler = null_sampler.Handle(),
571+
.imageView = null_surface.ImageView(),
572+
};
576573
continue;
577574
}
578575

@@ -583,16 +580,18 @@ void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
583580
Surface& surface = res_cache.GetTextureSurface(texture);
584581
Sampler& sampler = res_cache.GetSampler(texture.config);
585582
surface.flags |= VideoCore::SurfaceFlagBits::ShadowMap;
586-
update_queue.AddImageSampler(texture_set, texture_index, 0, surface.StorageView(),
587-
sampler.Handle());
583+
images[texture_index] = {
584+
.sampler = sampler.Handle(),
585+
.imageView = surface.StorageView(),
586+
};
588587
continue;
589588
}
590589
case TextureType::ShadowCube: {
591-
BindShadowCube(texture, texture_set);
590+
BindShadowCube(texture);
592591
continue;
593592
}
594593
case TextureType::TextureCube: {
595-
BindTextureCube(texture, texture_set);
594+
BindTextureCube(texture);
596595
continue;
597596
}
598597
default:
@@ -607,7 +606,21 @@ void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
607606
const bool is_feedback_loop = color_view == surface.ImageView();
608607
const vk::ImageView texture_view =
609608
is_feedback_loop ? surface.CopyImageView() : surface.ImageView();
610-
update_queue.AddImageSampler(texture_set, texture_index, 0, texture_view, sampler.Handle());
609+
images[texture_index] = {
610+
.sampler = sampler.Handle(),
611+
.imageView = texture_view,
612+
};
613+
}
614+
615+
const std::size_t hash = Common::ComputeStructHash64(images);
616+
const auto texture_set = pipeline_cache.Acquire(DescriptorHeapType::Texture, hash);
617+
if (!texture_set) {
618+
return;
619+
}
620+
621+
for (u32 texture_index = 0; texture_index < pica_textures.size(); texture_index++) {
622+
update_queue.AddImageSampler(texture_set, texture_index, 0,
623+
images[texture_index].imageView, images[texture_index].sampler);
611624
}
612625
}
613626

@@ -621,16 +634,15 @@ void RasterizerVulkan::SyncUtilityTextures(const Framebuffer* framebuffer) {
621634
update_queue.AddStorageImage(utility_set, 0, framebuffer->ImageView(SurfaceType::Color));
622635
}
623636

624-
void RasterizerVulkan::BindShadowCube(const Pica::TexturingRegs::FullTextureConfig& texture,
625-
vk::DescriptorSet texture_set) {
626-
using CubeFace = Pica::TexturingRegs::CubeFace;
627-
auto info = Pica::Texture::TextureInfo::FromPicaRegister(texture.config, texture.format);
628-
constexpr std::array faces = {
629-
CubeFace::PositiveX, CubeFace::NegativeX, CubeFace::PositiveY,
630-
CubeFace::NegativeY, CubeFace::PositiveZ, CubeFace::NegativeZ,
631-
};
637+
void RasterizerVulkan::BindShadowCube(const Pica::TexturingRegs::FullTextureConfig& texture) {
638+
//using CubeFace = Pica::TexturingRegs::CubeFace;
639+
//auto info = Pica::Texture::TextureInfo::FromPicaRegister(texture.config, texture.format);
640+
//constexpr std::array faces = {
641+
// CubeFace::PositiveX, CubeFace::NegativeX, CubeFace::PositiveY,
642+
// CubeFace::NegativeY, CubeFace::PositiveZ, CubeFace::NegativeZ,
643+
//};
632644

633-
Sampler& sampler = res_cache.GetSampler(texture.config);
645+
/*Sampler& sampler = res_cache.GetSampler(texture.config);
634646
635647
for (CubeFace face : faces) {
636648
const u32 binding = static_cast<u32>(face);
@@ -639,13 +651,12 @@ void RasterizerVulkan::BindShadowCube(const Pica::TexturingRegs::FullTextureConf
639651
const VideoCore::SurfaceId surface_id = res_cache.GetTextureSurface(info);
640652
Surface& surface = res_cache.GetSurface(surface_id);
641653
surface.flags |= VideoCore::SurfaceFlagBits::ShadowMap;
642-
update_queue.AddImageSampler(texture_set, 0, binding, surface.StorageView(),
643-
sampler.Handle());
644-
}
654+
//update_queue.AddImageSampler(texture_set, 0, binding, surface.StorageView(),
655+
// sampler.Handle());
656+
}*/
645657
}
646658

647-
void RasterizerVulkan::BindTextureCube(const Pica::TexturingRegs::FullTextureConfig& texture,
648-
vk::DescriptorSet texture_set) {
659+
void RasterizerVulkan::BindTextureCube(const Pica::TexturingRegs::FullTextureConfig& texture) {
649660
using CubeFace = Pica::TexturingRegs::CubeFace;
650661
const VideoCore::TextureCubeConfig config = {
651662
.px = regs.texturing.GetCubePhysicalAddress(CubeFace::PositiveX),
@@ -661,7 +672,10 @@ void RasterizerVulkan::BindTextureCube(const Pica::TexturingRegs::FullTextureCon
661672

662673
Surface& surface = res_cache.GetTextureCube(config);
663674
Sampler& sampler = res_cache.GetSampler(texture.config);
664-
update_queue.AddImageSampler(texture_set, 0, 0, surface.ImageView(), sampler.Handle());
675+
images[0] = {
676+
.sampler = sampler.Handle(),
677+
.imageView = surface.ImageView(),
678+
};
665679
}
666680

667681
void RasterizerVulkan::NotifyFixedFunctionPicaRegisterChanged(u32 id) {

Diff for: src/video_core/renderer_vulkan/vk_rasterizer.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ class RasterizerVulkan : public VideoCore::RasterizerAccelerated {
107107
void SyncUtilityTextures(const Framebuffer* framebuffer);
108108

109109
/// Binds the PICA shadow cube required for shadow mapping
110-
void BindShadowCube(const Pica::TexturingRegs::FullTextureConfig& texture,
111-
vk::DescriptorSet texture_set);
110+
void BindShadowCube(const Pica::TexturingRegs::FullTextureConfig& texture);
112111

113112
/// Binds a texture cube to texture unit 0
114-
void BindTextureCube(const Pica::TexturingRegs::FullTextureConfig& texture,
115-
vk::DescriptorSet texture_set);
113+
void BindTextureCube(const Pica::TexturingRegs::FullTextureConfig& texture);
116114

117115
/// Upload the uniform blocks to the uniform buffer object
118116
void UploadUniforms(bool accelerate_draw);
@@ -154,6 +152,7 @@ class RasterizerVulkan : public VideoCore::RasterizerAccelerated {
154152
std::array<u32, 16> binding_offsets{};
155153
std::array<bool, 16> enable_attributes{};
156154
std::array<vk::Buffer, 16> vertex_buffers;
155+
std::array<vk::DescriptorImageInfo, 3> images{};
157156
VertexArrayInfo vertex_info;
158157
PipelineInfo pipeline_info{};
159158

Diff for: src/video_core/renderer_vulkan/vk_resource_pool.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ DescriptorHeap::~DescriptorHeap() = default;
140140
void DescriptorHeap::Allocate(std::size_t begin, std::size_t end) {
141141
ASSERT(end - begin == DESCRIPTOR_SET_BATCH);
142142
descriptor_sets.resize(end);
143+
hashes.resize(end);
143144

144145
std::array<vk::DescriptorSetLayout, DESCRIPTOR_SET_BATCH> layouts;
145146
layouts.fill(*descriptor_set_layout);
@@ -170,9 +171,27 @@ void DescriptorHeap::Allocate(std::size_t begin, std::size_t end) {
170171
}
171172
}
172173

173-
vk::DescriptorSet DescriptorHeap::Commit() {
174+
std::pair<vk::DescriptorSet, bool> DescriptorHeap::Commit(std::size_t hash) {
175+
if (hash == 0) {
176+
const std::size_t index = CommitResource();
177+
return {descriptor_sets[index], true};
178+
}
179+
180+
// Try to recycle an existing descriptor set that matches the content hash.
181+
const auto it = descriptor_content_map.find(hash);
182+
if (it != descriptor_content_map.end()) {
183+
ticks[it->second] = master_semaphore->CurrentTick();
184+
return {descriptor_sets[it->second], false};
185+
}
186+
187+
// No descriptor set found, provide a fresh one
174188
const std::size_t index = CommitResource();
175-
return descriptor_sets[index];
189+
if (hashes[index] != 0) {
190+
descriptor_content_map.erase(hashes[index]);
191+
}
192+
descriptor_content_map[hash] = index;
193+
hashes[index] = hash;
194+
return {descriptor_sets[index], true};
176195
}
177196

178197
void DescriptorHeap::AppendDescriptorPool() {

Diff for: src/video_core/renderer_vulkan/vk_resource_pool.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#pragma once
66

77
#include <vector>
8+
#include <tsl/robin_map.h>
9+
810
#include "common/common_types.h"
911
#include "video_core/renderer_vulkan/vk_common.h"
1012

@@ -74,7 +76,7 @@ class DescriptorHeap final : public ResourcePool {
7476

7577
void Allocate(std::size_t begin, std::size_t end) override;
7678

77-
vk::DescriptorSet Commit();
79+
std::pair<vk::DescriptorSet, bool> Commit(std::size_t hash = 0);
7880

7981
private:
8082
void AppendDescriptorPool();
@@ -86,6 +88,8 @@ class DescriptorHeap final : public ResourcePool {
8688
std::vector<vk::DescriptorPoolSize> pool_sizes;
8789
std::vector<vk::UniqueDescriptorPool> pools;
8890
std::vector<vk::DescriptorSet> descriptor_sets;
91+
std::vector<std::size_t> hashes;
92+
tsl::robin_map<std::size_t, std::size_t> descriptor_content_map;
8993
};
9094

9195
} // namespace Vulkan

0 commit comments

Comments
 (0)