Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhog committed Feb 25, 2019
2 parents 38e0901 + 56e457b commit e8c27bb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 32 deletions.
4 changes: 3 additions & 1 deletion include/vsg/core/Result.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ namespace vsg
return _message;
}

bool valid() const { return _ptr.valid(); }
bool valid() const noexcept { return _ptr.valid(); }

explicit operator bool() const noexcept { return valid(); }

ref_ptr<T> object() { return _ptr; }

Expand Down
7 changes: 5 additions & 2 deletions include/vsg/vk/ImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ namespace vsg

using Result = vsg::Result<ImageView, VkResult, VK_SUCCESS>;

static Result create(Device* device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator = nullptr);
static Result create(Device* device, const VkImageViewCreateInfo& createInfo, AllocationCallbacks* allocator = nullptr);

static Result create(Device* device, Image* image, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator = nullptr);
static Result create(Device* device, VkImage image, VkImageViewType type, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator = nullptr);

static Result create(Device* device, Image* image, VkImageViewType type, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator = nullptr);

operator VkImageView() const { return _imageView; }

Device* getDevice() { return _device; }
const Device* getDevice() const { return _device; }

void setImage(Image* image) { _image = image; }
Image* getImage() { return _image; }
const Image* getImage() const { return _image; }

Expand Down
2 changes: 1 addition & 1 deletion src/vsg/viewer/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void Window::buildSwapchain(uint32_t width, uint32_t height)

vkBindImageMemory(*_device, *_depthImage, *_depthImageMemory, 0);

_depthImageView = ImageView::create(_device, _depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
_depthImageView = ImageView::create(_device, _depthImage, VK_IMAGE_VIEW_TYPE_2D, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);

// set up framebuffer and associated resources
Swapchain::ImageViews& imageViews = _swapchain->getImageViews();
Expand Down
9 changes: 7 additions & 2 deletions src/vsg/vk/Descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ ImageData vsg::transferImageData(Device* device, CommandPool* commandPool, VkQue
std::cout << "Creating imageStagingBuffer and memorory size = " << imageTotalSize << std::endl;
#endif

VkImageType imageType = data->depth() > 1 ? VK_IMAGE_TYPE_3D : (data->width() > 1 ? VK_IMAGE_TYPE_2D : VK_IMAGE_TYPE_1D);
VkImageViewType imageViewType = data->depth() > 1 ? VK_IMAGE_VIEW_TYPE_3D : (data->width() > 1 ? VK_IMAGE_VIEW_TYPE_2D : VK_IMAGE_VIEW_TYPE_1D);

VkImageCreateInfo imageCreateInfo = {};
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageCreateInfo.imageType = data->depth() > 1 ? VK_IMAGE_TYPE_3D : (data->width() > 1 ? VK_IMAGE_TYPE_2D : VK_IMAGE_TYPE_1D);
imageCreateInfo.imageType = imageType;
imageCreateInfo.extent.width = static_cast<uint32_t>(data->width());
imageCreateInfo.extent.height = static_cast<uint32_t>(data->height());
imageCreateInfo.extent.depth = static_cast<uint32_t>(data->depth());
Expand Down Expand Up @@ -107,7 +110,9 @@ ImageData vsg::transferImageData(Device* device, CommandPool* commandPool, VkQue
imageStagingMemory = 0;

ref_ptr<Sampler> textureSampler = sampler != nullptr ? Sampler::Result(sampler) : Sampler::create(device);
ref_ptr<ImageView> textureImageView = ImageView::create(device, textureImage, data->getFormat(), VK_IMAGE_ASPECT_COLOR_BIT);
ref_ptr<ImageView> textureImageView = ImageView::create(device, textureImage, imageViewType, data->getFormat(), VK_IMAGE_ASPECT_COLOR_BIT);

if (textureImageView) textureImageView->setImage(textureImage);

return ImageData(textureSampler, textureImageView, VK_IMAGE_LAYOUT_UNDEFINED);
}
48 changes: 23 additions & 25 deletions src/vsg/vk/ImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@ ImageView::~ImageView()
}
}

ImageView::Result ImageView::create(Device* device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator)
ImageView::Result ImageView::create(Device* device, const VkImageViewCreateInfo& createInfo, AllocationCallbacks* allocator)
{
VkImageViewCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.image = image;
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
createInfo.format = format;
createInfo.subresourceRange.aspectMask = aspectFlags;
createInfo.subresourceRange.baseMipLevel = 0;
createInfo.subresourceRange.levelCount = 1;
createInfo.subresourceRange.baseArrayLayer = 0;
createInfo.subresourceRange.layerCount = 1;

VkImageView view;
VkResult result = vkCreateImageView(*device, &createInfo, allocator, &view);
if (result == VK_SUCCESS)
Expand All @@ -55,27 +44,36 @@ ImageView::Result ImageView::create(Device* device, VkImage image, VkFormat form
}
}

ImageView::Result ImageView::create(Device* device, Image* image, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator)
ImageView::Result ImageView::create(Device* device, VkImage image, VkImageViewType type, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator)
{
VkImageViewCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.image = *image;
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; // read from image?
createInfo.image = image;
createInfo.viewType = type;
createInfo.format = format;
createInfo.subresourceRange.aspectMask = aspectFlags;
createInfo.subresourceRange.baseMipLevel = 0;
createInfo.subresourceRange.levelCount = 1;
createInfo.subresourceRange.baseArrayLayer = 0;
createInfo.subresourceRange.layerCount = 1;

VkImageView view;
VkResult result = vkCreateImageView(*device, &createInfo, allocator, &view);
if (result == VK_SUCCESS)
{
return Result(new ImageView(view, device, image, allocator));
}
else
{
return Result("Error: Failed to create ImageView.", result);
}
return create(device, createInfo, allocator);
}

ImageView::Result ImageView::create(Device* device, Image* image, VkImageViewType type, VkFormat format, VkImageAspectFlags aspectFlags, AllocationCallbacks* allocator)
{
VkImageViewCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.image = *image;
createInfo.viewType = type; // read from image?
createInfo.format = format; // read from image?
createInfo.subresourceRange.aspectMask = aspectFlags;
createInfo.subresourceRange.baseMipLevel = 0;
createInfo.subresourceRange.levelCount = 1;
createInfo.subresourceRange.baseArrayLayer = 0;
createInfo.subresourceRange.layerCount = 1;

Result result = create(device, createInfo, allocator);
if (result) result.object()->setImage(image);
return result;
}
2 changes: 1 addition & 1 deletion src/vsg/vk/Swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Swapchain::Result Swapchain::create(PhysicalDevice* physicalDevice, Device* devi

for (std::size_t i = 0; i < images.size(); ++i)
{
ref_ptr<ImageView> view = ImageView::create(device, images[i], surfaceFormat.format, VK_IMAGE_ASPECT_COLOR_BIT, allocator);
ref_ptr<ImageView> view = ImageView::create(device, images[i], VK_IMAGE_VIEW_TYPE_2D, surfaceFormat.format, VK_IMAGE_ASPECT_COLOR_BIT, allocator);
if (view) sw->getImageViews().push_back(view);
}

Expand Down

0 comments on commit e8c27bb

Please sign in to comment.