c4e4c5e9c22797d991d250250f13dd8e608a9b93
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / protected_memory / vktProtectedMemContext.hpp
1 #ifndef _VKTPROTECTEDMEMCONTEXT_HPP
2 #define _VKTPROTECTEDMEMCONTEXT_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2017 The Khronos Group Inc.
8  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Protected Memory image validator helper
25  *//*--------------------------------------------------------------------*/
26
27 #include "tcuVector.hpp"
28 #include "vkDefs.hpp"
29 #include "vktTestCase.hpp"
30
31 #include "vktProtectedMemUtils.hpp"
32 #include "tcuCommandLine.hpp"
33 #include "vkMemUtil.hpp"
34
35 namespace vkt
36 {
37 namespace ProtectedMem
38 {
39
40
41 class ProtectedContext
42 {
43 public:
44                 ProtectedContext        (Context& ctx)
45                         : m_context                             (ctx)
46                         , m_interface                   (m_context.getPlatformInterface())
47                         , m_instance                    (makeProtectedMemInstance(m_interface, m_context))
48                         , m_vki                                 (m_interface, *m_instance)
49                         , m_phyDevice                   (vk::chooseDevice(m_vki, *m_instance, m_context.getTestContext().getCommandLine()))
50                         , m_queueFamilyIndex    (chooseProtectedMemQueueFamilyIndex(m_vki, m_phyDevice))
51                         , m_device                              (makeProtectedMemDevice(m_vki, m_phyDevice, m_queueFamilyIndex, ctx.getUsedApiVersion()))
52                         , m_allocator                   (createAllocator())
53                         , m_deviceDriver                (m_vki, *m_device)
54                         , m_queue                               (getProtectedQueue(m_deviceDriver, *m_device, m_queueFamilyIndex, 0))
55                 {}
56
57         const vk::DeviceInterface&                                      getDeviceInterface      (void) const    { return m_deviceDriver;                                        }
58         vk::VkDevice                                                            getDevice                       (void) const    { return *m_device;                                                     }
59         vk::VkQueue                                                                     getQueue                        (void) const    { return m_queue;                                                       }
60         deUint32                                                                        getQueueFamilyIndex     (void) const    { return m_queueFamilyIndex;                            }
61
62         tcu::TestContext&                                                       getTestContext          (void) const    { return m_context.getTestContext();            }
63         vk::BinaryCollection&                                           getBinaryCollection     (void) const    { return m_context.getBinaryCollection();       }
64         vk::Allocator&                                                          getDefaultAllocator     (void) const    { return *m_allocator;  }
65
66 private:
67         vk::Allocator* createAllocator (void)
68         {
69                 const vk::VkPhysicalDeviceMemoryProperties memoryProperties =
70                         vk::getPhysicalDeviceMemoryProperties(m_vki, m_phyDevice);
71
72                 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time)
73                 return new vk::SimpleAllocator(getDeviceInterface(), getDevice(), memoryProperties);
74         }
75
76         Context&                                                m_context;
77         const vk::PlatformInterface&    m_interface;
78         vk::Move<vk::VkInstance>                m_instance;
79         vk::InstanceDriver                              m_vki;
80         vk::VkPhysicalDevice                    m_phyDevice;
81         deUint32                                                m_queueFamilyIndex;
82         vk::Move<vk::VkDevice>                  m_device;
83         const de::UniquePtr<vk::Allocator>      m_allocator;
84         vk::DeviceDriver                                m_deviceDriver;
85         vk::VkQueue                                             m_queue;
86 };
87
88 class ProtectedTestInstance : public TestInstance
89 {
90 public:
91                                 ProtectedTestInstance   (Context& ctx)
92                                         : TestInstance                  (ctx)
93                                         , m_protectedContext    (ctx)
94                                 {}
95 protected:
96         ProtectedContext        m_protectedContext;
97 };
98
99 } // ProtectedMem
100 } // vkt
101
102 #endif // _VKTPROTECTEDMEMCONTEXT_HPP