1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-30 22:24:15 +01:00

[d3d11] Implemented SRV and RTV normalization

This commit is contained in:
Philip Rebohle 2018-02-14 01:29:50 +01:00
parent 54cfdbdc51
commit 4965f8c318
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 176 additions and 0 deletions

View File

@ -510,6 +510,9 @@ namespace dxvk {
return E_INVALIDARG;
} else {
desc = *pDesc;
if (FAILED(SetRenderTargetViewDescUnspecValues(pResource, &desc)))
return E_INVALIDARG;
}
// Retrieve the image that we are going to create the view for
@ -600,6 +603,9 @@ namespace dxvk {
return E_INVALIDARG;
} else {
desc = *pDesc;
if (FAILED(SetDepthStencilViewDescUnspecValues(pResource, &desc)))
return E_INVALIDARG;
}
// Retrieve the image that we are going to create the view for
@ -2005,6 +2011,168 @@ namespace dxvk {
}
HRESULT D3D11Device::SetRenderTargetViewDescUnspecValues(
ID3D11Resource* pResource,
D3D11_RENDER_TARGET_VIEW_DESC* pDesc) {
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pResource->GetType(&resourceDim);
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
uint32_t numLayers = 0;
switch (resourceDim) {
case D3D11_RESOURCE_DIMENSION_BUFFER: {
if (pDesc->ViewDimension != D3D11_RTV_DIMENSION_BUFFER) {
Logger::err("D3D11: Incompatible view dimension for Buffer");
return E_INVALIDARG;
}
} break;
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
D3D11_TEXTURE1D_DESC resourceDesc;
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
if (pDesc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE1D
&& pDesc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE1DARRAY) {
Logger::err("D3D11: Incompatible view dimension for Texture1D");
return E_INVALIDARG;
}
format = resourceDesc.Format;
numLayers = resourceDesc.ArraySize;
} break;
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
D3D11_TEXTURE2D_DESC resourceDesc;
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
if (pDesc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2D
&& pDesc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DARRAY
&& pDesc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS
&& pDesc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY) {
Logger::err("D3D11: Incompatible view dimension for Texture2D");
return E_INVALIDARG;
}
format = resourceDesc.Format;
numLayers = resourceDesc.ArraySize;
} break;
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
D3D11_TEXTURE3D_DESC resourceDesc;
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
if (pDesc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE3D) {
Logger::err("D3D11: Incompatible view dimension for Texture3D");
return E_INVALIDARG;
}
format = resourceDesc.Format;
numLayers = 1;
} break;
default:
return E_INVALIDARG;
}
if (pDesc->Format == DXGI_FORMAT_UNKNOWN)
pDesc->Format = format;
switch (pDesc->ViewDimension) {
case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
if (pDesc->Texture1DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
pDesc->Texture1DArray.ArraySize = numLayers - pDesc->Texture1DArray.FirstArraySlice;
break;
case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
if (pDesc->Texture2DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
pDesc->Texture2DArray.ArraySize = numLayers - pDesc->Texture2DArray.FirstArraySlice;
break;
case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
if (pDesc->Texture2DMSArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
pDesc->Texture2DMSArray.ArraySize = numLayers - pDesc->Texture2DMSArray.FirstArraySlice;
break;
default:
break;
}
return S_OK;
}
HRESULT D3D11Device::SetDepthStencilViewDescUnspecValues(
ID3D11Resource* pResource,
D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc) {
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pResource->GetType(&resourceDim);
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
uint32_t numLayers = 0;
switch (resourceDim) {
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
D3D11_TEXTURE1D_DESC resourceDesc;
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
if (pDesc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE1D
&& pDesc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE1DARRAY) {
Logger::err("D3D11: Incompatible view dimension for Texture1D");
return E_INVALIDARG;
}
format = resourceDesc.Format;
numLayers = resourceDesc.ArraySize;
} break;
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
D3D11_TEXTURE2D_DESC resourceDesc;
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
if (pDesc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2D
&& pDesc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DARRAY
&& pDesc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS
&& pDesc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY) {
Logger::err("D3D11: Incompatible view dimension for Texture2D");
return E_INVALIDARG;
}
format = resourceDesc.Format;
numLayers = resourceDesc.ArraySize;
} break;
default:
return E_INVALIDARG;
}
if (pDesc->Format == DXGI_FORMAT_UNKNOWN)
pDesc->Format = format;
switch (pDesc->ViewDimension) {
case D3D11_DSV_DIMENSION_TEXTURE1DARRAY:
if (pDesc->Texture1DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
pDesc->Texture1DArray.ArraySize = numLayers - pDesc->Texture1DArray.FirstArraySlice;
break;
case D3D11_DSV_DIMENSION_TEXTURE2DARRAY:
if (pDesc->Texture2DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
pDesc->Texture2DArray.ArraySize = numLayers - pDesc->Texture2DArray.FirstArraySlice;
break;
case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY:
if (pDesc->Texture2DMSArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
pDesc->Texture2DMSArray.ArraySize = numLayers - pDesc->Texture2DMSArray.FirstArraySlice;
break;
default:
break;
}
return S_OK;
}
VkSamplerAddressMode D3D11Device::DecodeAddressMode(
D3D11_TEXTURE_ADDRESS_MODE mode) const {
switch (mode) {

View File

@ -322,6 +322,14 @@ namespace dxvk {
ID3D11Resource* pResource,
D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc);
HRESULT SetRenderTargetViewDescUnspecValues(
ID3D11Resource* pResource,
D3D11_RENDER_TARGET_VIEW_DESC* pDesc);
HRESULT SetDepthStencilViewDescUnspecValues(
ID3D11Resource* pResource,
D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc);
VkSamplerAddressMode DecodeAddressMode(
D3D11_TEXTURE_ADDRESS_MODE mode) const;