forked from ShuriZma/suyu
1
0
Fork 0

buffer_cache: Mark uniform buffers as dirty if any enable bit changes

This commit is contained in:
ReinUsesLisp 2021-05-30 02:57:42 -03:00 committed by ameerj
parent 329dea217d
commit a7e9756671
5 changed files with 17 additions and 7 deletions

View File

@ -142,7 +142,7 @@ public:
void BindHostComputeBuffers(); void BindHostComputeBuffers();
void SetEnabledUniformBuffers(size_t stage, u32 enabled); void SetEnabledUniformBuffers(const std::array<u32, NUM_STAGES>& mask);
void SetEnabledComputeUniformBuffers(u32 enabled); void SetEnabledComputeUniformBuffers(u32 enabled);
@ -670,13 +670,13 @@ void BufferCache<P>::BindHostComputeBuffers() {
} }
template <class P> template <class P>
void BufferCache<P>::SetEnabledUniformBuffers(size_t stage, u32 enabled) { void BufferCache<P>::SetEnabledUniformBuffers(const std::array<u32, NUM_STAGES>& mask) {
if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) {
if (enabled_uniform_buffers[stage] != enabled) { if (enabled_uniform_buffers != mask) {
dirty_uniform_buffers[stage] = ~u32{0}; dirty_uniform_buffers.fill(~u32{0});
} }
} }
enabled_uniform_buffers[stage] = enabled; enabled_uniform_buffers = mask;
} }
template <class P> template <class P>

View File

@ -100,6 +100,8 @@ GraphicsPipeline::GraphicsPipeline(const Device& device, TextureCache& texture_c
base_uniform_bindings[stage + 1] += AccumulateCount(info.constant_buffer_descriptors); base_uniform_bindings[stage + 1] += AccumulateCount(info.constant_buffer_descriptors);
base_storage_bindings[stage + 1] += AccumulateCount(info.storage_buffers_descriptors); base_storage_bindings[stage + 1] += AccumulateCount(info.storage_buffers_descriptors);
} }
enabled_uniform_buffers[stage] = info.constant_buffer_mask;
const u32 num_tex_buffer_bindings{AccumulateCount(info.texture_buffer_descriptors)}; const u32 num_tex_buffer_bindings{AccumulateCount(info.texture_buffer_descriptors)};
num_texture_buffers[stage] += num_tex_buffer_bindings; num_texture_buffers[stage] += num_tex_buffer_bindings;
num_textures += num_tex_buffer_bindings; num_textures += num_tex_buffer_bindings;
@ -145,6 +147,7 @@ void GraphicsPipeline::Configure(bool is_indexed) {
texture_cache.SynchronizeGraphicsDescriptors(); texture_cache.SynchronizeGraphicsDescriptors();
buffer_cache.SetEnabledUniformBuffers(enabled_uniform_buffers);
buffer_cache.runtime.SetBaseUniformBindings(base_uniform_bindings); buffer_cache.runtime.SetBaseUniformBindings(base_uniform_bindings);
buffer_cache.runtime.SetBaseStorageBindings(base_storage_bindings); buffer_cache.runtime.SetBaseStorageBindings(base_storage_bindings);
buffer_cache.runtime.SetEnableStorageBuffers(use_storage_buffers); buffer_cache.runtime.SetEnableStorageBuffers(use_storage_buffers);
@ -153,7 +156,6 @@ void GraphicsPipeline::Configure(bool is_indexed) {
const bool via_header_index{regs.sampler_index == Maxwell::SamplerIndex::ViaHeaderIndex}; const bool via_header_index{regs.sampler_index == Maxwell::SamplerIndex::ViaHeaderIndex};
const auto config_stage{[&](size_t stage) { const auto config_stage{[&](size_t stage) {
const Shader::Info& info{stage_infos[stage]}; const Shader::Info& info{stage_infos[stage]};
buffer_cache.SetEnabledUniformBuffers(stage, info.constant_buffer_mask);
buffer_cache.UnbindGraphicsStorageBuffers(stage); buffer_cache.UnbindGraphicsStorageBuffers(stage);
if constexpr (Spec::has_storage_buffers) { if constexpr (Spec::has_storage_buffers) {
size_t ssbo_index{}; size_t ssbo_index{};

View File

@ -99,6 +99,7 @@ private:
u32 enabled_stages_mask{}; u32 enabled_stages_mask{};
std::array<Shader::Info, 5> stage_infos{}; std::array<Shader::Info, 5> stage_infos{};
std::array<u32, 5> enabled_uniform_buffers{};
std::array<u32, 5> base_uniform_bindings{}; std::array<u32, 5> base_uniform_bindings{};
std::array<u32, 5> base_storage_bindings{}; std::array<u32, 5> base_storage_bindings{};
std::array<u32, 5> num_texture_buffers{}; std::array<u32, 5> num_texture_buffers{};

View File

@ -218,6 +218,9 @@ GraphicsPipeline::GraphicsPipeline(Tegra::Engines::Maxwell3D& maxwell3d_,
update_descriptor_queue{update_descriptor_queue_}, spv_modules{std::move(stages)} { update_descriptor_queue{update_descriptor_queue_}, spv_modules{std::move(stages)} {
std::ranges::transform(infos, stage_infos.begin(), std::ranges::transform(infos, stage_infos.begin(),
[](const Shader::Info* info) { return info ? *info : Shader::Info{}; }); [](const Shader::Info* info) { return info ? *info : Shader::Info{}; });
std::ranges::transform(infos, enabled_uniform_buffers.begin(), [](const Shader::Info* info) {
return info ? info->constant_buffer_mask : 0;
});
auto func{[this, &render_pass_cache, &descriptor_pool] { auto func{[this, &render_pass_cache, &descriptor_pool] {
DescriptorLayoutBuilder builder{MakeBuilder(device, stage_infos)}; DescriptorLayoutBuilder builder{MakeBuilder(device, stage_infos)};
@ -259,11 +262,12 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) {
texture_cache.SynchronizeGraphicsDescriptors(); texture_cache.SynchronizeGraphicsDescriptors();
buffer_cache.SetEnabledUniformBuffers(enabled_uniform_buffers);
const auto& regs{maxwell3d.regs}; const auto& regs{maxwell3d.regs};
const bool via_header_index{regs.sampler_index == Maxwell::SamplerIndex::ViaHeaderIndex}; const bool via_header_index{regs.sampler_index == Maxwell::SamplerIndex::ViaHeaderIndex};
const auto config_stage{[&](size_t stage) LAMBDA_FORCEINLINE { const auto config_stage{[&](size_t stage) LAMBDA_FORCEINLINE {
const Shader::Info& info{stage_infos[stage]}; const Shader::Info& info{stage_infos[stage]};
buffer_cache.SetEnabledUniformBuffers(stage, info.constant_buffer_mask);
buffer_cache.UnbindGraphicsStorageBuffers(stage); buffer_cache.UnbindGraphicsStorageBuffers(stage);
if constexpr (Spec::has_storage_buffers) { if constexpr (Spec::has_storage_buffers) {
size_t ssbo_index{}; size_t ssbo_index{};

View File

@ -128,7 +128,10 @@ private:
std::vector<GraphicsPipeline*> transitions; std::vector<GraphicsPipeline*> transitions;
std::array<vk::ShaderModule, NUM_STAGES> spv_modules; std::array<vk::ShaderModule, NUM_STAGES> spv_modules;
std::array<Shader::Info, NUM_STAGES> stage_infos; std::array<Shader::Info, NUM_STAGES> stage_infos;
std::array<u32, 5> enabled_uniform_buffers{};
vk::DescriptorSetLayout descriptor_set_layout; vk::DescriptorSetLayout descriptor_set_layout;
DescriptorAllocator descriptor_allocator; DescriptorAllocator descriptor_allocator;
vk::PipelineLayout pipeline_layout; vk::PipelineLayout pipeline_layout;