From e6f90b80034abba12dcf5e7e71ad15d2651532b3 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 6 Oct 2024 20:51:11 +0200 Subject: [PATCH] [dxvk] Remove legacy depth/stencil repacking code --- src/dxvk/dxvk_context.cpp | 317 ------------------ src/dxvk/dxvk_context.h | 55 --- src/dxvk/dxvk_meta_pack.cpp | 226 ------------- src/dxvk/dxvk_meta_pack.h | 129 ------- src/dxvk/dxvk_objects.h | 6 - src/dxvk/meson.build | 8 - src/dxvk/shaders/dxvk_pack_d24s8.comp | 43 --- src/dxvk/shaders/dxvk_pack_d32s8.comp | 46 --- src/dxvk/shaders/dxvk_unpack_d24s8.comp | 41 --- .../shaders/dxvk_unpack_d24s8_as_d32s8.comp | 41 --- src/dxvk/shaders/dxvk_unpack_d32s8.comp | 46 --- 11 files changed, 958 deletions(-) delete mode 100644 src/dxvk/dxvk_meta_pack.cpp delete mode 100644 src/dxvk/dxvk_meta_pack.h delete mode 100644 src/dxvk/shaders/dxvk_pack_d24s8.comp delete mode 100644 src/dxvk/shaders/dxvk_pack_d32s8.comp delete mode 100644 src/dxvk/shaders/dxvk_unpack_d24s8.comp delete mode 100644 src/dxvk/shaders/dxvk_unpack_d24s8_as_d32s8.comp delete mode 100644 src/dxvk/shaders/dxvk_unpack_d32s8.comp diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 7bd25d8e2..dc5933c96 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -644,125 +644,6 @@ namespace dxvk { } - void DxvkContext::copyDepthStencilImageToPackedBuffer( - const Rc& dstBuffer, - VkDeviceSize dstBufferOffset, - VkOffset2D dstOffset, - VkExtent2D dstExtent, - const Rc& srcImage, - VkImageSubresourceLayers srcSubresource, - VkOffset2D srcOffset, - VkExtent2D srcExtent, - VkFormat format) { - this->spillRenderPass(true); - this->prepareImage(srcImage, vk::makeSubresourceRange(srcSubresource)); - - this->invalidateState(); - - DxvkImageUsageInfo usageInfo = { }; - usageInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT; - - if (!ensureImageCompatibility(srcImage, usageInfo)) { - Logger::err(str::format("DxvkContext: copyDepthStencilImageToPackedBuffer: Unsupported image:" - "\n src format: ", srcImage->info().format)); - } - - // Retrieve compute pipeline for the given format - auto pipeInfo = m_common->metaPack().getPackPipeline(format); - - if (!pipeInfo.pipeHandle) - return; - - // Create one depth view and one stencil view - DxvkImageViewKey dViewInfo = { }; - dViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; - dViewInfo.format = srcImage->info().format; - dViewInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT; - dViewInfo.aspects = VK_IMAGE_ASPECT_DEPTH_BIT; - dViewInfo.mipIndex = srcSubresource.mipLevel; - dViewInfo.mipCount = 1; - dViewInfo.layerIndex = srcSubresource.baseArrayLayer; - dViewInfo.layerCount = srcSubresource.layerCount; - - DxvkImageViewKey sViewInfo = dViewInfo; - sViewInfo.aspects = VK_IMAGE_ASPECT_STENCIL_BIT; - - Rc dView = srcImage->createView(dViewInfo); - Rc sView = srcImage->createView(sViewInfo); - - // Create a descriptor set for the pack operation - VkImageLayout layout = srcImage->pickLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL); - - DxvkMetaPackDescriptors descriptors; - descriptors.dstBuffer = dstBuffer->getDescriptor(dstBufferOffset, VK_WHOLE_SIZE).buffer; - descriptors.srcDepth = dView->getDescriptor(VK_IMAGE_VIEW_TYPE_2D_ARRAY, layout).image; - descriptors.srcStencil = sView->getDescriptor(VK_IMAGE_VIEW_TYPE_2D_ARRAY, layout).image; - - VkDescriptorSet dset = m_descriptorPool->alloc(pipeInfo.dsetLayout); - m_cmd->updateDescriptorSetWithTemplate(dset, pipeInfo.dsetTemplate, &descriptors); - - // Since this is a meta operation, the image may be - // in a different layout and we have to transition it - auto subresourceRange = vk::makeSubresourceRange(srcSubresource); - - if (m_execBarriers.isImageDirty(srcImage, subresourceRange, DxvkAccess::Write)) - m_execBarriers.recordCommands(m_cmd); - - if (srcImage->info().layout != layout) { - m_execAcquires.accessImage( - srcImage, subresourceRange, - srcImage->info().layout, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, - layout, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_SHADER_READ_BIT); - - m_execAcquires.recordCommands(m_cmd); - } - - // Execute the actual pack operation - DxvkMetaPackArgs args; - args.srcOffset = srcOffset; - args.srcExtent = srcExtent; - args.dstOffset = dstOffset; - args.dstExtent = dstExtent; - - m_cmd->cmdBindPipeline(DxvkCmdBuffer::ExecBuffer, - VK_PIPELINE_BIND_POINT_COMPUTE, pipeInfo.pipeHandle); - - m_cmd->cmdBindDescriptorSet(DxvkCmdBuffer::ExecBuffer, - VK_PIPELINE_BIND_POINT_COMPUTE, pipeInfo.pipeLayout, - dset, 0, nullptr); - - m_cmd->cmdPushConstants(DxvkCmdBuffer::ExecBuffer, - pipeInfo.pipeLayout, VK_SHADER_STAGE_COMPUTE_BIT, - 0, sizeof(args), &args); - - m_cmd->cmdDispatch(DxvkCmdBuffer::ExecBuffer, - (srcExtent.width + 7) / 8, - (srcExtent.height + 7) / 8, - srcSubresource.layerCount); - - m_execBarriers.accessImage( - srcImage, subresourceRange, layout, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_SHADER_READ_BIT, - srcImage->info().layout, - srcImage->info().stages, - srcImage->info().access); - - m_execBarriers.accessBuffer( - dstBuffer->getSliceHandle(), - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_SHADER_WRITE_BIT, - dstBuffer->info().stages, - dstBuffer->info().access); - - m_cmd->trackResource(dstBuffer); - m_cmd->trackResource(srcImage); - } - - void DxvkContext::copyPackedBufferImage( const Rc& dstBuffer, VkDeviceSize dstBufferOffset, @@ -928,204 +809,6 @@ namespace dxvk { } - void DxvkContext::copyPackedBufferToDepthStencilImage( - const Rc& dstImage, - VkImageSubresourceLayers dstSubresource, - VkOffset2D dstOffset, - VkExtent2D dstExtent, - const Rc& srcBuffer, - VkDeviceSize srcBufferOffset, - VkOffset2D srcOffset, - VkExtent2D srcExtent, - VkFormat format) { - this->spillRenderPass(true); - this->invalidateState(); - - this->prepareImage(dstImage, vk::makeSubresourceRange(dstSubresource)); - - DxvkImageUsageInfo usageInfo = { }; - usageInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - - if (!ensureImageCompatibility(dstImage, usageInfo)) { - Logger::err(str::format("DxvkCOntext: copyPackedBufferToDepthStencilImage: Unsupported image:" - "\n dst format: ", dstImage->info().format)); - return; - } - - if (m_execBarriers.isBufferDirty(srcBuffer->getSliceHandle(), DxvkAccess::Read) - || m_execBarriers.isImageDirty(dstImage, vk::makeSubresourceRange(dstSubresource), DxvkAccess::Write)) - m_execBarriers.recordCommands(m_cmd); - - // Retrieve compute pipeline for the given format - auto pipeInfo = m_common->metaPack().getUnpackPipeline(dstImage->info().format, format); - - if (!pipeInfo.pipeHandle) { - Logger::err(str::format( - "DxvkContext: copyPackedBufferToDepthStencilImage: Unhandled formats" - "\n dstFormat = ", dstImage->info().format, - "\n srcFormat = ", format)); - return; - } - - // Pick depth and stencil data formats - VkFormat dataFormatD = VK_FORMAT_UNDEFINED; - VkFormat dataFormatS = VK_FORMAT_UNDEFINED; - - const std::array, 2> formats = {{ - { VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_R32_UINT, VK_FORMAT_R8_UINT }, - { VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_R8_UINT }, - }}; - - for (const auto& e : formats) { - if (std::get<0>(e) == dstImage->info().format) { - dataFormatD = std::get<1>(e); - dataFormatS = std::get<2>(e); - } - } - - // Create temporary buffer for depth/stencil data - VkDeviceSize pixelCount = dstExtent.width * dstExtent.height * dstSubresource.layerCount; - VkDeviceSize dataSizeD = align(pixelCount * lookupFormatInfo(dataFormatD)->elementSize, 256); - VkDeviceSize dataSizeS = align(pixelCount * lookupFormatInfo(dataFormatS)->elementSize, 256); - - DxvkBufferCreateInfo tmpBufferInfo; - tmpBufferInfo.size = dataSizeD + dataSizeS; - tmpBufferInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT - | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - tmpBufferInfo.stages = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT - | VK_PIPELINE_STAGE_TRANSFER_BIT; - tmpBufferInfo.access = VK_ACCESS_SHADER_WRITE_BIT - | VK_ACCESS_TRANSFER_READ_BIT; - - auto tmpBuffer = m_device->createBuffer(tmpBufferInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - - // Create formatted buffer views - DxvkBufferViewKey tmpViewInfoD; - tmpViewInfoD.format = dataFormatD; - tmpViewInfoD.offset = 0; - tmpViewInfoD.size = dataSizeD; - tmpViewInfoD.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; - - DxvkBufferViewKey tmpViewInfoS; - tmpViewInfoS.format = dataFormatS; - tmpViewInfoS.offset = dataSizeD; - tmpViewInfoS.size = dataSizeS; - tmpViewInfoS.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; - - auto tmpBufferViewD = tmpBuffer->createView(tmpViewInfoD); - auto tmpBufferViewS = tmpBuffer->createView(tmpViewInfoS); - - // Create descriptor set for the unpack operation - DxvkMetaUnpackDescriptors descriptors; - descriptors.dstDepth = tmpBufferViewD->handle(); - descriptors.dstStencil = tmpBufferViewS->handle(); - descriptors.srcBuffer = srcBuffer->getDescriptor(srcBufferOffset, VK_WHOLE_SIZE).buffer; - - VkDescriptorSet dset = m_descriptorPool->alloc(pipeInfo.dsetLayout); - m_cmd->updateDescriptorSetWithTemplate(dset, pipeInfo.dsetTemplate, &descriptors); - - // Unpack the source buffer to temporary buffers - DxvkMetaPackArgs args; - args.srcOffset = srcOffset; - args.srcExtent = srcExtent; - args.dstOffset = VkOffset2D { 0, 0 }; - args.dstExtent = dstExtent; - - m_cmd->cmdBindPipeline(DxvkCmdBuffer::ExecBuffer, - VK_PIPELINE_BIND_POINT_COMPUTE, pipeInfo.pipeHandle); - - m_cmd->cmdBindDescriptorSet(DxvkCmdBuffer::ExecBuffer, - VK_PIPELINE_BIND_POINT_COMPUTE, pipeInfo.pipeLayout, - dset, 0, nullptr); - - m_cmd->cmdPushConstants(DxvkCmdBuffer::ExecBuffer, - pipeInfo.pipeLayout, VK_SHADER_STAGE_COMPUTE_BIT, - 0, sizeof(args), &args); - - m_cmd->cmdDispatch(DxvkCmdBuffer::ExecBuffer, - (dstExtent.width + 63) / 64, - dstExtent.height, - dstSubresource.layerCount); - - m_execBarriers.accessBuffer( - tmpBuffer->getSliceHandle(), - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_SHADER_WRITE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_ACCESS_TRANSFER_READ_BIT); - - m_execBarriers.accessBuffer( - srcBuffer->getSliceHandle(), - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_SHADER_READ_BIT, - srcBuffer->info().stages, - srcBuffer->info().access); - - // Prepare image for the data transfer operation - VkOffset3D dstOffset3D = { dstOffset.x, dstOffset.y, 0 }; - VkExtent3D dstExtent3D = { dstExtent.width, dstExtent.height, 1 }; - - VkImageLayout initialImageLayout = dstImage->info().layout; - - if (dstImage->isFullSubresource(dstSubresource, dstExtent3D)) - initialImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - m_execBarriers.accessImage( - dstImage, vk::makeSubresourceRange(dstSubresource), - initialImageLayout, - dstImage->info().stages, - dstImage->info().access, - dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL), - VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT); - - m_execBarriers.recordCommands(m_cmd); - - // Copy temporary buffer data to depth-stencil image - VkImageSubresourceLayers dstSubresourceD = dstSubresource; - dstSubresourceD.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - - VkImageSubresourceLayers dstSubresourceS = dstSubresource; - dstSubresourceS.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; - - std::array copyRegions; - copyRegions[0] = { VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2 }; - copyRegions[0].bufferOffset = tmpBufferViewD->info().offset; - copyRegions[0].imageSubresource = dstSubresourceD; - copyRegions[0].imageOffset = dstOffset3D; - copyRegions[0].imageExtent = dstExtent3D; - - copyRegions[1] = { VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2 }; - copyRegions[1].bufferOffset = tmpBufferViewS->info().offset; - copyRegions[1].imageSubresource = dstSubresourceS; - copyRegions[1].imageOffset = dstOffset3D; - copyRegions[1].imageExtent = dstExtent3D; - - VkCopyBufferToImageInfo2 copyInfo = { VK_STRUCTURE_TYPE_COPY_BUFFER_TO_IMAGE_INFO_2 }; - copyInfo.srcBuffer = tmpBuffer->getSliceHandle().handle; - copyInfo.dstImage = dstImage->handle(); - copyInfo.dstImageLayout = dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - copyInfo.regionCount = copyRegions.size(); - copyInfo.pRegions = copyRegions.data(); - - m_cmd->cmdCopyBufferToImage(DxvkCmdBuffer::ExecBuffer, ©Info); - - m_execBarriers.accessImage( - dstImage, vk::makeSubresourceRange(dstSubresource), - dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL), - VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT, - dstImage->info().layout, - dstImage->info().stages, - dstImage->info().access); - - // Track all involved resources - m_cmd->trackResource(dstImage); - m_cmd->trackResource(srcBuffer); - m_cmd->trackResource(tmpBuffer); - } - - void DxvkContext::copySparsePagesToBuffer( const Rc& dstBuffer, VkDeviceSize dstOffset, diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index adedbffae..6fc69b4dc 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -622,34 +622,6 @@ namespace dxvk { VkOffset3D srcOffset, VkExtent3D srcExtent); - /** - * \brief Packs depth-stencil image data to a buffer - * - * Packs data from both the depth and stencil aspects - * of an image into a buffer. The supported formats are: - * - \c VK_FORMAT_D24_UNORM_S8_UINT: 0xssdddddd - * - \c VK_FORMAT_D32_SFLOAT_S8_UINT: 0xdddddddd 0x000000ss - * \param [in] dstBuffer Destination buffer - * \param [in] dstBufferOffset Destination offset, in bytes - * \param [in] dstOffset Destination image offset - * \param [in] dstSize Destination image size - * \param [in] srcImage Source image - * \param [in] srcSubresource Source subresource - * \param [in] srcOffset Source area offset - * \param [in] srcExtent Source area size - * \param [in] format Packed data format - */ - void copyDepthStencilImageToPackedBuffer( - const Rc& dstBuffer, - VkDeviceSize dstBufferOffset, - VkOffset2D dstOffset, - VkExtent2D dstExtent, - const Rc& srcImage, - VkImageSubresourceLayers srcSubresource, - VkOffset2D srcOffset, - VkExtent2D srcExtent, - VkFormat format); - /** * \brief Copies image data stored in a linear buffer to another * @@ -678,33 +650,6 @@ namespace dxvk { VkExtent3D extent, VkDeviceSize elementSize); - /** - * \brief Unpacks buffer data to a depth-stencil image - * - * Writes the packed depth-stencil data to an image. - * See \ref copyDepthStencilImageToPackedBuffer for - * which formats are supported and how they are packed. - * \param [in] dstImage Destination image - * \param [in] dstSubresource Destination subresource - * \param [in] dstOffset Image area offset - * \param [in] dstExtent Image area size - * \param [in] srcBuffer Packed data buffer - * \param [in] srcBufferOffset Buffer offset of source image - * \param [in] srcOffset Offset into the source image - * \param [in] srcExtent Total size of the source image - * \param [in] format Packed data format - */ - void copyPackedBufferToDepthStencilImage( - const Rc& dstImage, - VkImageSubresourceLayers dstSubresource, - VkOffset2D dstOffset, - VkExtent2D dstExtent, - const Rc& srcBuffer, - VkDeviceSize srcBufferOffset, - VkOffset2D srcOffset, - VkExtent2D srcExtent, - VkFormat format); - /** * \brief Copies pages from a sparse resource to a buffer * diff --git a/src/dxvk/dxvk_meta_pack.cpp b/src/dxvk/dxvk_meta_pack.cpp deleted file mode 100644 index 0a5475f8a..000000000 --- a/src/dxvk/dxvk_meta_pack.cpp +++ /dev/null @@ -1,226 +0,0 @@ -#include "dxvk_meta_pack.h" -#include "dxvk_device.h" - -#include -#include - -#include -#include -#include - -namespace dxvk { - - DxvkMetaPackObjects::DxvkMetaPackObjects(const DxvkDevice* device) - : m_vkd (device->vkd()), - m_dsetLayoutPack (createPackDescriptorSetLayout()), - m_dsetLayoutUnpack(createUnpackDescriptorSetLayout()), - m_pipeLayoutPack (createPipelineLayout(m_dsetLayoutPack, sizeof(DxvkMetaPackArgs))), - m_pipeLayoutUnpack(createPipelineLayout(m_dsetLayoutUnpack, sizeof(DxvkMetaPackArgs))), - m_templatePack (createPackDescriptorUpdateTemplate()), - m_templateUnpack (createUnpackDescriptorUpdateTemplate()), - m_pipePackD24S8 (createPipeline(m_pipeLayoutPack, dxvk_pack_d24s8)), - m_pipePackD32S8 (createPipeline(m_pipeLayoutPack, dxvk_pack_d32s8)), - m_pipeUnpackD24S8AsD32S8(createPipeline(m_pipeLayoutUnpack, dxvk_unpack_d24s8_as_d32s8)), - m_pipeUnpackD24S8 (createPipeline(m_pipeLayoutUnpack, dxvk_unpack_d24s8)), - m_pipeUnpackD32S8 (createPipeline(m_pipeLayoutUnpack, dxvk_unpack_d32s8)) { - - } - - - DxvkMetaPackObjects::~DxvkMetaPackObjects() { - m_vkd->vkDestroyPipeline(m_vkd->device(), m_pipeUnpackD32S8, nullptr); - m_vkd->vkDestroyPipeline(m_vkd->device(), m_pipeUnpackD24S8, nullptr); - m_vkd->vkDestroyPipeline(m_vkd->device(), m_pipeUnpackD24S8AsD32S8, nullptr); - - m_vkd->vkDestroyPipeline(m_vkd->device(), m_pipePackD32S8, nullptr); - m_vkd->vkDestroyPipeline(m_vkd->device(), m_pipePackD24S8, nullptr); - - m_vkd->vkDestroyDescriptorUpdateTemplate(m_vkd->device(), m_templatePack, nullptr); - m_vkd->vkDestroyDescriptorUpdateTemplate(m_vkd->device(), m_templateUnpack, nullptr); - - m_vkd->vkDestroyPipelineLayout(m_vkd->device(), m_pipeLayoutPack, nullptr); - m_vkd->vkDestroyPipelineLayout(m_vkd->device(), m_pipeLayoutUnpack, nullptr); - - m_vkd->vkDestroyDescriptorSetLayout(m_vkd->device(), m_dsetLayoutPack, nullptr); - m_vkd->vkDestroyDescriptorSetLayout(m_vkd->device(), m_dsetLayoutUnpack, nullptr); - } - - - DxvkMetaPackPipeline DxvkMetaPackObjects::getPackPipeline(VkFormat format) { - DxvkMetaPackPipeline result; - result.dsetTemplate = m_templatePack; - result.dsetLayout = m_dsetLayoutPack; - result.pipeLayout = m_pipeLayoutPack; - result.pipeHandle = VK_NULL_HANDLE; - - switch (format) { - case VK_FORMAT_D24_UNORM_S8_UINT: result.pipeHandle = m_pipePackD24S8; break; - case VK_FORMAT_D32_SFLOAT_S8_UINT: result.pipeHandle = m_pipePackD32S8; break; - default: Logger::err(str::format("DxvkMetaPackObjects: Unknown format: ", format)); - } - - return result; - } - - - DxvkMetaPackPipeline DxvkMetaPackObjects::getUnpackPipeline( - VkFormat dstFormat, - VkFormat srcFormat) { - DxvkMetaPackPipeline result; - result.dsetTemplate = m_templateUnpack; - result.dsetLayout = m_dsetLayoutUnpack; - result.pipeLayout = m_pipeLayoutUnpack; - result.pipeHandle = VK_NULL_HANDLE; - - std::array, 3> pipeSelector = {{ - { VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, m_pipeUnpackD24S8 }, - { VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, m_pipeUnpackD24S8AsD32S8 }, - { VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, m_pipeUnpackD32S8 }, - }}; - - for (const auto& e : pipeSelector) { - if (std::get<0>(e) == dstFormat - && std::get<1>(e) == srcFormat) - result.pipeHandle = std::get<2>(e); - } - - return result; - } - - - VkDescriptorSetLayout DxvkMetaPackObjects::createPackDescriptorSetLayout() { - std::array bindings = {{ - { 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr }, - { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr }, - { 2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr }, - }}; - - VkDescriptorSetLayoutCreateInfo dsetInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO }; - dsetInfo.bindingCount = bindings.size(); - dsetInfo.pBindings = bindings.data(); - - VkDescriptorSetLayout result = VK_NULL_HANDLE; - if (m_vkd->vkCreateDescriptorSetLayout(m_vkd->device(), &dsetInfo, nullptr, &result) != VK_SUCCESS) - throw DxvkError("DxvkMetaPackObjects: Failed to create descriptor set layout"); - return result; - } - - - VkDescriptorSetLayout DxvkMetaPackObjects::createUnpackDescriptorSetLayout() { - std::array bindings = {{ - { 0, VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr }, - { 1, VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr }, - { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr }, - }}; - - VkDescriptorSetLayoutCreateInfo dsetInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO }; - dsetInfo.bindingCount = bindings.size(); - dsetInfo.pBindings = bindings.data(); - - VkDescriptorSetLayout result = VK_NULL_HANDLE; - if (m_vkd->vkCreateDescriptorSetLayout(m_vkd->device(), &dsetInfo, nullptr, &result) != VK_SUCCESS) - throw DxvkError("DxvkMetaPackObjects: Failed to create descriptor set layout"); - return result; - } - - - VkPipelineLayout DxvkMetaPackObjects::createPipelineLayout( - VkDescriptorSetLayout dsetLayout, - uint32_t pushLayout) { - VkPushConstantRange push = { VK_SHADER_STAGE_COMPUTE_BIT, 0, pushLayout }; - - VkPipelineLayoutCreateInfo layoutInfo = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO }; - layoutInfo.setLayoutCount = 1; - layoutInfo.pSetLayouts = &dsetLayout; - layoutInfo.pushConstantRangeCount = 1; - layoutInfo.pPushConstantRanges = &push; - - VkPipelineLayout result = VK_NULL_HANDLE; - if (m_vkd->vkCreatePipelineLayout(m_vkd->device(), &layoutInfo, nullptr, &result) != VK_SUCCESS) - throw DxvkError("DxvkMetaPackObjects: Failed to create pipeline layout"); - return result; - } - - - VkDescriptorUpdateTemplate DxvkMetaPackObjects::createPackDescriptorUpdateTemplate() { - std::array bindings = {{ - { 0, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, offsetof(DxvkMetaPackDescriptors, dstBuffer), 0 }, - { 1, 0, 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, offsetof(DxvkMetaPackDescriptors, srcDepth), 0 }, - { 2, 0, 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, offsetof(DxvkMetaPackDescriptors, srcStencil), 0 }, - }}; - - VkDescriptorUpdateTemplateCreateInfo templateInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO }; - templateInfo.descriptorUpdateEntryCount = bindings.size(); - templateInfo.pDescriptorUpdateEntries = bindings.data(); - templateInfo.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET; - templateInfo.descriptorSetLayout = m_dsetLayoutPack; - templateInfo.pipelineBindPoint = VK_PIPELINE_BIND_POINT_COMPUTE; - templateInfo.pipelineLayout = m_pipeLayoutPack; - - VkDescriptorUpdateTemplate result = VK_NULL_HANDLE; - if (m_vkd->vkCreateDescriptorUpdateTemplate(m_vkd->device(), - &templateInfo, nullptr, &result) != VK_SUCCESS) - throw DxvkError("DxvkMetaPackObjects: Failed to create descriptor update template"); - return result; - } - - - VkDescriptorUpdateTemplate DxvkMetaPackObjects::createUnpackDescriptorUpdateTemplate() { - std::array bindings = {{ - { 0, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, offsetof(DxvkMetaUnpackDescriptors, dstDepth), 0 }, - { 1, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, offsetof(DxvkMetaUnpackDescriptors, dstStencil), 0 }, - { 2, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, offsetof(DxvkMetaUnpackDescriptors, srcBuffer), 0 }, - }}; - - VkDescriptorUpdateTemplateCreateInfo templateInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO }; - templateInfo.descriptorUpdateEntryCount = bindings.size(); - templateInfo.pDescriptorUpdateEntries = bindings.data(); - templateInfo.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET; - templateInfo.descriptorSetLayout = m_dsetLayoutUnpack; - templateInfo.pipelineBindPoint = VK_PIPELINE_BIND_POINT_COMPUTE; - templateInfo.pipelineLayout = m_pipeLayoutUnpack; - templateInfo.set = 0; - - VkDescriptorUpdateTemplate result = VK_NULL_HANDLE; - if (m_vkd->vkCreateDescriptorUpdateTemplate(m_vkd->device(), - &templateInfo, nullptr, &result) != VK_SUCCESS) - throw DxvkError("DxvkMetaPackObjects: Failed to create descriptor update template"); - return result; - } - - - VkPipeline DxvkMetaPackObjects::createPipeline( - VkPipelineLayout pipeLayout, - const SpirvCodeBuffer& code) { - VkShaderModuleCreateInfo shaderInfo = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO }; - shaderInfo.codeSize = code.size(); - shaderInfo.pCode = code.data(); - - VkShaderModule module = VK_NULL_HANDLE; - - if (m_vkd->vkCreateShaderModule(m_vkd->device(), &shaderInfo, nullptr, &module) != VK_SUCCESS) - throw DxvkError("DxvkMetaPackObjects: Failed to create shader module"); - - VkPipelineShaderStageCreateInfo stageInfo = { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO }; - stageInfo.stage = VK_SHADER_STAGE_COMPUTE_BIT; - stageInfo.module = module; - stageInfo.pName = "main"; - - VkComputePipelineCreateInfo pipeInfo = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO }; - pipeInfo.stage = stageInfo; - pipeInfo.layout = pipeLayout; - pipeInfo.basePipelineIndex = -1; - - VkPipeline result = VK_NULL_HANDLE; - - VkResult status = m_vkd->vkCreateComputePipelines( - m_vkd->device(), VK_NULL_HANDLE, 1, &pipeInfo, nullptr, &result); - - m_vkd->vkDestroyShaderModule(m_vkd->device(), module, nullptr); - - if (status != VK_SUCCESS) - throw DxvkError("DxvkMetaPackObjects: Failed to create pipeline"); - return result; - } - -} \ No newline at end of file diff --git a/src/dxvk/dxvk_meta_pack.h b/src/dxvk/dxvk_meta_pack.h deleted file mode 100644 index 1e3df7764..000000000 --- a/src/dxvk/dxvk_meta_pack.h +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -#include "../spirv/spirv_code_buffer.h" - -#include "dxvk_cmdlist.h" -#include "dxvk_resource.h" - -namespace dxvk { - - /** - * \brief Packing arguments - * - * Passed in as push constants - * to the compute shader. - */ - struct DxvkMetaPackArgs { - VkOffset2D srcOffset; - VkExtent2D srcExtent; - VkOffset2D dstOffset; - VkExtent2D dstExtent; - }; - - - /** - * \brief Packing pipeline - * - * Stores the objects for a single pipeline - * that is used to pack depth-stencil image - * data into a linear buffer. - */ - struct DxvkMetaPackPipeline { - VkDescriptorUpdateTemplateKHR dsetTemplate; - VkDescriptorSetLayout dsetLayout; - VkPipelineLayout pipeLayout; - VkPipeline pipeHandle; - }; - - - /** - * \brief Packing descriptors - */ - struct DxvkMetaPackDescriptors { - VkDescriptorBufferInfo dstBuffer; - VkDescriptorImageInfo srcDepth; - VkDescriptorImageInfo srcStencil; - }; - - - /** - * \brief Unpacking descriptors - */ - struct DxvkMetaUnpackDescriptors { - VkBufferView dstDepth; - VkBufferView dstStencil; - VkDescriptorBufferInfo srcBuffer; - }; - - - /** - * \brief Depth-stencil pack objects - * - * Stores compute shaders and related objects - * for depth-stencil image packing operations. - */ - class DxvkMetaPackObjects { - - public: - - DxvkMetaPackObjects(const DxvkDevice* device); - ~DxvkMetaPackObjects(); - - /** - * \brief Retrieves depth-stencil packing pipeline - * - * \param [in] format Destination format - * \returns Data packing pipeline - */ - DxvkMetaPackPipeline getPackPipeline(VkFormat format); - - /** - * \brief Retrieves depth-stencil unpacking pipeline - * - * \param [in] dstFormat Destination image format - * \param [in] srcFormat Source buffer format - * \returns Data unpacking pipeline - */ - DxvkMetaPackPipeline getUnpackPipeline( - VkFormat dstFormat, - VkFormat srcFormat); - - private: - - Rc m_vkd; - - VkDescriptorSetLayout m_dsetLayoutPack; - VkDescriptorSetLayout m_dsetLayoutUnpack; - - VkPipelineLayout m_pipeLayoutPack; - VkPipelineLayout m_pipeLayoutUnpack; - - VkDescriptorUpdateTemplateKHR m_templatePack; - VkDescriptorUpdateTemplateKHR m_templateUnpack; - - VkPipeline m_pipePackD24S8; - VkPipeline m_pipePackD32S8; - - VkPipeline m_pipeUnpackD24S8AsD32S8; - VkPipeline m_pipeUnpackD24S8; - VkPipeline m_pipeUnpackD32S8; - - VkDescriptorSetLayout createPackDescriptorSetLayout(); - - VkDescriptorSetLayout createUnpackDescriptorSetLayout(); - - VkPipelineLayout createPipelineLayout( - VkDescriptorSetLayout dsetLayout, - uint32_t pushLayout); - - VkDescriptorUpdateTemplateKHR createPackDescriptorUpdateTemplate(); - - VkDescriptorUpdateTemplateKHR createUnpackDescriptorUpdateTemplate(); - - VkPipeline createPipeline( - VkPipelineLayout pipeLayout, - const SpirvCodeBuffer& code); - - }; - -} \ No newline at end of file diff --git a/src/dxvk/dxvk_objects.h b/src/dxvk/dxvk_objects.h index 91508d1a1..2309eaae2 100644 --- a/src/dxvk/dxvk_objects.h +++ b/src/dxvk/dxvk_objects.h @@ -7,7 +7,6 @@ #include "dxvk_meta_clear.h" #include "dxvk_meta_copy.h" #include "dxvk_meta_mipgen.h" -#include "dxvk_meta_pack.h" #include "dxvk_meta_resolve.h" #include "dxvk_pipemanager.h" #include "dxvk_renderpass.h" @@ -73,10 +72,6 @@ namespace dxvk { return m_metaResolve.get(m_device); } - DxvkMetaPackObjects& metaPack() { - return m_metaPack.get(m_device); - } - private: DxvkDevice* m_device; @@ -94,7 +89,6 @@ namespace dxvk { Lazy m_metaClear; Lazy m_metaCopy; Lazy m_metaResolve; - Lazy m_metaPack; }; diff --git a/src/dxvk/meson.build b/src/dxvk/meson.build index edf8ecafe..cebdb209e 100644 --- a/src/dxvk/meson.build +++ b/src/dxvk/meson.build @@ -37,9 +37,6 @@ dxvk_shaders = files([ 'shaders/dxvk_image_to_buffer_ds.comp', 'shaders/dxvk_image_to_buffer_f.comp', - 'shaders/dxvk_pack_d24s8.comp', - 'shaders/dxvk_pack_d32s8.comp', - 'shaders/dxvk_present_frag.frag', 'shaders/dxvk_present_frag_blit.frag', 'shaders/dxvk_present_frag_ms.frag', @@ -54,10 +51,6 @@ dxvk_shaders = files([ 'shaders/dxvk_resolve_frag_i.frag', 'shaders/dxvk_resolve_frag_u.frag', - 'shaders/dxvk_unpack_d24s8_as_d32s8.comp', - 'shaders/dxvk_unpack_d24s8.comp', - 'shaders/dxvk_unpack_d32s8.comp', - 'hud/shaders/hud_chunk_frag_background.frag', 'hud/shaders/hud_chunk_frag_visualize.frag', 'hud/shaders/hud_chunk_vert_background.vert', @@ -99,7 +92,6 @@ dxvk_src = [ 'dxvk_meta_clear.cpp', 'dxvk_meta_copy.cpp', 'dxvk_meta_mipgen.cpp', - 'dxvk_meta_pack.cpp', 'dxvk_meta_resolve.cpp', 'dxvk_options.cpp', 'dxvk_pipelayout.cpp', diff --git a/src/dxvk/shaders/dxvk_pack_d24s8.comp b/src/dxvk/shaders/dxvk_pack_d24s8.comp deleted file mode 100644 index b828c24a8..000000000 --- a/src/dxvk/shaders/dxvk_pack_d24s8.comp +++ /dev/null @@ -1,43 +0,0 @@ -#version 450 - -#extension GL_EXT_samplerless_texture_functions : require - -layout( - local_size_x = 8, - local_size_y = 8, - local_size_z = 1) in; - -layout(binding = 0, std430) -writeonly buffer s_buffer_t { - uint data[]; -} s_buffer; - -layout(binding = 1) uniform texture2DArray u_depth; -layout(binding = 2) uniform utexture2DArray u_stencil; - -layout(push_constant) -uniform u_info_t { - uvec2 src_offset; - uvec2 src_extent; - uvec2 dst_offset; - uvec2 dst_extent; -} u_info; - -void main() { - if (all(lessThan(gl_GlobalInvocationID.xy, u_info.src_extent))) { - uvec3 src_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.src_offset, - gl_GlobalInvocationID.z); - - uvec3 dst_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.dst_offset, - gl_GlobalInvocationID.z); - - uint dst_index = dst_coord.x + u_info.dst_extent.x * (dst_coord.y + u_info.dst_extent.y * dst_coord.z); - - float depth = texelFetch(u_depth, ivec3(src_coord), 0).r; - uint stencil = texelFetch(u_stencil, ivec3(src_coord), 0).r; - - s_buffer.data[dst_index] = uint(mix(0.0f, float((1 << 24) - 1), depth)) | (stencil << 24); - } -} \ No newline at end of file diff --git a/src/dxvk/shaders/dxvk_pack_d32s8.comp b/src/dxvk/shaders/dxvk_pack_d32s8.comp deleted file mode 100644 index 89bafe63d..000000000 --- a/src/dxvk/shaders/dxvk_pack_d32s8.comp +++ /dev/null @@ -1,46 +0,0 @@ -#version 450 - -#extension GL_EXT_samplerless_texture_functions : require - -layout( - local_size_x = 8, - local_size_y = 8, - local_size_z = 1) in; - -struct d32s8_t { - float d32; - uint s8; -}; - -layout(binding = 0, std430) -writeonly buffer s_buffer_t { - d32s8_t data[]; -} s_buffer; - -layout(binding = 1) uniform texture2DArray u_depth; -layout(binding = 2) uniform utexture2DArray u_stencil; - -layout(push_constant) -uniform u_info_t { - uvec2 src_offset; - uvec2 src_extent; - uvec2 dst_offset; - uvec2 dst_extent; -} u_info; - -void main() { - if (all(lessThan(gl_GlobalInvocationID.xy, u_info.src_extent))) { - uvec3 src_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.src_offset, - gl_GlobalInvocationID.z); - - uvec3 dst_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.dst_offset, - gl_GlobalInvocationID.z); - - uint dst_index = dst_coord.x + u_info.dst_extent.x * (dst_coord.y + u_info.dst_extent.y * dst_coord.z); - - s_buffer.data[dst_index].d32 = texelFetch(u_depth, ivec3(src_coord), 0).r; - s_buffer.data[dst_index].s8 = texelFetch(u_stencil, ivec3(src_coord), 0).r; - } -} \ No newline at end of file diff --git a/src/dxvk/shaders/dxvk_unpack_d24s8.comp b/src/dxvk/shaders/dxvk_unpack_d24s8.comp deleted file mode 100644 index 6b7a85575..000000000 --- a/src/dxvk/shaders/dxvk_unpack_d24s8.comp +++ /dev/null @@ -1,41 +0,0 @@ -#version 450 - -layout( - local_size_x = 64, - local_size_y = 1, - local_size_z = 1) in; - -layout(binding = 0, r32ui) writeonly uniform uimageBuffer u_depth; -layout(binding = 1, r8ui) writeonly uniform uimageBuffer u_stencil; - -layout(binding = 2) -readonly buffer s_buffer_t { - uint data[]; -} s_buffer; - -layout(push_constant) -uniform u_info_t { - uvec2 src_offset; - uvec2 src_extent; - uvec2 dst_offset; - uvec2 dst_extent; -} u_info; - -void main() { - if (all(lessThan(gl_GlobalInvocationID.xy, u_info.dst_extent))) { - uvec3 src_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.src_offset, - gl_GlobalInvocationID.z); - - uvec3 dst_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.dst_offset, - gl_GlobalInvocationID.z); - - uint src_index = src_coord.x + u_info.src_extent.x * (src_coord.y + u_info.src_extent.y * src_coord.z); - uint dst_index = dst_coord.x + u_info.dst_extent.x * (dst_coord.y + u_info.dst_extent.y * dst_coord.z); - - uint src_data = s_buffer.data[src_index]; - imageStore(u_depth, int(dst_index), uvec4(src_data & 0xFFFFFF)); - imageStore(u_stencil, int(dst_index), uvec4(src_data >> 24)); - } -} \ No newline at end of file diff --git a/src/dxvk/shaders/dxvk_unpack_d24s8_as_d32s8.comp b/src/dxvk/shaders/dxvk_unpack_d24s8_as_d32s8.comp deleted file mode 100644 index 4c87fbba0..000000000 --- a/src/dxvk/shaders/dxvk_unpack_d24s8_as_d32s8.comp +++ /dev/null @@ -1,41 +0,0 @@ -#version 450 - -layout( - local_size_x = 64, - local_size_y = 1, - local_size_z = 1) in; - -layout(binding = 0, r32f) writeonly uniform imageBuffer u_depth; -layout(binding = 1, r8ui) writeonly uniform uimageBuffer u_stencil; - -layout(binding = 2) -readonly buffer s_buffer_t { - uint data[]; -} s_buffer; - -layout(push_constant) -uniform u_info_t { - uvec2 src_offset; - uvec2 src_extent; - uvec2 dst_offset; - uvec2 dst_extent; -} u_info; - -void main() { - if (all(lessThan(gl_GlobalInvocationID.xy, u_info.dst_extent))) { - uvec3 src_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.src_offset, - gl_GlobalInvocationID.z); - - uvec3 dst_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.dst_offset, - gl_GlobalInvocationID.z); - - uint src_index = src_coord.x + u_info.src_extent.x * (src_coord.y + u_info.src_extent.y * src_coord.z); - uint dst_index = dst_coord.x + u_info.dst_extent.x * (dst_coord.y + u_info.dst_extent.y * dst_coord.z); - - uint src_data = s_buffer.data[src_index]; - imageStore(u_depth, int(dst_index), vec4(float(src_data & 0xFFFFFF) / float(0xFFFFFF))); - imageStore(u_stencil, int(dst_index), uvec4(src_data >> 24)); - } -} \ No newline at end of file diff --git a/src/dxvk/shaders/dxvk_unpack_d32s8.comp b/src/dxvk/shaders/dxvk_unpack_d32s8.comp deleted file mode 100644 index dd1147468..000000000 --- a/src/dxvk/shaders/dxvk_unpack_d32s8.comp +++ /dev/null @@ -1,46 +0,0 @@ -#version 450 - -layout( - local_size_x = 64, - local_size_y = 1, - local_size_z = 1) in; - -struct d32s8_t { - float d32; - uint s8; -}; - -layout(binding = 0, r32f) writeonly uniform imageBuffer u_depth; -layout(binding = 1, r8ui) writeonly uniform uimageBuffer u_stencil; - -layout(binding = 2) -readonly buffer s_buffer_t { - d32s8_t data[]; -} s_buffer; - -layout(push_constant) -uniform u_info_t { - uvec2 src_offset; - uvec2 src_extent; - uvec2 dst_offset; - uvec2 dst_extent; -} u_info; - -void main() { - if (all(lessThan(gl_GlobalInvocationID.xy, u_info.dst_extent))) { - uvec3 src_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.src_offset, - gl_GlobalInvocationID.z); - - uvec3 dst_coord = uvec3( - gl_GlobalInvocationID.xy + u_info.dst_offset, - gl_GlobalInvocationID.z); - - uint src_index = src_coord.x + u_info.src_extent.x * (src_coord.y + u_info.src_extent.y * src_coord.z); - uint dst_index = dst_coord.x + u_info.dst_extent.x * (dst_coord.y + u_info.dst_extent.y * dst_coord.z); - - d32s8_t src_data = s_buffer.data[src_index]; - imageStore(u_depth, int(dst_index), vec4(src_data.d32)); - imageStore(u_stencil, int(dst_index), uvec4(src_data.s8)); - } -} \ No newline at end of file