mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[dxvk] Add some component mapping helpers
This commit is contained in:
parent
0d7f658f96
commit
d998aaad12
@ -140,6 +140,59 @@ namespace dxvk::util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static VkComponentMapping normalizeComponentMapping(
|
||||||
|
VkComponentMapping mapping) {
|
||||||
|
mapping.r = mapping.r == VK_COMPONENT_SWIZZLE_IDENTITY ? VK_COMPONENT_SWIZZLE_R : mapping.r;
|
||||||
|
mapping.g = mapping.g == VK_COMPONENT_SWIZZLE_IDENTITY ? VK_COMPONENT_SWIZZLE_G : mapping.g;
|
||||||
|
mapping.b = mapping.b == VK_COMPONENT_SWIZZLE_IDENTITY ? VK_COMPONENT_SWIZZLE_B : mapping.b;
|
||||||
|
mapping.a = mapping.a == VK_COMPONENT_SWIZZLE_IDENTITY ? VK_COMPONENT_SWIZZLE_A : mapping.a;
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static VkComponentSwizzle resolveComponentSwizzle(
|
||||||
|
VkComponentSwizzle swizzle,
|
||||||
|
VkComponentMapping dstMapping,
|
||||||
|
VkComponentMapping srcMapping) {
|
||||||
|
VkComponentSwizzle dstSwizzle = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
if (dstMapping.r == swizzle) dstSwizzle = VK_COMPONENT_SWIZZLE_R;
|
||||||
|
if (dstMapping.g == swizzle) dstSwizzle = VK_COMPONENT_SWIZZLE_G;
|
||||||
|
if (dstMapping.b == swizzle) dstSwizzle = VK_COMPONENT_SWIZZLE_B;
|
||||||
|
if (dstMapping.a == swizzle) dstSwizzle = VK_COMPONENT_SWIZZLE_A;
|
||||||
|
|
||||||
|
switch (dstSwizzle) {
|
||||||
|
case VK_COMPONENT_SWIZZLE_R: return srcMapping.r;
|
||||||
|
case VK_COMPONENT_SWIZZLE_G: return srcMapping.g;
|
||||||
|
case VK_COMPONENT_SWIZZLE_B: return srcMapping.b;
|
||||||
|
case VK_COMPONENT_SWIZZLE_A: return srcMapping.a;
|
||||||
|
default: return VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
VkComponentMapping resolveSrcComponentMapping(
|
||||||
|
VkComponentMapping dstMapping,
|
||||||
|
VkComponentMapping srcMapping) {
|
||||||
|
dstMapping = normalizeComponentMapping(dstMapping);
|
||||||
|
|
||||||
|
VkComponentMapping result;
|
||||||
|
result.r = resolveComponentSwizzle(VK_COMPONENT_SWIZZLE_R, dstMapping, srcMapping);
|
||||||
|
result.g = resolveComponentSwizzle(VK_COMPONENT_SWIZZLE_G, dstMapping, srcMapping);
|
||||||
|
result.b = resolveComponentSwizzle(VK_COMPONENT_SWIZZLE_B, dstMapping, srcMapping);
|
||||||
|
result.a = resolveComponentSwizzle(VK_COMPONENT_SWIZZLE_A, dstMapping, srcMapping);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isIdentityMapping(
|
||||||
|
VkComponentMapping mapping) {
|
||||||
|
return (mapping.r == VK_COMPONENT_SWIZZLE_R || mapping.r == VK_COMPONENT_SWIZZLE_IDENTITY)
|
||||||
|
&& (mapping.g == VK_COMPONENT_SWIZZLE_G || mapping.g == VK_COMPONENT_SWIZZLE_IDENTITY)
|
||||||
|
&& (mapping.b == VK_COMPONENT_SWIZZLE_B || mapping.b == VK_COMPONENT_SWIZZLE_IDENTITY)
|
||||||
|
&& (mapping.a == VK_COMPONENT_SWIZZLE_A || mapping.a == VK_COMPONENT_SWIZZLE_IDENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t getComponentIndex(
|
uint32_t getComponentIndex(
|
||||||
VkComponentSwizzle component,
|
VkComponentSwizzle component,
|
||||||
uint32_t identity) {
|
uint32_t identity) {
|
||||||
|
@ -225,7 +225,23 @@ namespace dxvk::util {
|
|||||||
*/
|
*/
|
||||||
VkComponentMapping invertComponentMapping(
|
VkComponentMapping invertComponentMapping(
|
||||||
VkComponentMapping mapping);
|
VkComponentMapping mapping);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Resolves source component mapping
|
||||||
|
*
|
||||||
|
* Returns the source component mapping after rearranging
|
||||||
|
* the destination mapping to be the identity mapping.
|
||||||
|
* \param [in] dstMapping Destination mapping
|
||||||
|
* \param [in] srcMapping Source mapping
|
||||||
|
* \returns Adjusted src component mapping
|
||||||
|
*/
|
||||||
|
VkComponentMapping resolveSrcComponentMapping(
|
||||||
|
VkComponentMapping dstMapping,
|
||||||
|
VkComponentMapping srcMapping);
|
||||||
|
|
||||||
|
bool isIdentityMapping(
|
||||||
|
VkComponentMapping mapping);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Computes component index for a component swizzle
|
* \brief Computes component index for a component swizzle
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user