1 #ifndef _VKTPIPELINEIMAGESAMPLINGINSTANCE_HPP
2 #define _VKTPIPELINEIMAGESAMPLINGINSTANCE_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Imagination Technologies Ltd.
9  * Copyright (c) 2023 LunarG, Inc.
10  * Copyright (c) 2023 Nintendo
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *      http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  *//*!
25  * \file
26  * \brief Image sampling case
27  *//*--------------------------------------------------------------------*/
28 
29 #include "vkDefs.hpp"
30 
31 #include "vktTestCase.hpp"
32 #include "vktTestCaseUtil.hpp"
33 #include "vktPipelineImageUtil.hpp"
34 #include "vktPipelineReferenceRenderer.hpp"
35 #include "vktPipelineVertexUtil.hpp"
36 #include "vkPipelineConstructionUtil.hpp"
37 #include "tcuVectorUtil.hpp"
38 #include "deSharedPtr.hpp"
39 
40 namespace vkt
41 {
42 namespace pipeline
43 {
44 
45 enum AllocationKind
46 {
47     ALLOCATION_KIND_SUBALLOCATED,
48     ALLOCATION_KIND_DEDICATED,
49 };
50 
51 struct ImageSamplingInstanceParams
52 {
ImageSamplingInstanceParamsvkt::pipeline::ImageSamplingInstanceParams53     ImageSamplingInstanceParams(const vk::PipelineConstructionType pipelineConstructionType_,
54                                 const tcu::UVec2 &renderSize_, vk::VkImageViewType imageViewType_,
55                                 vk::VkFormat imageFormat_, const tcu::IVec3 &imageSize_, int layerCount_,
56                                 const vk::VkComponentMapping &componentMapping_,
57                                 const vk::VkImageSubresourceRange &subresourceRange_,
58                                 const vk::VkSamplerCreateInfo &samplerParams_, float samplerLod_,
59                                 const std::vector<Vertex4Tex4> &vertices_, bool separateStencilUsage_ = false,
60                                 vk::VkDescriptorType samplingType_ = vk::VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
61                                 int imageCount_ = 1, AllocationKind allocationKind_ = ALLOCATION_KIND_SUBALLOCATED,
62                                 const vk::VkImageLayout imageLayout_ = vk::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
63                                 const vk::VkPipelineCreateFlags pipelineCreateFlags_ = 0u)
64         : pipelineConstructionType(pipelineConstructionType_)
65         , renderSize(renderSize_)
66         , imageViewType(imageViewType_)
67         , imageFormat(imageFormat_)
68         , imageSize(imageSize_)
69         , layerCount(layerCount_)
70         , componentMapping(componentMapping_)
71         , subresourceRange(subresourceRange_)
72         , samplerParams(samplerParams_)
73         , samplerLod(samplerLod_)
74         , vertices(vertices_)
75         , separateStencilUsage(separateStencilUsage_)
76         , samplingType(samplingType_)
77         , imageCount(imageCount_)
78         , allocationKind(allocationKind_)
79         , imageLayout(imageLayout_)
80         , pipelineCreateFlags(pipelineCreateFlags_)
81     {
82     }
83 
84     const vk::PipelineConstructionType pipelineConstructionType;
85     const tcu::UVec2 renderSize;
86     vk::VkImageViewType imageViewType;
87     vk::VkFormat imageFormat;
88     const tcu::IVec3 imageSize;
89     int layerCount;
90     const vk::VkComponentMapping componentMapping;
91     const vk::VkImageSubresourceRange subresourceRange;
92     const vk::VkSamplerCreateInfo samplerParams;
93     float samplerLod;
94     const std::vector<Vertex4Tex4> vertices;
95     bool separateStencilUsage;
96     vk::VkDescriptorType samplingType;
97     int imageCount;
98     AllocationKind allocationKind;
99     const vk::VkImageLayout imageLayout;
100     const vk::VkPipelineCreateFlags pipelineCreateFlags;
101 };
102 
103 void checkSupportImageSamplingInstance(Context &context, ImageSamplingInstanceParams params);
104 
105 class ImageSamplingInstance : public vkt::TestInstance
106 {
107 public:
108     ImageSamplingInstance(Context &context, ImageSamplingInstanceParams params);
109 
110     virtual ~ImageSamplingInstance(void);
111 
112     virtual tcu::TestStatus iterate(void);
113 
114 protected:
115     virtual tcu::TestStatus verifyImage(void);
116     virtual void setup(void);
117 
118     typedef vk::Unique<vk::VkImage> UniqueImage;
119     typedef vk::Unique<vk::VkImageView> UniqueImageView;
120     typedef de::UniquePtr<vk::Allocation> UniqueAlloc;
121     typedef de::SharedPtr<UniqueImage> SharedImagePtr;
122     typedef de::SharedPtr<UniqueImageView> SharedImageViewPtr;
123     typedef de::SharedPtr<UniqueAlloc> SharedAllocPtr;
124 
125     const AllocationKind m_allocationKind;
126     const vk::VkDescriptorType m_samplingType;
127     const vk::VkImageViewType m_imageViewType;
128     const vk::VkFormat m_imageFormat;
129     const tcu::IVec3 m_imageSize;
130     const int m_layerCount;
131     const int m_imageCount;
132 
133     const vk::VkComponentMapping m_componentMapping;
134     tcu::BVec4 m_componentMask;
135     const vk::VkImageSubresourceRange m_subresourceRange;
136     const vk::VkSamplerCreateInfo m_samplerParams;
137     const float m_samplerLod;
138 
139     std::vector<SharedImagePtr> m_images;
140     std::vector<SharedAllocPtr> m_imageAllocs;
141     std::vector<SharedImageViewPtr> m_imageViews;
142     vk::Move<vk::VkSampler> m_sampler;
143     de::MovePtr<TestTexture> m_texture;
144 
145     const tcu::UVec2 m_renderSize;
146     const vk::VkFormat m_colorFormat;
147 
148     vk::Move<vk::VkDescriptorPool> m_descriptorPool;
149     vk::Move<vk::VkDescriptorSetLayout> m_descriptorSetLayout;
150     vk::Move<vk::VkDescriptorSet> m_descriptorSet;
151 
152     std::vector<SharedImagePtr> m_colorImages;
153     std::vector<SharedAllocPtr> m_colorImageAllocs;
154     std::vector<SharedImageViewPtr> m_colorAttachmentViews;
155     vk::RenderPassWrapper m_renderPass;
156 
157     vk::ShaderWrapper m_vertexShaderModule;
158     vk::ShaderWrapper m_fragmentShaderModule;
159 
160     vk::Move<vk::VkBuffer> m_vertexBuffer;
161     std::vector<Vertex4Tex4> m_vertices;
162     de::MovePtr<vk::Allocation> m_vertexBufferAlloc;
163 
164     vk::PipelineLayoutWrapper m_preRasterizationStatePipelineLayout;
165     vk::PipelineLayoutWrapper m_fragmentStatePipelineLayout;
166     vk::GraphicsPipelineWrapper m_graphicsPipeline;
167     const vk::PipelineConstructionType m_pipelineConstructionType;
168 
169     vk::Move<vk::VkCommandPool> m_cmdPool;
170     vk::Move<vk::VkCommandBuffer> m_cmdBuffer;
171 
172     const vk::VkImageLayout m_imageLayout;
173 };
174 
175 } // namespace pipeline
176 } // namespace vkt
177 
178 #endif // _VKTPIPELINEIMAGESAMPLINGINSTANCE_HPP
179