mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-21 13:54:18 +01:00
[d3d9] Genericise video format conversion
This commit is contained in:
parent
2caa3c9f88
commit
51903d8348
@ -19,7 +19,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
m_mapping = pDevice->LookupFormat(m_desc.Format);
|
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_adjustedExtent = VkExtent3D{ m_desc.Width / pxSize.width, m_desc.Height / pxSize.height, m_desc.Depth };
|
||||||
|
|
||||||
m_mapMode = DetermineMapMode();
|
m_mapMode = DetermineMapMode();
|
||||||
@ -147,7 +147,7 @@ namespace dxvk {
|
|||||||
info.access = VK_ACCESS_TRANSFER_READ_BIT
|
info.access = VK_ACCESS_TRANSFER_READ_BIT
|
||||||
| VK_ACCESS_TRANSFER_WRITE_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.usage |= VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
|
||||||
info.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
info.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
||||||
}
|
}
|
||||||
@ -188,7 +188,9 @@ namespace dxvk {
|
|||||||
Rc<DxvkImage> D3D9CommonTexture::CreatePrimaryImage(D3DRESOURCETYPE ResourceType) const {
|
Rc<DxvkImage> D3D9CommonTexture::CreatePrimaryImage(D3DRESOURCETYPE ResourceType) const {
|
||||||
DxvkImageCreateInfo imageInfo;
|
DxvkImageCreateInfo imageInfo;
|
||||||
imageInfo.type = GetImageTypeFromResourceType(ResourceType);
|
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.flags = 0;
|
||||||
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
||||||
imageInfo.extent.width = m_desc.Width;
|
imageInfo.extent.width = m_desc.Width;
|
||||||
@ -207,7 +209,7 @@ namespace dxvk {
|
|||||||
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL;
|
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.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
|
||||||
imageInfo.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
imageInfo.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
||||||
}
|
}
|
||||||
|
@ -4073,9 +4073,9 @@ namespace dxvk {
|
|||||||
subresource.mipLevel,
|
subresource.mipLevel,
|
||||||
subresource.arrayLayer, 1 };
|
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([
|
EmitCs([
|
||||||
cSrcBuffer = copyBuffer,
|
cSrcBuffer = copyBuffer,
|
||||||
cDstImage = image,
|
cDstImage = image,
|
||||||
@ -4088,8 +4088,8 @@ namespace dxvk {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_converter->ConvertVideoFormat(
|
m_converter->ConvertFormat(
|
||||||
videoFormat,
|
convertFormat,
|
||||||
image, subresourceLayers,
|
image, subresourceLayers,
|
||||||
copyBuffer);
|
copyBuffer);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ namespace dxvk {
|
|||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
{ VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
{ VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
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 {
|
case D3D9Format::R8G8_B8G8: return {
|
||||||
@ -167,7 +167,7 @@ namespace dxvk {
|
|||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
{ VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
{ VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
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 {
|
case D3D9Format::G8R8_G8B8: return {
|
||||||
|
@ -127,16 +127,17 @@ namespace dxvk {
|
|||||||
|
|
||||||
std::ostream& operator << (std::ostream& os, D3D9Format format);
|
std::ostream& operator << (std::ostream& os, D3D9Format format);
|
||||||
|
|
||||||
enum D3D9VideoFormat : uint32_t {
|
enum D3D9ConversionFormat : uint32_t {
|
||||||
D3D9VideoFormat_None = 0,
|
D3D9ConversionFormat_None = 0,
|
||||||
D3D9VideoFormat_YUY2 = 1,
|
D3D9ConversionFormat_YUY2 = 1,
|
||||||
D3D9VideoFormat_UYVY,
|
D3D9ConversionFormat_UYVY,
|
||||||
D3D9VideoFormat_Count
|
D3D9ConversionFormat_Count
|
||||||
};
|
};
|
||||||
|
|
||||||
struct D3D9_VIDEO_FORMAT_INFO {
|
struct D3D9_CONVERSION_FORMAT_INFO {
|
||||||
D3D9VideoFormat FormatType = D3D9VideoFormat_None;
|
D3D9ConversionFormat FormatType = D3D9ConversionFormat_None;
|
||||||
VkExtent2D MacroPixelSize = { 1u, 1u };
|
VkExtent2D MacroPixelSize = { 1u, 1u };
|
||||||
|
VkFormat VulkanFormat = VK_FORMAT_UNDEFINED;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,7 +157,7 @@ namespace dxvk {
|
|||||||
VkComponentMapping Swizzle = { ///< Color component swizzle
|
VkComponentMapping Swizzle = { ///< Color component swizzle
|
||||||
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
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; }
|
bool IsValid() { return FormatColor != VK_FORMAT_UNDEFINED; }
|
||||||
};
|
};
|
||||||
|
@ -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(
|
void D3D9FormatHelper::ConvertVideoFormat(
|
||||||
D3D9_VIDEO_FORMAT_INFO videoFormat,
|
D3D9_CONVERSION_FORMAT_INFO videoFormat,
|
||||||
const Rc<DxvkImage>& dstImage,
|
const Rc<DxvkImage>& dstImage,
|
||||||
VkImageSubresourceLayers dstSubresource,
|
VkImageSubresourceLayers dstSubresource,
|
||||||
const Rc<DxvkBuffer>& srcBuffer) {
|
const Rc<DxvkBuffer>& srcBuffer) {
|
||||||
DxvkImageViewCreateInfo imageViewInfo;
|
DxvkImageViewCreateInfo imageViewInfo;
|
||||||
imageViewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
imageViewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
imageViewInfo.format = dstImage->info().format;
|
imageViewInfo.format = dstImage->info().format;
|
||||||
@ -40,10 +55,7 @@ namespace dxvk {
|
|||||||
bufferViewInfo.rangeLength = srcBuffer->info().size;
|
bufferViewInfo.rangeLength = srcBuffer->info().size;
|
||||||
auto tmpBufferView = m_device->createBufferView(srcBuffer, bufferViewInfo);
|
auto tmpBufferView = m_device->createBufferView(srcBuffer, bufferViewInfo);
|
||||||
|
|
||||||
if (videoFormat.FormatType == D3D9VideoFormat_UYVY
|
m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, videoFormat.FormatType == D3D9ConversionFormat_UYVY);
|
||||||
|| videoFormat.FormatType == D3D9VideoFormat_YUY2) {
|
|
||||||
m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, videoFormat.FormatType == D3D9VideoFormat_UYVY);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_context->bindResourceView(BindingIds::Image, tmpImageView, nullptr);
|
m_context->bindResourceView(BindingIds::Image, tmpImageView, nullptr);
|
||||||
m_context->bindResourceView(BindingIds::Buffer, nullptr, tmpBufferView);
|
m_context->bindResourceView(BindingIds::Buffer, nullptr, tmpBufferView);
|
||||||
@ -62,8 +74,8 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
void D3D9FormatHelper::InitShaders() {
|
void D3D9FormatHelper::InitShaders() {
|
||||||
m_shaders[D3D9VideoFormat_YUY2] = InitShader(d3d9_convert_yuy2_uyvy);
|
m_shaders[D3D9ConversionFormat_YUY2] = InitShader(d3d9_convert_yuy2_uyvy);
|
||||||
m_shaders[D3D9VideoFormat_UYVY] = m_shaders[D3D9VideoFormat_YUY2];
|
m_shaders[D3D9ConversionFormat_UYVY] = m_shaders[D3D9ConversionFormat_YUY2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,14 +13,20 @@ namespace dxvk {
|
|||||||
|
|
||||||
D3D9FormatHelper(const Rc<DxvkDevice>& device);
|
D3D9FormatHelper(const Rc<DxvkDevice>& device);
|
||||||
|
|
||||||
void ConvertVideoFormat(
|
void ConvertFormat(
|
||||||
D3D9_VIDEO_FORMAT_INFO videoFormat,
|
D3D9_CONVERSION_FORMAT_INFO conversionFormat,
|
||||||
const Rc<DxvkImage>& dstImage,
|
const Rc<DxvkImage>& dstImage,
|
||||||
VkImageSubresourceLayers dstSubresource,
|
VkImageSubresourceLayers dstSubresource,
|
||||||
const Rc<DxvkBuffer>& srcBuffer);
|
const Rc<DxvkBuffer>& srcBuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void ConvertVideoFormat(
|
||||||
|
D3D9_CONVERSION_FORMAT_INFO videoFormat,
|
||||||
|
const Rc<DxvkImage>& dstImage,
|
||||||
|
VkImageSubresourceLayers dstSubresource,
|
||||||
|
const Rc<DxvkBuffer>& srcBuffer);
|
||||||
|
|
||||||
enum BindingIds : uint32_t {
|
enum BindingIds : uint32_t {
|
||||||
Image = 0,
|
Image = 0,
|
||||||
Buffer = 1,
|
Buffer = 1,
|
||||||
@ -33,7 +39,7 @@ namespace dxvk {
|
|||||||
Rc<DxvkDevice> m_device;
|
Rc<DxvkDevice> m_device;
|
||||||
Rc<DxvkContext> m_context;
|
Rc<DxvkContext> m_context;
|
||||||
|
|
||||||
std::array<Rc<DxvkShader>, D3D9VideoFormat_Count> m_shaders;
|
std::array<Rc<DxvkShader>, D3D9ConversionFormat_Count> m_shaders;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user