Add bufferOffset to CopyBufferToTexture.
This commit is contained in:
parent
a2d4d14bd4
commit
7f433a5b52
|
@ -85,7 +85,7 @@ void initTextures() {
|
||||||
|
|
||||||
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
|
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
|
||||||
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
|
.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();
|
.GetResult();
|
||||||
|
|
||||||
queue.Submit(1, ©);
|
queue.Submit(1, ©);
|
||||||
|
|
|
@ -377,7 +377,7 @@ namespace {
|
||||||
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
|
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
|
||||||
auto cmdbuf = device.CreateCommandBufferBuilder()
|
auto cmdbuf = device.CreateCommandBufferBuilder()
|
||||||
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
|
.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();
|
.GetResult();
|
||||||
queue.Submit(1, &cmdbuf);
|
queue.Submit(1, &cmdbuf);
|
||||||
oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled);
|
oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled);
|
||||||
|
@ -440,7 +440,7 @@ namespace {
|
||||||
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
|
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
|
||||||
auto cmdbuf = device.CreateCommandBufferBuilder()
|
auto cmdbuf = device.CreateCommandBufferBuilder()
|
||||||
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
|
.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();
|
.GetResult();
|
||||||
queue.Submit(1, &cmdbuf);
|
queue.Submit(1, &cmdbuf);
|
||||||
oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled);
|
oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled);
|
||||||
|
|
|
@ -207,6 +207,7 @@
|
||||||
"name": "copy buffer to texture",
|
"name": "copy buffer to texture",
|
||||||
"args": [
|
"args": [
|
||||||
{"name": "buffer", "type": "buffer"},
|
{"name": "buffer", "type": "buffer"},
|
||||||
|
{"name": "buffer offset", "type": "uint32_t"},
|
||||||
{"name": "texture", "type": "texture"},
|
{"name": "texture", "type": "texture"},
|
||||||
{"name": "x", "type": "uint32_t"},
|
{"name": "x", "type": "uint32_t"},
|
||||||
{"name": "y", "type": "uint32_t"},
|
{"name": "y", "type": "uint32_t"},
|
||||||
|
@ -219,11 +220,9 @@
|
||||||
"TODO": [
|
"TODO": [
|
||||||
"Make pretty with Offset and Extents structures",
|
"Make pretty with Offset and Extents structures",
|
||||||
"Allow choosing the aspect (depth vs. stencil)?",
|
"Allow choosing the aspect (depth vs. stencil)?",
|
||||||
"The following where removed because gmock supports only 10 arguments",
|
"Add these arguments too",
|
||||||
"this means the buffer is assumed to be packed and starting at 0.",
|
|
||||||
{"name": "row length", "type": "uint32_t"},
|
{"name": "row length", "type": "uint32_t"},
|
||||||
{"name": "image height", "type": "uint32_t"},
|
{"name": "image height", "type": "uint32_t"}
|
||||||
{"name": "buffer offset", "type": "uint32_t"}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -245,6 +245,7 @@ namespace backend {
|
||||||
{
|
{
|
||||||
CopyBufferToTextureCmd* copy = iterator.NextCommand<CopyBufferToTextureCmd>();
|
CopyBufferToTextureCmd* copy = iterator.NextCommand<CopyBufferToTextureCmd>();
|
||||||
BufferBase* buffer = copy->buffer.Get();
|
BufferBase* buffer = copy->buffer.Get();
|
||||||
|
uint32_t bufferOffset = copy->bufferOffset;
|
||||||
TextureBase* texture = copy->texture.Get();
|
TextureBase* texture = copy->texture.Get();
|
||||||
uint64_t width = copy->width;
|
uint64_t width = copy->width;
|
||||||
uint64_t height = copy->height;
|
uint64_t height = copy->height;
|
||||||
|
@ -273,8 +274,7 @@ namespace backend {
|
||||||
uint64_t pixelSize = TextureFormatPixelSize(texture->GetFormat());
|
uint64_t pixelSize = TextureFormatPixelSize(texture->GetFormat());
|
||||||
uint64_t dataSize = width * height * depth * pixelSize;
|
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>(bufferOffset) > static_cast<uint64_t>(buffer->GetSize())) {
|
||||||
if (dataSize > static_cast<uint64_t>(buffer->GetSize())) {
|
|
||||||
device->HandleError("Copy would read after end of the buffer");
|
device->HandleError("Copy would read after end of the buffer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -497,11 +497,13 @@ namespace backend {
|
||||||
return device->CreateCommandBuffer(this);
|
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) {
|
uint32_t width, uint32_t height, uint32_t depth, uint32_t level) {
|
||||||
CopyBufferToTextureCmd* copy = allocator.Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
|
CopyBufferToTextureCmd* copy = allocator.Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
|
||||||
new(copy) CopyBufferToTextureCmd;
|
new(copy) CopyBufferToTextureCmd;
|
||||||
copy->buffer = buffer;
|
copy->buffer = buffer;
|
||||||
|
copy->bufferOffset = bufferOffset;
|
||||||
copy->texture = texture;
|
copy->texture = texture;
|
||||||
copy->x = x;
|
copy->x = x;
|
||||||
copy->y = y;
|
copy->y = y;
|
||||||
|
|
|
@ -57,7 +57,8 @@ namespace backend {
|
||||||
// NXT API
|
// NXT API
|
||||||
CommandBufferBase* GetResult();
|
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);
|
uint32_t width, uint32_t height, uint32_t depth, uint32_t level);
|
||||||
void Dispatch(uint32_t x, uint32_t y, uint32_t z);
|
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);
|
void DrawArrays(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace backend {
|
||||||
|
|
||||||
struct CopyBufferToTextureCmd {
|
struct CopyBufferToTextureCmd {
|
||||||
Ref<BufferBase> buffer;
|
Ref<BufferBase> buffer;
|
||||||
|
uint32_t bufferOffset;
|
||||||
Ref<TextureBase> texture;
|
Ref<TextureBase> texture;
|
||||||
uint32_t x, y, z;
|
uint32_t x, y, z;
|
||||||
uint32_t width, height, depth;
|
uint32_t width, height, depth;
|
||||||
|
|
|
@ -330,7 +330,7 @@ namespace metal {
|
||||||
encoders.EnsureBlit(commandBuffer);
|
encoders.EnsureBlit(commandBuffer);
|
||||||
[encoders.blit
|
[encoders.blit
|
||||||
copyFromBuffer:buffer->GetMTLBuffer()
|
copyFromBuffer:buffer->GetMTLBuffer()
|
||||||
sourceOffset:0
|
sourceOffset:copy->bufferOffset
|
||||||
sourceBytesPerRow:rowSize
|
sourceBytesPerRow:rowSize
|
||||||
sourceBytesPerImage:(rowSize * copy->height)
|
sourceBytesPerImage:(rowSize * copy->height)
|
||||||
sourceSize:size
|
sourceSize:size
|
||||||
|
|
|
@ -74,7 +74,8 @@ namespace opengl {
|
||||||
glBindTexture(target, texture->GetHandle());
|
glBindTexture(target, texture->GetHandle());
|
||||||
|
|
||||||
glTexSubImage2D(target, copy->level, copy->x, copy->y, copy->width, copy->height,
|
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);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue