1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-31 05:52:11 +01:00

[dxvk] Initial support for format info

This commit is contained in:
Philip Rebohle 2017-12-09 02:44:59 +01:00
parent 36e6ba4ebc
commit a43bb134e0
6 changed files with 487 additions and 7 deletions

View File

@ -333,7 +333,7 @@ namespace dxvk {
// Fill in Vulkan image view info
DxvkImageViewCreateInfo viewInfo;
viewInfo.format = m_dxgiAdapter->LookupFormat(desc.Format).actual;
viewInfo.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
viewInfo.aspect = imageFormatInfo(viewInfo.format)->aspectMask;
switch (desc.ViewDimension) {
case D3D11_RTV_DIMENSION_TEXTURE2D:
@ -465,11 +465,9 @@ namespace dxvk {
}
// Fill in Vulkan image view info
// TODO Implement some sort of format reflection
DxvkImageViewCreateInfo viewInfo;
viewInfo.format = m_dxgiAdapter->LookupFormat(desc.Format).actual;
viewInfo.aspect = VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT;
viewInfo.aspect = imageFormatInfo(viewInfo.format)->aspectMask;
switch (desc.ViewDimension) {
case D3D11_DSV_DIMENSION_TEXTURE2D:
@ -1038,10 +1036,8 @@ namespace dxvk {
const Rc<DxvkImage> image = pImage->GetDXVKImage();
// TODO implement some sort of format info
VkImageSubresourceRange subresources;
subresources.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT;
subresources.aspectMask = imageFormatInfo(image->info().format)->aspectMask;
subresources.baseMipLevel = 0;
subresources.levelCount = image->info().mipLevels;
subresources.baseArrayLayer = 0;

View File

@ -1,5 +1,6 @@
#pragma once
#include "dxvk_format.h"
#include "dxvk_memory.h"
#include "dxvk_resource.h"

457
src/dxvk/dxvk_format.cpp Normal file
View File

@ -0,0 +1,457 @@
#include "dxvk_format.h"
namespace dxvk {
const std::array<DxvkFormatInfo, 147> g_formatInfos = {{
// VK_FORMAT_UNDEFINED
{ 0, 0 },
// VK_FORMAT_R4G4_UNORM_PACK8
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R4G4B4A4_UNORM_PACK16
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B4G4R4A4_UNORM_PACK16
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R5G6B5_UNORM_PACK16
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B5G6R5_UNORM_PACK16
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R5G5B5A1_UNORM_PACK16
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B5G5R5A1_UNORM_PACK16
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A1R5G5B5_UNORM_PACK16
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8_UNORM
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8_SNORM
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8_USCALED
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8_SSCALED
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8_UINT
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8_SINT
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8_SRGB
{ 1, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8_UNORM
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8_SNORM
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8_USCALED
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8_SSCALED
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8_UINT
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8_SINT
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8_SRGB
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8_UNORM
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8_SNORM
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8_USCALED
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8_SSCALED
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8_UINT
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8_SINT
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8_SRGB
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8_UNORM
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8_SNORM
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8_USCALED
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8_SSCALED
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8_UINT
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8_SINT
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8_SRGB
{ 3, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8A8_UNORM
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8A8_SNORM
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8A8_USCALED
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8A8_SSCALED
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8A8_UINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8A8_SINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R8G8B8A8_SRGB
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8A8_UNORM
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8A8_SNORM
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8A8_USCALED
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8A8_SSCALED
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8A8_UINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8A8_SINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B8G8R8A8_SRGB
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A8B8G8R8_UNORM_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A8B8G8R8_SNORM_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A8B8G8R8_USCALED_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A8B8G8R8_SSCALED_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A8B8G8R8_UINT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A8B8G8R8_SINT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A8B8G8R8_SRGB_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2R10G10B10_UNORM_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2R10G10B10_SNORM_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2R10G10B10_USCALED_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2R10G10B10_SSCALED_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2R10G10B10_UINT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2R10G10B10_SINT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2B10G10R10_UNORM_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2B10G10R10_SNORM_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2B10G10R10_USCALED_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2B10G10R10_SSCALED_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2B10G10R10_UINT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_A2B10G10R10_SINT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16_UNORM
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16_SNORM
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16_USCALED
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16_SSCALED
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16_UINT
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16_SINT
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16_SFLOAT
{ 2, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16_UNORM
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16_SNORM
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16_USCALED
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16_SSCALED
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16_UINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16_SINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16_SFLOAT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16_UNORM
{ 6, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16_SNORM
{ 6, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16_USCALED
{ 6, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16_SSCALED
{ 6, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16_UINT
{ 6, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16_SINT
{ 6, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16_SFLOAT
{ 6, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16A16_UNORM
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16A16_SNORM
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16A16_USCALED
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16A16_SSCALED
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16A16_UINT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16A16_SINT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R16G16B16A16_SFLOAT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32_UINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32_SINT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32_SFLOAT
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32_UINT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32_SINT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32_SFLOAT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32B32_UINT
{ 12, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32B32_SINT
{ 12, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32B32_SFLOAT
{ 12, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32B32A32_UINT
{ 16, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32B32A32_SINT
{ 16, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R32G32B32A32_SFLOAT
{ 16, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64_UINT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64_SINT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64_SFLOAT
{ 8, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64_UINT
{ 16, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64_SINT
{ 16, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64_SFLOAT
{ 16, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64B64_UINT
{ 24, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64B64_SINT
{ 24, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64B64_SFLOAT
{ 24, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64B64A64_UINT
{ 32, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64B64A64_SINT
{ 32, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_R64G64B64A64_SFLOAT
{ 32, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_B10G11R11_UFLOAT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
{ 4, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_D16_UNORM
{ 0, VK_IMAGE_ASPECT_DEPTH_BIT },
// VK_FORMAT_X8_D24_UNORM_PACK32
{ 0, VK_IMAGE_ASPECT_DEPTH_BIT },
// VK_FORMAT_D32_SFLOAT
{ 0, VK_IMAGE_ASPECT_DEPTH_BIT },
// VK_FORMAT_S8_UINT
{ 0, VK_IMAGE_ASPECT_STENCIL_BIT },
// VK_FORMAT_D16_UNORM_S8_UINT
{ 0, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT },
// VK_FORMAT_D24_UNORM_S8_UINT
{ 0, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT },
// VK_FORMAT_D32_SFLOAT_S8_UINT
{ 0, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT },
// VK_FORMAT_BC1_RGB_UNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC1_RGB_SRGB_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC1_RGBA_UNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC1_RGBA_SRGB_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC2_UNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC2_SRGB_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC3_UNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC3_SRGB_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC4_UNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC4_SNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC5_UNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC5_SNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC6H_UFLOAT_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC6H_SFLOAT_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC7_UNORM_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
// VK_FORMAT_BC7_SRGB_BLOCK
{ 0, VK_IMAGE_ASPECT_COLOR_BIT },
}};
const DxvkFormatInfo* imageFormatInfo(VkFormat format) {
const uint32_t formatId = static_cast<uint32_t>(format);
if (formatId < g_formatInfos.size())
return &g_formatInfos.at(formatId);
return nullptr;
}
}

24
src/dxvk/dxvk_format.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include "dxvk_include.h"
namespace dxvk {
/**
* \brief Format info structure
*
* Provides some useful information
* about a Vulkan image format.
*/
struct DxvkFormatInfo {
/// Size of an element in this format
uint32_t byteSize;
/// Available image aspect flags
VkImageAspectFlags aspectMask;
};
const DxvkFormatInfo* imageFormatInfo(VkFormat format);
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "dxvk_format.h"
#include "dxvk_memory.h"
#include "dxvk_resource.h"

View File

@ -8,6 +8,7 @@ dxvk_src = files([
'dxvk_data.cpp',
'dxvk_descriptor.cpp',
'dxvk_device.cpp',
'dxvk_format.cpp',
'dxvk_framebuffer.cpp',
'dxvk_graphics.cpp',
'dxvk_image.cpp',