Skip to content

Commit

Permalink
MVKPixelFormats: Handle the B4G4R4A4 format.
Browse files Browse the repository at this point in the history
Handle it similarly to the `A4R4B4G4` and `A4B4G4R4` formats, with a
swizzle. Vulkan requires support for this format.

Fixes the following tests:
* `dEQP-VK.api.info.format_properties.b4g4r4a4_unorm_pack16`.
* `dEQP-VK.texture.explicit_lod.2d.formats.b4g4r4a4*`
  • Loading branch information
cdavis5e committed Nov 22, 2023
1 parent a7dc8da commit 552e5c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,14 @@ static void signalAndUnmarkAsTracked(const MVKSwapchainSignaler& signaler) {
adjustAnyComponentSwizzleValue(a, R, A, B, G, R);
break;

case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
// Metal doesn't support this directly, so use a swizzle to get the ordering right.
adjustAnyComponentSwizzleValue(r, B, B, G, R, A);
adjustAnyComponentSwizzleValue(g, G, B, G, R, A);
adjustAnyComponentSwizzleValue(b, R, B, G, R, A);
adjustAnyComponentSwizzleValue(a, A, B, G, R, A);
break;

default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
#define OFFSET_SNORM(COLOR, BIT_WIDTH) OFFSET_NORM(-1.0, COLOR, BIT_WIDTH - 1)
switch (vkFormat) {
case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
case VK_FORMAT_A4B4G4R4_UNORM_PACK16:
OFFSET_UNORM(red, 4)
Expand Down Expand Up @@ -831,7 +832,7 @@

addVkFormatDesc( R4G4_UNORM_PACK8, Invalid, Invalid, Invalid, Invalid, 1, 1, 1, ColorFloat );
addVkFormatDesc( R4G4B4A4_UNORM_PACK16, ABGR4Unorm, Invalid, Invalid, Invalid, 1, 1, 2, ColorFloat );
addVkFormatDesc( B4G4R4A4_UNORM_PACK16, Invalid, Invalid, Invalid, Invalid, 1, 1, 2, ColorFloat );
addVkFormatDescSwizzled( B4G4R4A4_UNORM_PACK16, ABGR4Unorm, Invalid, Invalid, Invalid, 1, 1, 2, ColorFloat, B, G, R, A );
addVkFormatDescSwizzled( A4R4G4B4_UNORM_PACK16, ABGR4Unorm, Invalid, Invalid, Invalid, 1, 1, 2, ColorFloat, G, B, A, R );
addVkFormatDescSwizzled( A4B4G4R4_UNORM_PACK16, ABGR4Unorm, Invalid, Invalid, Invalid, 1, 1, 2, ColorFloat, A, B, G, R );

Expand Down

0 comments on commit 552e5c0

Please sign in to comment.