mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-02 19:24:12 +01:00
[d3d11] Moved GetViewFromDesc and NormalizeDesc out of D3D11Devuce
This commit is contained in:
parent
0ddbb58ce4
commit
ccfe1a346b
@ -217,12 +217,12 @@ namespace dxvk {
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC desc;
|
||||
|
||||
if (pDesc == nullptr) {
|
||||
if (FAILED(GetShaderResourceViewDescFromResource(pResource, &desc)))
|
||||
if (FAILED(D3D11ShaderResourceView::GetDescFromResource(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
} else {
|
||||
desc = *pDesc;
|
||||
|
||||
if (FAILED(SetShaderResourceViewDescUnspecValues(pResource, &desc)))
|
||||
if (FAILED(D3D11ShaderResourceView::NormalizeDesc(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
@ -422,12 +422,12 @@ namespace dxvk {
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
|
||||
|
||||
if (pDesc == nullptr) {
|
||||
if (FAILED(GetUnorderedAccessViewDescFromResource(pResource, &desc)))
|
||||
if (FAILED(D3D11UnorderedAccessView::GetDescFromResource(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
} else {
|
||||
desc = *pDesc;
|
||||
|
||||
if (FAILED(SetUnorderedAccessViewDescUnspecValues(pResource, &desc)))
|
||||
if (FAILED(D3D11UnorderedAccessView::NormalizeDesc(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
@ -589,12 +589,12 @@ namespace dxvk {
|
||||
D3D11_RENDER_TARGET_VIEW_DESC desc;
|
||||
|
||||
if (pDesc == nullptr) {
|
||||
if (FAILED(GetRenderTargetViewDescFromResource(pResource, &desc)))
|
||||
if (FAILED(D3D11RenderTargetView::GetDescFromResource(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
} else {
|
||||
desc = *pDesc;
|
||||
|
||||
if (FAILED(SetRenderTargetViewDescUnspecValues(pResource, &desc)))
|
||||
if (FAILED(D3D11RenderTargetView::NormalizeDesc(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
@ -706,12 +706,12 @@ namespace dxvk {
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC desc;
|
||||
|
||||
if (pDesc == nullptr) {
|
||||
if (FAILED(GetDepthStencilViewDescFromResource(pResource, &desc)))
|
||||
if (FAILED(D3D11DepthStencilView::GetDescFromResource(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
} else {
|
||||
desc = *pDesc;
|
||||
|
||||
if (FAILED(SetDepthStencilViewDescUnspecValues(pResource, &desc)))
|
||||
if (FAILED(D3D11DepthStencilView::NormalizeDesc(pResource, &desc)))
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
@ -1664,681 +1664,6 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11Device::GetShaderResourceViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER: {
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
static_cast<D3D11Buffer*>(pResource)->GetDesc(&bufferDesc);
|
||||
|
||||
if (bufferDesc.MiscFlags == D3D11_RESOURCE_MISC_BUFFER_STRUCTURED) {
|
||||
pDesc->Format = DXGI_FORMAT_UNKNOWN;
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
|
||||
pDesc->Buffer.FirstElement = 0;
|
||||
pDesc->Buffer.NumElements = bufferDesc.ByteWidth / bufferDesc.StructureByteStride;
|
||||
return S_OK;
|
||||
}
|
||||
} return E_INVALIDARG;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MostDetailedMip = 0;
|
||||
pDesc->Texture1D.MipLevels = resourceDesc.MipLevels;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MostDetailedMip = 0;
|
||||
pDesc->Texture1DArray.MipLevels = resourceDesc.MipLevels;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.SampleDesc.Count == 1) {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MostDetailedMip = 0;
|
||||
pDesc->Texture2D.MipLevels = resourceDesc.MipLevels;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MostDetailedMip = 0;
|
||||
pDesc->Texture2DArray.MipLevels = resourceDesc.MipLevels;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} else {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY;
|
||||
pDesc->Texture2DMSArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DMSArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
|
||||
pDesc->Texture3D.MostDetailedMip = 0;
|
||||
pDesc->Texture3D.MipLevels = resourceDesc.MipLevels;
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for shader resource view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11Device::GetUnorderedAccessViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER: {
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
static_cast<D3D11Buffer*>(pResource)->GetDesc(&bufferDesc);
|
||||
|
||||
if (bufferDesc.MiscFlags == D3D11_RESOURCE_MISC_BUFFER_STRUCTURED) {
|
||||
pDesc->Format = DXGI_FORMAT_UNKNOWN;
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
|
||||
pDesc->Buffer.FirstElement = 0;
|
||||
pDesc->Buffer.NumElements = bufferDesc.ByteWidth / bufferDesc.StructureByteStride;
|
||||
return S_OK;
|
||||
}
|
||||
} return E_INVALIDARG;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MipSlice = 0;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MipSlice = 0;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
|
||||
pDesc->Texture3D.MipSlice = 0;
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for unordered access view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11Device::GetRenderTargetViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_RENDER_TARGET_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MipSlice = 0;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.SampleDesc.Count == 1) {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MipSlice = 0;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} else {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
|
||||
pDesc->Texture2DMSArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DMSArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
|
||||
pDesc->Texture3D.MipSlice = 0;
|
||||
pDesc->Texture3D.FirstWSlice = 0;
|
||||
pDesc->Texture3D.WSize = resourceDesc.Depth;
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for render target view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11Device::GetDepthStencilViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MipSlice = 0;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.SampleDesc.Count == 1) {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MipSlice = 0;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} else {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
|
||||
pDesc->Texture2DMSArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DMSArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for depth stencil view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11Device::SetShaderResourceViewDescUnspecValues(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
|
||||
uint32_t mipLevels = 0;
|
||||
uint32_t numLayers = 0;
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER: {
|
||||
if (pDesc->ViewDimension != D3D11_SRV_DIMENSION_BUFFER
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX) {
|
||||
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_SRV_DIMENSION_TEXTURE1D
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE1DARRAY) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture1D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
mipLevels = resourceDesc.MipLevels;
|
||||
numLayers = resourceDesc.ArraySize;
|
||||
} break;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
if (pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2D
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DARRAY
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURECUBE
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURECUBEARRAY) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture2D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
mipLevels = resourceDesc.MipLevels;
|
||||
numLayers = resourceDesc.ArraySize;
|
||||
} break;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
if (pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE3D) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture3D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
mipLevels = resourceDesc.MipLevels;
|
||||
numLayers = 1;
|
||||
} break;
|
||||
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (pDesc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
pDesc->Format = format;
|
||||
|
||||
switch (pDesc->ViewDimension) {
|
||||
case D3D11_SRV_DIMENSION_TEXTURE1D:
|
||||
if (pDesc->Texture1D.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture1D.MipLevels = mipLevels - pDesc->Texture1D.MostDetailedMip;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
|
||||
if (pDesc->Texture1DArray.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture1DArray.MipLevels = mipLevels - pDesc->Texture1DArray.MostDetailedMip;
|
||||
if (pDesc->Texture1DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture1DArray.ArraySize = numLayers - pDesc->Texture1DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE2D:
|
||||
if (pDesc->Texture2D.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture2D.MipLevels = mipLevels - pDesc->Texture2D.MostDetailedMip;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
|
||||
if (pDesc->Texture2DArray.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture2DArray.MipLevels = mipLevels - pDesc->Texture2DArray.MostDetailedMip;
|
||||
if (pDesc->Texture2DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture2DArray.ArraySize = numLayers - pDesc->Texture2DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
|
||||
if (pDesc->Texture2DMSArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture2DMSArray.ArraySize = numLayers - pDesc->Texture2DMSArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURECUBE:
|
||||
if (pDesc->TextureCube.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->TextureCube.MipLevels = mipLevels - pDesc->TextureCube.MostDetailedMip;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY:
|
||||
if (pDesc->TextureCubeArray.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->TextureCubeArray.MipLevels = mipLevels - pDesc->TextureCubeArray.MostDetailedMip;
|
||||
if (pDesc->TextureCubeArray.NumCubes == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->TextureCubeArray.NumCubes = (numLayers - pDesc->TextureCubeArray.First2DArrayFace / 6);
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE3D:
|
||||
if (pDesc->Texture3D.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture3D.MipLevels = mipLevels - pDesc->Texture3D.MostDetailedMip;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11Device::SetUnorderedAccessViewDescUnspecValues(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_UNORDERED_ACCESS_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_UAV_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_UAV_DIMENSION_TEXTURE1D
|
||||
&& pDesc->ViewDimension != D3D11_UAV_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_UAV_DIMENSION_TEXTURE2D
|
||||
&& pDesc->ViewDimension != D3D11_UAV_DIMENSION_TEXTURE2DARRAY) {
|
||||
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_UAV_DIMENSION_TEXTURE3D) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture3D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
numLayers = resourceDesc.Depth >> pDesc->Texture3D.MipSlice;
|
||||
} break;
|
||||
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (pDesc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
pDesc->Format = format;
|
||||
|
||||
switch (pDesc->ViewDimension) {
|
||||
case D3D11_UAV_DIMENSION_TEXTURE1DARRAY:
|
||||
if (pDesc->Texture1DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture1DArray.ArraySize = numLayers - pDesc->Texture1DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_UAV_DIMENSION_TEXTURE2DARRAY:
|
||||
if (pDesc->Texture2DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture2DArray.ArraySize = numLayers - pDesc->Texture2DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_UAV_DIMENSION_TEXTURE3D:
|
||||
if (pDesc->Texture3D.WSize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture3D.WSize = numLayers - pDesc->Texture3D.FirstWSlice;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
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 = resourceDesc.Depth;
|
||||
} 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;
|
||||
|
||||
case D3D11_RTV_DIMENSION_TEXTURE3D:
|
||||
if (pDesc->Texture3D.WSize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture3D.WSize = numLayers - pDesc->Texture3D.FirstWSlice;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11Device::GetFormatSupportFlags(DXGI_FORMAT Format, UINT* pFlags) const {
|
||||
const VkFormat fmt = m_dxgiAdapter->LookupFormat(Format, DxgiFormatMode::Any).format;
|
||||
const VkFormatProperties fmtInfo = m_dxvkAdapter->formatProperties(fmt);
|
||||
|
@ -299,38 +299,6 @@ namespace dxvk {
|
||||
const Rc<DxvkImage>& image,
|
||||
const D3D11_SUBRESOURCE_DATA* pInitialData);
|
||||
|
||||
HRESULT GetShaderResourceViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc);
|
||||
|
||||
HRESULT GetUnorderedAccessViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc);
|
||||
|
||||
HRESULT GetRenderTargetViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_RENDER_TARGET_VIEW_DESC* pDesc);
|
||||
|
||||
HRESULT GetDepthStencilViewDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc);
|
||||
|
||||
HRESULT SetShaderResourceViewDescUnspecValues(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc);
|
||||
|
||||
HRESULT SetUnorderedAccessViewDescUnspecValues(
|
||||
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);
|
||||
|
||||
HRESULT GetFormatSupportFlags(DXGI_FORMAT Format, UINT* pFlags) const;
|
||||
|
||||
void CreateCounterBuffer();
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "d3d11_device.h"
|
||||
#include "d3d11_buffer.h"
|
||||
#include "d3d11_texture.h"
|
||||
#include "d3d11_view_dsv.h"
|
||||
|
||||
namespace dxvk {
|
||||
@ -43,4 +45,135 @@ namespace dxvk {
|
||||
*pDesc = m_desc;
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11DepthStencilView::GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MipSlice = 0;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.SampleDesc.Count == 1) {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MipSlice = 0;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} else {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
|
||||
pDesc->Texture2DMSArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DMSArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for depth stencil view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11DepthStencilView::NormalizeDesc(
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,6 +58,14 @@ namespace dxvk {
|
||||
}
|
||||
}
|
||||
|
||||
static HRESULT GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc);
|
||||
|
||||
static HRESULT NormalizeDesc(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC* pDesc);
|
||||
|
||||
private:
|
||||
|
||||
Com<D3D11Device> m_device;
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "d3d11_device.h"
|
||||
#include "d3d11_buffer.h"
|
||||
#include "d3d11_texture.h"
|
||||
#include "d3d11_view_rtv.h"
|
||||
|
||||
namespace dxvk {
|
||||
@ -43,4 +45,171 @@ namespace dxvk {
|
||||
*pDesc = m_desc;
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11RenderTargetView::GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_RENDER_TARGET_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MipSlice = 0;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.SampleDesc.Count == 1) {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MipSlice = 0;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} else {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
|
||||
pDesc->Texture2DMSArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DMSArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
pDesc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
|
||||
pDesc->Texture3D.MipSlice = 0;
|
||||
pDesc->Texture3D.FirstWSlice = 0;
|
||||
pDesc->Texture3D.WSize = resourceDesc.Depth;
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for render target view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11RenderTargetView::NormalizeDesc(
|
||||
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 = resourceDesc.Depth;
|
||||
} 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;
|
||||
|
||||
case D3D11_RTV_DIMENSION_TEXTURE3D:
|
||||
if (pDesc->Texture3D.WSize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture3D.WSize = numLayers - pDesc->Texture3D.FirstWSlice;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,6 +46,14 @@ namespace dxvk {
|
||||
return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
|
||||
static HRESULT GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_RENDER_TARGET_VIEW_DESC* pDesc);
|
||||
|
||||
static HRESULT NormalizeDesc(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_RENDER_TARGET_VIEW_DESC* pDesc);
|
||||
|
||||
private:
|
||||
|
||||
Com<D3D11Device> m_device;
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "d3d11_device.h"
|
||||
#include "d3d11_buffer.h"
|
||||
#include "d3d11_texture.h"
|
||||
#include "d3d11_view_srv.h"
|
||||
|
||||
namespace dxvk {
|
||||
@ -52,4 +54,220 @@ namespace dxvk {
|
||||
*pDesc = m_desc;
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11ShaderResourceView::GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER: {
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
static_cast<D3D11Buffer*>(pResource)->GetDesc(&bufferDesc);
|
||||
|
||||
if (bufferDesc.MiscFlags == D3D11_RESOURCE_MISC_BUFFER_STRUCTURED) {
|
||||
pDesc->Format = DXGI_FORMAT_UNKNOWN;
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
|
||||
pDesc->Buffer.FirstElement = 0;
|
||||
pDesc->Buffer.NumElements = bufferDesc.ByteWidth / bufferDesc.StructureByteStride;
|
||||
return S_OK;
|
||||
}
|
||||
} return E_INVALIDARG;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MostDetailedMip = 0;
|
||||
pDesc->Texture1D.MipLevels = resourceDesc.MipLevels;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MostDetailedMip = 0;
|
||||
pDesc->Texture1DArray.MipLevels = resourceDesc.MipLevels;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.SampleDesc.Count == 1) {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MostDetailedMip = 0;
|
||||
pDesc->Texture2D.MipLevels = resourceDesc.MipLevels;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MostDetailedMip = 0;
|
||||
pDesc->Texture2DArray.MipLevels = resourceDesc.MipLevels;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} else {
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY;
|
||||
pDesc->Texture2DMSArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DMSArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
pDesc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
|
||||
pDesc->Texture3D.MostDetailedMip = 0;
|
||||
pDesc->Texture3D.MipLevels = resourceDesc.MipLevels;
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for shader resource view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11ShaderResourceView::NormalizeDesc(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
|
||||
uint32_t mipLevels = 0;
|
||||
uint32_t numLayers = 0;
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER: {
|
||||
if (pDesc->ViewDimension != D3D11_SRV_DIMENSION_BUFFER
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX) {
|
||||
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_SRV_DIMENSION_TEXTURE1D
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE1DARRAY) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture1D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
mipLevels = resourceDesc.MipLevels;
|
||||
numLayers = resourceDesc.ArraySize;
|
||||
} break;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
if (pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2D
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DARRAY
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURECUBE
|
||||
&& pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURECUBEARRAY) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture2D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
mipLevels = resourceDesc.MipLevels;
|
||||
numLayers = resourceDesc.ArraySize;
|
||||
} break;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
if (pDesc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE3D) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture3D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
mipLevels = resourceDesc.MipLevels;
|
||||
numLayers = 1;
|
||||
} break;
|
||||
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (pDesc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
pDesc->Format = format;
|
||||
|
||||
switch (pDesc->ViewDimension) {
|
||||
case D3D11_SRV_DIMENSION_TEXTURE1D:
|
||||
if (pDesc->Texture1D.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture1D.MipLevels = mipLevels - pDesc->Texture1D.MostDetailedMip;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
|
||||
if (pDesc->Texture1DArray.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture1DArray.MipLevels = mipLevels - pDesc->Texture1DArray.MostDetailedMip;
|
||||
if (pDesc->Texture1DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture1DArray.ArraySize = numLayers - pDesc->Texture1DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE2D:
|
||||
if (pDesc->Texture2D.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture2D.MipLevels = mipLevels - pDesc->Texture2D.MostDetailedMip;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
|
||||
if (pDesc->Texture2DArray.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture2DArray.MipLevels = mipLevels - pDesc->Texture2DArray.MostDetailedMip;
|
||||
if (pDesc->Texture2DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture2DArray.ArraySize = numLayers - pDesc->Texture2DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
|
||||
if (pDesc->Texture2DMSArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture2DMSArray.ArraySize = numLayers - pDesc->Texture2DMSArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURECUBE:
|
||||
if (pDesc->TextureCube.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->TextureCube.MipLevels = mipLevels - pDesc->TextureCube.MostDetailedMip;
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY:
|
||||
if (pDesc->TextureCubeArray.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->TextureCubeArray.MipLevels = mipLevels - pDesc->TextureCubeArray.MostDetailedMip;
|
||||
if (pDesc->TextureCubeArray.NumCubes == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->TextureCubeArray.NumCubes = (numLayers - pDesc->TextureCubeArray.First2DArrayFace / 6);
|
||||
break;
|
||||
|
||||
case D3D11_SRV_DIMENSION_TEXTURE3D:
|
||||
if (pDesc->Texture3D.MipLevels == D3D11_DXVK_USE_REMAINING_LEVELS)
|
||||
pDesc->Texture3D.MipLevels = mipLevels - pDesc->Texture3D.MostDetailedMip;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,6 +51,14 @@ namespace dxvk {
|
||||
return m_imageView;
|
||||
}
|
||||
|
||||
static HRESULT GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc);
|
||||
|
||||
static HRESULT NormalizeDesc(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc);
|
||||
|
||||
private:
|
||||
|
||||
Com<D3D11Device> m_device;
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "d3d11_device.h"
|
||||
#include "d3d11_buffer.h"
|
||||
#include "d3d11_texture.h"
|
||||
#include "d3d11_view_uav.h"
|
||||
|
||||
namespace dxvk {
|
||||
@ -57,4 +59,165 @@ namespace dxvk {
|
||||
*pDesc = m_desc;
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11UnorderedAccessView::GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc) {
|
||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||
pResource->GetType(&resourceDim);
|
||||
|
||||
switch (resourceDim) {
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER: {
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
static_cast<D3D11Buffer*>(pResource)->GetDesc(&bufferDesc);
|
||||
|
||||
if (bufferDesc.MiscFlags == D3D11_RESOURCE_MISC_BUFFER_STRUCTURED) {
|
||||
pDesc->Format = DXGI_FORMAT_UNKNOWN;
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
|
||||
pDesc->Buffer.FirstElement = 0;
|
||||
pDesc->Buffer.NumElements = bufferDesc.ByteWidth / bufferDesc.StructureByteStride;
|
||||
return S_OK;
|
||||
}
|
||||
} return E_INVALIDARG;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D: {
|
||||
D3D11_TEXTURE1D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture1D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1D;
|
||||
pDesc->Texture1D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1DARRAY;
|
||||
pDesc->Texture1DArray.MipSlice = 0;
|
||||
pDesc->Texture1DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture1DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
|
||||
D3D11_TEXTURE2D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture2D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
|
||||
if (resourceDesc.ArraySize == 1) {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
|
||||
pDesc->Texture2D.MipSlice = 0;
|
||||
} else {
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
|
||||
pDesc->Texture2DArray.MipSlice = 0;
|
||||
pDesc->Texture2DArray.FirstArraySlice = 0;
|
||||
pDesc->Texture2DArray.ArraySize = resourceDesc.ArraySize;
|
||||
}
|
||||
} return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D: {
|
||||
D3D11_TEXTURE3D_DESC resourceDesc;
|
||||
static_cast<D3D11Texture3D*>(pResource)->GetDesc(&resourceDesc);
|
||||
|
||||
pDesc->Format = resourceDesc.Format;
|
||||
pDesc->ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
|
||||
pDesc->Texture3D.MipSlice = 0;
|
||||
} return S_OK;
|
||||
|
||||
default:
|
||||
Logger::err(str::format(
|
||||
"D3D11: Unsupported dimension for unordered access view: ",
|
||||
resourceDim));
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT D3D11UnorderedAccessView::NormalizeDesc(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_UNORDERED_ACCESS_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_UAV_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_UAV_DIMENSION_TEXTURE1D
|
||||
&& pDesc->ViewDimension != D3D11_UAV_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_UAV_DIMENSION_TEXTURE2D
|
||||
&& pDesc->ViewDimension != D3D11_UAV_DIMENSION_TEXTURE2DARRAY) {
|
||||
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_UAV_DIMENSION_TEXTURE3D) {
|
||||
Logger::err("D3D11: Incompatible view dimension for Texture3D");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
format = resourceDesc.Format;
|
||||
numLayers = resourceDesc.Depth >> pDesc->Texture3D.MipSlice;
|
||||
} break;
|
||||
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (pDesc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
pDesc->Format = format;
|
||||
|
||||
switch (pDesc->ViewDimension) {
|
||||
case D3D11_UAV_DIMENSION_TEXTURE1DARRAY:
|
||||
if (pDesc->Texture1DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture1DArray.ArraySize = numLayers - pDesc->Texture1DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_UAV_DIMENSION_TEXTURE2DARRAY:
|
||||
if (pDesc->Texture2DArray.ArraySize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture2DArray.ArraySize = numLayers - pDesc->Texture2DArray.FirstArraySlice;
|
||||
break;
|
||||
|
||||
case D3D11_UAV_DIMENSION_TEXTURE3D:
|
||||
if (pDesc->Texture3D.WSize == D3D11_DXVK_USE_REMAINING_LAYERS)
|
||||
pDesc->Texture3D.WSize = numLayers - pDesc->Texture3D.FirstWSlice;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,6 +66,14 @@ namespace dxvk {
|
||||
return m_counterSlice;
|
||||
}
|
||||
|
||||
static HRESULT GetDescFromResource(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc);
|
||||
|
||||
static HRESULT NormalizeDesc(
|
||||
ID3D11Resource* pResource,
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC* pDesc);
|
||||
|
||||
private:
|
||||
|
||||
Com<D3D11Device> m_device;
|
||||
|
Loading…
Reference in New Issue
Block a user