Pass:copy(tally, buffer);

This commit is contained in:
bjorn 2022-06-30 18:51:03 -07:00
parent 8b37b25e54
commit d9d54ce348
2 changed files with 21 additions and 3 deletions

View File

@ -706,7 +706,7 @@ static int l_lovrPassCopy(lua_State* L) {
return 0;
}
Image* image = luax_checktype(L, 2, Image);
Image* image = luax_totype(L, 2, Image);
if (image) {
Texture* texture = luax_checktype(L, 3, Texture);
@ -728,7 +728,7 @@ static int l_lovrPassCopy(lua_State* L) {
return 0;
}
Texture* texture = luax_checktype(L, 2, Texture);
Texture* texture = luax_totype(L, 2, Texture);
if (texture) {
Texture* dst = luax_checktype(L, 3, Texture);
@ -750,7 +750,18 @@ static int l_lovrPassCopy(lua_State* L) {
return 0;
}
return luax_typeerror(L, 2, "Blob, Buffer, Image, or Texture");
Tally* tally = luax_totype(L, 2, Tally);
if (tally) {
Buffer* buffer = luax_checktype(L, 3, Buffer);
uint32_t srcIndex = luax_optu32(L, 4, 0);
uint32_t dstOffset = luax_optu32(L, 5, 0);
uint32_t count = luax_optu32(L, 5, ~0u);
lovrPassCopyTallyToBuffer(pass, tally, buffer, srcIndex, dstOffset, count);
return 0;
}
return luax_typeerror(L, 2, "table, Blob, Buffer, Image, Texture, or Tally");
}
static int l_lovrPassBlit(lua_State* L) {

View File

@ -3843,11 +3843,18 @@ void lovrPassCopyBufferToBuffer(Pass* pass, Buffer* src, Buffer* dst, uint32_t s
}
void lovrPassCopyTallyToBuffer(Pass* pass, Tally* tally, Buffer* buffer, uint32_t srcIndex, uint32_t dstOffset, uint32_t count) {
if (count == ~0u) count = tally->info.count;
lovrCheck(pass->info.type == PASS_TRANSFER, "This function can only be called on a transfer pass");
lovrCheck(!lovrBufferIsTemporary(buffer), "Temporary buffers can not be copied to");
lovrCheck(srcIndex + count <= tally->info.count, "Tally copy range exceeds the number of slots in the Tally");
lovrCheck(dstOffset + count * 4 <= buffer->size, "Buffer copy range goes past the end of the destination Buffer");
lovrCheck(dstOffset % 4 == 0, "Buffer copy offset must be a multiple of 4");
for (uint32_t i = 0; i < count; i++) {
uint32_t index = srcIndex + i;
lovrCheck(tally->masks[index / 64] & (1 << (index % 64)), "Trying to copy Tally slot %d, but it hasn't been marked yet", index + 1);
}
if (tally->info.type == TALLY_TIMER) {
gpu_copy_tally_buffer(pass->stream, tally->gpu, tally->buffer, srcIndex, 0, count, 4);