Commit 9fbaf697 by Alexis Hetu Committed by Alexis Hétu

VkImageView initial implementation

Added VkImageView object. Added "clear" function to illustrate the link between VkFramebuffer attachments, VkImageView and VkImage, along with the minimal set of class members to allows the function arguments to be used properly. Bug b/119620767 b/119621736 Change-Id: I0e7e6017979960bacbdf888d632c83edda3483cf Reviewed-on: https://swiftshader-review.googlesource.com/c/22668Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 09056de4
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "VkFence.hpp" #include "VkFence.hpp"
#include "VkFramebuffer.hpp" #include "VkFramebuffer.hpp"
#include "VkImage.hpp" #include "VkImage.hpp"
#include "VkImageView.hpp"
#include "VkInstance.hpp" #include "VkInstance.hpp"
#include "VkPipeline.hpp" #include "VkPipeline.hpp"
#include "VkPipelineCache.hpp" #include "VkPipelineCache.hpp"
......
...@@ -13,21 +13,40 @@ ...@@ -13,21 +13,40 @@
// limitations under the License. // limitations under the License.
#include "VkFramebuffer.hpp" #include "VkFramebuffer.hpp"
#include "VkImageView.hpp"
#include <memory.h>
namespace vk namespace vk
{ {
Framebuffer::Framebuffer(const VkFramebufferCreateInfo* pCreateInfo, void* mem) Framebuffer::Framebuffer(const VkFramebufferCreateInfo* pCreateInfo, void* mem) :
attachmentCount(pCreateInfo->attachmentCount),
attachments(reinterpret_cast<ImageView**>(mem))
{ {
for(uint32_t i = 0; i < attachmentCount; i++)
{
attachments[i] = Cast(pCreateInfo->pAttachments[i]);
}
} }
void Framebuffer::destroy(const VkAllocationCallbacks* pAllocator) void Framebuffer::destroy(const VkAllocationCallbacks* pAllocator)
{ {
vk::deallocate(attachments, pAllocator);
}
void Framebuffer::clear(uint32_t clearValueCount, const VkClearValue* pClearValues, const VkRect2D& renderArea)
{
ASSERT(clearValueCount >= attachmentCount);
for(uint32_t i = 0; i < attachmentCount; i++)
{
attachments[i]->clear(pClearValues[i], renderArea);
}
} }
size_t Framebuffer::ComputeRequiredAllocationSize(const VkFramebufferCreateInfo* pCreateInfo) size_t Framebuffer::ComputeRequiredAllocationSize(const VkFramebufferCreateInfo* pCreateInfo)
{ {
return 0; return pCreateInfo->attachmentCount * sizeof(void*);
} }
} // namespace vk } // namespace vk
\ No newline at end of file
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
namespace vk namespace vk
{ {
class ImageView;
class Framebuffer : public Object<Framebuffer, VkFramebuffer> class Framebuffer : public Object<Framebuffer, VkFramebuffer>
{ {
public: public:
...@@ -27,9 +29,13 @@ public: ...@@ -27,9 +29,13 @@ public:
~Framebuffer() = delete; ~Framebuffer() = delete;
void destroy(const VkAllocationCallbacks* pAllocator); void destroy(const VkAllocationCallbacks* pAllocator);
void clear(uint32_t clearValueCount, const VkClearValue* pClearValues, const VkRect2D& renderArea);
static size_t ComputeRequiredAllocationSize(const VkFramebufferCreateInfo* pCreateInfo); static size_t ComputeRequiredAllocationSize(const VkFramebufferCreateInfo* pCreateInfo);
private: private:
uint32_t attachmentCount = 0;
ImageView** attachments = nullptr;
}; };
static inline Framebuffer* Cast(VkFramebuffer object) static inline Framebuffer* Cast(VkFramebuffer object)
......
...@@ -221,4 +221,18 @@ VkDeviceSize Image::getStorageSize() const ...@@ -221,4 +221,18 @@ VkDeviceSize Image::getStorageSize() const
return extent.depth * slicePitchBytes(); return extent.depth * slicePitchBytes();
} }
void Image::clear(const VkClearValue& clearValue, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange)
{
if((subresourceRange.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) ||
(subresourceRange.baseMipLevel != 0) ||
(subresourceRange.levelCount != 1) ||
(subresourceRange.baseArrayLayer != 0) ||
(subresourceRange.layerCount != 1))
{
UNIMPLEMENTED();
}
UNIMPLEMENTED();
}
} // namespace vk } // namespace vk
\ No newline at end of file
...@@ -41,6 +41,11 @@ public: ...@@ -41,6 +41,11 @@ public:
void copyTo(VkBuffer dstBuffer, const VkBufferImageCopy& pRegion); void copyTo(VkBuffer dstBuffer, const VkBufferImageCopy& pRegion);
void copyFrom(VkBuffer srcBuffer, const VkBufferImageCopy& pRegion); void copyFrom(VkBuffer srcBuffer, const VkBufferImageCopy& pRegion);
void clear(const VkClearValue& clearValue, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange);
VkImageType getImageType() const { return imageType; }
VkFormat getFormat() const { return format; }
private: private:
void* getTexelPointer(const VkOffset3D& offset) const; void* getTexelPointer(const VkOffset3D& offset) const;
VkDeviceSize texelOffsetBytesInStorage(const VkOffset3D& offset) const; VkDeviceSize texelOffsetBytesInStorage(const VkOffset3D& offset) const;
......
// Copyright 2018 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "VkImageView.hpp"
#include "VkImage.hpp"
namespace vk
{
ImageView::ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem) :
image(pCreateInfo->image), viewType(pCreateInfo->viewType), format(pCreateInfo->format),
components(pCreateInfo->components), subresourceRange(pCreateInfo->subresourceRange)
{
}
size_t ImageView::ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo)
{
return 0;
}
void ImageView::destroy(const VkAllocationCallbacks* pAllocator)
{
}
void ImageView::clear(const VkClearValue& clearValue, const VkRect2D& renderArea)
{
// Note: clearing ignores swizzling, so components is ignored.
auto imageObject = Cast(image);
if(imageObject->getImageType() != viewType)
{
UNIMPLEMENTED();
}
if(imageObject->getFormat() != format)
{
UNIMPLEMENTED();
}
imageObject->clear(clearValue, renderArea, subresourceRange);
}
}
\ No newline at end of file
// Copyright 2018 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef VK_IMAGE_VIEW_HPP_
#define VK_IMAGE_VIEW_HPP_
#include "VkDebug.hpp"
#include "VkObject.hpp"
#include "VkImage.hpp"
namespace vk
{
class ImageView : public Object<ImageView, VkImageView>
{
public:
ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem);
~ImageView() = delete;
void destroy(const VkAllocationCallbacks* pAllocator);
static size_t ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo);
void clear(const VkClearValue& clearValues, const VkRect2D& renderArea);
private:
VkImage image = VK_NULL_HANDLE;
VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_2D;
VkFormat format = VK_FORMAT_UNDEFINED;
VkComponentMapping components = {};
VkImageSubresourceRange subresourceRange = {};
};
static inline ImageView* Cast(VkImageView object)
{
return reinterpret_cast<ImageView*>(object);
}
} // namespace vk
#endif // VK_IMAGE_VIEW_HPP_
\ No newline at end of file
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "VkFramebuffer.hpp" #include "VkFramebuffer.hpp"
#include "VkGetProcAddress.h" #include "VkGetProcAddress.h"
#include "VkImage.hpp" #include "VkImage.hpp"
#include "VkImageView.hpp"
#include "VkInstance.hpp" #include "VkInstance.hpp"
#include "VkPhysicalDevice.hpp" #include "VkPhysicalDevice.hpp"
#include "VkPipeline.hpp" #include "VkPipeline.hpp"
...@@ -808,21 +809,26 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageV ...@@ -808,21 +809,26 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageV
TRACE("(VkDevice device = 0x%X, const VkImageViewCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkImageView* pView = 0x%X)", TRACE("(VkDevice device = 0x%X, const VkImageViewCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkImageView* pView = 0x%X)",
device, pCreateInfo, pAllocator, pView); device, pCreateInfo, pAllocator, pView);
UNIMPLEMENTED(); if(pCreateInfo->pNext || pCreateInfo->flags)
{
UNIMPLEMENTED();
}
return VK_SUCCESS; return vk::ImageView::Create(pAllocator, pCreateInfo, pView);
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator) VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
{ {
TRACE("()"); TRACE("(VkDevice device = 0x%X, VkImageView imageView = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
UNIMPLEMENTED(); device, imageView, pAllocator);
vk::destroy(imageView, pAllocator);
} }
VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule) VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
{ {
TRACE("(VkDevice device = 0x%X, const VkShaderModuleCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkShaderModule* pShaderModule = 0x%X)", TRACE("(VkDevice device = 0x%X, const VkShaderModuleCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkShaderModule* pShaderModule = 0x%X)",
device, pCreateInfo, pAllocator, pShaderModule); device, pCreateInfo, pAllocator, pShaderModule);
if(pCreateInfo->pNext || pCreateInfo->flags) if(pCreateInfo->pNext || pCreateInfo->flags)
{ {
......
...@@ -109,6 +109,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor ...@@ -109,6 +109,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClCompile Include="VkFramebuffer.cpp" /> <ClCompile Include="VkFramebuffer.cpp" />
<ClCompile Include="VkGetProcAddress.cpp" /> <ClCompile Include="VkGetProcAddress.cpp" />
<ClCompile Include="VkImage.cpp" /> <ClCompile Include="VkImage.cpp" />
<ClCompile Include="VkImageView.cpp" />
<ClCompile Include="VkInstance.cpp" /> <ClCompile Include="VkInstance.cpp" />
<ClCompile Include="VkMemory.cpp" /> <ClCompile Include="VkMemory.cpp" />
<ClCompile Include="VkPhysicalDevice.cpp" /> <ClCompile Include="VkPhysicalDevice.cpp" />
...@@ -203,6 +204,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor ...@@ -203,6 +204,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClInclude Include="VkFramebuffer.hpp" /> <ClInclude Include="VkFramebuffer.hpp" />
<ClInclude Include="VkGetProcAddress.h" /> <ClInclude Include="VkGetProcAddress.h" />
<ClInclude Include="VkImage.hpp" /> <ClInclude Include="VkImage.hpp" />
<ClInclude Include="VkImageView.hpp" />
<ClInclude Include="VkInstance.hpp" /> <ClInclude Include="VkInstance.hpp" />
<ClInclude Include="VkMemory.h" /> <ClInclude Include="VkMemory.h" />
<ClInclude Include="VkObject.hpp" /> <ClInclude Include="VkObject.hpp" />
......
...@@ -237,6 +237,9 @@ ...@@ -237,6 +237,9 @@
<ClCompile Include="VkImage.cpp"> <ClCompile Include="VkImage.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkImageView.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkPromotedExtensions.cpp"> <ClCompile Include="VkPromotedExtensions.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
...@@ -293,6 +296,9 @@ ...@@ -293,6 +296,9 @@
<ClInclude Include="VkImage.hpp"> <ClInclude Include="VkImage.hpp">
<Filter>Header Files\Vulkan</Filter> <Filter>Header Files\Vulkan</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="VkImageView.hpp">
<Filter>Header Files\Vulkan</Filter>
</ClInclude>
<ClInclude Include="VkInstance.hpp"> <ClInclude Include="VkInstance.hpp">
<Filter>Header Files\Vulkan</Filter> <Filter>Header Files\Vulkan</Filter>
</ClInclude> </ClInclude>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment