mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(agc): add gpu texture detiling shader
This commit is contained in:
@@ -22,5 +22,110 @@ layout(push_constant) uniform Push {
|
||||
uint elementBytes;
|
||||
} params;
|
||||
|
||||
void main() {
|
||||
uint standardOffset(uint x, uint y) {
|
||||
switch (ELEMENT_BYTES) {
|
||||
case 1u:
|
||||
return ((y << 4) & 0x1f0u) ^ ((y << 5) & 0x400u) ^ (x & 0x00fu) ^
|
||||
((x << 5) & 0x200u) ^ ((x << 6) & 0x800u);
|
||||
case 2u:
|
||||
return ((y << 4) & 0x070u) ^ ((y << 5) & 0x100u) ^ ((y << 6) & 0x400u) ^
|
||||
((x << 1) & 0x00eu) ^ ((x << 4) & 0x080u) ^
|
||||
((x << 5) & 0x200u) ^ ((x << 6) & 0x800u);
|
||||
case 4u:
|
||||
return ((y << 4) & 0x070u) ^ ((y << 5) & 0x100u) ^ ((y << 6) & 0x400u) ^
|
||||
((x << 2) & 0x00cu) ^ ((x << 5) & 0x080u) ^
|
||||
((x << 6) & 0x200u) ^ ((x << 7) & 0x800u);
|
||||
case 8u:
|
||||
return ((y << 4) & 0x030u) ^ ((y << 6) & 0x100u) ^ ((y << 7) & 0x400u) ^
|
||||
((x << 3) & 0x008u) ^ ((x << 5) & 0x0c0u) ^
|
||||
((x << 6) & 0x200u) ^ ((x << 7) & 0x800u);
|
||||
default:
|
||||
return ((y << 4) & 0x030u) ^ ((y << 6) & 0x100u) ^ ((y << 7) & 0x400u) ^
|
||||
((x << 6) & 0x0c0u) ^ ((x << 7) & 0x200u) ^ ((x << 8) & 0x800u);
|
||||
}
|
||||
}
|
||||
|
||||
uint standard64Extra(uint x, uint y) {
|
||||
switch (ELEMENT_BYTES) {
|
||||
case 1u:
|
||||
return ((x << 7) & 0x2000u) ^ ((x << 8) & 0x8000u) ^
|
||||
((y << 6) & 0x1000u) ^ ((y << 7) & 0x4000u);
|
||||
case 2u:
|
||||
return ((x << 7) & 0x2000u) ^ ((x << 8) & 0x8000u) ^
|
||||
((y << 7) & 0x1000u) ^ ((y << 8) & 0x4000u);
|
||||
case 4u:
|
||||
return ((x << 8) & 0x2000u) ^ ((x << 9) & 0x8000u) ^
|
||||
((y << 7) & 0x1000u) ^ ((y << 8) & 0x4000u);
|
||||
case 8u:
|
||||
return ((x << 8) & 0x2000u) ^ ((x << 9) & 0x8000u) ^
|
||||
((y << 8) & 0x1000u) ^ ((y << 9) & 0x4000u);
|
||||
default:
|
||||
return ((x << 9) & 0x2000u) ^ ((x << 10) & 0x8000u) ^
|
||||
((y << 8) & 0x1000u) ^ ((y << 9) & 0x4000u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint blockOffset(uvec2 p) {
|
||||
uint offset = standardOffset(p.x, p.y);
|
||||
if (BLOCK_BYTES > 4096u) {
|
||||
offset ^= standard64Extra(p.x, p.y);
|
||||
}
|
||||
return offset & (BLOCK_BYTES - 1u);
|
||||
}
|
||||
|
||||
uvec2 blockExtent() {
|
||||
uint width;
|
||||
if (BLOCK_BYTES <= 256u) {
|
||||
width = ELEMENT_BYTES <= 2u ? 16u : (ELEMENT_BYTES <= 8u ? 8u : 4u);
|
||||
} else if (BLOCK_BYTES <= 4096u) {
|
||||
width = ELEMENT_BYTES <= 2u ? 64u : (ELEMENT_BYTES <= 8u ? 32u : 16u);
|
||||
} else {
|
||||
width = ELEMENT_BYTES <= 2u ? 256u : (ELEMENT_BYTES <= 8u ? 128u : 64u);
|
||||
}
|
||||
return uvec2(width, BLOCK_BYTES / (width * ELEMENT_BYTES));
|
||||
}
|
||||
|
||||
void copyElement(uint src, uint dst) {
|
||||
if (ELEMENT_BYTES >= 4u) {
|
||||
for (uint i = 0u; i < ELEMENT_BYTES; i += 4u) {
|
||||
outputBuffer.data[(dst + i) >> 2] = inputBuffer.data[(src + i) >> 2];
|
||||
}
|
||||
} else {
|
||||
uint mask = ELEMENT_BYTES == 1u ? 0xffu : 0xffffu;
|
||||
uint value = (inputBuffer.data[src >> 2] >> ((src & 3u) * 8u)) & mask;
|
||||
uint shift = (dst & 3u) * 8u;
|
||||
atomicAnd(outputBuffer.data[dst >> 2], ~(mask << shift));
|
||||
atomicOr(outputBuffer.data[dst >> 2], value << shift);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
uvec2 p = gl_GlobalInvocationID.xy;
|
||||
if (p.x >= params.width || p.y >= params.height) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint linearOffset = p.y * params.pitchBytes + p.x * ELEMENT_BYTES;
|
||||
|
||||
if (TILE_FAMILY == 0u) {
|
||||
// kLinear: guest and host layouts match; a straight copy at the
|
||||
// same pitch, no swizzle.
|
||||
copyElement(params.srcBase + linearOffset, params.dstBase + linearOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
uvec2 swizzle = p;
|
||||
uvec2 block = uvec2(0u);
|
||||
if (params.tail != 0u) {
|
||||
swizzle += uvec2(params.tailX, params.tailY);
|
||||
} else {
|
||||
block = p / blockExtent();
|
||||
}
|
||||
|
||||
uint blockIndex = block.y * params.blocksPerRow + block.x;
|
||||
uint tiledOffset = blockIndex * BLOCK_BYTES + blockOffset(swizzle);
|
||||
|
||||
copyElement(params.srcBase + tiledOffset, params.dstBase + linearOffset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user