[GPU] XeSL texture load shaders + minor XeSL cleanup

This commit is contained in:
Triang3l
2022-04-04 21:48:27 +03:00
parent c4eae232f1
commit 3d48fde5ca
197 changed files with 56046 additions and 7249 deletions

View File

@@ -0,0 +1,90 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2022 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "pixel_formats.xesli"
#include "texture_load.xesli"
xesl_entry
xesl_writeTypedStorageBuffer(xesl_uint4, xe_texture_load_dest, set=0,
binding=0, u0, space0)
xesl_entry_binding_next
xesl_typedStorageBuffer(xesl_uint4, xe_texture_load_source, set=1, binding=0,
t0, space0)
xesl_entry_bindings_end_local_size(16, 32, 1)
xesl_input_global_invocation_id
xesl_entry_signature_end
// 1 thread = 2 DXT5 blocks to 8x4 R8G8B8A8 texels.
xesl_uint3 block_index = xesl_GlobalInvocationID << xesl_uint3(1u, 0u, 0u);
xesl_dont_flatten
if (any(xesl_greaterThanEqual(block_index.xy,
XeTextureLoadSizeBlocks().xy))) {
return;
}
xesl_uint3 texel_index_host = block_index << xesl_uint3(2u, 2u, 0u);
uint blocks_pitch_host = XeTextureLoadHostPitch();
uint height_texels = XeTextureLoadHeightTexels();
uint block_offset_host = uint(
(XeTextureHostLinearOffset(xesl_int3(texel_index_host), blocks_pitch_host,
height_texels, 4u) +
XeTextureLoadHostOffset()) >> 4u);
uint elements_pitch_host = blocks_pitch_host >> 4u;
uint block_offset_guest =
XeTextureLoadGuestBlockOffset(block_index, 16u, 4u) >> 4u;
uint endian = XeTextureLoadEndian32();
uint i;
xesl_unroll for (i = 0u; i < 2u; ++i) {
if (i != 0u) {
++block_offset_host;
// Odd block = even block + 32 guest bytes when tiled.
block_offset_guest += XeTextureLoadIsTiled() ? 2u : 1u;
}
xesl_uint4 block = XeEndianSwap32(
xesl_typedStorageBufferLoad(xe_texture_load_source, block_offset_guest),
endian);
xesl_uint2 bgr_end_8in10 = XeDXTColorEndpointsToBGR8In10(block.z);
// Sort the color indices so they can be used as weights for the second
// endpoint.
uint bgr_weights = XeDXTHighColorWeights(block.w);
xesl_uint2 alpha_end = (block.xx >> xesl_uint2(0u, 8u)) & 0xFFu;
uint alpha_weights = XeDXT5HighAlphaWeights(
alpha_end, (block.x >> 16u) | ((block.y & 0xFFu) << 16u));
xesl_writeTypedStorageBufferStore(
xe_texture_load_dest, block_offset_host,
XeDXTOpaqueRowToRGB8(bgr_end_8in10, bgr_weights) |
((XeDXT5RowToA8(alpha_end, alpha_weights).xxxx <<
xesl_uint4(24u, 16u, 8u, 0u))
& 0xFF000000u));
xesl_dont_flatten if (texel_index_host.y + 1u < height_texels) {
xesl_writeTypedStorageBufferStore(
xe_texture_load_dest, block_offset_host + elements_pitch_host,
XeDXTOpaqueRowToRGB8(bgr_end_8in10, bgr_weights >> 8u) |
((XeDXT5RowToA8(alpha_end, alpha_weights >> 12u).xxxx <<
xesl_uint4(24u, 16u, 8u, 0u))
& 0xFF000000u));
xesl_dont_flatten if (texel_index_host.y + 2u < height_texels) {
alpha_weights = XeDXT5HighAlphaWeights(alpha_end, block.y >> 8u);
xesl_writeTypedStorageBufferStore(
xe_texture_load_dest, block_offset_host + 2u * elements_pitch_host,
XeDXTOpaqueRowToRGB8(bgr_end_8in10, bgr_weights >> 16u) |
((XeDXT5RowToA8(alpha_end, alpha_weights).xxxx <<
xesl_uint4(24u, 16u, 8u, 0u))
& 0xFF000000u));
xesl_dont_flatten if (texel_index_host.y + 3u < height_texels) {
xesl_writeTypedStorageBufferStore(
xe_texture_load_dest,
block_offset_host + 3u * elements_pitch_host,
XeDXTOpaqueRowToRGB8(bgr_end_8in10, bgr_weights >> 24u) |
((XeDXT5RowToA8(alpha_end, alpha_weights >> 12u).xxxx <<
xesl_uint4(24u, 16u, 8u, 0u))
& 0xFF000000u));
}
}
}
}
xesl_entry_end