From f49c0ab19037ea2c3883a4531563f3808bc3b1df Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 13 Sep 2022 20:51:41 +0000 Subject: [PATCH] Texture format rework (#21) - Adds number format information to the texture format names - Adds several unsigned integer texture formats Reviewed-on: https://gitea.moonside.games/MoonsideGames/Refresh/pulls/21 --- include/Refresh.h | 30 ++++++++----- src/Refresh_Driver.h | 8 +++- src/Refresh_Driver_Vulkan.c | 85 +++++++++++++++++++++++-------------- 3 files changed, 79 insertions(+), 44 deletions(-) diff --git a/include/Refresh.h b/include/Refresh.h index 827328f..c0618d7 100644 --- a/include/Refresh.h +++ b/include/Refresh.h @@ -115,28 +115,38 @@ typedef enum Refresh_IndexElementSize typedef enum Refresh_TextureFormat { - /* Color Formats */ + /* Unsigned Normalized Float Color Formats */ REFRESH_TEXTUREFORMAT_R8G8B8A8, REFRESH_TEXTUREFORMAT_B8G8R8A8, REFRESH_TEXTUREFORMAT_R5G6B5, REFRESH_TEXTUREFORMAT_A1R5G5B5, REFRESH_TEXTUREFORMAT_B4G4R4A4, - REFRESH_TEXTUREFORMAT_BC1, - REFRESH_TEXTUREFORMAT_BC2, - REFRESH_TEXTUREFORMAT_BC3, - REFRESH_TEXTUREFORMAT_BC7, - REFRESH_TEXTUREFORMAT_R8G8_SNORM, - REFRESH_TEXTUREFORMAT_R8G8B8A8_SNORM, REFRESH_TEXTUREFORMAT_A2R10G10B10, REFRESH_TEXTUREFORMAT_R16G16, REFRESH_TEXTUREFORMAT_R16G16B16A16, REFRESH_TEXTUREFORMAT_R8, - REFRESH_TEXTUREFORMAT_R32_SFLOAT, - REFRESH_TEXTUREFORMAT_R32G32_SFLOAT, - REFRESH_TEXTUREFORMAT_R32G32B32A32_SFLOAT, + /* Compressed Unsigned Normalized Float Color Formats */ + REFRESH_TEXTUREFORMAT_BC1, + REFRESH_TEXTUREFORMAT_BC2, + REFRESH_TEXTUREFORMAT_BC3, + REFRESH_TEXTUREFORMAT_BC7, + /* Signed Normalized Float Color Formats */ + REFRESH_TEXTUREFORMAT_R8G8_SNORM, + REFRESH_TEXTUREFORMAT_R8G8B8A8_SNORM, + /* Signed Float Color Formats */ REFRESH_TEXTUREFORMAT_R16_SFLOAT, REFRESH_TEXTUREFORMAT_R16G16_SFLOAT, REFRESH_TEXTUREFORMAT_R16G16B16A16_SFLOAT, + REFRESH_TEXTUREFORMAT_R32_SFLOAT, + REFRESH_TEXTUREFORMAT_R32G32_SFLOAT, + REFRESH_TEXTUREFORMAT_R32G32B32A32_SFLOAT, + /* Unsigned Integer Color Formats */ + REFRESH_TEXTUREFORMAT_R8_UINT, + REFRESH_TEXTUREFORMAT_R8G8_UINT, + REFRESH_TEXTUREFORMAT_R8G8B8A8_UINT, + REFRESH_TEXTUREFORMAT_R16_UINT, + REFRESH_TEXTUREFORMAT_R16G16_UINT, + REFRESH_TEXTUREFORMAT_R16G16B16A16_UINT, /* Depth Formats */ REFRESH_TEXTUREFORMAT_D16_UNORM, REFRESH_TEXTUREFORMAT_D32_SFLOAT, diff --git a/src/Refresh_Driver.h b/src/Refresh_Driver.h index aca69a8..7b5a1c6 100644 --- a/src/Refresh_Driver.h +++ b/src/Refresh_Driver.h @@ -60,22 +60,28 @@ static inline uint32_t Texture_GetFormatSize( case REFRESH_TEXTUREFORMAT_BC7: return 16; case REFRESH_TEXTUREFORMAT_R8: + case REFRESH_TEXTUREFORMAT_R8_UINT: return 1; case REFRESH_TEXTUREFORMAT_R5G6B5: case REFRESH_TEXTUREFORMAT_B4G4R4A4: case REFRESH_TEXTUREFORMAT_A1R5G5B5: case REFRESH_TEXTUREFORMAT_R16_SFLOAT: case REFRESH_TEXTUREFORMAT_R8G8_SNORM: + case REFRESH_TEXTUREFORMAT_R8G8_UINT: + case REFRESH_TEXTUREFORMAT_R16_UINT: return 2; case REFRESH_TEXTUREFORMAT_R8G8B8A8: case REFRESH_TEXTUREFORMAT_R32_SFLOAT: case REFRESH_TEXTUREFORMAT_R16G16_SFLOAT: case REFRESH_TEXTUREFORMAT_R8G8B8A8_SNORM: case REFRESH_TEXTUREFORMAT_A2R10G10B10: + case REFRESH_TEXTUREFORMAT_R8G8B8A8_UINT: + case REFRESH_TEXTUREFORMAT_R16G16_UINT: return 4; case REFRESH_TEXTUREFORMAT_R16G16B16A16_SFLOAT: case REFRESH_TEXTUREFORMAT_R16G16B16A16: case REFRESH_TEXTUREFORMAT_R32G32_SFLOAT: + case REFRESH_TEXTUREFORMAT_R16G16B16A16_UINT: return 8; case REFRESH_TEXTUREFORMAT_R32G32B32A32_SFLOAT: return 16; @@ -144,7 +150,7 @@ static inline int32_t BytesPerImage( if ( format == REFRESH_TEXTUREFORMAT_BC1 || format == REFRESH_TEXTUREFORMAT_BC2 || format == REFRESH_TEXTUREFORMAT_BC3 || - format == REFRESH_TEXTUREFORMAT_BC7 ) + format == REFRESH_TEXTUREFORMAT_BC7 ) { blocksPerRow = (width + 3) / 4; blocksPerColumn = (height + 3) / 4; diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c index 64b76f8..4ca36c2 100644 --- a/src/Refresh_Driver_Vulkan.c +++ b/src/Refresh_Driver_Vulkan.c @@ -185,47 +185,53 @@ static const uint8_t DEVICE_PRIORITY[] = static VkFormat RefreshToVK_SurfaceFormat[] = { - VK_FORMAT_R8G8B8A8_UNORM, /* R8G8B8A8 */ - VK_FORMAT_B8G8R8A8_UNORM, /* B8G8R8A8 */ - VK_FORMAT_R5G6B5_UNORM_PACK16, /* R5G6B5 */ - VK_FORMAT_A1R5G5B5_UNORM_PACK16, /* A1R5G5B5 */ - VK_FORMAT_B4G4R4A4_UNORM_PACK16, /* B4G4R4A4 */ - VK_FORMAT_BC1_RGBA_UNORM_BLOCK, /* BC1 */ - VK_FORMAT_BC2_UNORM_BLOCK, /* BC3 */ - VK_FORMAT_BC3_UNORM_BLOCK, /* BC5 */ - VK_FORMAT_BC7_UNORM_BLOCK, /* BC7 */ - VK_FORMAT_R8G8_SNORM, /* R8G8_SNORM */ - VK_FORMAT_R8G8B8A8_SNORM, /* R8G8B8A8_SNORM */ - VK_FORMAT_A2R10G10B10_UNORM_PACK32, /* A2R10G10B10 */ - VK_FORMAT_R16G16_UNORM, /* R16G16 */ - VK_FORMAT_R16G16B16A16_UNORM, /* R16G16B16A16 */ - VK_FORMAT_R8_UNORM, /* R8 */ - VK_FORMAT_R32_SFLOAT, /* R32_SFLOAT */ - VK_FORMAT_R32G32_SFLOAT, /* R32G32_SFLOAT */ - VK_FORMAT_R32G32B32A32_SFLOAT, /* R32G32B32A32_SFLOAT */ - VK_FORMAT_R16_SFLOAT, /* R16_SFLOAT */ - VK_FORMAT_R16G16_SFLOAT, /* R16G16_SFLOAT */ + VK_FORMAT_R8G8B8A8_UNORM, /* R8G8B8A8_UNORM */ + VK_FORMAT_B8G8R8A8_UNORM, /* B8G8R8A8_UNORM */ + VK_FORMAT_R5G6B5_UNORM_PACK16, /* R5G6B5_UNORM */ + VK_FORMAT_A1R5G5B5_UNORM_PACK16, /* A1R5G5B5_UNORM */ + VK_FORMAT_B4G4R4A4_UNORM_PACK16, /* B4G4R4A4_UNORM */ + VK_FORMAT_A2R10G10B10_UNORM_PACK32, /* A2R10G10B10_UNORM */ + VK_FORMAT_R16G16_UNORM, /* R16G16_UNORM */ + VK_FORMAT_R16G16B16A16_UNORM, /* R16G16B16A16_UNORM */ + VK_FORMAT_R8_UNORM, /* R8_UNORM */ + VK_FORMAT_BC1_RGBA_UNORM_BLOCK, /* BC1_UNORM */ + VK_FORMAT_BC2_UNORM_BLOCK, /* BC2_UNORM */ + VK_FORMAT_BC3_UNORM_BLOCK, /* BC3_UNORM */ + VK_FORMAT_BC7_UNORM_BLOCK, /* BC7_UNORM */ + VK_FORMAT_R8G8_SNORM, /* R8G8_SNORM */ + VK_FORMAT_R8G8B8A8_SNORM, /* R8G8B8A8_SNORM */ + VK_FORMAT_R16_SFLOAT, /* R16_SFLOAT */ + VK_FORMAT_R16G16_SFLOAT, /* R16G16_SFLOAT */ VK_FORMAT_R16G16B16A16_SFLOAT, /* R16G16B16A16_SFLOAT */ - VK_FORMAT_D16_UNORM, /* D16 */ - VK_FORMAT_D32_SFLOAT, /* D32 */ - VK_FORMAT_D16_UNORM_S8_UINT, /* D16S8 */ - VK_FORMAT_D32_SFLOAT_S8_UINT /* D32S8 */ + VK_FORMAT_R32_SFLOAT, /* R32_SFLOAT */ + VK_FORMAT_R32G32_SFLOAT, /* R32G32_SFLOAT */ + VK_FORMAT_R32G32B32A32_SFLOAT, /* R32G32B32A32_SFLOAT */ + VK_FORMAT_R8_UINT, /* R8_UINT */ + VK_FORMAT_R8G8_UINT, /* R8G8_UINT */ + VK_FORMAT_R8G8B8A8_UINT, /* R8G8B8A8_UINT */ + VK_FORMAT_R16_UINT, /* R16_UINT */ + VK_FORMAT_R16G16_UINT, /* R16G16_UINT */ + VK_FORMAT_R16G16B16A16_UINT, /* R16G16B16A16_UINT */ + VK_FORMAT_D16_UNORM, /* D16_UNORM */ + VK_FORMAT_D32_SFLOAT, /* D32_SFLOAT */ + VK_FORMAT_D16_UNORM_S8_UINT, /* D16_UNORM_S8_UINT */ + VK_FORMAT_D32_SFLOAT_S8_UINT /* D32_SFLOAT_S8_UINT */ }; static VkFormat RefreshToVK_VertexFormat[] = { - VK_FORMAT_R32_UINT, /* UINT */ - VK_FORMAT_R32_SFLOAT, /* FLOAT */ - VK_FORMAT_R32G32_SFLOAT, /* VECTOR2 */ - VK_FORMAT_R32G32B32_SFLOAT, /* VECTOR3 */ + VK_FORMAT_R32_UINT, /* UINT */ + VK_FORMAT_R32_SFLOAT, /* FLOAT */ + VK_FORMAT_R32G32_SFLOAT, /* VECTOR2 */ + VK_FORMAT_R32G32B32_SFLOAT, /* VECTOR3 */ VK_FORMAT_R32G32B32A32_SFLOAT, /* VECTOR4 */ - VK_FORMAT_R8G8B8A8_UNORM, /* COLOR */ - VK_FORMAT_R8G8B8A8_USCALED, /* BYTE4 */ - VK_FORMAT_R16G16_SSCALED, /* SHORT2 */ + VK_FORMAT_R8G8B8A8_UNORM, /* COLOR */ + VK_FORMAT_R8G8B8A8_USCALED, /* BYTE4 */ + VK_FORMAT_R16G16_SSCALED, /* SHORT2 */ VK_FORMAT_R16G16B16A16_SSCALED, /* SHORT4 */ - VK_FORMAT_R16G16_SNORM, /* NORMALIZEDSHORT2 */ + VK_FORMAT_R16G16_SNORM, /* NORMALIZEDSHORT2 */ VK_FORMAT_R16G16B16A16_SNORM, /* NORMALIZEDSHORT4 */ - VK_FORMAT_R16G16_SFLOAT, /* HALFVECTOR2 */ + VK_FORMAT_R16G16_SFLOAT, /* HALFVECTOR2 */ VK_FORMAT_R16G16B16A16_SFLOAT /* HALFVECTOR4 */ }; @@ -1908,6 +1914,7 @@ static inline uint32_t VULKAN_INTERNAL_BytesPerPixel(VkFormat format) case VK_FORMAT_BC2_UNORM_BLOCK: case VK_FORMAT_BC3_UNORM_BLOCK: case VK_FORMAT_BC7_UNORM_BLOCK: + case VK_FORMAT_R16G16B16A16_UINT: return 16; case VK_FORMAT_R8G8B8A8_UNORM: @@ -1917,6 +1924,8 @@ static inline uint32_t VULKAN_INTERNAL_BytesPerPixel(VkFormat format) case VK_FORMAT_R16G16_SFLOAT: case VK_FORMAT_R32_SFLOAT: case VK_FORMAT_D32_SFLOAT: + case VK_FORMAT_R8G8B8A8_UINT: + case VK_FORMAT_R16G16_UINT: return 4; case VK_FORMAT_R5G6B5_UNORM_PACK16: @@ -1925,12 +1934,15 @@ static inline uint32_t VULKAN_INTERNAL_BytesPerPixel(VkFormat format) case VK_FORMAT_R8G8_SNORM: case VK_FORMAT_R16_SFLOAT: case VK_FORMAT_D16_UNORM: + case VK_FORMAT_R8G8_UINT: + case VK_FORMAT_R16_UINT: return 2; case VK_FORMAT_R16G16B16A16_UNORM: case VK_FORMAT_R32G32_SFLOAT: case VK_FORMAT_R16G16B16A16_SFLOAT: case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: + case VK_FORMAT_R8_UINT: return 8; case VK_FORMAT_R8_UNORM: @@ -1975,6 +1987,12 @@ static inline uint32_t VULKAN_INTERNAL_GetTextureBlockSize( case VK_FORMAT_R16_SFLOAT: case VK_FORMAT_R16G16_SFLOAT: case VK_FORMAT_R16G16B16A16_SFLOAT: + case VK_FORMAT_R8_UINT: + case VK_FORMAT_R8G8_UINT: + case VK_FORMAT_R8G8B8A8_UINT: + case VK_FORMAT_R16_UINT: + case VK_FORMAT_R16G16_UINT: + case VK_FORMAT_R16G16B16A16_UINT: return 1; default: Refresh_LogError("Unrecognized texture format!"); @@ -10396,6 +10414,7 @@ static uint8_t VULKAN_INTERNAL_CreateLogicalDevice( SDL_zero(deviceFeatures); deviceFeatures.occlusionQueryPrecise = VK_TRUE; deviceFeatures.fillModeNonSolid = VK_TRUE; + deviceFeatures.depthClamp = VK_TRUE; /* creating the logical device */