mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-04 16:24:29 +01:00
[d3d11] Refactor Render Target View Creation
Part 2 / 4 of the refactor.
This commit is contained in:
parent
0598982f35
commit
1038bf2ef5
@ -694,96 +694,12 @@ namespace dxvk {
|
|||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the image that we are going to create the view for
|
|
||||||
const D3D11CommonTexture* textureInfo = GetCommonTexture(pResource);
|
|
||||||
|
|
||||||
// Fill in Vulkan image view info
|
|
||||||
DxvkImageViewCreateInfo viewInfo;
|
|
||||||
viewInfo.format = m_dxgiAdapter->LookupFormat(desc.Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
|
|
||||||
viewInfo.aspect = imageFormatInfo(viewInfo.format)->aspectMask;
|
|
||||||
viewInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
||||||
|
|
||||||
switch (desc.ViewDimension) {
|
|
||||||
case D3D11_RTV_DIMENSION_TEXTURE1D:
|
|
||||||
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
|
||||||
viewInfo.minLevel = desc.Texture1D.MipSlice;
|
|
||||||
viewInfo.numLevels = 1;
|
|
||||||
viewInfo.minLayer = 0;
|
|
||||||
viewInfo.numLayers = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
|
|
||||||
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
|
||||||
viewInfo.minLevel = desc.Texture1DArray.MipSlice;
|
|
||||||
viewInfo.numLevels = 1;
|
|
||||||
viewInfo.minLayer = desc.Texture1DArray.FirstArraySlice;
|
|
||||||
viewInfo.numLayers = desc.Texture1DArray.ArraySize;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RTV_DIMENSION_TEXTURE2D:
|
|
||||||
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
||||||
viewInfo.minLevel = desc.Texture2D.MipSlice;
|
|
||||||
viewInfo.numLevels = 1;
|
|
||||||
viewInfo.minLayer = 0;
|
|
||||||
viewInfo.numLayers = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
|
|
||||||
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
||||||
viewInfo.minLevel = desc.Texture2DArray.MipSlice;
|
|
||||||
viewInfo.numLevels = 1;
|
|
||||||
viewInfo.minLayer = desc.Texture2DArray.FirstArraySlice;
|
|
||||||
viewInfo.numLayers = desc.Texture2DArray.ArraySize;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RTV_DIMENSION_TEXTURE2DMS:
|
|
||||||
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
||||||
viewInfo.minLevel = 0;
|
|
||||||
viewInfo.numLevels = 1;
|
|
||||||
viewInfo.minLayer = 0;
|
|
||||||
viewInfo.numLayers = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
|
|
||||||
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
||||||
viewInfo.minLevel = 0;
|
|
||||||
viewInfo.numLevels = 1;
|
|
||||||
viewInfo.minLayer = desc.Texture2DMSArray.FirstArraySlice;
|
|
||||||
viewInfo.numLayers = desc.Texture2DMSArray.ArraySize;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RTV_DIMENSION_TEXTURE3D:
|
|
||||||
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
||||||
viewInfo.minLevel = desc.Texture3D.MipSlice;
|
|
||||||
viewInfo.numLevels = 1;
|
|
||||||
viewInfo.minLayer = desc.Texture3D.FirstWSlice;
|
|
||||||
viewInfo.numLayers = desc.Texture3D.WSize;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Logger::err(str::format(
|
|
||||||
"D3D11: pDesc->ViewDimension not supported for render target views: ",
|
|
||||||
desc.ViewDimension));
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normalize view type so that we won't accidentally
|
|
||||||
// bind 2D array views and 2D views at the same time
|
|
||||||
if (viewInfo.numLayers == 1) {
|
|
||||||
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_1D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
|
||||||
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_2D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the actual image view if requested
|
// Create the actual image view if requested
|
||||||
if (ppRTView == nullptr)
|
if (ppRTView == nullptr)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
*ppRTView = ref(new D3D11RenderTargetView(
|
*ppRTView = ref(new D3D11RenderTargetView(this, pResource, &desc));
|
||||||
this, pResource, desc,
|
|
||||||
m_dxvkDevice->createImageView(
|
|
||||||
textureInfo->GetImage(),
|
|
||||||
viewInfo)));
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
} catch (const DxvkError& e) {
|
} catch (const DxvkError& e) {
|
||||||
Logger::err(e.message());
|
Logger::err(e.message());
|
||||||
|
@ -6,12 +6,87 @@
|
|||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
D3D11RenderTargetView::D3D11RenderTargetView(
|
D3D11RenderTargetView::D3D11RenderTargetView(
|
||||||
D3D11Device* device,
|
D3D11Device* pDevice,
|
||||||
ID3D11Resource* resource,
|
ID3D11Resource* pResource,
|
||||||
const D3D11_RENDER_TARGET_VIEW_DESC& desc,
|
const D3D11_RENDER_TARGET_VIEW_DESC* pDesc)
|
||||||
const Rc<DxvkImageView>& view)
|
: m_device(pDevice), m_resource(pResource), m_desc(*pDesc) {
|
||||||
: m_device(device), m_resource(resource),
|
DxvkImageViewCreateInfo viewInfo;
|
||||||
m_desc(desc), m_view(view) { }
|
viewInfo.format = pDevice->LookupFormat(pDesc->Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
|
||||||
|
viewInfo.aspect = imageFormatInfo(viewInfo.format)->aspectMask;
|
||||||
|
viewInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
|
|
||||||
|
switch (pDesc->ViewDimension) {
|
||||||
|
case D3D11_RTV_DIMENSION_TEXTURE1D:
|
||||||
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
||||||
|
viewInfo.minLevel = pDesc->Texture1D.MipSlice;
|
||||||
|
viewInfo.numLevels = 1;
|
||||||
|
viewInfo.minLayer = 0;
|
||||||
|
viewInfo.numLayers = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
|
||||||
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
||||||
|
viewInfo.minLevel = pDesc->Texture1DArray.MipSlice;
|
||||||
|
viewInfo.numLevels = 1;
|
||||||
|
viewInfo.minLayer = pDesc->Texture1DArray.FirstArraySlice;
|
||||||
|
viewInfo.numLayers = pDesc->Texture1DArray.ArraySize;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case D3D11_RTV_DIMENSION_TEXTURE2D:
|
||||||
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
viewInfo.minLevel = pDesc->Texture2D.MipSlice;
|
||||||
|
viewInfo.numLevels = 1;
|
||||||
|
viewInfo.minLayer = 0;
|
||||||
|
viewInfo.numLayers = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
|
||||||
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
||||||
|
viewInfo.minLevel = pDesc->Texture2DArray.MipSlice;
|
||||||
|
viewInfo.numLevels = 1;
|
||||||
|
viewInfo.minLayer = pDesc->Texture2DArray.FirstArraySlice;
|
||||||
|
viewInfo.numLayers = pDesc->Texture2DArray.ArraySize;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case D3D11_RTV_DIMENSION_TEXTURE2DMS:
|
||||||
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
viewInfo.minLevel = 0;
|
||||||
|
viewInfo.numLevels = 1;
|
||||||
|
viewInfo.minLayer = 0;
|
||||||
|
viewInfo.numLayers = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
|
||||||
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
||||||
|
viewInfo.minLevel = 0;
|
||||||
|
viewInfo.numLevels = 1;
|
||||||
|
viewInfo.minLayer = pDesc->Texture2DMSArray.FirstArraySlice;
|
||||||
|
viewInfo.numLayers = pDesc->Texture2DMSArray.ArraySize;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case D3D11_RTV_DIMENSION_TEXTURE3D:
|
||||||
|
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
||||||
|
viewInfo.minLevel = pDesc->Texture3D.MipSlice;
|
||||||
|
viewInfo.numLevels = 1;
|
||||||
|
viewInfo.minLayer = pDesc->Texture3D.FirstWSlice;
|
||||||
|
viewInfo.numLayers = pDesc->Texture3D.WSize;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw DxvkError("D3D11: Invalid view dimension for RTV");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize view type so that we won't accidentally
|
||||||
|
// bind 2D array views and 2D views at the same time
|
||||||
|
if (viewInfo.numLayers == 1) {
|
||||||
|
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_1D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_1D;
|
||||||
|
if (viewInfo.type == VK_IMAGE_VIEW_TYPE_2D_ARRAY) viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the underlying image view object
|
||||||
|
m_view = pDevice->GetDXVKDevice()->createImageView(
|
||||||
|
GetCommonTexture(pResource)->GetImage(), viewInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
D3D11RenderTargetView::~D3D11RenderTargetView() {
|
D3D11RenderTargetView::~D3D11RenderTargetView() {
|
||||||
|
@ -16,10 +16,9 @@ namespace dxvk {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
D3D11RenderTargetView(
|
D3D11RenderTargetView(
|
||||||
D3D11Device* device,
|
D3D11Device* pDevice,
|
||||||
ID3D11Resource* resource,
|
ID3D11Resource* pResource,
|
||||||
const D3D11_RENDER_TARGET_VIEW_DESC& desc,
|
const D3D11_RENDER_TARGET_VIEW_DESC* pDesc);
|
||||||
const Rc<DxvkImageView>& view);
|
|
||||||
|
|
||||||
~D3D11RenderTargetView();
|
~D3D11RenderTargetView();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user