mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:58:37 +00:00
Cache GFX10 tile X offsets and per-row Y contributions
Avoid per-element bit interleaving in tile/detile copies; retain element_offset as the independent reference and validate decoded output against it. AI-assisted. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <bit>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
@ -122,10 +123,25 @@ private:
|
||||
if (source.size() < (to_tiled ? linear_size : size_) ||
|
||||
destination.size() < (to_tiled ? size_ : linear_size) ||
|
||||
tiling_detail::overlap(source, destination)) return false;
|
||||
const auto tile_x_bits = std::countr_zero(tile_width_);
|
||||
std::size_t x_offsets[256]{};
|
||||
for (std::size_t x = 0; x < tile_width_; ++x) {
|
||||
for (unsigned bit = 0; bit < bits_; ++bit) {
|
||||
const int source_bit = pattern_[bit];
|
||||
if (source_bit > 0) x_offsets[x] |= ((x >> (source_bit - 1)) & 1) << bit;
|
||||
}
|
||||
}
|
||||
for (std::size_t y = 0; y < height_; ++y) {
|
||||
std::size_t y_offset = 0;
|
||||
for (unsigned bit = 0; bit < bits_; ++bit) {
|
||||
const int source_bit = pattern_[bit];
|
||||
if (source_bit < 0) y_offset |= ((y >> (-source_bit - 1)) & 1) << bit;
|
||||
}
|
||||
const std::size_t tile_row = (y / tile_height_) * tiles_x_;
|
||||
for (std::size_t x = 0; x < width_; ++x) {
|
||||
const std::size_t linear = y * pitch + x * element_bytes_;
|
||||
const std::size_t tiled = address(x, y);
|
||||
const std::size_t tiled = ((tile_row + (x >> tile_x_bits)) << bits_) +
|
||||
y_offset + x_offsets[x & (tile_width_ - 1)];
|
||||
std::memcpy(destination.data() + (to_tiled ? tiled : linear),
|
||||
source.data() + (to_tiled ? linear : tiled), element_bytes_);
|
||||
}
|
||||
|
||||
@ -50,6 +50,15 @@ int check_surface(TileMode mode, std::size_t bpe, std::size_t width, std::size_t
|
||||
for (std::size_t y = 0; y < height; ++y)
|
||||
std::copy_n(linear.begin() + y * pitch, row_bytes, expected.begin() + y * pitch);
|
||||
CHECK(decoded == expected);
|
||||
std::vector<std::byte> reference(linear_size, std::byte{0xab});
|
||||
for (std::size_t y = 0; y < height; ++y) {
|
||||
for (std::size_t x = 0; x < width; ++x) {
|
||||
std::size_t offset;
|
||||
CHECK(surface.element_offset(x, y, offset));
|
||||
std::copy_n(tiled.begin() + offset, bpe, reference.begin() + y * pitch + x * bpe);
|
||||
}
|
||||
}
|
||||
CHECK(decoded == reference);
|
||||
std::vector<std::byte> encoded(tiled.size(), std::byte{0xcc});
|
||||
CHECK(surface.tile(decoded, encoded, pitch));
|
||||
CHECK(encoded == tiled);
|
||||
|
||||
Reference in New Issue
Block a user