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

@ -85,7 +85,7 @@ void initTextures() {
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(stagingBuffer, texture, 0, 0, 0, 1024, 1024, 1, 0)
.CopyBufferToTexture(stagingBuffer, 0, texture, 0, 0, 0, 1024, 1024, 1, 0)
.GetResult();
queue.Submit(1, &copy);

View File

@ -377,7 +377,7 @@ namespace {
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
auto cmdbuf = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(staging, oTexture, 0, 0, 0, 1, 1, 1, 0)
.CopyBufferToTexture(staging, 0, oTexture, 0, 0, 0, 1, 1, 1, 0)
.GetResult();
queue.Submit(1, &cmdbuf);
oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled);
@ -440,7 +440,7 @@ namespace {
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
auto cmdbuf = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(staging, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0)
.CopyBufferToTexture(staging, 0, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0)
.GetResult();
queue.Submit(1, &cmdbuf);
oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled);

View File

@ -207,6 +207,7 @@
"name": "copy buffer to texture",
"args": [
{"name": "buffer", "type": "buffer"},
{"name": "buffer offset", "type": "uint32_t"},
{"name": "texture", "type": "texture"},
{"name": "x", "type": "uint32_t"},
{"name": "y", "type": "uint32_t"},
@ -219,11 +220,9 @@
"TODO": [
"Make pretty with Offset and Extents structures",
"Allow choosing the aspect (depth vs. stencil)?",
"The following where removed because gmock supports only 10 arguments",
"this means the buffer is assumed to be packed and starting at 0.",
"Add these arguments too",
{"name": "row length", "type": "uint32_t"},
{"name": "image height", "type": "uint32_t"},
{"name": "buffer offset", "type": "uint32_t"}
{"name": "image height", "type": "uint32_t"}
]
},
{

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;