From aae772abfe667e24ebe8107073dadd457fe8d70f Mon Sep 17 00:00:00 2001 From: Luke Street Date: Fri, 10 Apr 2026 18:18:29 -0600 Subject: [PATCH] Disable texture upload buffer --- lib/gfx/common.cpp | 42 +++++++++++++++++++++++------------------- lib/gfx/common.hpp | 1 + lib/gfx/texture.cpp | 44 ++++++++++++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/lib/gfx/common.cpp b/lib/gfx/common.cpp index 72e2f20..a5a160c 100644 --- a/lib/gfx/common.cpp +++ b/lib/gfx/common.cpp @@ -30,8 +30,8 @@ std::vector g_debugGroupStack; std::vector g_debugMarkers; #endif -constexpr uint64_t StagingBufferSize = - UniformBufferSize + VertexBufferSize + IndexBufferSize + StorageBufferSize + TextureUploadSize; +constexpr uint64_t StagingBufferSize = UniformBufferSize + VertexBufferSize + IndexBufferSize + StorageBufferSize + + (UseTextureBuffer ? TextureUploadSize : 0); struct ShaderDrawCommand { ShaderType type; @@ -528,7 +528,9 @@ void begin_frame() { mapBuffer(g_uniforms, UniformBufferSize); mapBuffer(g_indices, IndexBufferSize); mapBuffer(g_storage, StorageBufferSize); - mapBuffer(g_textureUpload, TextureUploadSize); + if constexpr (UseTextureBuffer) { + mapBuffer(g_textureUpload, TextureUploadSize); + } g_stats.drawCallCount = 0; g_stats.mergedDrawCallCount = 0; @@ -562,23 +564,25 @@ void end_frame(const wgpu::CommandEncoder& cmd) { g_stats.lastUniformSize = writeBuffer(g_uniforms, g_uniformBuffer, UniformBufferSize, "Uniform"); g_stats.lastIndexSize = writeBuffer(g_indices, g_indexBuffer, IndexBufferSize, "Index"); g_stats.lastStorageSize = writeBuffer(g_storage, g_storageBuffer, StorageBufferSize, "Storage"); - g_stats.lastTextureUploadSize = g_textureUpload.size(); - { - // Perform texture copies - for (const auto& item : g_textureUploads) { - const wgpu::TexelCopyBufferInfo buf{ - .layout = - wgpu::TexelCopyBufferLayout{ - .offset = item.layout.offset + bufferOffset, - .bytesPerRow = AURORA_ALIGN(item.layout.bytesPerRow, 256), - .rowsPerImage = item.layout.rowsPerImage, - }, - .buffer = g_stagingBuffers[currentStagingBuffer], - }; - cmd.CopyBufferToTexture(&buf, &item.tex, &item.size); + if constexpr (UseTextureBuffer) { + g_stats.lastTextureUploadSize = g_textureUpload.size(); + { + // Perform texture copies + for (const auto& item : g_textureUploads) { + const wgpu::TexelCopyBufferInfo buf{ + .layout = + wgpu::TexelCopyBufferLayout{ + .offset = item.layout.offset + bufferOffset, + .bytesPerRow = AURORA_ALIGN(item.layout.bytesPerRow, 256), + .rowsPerImage = item.layout.rowsPerImage, + }, + .buffer = g_stagingBuffers[currentStagingBuffer], + }; + cmd.CopyBufferToTexture(&buf, &item.tex, &item.size); + } + g_textureUploads.clear(); + g_textureUpload.release(); } - g_textureUploads.clear(); - g_textureUpload.release(); } currentStagingBuffer = (currentStagingBuffer + 1) % g_stagingBuffers.size(); map_staging_buffer(); diff --git a/lib/gfx/common.hpp b/lib/gfx/common.hpp index a10f975..c339f47 100644 --- a/lib/gfx/common.hpp +++ b/lib/gfx/common.hpp @@ -162,6 +162,7 @@ private: } // namespace aurora namespace aurora::gfx { +inline constexpr bool UseTextureBuffer = false; inline constexpr uint64_t UniformBufferSize = 25165824; // 24mb inline constexpr uint64_t VertexBufferSize = 3145728; // 3mb inline constexpr uint64_t IndexBufferSize = 1048576; // 1mb diff --git a/lib/gfx/texture.cpp b/lib/gfx/texture.cpp index 8336e39..aff4824 100644 --- a/lib/gfx/texture.cpp +++ b/lib/gfx/texture.cpp @@ -98,13 +98,21 @@ TextureHandle new_static_texture_2d(uint32_t width, uint32_t height, uint32_t mi .texture = ref.texture, .mipLevel = mip, }; - const auto range = push_texture_data(data.data() + offset, dataSize, bytesPerRow, heightBlocks); - const wgpu::TexelCopyBufferLayout dataLayout{ - .offset = range.offset, - .bytesPerRow = bytesPerRow, - .rowsPerImage = heightBlocks, - }; - g_textureUploads.emplace_back(dataLayout, std::move(dstView), physicalSize); + if constexpr (UseTextureBuffer) { + const auto range = push_texture_data(data.data() + offset, dataSize, bytesPerRow, heightBlocks); + const wgpu::TexelCopyBufferLayout dataLayout{ + .offset = range.offset, + .bytesPerRow = bytesPerRow, + .rowsPerImage = heightBlocks, + }; + g_textureUploads.emplace_back(dataLayout, std::move(dstView), physicalSize); + } else { + const wgpu::TexelCopyBufferLayout dataLayout{ + .bytesPerRow = bytesPerRow, + .rowsPerImage = heightBlocks, + }; + g_queue.WriteTexture(&dstView, data.data() + offset, dataSize, &dataLayout, &physicalSize); + } offset += dataSize; } if (data.size() != UINT32_MAX && offset < data.size()) { @@ -286,13 +294,21 @@ void write_texture(const TextureRef& ref, ArrayRef data) noexcept { .texture = ref.texture, .mipLevel = mip, }; - const auto range = push_texture_data(data.data() + offset, dataSize, bytesPerRow, heightBlocks); - const wgpu::TexelCopyBufferLayout dataLayout{ - .offset = range.offset, - .bytesPerRow = bytesPerRow, - .rowsPerImage = heightBlocks, - }; - g_textureUploads.emplace_back(dataLayout, std::move(dstView), physicalSize); + if constexpr (UseTextureBuffer) { + const auto range = push_texture_data(data.data() + offset, dataSize, bytesPerRow, heightBlocks); + const wgpu::TexelCopyBufferLayout dataLayout{ + .offset = range.offset, + .bytesPerRow = bytesPerRow, + .rowsPerImage = heightBlocks, + }; + g_textureUploads.emplace_back(dataLayout, std::move(dstView), physicalSize); + } else { + const wgpu::TexelCopyBufferLayout dataLayout{ + .bytesPerRow = bytesPerRow, + .rowsPerImage = heightBlocks, + }; + g_queue.WriteTexture(&dstView, data.data() + offset, dataSize, &dataLayout, &physicalSize); + } offset += dataSize; } if (data.size() != UINT32_MAX && offset < data.size()) {