Always use GetLayerStride for layer stride in Texture

The `GuestTexture::GetLayerStride` function was not always being utilized to retrieve the layer stride inside `Texture`, it would instead directly access the `guestTexture::layerStride` member. This is problematic as it may not be initialized and return `0` which would lead to a broken image copy.
This commit is contained in:
PixelyIon 2022-05-13 14:21:37 +05:30
parent b81d5bc865
commit 168e51e7ad

View File

@ -161,6 +161,7 @@ namespace skyline::gpu {
} }
}()}; }()};
auto guestLayerStride{guest->GetLayerStride()};
for (size_t layer{}; layer < layerCount; ++layer) { for (size_t layer{}; layer < layerCount; ++layer) {
if (guest->tileConfig.mode == texture::TileMode::Block) if (guest->tileConfig.mode == texture::TileMode::Block)
texture::CopyBlockLinearToLinear(*guest, pointer, bufferData); texture::CopyBlockLinearToLinear(*guest, pointer, bufferData);
@ -168,7 +169,7 @@ namespace skyline::gpu {
texture::CopyPitchLinearToLinear(*guest, pointer, bufferData); texture::CopyPitchLinearToLinear(*guest, pointer, bufferData);
else if (guest->tileConfig.mode == texture::TileMode::Linear) else if (guest->tileConfig.mode == texture::TileMode::Linear)
std::memcpy(bufferData, pointer, size); std::memcpy(bufferData, pointer, size);
pointer += guest->GetLayerStride(); pointer += guestLayerStride;
bufferData += layerStride; bufferData += layerStride;
} }
@ -270,6 +271,7 @@ namespace skyline::gpu {
void Texture::CopyToGuest(u8 *hostBuffer) { void Texture::CopyToGuest(u8 *hostBuffer) {
auto guestOutput{mirror.data()}; auto guestOutput{mirror.data()};
auto guestLayerStride{guest->GetLayerStride()};
for (size_t layer{}; layer < layerCount; ++layer) { for (size_t layer{}; layer < layerCount; ++layer) {
if (guest->tileConfig.mode == texture::TileMode::Block) if (guest->tileConfig.mode == texture::TileMode::Block)
texture::CopyLinearToBlockLinear(*guest, hostBuffer, guestOutput); texture::CopyLinearToBlockLinear(*guest, hostBuffer, guestOutput);
@ -277,7 +279,7 @@ namespace skyline::gpu {
texture::CopyLinearToPitchLinear(*guest, hostBuffer, guestOutput); texture::CopyLinearToPitchLinear(*guest, hostBuffer, guestOutput);
else if (guest->tileConfig.mode == texture::TileMode::Linear) else if (guest->tileConfig.mode == texture::TileMode::Linear)
std::memcpy(hostBuffer, guestOutput, layerStride); std::memcpy(hostBuffer, guestOutput, layerStride);
guestOutput += guest->layerStride; guestOutput += guestLayerStride;
hostBuffer += layerStride; hostBuffer += layerStride;
} }
} }