2019-12-16 04:28:01 +01:00
|
|
|
#include "d3d9_format_helpers.h"
|
|
|
|
|
|
|
|
#include <d3d9_convert_yuy2_uyvy.h>
|
2020-02-24 07:39:25 +01:00
|
|
|
#include <d3d9_convert_l6v5u5.h>
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
D3D9FormatHelper::D3D9FormatHelper(const Rc<DxvkDevice>& device)
|
|
|
|
: m_device(device), m_context(m_device->createContext()) {
|
|
|
|
m_context->beginRecording(
|
|
|
|
m_device->createCommandList());
|
|
|
|
|
|
|
|
InitShaders();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 15:00:15 +01:00
|
|
|
void D3D9FormatHelper::Flush() {
|
|
|
|
if (m_transferCommands != 0)
|
|
|
|
FlushInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-10 19:26:54 +01:00
|
|
|
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);
|
2020-02-24 07:39:56 +01:00
|
|
|
break;
|
2020-02-24 07:39:25 +01:00
|
|
|
case D3D9ConversionFormat_L6V5U5:
|
|
|
|
ConvertGenericFormat(conversionFormat, dstImage, dstSubresource, srcBuffer, VK_FORMAT_R16_UINT);
|
2020-02-24 07:39:56 +01:00
|
|
|
break;
|
2020-02-10 19:26:54 +01:00
|
|
|
default:
|
|
|
|
Logger::warn("Unimplemented format conversion");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-24 07:39:25 +01:00
|
|
|
void D3D9FormatHelper::ConvertGenericFormat(
|
|
|
|
D3D9_CONVERSION_FORMAT_INFO videoFormat,
|
|
|
|
const Rc<DxvkImage>& dstImage,
|
|
|
|
VkImageSubresourceLayers dstSubresource,
|
|
|
|
const Rc<DxvkBuffer>& srcBuffer,
|
|
|
|
VkFormat bufferFormat) {
|
|
|
|
DxvkImageViewCreateInfo imageViewInfo;
|
|
|
|
imageViewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
imageViewInfo.format = dstImage->info().format;
|
|
|
|
imageViewInfo.usage = VK_IMAGE_USAGE_STORAGE_BIT;
|
|
|
|
imageViewInfo.aspect = dstSubresource.aspectMask;
|
|
|
|
imageViewInfo.minLevel = dstSubresource.mipLevel;
|
|
|
|
imageViewInfo.numLevels = 1;
|
|
|
|
imageViewInfo.minLayer = dstSubresource.baseArrayLayer;
|
|
|
|
imageViewInfo.numLayers = dstSubresource.layerCount;
|
|
|
|
auto tmpImageView = m_device->createImageView(dstImage, imageViewInfo);
|
|
|
|
|
|
|
|
VkExtent3D imageExtent = dstImage->mipLevelExtent(dstSubresource.mipLevel);
|
|
|
|
|
|
|
|
DxvkBufferViewCreateInfo bufferViewInfo;
|
|
|
|
bufferViewInfo.format = bufferFormat;
|
|
|
|
bufferViewInfo.rangeOffset = 0;
|
|
|
|
bufferViewInfo.rangeLength = srcBuffer->info().size;
|
|
|
|
auto tmpBufferView = m_device->createBufferView(srcBuffer, bufferViewInfo);
|
|
|
|
|
|
|
|
m_context->bindResourceView(BindingIds::Image, tmpImageView, nullptr);
|
|
|
|
m_context->bindResourceView(BindingIds::Buffer, nullptr, tmpBufferView);
|
|
|
|
m_context->bindShader(VK_SHADER_STAGE_COMPUTE_BIT, m_shaders[videoFormat.FormatType]);
|
|
|
|
m_context->pushConstants(0, sizeof(VkExtent2D), &imageExtent);
|
|
|
|
m_context->dispatch(
|
|
|
|
(imageExtent.width / 8) + (imageExtent.width % 8),
|
|
|
|
(imageExtent.height / 8) + (imageExtent.height % 8),
|
|
|
|
1);
|
|
|
|
|
2020-02-29 15:00:15 +01:00
|
|
|
m_transferCommands += 1;
|
2020-02-24 07:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
void D3D9FormatHelper::ConvertVideoFormat(
|
2020-02-10 19:26:54 +01:00
|
|
|
D3D9_CONVERSION_FORMAT_INFO videoFormat,
|
|
|
|
const Rc<DxvkImage>& dstImage,
|
|
|
|
VkImageSubresourceLayers dstSubresource,
|
|
|
|
const Rc<DxvkBuffer>& srcBuffer) {
|
2019-12-16 04:28:01 +01:00
|
|
|
DxvkImageViewCreateInfo imageViewInfo;
|
|
|
|
imageViewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
imageViewInfo.format = dstImage->info().format;
|
|
|
|
imageViewInfo.usage = VK_IMAGE_USAGE_STORAGE_BIT;
|
|
|
|
imageViewInfo.aspect = dstSubresource.aspectMask;
|
|
|
|
imageViewInfo.minLevel = dstSubresource.mipLevel;
|
|
|
|
imageViewInfo.numLevels = 1;
|
|
|
|
imageViewInfo.minLayer = dstSubresource.baseArrayLayer;
|
|
|
|
imageViewInfo.numLayers = dstSubresource.layerCount;
|
|
|
|
auto tmpImageView = m_device->createImageView(dstImage, imageViewInfo);
|
|
|
|
|
|
|
|
VkExtent3D imageExtent = dstImage->mipLevelExtent(dstSubresource.mipLevel);
|
|
|
|
imageExtent = VkExtent3D{ imageExtent.width / videoFormat.MacroPixelSize.width,
|
|
|
|
imageExtent.height / videoFormat.MacroPixelSize.height,
|
|
|
|
1 };
|
|
|
|
|
|
|
|
DxvkBufferViewCreateInfo bufferViewInfo;
|
|
|
|
bufferViewInfo.format = VK_FORMAT_R32_UINT;
|
|
|
|
bufferViewInfo.rangeOffset = 0;
|
|
|
|
bufferViewInfo.rangeLength = srcBuffer->info().size;
|
|
|
|
auto tmpBufferView = m_device->createBufferView(srcBuffer, bufferViewInfo);
|
|
|
|
|
2020-02-10 19:26:54 +01:00
|
|
|
m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, videoFormat.FormatType == D3D9ConversionFormat_UYVY);
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
m_context->bindResourceView(BindingIds::Image, tmpImageView, nullptr);
|
|
|
|
m_context->bindResourceView(BindingIds::Buffer, nullptr, tmpBufferView);
|
|
|
|
m_context->bindShader(VK_SHADER_STAGE_COMPUTE_BIT, m_shaders[videoFormat.FormatType]);
|
|
|
|
m_context->pushConstants(0, sizeof(VkExtent2D), &imageExtent);
|
|
|
|
m_context->dispatch(
|
|
|
|
(imageExtent.width / 8) + (imageExtent.width % 8),
|
|
|
|
(imageExtent.height / 8) + (imageExtent.height % 8),
|
|
|
|
1);
|
|
|
|
|
|
|
|
// Reset the spec constants used...
|
|
|
|
m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, 0);
|
|
|
|
|
2020-02-29 15:00:15 +01:00
|
|
|
m_transferCommands += 1;
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D9FormatHelper::InitShaders() {
|
2020-02-10 19:26:54 +01:00
|
|
|
m_shaders[D3D9ConversionFormat_YUY2] = InitShader(d3d9_convert_yuy2_uyvy);
|
|
|
|
m_shaders[D3D9ConversionFormat_UYVY] = m_shaders[D3D9ConversionFormat_YUY2];
|
2020-02-24 07:39:25 +01:00
|
|
|
m_shaders[D3D9ConversionFormat_L6V5U5] = InitShader(d3d9_convert_l6v5u5);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Rc<DxvkShader> D3D9FormatHelper::InitShader(SpirvCodeBuffer code) {
|
|
|
|
const std::array<DxvkResourceSlot, 2> resourceSlots = { {
|
2020-03-02 04:54:38 +01:00
|
|
|
{ BindingIds::Image, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_IMAGE_VIEW_TYPE_2D },
|
|
|
|
{ BindingIds::Buffer, VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, VK_IMAGE_VIEW_TYPE_1D },
|
2019-12-16 04:28:01 +01:00
|
|
|
} };
|
|
|
|
|
|
|
|
return m_device->createShader(
|
|
|
|
VK_SHADER_STAGE_COMPUTE_BIT,
|
|
|
|
resourceSlots.size(), resourceSlots.data(),
|
|
|
|
{ 0u, 0u, 0u, sizeof(VkExtent2D) }, code);
|
|
|
|
}
|
|
|
|
|
2020-02-29 15:00:15 +01:00
|
|
|
|
|
|
|
void D3D9FormatHelper::FlushInternal() {
|
|
|
|
m_context->flushCommandList();
|
|
|
|
|
|
|
|
m_transferCommands = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|