Skip to content

Commit

Permalink
[d3d11] Relaxed view format compatibility check
Browse files Browse the repository at this point in the history
Fixes regressions in multiple games. MSDN docs regarding
format compatibility are wrong in every way.
  • Loading branch information
doitsujin committed May 5, 2018
1 parent f4a92a6 commit fb3dbd8
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 264 deletions.
6 changes: 0 additions & 6 deletions src/d3d11/d3d11_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,12 +1695,6 @@ namespace dxvk {
}


DXGI_VK_FORMAT_MAPPING D3D11Device::GetFormatMapping(
DXGI_FORMAT Format) const {
return m_dxgiAdapter->GetFormatMapping(Format);
}


DXGI_VK_FORMAT_INFO D3D11Device::LookupFormat(
DXGI_FORMAT Format,
DXGI_VK_FORMAT_MODE Mode) const {
Expand Down
3 changes: 0 additions & 3 deletions src/d3d11/d3d11_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,6 @@ namespace dxvk {

VkPipelineStageFlags GetEnabledShaderStages() const;

DXGI_VK_FORMAT_MAPPING GetFormatMapping(
DXGI_FORMAT Format) const;

DXGI_VK_FORMAT_INFO LookupFormat(
DXGI_FORMAT Format,
DXGI_VK_FORMAT_MODE Mode) const;
Expand Down
41 changes: 24 additions & 17 deletions src/d3d11/d3d11_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ namespace dxvk {
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL;

// Typeless formats require MUTABLE_FORMAT_BIT to be set, but we
// only need to do that for color images since depth-stencil formats
// are not compatible to any other depth-stencil formats
DecodeSampleCount(m_desc.SampleDesc.Count, &imageInfo.sampleCount);

// Color formats require MUTABLE_FORMAT_BIT to be set since
// they can be reinterpreted, especially typeless formats.
// Depth-stencil formats are not compatible to each other.
VkImageAspectFlags formatAspect = imageFormatInfo(formatInfo.Format)->aspectMask;

if (formatInfo.Aspect == 0 && formatAspect == VK_IMAGE_ASPECT_COLOR_BIT)
if (formatAspect & VK_IMAGE_ASPECT_COLOR_BIT)
imageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;

DecodeSampleCount(m_desc.SampleDesc.Count, &imageInfo.sampleCount);

// Adjust image flags based on the corresponding D3D flags
if (m_desc.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
imageInfo.usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
Expand Down Expand Up @@ -167,21 +167,28 @@ namespace dxvk {


bool D3D11CommonTexture::CheckViewFormatCompatibility(DXGI_FORMAT Format) const {
DXGI_VK_FORMAT_MAPPING baseFormat = m_device->GetFormatMapping(m_desc.Format);
DXGI_VK_FORMAT_MAPPING viewFormat = m_device->GetFormatMapping(Format);
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);

// The view format cannot be typeless
if (Format == viewFormat.FormatFamily)
if (baseFormatInfo->aspectMask != viewFormatInfo->aspectMask)
return false;

// If the resource is strongly typed, the view
// format must be identical to the base format.
if (m_desc.Format != baseFormat.FormatFamily)
return Format == m_desc.Format;
// 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;

// If the resource is typeless, the view format
// must be part of the same format family.
return viewFormat.FormatFamily == baseFormat.FormatFamily;
return false;
}


Expand Down
6 changes: 0 additions & 6 deletions src/dxgi/dxgi_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ namespace dxvk {
}


DXGI_VK_FORMAT_MAPPING STDMETHODCALLTYPE DxgiAdapter::GetFormatMapping(
DXGI_FORMAT Format) {
return *GetDXGIFormatMapping(Format);
}


DXGI_VK_FORMAT_INFO STDMETHODCALLTYPE DxgiAdapter::LookupFormat(
DXGI_FORMAT Format,
DXGI_VK_FORMAT_MODE Mode) {
Expand Down
3 changes: 0 additions & 3 deletions src/dxgi/dxgi_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ namespace dxvk {
const VkPhysicalDeviceFeatures* pFeatures,
IDXGIVkDevice** ppDevice) final;

DXGI_VK_FORMAT_MAPPING STDMETHODCALLTYPE GetFormatMapping(
DXGI_FORMAT Format) final;

DXGI_VK_FORMAT_INFO STDMETHODCALLTYPE LookupFormat(
DXGI_FORMAT Format,
DXGI_VK_FORMAT_MODE Mode) final;
Expand Down
Loading

0 comments on commit fb3dbd8

Please sign in to comment.