DiligentGraphics / DiligentCore

A modern cross-platform low-level graphics API
http://diligentgraphics.com/diligent-engine/
Apache License 2.0
616 stars 133 forks source link

Add USAGE_DYNAMIC support to DynamicBuffer #598

Closed edunad closed 1 month ago

edunad commented 1 month ago

Tested using

    Diligent::BufferDesc VBDesc;
    VBDesc.Name = "RawrBox::Buffer:IMGUI::VERTEX";
    VBDesc.BindFlags = Diligent::BIND_VERTEX_BUFFER;
    VBDesc.Size = 1024 * sizeof(ImDrawVert);
    VBDesc.Usage = Diligent::USAGE_DYNAMIC;
    VBDesc.CPUAccessFlags = Diligent::CPU_ACCESS_WRITE;

    Diligent::DynamicBufferCreateInfo dynamicBuff;
    dynamicBuff.Desc = VBDesc;

    _pVB = std::make_unique<Diligent::DynamicBuffer>(renderer.device(), dynamicBuff);

Then resizing it later

uint64_t vtxSize = sizeof(ImDrawVert) * data->TotalVtxCount;
if (vtxSize > _pVB->GetDesc().Size) {
    _pVB->Resize(device, context, sizeof(ImDrawVert) * static_cast<uint64_t>(data->TotalVtxCount), true);
}

Had no issues, the only enforced require is discarding the content on resize, not sure if it's possible to copy it over

TheMostDiligent commented 1 month ago

This is invalid usage of the DynamicBuffer, which is intended to store persistent data of varying size. USAGE_DYNAMIC buffers are intended to keep small amount of temporary data that is only accessed during a single frame.