Add bufferOffset to CopyBufferToTexture.

This commit is contained in:
Corentin Wallez
2017-05-09 16:57:52 +02:00
committed by Corentin Wallez
parent a2d4d14bd4
commit 7f433a5b52
8 changed files with 17 additions and 13 deletions

View File

@@ -245,6 +245,7 @@ namespace backend {
{
CopyBufferToTextureCmd* copy = iterator.NextCommand<CopyBufferToTextureCmd>();
BufferBase* buffer = copy->buffer.Get();
uint32_t bufferOffset = copy->bufferOffset;
TextureBase* texture = copy->texture.Get();
uint64_t width = copy->width;
uint64_t height = copy->height;
@@ -273,8 +274,7 @@ namespace backend {
uint64_t pixelSize = TextureFormatPixelSize(texture->GetFormat());
uint64_t dataSize = width * height * depth * pixelSize;
// TODO(cwallez@chromium.org): handle buffer offset when it is in the command.
if (dataSize > static_cast<uint64_t>(buffer->GetSize())) {
if (dataSize + static_cast<uint64_t>(bufferOffset) > static_cast<uint64_t>(buffer->GetSize())) {
device->HandleError("Copy would read after end of the buffer");
return false;
}
@@ -497,11 +497,13 @@ namespace backend {
return device->CreateCommandBuffer(this);
}
void CommandBufferBuilder::CopyBufferToTexture(BufferBase* buffer, TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
void CommandBufferBuilder::CopyBufferToTexture(BufferBase* buffer, uint32_t bufferOffset,
TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
uint32_t width, uint32_t height, uint32_t depth, uint32_t level) {
CopyBufferToTextureCmd* copy = allocator.Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
new(copy) CopyBufferToTextureCmd;
copy->buffer = buffer;
copy->bufferOffset = bufferOffset;
copy->texture = texture;
copy->x = x;
copy->y = y;

View File

@@ -57,7 +57,8 @@ namespace backend {
// NXT API
CommandBufferBase* GetResult();
void CopyBufferToTexture(BufferBase* buffer, TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
void CopyBufferToTexture(BufferBase* buffer, uint32_t bufferOffset,
TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
uint32_t width, uint32_t height, uint32_t depth, uint32_t level);
void Dispatch(uint32_t x, uint32_t y, uint32_t z);
void DrawArrays(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);

View File

@@ -41,6 +41,7 @@ namespace backend {
struct CopyBufferToTextureCmd {
Ref<BufferBase> buffer;
uint32_t bufferOffset;
Ref<TextureBase> texture;
uint32_t x, y, z;
uint32_t width, height, depth;

View File

@@ -330,7 +330,7 @@ namespace metal {
encoders.EnsureBlit(commandBuffer);
[encoders.blit
copyFromBuffer:buffer->GetMTLBuffer()
sourceOffset:0
sourceOffset:copy->bufferOffset
sourceBytesPerRow:rowSize
sourceBytesPerImage:(rowSize * copy->height)
sourceSize:size

View File

@@ -74,7 +74,8 @@ namespace opengl {
glBindTexture(target, texture->GetHandle());
glTexSubImage2D(target, copy->level, copy->x, copy->y, copy->width, copy->height,
format.format, format.type, nullptr);
format.format, format.type,
reinterpret_cast<void*>(static_cast<uintptr_t>(copy->bufferOffset)));
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
break;