Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.10)

project(vsg
VERSION 1.1.13
VERSION 1.1.14
DESCRIPTION "VulkanSceneGraph library"
LANGUAGES CXX
)
set(VSG_SOVERSION 15)
set(VSG_SOVERSION 16)
SET(VSG_RELEASE_CANDIDATE 0)
set(Vulkan_MIN_VERSION 1.1.70.0)

Expand Down
2 changes: 1 addition & 1 deletion include/vsg/app/CompileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace vsg
Slots maxSlots;
bool containsPagedLOD = false;
ResourceRequirements::Views views;
ResourceRequirements::DynamicData dynamicData;
DynamicData dynamicData;

explicit operator bool() const noexcept { return result == VK_SUCCESS; }

Expand Down
2 changes: 1 addition & 1 deletion include/vsg/app/TransferTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace vsg

ref_ptr<Device> device;

void assign(const ResourceRequirements::DynamicData& dynamicData);
void assign(const DynamicData& dynamicData);
void assign(const BufferInfoList& bufferInfoList);
void assign(const ImageInfoList& imageInfoList);

Expand Down
2 changes: 1 addition & 1 deletion include/vsg/app/Viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace vsg
/// pass the Events into any registered EventHandlers
virtual void handleEvents();

virtual void compile(ref_ptr<ResourceHints> hints = {});
virtual CompileResult compile(ref_ptr<ResourceHints> hints = {});

virtual bool acquireNextFrame();

Expand Down
3 changes: 3 additions & 0 deletions include/vsg/state/BufferInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace vsg

void release();

/// compute size of associated data
VkDeviceSize computeDataSize() const;

/// Copy data to the VkBuffer(s) for all Devices associated with vsg::Buffer
/// Requires associated buffer memory to be host visible, for non host visible buffers you must use a staging buffer
void copyDataToBuffer();
Expand Down
5 changes: 3 additions & 2 deletions include/vsg/state/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ namespace vsg
/// return true if the Image's data has been modified and should be copied to the buffer, updating the device specific ModifiedCount to the Data's ModifiedCount.
bool syncModifiedCount(uint32_t deviceID) { return data && data->getModifiedCount(_vulkanData[deviceID].copiedModifiedCount); }

virtual void compile(Device* device);
virtual void compile(Context& context);
virtual VkResult compile(Device* device);
virtual VkResult compile(Context& context);
virtual VkResult compile(MemoryBufferPools& memoryBufferPools);

protected:
virtual ~Image();
Expand Down
3 changes: 3 additions & 0 deletions include/vsg/state/ImageInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace vsg
ref_ptr<ImageView> imageView;
VkImageLayout imageLayout = VK_IMAGE_LAYOUT_UNDEFINED;

/// compute size of associated data
VkDeviceSize computeDataSize() const;

/// return true if the ImageInfo's data has been modified and should be copied to the buffer
bool requiresCopy(uint32_t deviceID) const
{
Expand Down
31 changes: 31 additions & 0 deletions include/vsg/state/ResourceHints.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
</editor-fold> */

#include <vsg/maths/vec2.h>
#include <vsg/state/BufferInfo.h>
#include <vsg/state/ImageInfo.h>
#include <vsg/vk/DescriptorPool.h>

namespace vsg
Expand All @@ -30,6 +32,26 @@ namespace vsg
DYNAMIC_VIEWPORTSTATE = 1 << 1
};

struct DynamicData
{
BufferInfoList bufferInfos;
ImageInfoList imageInfos;

explicit operator bool() const noexcept { return !bufferInfos.empty() || !imageInfos.empty(); }

void clear()
{
bufferInfos.clear();
imageInfos.clear();
}

void add(const DynamicData& dd)
{
bufferInfos.insert(bufferInfos.end(), dd.bufferInfos.begin(), dd.bufferInfos.end());
imageInfos.insert(imageInfos.end(), dd.imageInfos.begin(), dd.imageInfos.end());
}
};

/// ResourceHints provides settings that help preallocation of Vulkan resources and memory.
class VSG_DECLSPEC ResourceHints : public Inherit<Object, ResourceHints>
{
Expand All @@ -56,6 +78,15 @@ namespace vsg
DataTransferHint dataTransferHint = COMPILE_TRAVERSAL_USE_TRANSFER_TASK;
uint32_t viewportStateHint = DYNAMIC_VIEWPORTSTATE;

DynamicData dynamicData;

bool containsPagedLOD = false;

/// Ratio of available device memory that can be allocated.
/// Ratios less than 1.0 require VK_EXT_memory_budget extension to be supported.
/// Ratio of 1.0 (or greater) will switch off checks for available memory and keep allocating till Vulkan memory allocations fail.
double allocatedMemoryLimit = 1.0;

public:
void read(Input& input) override;
void write(Output& output) const override;
Expand Down
2 changes: 1 addition & 1 deletion include/vsg/vk/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace vsg
ref_ptr<CommandBuffer> getOrCreateCommandBuffer();

/// reserve resources that may be needed during compile traversal.
void reserve(const ResourceRequirements& requirements);
VkResult reserve(ResourceRequirements& requirements);

ref_ptr<DescriptorSet::Implementation> allocateDescriptorSet(DescriptorSetLayout* descriptorSetLayout);

Expand Down
3 changes: 3 additions & 0 deletions include/vsg/vk/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ namespace vsg
/// return true if Device was created with specified extension
bool supportsDeviceExtension(const char* extensionName) const;

/// return the amount of memory available in deviceMemoryBufferPools and allocatable on device
VkDeviceSize availableMemory(bool includeMemoryPools = true) const;

// provide observer_ptr to memory buffer and descriptor pools so that these can be accessed when required
observer_ptr<MemoryBufferPools> deviceMemoryBufferPools;
observer_ptr<MemoryBufferPools> stagingMemoryBufferPools;
Expand Down
10 changes: 10 additions & 0 deletions include/vsg/vk/MemoryBufferPools.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ namespace vsg
VkDeviceSize minimumBufferSize = 16 * 1024 * 1024;
VkDeviceSize minimumDeviceMemorySize = 16 * 1024 * 1024;

/// Ratio of available device memory that can be allocated.
/// Ratios less than 1.0 require VK_EXT_memory_budget extension to be supported.
/// Ratio of 1.0 (or greater) will switch off checks for available memory and keep allocating till Vulkan memory allocations fail.
double allocatedMemoryLimit = 1.0;

/// throw vsg::Exception when reserveMemory() fails to allocated memory on device.
bool throwOutOfDeviceMemoryException = true;

VkDeviceSize computeMemoryTotalAvailable() const;
VkDeviceSize computeMemoryTotalReserved() const;
VkDeviceSize computeBufferTotalAvailable() const;
Expand All @@ -44,6 +52,8 @@ namespace vsg
using DeviceMemoryOffset = std::pair<ref_ptr<DeviceMemory>, VkDeviceSize>;
DeviceMemoryOffset reserveMemory(VkMemoryRequirements memRequirements, VkMemoryPropertyFlags memoryProperties, void* pNextAllocInfo = nullptr);

VkResult reserve(ResourceRequirements& requirements);

protected:
mutable std::mutex _mutex;

Expand Down
40 changes: 17 additions & 23 deletions include/vsg/vk/ResourceRequirements.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,6 @@ namespace vsg
using Views = std::map<const View*, ViewDetails>;
using ViewDetailStack = std::stack<ViewDetails>;

struct DynamicData
{
BufferInfoList bufferInfos;
ImageInfoList imageInfos;

explicit operator bool() const noexcept { return !bufferInfos.empty() || !imageInfos.empty(); }

void clear()
{
bufferInfos.clear();
imageInfos.clear();
}

void add(const DynamicData& dd)
{
bufferInfos.insert(bufferInfos.end(), dd.bufferInfos.begin(), dd.bufferInfos.end());
imageInfos.insert(imageInfos.end(), dd.imageInfos.begin(), dd.imageInfos.end());
}
};

DynamicData dynamicData;

Descriptors descriptors;
Expand All @@ -92,6 +72,17 @@ namespace vsg
uint32_t externalNumDescriptorSets = 0;
bool containsPagedLOD = false;

struct BufferProperties
{
VkBufferUsageFlags usageFlags = 0;
VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE;

bool operator<(const BufferProperties& rhs) const { return (usageFlags < rhs.usageFlags) || ((usageFlags == rhs.usageFlags) && (sharingMode < rhs.sharingMode)); }
};

std::map<BufferProperties, std::set<ref_ptr<BufferInfo>>> bufferInfos;
std::set<ref_ptr<ImageInfo>> imageInfos;

VkDeviceSize minimumBufferSize = 16 * 1024 * 1024;
VkDeviceSize minimumDeviceMemorySize = 16 * 1024 * 1024;

Expand Down Expand Up @@ -141,13 +132,16 @@ namespace vsg
void apply(const VertexIndexDraw& vid) override;
void apply(const BindVertexBuffers& bvb) override;
void apply(const BindIndexBuffer& bib) override;
void apply(const InstanceNode& in) override;
void apply(const InstanceDraw& id) override;
void apply(const InstanceDrawIndexed& idi) override;

virtual void apply(ref_ptr<BufferInfo> bufferInfo);
using BufferProperties = ResourceRequirements::BufferProperties;

virtual void apply(ref_ptr<BufferInfo> bufferInfo, BufferProperties bufferProperties);
virtual void apply(ref_ptr<ImageInfo> imageInfo);

protected:
uint32_t _numResourceHintsAbove = 0;

bool registerDescriptor(const Descriptor& descriptor);
};
VSG_type_name(vsg::CollectResourceRequirements);
Expand Down
Loading
Loading