Skip to content

Allocate and upload data to the GPU - #3510

Merged
IntegratedQuantum merged 8 commits into
PixelGuys:masterfrom
IntegratedQuantum:vma
Aug 15, 2026
Merged

IntegratedQuantum merged 8 commits into
PixelGuys:masterfrom
IntegratedQuantum:vma

Conversation

@IntegratedQuantum

@IntegratedQuantum IntegratedQuantum commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Upload happens using a staging buffer on a separate command buffer which gets submitted (and synchronized) before the other command buffers.

I also had to add a garbage collection thing for triple buffering, and I also hardcoded the number of frames to 2, any more than that and we have too much latency anyways.

progress towards #102

Comment thread src/graphics/vulkan.zig Outdated
.flags = 0,
.physicalDevice = physicalDevice,
.device = device,
.preferredLargeHeapBlockSize = 128 << 9, // TODO: What does this do?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this blizzard way of saying 65536?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my extended research, I think this controls the size of actual allocation (size of object rounded up) when allocation crosses the threshold that classifies it as large allocation.
Or more precisely, the overshoot of that allocation when allocating above 1GB, eg. If I alloc 1.1GB, with defaults it gets rounded to 1.25GB (block of 0.25GB)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why allocate more than needed?

@Argmaster Argmaster Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For same reason GPA does it. I have no idea.
I think this eases the consequences of deallocaitng and allocating again with just a bit different size (or reallocating or whatever).
If you perfect fit it, you can only use it for identical or smaller object.
And allocation calls are bad too, so I would assume they preallocate blocks instead of just calling driver for every object.

@IntegratedQuantum
IntegratedQuantum merged commit e1b638c into PixelGuys:master Aug 15, 2026
1 check passed
@IntegratedQuantum
IntegratedQuantum deleted the vma branch August 15, 2026 14:23
IntegratedQuantum added a commit that referenced this pull request Aug 16, 2026
This required several more changes to get working:
- support for push constants (I decided to only make the size
configurable, we don't need multiple with offset for now, and as far as
I can tell there is not going to be much of a performance impact from
this, and from always specifying all stage flags)
- support for vertex/index buffers (this was easy after #3510)
- Configuration of input assembly stage (fixing two TODOs from the code)
- To make it easier to introduce the new configs, I decided to finally
use a struct parameter for pipeline creation which holds all the vulkan
stuff
- empty star VAO is not easily convertible to vulkan (vulkan does not
like empty stuff at all)
- some small fixes

Apart from the push constant config, everything else takes the exact
same lines of code as the previous OpenGL config. However a most of the
drawing logic (uniforms, bindings, draw command) is currently
duplicated. But I don't think it's worth creating a unified API for
these things, as we are going to get rid of OpenGL once the vulkan
rewrite is complete.

progress towards #102
<img width="2377" height="857" alt="Screenshot at 2026-08-16 09-32-41"
src="https://github.com/user-attachments/assets/a760176d-f273-4d77-b7a0-e0d4909a6f58"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants