[D3D12] DXT1 decompression shader
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "pixel_formats.hlsli"
|
||||
#include "texture_copy.hlsli"
|
||||
|
||||
// http://fileadmin.cs.lth.se/cs/Personal/Michael_Doggett/talks/unc-xenos-doggett.pdf
|
||||
@@ -13,11 +14,11 @@
|
||||
// II JJ KK LL
|
||||
// MM NN OO PP
|
||||
|
||||
void XeCTX1FourBlocksRowToR8G8(uint4 weights_high, uint weights_shift,
|
||||
uint4 end_low_rr00gg00, uint4 end_high_rr00gg00,
|
||||
void XeCTX1FourBlocksRowToR8G8(uint4 end_low_rr00gg00, uint4 end_high_rr00gg00,
|
||||
uint4 weights_high, uint weights_shift,
|
||||
out uint4 row_01, out uint4 row_23) {
|
||||
uint4 weights_low = ~weights_high;
|
||||
uint4 weights_shifts = uint4(0u, 2u, 4u, 6u) + weights_shift;
|
||||
uint4 weights_shifts = weights_shift + uint4(0u, 2u, 4u, 6u);
|
||||
uint4 row_3aaaa =
|
||||
((weights_low >> weights_shifts.x) & 3u) * end_low_rr00gg00 +
|
||||
((weights_high >> weights_shifts.x) & 3u) * end_high_rr00gg00;
|
||||
@@ -63,15 +64,6 @@ void main(uint3 xe_thread_id : SV_DispatchThreadID) {
|
||||
blocks_01 = XeByteSwap(blocks_01, xe_texture_copy_endianness);
|
||||
blocks_23 = XeByteSwap(blocks_23, xe_texture_copy_endianness);
|
||||
|
||||
// Sort the color indices so they can be used as weights for the second
|
||||
// endpoint. Initially 00 = 3:0, 01 = 0:3, 10 = 2:1, 11 = 1:2.
|
||||
uint4 weights_high = uint4(blocks_01.yw, blocks_23.yw);
|
||||
// Swap bits. 00 = 3:0, 01 = 2:1, 10 = 0:3, 11 = 1:2.
|
||||
weights_high = ((weights_high & 0x55555555u) << 1u) |
|
||||
((weights_high & 0xAAAAAAAAu) >> 1u);
|
||||
// Swap 10 and 11. 00 = 3:0, 01 = 2:1, 10 = 1:2, 11 = 0:3.
|
||||
weights_high ^= ((weights_high & 0xAAAAAAAAu) >> 1u);
|
||||
|
||||
// Unpack the endpoints as:
|
||||
// 0x00g000r0 0x00g100r1 0x00g200r2 0x00g300r3
|
||||
// 0x00G000R0 0x00G100R1 0x00G200R2 0x00G300R3
|
||||
@@ -82,6 +74,10 @@ void main(uint3 xe_thread_id : SV_DispatchThreadID) {
|
||||
uint4 end_high_rr00gg00 =
|
||||
((end_packed & 0xFF0000u) >> 16u) | ((end_packed & 0xFF000000u) >> 8u);
|
||||
|
||||
// Sort the color indices so they can be used as weights for the second
|
||||
// endpoint.
|
||||
uint4 weights_high = XeDXTHighColorWeights(uint4(blocks_01.yw, blocks_23.yw));
|
||||
|
||||
// Uncompress and write the rows.
|
||||
uint3 texel_index_host = block_index << uint3(2u, 2u, 0u);
|
||||
uint texel_offset_host = XeTextureHostLinearOffset(
|
||||
@@ -89,8 +85,8 @@ void main(uint3 xe_thread_id : SV_DispatchThreadID) {
|
||||
xe_texture_copy_host_pitch, 2u) + xe_texture_copy_host_base;
|
||||
for (uint i = 0u; i < 4u; ++i) {
|
||||
uint4 row_01, row_23;
|
||||
XeCTX1FourBlocksRowToR8G8(weights_high, i * 8u, end_low_rr00gg00,
|
||||
end_high_rr00gg00, row_01, row_23);
|
||||
XeCTX1FourBlocksRowToR8G8(end_low_rr00gg00, end_high_rr00gg00, weights_high,
|
||||
i * 8u, row_01, row_23);
|
||||
xe_texture_copy_dest.Store4(texel_offset_host, row_01);
|
||||
xe_texture_copy_dest.Store4(texel_offset_host + 16u, row_23);
|
||||
if (++texel_index_host.y >= xe_texture_copy_size_texels.y) {
|
||||
|
||||
Reference in New Issue
Block a user