mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 23:26:24 +00:00
Add T->B copies.
This implements T->B copies on the Metal backend only and while it adds validation tests, end2end tests will be done in a follow-up commit.
This commit is contained in:
committed by
Corentin Wallez
parent
492cbe4a43
commit
e9d347e89e
@@ -129,6 +129,12 @@ namespace backend {
|
||||
copy->~CopyBufferToTextureCmd();
|
||||
}
|
||||
break;
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = commands->NextCommand<CopyTextureToBufferCmd>();
|
||||
copy->~CopyTextureToBufferCmd();
|
||||
}
|
||||
break;
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands->NextCommand<DispatchCmd>();
|
||||
@@ -286,6 +292,22 @@ namespace backend {
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = iterator.NextCommand<CopyTextureToBufferCmd>();
|
||||
|
||||
uint32_t bufferCopySize = 0;
|
||||
if (!ComputeTextureCopyBufferSize(this, copy->source, &bufferCopySize) ||
|
||||
!ValidateCopyLocationFitsInTexture(this, copy->source) ||
|
||||
!ValidateCopySizeFitsInBuffer(this, copy->destination, bufferCopySize) ||
|
||||
!state->ValidateCanCopy() ||
|
||||
!state->ValidateCanUseTextureAs(copy->source.texture.Get(), nxt::TextureUsageBit::TransferSrc) ||
|
||||
!state->ValidateCanUseBufferAs(copy->destination.buffer.Get(), nxt::BufferUsageBit::TransferDst)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
iterator.NextCommand<DispatchCmd>();
|
||||
@@ -460,6 +482,23 @@ namespace backend {
|
||||
copy->destination.level = level;
|
||||
}
|
||||
|
||||
void CommandBufferBuilder::CopyTextureToBuffer(TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
|
||||
uint32_t width, uint32_t height, uint32_t depth, uint32_t level,
|
||||
BufferBase* buffer, uint32_t bufferOffset) {
|
||||
CopyTextureToBufferCmd* copy = allocator.Allocate<CopyTextureToBufferCmd>(Command::CopyTextureToBuffer);
|
||||
new(copy) CopyTextureToBufferCmd;
|
||||
copy->source.texture = texture;
|
||||
copy->source.x = x;
|
||||
copy->source.y = y;
|
||||
copy->source.z = z;
|
||||
copy->source.width = width;
|
||||
copy->source.height = height;
|
||||
copy->source.depth = depth;
|
||||
copy->source.level = level;
|
||||
copy->destination.buffer = buffer;
|
||||
copy->destination.offset = bufferOffset;
|
||||
}
|
||||
|
||||
void CommandBufferBuilder::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
|
||||
DispatchCmd* dispatch = allocator.Allocate<DispatchCmd>(Command::Dispatch);
|
||||
new(dispatch) DispatchCmd;
|
||||
|
||||
@@ -65,6 +65,9 @@ namespace backend {
|
||||
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 CopyTextureToBuffer(TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
|
||||
uint32_t width, uint32_t height, uint32_t depth, uint32_t level,
|
||||
BufferBase* buffer, uint32_t bufferOffset);
|
||||
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 DrawElements(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t firstInstance);
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace backend {
|
||||
BeginRenderPass,
|
||||
CopyBufferToBuffer,
|
||||
CopyBufferToTexture,
|
||||
CopyTextureToBuffer,
|
||||
Dispatch,
|
||||
DrawArrays,
|
||||
DrawElements,
|
||||
@@ -77,6 +78,11 @@ namespace backend {
|
||||
TextureCopyLocation destination;
|
||||
};
|
||||
|
||||
struct CopyTextureToBufferCmd {
|
||||
TextureCopyLocation source;
|
||||
BufferCopyLocation destination;
|
||||
};
|
||||
|
||||
struct DispatchCmd {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
|
||||
@@ -73,6 +73,7 @@ namespace d3d12 {
|
||||
commandList->OMSetRenderTargets(1, &device->GetCurrentRenderTargetDescriptor(), FALSE, nullptr);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::CopyBufferToBuffer:
|
||||
{
|
||||
CopyBufferToBufferCmd* copy = commands.NextCommand<CopyBufferToBufferCmd>();
|
||||
@@ -85,6 +86,12 @@ namespace d3d12 {
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
||||
|
||||
@@ -209,6 +209,39 @@ namespace metal {
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>();
|
||||
auto& src = copy->source;
|
||||
auto& dst = copy->destination;
|
||||
Texture* texture = ToBackend(src.texture.Get());
|
||||
Buffer* buffer = ToBackend(dst.buffer.Get());
|
||||
|
||||
unsigned rowSize = src.width * TextureFormatPixelSize(texture->GetFormat());
|
||||
MTLOrigin origin;
|
||||
origin.x = src.x;
|
||||
origin.y = src.y;
|
||||
origin.z = src.z;
|
||||
|
||||
MTLSize size;
|
||||
size.width = src.width;
|
||||
size.height = src.height;
|
||||
size.depth = src.depth;
|
||||
|
||||
encoders.EnsureBlit(commandBuffer);
|
||||
[encoders.blit
|
||||
copyFromTexture:texture->GetMTLTexture()
|
||||
sourceSlice:0
|
||||
sourceLevel:src.level
|
||||
sourceOrigin:origin
|
||||
sourceSize:size
|
||||
toBuffer:buffer->GetMTLBuffer()
|
||||
destinationOffset:dst.offset
|
||||
destinationBytesPerRow:rowSize
|
||||
destinationBytesPerImage:rowSize * src.height];
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
||||
|
||||
@@ -114,6 +114,13 @@ namespace opengl {
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>();
|
||||
// TODO(cwallez@chromium.org): implement using a temporary FBO and ReadPixels
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
||||
|
||||
Reference in New Issue
Block a user