#define GPU_MAX_PER_FRAME_UPLOAD_SIZE ((uint64_t)(16 << 20)) static uint64_t GpuPrepareCopySrc(uint64_t copySize) { Game->stagingBufferAt = ALIGN_UP(Game->stagingBufferAt, Rhi_GetOptimalBufferCopyOffsetAlignment()); ASSERT(Game->stagingBufferAt + copySize <= GPU_MAX_PER_FRAME_UPLOAD_SIZE); Rhi_BufferMarkWritten(Game->stagingBuffer, Game->stagingBufferAt, copySize); uint64_t ret = Game->stagingBufferAt; return ret; } static uint8_t* GpuCmdCopyBuffer(rhi_cmdlist cmd, rhi_buffer dst, uint64_t dstOffset, uint64_t copySize) { uint64_t offset = GpuPrepareCopySrc(copySize); Rhi_CmdCopyBuffer(cmd, dst, dstOffset, Game->stagingBuffer, offset, copySize); Game->stagingBufferAt += copySize; return Rhi_MapBuffer(Game->stagingBuffer) + offset; } static uint8_t* GpuCmdCopyTexture(rhi_cmdlist cmd, rhi_texture dst, uint64_t copySize) { uint64_t offset = GpuPrepareCopySrc(copySize); Rhi_CmdCopyTexture(cmd, dst, Game->stagingBuffer, offset, copySize); Game->stagingBufferAt += copySize; return Rhi_MapBuffer(Game->stagingBuffer) + offset; } static uint8_t* GpuCmdCopyStaticVertices(rhi_cmdlist cmd, uint32_t copySize, uint64_t* outBufferOffset) { *outBufferOffset = Game->staticVertexBufferAt; uint8_t* ret = GpuCmdCopyBuffer(cmd, Game->staticVertexBuffer, Game->staticVertexBufferAt, copySize); Game->staticVertexBufferAt += copySize; return ret; } static uint8_t* GpuCmdCopyStaticIndices(rhi_cmdlist cmd, uint32_t copySize, uint64_t* outBufferOffset) { *outBufferOffset = Game->staticIndexBufferAt; uint8_t* ret = GpuCmdCopyBuffer(cmd, Game->staticIndexBuffer, Game->staticIndexBufferAt, copySize); Game->staticIndexBufferAt += copySize; return ret; } static void GpuCmdBindStaticMeshVertexBuffer(alloc* Scratch, rhi_cmdlist cmd, uint64_t offset) { Rhi_CmdBindVertexBuffers(Scratch, cmd, 0, &Game->staticVertexBuffer, 1, &offset); } static void GpuCmdBindStaticMeshIndexBuffer(rhi_cmdlist cmd, uint64_t offset) { Rhi_CmdBindIndexBuffer(cmd, Game->staticIndexBuffer, offset); }