Skip to content

Commit

Permalink
Merge branch 'master' into VulkanSceneGraph-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Aug 30, 2023
2 parents 6c12dcd + f941cea commit 401d877
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 56 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(vsg
LANGUAGES CXX
)
set(VSG_SOVERSION 14)
SET(VSG_RELEASE_CANDIDATE 3)
SET(VSG_RELEASE_CANDIDATE 4)
set(Vulkan_MIN_VERSION 1.1.70.0)

set(VSG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Root source directory of VulkanSceneGraph.")
Expand Down
17 changes: 2 additions & 15 deletions include/vsg/state/ImageInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,13 @@ namespace vsg
ImageInfo() :
imageLayout(VK_IMAGE_LAYOUT_UNDEFINED) {}

ImageInfo(ref_ptr<Sampler> in_sampler, ref_ptr<ImageView> in_imageView, VkImageLayout in_imageLayout = VK_IMAGE_LAYOUT_UNDEFINED) :
sampler(in_sampler),
imageView(in_imageView),
imageLayout(in_imageLayout)
{
computeNumMipMapLevels();
}
ImageInfo(ref_ptr<Sampler> in_sampler, ref_ptr<ImageView> in_imageView, VkImageLayout in_imageLayout = VK_IMAGE_LAYOUT_UNDEFINED);

// Convenience constructor that creates a vsg::ImageView and vsg::Image to represent the data on the GPU.
template<typename T>
ImageInfo(ref_ptr<Sampler> in_sampler, ref_ptr<T> in_data, VkImageLayout in_imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) :
sampler(in_sampler),
imageLayout(in_imageLayout)
ImageInfo(in_sampler, ImageView::create(Image::create(in_data)), in_imageLayout)
{
auto image = Image::create(in_data);
image->usage |= (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);

imageView = ImageView::create(image);

computeNumMipMapLevels();
}

ImageInfo(const ImageInfo&) = delete;
Expand Down
35 changes: 2 additions & 33 deletions include/vsg/vk/ResourceRequirements.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,8 @@ namespace vsg
void apply(const BindVertexBuffers& bvb) override;
void apply(const BindIndexBuffer& bib) override;

inline void apply(ref_ptr<BufferInfo> bufferInfo)
{
if (bufferInfo && bufferInfo->data && bufferInfo->data->dynamic())
{
if (bufferInfo->data->properties.dataVariance == DYNAMIC_DATA)
{
requirements.earlyDynamicData.bufferInfos.push_back(bufferInfo);
}
else // DYNAMIC_DATA_TRANSFER_AFTER_RECORD)
{
requirements.lateDynamicData.bufferInfos.push_back(bufferInfo);
}
}
}

inline void apply(ref_ptr<ImageInfo> imageInfo)
{
if (imageInfo && imageInfo->imageView && imageInfo->imageView->image)
{
auto& data = imageInfo->imageView->image->data;
if (data && data->dynamic())
{
if (data->properties.dataVariance == DYNAMIC_DATA)
{
requirements.earlyDynamicData.imageInfos.push_back(imageInfo);
}
else // DYNAMIC_DATA_TRANSFER_AFTER_RECORD)
{
requirements.lateDynamicData.imageInfos.push_back(imageInfo);
}
}
}
}
virtual void apply(ref_ptr<BufferInfo> bufferInfo);
virtual void apply(ref_ptr<ImageInfo> imageInfo);

protected:
uint32_t _numResourceHintsAbove = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/vsg/core/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ void Data::write(Output& output) const

Data::MipmapOffsets Data::computeMipmapOffsets() const
{
if (properties.maxNumMipmaps <= 1) return {};

uint32_t numMipmaps = properties.maxNumMipmaps;

MipmapOffsets offsets;
if (numMipmaps == 0) return offsets;

std::size_t w = width();
std::size_t h = height();
Expand Down
4 changes: 2 additions & 2 deletions src/vsg/state/DescriptorBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
</editor-fold> */

#include <vsg/core/compare.h>
#include <vsg/core/Exception.h>
#include <vsg/core/compare.h>
#include <vsg/io/Logger.h>
#include <vsg/io/Options.h>
#include <vsg/state/DescriptorBuffer.h>
Expand Down Expand Up @@ -179,7 +179,7 @@ void DescriptorBuffer::compile(Context& context)
{
auto memRequirements = bufferInfo->buffer->getMemoryRequirements(deviceID);
VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
auto [deviceMemory, offset] = context.deviceMemoryBufferPools->reserveMemory(memRequirements,flags);
auto [deviceMemory, offset] = context.deviceMemoryBufferPools->reserveMemory(memRequirements, flags);
if (deviceMemory)
{
bufferInfo->buffer->bind(deviceMemory, offset);
Expand Down
7 changes: 5 additions & 2 deletions src/vsg/state/DescriptorImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ void DescriptorImage::compile(Context& context)

for (auto& imageInfo : imageInfoList)
{
imageInfo->computeNumMipMapLevels();

if (imageInfo->sampler) imageInfo->sampler->compile(context);
if (imageInfo->imageView)
{
if (imageInfo->imageView->image->mipLevels == 0)
{
imageInfo->computeNumMipMapLevels();
}

auto& imageView = *imageInfo->imageView;
imageView.compile(context);

Expand Down
2 changes: 2 additions & 0 deletions src/vsg/state/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Image::Image(ref_ptr<Data> in_data) :
format = static_cast<VkFormat>(format + 7);
else if (format >= VK_FORMAT_R32G32B32_UINT && format <= VK_FORMAT_R32G32B32_SFLOAT)
format = static_cast<VkFormat>(format + 3);

usage = (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/vsg/state/ImageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
</editor-fold> */

#include <vsg/core/compare.h>
#include <vsg/io/Logger.h>
#include <vsg/io/Options.h>
#include <vsg/state/ImageInfo.h>

Expand Down Expand Up @@ -120,6 +121,13 @@ uint32_t vsg::computeNumMipMapLevels(const Data* data, const Sampler* sampler)
return mipLevels;
}

ImageInfo::ImageInfo(ref_ptr<Sampler> in_sampler, ref_ptr<ImageView> in_imageView, VkImageLayout in_imageLayout) :
sampler(in_sampler),
imageView(in_imageView),
imageLayout(in_imageLayout)
{
}

ImageInfo::~ImageInfo()
{
}
Expand Down Expand Up @@ -153,7 +161,11 @@ void ImageInfo::computeNumMipMapLevels()
const auto& properties = data->properties;
if (properties.blockWidth > 1 || properties.blockHeight > 1 || properties.blockDepth > 1)
{
sampler->maxLod = 0.0f;
if (sampler->maxLod != 0.0f && sampler->maxLod != VK_LOD_CLAMP_NONE)
{
warn("ImageInfo::computeNumMipMapLevels() cannot enable generated mipmaps for vsg::Image, but Sampler::maxLod is not zero or VK_LOD_CLAMP_NONE, sampler->maxLod = ", sampler->maxLod);
}

mipLevels = 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/utils/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ref_ptr<StateGroup> Builder::createStateGroup(const StateInfo& stateInfo)
if (si.two_sided) rs.cullMode = VK_CULL_MODE_NONE;
}

void apply(InputAssemblyState& ias)override
void apply(InputAssemblyState& ias) override
{
if (si.wireframe) ias.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
}
Expand Down
35 changes: 35 additions & 0 deletions src/vsg/vk/ResourceRequirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,38 @@ void CollectResourceRequirements::apply(const BindIndexBuffer& bib)
{
apply(bib.indices);
}

void CollectResourceRequirements::apply(ref_ptr<BufferInfo> bufferInfo)
{
if (bufferInfo && bufferInfo->data && bufferInfo->data->dynamic())
{
if (bufferInfo->data->properties.dataVariance == DYNAMIC_DATA)
{
requirements.earlyDynamicData.bufferInfos.push_back(bufferInfo);
}
else // DYNAMIC_DATA_TRANSFER_AFTER_RECORD)
{
requirements.lateDynamicData.bufferInfos.push_back(bufferInfo);
}
}
}

void CollectResourceRequirements::apply(ref_ptr<ImageInfo> imageInfo)
{
if (imageInfo && imageInfo->imageView && imageInfo->imageView->image)
{
// check for dynamic data
auto& data = imageInfo->imageView->image->data;
if (data && data->dynamic())
{
if (data->properties.dataVariance == DYNAMIC_DATA)
{
requirements.earlyDynamicData.imageInfos.push_back(imageInfo);
}
else // DYNAMIC_DATA_TRANSFER_AFTER_RECORD)
{
requirements.lateDynamicData.imageInfos.push_back(imageInfo);
}
}
}
}

0 comments on commit 401d877

Please sign in to comment.