[D3D12] Decompress textures if their size is not 4x4-aligned
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "pixel_formats.hlsli"
|
||||
#include "texture_copy.hlsli"
|
||||
|
||||
[numthreads(8, 32, 1)]
|
||||
void main(uint3 xe_thread_id : SV_DispatchThreadID) {
|
||||
// 1 thread = 4 DXT3A blocks to 4 DXT3 blocks with zero color.
|
||||
// 1 thread = 4 DXT3A (8bpb) blocks to 16x4 R8 texels (no need to convert to
|
||||
// DXT3 because the overhead is the same, 2x, but the size must be 4-aligned).
|
||||
uint3 block_index = xe_thread_id;
|
||||
block_index.x <<= 2u;
|
||||
[branch] if (any(block_index >= xe_texture_copy_size_blocks)) {
|
||||
@@ -16,14 +18,19 @@ void main(uint3 xe_thread_id : SV_DispatchThreadID) {
|
||||
xe_texture_copy_source.Load2(block_offsets_guest.w));
|
||||
blocks_01 = XeByteSwap(blocks_01, xe_texture_copy_endianness);
|
||||
blocks_23 = XeByteSwap(blocks_23, xe_texture_copy_endianness);
|
||||
uint block_offset_host = XeTextureHostLinearOffset(
|
||||
block_index, xe_texture_copy_size_blocks.y, xe_texture_copy_host_pitch,
|
||||
16u) + xe_texture_copy_host_base;
|
||||
xe_texture_copy_dest.Store4(block_offset_host, uint4(blocks_01.xy, 0u, 0u));
|
||||
xe_texture_copy_dest.Store4(block_offset_host + 16u,
|
||||
uint4(blocks_01.zw, 0u, 0u));
|
||||
xe_texture_copy_dest.Store4(block_offset_host + 32u,
|
||||
uint4(blocks_23.xy, 0u, 0u));
|
||||
xe_texture_copy_dest.Store4(block_offset_host + 48u,
|
||||
uint4(blocks_23.zw, 0u, 0u));
|
||||
uint4 alpha4_r01 = uint4(blocks_01.xz, blocks_23.xz);
|
||||
uint4 alpha4_r23 = 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(
|
||||
texel_index_host, xe_texture_copy_size_texels.y,
|
||||
xe_texture_copy_host_pitch, 1u) + xe_texture_copy_host_base;
|
||||
for (uint i = 0u; i < 4u; ++i) {
|
||||
xe_texture_copy_dest.Store4(texel_offset_host, XeDXT3FourBlocksRowToA8(
|
||||
(i < 2u ? alpha4_r01 : alpha4_r23) >> ((i & 1u) * 16u)));
|
||||
if (++texel_index_host.y >= xe_texture_copy_size_texels.y) {
|
||||
return;
|
||||
}
|
||||
texel_offset_host += xe_texture_copy_host_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user