summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/textures/decoders.cpp74
1 files changed, 71 insertions, 3 deletions
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp
index 8ae6dcf9a..d6750b174 100644
--- a/src/video_core/textures/decoders.cpp
+++ b/src/video_core/textures/decoders.cpp
@@ -98,6 +98,74 @@ static void FastSwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_
98 } 98 }
99} 99}
100 100
101void Precise3DProcessGobs(u8* swizzled_data, u8* unswizzled_data, bool unswizzle, const u32 x_start,
102 const u32 y_start, const u32 z_start, const u32 x_end, const u32 y_end,
103 const u32 z_end, const u32 tile_offset, const u32 xy_block_size,
104 const u32 layer_z, const u32 stride_x, const u32 bytes_per_pixel,
105 const u32 out_bytes_per_pixel) {
106 std::array<u8*, 2> data_ptrs;
107 u32 z_adress = tile_offset;
108 const u32 gob_size = 64 * 8 * 1;
109 for (u32 z = z_start; z < z_end; z++) {
110 u32 y_adress = z_adress;
111 u32 pixel_base = layer_z * z + y_start * stride_x;
112 for (u32 y = y_start; y < y_end; y++) {
113 const auto& table = legacy_swizzle_table[y % 8];
114 for (u32 x = x_start; x < x_end; x++) {
115 const u32 swizzle_offset{y_adress + table[x * bytes_per_pixel % 64]};
116 const u32 pixel_index{x * out_bytes_per_pixel + pixel_base};
117 data_ptrs[unswizzle] = swizzled_data + swizzle_offset;
118 data_ptrs[!unswizzle] = unswizzled_data + pixel_index;
119 std::memcpy(data_ptrs[0], data_ptrs[1], bytes_per_pixel);
120 }
121 pixel_base += stride_x;
122 if ((y + 1) % 8 == 0)
123 y_adress += gob_size;
124 }
125 z_adress += xy_block_size;
126 }
127}
128
129void Precise3DSwizzledData(u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 width,
130 u32 height, u32 depth, u32 bytes_per_pixel, u32 out_bytes_per_pixel,
131 u32 block_height, u32 block_depth) {
132 auto div_ceil = [](u32 x, u32 y) { return ((x + y - 1) / y); };
133
134 const u32 stride_x = width * out_bytes_per_pixel;
135 const u32 layer_z = height * stride_x;
136 const u32 gob_x_bytes = 64;
137 const u32 gob_elements_x = gob_x_bytes / bytes_per_pixel;
138 const u32 gob_elements_y = 8;
139 const u32 gob_elements_z = 1;
140 const u32 block_x_elements = gob_elements_x;
141 const u32 block_y_elements = gob_elements_y * block_height;
142 const u32 block_z_elements = gob_elements_z * block_depth;
143 const u32 blocks_on_x = div_ceil(width, block_x_elements);
144 const u32 blocks_on_y = div_ceil(height, block_y_elements);
145 const u32 blocks_on_z = div_ceil(depth, block_z_elements);
146 const u32 blocks = blocks_on_x * blocks_on_y * blocks_on_z;
147 const u32 gob_size = gob_x_bytes * gob_elements_y * gob_elements_z;
148 const u32 xy_block_size = gob_size * block_height;
149 const u32 block_size = xy_block_size * block_depth;
150 u32 tile_offset = 0;
151 for (u32 zb = 0; zb < blocks_on_z; zb++) {
152 const u32 z_start = zb * block_z_elements;
153 const u32 z_end = std::min(depth, z_start + block_z_elements);
154 for (u32 yb = 0; yb < blocks_on_y; yb++) {
155 const u32 y_start = yb * block_y_elements;
156 const u32 y_end = std::min(height, y_start + block_y_elements);
157 for (u32 xb = 0; xb < blocks_on_x; xb++) {
158 const u32 x_start = xb * block_x_elements;
159 const u32 x_end = std::min(width, x_start + block_x_elements);
160 Precise3DProcessGobs(swizzled_data, unswizzled_data, unswizzle, x_start, y_start,
161 z_start, x_end, y_end, z_end, tile_offset, xy_block_size, layer_z,
162 stride_x, bytes_per_pixel, out_bytes_per_pixel);
163 tile_offset += block_size;
164 }
165 }
166 }
167}
168
101void Fast3DProcessGobs(u8* swizzled_data, u8* unswizzled_data, bool unswizzle, const u32 x_start, 169void Fast3DProcessGobs(u8* swizzled_data, u8* unswizzled_data, bool unswizzle, const u32 x_start,
102 const u32 y_start, const u32 z_start, const u32 x_end, const u32 y_end, 170 const u32 y_start, const u32 z_start, const u32 x_end, const u32 y_end,
103 const u32 z_end, const u32 tile_offset, const u32 xy_block_size, 171 const u32 z_end, const u32 tile_offset, const u32 xy_block_size,
@@ -148,7 +216,7 @@ void Fast3DSwizzledData(u8* swizzled_data, u8* unswizzled_data, bool unswizzle,
148 const u32 blocks_on_y = div_ceil(height, block_y_elements); 216 const u32 blocks_on_y = div_ceil(height, block_y_elements);
149 const u32 blocks_on_z = div_ceil(depth, block_z_elements); 217 const u32 blocks_on_z = div_ceil(depth, block_z_elements);
150 const u32 blocks = blocks_on_x * blocks_on_y * blocks_on_z; 218 const u32 blocks = blocks_on_x * blocks_on_y * blocks_on_z;
151 const u32 gob_size = 64 * 8 * 1; 219 const u32 gob_size = gob_x_bytes * gob_elements_y * gob_elements_z;
152 const u32 xy_block_size = gob_size * block_height; 220 const u32 xy_block_size = gob_size * block_height;
153 const u32 block_size = xy_block_size * block_depth; 221 const u32 block_size = xy_block_size * block_depth;
154 u32 tile_offset = 0; 222 u32 tile_offset = 0;
@@ -176,8 +244,8 @@ void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_
176 Fast3DSwizzledData(swizzled_data, unswizzled_data, unswizzle, width, height, 1U, 244 Fast3DSwizzledData(swizzled_data, unswizzled_data, unswizzle, width, height, 1U,
177 bytes_per_pixel, out_bytes_per_pixel, block_height, 1U); 245 bytes_per_pixel, out_bytes_per_pixel, block_height, 1U);
178 } else { 246 } else {
179 LegacySwizzleData(width, height, bytes_per_pixel, out_bytes_per_pixel, swizzled_data, 247 Precise3DSwizzledData(swizzled_data, unswizzled_data, unswizzle, width, height, 1U,
180 unswizzled_data, unswizzle, block_height); 248 bytes_per_pixel, out_bytes_per_pixel, block_height, 1U);
181 } 249 }
182} 250}
183 251