mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-21 11:26:56 +02:00
render: clean up image setup and tiler recording
This commit is contained in:
@@ -23,7 +23,6 @@ BlitHelper::BlitHelper(GraphicContext& graphics, CommandScheduler& scheduler)
|
|||||||
texture_binding.stageFlags = vk::ShaderStageFlagBits::eFragment;
|
texture_binding.stageFlags = vk::ShaderStageFlagBits::eFragment;
|
||||||
|
|
||||||
vk::DescriptorSetLayoutCreateInfo descriptor_info {};
|
vk::DescriptorSetLayoutCreateInfo descriptor_info {};
|
||||||
descriptor_info.sType = vk::StructureType::eDescriptorSetLayoutCreateInfo;
|
|
||||||
descriptor_info.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR;
|
descriptor_info.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR;
|
||||||
descriptor_info.bindingCount = 1;
|
descriptor_info.bindingCount = 1;
|
||||||
descriptor_info.pBindings = &texture_binding;
|
descriptor_info.pBindings = &texture_binding;
|
||||||
@@ -32,7 +31,6 @@ BlitHelper::BlitHelper(GraphicContext& graphics, CommandScheduler& scheduler)
|
|||||||
"create BlitHelper descriptor layout");
|
"create BlitHelper descriptor layout");
|
||||||
|
|
||||||
vk::PipelineLayoutCreateInfo layout_info {};
|
vk::PipelineLayoutCreateInfo layout_info {};
|
||||||
layout_info.sType = vk::StructureType::ePipelineLayoutCreateInfo;
|
|
||||||
layout_info.setLayoutCount = 1;
|
layout_info.setLayoutCount = 1;
|
||||||
layout_info.pSetLayouts = &m_descriptor_layout;
|
layout_info.pSetLayouts = &m_descriptor_layout;
|
||||||
RequireVulkanSuccess(
|
RequireVulkanSuccess(
|
||||||
@@ -65,7 +63,6 @@ BlitHelper::~BlitHelper() {
|
|||||||
vk::ShaderModule BlitHelper::CreateShader(const uint32_t* code, size_t words) const {
|
vk::ShaderModule BlitHelper::CreateShader(const uint32_t* code, size_t words) const {
|
||||||
EXIT_IF(code == nullptr || words == 0);
|
EXIT_IF(code == nullptr || words == 0);
|
||||||
vk::ShaderModuleCreateInfo create {};
|
vk::ShaderModuleCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eShaderModuleCreateInfo;
|
|
||||||
create.codeSize = words * sizeof(uint32_t);
|
create.codeSize = words * sizeof(uint32_t);
|
||||||
create.pCode = code;
|
create.pCode = code;
|
||||||
vk::ShaderModule module = nullptr;
|
vk::ShaderModule module = nullptr;
|
||||||
@@ -84,51 +81,39 @@ vk::Pipeline BlitHelper::GetPipeline(PipelineKey key) {
|
|||||||
EXIT_IF(samples == vk::SampleCountFlagBits {} || key.format == vk::Format::eUndefined);
|
EXIT_IF(samples == vk::SampleCountFlagBits {} || key.format == vk::Format::eUndefined);
|
||||||
|
|
||||||
std::array<vk::PipelineShaderStageCreateInfo, 2> stages {};
|
std::array<vk::PipelineShaderStageCreateInfo, 2> stages {};
|
||||||
stages[0].sType = vk::StructureType::ePipelineShaderStageCreateInfo;
|
|
||||||
stages[0].stage = vk::ShaderStageFlagBits::eVertex;
|
stages[0].stage = vk::ShaderStageFlagBits::eVertex;
|
||||||
stages[0].module = m_vertex_shader;
|
stages[0].module = m_vertex_shader;
|
||||||
stages[0].pName = "main";
|
stages[0].pName = "main";
|
||||||
stages[1].sType = vk::StructureType::ePipelineShaderStageCreateInfo;
|
|
||||||
stages[1].stage = vk::ShaderStageFlagBits::eFragment;
|
stages[1].stage = vk::ShaderStageFlagBits::eFragment;
|
||||||
stages[1].module = m_fragment_shader;
|
stages[1].module = m_fragment_shader;
|
||||||
stages[1].pName = "main";
|
stages[1].pName = "main";
|
||||||
|
|
||||||
vk::PipelineVertexInputStateCreateInfo vertex_input {};
|
vk::PipelineVertexInputStateCreateInfo vertex_input {};
|
||||||
vertex_input.sType = vk::StructureType::ePipelineVertexInputStateCreateInfo;
|
|
||||||
vk::PipelineInputAssemblyStateCreateInfo input_assembly {};
|
vk::PipelineInputAssemblyStateCreateInfo input_assembly {};
|
||||||
input_assembly.sType = vk::StructureType::ePipelineInputAssemblyStateCreateInfo;
|
|
||||||
input_assembly.topology = vk::PrimitiveTopology::eTriangleList;
|
input_assembly.topology = vk::PrimitiveTopology::eTriangleList;
|
||||||
vk::PipelineViewportStateCreateInfo viewport {};
|
vk::PipelineViewportStateCreateInfo viewport {};
|
||||||
viewport.sType = vk::StructureType::ePipelineViewportStateCreateInfo;
|
|
||||||
viewport.viewportCount = 1;
|
viewport.viewportCount = 1;
|
||||||
viewport.scissorCount = 1;
|
viewport.scissorCount = 1;
|
||||||
vk::PipelineRasterizationStateCreateInfo rasterization {};
|
vk::PipelineRasterizationStateCreateInfo rasterization {};
|
||||||
rasterization.sType = vk::StructureType::ePipelineRasterizationStateCreateInfo;
|
|
||||||
rasterization.polygonMode = vk::PolygonMode::eFill;
|
rasterization.polygonMode = vk::PolygonMode::eFill;
|
||||||
rasterization.cullMode = vk::CullModeFlagBits::eNone;
|
rasterization.cullMode = vk::CullModeFlagBits::eNone;
|
||||||
rasterization.lineWidth = 1.0f;
|
rasterization.lineWidth = 1.0f;
|
||||||
vk::PipelineMultisampleStateCreateInfo multisample {};
|
vk::PipelineMultisampleStateCreateInfo multisample {};
|
||||||
multisample.sType = vk::StructureType::ePipelineMultisampleStateCreateInfo;
|
|
||||||
multisample.rasterizationSamples = samples;
|
multisample.rasterizationSamples = samples;
|
||||||
vk::PipelineDepthStencilStateCreateInfo depth {};
|
vk::PipelineDepthStencilStateCreateInfo depth {};
|
||||||
depth.sType = vk::StructureType::ePipelineDepthStencilStateCreateInfo;
|
|
||||||
depth.depthTestEnable = VK_TRUE;
|
depth.depthTestEnable = VK_TRUE;
|
||||||
depth.depthWriteEnable = VK_TRUE;
|
depth.depthWriteEnable = VK_TRUE;
|
||||||
depth.depthCompareOp = vk::CompareOp::eAlways;
|
depth.depthCompareOp = vk::CompareOp::eAlways;
|
||||||
vk::PipelineColorBlendStateCreateInfo color_blend {};
|
vk::PipelineColorBlendStateCreateInfo color_blend {};
|
||||||
color_blend.sType = vk::StructureType::ePipelineColorBlendStateCreateInfo;
|
|
||||||
const std::array dynamic_states {vk::DynamicState::eViewport, vk::DynamicState::eScissor};
|
const std::array dynamic_states {vk::DynamicState::eViewport, vk::DynamicState::eScissor};
|
||||||
vk::PipelineDynamicStateCreateInfo dynamic {};
|
vk::PipelineDynamicStateCreateInfo dynamic {};
|
||||||
dynamic.sType = vk::StructureType::ePipelineDynamicStateCreateInfo;
|
|
||||||
dynamic.dynamicStateCount = static_cast<uint32_t>(dynamic_states.size());
|
dynamic.dynamicStateCount = static_cast<uint32_t>(dynamic_states.size());
|
||||||
dynamic.pDynamicStates = dynamic_states.data();
|
dynamic.pDynamicStates = dynamic_states.data();
|
||||||
|
|
||||||
vk::PipelineRenderingCreateInfo rendering {};
|
vk::PipelineRenderingCreateInfo rendering {};
|
||||||
rendering.sType = vk::StructureType::ePipelineRenderingCreateInfo;
|
|
||||||
rendering.depthAttachmentFormat = key.format;
|
rendering.depthAttachmentFormat = key.format;
|
||||||
|
|
||||||
vk::GraphicsPipelineCreateInfo create {};
|
vk::GraphicsPipelineCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eGraphicsPipelineCreateInfo;
|
|
||||||
create.pNext = &rendering;
|
create.pNext = &rendering;
|
||||||
create.stageCount = static_cast<uint32_t>(stages.size());
|
create.stageCount = static_cast<uint32_t>(stages.size());
|
||||||
create.pStages = stages.data();
|
create.pStages = stages.data();
|
||||||
@@ -186,7 +171,6 @@ void BlitHelper::ReinterpretColorAsMsDepth(Image& source, Image& destination) {
|
|||||||
command);
|
command);
|
||||||
|
|
||||||
vk::RenderingAttachmentInfo depth_attachment {};
|
vk::RenderingAttachmentInfo depth_attachment {};
|
||||||
depth_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
|
|
||||||
depth_attachment.imageView = destination_view;
|
depth_attachment.imageView = destination_view;
|
||||||
depth_attachment.imageLayout = ColorToMsDepthLayout;
|
depth_attachment.imageLayout = ColorToMsDepthLayout;
|
||||||
depth_attachment.loadOp = vk::AttachmentLoadOp::eClear;
|
depth_attachment.loadOp = vk::AttachmentLoadOp::eClear;
|
||||||
@@ -194,7 +178,6 @@ void BlitHelper::ReinterpretColorAsMsDepth(Image& source, Image& destination) {
|
|||||||
depth_attachment.clearValue.depthStencil = {0.0f, 0};
|
depth_attachment.clearValue.depthStencil = {0.0f, 0};
|
||||||
|
|
||||||
vk::RenderingInfo rendering {};
|
vk::RenderingInfo rendering {};
|
||||||
rendering.sType = vk::StructureType::eRenderingInfo;
|
|
||||||
rendering.renderArea.extent = {destination_info.extent.width, destination_info.extent.height};
|
rendering.renderArea.extent = {destination_info.extent.width, destination_info.extent.height};
|
||||||
rendering.layerCount = 1;
|
rendering.layerCount = 1;
|
||||||
rendering.pDepthAttachment = &depth_attachment;
|
rendering.pDepthAttachment = &depth_attachment;
|
||||||
@@ -204,7 +187,6 @@ void BlitHelper::ReinterpretColorAsMsDepth(Image& source, Image& destination) {
|
|||||||
descriptor_image.imageView = source_view;
|
descriptor_image.imageView = source_view;
|
||||||
descriptor_image.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
|
descriptor_image.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
|
||||||
vk::WriteDescriptorSet descriptor_write {};
|
vk::WriteDescriptorSet descriptor_write {};
|
||||||
descriptor_write.sType = vk::StructureType::eWriteDescriptorSet;
|
|
||||||
descriptor_write.dstBinding = 0;
|
descriptor_write.dstBinding = 0;
|
||||||
descriptor_write.descriptorCount = 1;
|
descriptor_write.descriptorCount = 1;
|
||||||
descriptor_write.descriptorType = vk::DescriptorType::eSampledImage;
|
descriptor_write.descriptorType = vk::DescriptorType::eSampledImage;
|
||||||
|
|||||||
@@ -668,7 +668,6 @@ Image::Image(GraphicContext& graphics, CommandScheduler& scheduler, const ImageI
|
|||||||
backing.usage = ImageUsageFlags(graphics, info);
|
backing.usage = ImageUsageFlags(graphics, info);
|
||||||
|
|
||||||
vk::ImageCreateInfo create {};
|
vk::ImageCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eImageCreateInfo;
|
|
||||||
create.flags = backing.flags;
|
create.flags = backing.flags;
|
||||||
create.imageType = backing.image_type;
|
create.imageType = backing.image_type;
|
||||||
create.extent = backing.extent;
|
create.extent = backing.extent;
|
||||||
@@ -678,7 +677,6 @@ Image::Image(GraphicContext& graphics, CommandScheduler& scheduler, const ImageI
|
|||||||
create.tiling = vk::ImageTiling::eOptimal;
|
create.tiling = vk::ImageTiling::eOptimal;
|
||||||
create.initialLayout = backing.state.layout;
|
create.initialLayout = backing.state.layout;
|
||||||
create.usage = backing.usage;
|
create.usage = backing.usage;
|
||||||
create.sharingMode = vk::SharingMode::eExclusive;
|
|
||||||
create.samples = vulkan_sample_count(backing.samples);
|
create.samples = vulkan_sample_count(backing.samples);
|
||||||
|
|
||||||
vk::ImageFormatProperties properties {};
|
vk::ImageFormatProperties properties {};
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool IsCompatibleViewFormat(vk::Format image_format, vk::Format view_format) {
|
|
||||||
return ImageViewOps::FormatsCompatible(image_format, view_format);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool IsStencilViewFormat(vk::Format format) {
|
[[nodiscard]] bool IsStencilViewFormat(vk::Format format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case vk::Format::eS8Uint:
|
case vk::Format::eS8Uint:
|
||||||
@@ -327,7 +323,7 @@ vk::ImageView Image::FindView(const ImageViewInfo& view_info) {
|
|||||||
}
|
}
|
||||||
normalized.usage = is_storage ? vk::ImageUsageFlagBits::eStorage : vk::ImageUsageFlags {};
|
normalized.usage = is_storage ? vk::ImageUsageFlagBits::eStorage : vk::ImageUsageFlags {};
|
||||||
const bool format_compatible = normalized.format != vk::Format::eUndefined &&
|
const bool format_compatible = normalized.format != vk::Format::eUndefined &&
|
||||||
IsCompatibleViewFormat(image.format, normalized.format);
|
ImageViewOps::FormatsCompatible(image.format, normalized.format);
|
||||||
const bool slice_view =
|
const bool slice_view =
|
||||||
image.image_type == vk::ImageType::e3D && (normalized.type == vk::ImageViewType::e2D ||
|
image.image_type == vk::ImageType::e3D && (normalized.type == vk::ImageViewType::e2D ||
|
||||||
normalized.type == vk::ImageViewType::e2DArray);
|
normalized.type == vk::ImageViewType::e2DArray);
|
||||||
@@ -362,13 +358,11 @@ vk::ImageView Image::FindView(const ImageViewInfo& view_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vk::ImageViewUsageCreateInfo usage {};
|
vk::ImageViewUsageCreateInfo usage {};
|
||||||
usage.sType = vk::StructureType::eImageViewUsageCreateInfo;
|
|
||||||
usage.usage = image.usage;
|
usage.usage = image.usage;
|
||||||
if (!is_storage) {
|
if (!is_storage) {
|
||||||
usage.usage &= ~vk::ImageUsageFlagBits::eStorage;
|
usage.usage &= ~vk::ImageUsageFlagBits::eStorage;
|
||||||
}
|
}
|
||||||
vk::ImageViewCreateInfo create {};
|
vk::ImageViewCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eImageViewCreateInfo;
|
|
||||||
create.pNext = &usage;
|
create.pNext = &usage;
|
||||||
create.image = image.image;
|
create.image = image.image;
|
||||||
create.viewType = normalized.type;
|
create.viewType = normalized.type;
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ TileManager::TileManager(GraphicContext& graphics, CommandScheduler& scheduler,
|
|||||||
nullptr};
|
nullptr};
|
||||||
|
|
||||||
vk::DescriptorSetLayoutCreateInfo descriptor_info {};
|
vk::DescriptorSetLayoutCreateInfo descriptor_info {};
|
||||||
descriptor_info.sType = vk::StructureType::eDescriptorSetLayoutCreateInfo;
|
|
||||||
descriptor_info.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR;
|
descriptor_info.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR;
|
||||||
descriptor_info.bindingCount = static_cast<uint32_t>(bindings.size());
|
descriptor_info.bindingCount = static_cast<uint32_t>(bindings.size());
|
||||||
descriptor_info.pBindings = bindings.data();
|
descriptor_info.pBindings = bindings.data();
|
||||||
@@ -50,7 +49,6 @@ TileManager::TileManager(GraphicContext& graphics, CommandScheduler& scheduler,
|
|||||||
|
|
||||||
const vk::PushConstantRange push_range {vk::ShaderStageFlagBits::eCompute, 0, sizeof(Push)};
|
const vk::PushConstantRange push_range {vk::ShaderStageFlagBits::eCompute, 0, sizeof(Push)};
|
||||||
vk::PipelineLayoutCreateInfo layout_info {};
|
vk::PipelineLayoutCreateInfo layout_info {};
|
||||||
layout_info.sType = vk::StructureType::ePipelineLayoutCreateInfo;
|
|
||||||
layout_info.setLayoutCount = 1;
|
layout_info.setLayoutCount = 1;
|
||||||
layout_info.pSetLayouts = &m_descriptor_layout;
|
layout_info.pSetLayouts = &m_descriptor_layout;
|
||||||
layout_info.pushConstantRangeCount = 1;
|
layout_info.pushConstantRangeCount = 1;
|
||||||
@@ -92,11 +90,9 @@ TileManager::~TileManager() {
|
|||||||
TileManager::Scratch TileManager::AllocateScratch(uint64_t size) {
|
TileManager::Scratch TileManager::AllocateScratch(uint64_t size) {
|
||||||
EXIT_IF(size == 0);
|
EXIT_IF(size == 0);
|
||||||
vk::BufferCreateInfo create {};
|
vk::BufferCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eBufferCreateInfo;
|
|
||||||
create.size = size;
|
create.size = size;
|
||||||
create.usage = vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferSrc |
|
create.usage = vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferSrc |
|
||||||
vk::BufferUsageFlagBits::eTransferDst;
|
vk::BufferUsageFlagBits::eTransferDst;
|
||||||
create.sharingMode = vk::SharingMode::eExclusive;
|
|
||||||
|
|
||||||
VmaAllocationCreateInfo allocate {};
|
VmaAllocationCreateInfo allocate {};
|
||||||
allocate.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
allocate.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||||
@@ -264,20 +260,17 @@ vk::Pipeline TileManager::GetPipeline(uint32_t slot) {
|
|||||||
const vk::SpecializationMapEntry entries[] {{0, 0, 4}, {1, 4, 4}};
|
const vk::SpecializationMapEntry entries[] {{0, 0, 4}, {1, 4, 4}};
|
||||||
const vk::SpecializationInfo specialization {2, entries, sizeof(values), values};
|
const vk::SpecializationInfo specialization {2, entries, sizeof(values), values};
|
||||||
vk::ShaderModuleCreateInfo module_info {};
|
vk::ShaderModuleCreateInfo module_info {};
|
||||||
module_info.sType = vk::StructureType::eShaderModuleCreateInfo;
|
|
||||||
module_info.codeSize = shaders[family_index].words * sizeof(uint32_t);
|
module_info.codeSize = shaders[family_index].words * sizeof(uint32_t);
|
||||||
module_info.pCode = shaders[family_index].code;
|
module_info.pCode = shaders[family_index].code;
|
||||||
vk::ShaderModule module = nullptr;
|
vk::ShaderModule module = nullptr;
|
||||||
RequireVulkanSuccess(m_graphics.device.createShaderModule(&module_info, nullptr, &module),
|
RequireVulkanSuccess(m_graphics.device.createShaderModule(&module_info, nullptr, &module),
|
||||||
"create TileManager shader module");
|
"create TileManager shader module");
|
||||||
vk::PipelineShaderStageCreateInfo stage {};
|
vk::PipelineShaderStageCreateInfo stage {};
|
||||||
stage.sType = vk::StructureType::ePipelineShaderStageCreateInfo;
|
|
||||||
stage.stage = vk::ShaderStageFlagBits::eCompute;
|
stage.stage = vk::ShaderStageFlagBits::eCompute;
|
||||||
stage.module = module;
|
stage.module = module;
|
||||||
stage.pName = "main";
|
stage.pName = "main";
|
||||||
stage.pSpecializationInfo = &specialization;
|
stage.pSpecializationInfo = &specialization;
|
||||||
vk::ComputePipelineCreateInfo create {};
|
vk::ComputePipelineCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eComputePipelineCreateInfo;
|
|
||||||
create.stage = stage;
|
create.stage = stage;
|
||||||
create.layout = m_pipeline_layout;
|
create.layout = m_pipeline_layout;
|
||||||
const auto result =
|
const auto result =
|
||||||
@@ -287,7 +280,7 @@ vk::Pipeline TileManager::GetPipeline(uint32_t slot) {
|
|||||||
return m_pipelines[slot];
|
return m_pipelines[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileManager::Record(bool tile, vk::Buffer source, uint64_t source_offset,
|
void TileManager::Record(vk::Buffer source, uint64_t source_offset,
|
||||||
uint64_t source_capacity, vk::Buffer target, uint64_t target_offset,
|
uint64_t source_capacity, vk::Buffer target, uint64_t target_offset,
|
||||||
uint64_t target_capacity, std::span<Dispatch> dispatches,
|
uint64_t target_capacity, std::span<Dispatch> dispatches,
|
||||||
bool clear_target) {
|
bool clear_target) {
|
||||||
@@ -307,7 +300,6 @@ void TileManager::Record(bool tile, vk::Buffer source, uint64_t source_offset,
|
|||||||
m_scheduler.EndRendering();
|
m_scheduler.EndRendering();
|
||||||
auto command = m_scheduler.Current().Handle();
|
auto command = m_scheduler.Current().Handle();
|
||||||
vk::BufferMemoryBarrier barriers[3] {};
|
vk::BufferMemoryBarrier barriers[3] {};
|
||||||
barriers[0].sType = vk::StructureType::eBufferMemoryBarrier;
|
|
||||||
barriers[0].srcAccessMask = vk::AccessFlagBits::eMemoryWrite | vk::AccessFlagBits::eHostWrite;
|
barriers[0].srcAccessMask = vk::AccessFlagBits::eMemoryWrite | vk::AccessFlagBits::eHostWrite;
|
||||||
barriers[0].dstAccessMask = vk::AccessFlagBits::eShaderRead;
|
barriers[0].dstAccessMask = vk::AccessFlagBits::eShaderRead;
|
||||||
barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
@@ -316,7 +308,6 @@ void TileManager::Record(bool tile, vk::Buffer source, uint64_t source_offset,
|
|||||||
barriers[0].offset = source_offset;
|
barriers[0].offset = source_offset;
|
||||||
barriers[0].size = source_capacity;
|
barriers[0].size = source_capacity;
|
||||||
barriers[1] = barriers[0];
|
barriers[1] = barriers[0];
|
||||||
barriers[1].srcAccessMask = vk::AccessFlagBits::eMemoryWrite | vk::AccessFlagBits::eHostWrite;
|
|
||||||
barriers[1].dstAccessMask =
|
barriers[1].dstAccessMask =
|
||||||
clear_target ? vk::AccessFlagBits::eTransferWrite
|
clear_target ? vk::AccessFlagBits::eTransferWrite
|
||||||
: vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite;
|
: vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite;
|
||||||
@@ -352,7 +343,6 @@ void TileManager::Record(bool tile, vk::Buffer source, uint64_t source_offset,
|
|||||||
const vk::DescriptorBufferInfo infos[] {source_info, target_info, params_info};
|
const vk::DescriptorBufferInfo infos[] {source_info, target_info, params_info};
|
||||||
std::array<vk::WriteDescriptorSet, 3> writes {};
|
std::array<vk::WriteDescriptorSet, 3> writes {};
|
||||||
for (uint32_t index = 0; index < writes.size(); index++) {
|
for (uint32_t index = 0; index < writes.size(); index++) {
|
||||||
writes[index].sType = vk::StructureType::eWriteDescriptorSet;
|
|
||||||
writes[index].dstBinding = index;
|
writes[index].dstBinding = index;
|
||||||
writes[index].descriptorCount = 1;
|
writes[index].descriptorCount = 1;
|
||||||
writes[index].descriptorType = index == 2 ? vk::DescriptorType::eUniformBuffer
|
writes[index].descriptorType = index == 2 ? vk::DescriptorType::eUniformBuffer
|
||||||
@@ -384,7 +374,7 @@ TileManager::Result TileManager::Detile(vk::Buffer tiled, uint64_t tiled_offset,
|
|||||||
Prepare(false, tiled_capacity, linear_capacity, infos, source_base, 0, dispatches);
|
Prepare(false, tiled_capacity, linear_capacity, infos, source_base, 0, dispatches);
|
||||||
auto scratch = AllocateScratch((linear_capacity + 3u) & ~uint64_t {3});
|
auto scratch = AllocateScratch((linear_capacity + 3u) & ~uint64_t {3});
|
||||||
DeferDestroy(scratch);
|
DeferDestroy(scratch);
|
||||||
Record(false, tiled, tiled_offset, tiled_capacity, scratch.buffer, 0, scratch.size, dispatches,
|
Record(tiled, tiled_offset, tiled_capacity, scratch.buffer, 0, scratch.size, dispatches,
|
||||||
true);
|
true);
|
||||||
return {scratch.buffer, 0, linear_capacity};
|
return {scratch.buffer, 0, linear_capacity};
|
||||||
}
|
}
|
||||||
@@ -399,7 +389,7 @@ void TileManager::Tile(vk::Buffer linear, uint64_t linear_offset, uint64_t linea
|
|||||||
const uint64_t target_base = tiled_offset & (descriptor_alignment - 1);
|
const uint64_t target_base = tiled_offset & (descriptor_alignment - 1);
|
||||||
std::vector<Dispatch> dispatches;
|
std::vector<Dispatch> dispatches;
|
||||||
Prepare(true, tiled_capacity, linear_capacity, infos, source_base, target_base, dispatches);
|
Prepare(true, tiled_capacity, linear_capacity, infos, source_base, target_base, dispatches);
|
||||||
Record(true, linear, linear_offset, linear_capacity, tiled, tiled_offset, tiled_capacity,
|
Record(linear, linear_offset, linear_capacity, tiled, tiled_offset, tiled_capacity,
|
||||||
dispatches, false);
|
dispatches, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,7 +413,7 @@ void TileManager::TileImage(Image& image, std::span<const vk::BufferImageCopy> r
|
|||||||
if (transform == ColorTransform::SwapBgra16) {
|
if (transform == ColorTransform::SwapBgra16) {
|
||||||
source = SwapBgra16(source);
|
source = SwapBgra16(source);
|
||||||
}
|
}
|
||||||
Record(true, source.buffer, source.offset, linear_capacity, tiled, tiled_offset, tiled_capacity,
|
Record(source.buffer, source.offset, linear_capacity, tiled, tiled_offset, tiled_capacity,
|
||||||
dispatches, false);
|
dispatches, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,20 +472,17 @@ void TileManager::ConvertD16(Result source, Result target, D16Direction directio
|
|||||||
words = std::size(GPU_TILER_DEMOTE_D16_SPV);
|
words = std::size(GPU_TILER_DEMOTE_D16_SPV);
|
||||||
}
|
}
|
||||||
vk::ShaderModuleCreateInfo module_info {};
|
vk::ShaderModuleCreateInfo module_info {};
|
||||||
module_info.sType = vk::StructureType::eShaderModuleCreateInfo;
|
|
||||||
module_info.codeSize = words * sizeof(uint32_t);
|
module_info.codeSize = words * sizeof(uint32_t);
|
||||||
module_info.pCode = code;
|
module_info.pCode = code;
|
||||||
vk::ShaderModule module = nullptr;
|
vk::ShaderModule module = nullptr;
|
||||||
RequireVulkanSuccess(m_graphics.device.createShaderModule(&module_info, nullptr, &module),
|
RequireVulkanSuccess(m_graphics.device.createShaderModule(&module_info, nullptr, &module),
|
||||||
"create D16 conversion shader module");
|
"create D16 conversion shader module");
|
||||||
vk::PipelineShaderStageCreateInfo stage {};
|
vk::PipelineShaderStageCreateInfo stage {};
|
||||||
stage.sType = vk::StructureType::ePipelineShaderStageCreateInfo;
|
|
||||||
stage.stage = vk::ShaderStageFlagBits::eCompute;
|
stage.stage = vk::ShaderStageFlagBits::eCompute;
|
||||||
stage.module = module;
|
stage.module = module;
|
||||||
stage.pName = "main";
|
stage.pName = "main";
|
||||||
stage.pSpecializationInfo = &specialization;
|
stage.pSpecializationInfo = &specialization;
|
||||||
vk::ComputePipelineCreateInfo create {};
|
vk::ComputePipelineCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eComputePipelineCreateInfo;
|
|
||||||
create.stage = stage;
|
create.stage = stage;
|
||||||
create.layout = m_pipeline_layout;
|
create.layout = m_pipeline_layout;
|
||||||
const auto result =
|
const auto result =
|
||||||
@@ -532,7 +519,6 @@ void TileManager::ConvertD16(Result source, Result target, D16Direction directio
|
|||||||
m_scheduler.EndRendering();
|
m_scheduler.EndRendering();
|
||||||
auto command = m_scheduler.Current().Handle();
|
auto command = m_scheduler.Current().Handle();
|
||||||
vk::BufferMemoryBarrier barriers[2] {};
|
vk::BufferMemoryBarrier barriers[2] {};
|
||||||
barriers[0].sType = vk::StructureType::eBufferMemoryBarrier;
|
|
||||||
barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barriers[0].buffer = source.buffer;
|
barriers[0].buffer = source.buffer;
|
||||||
@@ -542,7 +528,6 @@ void TileManager::ConvertD16(Result source, Result target, D16Direction directio
|
|||||||
vk::AccessFlagBits::eTransferWrite |
|
vk::AccessFlagBits::eTransferWrite |
|
||||||
vk::AccessFlagBits::eShaderWrite;
|
vk::AccessFlagBits::eShaderWrite;
|
||||||
barriers[0].dstAccessMask = vk::AccessFlagBits::eShaderRead;
|
barriers[0].dstAccessMask = vk::AccessFlagBits::eShaderRead;
|
||||||
barriers[1].sType = vk::StructureType::eBufferMemoryBarrier;
|
|
||||||
barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barriers[1].buffer = target.buffer;
|
barriers[1].buffer = target.buffer;
|
||||||
@@ -596,7 +581,6 @@ void TileManager::ConvertD16(Result source, Result target, D16Direction directio
|
|||||||
};
|
};
|
||||||
std::array<vk::WriteDescriptorSet, 2> writes {};
|
std::array<vk::WriteDescriptorSet, 2> writes {};
|
||||||
for (uint32_t index = 0; index < writes.size(); index++) {
|
for (uint32_t index = 0; index < writes.size(); index++) {
|
||||||
writes[index].sType = vk::StructureType::eWriteDescriptorSet;
|
|
||||||
writes[index].dstBinding = index;
|
writes[index].dstBinding = index;
|
||||||
writes[index].descriptorCount = 1;
|
writes[index].descriptorCount = 1;
|
||||||
writes[index].descriptorType = vk::DescriptorType::eStorageBuffer;
|
writes[index].descriptorType = vk::DescriptorType::eStorageBuffer;
|
||||||
@@ -627,19 +611,16 @@ void TileManager::ConvertD16(Result source, Result target, D16Direction directio
|
|||||||
void TileManager::SwapBgra16(Result input, Result output, uint32_t pixels) {
|
void TileManager::SwapBgra16(Result input, Result output, uint32_t pixels) {
|
||||||
if (m_swap_bgra16 == nullptr) {
|
if (m_swap_bgra16 == nullptr) {
|
||||||
vk::ShaderModuleCreateInfo module_info {};
|
vk::ShaderModuleCreateInfo module_info {};
|
||||||
module_info.sType = vk::StructureType::eShaderModuleCreateInfo;
|
|
||||||
module_info.codeSize = std::size(GPU_TILER_SWAP_BGRA16_SPV) * sizeof(uint32_t);
|
module_info.codeSize = std::size(GPU_TILER_SWAP_BGRA16_SPV) * sizeof(uint32_t);
|
||||||
module_info.pCode = GPU_TILER_SWAP_BGRA16_SPV;
|
module_info.pCode = GPU_TILER_SWAP_BGRA16_SPV;
|
||||||
vk::ShaderModule module = nullptr;
|
vk::ShaderModule module = nullptr;
|
||||||
RequireVulkanSuccess(m_graphics.device.createShaderModule(&module_info, nullptr, &module),
|
RequireVulkanSuccess(m_graphics.device.createShaderModule(&module_info, nullptr, &module),
|
||||||
"create BGRA16 swap shader module");
|
"create BGRA16 swap shader module");
|
||||||
vk::PipelineShaderStageCreateInfo stage {};
|
vk::PipelineShaderStageCreateInfo stage {};
|
||||||
stage.sType = vk::StructureType::ePipelineShaderStageCreateInfo;
|
|
||||||
stage.stage = vk::ShaderStageFlagBits::eCompute;
|
stage.stage = vk::ShaderStageFlagBits::eCompute;
|
||||||
stage.module = module;
|
stage.module = module;
|
||||||
stage.pName = "main";
|
stage.pName = "main";
|
||||||
vk::ComputePipelineCreateInfo create {};
|
vk::ComputePipelineCreateInfo create {};
|
||||||
create.sType = vk::StructureType::eComputePipelineCreateInfo;
|
|
||||||
create.stage = stage;
|
create.stage = stage;
|
||||||
create.layout = m_pipeline_layout;
|
create.layout = m_pipeline_layout;
|
||||||
const auto result =
|
const auto result =
|
||||||
@@ -658,7 +639,6 @@ void TileManager::SwapBgra16(Result input, Result output, uint32_t pixels) {
|
|||||||
};
|
};
|
||||||
std::array<vk::WriteDescriptorSet, 2> writes {};
|
std::array<vk::WriteDescriptorSet, 2> writes {};
|
||||||
for (uint32_t index = 0; index < writes.size(); index++) {
|
for (uint32_t index = 0; index < writes.size(); index++) {
|
||||||
writes[index].sType = vk::StructureType::eWriteDescriptorSet;
|
|
||||||
writes[index].dstBinding = index;
|
writes[index].dstBinding = index;
|
||||||
writes[index].descriptorCount = 1;
|
writes[index].descriptorCount = 1;
|
||||||
writes[index].descriptorType = vk::DescriptorType::eStorageBuffer;
|
writes[index].descriptorType = vk::DescriptorType::eStorageBuffer;
|
||||||
@@ -666,7 +646,6 @@ void TileManager::SwapBgra16(Result input, Result output, uint32_t pixels) {
|
|||||||
}
|
}
|
||||||
vk::BufferMemoryBarrier barriers[2] {};
|
vk::BufferMemoryBarrier barriers[2] {};
|
||||||
for (uint32_t index = 0; index < 2; index++) {
|
for (uint32_t index = 0; index < 2; index++) {
|
||||||
barriers[index].sType = vk::StructureType::eBufferMemoryBarrier;
|
|
||||||
barriers[index].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barriers[index].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barriers[index].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barriers[index].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barriers[index].buffer = infos[index].buffer;
|
barriers[index].buffer = infos[index].buffer;
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ private:
|
|||||||
void Prepare(bool tile, uint64_t tiled_capacity, uint64_t linear_capacity,
|
void Prepare(bool tile, uint64_t tiled_capacity, uint64_t linear_capacity,
|
||||||
std::span<const GpuTileInfo> infos, uint64_t source_base, uint64_t target_base,
|
std::span<const GpuTileInfo> infos, uint64_t source_base, uint64_t target_base,
|
||||||
std::vector<Dispatch>& dispatches);
|
std::vector<Dispatch>& dispatches);
|
||||||
void Record(bool tile, vk::Buffer source, uint64_t source_offset, uint64_t source_capacity,
|
void Record(vk::Buffer source, uint64_t source_offset, uint64_t source_capacity,
|
||||||
vk::Buffer target, uint64_t target_offset, uint64_t target_capacity,
|
vk::Buffer target, uint64_t target_offset, uint64_t target_capacity,
|
||||||
std::span<Dispatch> dispatches, bool clear_target);
|
std::span<Dispatch> dispatches, bool clear_target);
|
||||||
[[nodiscard]] vk::Pipeline GetPipeline(uint32_t slot);
|
[[nodiscard]] vk::Pipeline GetPipeline(uint32_t slot);
|
||||||
|
|||||||
Reference in New Issue
Block a user