add correct defaults for buffer stride and buffer image height
continuous-integration/drone/push Build is failing Details

d3d11
cosmonaut 2024-03-05 16:06:39 -08:00
parent 3c74ddf8fa
commit 6c2eef669e
1 changed files with 25 additions and 4 deletions

View File

@ -1990,7 +1990,8 @@ static void D3D11_UploadToTexture(
D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer*) transferBuffer;
D3D11TransferBuffer *d3d11TransferBuffer = container->activeBuffer;
D3D11Texture *d3d11Texture = (D3D11Texture*) textureRegion->textureSlice.texture;
uint32_t bufferStride = copyParams->bufferStride;
uint32_t bufferImageHeight = copyParams->bufferImageHeight;
int32_t w = textureRegion->w;
int32_t h = textureRegion->h;
@ -2001,6 +2002,15 @@ static void D3D11_UploadToTexture(
h = (h + blockSize - 1) & ~(blockSize - 1);
}
if (bufferStride == 0)
{
bufferStride = BytesPerRow(w, d3d11Texture->format);
}
if (bufferImageHeight == 0)
{
bufferImageHeight = h;
}
D3D11_BOX dstBox;
dstBox.left = textureRegion->x;
dstBox.top = textureRegion->y;
@ -2019,8 +2029,8 @@ static void D3D11_UploadToTexture(
),
&dstBox,
(uint8_t*) d3d11TransferBuffer->data + copyParams->bufferOffset,
copyParams->bufferStride,
copyParams->bufferStride * copyParams->bufferImageHeight,
bufferStride,
bufferStride * bufferImageHeight,
writeOption == REFRESH_WRITEOPTIONS_SAFEDISCARD ? D3D11_COPY_DISCARD : 0
);
@ -2076,6 +2086,8 @@ static void D3D11_DownloadFromTexture(
d3d11Texture->levelCount
);
int32_t formatSize = Texture_GetFormatSize(d3d11Texture->format);
uint32_t bufferStride = copyParams->bufferStride;
uint32_t bufferImageHeight = copyParams->bufferImageHeight;
D3D11_BOX srcBox = {textureRegion->x, textureRegion->y, textureRegion->z, textureRegion->x + textureRegion->w, textureRegion->y + textureRegion->h, 1};
D3D11_MAPPED_SUBRESOURCE subresource;
HRESULT res;
@ -2136,12 +2148,21 @@ static void D3D11_DownloadFromTexture(
);
ERROR_CHECK_RETURN("Could not map texture for reading",)
if (bufferStride == 0)
{
bufferStride = BytesPerRow(textureRegion->w, d3d11Texture->format);
}
if (bufferImageHeight == 0)
{
bufferImageHeight = textureRegion->h;
}
uint8_t* dataPtr = (uint8_t*) d3d11TransferBuffer->data + copyParams->bufferOffset;
for (uint32_t row = textureRegion->y; row < copyParams->bufferImageHeight; row += 1)
{
SDL_memcpy(
dataPtr,
(uint8_t*) subresource.pData + (row * copyParams->bufferStride) + (textureRegion->x * formatSize),
(uint8_t*) subresource.pData + (row * bufferStride) + (textureRegion->x * formatSize),
textureRegion->w * formatSize
);
}