texture_codec: Align buffer sizes to bpp

* Prevents out of bounds texture reads when launching TOA from the HOME menu
This commit is contained in:
GPUCode 2024-01-24 04:55:33 +02:00
parent 2cbb2d379e
commit 4c1933e0b6
4 changed files with 12 additions and 6 deletions

View File

@ -35,7 +35,7 @@ PicaCore::PicaCore(Memory::MemorySystem& memory_, std::shared_ptr<DebugContext>
gs_unit,
gs_setup},
shader_engine{CreateEngine(Settings::values.use_shader_jit.GetValue())} {
SetFramebufferDefaults();
InitializeRegs();
const auto submit_vertex = [this](const AttributeBuffer& buffer) {
const auto add_triangle = [this](const OutputVertex& v0, const OutputVertex& v1,
@ -54,7 +54,7 @@ PicaCore::PicaCore(Memory::MemorySystem& memory_, std::shared_ptr<DebugContext>
PicaCore::~PicaCore() = default;
void PicaCore::SetFramebufferDefaults() {
void PicaCore::InitializeRegs() {
auto& framebuffer_top = regs.framebuffer_config[0];
auto& framebuffer_sub = regs.framebuffer_config[1];
@ -77,6 +77,9 @@ void PicaCore::SetFramebufferDefaults() {
framebuffer_sub.stride = 3 * 240;
framebuffer_sub.color_format.Assign(PixelFormat::RGB8);
framebuffer_sub.active_fb = 0;
// Tales of Abyss expects this register to have the following default value.
regs.internal.gs.input_buffer_config = 0xa0000001;
}
void PicaCore::BindRasterizer(VideoCore::RasterizerInterface* rasterizer) {

View File

@ -39,7 +39,7 @@ public:
void ProcessCmdList(PAddr list, u32 size);
private:
void SetFramebufferDefaults();
void InitializeRegs();
void WriteInternalReg(u32 id, u32 value, u32 mask);

View File

@ -35,7 +35,7 @@ struct ShaderRegs {
union {
// Number of input attributes to shader unit - 1
u32 raw{0xa0000001};
u32 input_buffer_config;
BitField<0, 4, u32> max_input_attribute_index;
BitField<8, 8, u32> input_to_uniform;
BitField<24, 8, ShaderMode> shader_mode;

View File

@ -341,8 +341,8 @@ static constexpr void MortonCopy(u32 width, u32 height, u32 start_offset, u32 en
*/
template <bool decode, PixelFormat format, bool converted = false>
static constexpr void LinearCopy(std::span<u8> src_buffer, std::span<u8> dst_buffer) {
const std::size_t src_size = src_buffer.size();
const std::size_t dst_size = dst_buffer.size();
std::size_t src_size = src_buffer.size();
std::size_t dst_size = dst_buffer.size();
if constexpr (converted) {
constexpr u32 encoded_bytes_per_pixel = GetFormatBpp(format) / 8;
@ -352,6 +352,9 @@ static constexpr void LinearCopy(std::span<u8> src_buffer, std::span<u8> dst_buf
constexpr u32 dst_bytes_per_pixel =
decode ? decoded_bytes_per_pixel : encoded_bytes_per_pixel;
src_size = Common::AlignDown(src_size, src_bytes_per_pixel);
dst_size = Common::AlignDown(dst_size, dst_bytes_per_pixel);
for (std::size_t src_index = 0, dst_index = 0; src_index < src_size && dst_index < dst_size;
src_index += src_bytes_per_pixel, dst_index += dst_bytes_per_pixel) {
const auto src_pixel = src_buffer.subspan(src_index, src_bytes_per_pixel);