diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp index 63c208f7..9c9a7817 100644 --- a/src/d3d9/d3d9_common_texture.cpp +++ b/src/d3d9/d3d9_common_texture.cpp @@ -19,7 +19,7 @@ namespace dxvk { m_mapping = pDevice->LookupFormat(m_desc.Format); - auto pxSize = m_mapping.VideoFormatInfo.MacroPixelSize; + auto pxSize = m_mapping.ConversionFormatInfo.MacroPixelSize; m_adjustedExtent = VkExtent3D{ m_desc.Width / pxSize.width, m_desc.Height / pxSize.height, m_desc.Depth }; m_mapMode = DetermineMapMode(); @@ -147,7 +147,7 @@ namespace dxvk { info.access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; - if (m_mapping.VideoFormatInfo.FormatType != D3D9VideoFormat_None) { + if (m_mapping.ConversionFormatInfo.FormatType != D3D9ConversionFormat_None) { info.usage |= VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; info.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; } @@ -188,7 +188,9 @@ namespace dxvk { Rc D3D9CommonTexture::CreatePrimaryImage(D3DRESOURCETYPE ResourceType) const { DxvkImageCreateInfo imageInfo; imageInfo.type = GetImageTypeFromResourceType(ResourceType); - imageInfo.format = m_mapping.FormatColor; + imageInfo.format = m_mapping.ConversionFormatInfo.VulkanFormat != VK_FORMAT_UNDEFINED + ? m_mapping.ConversionFormatInfo.VulkanFormat + : m_mapping.FormatColor; imageInfo.flags = 0; imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT; imageInfo.extent.width = m_desc.Width; @@ -207,7 +209,7 @@ namespace dxvk { imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL; - if (m_mapping.VideoFormatInfo.FormatType != D3D9VideoFormat_None) { + if (m_mapping.ConversionFormatInfo.FormatType != D3D9ConversionFormat_None) { imageInfo.usage |= VK_IMAGE_USAGE_STORAGE_BIT; imageInfo.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; } diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 8864a272..dbfbaf21 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -4073,9 +4073,9 @@ namespace dxvk { subresource.mipLevel, subresource.arrayLayer, 1 }; - auto videoFormat = pResource->GetFormatMapping().VideoFormatInfo; + auto convertFormat = pResource->GetFormatMapping().ConversionFormatInfo; - if (likely(videoFormat.FormatType == D3D9VideoFormat_None)) { + if (likely(convertFormat.FormatType == D3D9ConversionFormat_None)) { EmitCs([ cSrcBuffer = copyBuffer, cDstImage = image, @@ -4088,8 +4088,8 @@ namespace dxvk { }); } else { - m_converter->ConvertVideoFormat( - videoFormat, + m_converter->ConvertFormat( + convertFormat, image, subresourceLayers, copyBuffer); } diff --git a/src/d3d9/d3d9_format.cpp b/src/d3d9/d3d9_format.cpp index b875398e..b3c4a3ab 100644 --- a/src/d3d9/d3d9_format.cpp +++ b/src/d3d9/d3d9_format.cpp @@ -153,7 +153,7 @@ namespace dxvk { VK_IMAGE_ASPECT_COLOR_BIT, { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }, - { D3D9VideoFormat_UYVY, { 2u, 1u } } + { D3D9ConversionFormat_UYVY, { 2u, 1u } } }; case D3D9Format::R8G8_B8G8: return { @@ -167,7 +167,7 @@ namespace dxvk { VK_IMAGE_ASPECT_COLOR_BIT, { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }, - { D3D9VideoFormat_YUY2, { 2u, 1u } } + { D3D9ConversionFormat_YUY2, { 2u, 1u } } }; case D3D9Format::G8R8_G8B8: return { diff --git a/src/d3d9/d3d9_format.h b/src/d3d9/d3d9_format.h index 8f63ae6e..eff54b59 100644 --- a/src/d3d9/d3d9_format.h +++ b/src/d3d9/d3d9_format.h @@ -127,16 +127,17 @@ namespace dxvk { std::ostream& operator << (std::ostream& os, D3D9Format format); - enum D3D9VideoFormat : uint32_t { - D3D9VideoFormat_None = 0, - D3D9VideoFormat_YUY2 = 1, - D3D9VideoFormat_UYVY, - D3D9VideoFormat_Count + enum D3D9ConversionFormat : uint32_t { + D3D9ConversionFormat_None = 0, + D3D9ConversionFormat_YUY2 = 1, + D3D9ConversionFormat_UYVY, + D3D9ConversionFormat_Count }; - struct D3D9_VIDEO_FORMAT_INFO { - D3D9VideoFormat FormatType = D3D9VideoFormat_None; - VkExtent2D MacroPixelSize = { 1u, 1u }; + struct D3D9_CONVERSION_FORMAT_INFO { + D3D9ConversionFormat FormatType = D3D9ConversionFormat_None; + VkExtent2D MacroPixelSize = { 1u, 1u }; + VkFormat VulkanFormat = VK_FORMAT_UNDEFINED; }; /** @@ -156,7 +157,7 @@ namespace dxvk { VkComponentMapping Swizzle = { ///< Color component swizzle VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; - D3D9_VIDEO_FORMAT_INFO VideoFormatInfo = { }; + D3D9_CONVERSION_FORMAT_INFO ConversionFormatInfo = { }; bool IsValid() { return FormatColor != VK_FORMAT_UNDEFINED; } }; diff --git a/src/d3d9/d3d9_format_helpers.cpp b/src/d3d9/d3d9_format_helpers.cpp index 67d0dac8..4c7e5251 100644 --- a/src/d3d9/d3d9_format_helpers.cpp +++ b/src/d3d9/d3d9_format_helpers.cpp @@ -13,11 +13,26 @@ namespace dxvk { } + void D3D9FormatHelper::ConvertFormat( + D3D9_CONVERSION_FORMAT_INFO conversionFormat, + const Rc& dstImage, + VkImageSubresourceLayers dstSubresource, + const Rc& srcBuffer) { + switch (conversionFormat.FormatType) { + case D3D9ConversionFormat_YUY2: + case D3D9ConversionFormat_UYVY: + ConvertVideoFormat(conversionFormat, dstImage, dstSubresource, srcBuffer); + default: + Logger::warn("Unimplemented format conversion"); + } + } + + void D3D9FormatHelper::ConvertVideoFormat( - D3D9_VIDEO_FORMAT_INFO videoFormat, - const Rc& dstImage, - VkImageSubresourceLayers dstSubresource, - const Rc& srcBuffer) { + D3D9_CONVERSION_FORMAT_INFO videoFormat, + const Rc& dstImage, + VkImageSubresourceLayers dstSubresource, + const Rc& srcBuffer) { DxvkImageViewCreateInfo imageViewInfo; imageViewInfo.type = VK_IMAGE_VIEW_TYPE_2D; imageViewInfo.format = dstImage->info().format; @@ -40,10 +55,7 @@ namespace dxvk { bufferViewInfo.rangeLength = srcBuffer->info().size; auto tmpBufferView = m_device->createBufferView(srcBuffer, bufferViewInfo); - if (videoFormat.FormatType == D3D9VideoFormat_UYVY - || videoFormat.FormatType == D3D9VideoFormat_YUY2) { - m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, videoFormat.FormatType == D3D9VideoFormat_UYVY); - } + m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, videoFormat.FormatType == D3D9ConversionFormat_UYVY); m_context->bindResourceView(BindingIds::Image, tmpImageView, nullptr); m_context->bindResourceView(BindingIds::Buffer, nullptr, tmpBufferView); @@ -62,8 +74,8 @@ namespace dxvk { void D3D9FormatHelper::InitShaders() { - m_shaders[D3D9VideoFormat_YUY2] = InitShader(d3d9_convert_yuy2_uyvy); - m_shaders[D3D9VideoFormat_UYVY] = m_shaders[D3D9VideoFormat_YUY2]; + m_shaders[D3D9ConversionFormat_YUY2] = InitShader(d3d9_convert_yuy2_uyvy); + m_shaders[D3D9ConversionFormat_UYVY] = m_shaders[D3D9ConversionFormat_YUY2]; } diff --git a/src/d3d9/d3d9_format_helpers.h b/src/d3d9/d3d9_format_helpers.h index 6a3bfdb9..378da702 100644 --- a/src/d3d9/d3d9_format_helpers.h +++ b/src/d3d9/d3d9_format_helpers.h @@ -13,14 +13,20 @@ namespace dxvk { D3D9FormatHelper(const Rc& device); - void ConvertVideoFormat( - D3D9_VIDEO_FORMAT_INFO videoFormat, - const Rc& dstImage, - VkImageSubresourceLayers dstSubresource, - const Rc& srcBuffer); + void ConvertFormat( + D3D9_CONVERSION_FORMAT_INFO conversionFormat, + const Rc& dstImage, + VkImageSubresourceLayers dstSubresource, + const Rc& srcBuffer); private: + void ConvertVideoFormat( + D3D9_CONVERSION_FORMAT_INFO videoFormat, + const Rc& dstImage, + VkImageSubresourceLayers dstSubresource, + const Rc& srcBuffer); + enum BindingIds : uint32_t { Image = 0, Buffer = 1, @@ -33,7 +39,7 @@ namespace dxvk { Rc m_device; Rc m_context; - std::array, D3D9VideoFormat_Count> m_shaders; + std::array, D3D9ConversionFormat_Count> m_shaders; };