Commit 6a1d92b5 by Alexis Hetu Committed by Alexis Hétu

Add utility functions from sw::Surface to vk::Format

In order to eventually remove sw::Surface, some utility functions used by vk::Image were copied to vk::Format. Bug b/126883332 Change-Id: Ie8404b70adc3336d536dcd5c0ec26b63e46c5174 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26872Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 6193cb18
// Copyright 2019 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_FORMAT_UTILS_HPP_
#define VK_FORMAT_UTILS_HPP_
#include <vulkan/vulkan_core.h>
namespace vk
{
class Format
{
public:
Format(VkFormat format) : format(format) {}
operator VkFormat() const { return format; }
bool isSignedNonNormalizedInteger() const;
bool isUnsignedNonNormalizedInteger() const;
bool isStencil() const;
bool isDepth() const;
int bytes() const;
int pitchB(int width, int border, bool target) const;
int sliceB(int width, int height, int border, bool target) const;
private:
VkFormat format;
};
} // namespace vk
#endif // VK_FORMAT_UTILS_HPP_
\ No newline at end of file
...@@ -17,19 +17,18 @@ ...@@ -17,19 +17,18 @@
#include "VkDevice.hpp" #include "VkDevice.hpp"
#include "VkImage.hpp" #include "VkImage.hpp"
#include "Device/Blitter.hpp" #include "Device/Blitter.hpp"
#include "Device/Surface.hpp"
#include <cstring> #include <cstring>
namespace namespace
{ {
VkImageAspectFlags GetAspects(VkFormat format) VkImageAspectFlags GetAspects(vk::Format format)
{ {
// TODO: probably just flatten this out to a full format list, and alter // TODO: probably just flatten this out to a full format list, and alter
// isDepth / isStencil etc to check for their aspect // isDepth / isStencil etc to check for their aspect
VkImageAspectFlags aspects = 0; VkImageAspectFlags aspects = 0;
if (sw::Surface::isDepth(format)) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT; if (format.isDepth()) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
if (sw::Surface::isStencil(format)) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT; if (format.isStencil()) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT;
// TODO: YCbCr planar formats have different aspects // TODO: YCbCr planar formats have different aspects
...@@ -337,7 +336,7 @@ int Image::rowPitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const ...@@ -337,7 +336,7 @@ int Image::rowPitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const
// Depth and Stencil pitch should be computed separately // Depth and Stencil pitch should be computed separately
ASSERT((aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != ASSERT((aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) !=
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT));
return sw::Surface::pitchB(getMipLevelExtent(mipLevel).width, isCube() ? 1 : 0, getFormat(aspect), false); return getFormat(aspect).pitchB(getMipLevelExtent(mipLevel).width, isCube() ? 1 : 0, false);
} }
int Image::slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const int Image::slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const
...@@ -346,7 +345,7 @@ int Image::slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) cons ...@@ -346,7 +345,7 @@ int Image::slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) cons
ASSERT((aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != ASSERT((aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) !=
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT));
VkExtent3D mipLevelExtent = getMipLevelExtent(mipLevel); VkExtent3D mipLevelExtent = getMipLevelExtent(mipLevel);
return sw::Surface::sliceB(mipLevelExtent.width, mipLevelExtent.height, isCube() ? 1 : 0, getFormat(aspect), false); return getFormat(aspect).sliceB(mipLevelExtent.width, mipLevelExtent.height, isCube() ? 1 : 0, false);
} }
int Image::bytesPerTexel(VkImageAspectFlagBits aspect) const int Image::bytesPerTexel(VkImageAspectFlagBits aspect) const
...@@ -354,10 +353,10 @@ int Image::bytesPerTexel(VkImageAspectFlagBits aspect) const ...@@ -354,10 +353,10 @@ int Image::bytesPerTexel(VkImageAspectFlagBits aspect) const
// Depth and Stencil bytes should be computed separately // Depth and Stencil bytes should be computed separately
ASSERT((aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != ASSERT((aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) !=
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT));
return sw::Surface::bytes(getFormat(aspect)); return getFormat(aspect).bytes();
} }
VkFormat Image::getFormat(VkImageAspectFlagBits aspect) const Format Image::getFormat(VkImageAspectFlagBits aspect) const
{ {
switch(aspect) switch(aspect)
{ {
...@@ -467,11 +466,11 @@ VkFormat Image::getClearFormat() const ...@@ -467,11 +466,11 @@ VkFormat Image::getClearFormat() const
{ {
// Set the proper format for the clear value, as described here: // Set the proper format for the clear value, as described here:
// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#clears-values // https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#clears-values
if(sw::Surface::isSignedNonNormalizedInteger(format)) if(format.isSignedNonNormalizedInteger())
{ {
return VK_FORMAT_R32G32B32A32_SINT; return VK_FORMAT_R32G32B32A32_SINT;
} }
else if(sw::Surface::isUnsignedNonNormalizedInteger(format)) else if(format.isUnsignedNonNormalizedInteger())
{ {
return VK_FORMAT_R32G32B32A32_UINT; return VK_FORMAT_R32G32B32A32_UINT;
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define VK_IMAGE_HPP_ #define VK_IMAGE_HPP_
#include "VkObject.hpp" #include "VkObject.hpp"
#include "VkFormat.h"
namespace vk namespace vk
{ {
...@@ -51,8 +52,8 @@ public: ...@@ -51,8 +52,8 @@ public:
void clear(const VkClearDepthStencilValue& color, const VkImageSubresourceRange& subresourceRange); void clear(const VkClearDepthStencilValue& color, const VkImageSubresourceRange& subresourceRange);
VkImageType getImageType() const { return imageType; } VkImageType getImageType() const { return imageType; }
VkFormat getFormat() const { return format; } const Format& getFormat() const { return format; }
VkFormat getFormat(VkImageAspectFlagBits aspect) const; Format getFormat(VkImageAspectFlagBits aspect) const;
uint32_t getArrayLayers() const { return arrayLayers; } uint32_t getArrayLayers() const { return arrayLayers; }
uint32_t getMipLevels() const { return mipLevels; } uint32_t getMipLevels() const { return mipLevels; }
uint32_t getLastLayerIndex(const VkImageSubresourceRange& subresourceRange) const; uint32_t getLastLayerIndex(const VkImageSubresourceRange& subresourceRange) const;
...@@ -82,7 +83,7 @@ private: ...@@ -82,7 +83,7 @@ private:
VkDeviceSize memoryOffset = 0; VkDeviceSize memoryOffset = 0;
VkImageCreateFlags flags = 0; VkImageCreateFlags flags = 0;
VkImageType imageType = VK_IMAGE_TYPE_2D; VkImageType imageType = VK_IMAGE_TYPE_2D;
VkFormat format = VK_FORMAT_UNDEFINED; Format format = VK_FORMAT_UNDEFINED;
VkExtent3D extent = {0, 0, 0}; VkExtent3D extent = {0, 0, 0};
uint32_t mipLevels = 0; uint32_t mipLevels = 0;
uint32_t arrayLayers = 0; uint32_t arrayLayers = 0;
......
...@@ -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="VkDescriptorUpdateTemplate.cpp" /> <ClCompile Include="VkDescriptorUpdateTemplate.cpp" />
<ClCompile Include="VkDevice.cpp" /> <ClCompile Include="VkDevice.cpp" />
<ClCompile Include="VkDeviceMemory.cpp" /> <ClCompile Include="VkDeviceMemory.cpp" />
<ClCompile Include="VkFormat.cpp" />
<ClCompile Include="VkFramebuffer.cpp" /> <ClCompile Include="VkFramebuffer.cpp" />
<ClCompile Include="VkGetProcAddress.cpp" /> <ClCompile Include="VkGetProcAddress.cpp" />
<ClCompile Include="VkImage.cpp" /> <ClCompile Include="VkImage.cpp" />
...@@ -210,6 +211,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor ...@@ -210,6 +211,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClInclude Include="VkDeviceMemory.hpp" /> <ClInclude Include="VkDeviceMemory.hpp" />
<ClInclude Include="VkEvent.hpp" /> <ClInclude Include="VkEvent.hpp" />
<ClInclude Include="VkFence.hpp" /> <ClInclude Include="VkFence.hpp" />
<ClInclude Include="VkFormat.h" />
<ClInclude Include="VkFramebuffer.hpp" /> <ClInclude Include="VkFramebuffer.hpp" />
<ClInclude Include="VkGetProcAddress.h" /> <ClInclude Include="VkGetProcAddress.h" />
<ClInclude Include="VkImage.hpp" /> <ClInclude Include="VkImage.hpp" />
......
...@@ -222,9 +222,21 @@ ...@@ -222,9 +222,21 @@
<ClCompile Include="VkDeviceMemory.cpp"> <ClCompile Include="VkDeviceMemory.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkFormat.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkFramebuffer.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkGetProcAddress.cpp"> <ClCompile Include="VkGetProcAddress.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkImage.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkImageView.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkInstance.cpp"> <ClCompile Include="VkInstance.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
...@@ -240,19 +252,13 @@ ...@@ -240,19 +252,13 @@
<ClCompile Include="VkPipelineLayout.cpp"> <ClCompile Include="VkPipelineLayout.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkImage.cpp">
<Filter>Source Files\Vulkan</Filter>
</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>
<ClCompile Include="VkQueue.cpp"> <ClCompile Include="VkQueryPool.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkFramebuffer.cpp"> <ClCompile Include="VkQueue.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkRenderPass.cpp"> <ClCompile Include="VkRenderPass.cpp">
...@@ -261,9 +267,6 @@ ...@@ -261,9 +267,6 @@
<ClCompile Include="VkShaderModule.cpp"> <ClCompile Include="VkShaderModule.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkQueryPool.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="..\Pipeline\SpirvShader.cpp"> <ClCompile Include="..\Pipeline\SpirvShader.cpp">
<Filter>Source Files\Pipeline</Filter> <Filter>Source Files\Pipeline</Filter>
</ClCompile> </ClCompile>
...@@ -311,6 +314,9 @@ ...@@ -311,6 +314,9 @@
<ClInclude Include="VkFence.hpp"> <ClInclude Include="VkFence.hpp">
<Filter>Header Files\Vulkan</Filter> <Filter>Header Files\Vulkan</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="VkFormat.h">
<Filter>Header Files\Vulkan</Filter>
</ClInclude>
<ClInclude Include="VkFramebuffer.hpp"> <ClInclude Include="VkFramebuffer.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