Closed jherico closed 8 months ago
Note in this case I've explicitly set up the builder ctor to require any params without which the resulting object would make no sense. In the case of Images that's the extent and the format, although even the format is defaulted in the ctor. In the case of buffers it's just the size.
Hey @jherico, great ideas!
I agree that we are a little bloated in this area. There is an ongoing initiative to simplify the framework. I think i have a branch with a pattern like this on. Just hard to get in as nearly every place in the framework uses the existing interface so there are a lot of places that need changing.
I agree that a builder pattern could simplify how we create images
I've got a branch that does this partially, built on top of the VMA version update. I'll see if I can whip it into shape and put it up.
Feel free to request my review when your ready, I'll try be prompt
@tomadamatkinson it's #906
The current PR just sets up the new builder ctors without removing the old ones, but it does change a few uses inside the framework.
This sounds similar to what @asuessenbach is working on in #880. We should talk about how this fits into our framework roadmap.
The
Buffer
andImage
classes (along with their corresponding HPP versions) have a few things that might benefit from refactoring.Buffer
classes have some odd choices for the defaults in their constructorsVmaMemoryUsage
but the do defaultVmaAllocationCreateFlags
toVMA_ALLOCATION_CREATE_MAPPED_BIT
as mentioned. This is actually inverted. TheVmaAllocationCreateFlags
should probably NOT have a default while theVmaMemoryUsage
should almost always default toVMA_MEMORY_USAGE_AUTO
.Image
constructors don't expose theVmaAllocationCreateFlags
but are already unwieldy in terms of the number of argumentsVMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
flag automatically?I propose a change.
First, create a shared base class for anything that uses
VmaAllocation
for storage. Since VMA doesn't have a C++ set of bindings, the base class could be shared by both the C++ and C classes (the class would include a template argument to specify whether it derived fromHPPVulkanResource
orVulkanResource
). All of the VMA specific members could move into this base class, including all the mapping, unmapping and flushing related code.Second, fixing the
Buffer
constructor to reverse the arguments to give one a new default and take the other away would create a large burden for a single change, and adding any arguments to theImage
ctors would probably be a mistake.As an alternative, I suggest that a builder pattern be added. Instead a long list of ctor arguments, a set of reasonable defaults inside a builder object could be created, and then customized as much or as little as desired in use cases. The
Image
andBuffer
classes could then accept as their primary constructor a builder object.Again, a common base class could be utilized, so that you'd have builder functionality that was VMA specific centralized, looking something like this
And then for each subclass you'd have an individual builder like this for for example for the
HPPImage
The main
HPPImage
constructor could then look likeHPPImage(HPPDevice &device, HPPImageBuilder const & builder);
A given use case for the object might change from this...
to this
In this case I've included a
core::HPPImageBuilder
ctor that accepts anExtent2D
and automatically extends it to theExtent3D
inside the builder class.