vulkan: Fix rescaling push constant usage
This commit is contained in:
parent
b7ccc58f23
commit
618de4e787
8 changed files with 78 additions and 69 deletions
|
@ -22,7 +22,6 @@
|
|||
namespace Vulkan {
|
||||
|
||||
using Shader::Backend::SPIRV::NUM_TEXTURE_AND_IMAGE_SCALING_WORDS;
|
||||
using Shader::Backend::SPIRV::RESCALING_PUSH_CONSTANT_WORDS_OFFSET;
|
||||
|
||||
class DescriptorLayoutBuilder {
|
||||
public:
|
||||
|
@ -73,12 +72,12 @@ public:
|
|||
|
||||
vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const {
|
||||
using Shader::Backend::SPIRV::RescalingLayout;
|
||||
const u32 push_offset = is_compute ? RESCALING_PUSH_CONSTANT_WORDS_OFFSET : 0;
|
||||
const u32 size_offset = is_compute ? sizeof(RescalingLayout::down_factor) : 0u;
|
||||
const VkPushConstantRange range{
|
||||
.stageFlags = static_cast<VkShaderStageFlags>(
|
||||
is_compute ? VK_SHADER_STAGE_COMPUTE_BIT : VK_SHADER_STAGE_ALL_GRAPHICS),
|
||||
.offset = 0,
|
||||
.size = sizeof(RescalingLayout) - push_offset,
|
||||
.size = sizeof(RescalingLayout) - size_offset,
|
||||
};
|
||||
return device->GetLogical().CreatePipelineLayout({
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
|
@ -139,21 +138,21 @@ private:
|
|||
|
||||
class RescalingPushConstant {
|
||||
public:
|
||||
explicit RescalingPushConstant(u32 num_textures) noexcept {}
|
||||
explicit RescalingPushConstant() noexcept {}
|
||||
|
||||
void PushTexture(bool is_rescaled) noexcept {
|
||||
*texture_ptr |= is_rescaled ? texture_bit : 0;
|
||||
texture_bit <<= 1;
|
||||
if (texture_bit == 0) {
|
||||
*texture_ptr |= is_rescaled ? texture_bit : 0u;
|
||||
texture_bit <<= 1u;
|
||||
if (texture_bit == 0u) {
|
||||
texture_bit = 1u;
|
||||
++texture_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
void PushImage(bool is_rescaled) noexcept {
|
||||
*image_ptr |= is_rescaled ? image_bit : 0;
|
||||
image_bit <<= 1;
|
||||
if (image_bit == 0) {
|
||||
*image_ptr |= is_rescaled ? image_bit : 0u;
|
||||
image_bit <<= 1u;
|
||||
if (image_bit == 0u) {
|
||||
image_bit = 1u;
|
||||
++image_ptr;
|
||||
}
|
||||
|
@ -176,8 +175,10 @@ inline void PushImageDescriptors(TextureCache& texture_cache,
|
|||
const Shader::Info& info, RescalingPushConstant& rescaling,
|
||||
const VkSampler*& samplers,
|
||||
const VideoCommon::ImageViewInOut*& views) {
|
||||
views += Shader::NumDescriptors(info.texture_buffer_descriptors);
|
||||
views += Shader::NumDescriptors(info.image_buffer_descriptors);
|
||||
const u32 num_texture_buffers = Shader::NumDescriptors(info.texture_buffer_descriptors);
|
||||
const u32 num_image_buffers = Shader::NumDescriptors(info.image_buffer_descriptors);
|
||||
views += num_texture_buffers;
|
||||
views += num_image_buffers;
|
||||
for (const auto& desc : info.texture_descriptors) {
|
||||
for (u32 index = 0; index < desc.count; ++index) {
|
||||
const VideoCommon::ImageViewId image_view_id{(views++)->id};
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
namespace Vulkan {
|
||||
|
||||
using Shader::ImageBufferDescriptor;
|
||||
using Shader::Backend::SPIRV::RESCALING_LAYOUT_WORDS_OFFSET;
|
||||
using Tegra::Texture::TexturePair;
|
||||
|
||||
ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descriptor_pool,
|
||||
|
@ -185,7 +186,7 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
|
|||
buffer_cache.UpdateComputeBuffers();
|
||||
buffer_cache.BindHostComputeBuffers();
|
||||
|
||||
RescalingPushConstant rescaling(num_textures);
|
||||
RescalingPushConstant rescaling;
|
||||
const VkSampler* samplers_it{samplers.data()};
|
||||
const VideoCommon::ImageViewInOut* views_it{views.data()};
|
||||
PushImageDescriptors(texture_cache, update_descriptor_queue, info, rescaling, samplers_it,
|
||||
|
@ -199,21 +200,24 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
|
|||
});
|
||||
}
|
||||
const void* const descriptor_data{update_descriptor_queue.UpdateData()};
|
||||
scheduler.Record(
|
||||
[this, descriptor_data, rescaling_data = rescaling.Data()](vk::CommandBuffer cmdbuf) {
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
|
||||
if (!descriptor_set_layout) {
|
||||
return;
|
||||
}
|
||||
if (num_textures > 0) {
|
||||
cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, rescaling_data);
|
||||
}
|
||||
const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()};
|
||||
const vk::Device& dev{device.GetLogical()};
|
||||
dev.UpdateDescriptorSet(descriptor_set, *descriptor_update_template, descriptor_data);
|
||||
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline_layout, 0,
|
||||
descriptor_set, nullptr);
|
||||
});
|
||||
const bool is_rescaling = !info.texture_descriptors.empty() || !info.image_descriptors.empty();
|
||||
scheduler.Record([this, descriptor_data, is_rescaling,
|
||||
rescaling_data = rescaling.Data()](vk::CommandBuffer cmdbuf) {
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
|
||||
if (!descriptor_set_layout) {
|
||||
return;
|
||||
}
|
||||
if (is_rescaling) {
|
||||
cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
RESCALING_LAYOUT_WORDS_OFFSET, sizeof(rescaling_data),
|
||||
rescaling_data.data());
|
||||
}
|
||||
const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()};
|
||||
const vk::Device& dev{device.GetLogical()};
|
||||
dev.UpdateDescriptorSet(descriptor_set, *descriptor_update_template, descriptor_data);
|
||||
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline_layout, 0,
|
||||
descriptor_set, nullptr);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
|
|
|
@ -59,7 +59,6 @@ private:
|
|||
vk::PipelineLayout pipeline_layout;
|
||||
vk::DescriptorUpdateTemplateKHR descriptor_update_template;
|
||||
vk::Pipeline pipeline;
|
||||
u32 num_textures{};
|
||||
|
||||
std::condition_variable build_condvar;
|
||||
std::mutex build_mutex;
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace {
|
|||
using boost::container::small_vector;
|
||||
using boost::container::static_vector;
|
||||
using Shader::ImageBufferDescriptor;
|
||||
using Shader::Backend::SPIRV::RESCALING_LAYOUT_DOWN_FACTOR_OFFSET;
|
||||
using Shader::Backend::SPIRV::RESCALING_LAYOUT_WORDS_OFFSET;
|
||||
using Tegra::Texture::TexturePair;
|
||||
using VideoCore::Surface::PixelFormat;
|
||||
using VideoCore::Surface::PixelFormatFromDepthFormat;
|
||||
|
@ -431,7 +433,7 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) {
|
|||
|
||||
update_descriptor_queue.Acquire();
|
||||
|
||||
RescalingPushConstant rescaling(num_textures);
|
||||
RescalingPushConstant rescaling;
|
||||
const VkSampler* samplers_it{samplers.data()};
|
||||
const VideoCommon::ImageViewInOut* views_it{views.data()};
|
||||
const auto prepare_stage{[&](size_t stage) LAMBDA_FORCEINLINE {
|
||||
|
@ -477,15 +479,16 @@ void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling) {
|
|||
if (bind_pipeline) {
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
|
||||
}
|
||||
cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||
RESCALING_LAYOUT_WORDS_OFFSET, sizeof(rescaling_data),
|
||||
rescaling_data.data());
|
||||
if (update_rescaling) {
|
||||
const f32 config_down_factor{Settings::values.resolution_info.down_factor};
|
||||
const f32 scale_down_factor{is_rescaling ? config_down_factor : 1.0f};
|
||||
cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS, 0,
|
||||
sizeof(scale_down_factor), &scale_down_factor);
|
||||
cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||
RESCALING_LAYOUT_DOWN_FACTOR_OFFSET, sizeof(scale_down_factor),
|
||||
&scale_down_factor);
|
||||
}
|
||||
cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||
RESCALING_PUSH_CONSTANT_WORDS_OFFSET, sizeof(rescaling_data),
|
||||
rescaling_data.data());
|
||||
if (!descriptor_set_layout) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue