MCPcopy Create free account
hub / github.com/GPUOpen-Tools/compressonator / GetBC7Ramp

Function GetBC7Ramp

cmp_core/shaders/bc7_encode_kernel.cpp:2974–3056  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2972#endif
2973
2974void GetBC7Ramp(CGU_UINT32 endpoint[][MAX_DIMENSION_BIG],
2975 CGU_FLOAT ramp[MAX_DIMENSION_BIG][(1 << MAX_INDEX_BITS)],
2976 CGU_UINT32 clusters[2],
2977 CGU_UINT32 componentBits[MAX_DIMENSION_BIG])
2978{
2979 CGU_UINT32 ep[2][MAX_DIMENSION_BIG];
2980 CGU_UINT32 i;
2981
2982 // Expand each endpoint component to 8 bits by shifting the MSB to bit 7
2983 // and then replicating the high bits to the low bits revealed by
2984 // the shift
2985 for (i = 0; i < MAX_DIMENSION_BIG; i++)
2986 {
2987 ep[0][i] = 0;
2988 ep[1][i] = 0;
2989 if (componentBits[i])
2990 {
2991 ep[0][i] = (CGU_UINT32)(endpoint[0][i] << (8 - componentBits[i]));
2992 ep[1][i] = (CGU_UINT32)(endpoint[1][i] << (8 - componentBits[i]));
2993 ep[0][i] += (CGU_UINT32)(ep[0][i] >> componentBits[i]);
2994 ep[1][i] += (CGU_UINT32)(ep[1][i] >> componentBits[i]);
2995
2996 ep[0][i] = min8(255, max8(0, CMP_STATIC_CAST(CGU_UINT8, ep[0][i])));
2997 ep[1][i] = min8(255, max8(0, CMP_STATIC_CAST(CGU_UINT8, ep[1][i])));
2998 }
2999 }
3000
3001 // If this block type has no explicit alpha channel
3002 // then make sure alpha is 1.0 for all points on the ramp
3003 if (!componentBits[COMP_ALPHA])
3004 {
3005 ep[0][COMP_ALPHA] = ep[1][COMP_ALPHA] = 255;
3006 }
3007
3008 CGU_UINT32 rampIndex = clusters[0];
3009
3010 rampIndex = (CGU_UINT32)(log((double)rampIndex) / log(2.0));
3011
3012 // Generate colours for the RGB ramp
3013 for (i = 0; i < clusters[0]; i++)
3014 {
3015#ifdef USE_HIGH_PRECISION_INTERPOLATION_BC7
3016 ramp[COMP_RED][i] =
3017 (CGU_FLOAT)cmp_floor((ep[0][COMP_RED] * (1.0 - rampLerpWeightsBC7[rampIndex][i])) + (ep[1][COMP_RED] * rampLerpWeightsBC7[rampIndex][i]) + 0.5);
3018 ramp[COMP_RED][i] = bc7_minf(255.0, bc7_maxf(0., ramp[COMP_RED][i]));
3019 ramp[COMP_GREEN][i] =
3020 (CGU_FLOAT)cmp_floor((ep[0][COMP_GREEN] * (1.0 - rampLerpWeightsBC7[rampIndex][i])) + (ep[1][COMP_GREEN] * rampLerpWeightsBC7[rampIndex][i]) + 0.5);
3021 ramp[COMP_GREEN][i] = bc7_minf(255.0, bc7_maxf(0., ramp[COMP_GREEN][i]));
3022 ramp[COMP_BLUE][i] =
3023 (CGU_FLOAT)cmp_floor((ep[0][COMP_BLUE] * (1.0 - rampLerpWeightsBC7[rampIndex][i])) + (ep[1][COMP_BLUE] * rampLerpWeightsBC7[rampIndex][i]) + 0.5);
3024 ramp[COMP_BLUE][i] = bc7_minf(255.0, bc7_maxf(0., ramp[COMP_BLUE][i]));
3025#else
3026 ramp[COMP_RED][i] = interpolate(ep[0][COMP_RED], ep[1][COMP_RED], i, rampIndex);
3027 ramp[COMP_GREEN][i] = interpolate(ep[0][COMP_GREEN], ep[1][COMP_GREEN], i, rampIndex);
3028 ramp[COMP_BLUE][i] = interpolate(ep[0][COMP_BLUE], ep[1][COMP_BLUE], i, rampIndex);
3029#endif
3030 }
3031

Callers 2

DecompressDualIndexBlockFunction · 0.85
DecompressBC7_internalFunction · 0.85

Calls 6

min8Function · 0.85
max8Function · 0.85
cmp_floorFunction · 0.85
bc7_minfFunction · 0.85
bc7_maxfFunction · 0.85
interpolateFunction · 0.70

Tested by

no test coverage detected