Disable texture upload buffer

This commit is contained in:
Luke Street
2026-04-10 18:18:29 -06:00
parent e39f8c6f72
commit aae772abfe
3 changed files with 54 additions and 33 deletions
+23 -19
View File
@@ -30,8 +30,8 @@ std::vector<std::string> g_debugGroupStack;
std::vector<std::string> 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();
+1
View File
@@ -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
+30 -14
View File
@@ -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<uint8_t> 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()) {