Add vkTypeUtil
authorPyry Haulos <phaulos@google.com>
Thu, 1 Oct 2015 15:13:47 +0000 (08:13 -0700)
committerPyry Haulos <phaulos@google.com>
Thu, 1 Oct 2015 20:21:09 +0000 (13:21 -0700)
vkTypeUtil.hpp provides convenience functions for creating "simple"
Vulkan composite types, such as VkRect2D or VkChannelMapping.

Change-Id: I5b76046a61a06e92539a19666391b3c322863fca

external/vulkancts/framework/vulkan/CMakeLists.txt
external/vulkancts/framework/vulkan/vkDefs.cpp
external/vulkancts/framework/vulkan/vkDefs.hpp
external/vulkancts/framework/vulkan/vkQueryUtil.cpp
external/vulkancts/framework/vulkan/vkTypeUtil.cpp [new file with mode: 0644]
external/vulkancts/framework/vulkan/vkTypeUtil.hpp [new file with mode: 0644]
external/vulkancts/framework/vulkan/vkTypeUtil.inl [new file with mode: 0644]
external/vulkancts/gen_framework.py
external/vulkancts/modules/vulkan/api/vktApiSmokeTests.cpp

index 5ab0112..ab67b01 100644 (file)
@@ -35,6 +35,8 @@ set(VKUTIL_SRCS
        vkNullDriver.hpp
        vkImageUtil.cpp
        vkImageUtil.hpp
+       vkTypeUtil.cpp
+       vkTypeUtil.hpp
        )
 
 set(VKUTIL_LIBS
index 4c4aceb..fc09ec3 100644 (file)
@@ -104,14 +104,4 @@ void checkResult (VkResult result, const char* msg, const char* file, int line)
        }
 }
 
-VkClearValue clearValueColorF32 (float r, float g, float b, float a)
-{
-       VkClearValue v;
-       v.color.f32[0] = r;
-       v.color.f32[1] = g;
-       v.color.f32[2] = b;
-       v.color.f32[3] = a;
-       return v;
-}
-
 } // vk
index c87caa3..ca35084 100644 (file)
@@ -187,9 +187,6 @@ private:
 
 void                   checkResult                     (VkResult result, const char* message, const char* file, int line);
 
-// \todo [2015-07-30 jarkko] move to vkStructUtil/TypeUtils
-VkClearValue   clearValueColorF32      (float r, float g, float b, float a);
-
 } // vk
 
 #endif // _VKDEFS_HPP
index c3bda9a..823e69a 100644 (file)
@@ -57,7 +57,6 @@ std::vector<VkPhysicalDevice> enumeratePhysicalDevices (const InstanceInterface&
        return devices;
 }
 
-
 std::vector<VkPhysicalDeviceQueueProperties> getPhysicalDeviceQueueProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice)
 {
        deUint32                                                                                numQueues       = 0;
diff --git a/external/vulkancts/framework/vulkan/vkTypeUtil.cpp b/external/vulkancts/framework/vulkan/vkTypeUtil.cpp
new file mode 100644 (file)
index 0000000..a27f7f1
--- /dev/null
@@ -0,0 +1,37 @@
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2015 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice(s) and this permission notice shall be
+ * included in all copies or substantial portions of the Materials.
+ *
+ * The Materials are Confidential Information as defined by the
+ * Khronos Membership Agreement until designated non-confidential by
+ * Khronos, at which point this condition clause shall be removed.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//*!
+ * \file
+ * \brief Utilities for creating commonly used composite types.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkTypeUtil.hpp"
+
+DE_EMPTY_CPP_FILE
diff --git a/external/vulkancts/framework/vulkan/vkTypeUtil.hpp b/external/vulkancts/framework/vulkan/vkTypeUtil.hpp
new file mode 100644 (file)
index 0000000..881bbad
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef _VKTYPEUTIL_HPP
+#define _VKTYPEUTIL_HPP
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2015 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice(s) and this permission notice shall be
+ * included in all copies or substantial portions of the Materials.
+ *
+ * The Materials are Confidential Information as defined by the
+ * Khronos Membership Agreement until designated non-confidential by
+ * Khronos, at which point this condition clause shall be removed.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//*!
+ * \file
+ * \brief Utilities for creating commonly used composite types.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkDefs.hpp"
+
+namespace vk
+{
+
+#include "vkTypeUtil.inl"
+
+inline VkClearValue makeClearValueColorF32 (float r, float g, float b, float a)
+{
+       VkClearValue v;
+       v.color.f32[0] = r;
+       v.color.f32[1] = g;
+       v.color.f32[2] = b;
+       v.color.f32[3] = a;
+       return v;
+}
+
+inline VkChannelMapping makeChannelMappingRGBA (void)
+{
+       return makeChannelMapping(VK_CHANNEL_SWIZZLE_R, VK_CHANNEL_SWIZZLE_G, VK_CHANNEL_SWIZZLE_B, VK_CHANNEL_SWIZZLE_A);
+}
+
+} // vk
+
+#endif // _VKTYPEUTIL_HPP
diff --git a/external/vulkancts/framework/vulkan/vkTypeUtil.inl b/external/vulkancts/framework/vulkan/vkTypeUtil.inl
new file mode 100644 (file)
index 0000000..8b12f94
--- /dev/null
@@ -0,0 +1,298 @@
+/* WARNING: This is auto-generated file. Do not modify, since changes will
+ * be lost! Modify the generating script instead.
+ */
+
+inline VkAllocCallbacks makeAllocCallbacks (void* pUserData, PFN_vkAllocFunction pfnAlloc, PFN_vkFreeFunction pfnFree)
+{
+       VkAllocCallbacks res;
+       res.pUserData   = pUserData;
+       res.pfnAlloc    = pfnAlloc;
+       res.pfnFree             = pfnFree;
+       return res;
+}
+
+inline VkPhysicalDeviceQueueProperties makePhysicalDeviceQueueProperties (VkQueueFlags queueFlags, deUint32 queueCount, VkBool32 supportsTimestamps)
+{
+       VkPhysicalDeviceQueueProperties res;
+       res.queueFlags                  = queueFlags;
+       res.queueCount                  = queueCount;
+       res.supportsTimestamps  = supportsTimestamps;
+       return res;
+}
+
+inline VkDeviceQueueCreateInfo makeDeviceQueueCreateInfo (deUint32 queueFamilyIndex, deUint32 queueCount)
+{
+       VkDeviceQueueCreateInfo res;
+       res.queueFamilyIndex    = queueFamilyIndex;
+       res.queueCount                  = queueCount;
+       return res;
+}
+
+inline VkMemoryRequirements makeMemoryRequirements (VkDeviceSize size, VkDeviceSize alignment, deUint32 memoryTypeBits)
+{
+       VkMemoryRequirements res;
+       res.size                        = size;
+       res.alignment           = alignment;
+       res.memoryTypeBits      = memoryTypeBits;
+       return res;
+}
+
+inline VkExtent3D makeExtent3D (deInt32 width, deInt32 height, deInt32 depth)
+{
+       VkExtent3D res;
+       res.width       = width;
+       res.height      = height;
+       res.depth       = depth;
+       return res;
+}
+
+inline VkSparseMemoryBindInfo makeSparseMemoryBindInfo (VkDeviceSize rangeOffset, VkDeviceSize rangeSize, VkDeviceSize memOffset, VkDeviceMemory mem, VkSparseMemoryBindFlags flags)
+{
+       VkSparseMemoryBindInfo res;
+       res.rangeOffset = rangeOffset;
+       res.rangeSize   = rangeSize;
+       res.memOffset   = memOffset;
+       res.mem                 = mem;
+       res.flags               = flags;
+       return res;
+}
+
+inline VkImageSubresource makeImageSubresource (VkImageAspect aspect, deUint32 mipLevel, deUint32 arraySlice)
+{
+       VkImageSubresource res;
+       res.aspect              = aspect;
+       res.mipLevel    = mipLevel;
+       res.arraySlice  = arraySlice;
+       return res;
+}
+
+inline VkOffset3D makeOffset3D (deInt32 x, deInt32 y, deInt32 z)
+{
+       VkOffset3D res;
+       res.x   = x;
+       res.y   = y;
+       res.z   = z;
+       return res;
+}
+
+inline VkSubresourceLayout makeSubresourceLayout (VkDeviceSize offset, VkDeviceSize size, VkDeviceSize rowPitch, VkDeviceSize depthPitch)
+{
+       VkSubresourceLayout res;
+       res.offset              = offset;
+       res.size                = size;
+       res.rowPitch    = rowPitch;
+       res.depthPitch  = depthPitch;
+       return res;
+}
+
+inline VkChannelMapping makeChannelMapping (VkChannelSwizzle r, VkChannelSwizzle g, VkChannelSwizzle b, VkChannelSwizzle a)
+{
+       VkChannelMapping res;
+       res.r   = r;
+       res.g   = g;
+       res.b   = b;
+       res.a   = a;
+       return res;
+}
+
+inline VkImageSubresourceRange makeImageSubresourceRange (VkImageAspect aspect, deUint32 baseMipLevel, deUint32 mipLevels, deUint32 baseArraySlice, deUint32 arraySize)
+{
+       VkImageSubresourceRange res;
+       res.aspect                      = aspect;
+       res.baseMipLevel        = baseMipLevel;
+       res.mipLevels           = mipLevels;
+       res.baseArraySlice      = baseArraySlice;
+       res.arraySize           = arraySize;
+       return res;
+}
+
+inline VkSpecializationMapEntry makeSpecializationMapEntry (deUint32 constantId, deUintptr size, deUint32 offset)
+{
+       VkSpecializationMapEntry res;
+       res.constantId  = constantId;
+       res.size                = size;
+       res.offset              = offset;
+       return res;
+}
+
+inline VkSpecializationInfo makeSpecializationInfo (deUint32 mapEntryCount, const VkSpecializationMapEntry* pMap, deUintptr dataSize, const void* pData)
+{
+       VkSpecializationInfo res;
+       res.mapEntryCount       = mapEntryCount;
+       res.pMap                        = pMap;
+       res.dataSize            = dataSize;
+       res.pData                       = pData;
+       return res;
+}
+
+inline VkVertexInputBindingDescription makeVertexInputBindingDescription (deUint32 binding, deUint32 strideInBytes, VkVertexInputStepRate stepRate)
+{
+       VkVertexInputBindingDescription res;
+       res.binding                     = binding;
+       res.strideInBytes       = strideInBytes;
+       res.stepRate            = stepRate;
+       return res;
+}
+
+inline VkVertexInputAttributeDescription makeVertexInputAttributeDescription (deUint32 location, deUint32 binding, VkFormat format, deUint32 offsetInBytes)
+{
+       VkVertexInputAttributeDescription res;
+       res.location            = location;
+       res.binding                     = binding;
+       res.format                      = format;
+       res.offsetInBytes       = offsetInBytes;
+       return res;
+}
+
+inline VkStencilOpState makeStencilOpState (VkStencilOp stencilFailOp, VkStencilOp stencilPassOp, VkStencilOp stencilDepthFailOp, VkCompareOp stencilCompareOp)
+{
+       VkStencilOpState res;
+       res.stencilFailOp               = stencilFailOp;
+       res.stencilPassOp               = stencilPassOp;
+       res.stencilDepthFailOp  = stencilDepthFailOp;
+       res.stencilCompareOp    = stencilCompareOp;
+       return res;
+}
+
+inline VkPipelineColorBlendAttachmentState makePipelineColorBlendAttachmentState (VkBool32 blendEnable, VkBlend srcBlendColor, VkBlend destBlendColor, VkBlendOp blendOpColor, VkBlend srcBlendAlpha, VkBlend destBlendAlpha, VkBlendOp blendOpAlpha, VkChannelFlags channelWriteMask)
+{
+       VkPipelineColorBlendAttachmentState res;
+       res.blendEnable                 = blendEnable;
+       res.srcBlendColor               = srcBlendColor;
+       res.destBlendColor              = destBlendColor;
+       res.blendOpColor                = blendOpColor;
+       res.srcBlendAlpha               = srcBlendAlpha;
+       res.destBlendAlpha              = destBlendAlpha;
+       res.blendOpAlpha                = blendOpAlpha;
+       res.channelWriteMask    = channelWriteMask;
+       return res;
+}
+
+inline VkPushConstantRange makePushConstantRange (VkShaderStageFlags stageFlags, deUint32 start, deUint32 length)
+{
+       VkPushConstantRange res;
+       res.stageFlags  = stageFlags;
+       res.start               = start;
+       res.length              = length;
+       return res;
+}
+
+inline VkDescriptorSetLayoutBinding makeDescriptorSetLayoutBinding (VkDescriptorType descriptorType, deUint32 arraySize, VkShaderStageFlags stageFlags, const VkSampler* pImmutableSamplers)
+{
+       VkDescriptorSetLayoutBinding res;
+       res.descriptorType              = descriptorType;
+       res.arraySize                   = arraySize;
+       res.stageFlags                  = stageFlags;
+       res.pImmutableSamplers  = pImmutableSamplers;
+       return res;
+}
+
+inline VkDescriptorTypeCount makeDescriptorTypeCount (VkDescriptorType type, deUint32 count)
+{
+       VkDescriptorTypeCount res;
+       res.type        = type;
+       res.count       = count;
+       return res;
+}
+
+inline VkDescriptorInfo makeDescriptorInfo (VkBufferView bufferView, VkSampler sampler, VkImageView imageView, VkAttachmentView attachmentView, VkImageLayout imageLayout)
+{
+       VkDescriptorInfo res;
+       res.bufferView          = bufferView;
+       res.sampler                     = sampler;
+       res.imageView           = imageView;
+       res.attachmentView      = attachmentView;
+       res.imageLayout         = imageLayout;
+       return res;
+}
+
+inline VkViewport makeViewport (float originX, float originY, float width, float height, float minDepth, float maxDepth)
+{
+       VkViewport res;
+       res.originX             = originX;
+       res.originY             = originY;
+       res.width               = width;
+       res.height              = height;
+       res.minDepth    = minDepth;
+       res.maxDepth    = maxDepth;
+       return res;
+}
+
+inline VkOffset2D makeOffset2D (deInt32 x, deInt32 y)
+{
+       VkOffset2D res;
+       res.x   = x;
+       res.y   = y;
+       return res;
+}
+
+inline VkExtent2D makeExtent2D (deInt32 width, deInt32 height)
+{
+       VkExtent2D res;
+       res.width       = width;
+       res.height      = height;
+       return res;
+}
+
+inline VkAttachmentBindInfo makeAttachmentBindInfo (VkAttachmentView view, VkImageLayout layout)
+{
+       VkAttachmentBindInfo res;
+       res.view        = view;
+       res.layout      = layout;
+       return res;
+}
+
+inline VkAttachmentReference makeAttachmentReference (deUint32 attachment, VkImageLayout layout)
+{
+       VkAttachmentReference res;
+       res.attachment  = attachment;
+       res.layout              = layout;
+       return res;
+}
+
+inline VkBufferCopy makeBufferCopy (VkDeviceSize srcOffset, VkDeviceSize destOffset, VkDeviceSize copySize)
+{
+       VkBufferCopy res;
+       res.srcOffset   = srcOffset;
+       res.destOffset  = destOffset;
+       res.copySize    = copySize;
+       return res;
+}
+
+inline VkClearDepthStencilValue makeClearDepthStencilValue (float depth, deUint32 stencil)
+{
+       VkClearDepthStencilValue res;
+       res.depth       = depth;
+       res.stencil     = stencil;
+       return res;
+}
+
+inline VkDispatchIndirectCmd makeDispatchIndirectCmd (deUint32 x, deUint32 y, deUint32 z)
+{
+       VkDispatchIndirectCmd res;
+       res.x   = x;
+       res.y   = y;
+       res.z   = z;
+       return res;
+}
+
+inline VkDrawIndexedIndirectCmd makeDrawIndexedIndirectCmd (deUint32 indexCount, deUint32 instanceCount, deUint32 firstIndex, deInt32 vertexOffset, deUint32 firstInstance)
+{
+       VkDrawIndexedIndirectCmd res;
+       res.indexCount          = indexCount;
+       res.instanceCount       = instanceCount;
+       res.firstIndex          = firstIndex;
+       res.vertexOffset        = vertexOffset;
+       res.firstInstance       = firstInstance;
+       return res;
+}
+
+inline VkDrawIndirectCmd makeDrawIndirectCmd (deUint32 vertexCount, deUint32 instanceCount, deUint32 firstVertex, deUint32 firstInstance)
+{
+       VkDrawIndirectCmd res;
+       res.vertexCount         = vertexCount;
+       res.instanceCount       = instanceCount;
+       res.firstVertex         = firstVertex;
+       res.firstInstance       = firstInstance;
+       return res;
+}
index 14e1bac..a44a6c7 100644 (file)
@@ -690,6 +690,55 @@ def writeNullDriverImpl (api, filename):
 
        writeInlFile(filename, INL_HEADER, genNullDriverImpl())
 
+def writeTypeUtil (api, filename):
+       # Structs filled by API queries are not often used in test code
+       QUERY_RESULT_TYPES = set([
+                       "VkPhysicalDeviceFeatures",
+                       "VkPhysicalDeviceLimits",
+                       "VkFormatProperties",
+                       "VkImageFormatProperties",
+                       "VkPhysicalDeviceSparseProperties",
+                       "VkQueueFamilyProperties",
+                       "VkMemoryType",
+                       "VkMemoryHeap",
+               ])
+       COMPOSITE_TYPES = set([t.name for t in api.compositeTypes])
+
+       def isSimpleStruct (type):
+               def hasArrayMember (type):
+                       for member in type.members:
+                               if "[" in member.name:
+                                       return True
+                       return False
+
+               def hasCompositeMember (type):
+                       for member in type.members:
+                               if member.type in COMPOSITE_TYPES:
+                                       return True
+                       return False
+
+               return type.typeClass == CompositeType.CLASS_STRUCT and \
+                          type.members[0].type != "VkStructureType" and \
+                          not type.name in QUERY_RESULT_TYPES and \
+                          not hasArrayMember(type) and \
+                          not hasCompositeMember(type)
+
+       def gen ():
+               for type in api.compositeTypes:
+                       if not isSimpleStruct(type):
+                               continue
+
+                       yield ""
+                       yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members))
+                       yield "{"
+                       yield "\t%s res;" % type.name
+                       for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]):
+                               yield line
+                       yield "\treturn res;"
+                       yield "}"
+
+       writeInlFile(filename, INL_HEADER, gen())
+
 if __name__ == "__main__":
        src                             = readFile(sys.argv[1])
        api                             = parseAPI(src)
@@ -721,3 +770,4 @@ if __name__ == "__main__":
        writeRefUtilProto                       (api, os.path.join(VULKAN_DIR, "vkRefUtil.inl"))
        writeRefUtilImpl                        (api, os.path.join(VULKAN_DIR, "vkRefUtilImpl.inl"))
        writeNullDriverImpl                     (api, os.path.join(VULKAN_DIR, "vkNullDriverImpl.inl"))
+       writeTypeUtil                           (api, os.path.join(VULKAN_DIR, "vkTypeUtil.inl"))
index 555828b..0f60a3b 100644 (file)
@@ -45,6 +45,7 @@
 #include "vkMemUtil.hpp"
 #include "vkDeviceUtil.hpp"
 #include "vkPrograms.hpp"
+#include "vkTypeUtil.hpp"
 
 #include "tcuTestLog.hpp"
 #include "tcuFormatUtil.hpp"
@@ -646,7 +647,7 @@ tcu::TestStatus renderTriangleTest (Context& context)
        }
 
        {
-               const VkClearValue                      clearValue              = clearValueColorF32(0.125f, 0.25f, 0.75f, 1.0f);
+               const VkClearValue                      clearValue              = makeClearValueColorF32(0.125f, 0.25f, 0.75f, 1.0f);
                const VkRenderPassBeginInfo     passBeginParams =
                {
                        VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                       //      VkStructureType         sType;