1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-14 04:29:15 +01:00

[d3d11] Refactored texture interfaces

All texture classes now use the common info structure
internally as well so that it can be queried efficiently.
This commit is contained in:
Philip Rebohle 2018-01-05 01:15:56 +01:00
parent c816078f13
commit 93a5cf093c
5 changed files with 109 additions and 137 deletions

View File

@ -236,14 +236,10 @@ namespace dxvk {
pMappedResource->DepthPitch = buffer->info().size;
return S_OK;
} else {
D3D11TextureInfo textureInfo;
const D3D11TextureInfo* textureInfo
= GetCommonTextureInfo(pResource);
if (FAILED(GetCommonTextureInfo(pResource, &textureInfo))) {
Logger::err("D3D11DeviceContext: Failed to retrieve texture info");
return E_FAIL;
}
if (textureInfo.image->mapPtr(0) == nullptr) {
if (textureInfo->image->mapPtr(0) == nullptr) {
Logger::err("D3D11DeviceContext: Cannot map a device-local image");
return E_FAIL;
}
@ -251,7 +247,7 @@ namespace dxvk {
if (pMappedResource == nullptr)
return S_OK;
if (textureInfo.image->isInUse()) {
if (textureInfo->image->isInUse()) {
// Don't wait if the application tells us not to
if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT)
return DXGI_ERROR_WAS_STILL_DRAWING;
@ -260,17 +256,17 @@ namespace dxvk {
this->Synchronize();
}
const DxvkImageCreateInfo imageInfo = textureInfo.image->info();
const DxvkImageCreateInfo imageInfo = textureInfo->image->info();
const VkImageSubresource imageSubresource =
GetSubresourceFromIndex(VK_IMAGE_ASPECT_COLOR_BIT,
imageInfo.mipLevels, Subresource);
const VkSubresourceLayout layout =
textureInfo.image->querySubresourceLayout(imageSubresource);
textureInfo->image->querySubresourceLayout(imageSubresource);
// TODO handle undefined stuff
pMappedResource->pData = textureInfo.image->mapPtr(layout.offset);
pMappedResource->pData = textureInfo->image->mapPtr(layout.offset);
pMappedResource->RowPitch = layout.rowPitch;
pMappedResource->DepthPitch = layout.depthPitch;
return S_OK;
@ -355,14 +351,8 @@ namespace dxvk {
if (dstResourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
Logger::err("D3D11DeviceContext::CopySubresourceRegion: Buffers not supported");
} else {
D3D11TextureInfo dstTextureInfo;
D3D11TextureInfo srcTextureInfo;
if (FAILED(GetCommonTextureInfo(pDstResource, &dstTextureInfo))
|| FAILED(GetCommonTextureInfo(pSrcResource, &srcTextureInfo))) {
Logger::err("D3D11DeviceContext: Failed to retrieve DXVK images");
return;
}
const D3D11TextureInfo* dstTextureInfo = GetCommonTextureInfo(pDstResource);
const D3D11TextureInfo* srcTextureInfo = GetCommonTextureInfo(pSrcResource);
VkOffset3D srcOffset = { 0, 0, 0 };
VkOffset3D dstOffset = {
@ -370,7 +360,7 @@ namespace dxvk {
static_cast<int32_t>(DstY),
static_cast<int32_t>(DstZ) };
VkExtent3D extent = srcTextureInfo.image->info().extent;
VkExtent3D extent = srcTextureInfo->image->info().extent;
if (pSrcBox != nullptr) {
if (pSrcBox->left >= pSrcBox->right
@ -387,18 +377,18 @@ namespace dxvk {
extent.depth = pSrcBox->back - pSrcBox->front;
}
const DxvkFormatInfo* dstFormatInfo = imageFormatInfo(dstTextureInfo.image->info().format);
const DxvkFormatInfo* srcFormatInfo = imageFormatInfo(srcTextureInfo.image->info().format);
const DxvkFormatInfo* dstFormatInfo = imageFormatInfo(dstTextureInfo->image->info().format);
const DxvkFormatInfo* srcFormatInfo = imageFormatInfo(srcTextureInfo->image->info().format);
const VkImageSubresource dstSubresource =
GetSubresourceFromIndex(
dstFormatInfo->aspectMask & srcFormatInfo->aspectMask,
dstTextureInfo.image->info().mipLevels, DstSubresource);
dstTextureInfo->image->info().mipLevels, DstSubresource);
const VkImageSubresource srcSubresource =
GetSubresourceFromIndex(
dstFormatInfo->aspectMask & srcFormatInfo->aspectMask,
srcTextureInfo.image->info().mipLevels, SrcSubresource);
srcTextureInfo->image->info().mipLevels, SrcSubresource);
const VkImageSubresourceLayers dstLayers = {
dstSubresource.aspectMask,
@ -411,8 +401,8 @@ namespace dxvk {
srcSubresource.arrayLayer, 1 };
m_context->copyImage(
dstTextureInfo.image, dstLayers, dstOffset,
srcTextureInfo.image, srcLayers, srcOffset,
dstTextureInfo->image, dstLayers, dstOffset,
srcTextureInfo->image, srcLayers, srcOffset,
extent);
}
}
@ -615,15 +605,11 @@ namespace dxvk {
size, pSrcData);
}
} else {
D3D11TextureInfo textureInfo;
if (FAILED(GetCommonTextureInfo(pDstResource, &textureInfo))) {
Logger::err("D3D11DeviceContext: Failed to retrieve DXVK image");
return;
}
const D3D11TextureInfo* textureInfo
= GetCommonTextureInfo(pDstResource);
VkOffset3D offset = { 0, 0, 0 };
VkExtent3D extent = textureInfo.image->info().extent;
VkExtent3D extent = textureInfo->image->info().extent;
if (pDstBox != nullptr) {
if (pDstBox->left >= pDstBox->right
@ -642,7 +628,7 @@ namespace dxvk {
const VkImageSubresource imageSubresource =
GetSubresourceFromIndex(VK_IMAGE_ASPECT_COLOR_BIT,
textureInfo.image->info().mipLevels, DstSubresource);
textureInfo->image->info().mipLevels, DstSubresource);
VkImageSubresourceLayers layers;
layers.aspectMask = imageSubresource.aspectMask;
@ -651,7 +637,7 @@ namespace dxvk {
layers.layerCount = 1;
m_context->updateImage(
textureInfo.image, layers,
textureInfo->image, layers,
offset, extent, pSrcData,
SrcRowPitch, SrcDepthPitch);
}

View File

@ -88,7 +88,7 @@ namespace dxvk {
const Com<D3D11Texture1D> texture
= new D3D11Texture1D(this, pDesc);
this->InitTexture(texture->GetDXVKImage(), pInitialData);
this->InitTexture(texture->GetTextureInfo()->image, pInitialData);
*ppTexture1D = texture.ref();
}
@ -104,7 +104,7 @@ namespace dxvk {
const Com<D3D11Texture2D> texture
= new D3D11Texture2D(this, pDesc);
this->InitTexture(texture->GetDXVKImage(), pInitialData);
this->InitTexture(texture->GetTextureInfo()->image, pInitialData);
*ppTexture2D = texture.ref();
}
@ -120,7 +120,7 @@ namespace dxvk {
const Com<D3D11Texture3D> texture
= new D3D11Texture3D(this, pDesc);
this->InitTexture(texture->GetDXVKImage(), pInitialData);
this->InitTexture(texture->GetTextureInfo()->image, pInitialData);
*ppTexture3D = texture.ref();
}
@ -210,18 +210,14 @@ namespace dxvk {
}
} else {
// Retrieve info about the image
D3D11TextureInfo textureInfo;
if (FAILED(GetCommonTextureInfo(pResource, &textureInfo))) {
Logger::err("D3D11Device: Cannot create shader resource view: Invalid texture");
return E_INVALIDARG;
}
const D3D11TextureInfo* textureInfo
= GetCommonTextureInfo(pResource);
// Fill in the view info. The view type depends solely
// on the view dimension field in the view description,
// not on the resource type.
const DxgiFormatInfo formatInfo = m_dxgiAdapter
->LookupFormat(desc.Format, textureInfo.formatMode);
->LookupFormat(desc.Format, textureInfo->formatMode);
DxvkImageViewCreateInfo viewInfo;
viewInfo.format = formatInfo.format;
@ -309,7 +305,7 @@ namespace dxvk {
}
if (viewInfo.numLevels == 0 || viewInfo.numLevels == 0xFFFFFFFF)
viewInfo.numLevels = textureInfo.image->info().mipLevels - viewInfo.minLevel;
viewInfo.numLevels = textureInfo->image->info().mipLevels - viewInfo.minLevel;
if (ppSRView == nullptr)
return S_FALSE;
@ -318,7 +314,7 @@ namespace dxvk {
*ppSRView = ref(new D3D11ShaderResourceView(
this, pResource, desc,
m_dxvkDevice->createImageView(
textureInfo.image, viewInfo)));
textureInfo->image, viewInfo)));
return S_OK;
} catch (const DxvkError& e) {
Logger::err(e.message());
@ -392,18 +388,14 @@ namespace dxvk {
}
} else {
// Retrieve info about the image
D3D11TextureInfo textureInfo;
if (FAILED(GetCommonTextureInfo(pResource, &textureInfo))) {
Logger::err("D3D11Device: Cannot create unordered access view: Invalid texture");
return E_INVALIDARG;
}
const D3D11TextureInfo* textureInfo
= GetCommonTextureInfo(pResource);
// Fill in the view info. The view type depends solely
// on the view dimension field in the view description,
// not on the resource type.
const DxgiFormatInfo formatInfo = m_dxgiAdapter
->LookupFormat(desc.Format, textureInfo.formatMode);
->LookupFormat(desc.Format, textureInfo->formatMode);
DxvkImageViewCreateInfo viewInfo;
viewInfo.format = formatInfo.format;
@ -465,7 +457,7 @@ namespace dxvk {
*ppUAView = ref(new D3D11UnorderedAccessView(
this, pResource, desc,
m_dxvkDevice->createImageView(
textureInfo.image, viewInfo)));
textureInfo->image, viewInfo)));
return S_OK;
} catch (const DxvkError& e) {
Logger::err(e.message());
@ -500,12 +492,8 @@ namespace dxvk {
}
// Retrieve the image that we are going to create the view for
D3D11TextureInfo textureInfo;
if (FAILED(GetCommonTextureInfo(pResource, &textureInfo))) {
Logger::err("D3D11Device: Cannot create shader resource view: Invalid texture");
return E_INVALIDARG;
}
const D3D11TextureInfo* textureInfo
= GetCommonTextureInfo(pResource);
// Fill in Vulkan image view info
DxvkImageViewCreateInfo viewInfo;
@ -560,7 +548,7 @@ namespace dxvk {
*ppRTView = ref(new D3D11RenderTargetView(
this, pResource, desc,
m_dxvkDevice->createImageView(
textureInfo.image, viewInfo)));
textureInfo->image, viewInfo)));
return S_OK;
} catch (const DxvkError& e) {
Logger::err(e.message());
@ -594,12 +582,8 @@ namespace dxvk {
}
// Retrieve the image that we are going to create the view for
D3D11TextureInfo textureInfo;
if (FAILED(GetCommonTextureInfo(pResource, &textureInfo))) {
Logger::err("D3D11Device: Cannot create shader resource view: Invalid texture");
return E_INVALIDARG;
}
const D3D11TextureInfo* textureInfo
= GetCommonTextureInfo(pResource);
// Fill in Vulkan image view info
DxvkImageViewCreateInfo viewInfo;
@ -654,7 +638,7 @@ namespace dxvk {
*ppDepthStencilView = ref(new D3D11DepthStencilView(
this, pResource, desc,
m_dxvkDevice->createImageView(
textureInfo.image, viewInfo)));
textureInfo->image, viewInfo)));
return S_OK;
} catch (const DxvkError& e) {
Logger::err(e.message());

View File

@ -9,7 +9,7 @@ namespace dxvk {
Rc<DxvkImage> D3D11PresentBackBuffer::GetDXVKImage() {
return m_texture->GetDXVKImage();
return m_texture->GetTextureInfo()->image;
}

View File

@ -126,12 +126,14 @@ namespace dxvk {
D3D11Device* pDevice,
const D3D11_TEXTURE1D_DESC* pDesc)
: m_device (pDevice),
m_formatMode(GetFormatModeFromBindFlags(pDesc->BindFlags)),
m_desc (*pDesc) {
const DxgiFormatMode formatMode
= GetFormatModeFromBindFlags(pDesc->BindFlags);
DxvkImageCreateInfo info;
info.type = VK_IMAGE_TYPE_1D;
info.format = pDevice->LookupFormat(pDesc->Format, m_formatMode).format;
info.format = pDevice->LookupFormat(pDesc->Format, formatMode).format;
info.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
info.sampleCount = VK_SAMPLE_COUNT_1_BIT;
info.extent.width = pDesc->Width;
@ -154,8 +156,11 @@ namespace dxvk {
pDesc->MiscFlags,
&info);
m_image = pDevice->GetDXVKDevice()->createImage(
// Create the image and, if necessary, the image buffer
m_texInfo.formatMode = formatMode;
m_texInfo.image = pDevice->GetDXVKDevice()->createImage(
info, GetMemoryFlagsForUsage(pDesc->Usage));
m_texInfo.imageBuffer = D3D11ImageBuffer { nullptr, 0, 0 };
}
///////////////////////////////////////////
@ -208,12 +213,14 @@ namespace dxvk {
D3D11Device* pDevice,
const D3D11_TEXTURE2D_DESC* pDesc)
: m_device (pDevice),
m_formatMode(GetFormatModeFromBindFlags(pDesc->BindFlags)),
m_desc (*pDesc) {
const DxgiFormatMode formatMode
= GetFormatModeFromBindFlags(pDesc->BindFlags);
DxvkImageCreateInfo info;
info.type = VK_IMAGE_TYPE_2D;
info.format = pDevice->LookupFormat(pDesc->Format, m_formatMode).format;
info.format = pDevice->LookupFormat(pDesc->Format, formatMode).format;
info.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
info.sampleCount = VK_SAMPLE_COUNT_1_BIT;
info.extent.width = pDesc->Width;
@ -239,8 +246,11 @@ namespace dxvk {
pDesc->MiscFlags,
&info);
m_image = pDevice->GetDXVKDevice()->createImage(
// Create the image and, if necessary, the image buffer
m_texInfo.formatMode = formatMode;
m_texInfo.image = pDevice->GetDXVKDevice()->createImage(
info, GetMemoryFlagsForUsage(pDesc->Usage));
m_texInfo.imageBuffer = D3D11ImageBuffer { nullptr, 0, 0 };
}
@ -292,12 +302,14 @@ namespace dxvk {
D3D11Device* pDevice,
const D3D11_TEXTURE3D_DESC* pDesc)
: m_device (pDevice),
m_formatMode(GetFormatModeFromBindFlags(pDesc->BindFlags)),
m_desc (*pDesc) {
const DxgiFormatMode formatMode
= GetFormatModeFromBindFlags(pDesc->BindFlags);
DxvkImageCreateInfo info;
info.type = VK_IMAGE_TYPE_3D;
info.format = pDevice->LookupFormat(pDesc->Format, m_formatMode).format;
info.format = pDevice->LookupFormat(pDesc->Format, formatMode).format;
info.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
| VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR;
info.sampleCount = VK_SAMPLE_COUNT_1_BIT;
@ -321,8 +333,11 @@ namespace dxvk {
pDesc->MiscFlags,
&info);
m_image = pDevice->GetDXVKDevice()->createImage(
// Create the image and, if necessary, the image buffer
m_texInfo.formatMode = formatMode;
m_texInfo.image = pDevice->GetDXVKDevice()->createImage(
info, GetMemoryFlagsForUsage(pDesc->Usage));
m_texInfo.imageBuffer = D3D11ImageBuffer { nullptr, 0, 0 };
}
@ -369,33 +384,22 @@ namespace dxvk {
HRESULT GetCommonTextureInfo(
ID3D11Resource* pResource,
D3D11TextureInfo* pTextureInfo) {
const D3D11TextureInfo* GetCommonTextureInfo(ID3D11Resource* pResource) {
D3D11_RESOURCE_DIMENSION dimension = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pResource->GetType(&dimension);
switch (dimension) {
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
auto tex = static_cast<D3D11Texture1D*>(pResource);
pTextureInfo->formatMode = tex->GetFormatMode();
pTextureInfo->image = tex->GetDXVKImage();
} return S_OK;
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
return static_cast<D3D11Texture1D*>(pResource)->GetTextureInfo();
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
auto tex = static_cast<D3D11Texture2D*>(pResource);
pTextureInfo->formatMode = tex->GetFormatMode();
pTextureInfo->image = tex->GetDXVKImage();
} return S_OK;
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
return static_cast<D3D11Texture2D*>(pResource)->GetTextureInfo();
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
auto tex = static_cast<D3D11Texture3D*>(pResource);
pTextureInfo->formatMode = tex->GetFormatMode();
pTextureInfo->image = tex->GetDXVKImage();
} return S_OK;
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
return static_cast<D3D11Texture3D*>(pResource)->GetTextureInfo();
default:
return E_INVALIDARG;
return nullptr;
}
}

View File

@ -9,6 +9,32 @@ namespace dxvk {
class D3D11Device;
/**
* \brief Image buffer info
*
* Stores the buffer used for mapping
* an image and the row/layer strides.
*/
struct D3D11ImageBuffer {
Rc<DxvkBuffer> buffer;
VkDeviceSize bytesPerRow;
VkDeviceSize bytesPerLayer;
};
/**
* \brief Common texture info
*
* Stores the image and the image format
* mode for a texture of any type.
*/
struct D3D11TextureInfo {
DxgiFormatMode formatMode;
D3D11ImageBuffer imageBuffer;
Rc<DxvkImage> image;
};
///////////////////////////////////////////
// D 3 D 1 1 T E X T U R E 1 D
class D3D11Texture1D : public D3D11DeviceChild<ID3D11Texture1D> {
@ -38,20 +64,15 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc(
D3D11_TEXTURE1D_DESC *pDesc) final;
DxgiFormatMode GetFormatMode() const {
return m_formatMode;
}
Rc<DxvkImage> GetDXVKImage() const {
return m_image;
const D3D11TextureInfo* GetTextureInfo() const {
return &m_texInfo;
}
private:
Com<D3D11Device> m_device;
DxgiFormatMode m_formatMode;
D3D11_TEXTURE1D_DESC m_desc;
Rc<DxvkImage> m_image;
D3D11TextureInfo m_texInfo;
};
@ -85,20 +106,15 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc(
D3D11_TEXTURE2D_DESC *pDesc) final;
DxgiFormatMode GetFormatMode() const {
return m_formatMode;
}
Rc<DxvkImage> GetDXVKImage() const {
return m_image;
const D3D11TextureInfo* GetTextureInfo() const {
return &m_texInfo;
}
private:
Com<D3D11Device> m_device;
DxgiFormatMode m_formatMode;
D3D11_TEXTURE2D_DESC m_desc;
Rc<DxvkImage> m_image;
D3D11TextureInfo m_texInfo;
};
@ -132,36 +148,19 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc(
D3D11_TEXTURE3D_DESC *pDesc) final;
DxgiFormatMode GetFormatMode() const {
return m_formatMode;
}
Rc<DxvkImage> GetDXVKImage() const {
return m_image;
const D3D11TextureInfo* GetTextureInfo() const {
return &m_texInfo;
}
private:
Com<D3D11Device> m_device;
DxgiFormatMode m_formatMode;
D3D11_TEXTURE3D_DESC m_desc;
Rc<DxvkImage> m_image;
D3D11TextureInfo m_texInfo;
};
/**
* \brief Common texture info
*
* Stores the image and the image format
* mode for a texture of any type.
*/
struct D3D11TextureInfo {
DxgiFormatMode formatMode;
Rc<DxvkImage> image;
};
/**
* \brief Retrieves common info about a texture
*
@ -169,9 +168,8 @@ namespace dxvk {
* \param [out] pTextureInfo Pointer to the texture info struct.
* \returns E_INVALIDARG if the resource is not a texture
*/
HRESULT GetCommonTextureInfo(
ID3D11Resource* pResource,
D3D11TextureInfo* pTextureInfo);
const D3D11TextureInfo* GetCommonTextureInfo(
ID3D11Resource* pResource);
/**
* \brief Computes image subresource from subresource index