2017-11-27 15:52:24 +01:00
|
|
|
#include "d3d11_device.h"
|
|
|
|
#include "d3d11_texture.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
D3D11CommonTexture::D3D11CommonTexture(
|
|
|
|
D3D11Device* pDevice,
|
|
|
|
const D3D11_COMMON_TEXTURE_DESC* pDesc,
|
|
|
|
D3D11_RESOURCE_DIMENSION Dimension)
|
2018-03-14 16:03:48 +01:00
|
|
|
: m_device(pDevice), m_desc(*pDesc) {
|
2018-07-03 12:44:56 +02:00
|
|
|
DXGI_VK_FORMAT_MODE formatMode = GetFormatMode();
|
|
|
|
DXGI_VK_FORMAT_INFO formatInfo = m_device->LookupFormat(m_desc.Format, formatMode);
|
|
|
|
DXGI_VK_FORMAT_FAMILY formatFamily = m_device->LookupFamily(m_desc.Format, formatMode);
|
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
DxvkImageCreateInfo imageInfo;
|
2018-07-03 12:44:56 +02:00
|
|
|
imageInfo.type = GetImageTypeFromResourceDim(Dimension);
|
|
|
|
imageInfo.format = formatInfo.Format;
|
|
|
|
imageInfo.flags = 0;
|
|
|
|
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
imageInfo.extent.width = m_desc.Width;
|
|
|
|
imageInfo.extent.height = m_desc.Height;
|
|
|
|
imageInfo.extent.depth = m_desc.Depth;
|
|
|
|
imageInfo.numLayers = m_desc.ArraySize;
|
|
|
|
imageInfo.mipLevels = m_desc.MipLevels;
|
|
|
|
imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
|
|
|
imageInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
|
|
|
imageInfo.access = VK_ACCESS_TRANSFER_READ_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
|
|
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
|
|
imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
|
imageInfo.viewFormatCount = formatFamily.FormatCount;
|
|
|
|
imageInfo.viewFormats = formatFamily.Formats;
|
2018-06-28 16:47:54 +02:00
|
|
|
|
2018-05-05 20:16:01 +02:00
|
|
|
DecodeSampleCount(m_desc.SampleDesc.Count, &imageInfo.sampleCount);
|
|
|
|
|
2018-07-03 12:44:56 +02:00
|
|
|
// The image must be marked as mutable if it can be
|
|
|
|
// reinterpreted by a view with a different format
|
|
|
|
bool mutableFormat = formatFamily.FormatCount > 1;
|
|
|
|
|
|
|
|
// For UAVs, the format restrictions are more relaxed.
|
|
|
|
// FIXME for typed formats, we should just add the
|
|
|
|
// corresponding integer format to the format family
|
|
|
|
if (m_desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) {
|
|
|
|
imageInfo.viewFormatCount = 0;
|
|
|
|
imageInfo.viewFormats = nullptr;
|
|
|
|
mutableFormat = true;
|
|
|
|
}
|
2018-06-24 17:01:05 +02:00
|
|
|
|
2018-05-05 20:16:01 +02:00
|
|
|
// Depth-stencil formats are not compatible to each other.
|
2018-05-05 00:49:23 +02:00
|
|
|
VkImageAspectFlags formatAspect = imageFormatInfo(formatInfo.Format)->aspectMask;
|
|
|
|
|
2018-06-24 17:01:05 +02:00
|
|
|
if (mutableFormat && (formatAspect & VK_IMAGE_ASPECT_COLOR_BIT))
|
2018-05-05 00:49:23 +02:00
|
|
|
imageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
|
|
|
|
2018-03-14 16:03:48 +01:00
|
|
|
// Adjust image flags based on the corresponding D3D flags
|
2018-03-14 01:16:31 +01:00
|
|
|
if (m_desc.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
|
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
|
|
|
|
imageInfo.stages |= pDevice->GetEnabledShaderStages();
|
|
|
|
imageInfo.access |= VK_ACCESS_SHADER_READ_BIT;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
if (m_desc.BindFlags & D3D11_BIND_RENDER_TARGET) {
|
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
|
|
imageInfo.stages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
imageInfo.access |= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
2018-03-14 14:49:45 +01:00
|
|
|
| VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
if (m_desc.BindFlags & D3D11_BIND_DEPTH_STENCIL) {
|
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
|
|
|
imageInfo.stages |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
|
2018-03-14 14:49:45 +01:00
|
|
|
| VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
2018-03-14 01:16:31 +01:00
|
|
|
imageInfo.access |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
|
2018-03-14 14:49:45 +01:00
|
|
|
| VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
if (m_desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) {
|
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
|
|
|
|
imageInfo.stages |= pDevice->GetEnabledShaderStages();
|
|
|
|
imageInfo.access |= VK_ACCESS_SHADER_READ_BIT
|
2018-03-14 14:49:45 +01:00
|
|
|
| VK_ACCESS_SHADER_WRITE_BIT;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 16:47:54 +02:00
|
|
|
// Access pattern for meta-resolve operations
|
|
|
|
if (imageInfo.sampleCount != VK_SAMPLE_COUNT_1_BIT) {
|
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
|
|
|
|
imageInfo.stages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
|
|
|
imageInfo.access |= VK_ACCESS_SHADER_READ_BIT;
|
|
|
|
}
|
|
|
|
|
2018-03-14 14:40:09 +01:00
|
|
|
if (m_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE)
|
|
|
|
imageInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
|
|
|
|
|
2018-03-14 20:40:11 +01:00
|
|
|
if (Dimension == D3D11_RESOURCE_DIMENSION_TEXTURE3D)
|
|
|
|
imageInfo.flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR;
|
|
|
|
|
2018-04-29 14:43:24 +02:00
|
|
|
// Some image formats (i.e. the R32G32B32 ones) are
|
|
|
|
// only supported with linear tiling on most GPUs
|
|
|
|
if (!CheckImageSupport(&imageInfo, VK_IMAGE_TILING_OPTIMAL))
|
|
|
|
imageInfo.tiling = VK_IMAGE_TILING_LINEAR;
|
2018-03-14 16:03:48 +01:00
|
|
|
|
|
|
|
// Determine map mode based on our findings
|
|
|
|
m_mapMode = DetermineMapMode(&imageInfo);
|
|
|
|
|
2018-03-14 14:49:45 +01:00
|
|
|
// If the image is mapped directly to host memory, we need
|
|
|
|
// to enable linear tiling, and DXVK needs to be aware that
|
|
|
|
// the image can be accessed by the host.
|
2018-03-14 14:40:09 +01:00
|
|
|
if (m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_DIRECT) {
|
2018-03-14 01:16:31 +01:00
|
|
|
imageInfo.stages |= VK_PIPELINE_STAGE_HOST_BIT;
|
2018-03-14 14:40:09 +01:00
|
|
|
imageInfo.tiling = VK_IMAGE_TILING_LINEAR;
|
2017-12-23 17:05:07 +01:00
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
if (m_desc.CPUAccessFlags & D3D11_CPU_ACCESS_WRITE)
|
|
|
|
imageInfo.access |= VK_ACCESS_HOST_WRITE_BIT;
|
2017-12-23 17:05:07 +01:00
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
if (m_desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ)
|
|
|
|
imageInfo.access |= VK_ACCESS_HOST_READ_BIT;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 14:49:45 +01:00
|
|
|
// We must keep LINEAR images in GENERAL layout, but we
|
|
|
|
// can choose a better layout for the image based on how
|
|
|
|
// it is going to be used by the game.
|
2018-03-14 01:16:31 +01:00
|
|
|
if (imageInfo.tiling == VK_IMAGE_TILING_OPTIMAL)
|
|
|
|
imageInfo.layout = OptimizeLayout(imageInfo.usage);
|
2017-12-19 16:01:50 +01:00
|
|
|
|
2018-04-29 14:43:24 +02:00
|
|
|
// Check if we can actually create the image
|
|
|
|
if (!CheckImageSupport(&imageInfo, imageInfo.tiling)) {
|
|
|
|
throw DxvkError(str::format(
|
|
|
|
"D3D11: Cannot create texture:",
|
|
|
|
"\n Format: ", imageInfo.format,
|
|
|
|
"\n Extent: ", imageInfo.extent.width,
|
|
|
|
"x", imageInfo.extent.height,
|
|
|
|
"x", imageInfo.extent.depth,
|
|
|
|
"\n Samples: ", imageInfo.sampleCount,
|
|
|
|
"\n Layers: ", imageInfo.numLayers,
|
|
|
|
"\n Levels: ", imageInfo.mipLevels,
|
|
|
|
"\n Usage: ", std::hex, imageInfo.usage));
|
|
|
|
}
|
|
|
|
|
2018-03-14 14:49:45 +01:00
|
|
|
// If necessary, create the mapped linear buffer
|
|
|
|
if (m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER)
|
|
|
|
m_buffer = CreateMappedBuffer();
|
|
|
|
|
2018-03-14 16:03:48 +01:00
|
|
|
// Create the image on a host-visible memory type
|
|
|
|
// in case it is going to be mapped directly.
|
|
|
|
VkMemoryPropertyFlags memoryProperties = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
|
|
|
|
|
|
if (m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_DIRECT) {
|
|
|
|
memoryProperties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
|
|
|
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
|
|
|
| VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_image = m_device->GetDXVKDevice()->createImage(imageInfo, memoryProperties);
|
2018-03-13 23:51:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11CommonTexture::~D3D11CommonTexture() {
|
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 23:51:30 +01:00
|
|
|
|
|
|
|
VkImageSubresource D3D11CommonTexture::GetSubresourceFromIndex(
|
|
|
|
VkImageAspectFlags Aspect,
|
2018-03-14 00:45:07 +01:00
|
|
|
UINT Subresource) const {
|
2018-03-13 23:51:30 +01:00
|
|
|
VkImageSubresource result;
|
|
|
|
result.aspectMask = Aspect;
|
|
|
|
result.mipLevel = Subresource % m_desc.MipLevels;
|
|
|
|
result.arrayLayer = Subresource / m_desc.MipLevels;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 17:49:14 +02:00
|
|
|
DXGI_VK_FORMAT_MODE D3D11CommonTexture::GetFormatMode() const {
|
2018-03-13 23:51:30 +01:00
|
|
|
if (m_desc.BindFlags & D3D11_BIND_RENDER_TARGET)
|
2018-04-12 17:49:14 +02:00
|
|
|
return DXGI_VK_FORMAT_MODE_COLOR;
|
2018-03-13 23:51:30 +01:00
|
|
|
|
|
|
|
if (m_desc.BindFlags & D3D11_BIND_DEPTH_STENCIL)
|
2018-04-12 17:49:14 +02:00
|
|
|
return DXGI_VK_FORMAT_MODE_DEPTH;
|
2018-03-13 23:51:30 +01:00
|
|
|
|
2018-04-12 17:49:14 +02:00
|
|
|
return DXGI_VK_FORMAT_MODE_ANY;
|
2018-03-13 23:51:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11CommonTexture::GetDevice(ID3D11Device** ppDevice) const {
|
|
|
|
*ppDevice = m_device.ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-05 15:13:35 +02:00
|
|
|
bool D3D11CommonTexture::CheckViewFormatCompatibility(DXGI_FORMAT Format) const {
|
2018-05-05 20:16:01 +02:00
|
|
|
DXGI_VK_FORMAT_MODE formatMode = GetFormatMode();
|
|
|
|
DXGI_VK_FORMAT_INFO baseFormat = m_device->LookupFormat(m_desc.Format, formatMode);
|
|
|
|
DXGI_VK_FORMAT_INFO viewFormat = m_device->LookupFormat(Format, formatMode);
|
|
|
|
|
|
|
|
// Identical formats always pass this test
|
|
|
|
if (baseFormat.Format == viewFormat.Format)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// The available image aspects must match
|
|
|
|
auto baseFormatInfo = imageFormatInfo(baseFormat.Format);
|
|
|
|
auto viewFormatInfo = imageFormatInfo(viewFormat.Format);
|
2018-05-05 15:13:35 +02:00
|
|
|
|
2018-05-05 20:16:01 +02:00
|
|
|
if (baseFormatInfo->aspectMask != viewFormatInfo->aspectMask)
|
2018-05-05 15:13:35 +02:00
|
|
|
return false;
|
|
|
|
|
2018-05-05 20:16:01 +02:00
|
|
|
// Color formats can be reinterpreted. This is not restricted
|
|
|
|
// to typeless formats, we we can create SRGB views for UNORM
|
|
|
|
// textures as well etc. as long as they are bit-compatible.
|
|
|
|
if (baseFormatInfo->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT)
|
|
|
|
return baseFormatInfo->elementSize == viewFormatInfo->elementSize;
|
2018-05-05 15:13:35 +02:00
|
|
|
|
2018-05-05 20:16:01 +02:00
|
|
|
return false;
|
2018-05-05 15:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-13 23:51:30 +01:00
|
|
|
HRESULT D3D11CommonTexture::NormalizeTextureProperties(D3D11_COMMON_TEXTURE_DESC* pDesc) {
|
2018-04-13 13:46:45 +02:00
|
|
|
if (FAILED(DecodeSampleCount(pDesc->SampleDesc.Count, nullptr)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
// Use the maximum possible mip level count if the supplied
|
|
|
|
// mip level count is either unspecified (0) or invalid
|
|
|
|
const uint32_t maxMipLevelCount = pDesc->SampleDesc.Count <= 1
|
2018-04-12 23:42:11 +02:00
|
|
|
? util::computeMipLevelCount({ pDesc->Width, pDesc->Height, pDesc->Depth })
|
|
|
|
: 1u;
|
|
|
|
|
|
|
|
if (pDesc->MipLevels == 0 || pDesc->MipLevels > maxMipLevelCount)
|
|
|
|
pDesc->MipLevels = maxMipLevelCount;
|
2018-03-13 23:51:30 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-14 16:03:48 +01:00
|
|
|
BOOL D3D11CommonTexture::CheckImageSupport(
|
|
|
|
const DxvkImageCreateInfo* pImageInfo,
|
|
|
|
VkImageTiling Tiling) const {
|
|
|
|
const Rc<DxvkAdapter> adapter = m_device->GetDXVKDevice()->adapter();
|
|
|
|
|
|
|
|
VkImageFormatProperties formatProps = { };
|
|
|
|
|
|
|
|
VkResult status = adapter->imageFormatProperties(
|
|
|
|
pImageInfo->format, pImageInfo->type, Tiling,
|
|
|
|
pImageInfo->usage, pImageInfo->flags, formatProps);
|
|
|
|
|
|
|
|
if (status != VK_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return (pImageInfo->extent.width <= formatProps.maxExtent.width)
|
|
|
|
&& (pImageInfo->extent.height <= formatProps.maxExtent.height)
|
|
|
|
&& (pImageInfo->extent.depth <= formatProps.maxExtent.depth)
|
|
|
|
&& (pImageInfo->numLayers <= formatProps.maxArrayLayers)
|
|
|
|
&& (pImageInfo->mipLevels <= formatProps.maxMipLevels)
|
|
|
|
&& (pImageInfo->sampleCount & formatProps.sampleCounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11_COMMON_TEXTURE_MAP_MODE D3D11CommonTexture::DetermineMapMode(
|
|
|
|
const DxvkImageCreateInfo* pImageInfo) const {
|
|
|
|
// Don't map an image unless the application requests it
|
|
|
|
if (m_desc.CPUAccessFlags == 0)
|
|
|
|
return D3D11_COMMON_TEXTURE_MAP_MODE_NONE;
|
|
|
|
|
|
|
|
// Write-only images should go through a buffer for multiple reasons:
|
|
|
|
// 1. Some games do not respect the row and depth pitch that is returned
|
|
|
|
// by the Map() method, which leads to incorrect rendering (e.g. Nier)
|
|
|
|
// 2. Since the image will most likely be read for rendering by the GPU,
|
|
|
|
// writing the image to device-local image may be more efficient than
|
|
|
|
// reading its contents from host-visible memory.
|
2018-03-14 16:40:28 +01:00
|
|
|
if (m_desc.Usage == D3D11_USAGE_DYNAMIC)
|
2018-03-14 16:03:48 +01:00
|
|
|
return D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER;
|
|
|
|
|
|
|
|
// Images that can be read by the host should be mapped directly in
|
|
|
|
// order to avoid expensive synchronization with the GPU. This does
|
|
|
|
// however require linear tiling, which may not be supported for all
|
|
|
|
// combinations of image parameters.
|
|
|
|
return this->CheckImageSupport(pImageInfo, VK_IMAGE_TILING_LINEAR)
|
|
|
|
? D3D11_COMMON_TEXTURE_MAP_MODE_DIRECT
|
2018-03-14 14:40:09 +01:00
|
|
|
: D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
Rc<DxvkBuffer> D3D11CommonTexture::CreateMappedBuffer() const {
|
|
|
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(
|
2018-04-12 17:49:14 +02:00
|
|
|
m_device->LookupFormat(m_desc.Format, GetFormatMode()).Format);
|
2018-03-14 01:16:31 +01:00
|
|
|
|
|
|
|
const VkExtent3D blockCount = util::computeBlockCount(
|
|
|
|
VkExtent3D { m_desc.Width, m_desc.Height, m_desc.Depth },
|
|
|
|
formatInfo->blockSize);
|
|
|
|
|
|
|
|
DxvkBufferCreateInfo info;
|
|
|
|
info.size = formatInfo->elementSize
|
|
|
|
* blockCount.width
|
|
|
|
* blockCount.height
|
|
|
|
* blockCount.depth;
|
|
|
|
info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
|
|
|
info.stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
|
|
|
info.access = VK_ACCESS_TRANSFER_READ_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
|
|
|
|
|
|
return m_device->GetDXVKDevice()->createBuffer(info,
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
|
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-13 23:51:30 +01:00
|
|
|
VkImageType D3D11CommonTexture::GetImageTypeFromResourceDim(D3D11_RESOURCE_DIMENSION Dimension) {
|
|
|
|
switch (Dimension) {
|
|
|
|
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: return VK_IMAGE_TYPE_1D;
|
|
|
|
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: return VK_IMAGE_TYPE_2D;
|
|
|
|
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: return VK_IMAGE_TYPE_3D;
|
|
|
|
default: throw DxvkError("D3D11CommonTexture: Unhandled resource dimension");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-14 01:16:31 +01:00
|
|
|
VkImageLayout D3D11CommonTexture::OptimizeLayout(VkImageUsageFlags Usage) {
|
|
|
|
const VkImageUsageFlags usageFlags = Usage;
|
|
|
|
|
|
|
|
// Filter out unnecessary flags. Transfer operations
|
|
|
|
// are handled by the backend in a transparent manner.
|
|
|
|
Usage &= ~(VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
|
|
|
|
|
|
|
|
// If the image is used only as an attachment, we never
|
|
|
|
// have to transform the image back to a different layout
|
|
|
|
if (Usage == VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
|
|
|
return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
if (Usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
Usage &= ~(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
|
|
|
| VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
|
|
|
|
|
|
|
|
// If the image is used for reading but not as a storage
|
|
|
|
// image, we can optimize the image for texture access
|
|
|
|
if (Usage == VK_IMAGE_USAGE_SAMPLED_BIT) {
|
|
|
|
return usageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
|
|
|
|
? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
|
|
|
|
: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we have to stick with the default layout
|
|
|
|
return VK_IMAGE_LAYOUT_GENERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-20 10:38:39 +02:00
|
|
|
D3D11VkInteropSurface::D3D11VkInteropSurface(
|
2018-04-20 11:12:54 +02:00
|
|
|
ID3D11DeviceChild* pContainer,
|
2018-04-20 10:38:39 +02:00
|
|
|
D3D11CommonTexture* pTexture)
|
|
|
|
: m_container (pContainer),
|
|
|
|
m_texture (pTexture) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11VkInteropSurface::~D3D11VkInteropSurface() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11VkInteropSurface::AddRef() {
|
|
|
|
return m_container->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11VkInteropSurface::Release() {
|
|
|
|
return m_container->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11VkInteropSurface::QueryInterface(
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject) {
|
|
|
|
return m_container->QueryInterface(riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-01 23:30:39 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11VkInteropSurface::GetDevice(
|
|
|
|
IDXGIVkInteropDevice** ppDevice) {
|
|
|
|
Com<ID3D11Device> device;
|
|
|
|
m_container->GetDevice(&device);
|
|
|
|
|
|
|
|
return device->QueryInterface(
|
|
|
|
__uuidof(IDXGIVkInteropDevice),
|
|
|
|
reinterpret_cast<void**>(ppDevice));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-20 10:38:39 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11VkInteropSurface::GetVulkanImageInfo(
|
|
|
|
VkImage* pHandle,
|
|
|
|
VkImageLayout* pLayout,
|
|
|
|
VkImageCreateInfo* pInfo) {
|
|
|
|
const Rc<DxvkImage> image = m_texture->GetImage();
|
|
|
|
const DxvkImageCreateInfo& info = image->info();
|
|
|
|
|
|
|
|
if (pHandle != nullptr)
|
|
|
|
*pHandle = image->handle();
|
|
|
|
|
|
|
|
if (pLayout != nullptr)
|
|
|
|
*pLayout = info.layout;
|
|
|
|
|
|
|
|
if (pInfo != nullptr) {
|
|
|
|
// We currently don't support any extended structures
|
|
|
|
if (pInfo->sType != VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
|
|
|
|
|| pInfo->pNext != nullptr)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
pInfo->flags = 0;
|
|
|
|
pInfo->imageType = info.type;
|
|
|
|
pInfo->format = info.format;
|
|
|
|
pInfo->extent = info.extent;
|
|
|
|
pInfo->mipLevels = info.mipLevels;
|
|
|
|
pInfo->arrayLayers = info.numLayers;
|
|
|
|
pInfo->samples = info.sampleCount;
|
|
|
|
pInfo->tiling = info.tiling;
|
|
|
|
pInfo->usage = info.usage;
|
|
|
|
pInfo->sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
|
|
|
pInfo->queueFamilyIndexCount = 0;
|
|
|
|
pInfo->initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// D 3 D 1 1 T E X T U R E 1 D
|
2018-03-13 23:51:30 +01:00
|
|
|
D3D11Texture1D::D3D11Texture1D(
|
|
|
|
D3D11Device* pDevice,
|
|
|
|
const D3D11_COMMON_TEXTURE_DESC* pDesc)
|
2018-04-20 11:12:54 +02:00
|
|
|
: m_texture(pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE1D),
|
|
|
|
m_interop(this, &m_texture) {
|
2018-03-13 23:51:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
D3D11Texture1D::~D3D11Texture1D() {
|
2017-12-19 16:01:50 +01:00
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Texture1D::QueryInterface(REFIID riid, void** ppvObject) {
|
2018-04-02 12:52:02 +02:00
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceChild)
|
|
|
|
|| riid == __uuidof(ID3D11Resource)
|
|
|
|
|| riid == __uuidof(ID3D11Texture1D)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-12-19 16:01:50 +01:00
|
|
|
|
2018-04-20 11:12:54 +02:00
|
|
|
if (riid == __uuidof(IDXGIVkInteropSurface)) {
|
|
|
|
*ppvObject = ref(&m_interop);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
Logger::warn("D3D11Texture1D::QueryInterface: Unknown interface query");
|
2018-03-12 12:05:43 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2017-12-23 17:05:07 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2017-11-27 15:52:24 +01:00
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Texture1D::GetDevice(ID3D11Device** ppDevice) {
|
2018-03-13 23:51:30 +01:00
|
|
|
m_texture.GetDevice(ppDevice);
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Texture1D::GetType(D3D11_RESOURCE_DIMENSION *pResourceDimension) {
|
|
|
|
*pResourceDimension = D3D11_RESOURCE_DIMENSION_TEXTURE1D;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UINT STDMETHODCALLTYPE D3D11Texture1D::GetEvictionPriority() {
|
|
|
|
Logger::warn("D3D11Texture1D::GetEvictionPriority: Stub");
|
|
|
|
return DXGI_RESOURCE_PRIORITY_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Texture1D::SetEvictionPriority(UINT EvictionPriority) {
|
|
|
|
Logger::warn("D3D11Texture1D::SetEvictionPriority: Stub");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Texture1D::GetDesc(D3D11_TEXTURE1D_DESC *pDesc) {
|
2018-03-13 23:51:30 +01:00
|
|
|
pDesc->Width = m_texture.Desc()->Width;
|
|
|
|
pDesc->MipLevels = m_texture.Desc()->MipLevels;
|
|
|
|
pDesc->ArraySize = m_texture.Desc()->ArraySize;
|
|
|
|
pDesc->Format = m_texture.Desc()->Format;
|
|
|
|
pDesc->Usage = m_texture.Desc()->Usage;
|
|
|
|
pDesc->BindFlags = m_texture.Desc()->BindFlags;
|
|
|
|
pDesc->CPUAccessFlags = m_texture.Desc()->CPUAccessFlags;
|
|
|
|
pDesc->MiscFlags = m_texture.Desc()->MiscFlags;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
// D 3 D 1 1 T E X T U R E 2 D
|
|
|
|
D3D11Texture2D::D3D11Texture2D(
|
|
|
|
D3D11Device* pDevice,
|
2018-03-13 23:51:30 +01:00
|
|
|
const D3D11_COMMON_TEXTURE_DESC* pDesc)
|
2018-04-20 11:12:54 +02:00
|
|
|
: m_texture(pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE2D),
|
|
|
|
m_interop(this, &m_texture) {
|
2017-12-19 16:01:50 +01:00
|
|
|
|
2017-11-27 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11Texture2D::~D3D11Texture2D() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Texture2D::QueryInterface(REFIID riid, void** ppvObject) {
|
2018-04-02 12:52:02 +02:00
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceChild)
|
|
|
|
|| riid == __uuidof(ID3D11Resource)
|
|
|
|
|| riid == __uuidof(ID3D11Texture2D)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-11-27 15:52:24 +01:00
|
|
|
|
2018-04-20 11:12:54 +02:00
|
|
|
if (riid == __uuidof(IDXGIVkInteropSurface)) {
|
|
|
|
*ppvObject = ref(&m_interop);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-27 15:52:24 +01:00
|
|
|
Logger::warn("D3D11Texture2D::QueryInterface: Unknown interface query");
|
2018-03-12 12:05:43 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2017-11-27 15:52:24 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Texture2D::GetDevice(ID3D11Device** ppDevice) {
|
2018-03-13 23:51:30 +01:00
|
|
|
m_texture.GetDevice(ppDevice);
|
2017-11-27 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Texture2D::GetType(D3D11_RESOURCE_DIMENSION *pResourceDimension) {
|
2017-11-27 15:52:24 +01:00
|
|
|
*pResourceDimension = D3D11_RESOURCE_DIMENSION_TEXTURE2D;
|
|
|
|
}
|
|
|
|
|
2017-11-29 07:55:44 +01:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
UINT STDMETHODCALLTYPE D3D11Texture2D::GetEvictionPriority() {
|
2017-12-19 16:01:50 +01:00
|
|
|
Logger::warn("D3D11Texture2D::GetEvictionPriority: Stub");
|
|
|
|
return DXGI_RESOURCE_PRIORITY_NORMAL;
|
2017-11-29 15:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Texture2D::SetEvictionPriority(UINT EvictionPriority) {
|
2017-12-19 16:01:50 +01:00
|
|
|
Logger::warn("D3D11Texture2D::SetEvictionPriority: Stub");
|
2017-11-29 15:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11Texture2D::GetDesc(D3D11_TEXTURE2D_DESC *pDesc) {
|
2018-03-13 23:51:30 +01:00
|
|
|
pDesc->Width = m_texture.Desc()->Width;
|
|
|
|
pDesc->Height = m_texture.Desc()->Height;
|
|
|
|
pDesc->MipLevels = m_texture.Desc()->MipLevels;
|
|
|
|
pDesc->ArraySize = m_texture.Desc()->ArraySize;
|
|
|
|
pDesc->Format = m_texture.Desc()->Format;
|
|
|
|
pDesc->SampleDesc = m_texture.Desc()->SampleDesc;
|
|
|
|
pDesc->Usage = m_texture.Desc()->Usage;
|
|
|
|
pDesc->BindFlags = m_texture.Desc()->BindFlags;
|
|
|
|
pDesc->CPUAccessFlags = m_texture.Desc()->CPUAccessFlags;
|
|
|
|
pDesc->MiscFlags = m_texture.Desc()->MiscFlags;
|
2017-11-27 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
2017-12-19 16:01:50 +01:00
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
///////////////////////////////////////////
|
2018-03-10 23:32:15 +01:00
|
|
|
// D 3 D 1 1 T E X T U R E 3 D
|
2017-12-23 17:05:07 +01:00
|
|
|
D3D11Texture3D::D3D11Texture3D(
|
|
|
|
D3D11Device* pDevice,
|
2018-03-13 23:51:30 +01:00
|
|
|
const D3D11_COMMON_TEXTURE_DESC* pDesc)
|
2018-04-20 11:12:54 +02:00
|
|
|
: m_texture(pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE3D),
|
|
|
|
m_interop(this, &m_texture) {
|
2018-01-06 02:09:07 +01:00
|
|
|
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11Texture3D::~D3D11Texture3D() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11Texture3D::QueryInterface(REFIID riid, void** ppvObject) {
|
2018-04-02 12:52:02 +02:00
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceChild)
|
|
|
|
|| riid == __uuidof(ID3D11Resource)
|
|
|
|
|| riid == __uuidof(ID3D11Texture3D)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
2018-04-20 11:12:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (riid == __uuidof(IDXGIVkInteropSurface)) {
|
|
|
|
*ppvObject = ref(&m_interop);
|
|
|
|
return S_OK;
|
2018-04-02 12:52:02 +02:00
|
|
|
}
|
2017-12-23 17:05:07 +01:00
|
|
|
|
|
|
|
Logger::warn("D3D11Texture3D::QueryInterface: Unknown interface query");
|
2018-03-12 12:05:43 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2017-12-23 17:05:07 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Texture3D::GetDevice(ID3D11Device** ppDevice) {
|
2018-03-13 23:51:30 +01:00
|
|
|
m_texture.GetDevice(ppDevice);
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Texture3D::GetType(D3D11_RESOURCE_DIMENSION *pResourceDimension) {
|
|
|
|
*pResourceDimension = D3D11_RESOURCE_DIMENSION_TEXTURE3D;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UINT STDMETHODCALLTYPE D3D11Texture3D::GetEvictionPriority() {
|
|
|
|
Logger::warn("D3D11Texture3D::GetEvictionPriority: Stub");
|
|
|
|
return DXGI_RESOURCE_PRIORITY_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Texture3D::SetEvictionPriority(UINT EvictionPriority) {
|
|
|
|
Logger::warn("D3D11Texture3D::SetEvictionPriority: Stub");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11Texture3D::GetDesc(D3D11_TEXTURE3D_DESC *pDesc) {
|
2018-03-13 23:51:30 +01:00
|
|
|
pDesc->Width = m_texture.Desc()->Width;
|
|
|
|
pDesc->Height = m_texture.Desc()->Height;
|
|
|
|
pDesc->Depth = m_texture.Desc()->Depth;
|
|
|
|
pDesc->MipLevels = m_texture.Desc()->MipLevels;
|
|
|
|
pDesc->Format = m_texture.Desc()->Format;
|
|
|
|
pDesc->Usage = m_texture.Desc()->Usage;
|
|
|
|
pDesc->BindFlags = m_texture.Desc()->BindFlags;
|
|
|
|
pDesc->CPUAccessFlags = m_texture.Desc()->CPUAccessFlags;
|
|
|
|
pDesc->MiscFlags = m_texture.Desc()->MiscFlags;
|
2017-12-23 17:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-19 16:01:50 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
D3D11CommonTexture* GetCommonTexture(ID3D11Resource* pResource) {
|
2017-12-19 16:01:50 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION dimension = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
pResource->GetType(&dimension);
|
|
|
|
|
|
|
|
switch (dimension) {
|
2018-01-05 01:15:56 +01:00
|
|
|
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
2018-03-14 00:45:07 +01:00
|
|
|
return static_cast<D3D11Texture1D*>(pResource)->GetCommonTexture();
|
2017-12-23 17:05:07 +01:00
|
|
|
|
2018-01-05 01:15:56 +01:00
|
|
|
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
2018-03-14 00:45:07 +01:00
|
|
|
return static_cast<D3D11Texture2D*>(pResource)->GetCommonTexture();
|
2017-12-19 16:01:50 +01:00
|
|
|
|
2018-01-05 01:15:56 +01:00
|
|
|
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
2018-03-14 00:45:07 +01:00
|
|
|
return static_cast<D3D11Texture3D*>(pResource)->GetCommonTexture();
|
2017-12-23 17:05:07 +01:00
|
|
|
|
2017-12-19 16:01:50 +01:00
|
|
|
default:
|
2018-01-05 01:15:56 +01:00
|
|
|
return nullptr;
|
2017-12-19 16:01:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 15:52:24 +01:00
|
|
|
}
|