1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 10:54:16 +01:00

[d3d9] Genericise video format conversion

This commit is contained in:
Joshua Ashton 2020-02-10 18:26:54 +00:00
parent 2caa3c9f88
commit 51903d8348
6 changed files with 56 additions and 35 deletions

View File

@ -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<DxvkImage> 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;
}

View File

@ -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);
}

View File

@ -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 {

View File

@ -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; }
};

View File

@ -13,11 +13,26 @@ namespace dxvk {
}
void D3D9FormatHelper::ConvertFormat(
D3D9_CONVERSION_FORMAT_INFO conversionFormat,
const Rc<DxvkImage>& dstImage,
VkImageSubresourceLayers dstSubresource,
const Rc<DxvkBuffer>& 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<DxvkImage>& dstImage,
VkImageSubresourceLayers dstSubresource,
const Rc<DxvkBuffer>& srcBuffer) {
D3D9_CONVERSION_FORMAT_INFO videoFormat,
const Rc<DxvkImage>& dstImage,
VkImageSubresourceLayers dstSubresource,
const Rc<DxvkBuffer>& 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];
}

View File

@ -13,14 +13,20 @@ namespace dxvk {
D3D9FormatHelper(const Rc<DxvkDevice>& device);
void ConvertVideoFormat(
D3D9_VIDEO_FORMAT_INFO videoFormat,
const Rc<DxvkImage>& dstImage,
VkImageSubresourceLayers dstSubresource,
const Rc<DxvkBuffer>& srcBuffer);
void ConvertFormat(
D3D9_CONVERSION_FORMAT_INFO conversionFormat,
const Rc<DxvkImage>& dstImage,
VkImageSubresourceLayers dstSubresource,
const Rc<DxvkBuffer>& srcBuffer);
private:
void ConvertVideoFormat(
D3D9_CONVERSION_FORMAT_INFO videoFormat,
const Rc<DxvkImage>& dstImage,
VkImageSubresourceLayers dstSubresource,
const Rc<DxvkBuffer>& srcBuffer);
enum BindingIds : uint32_t {
Image = 0,
Buffer = 1,
@ -33,7 +39,7 @@ namespace dxvk {
Rc<DxvkDevice> m_device;
Rc<DxvkContext> m_context;
std::array<Rc<DxvkShader>, D3D9VideoFormat_Count> m_shaders;
std::array<Rc<DxvkShader>, D3D9ConversionFormat_Count> m_shaders;
};