1 /* Copyright (c) 2015-2021 The Khronos Group Inc.
2  * Copyright (c) 2015-2021 Valve Corporation
3  * Copyright (c) 2015-2021 LunarG, Inc.
4  * Copyright (C) 2015-2021 Google Inc.
5  * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Author: Courtney Goeltzenleuchter <courtneygo@google.com>
20  * Author: Tobin Ehlis <tobine@google.com>
21  * Author: Chris Forbes <chrisf@ijw.co.nz>
22  * Author: Mark Lobodzinski <mark@lunarg.com>
23  * Author: Dave Houlton <daveh@lunarg.com>
24  * Author: John Zulauf <jzulauf@lunarg.com>
25  * Author: Tobias Hector <tobias.hector@amd.com>
26  */
27 #pragma once
28 #include "base_node.h"
29 #include "layer_chassis_dispatch.h"
30 #include <vector>
31 
32 struct DeviceFeatures {
33     VkPhysicalDeviceFeatures core;
34     VkPhysicalDeviceVulkan11Features core11;
35     VkPhysicalDeviceVulkan12Features core12;
36 
37     VkPhysicalDeviceExclusiveScissorFeaturesNV exclusive_scissor_features;
38     VkPhysicalDeviceShadingRateImageFeaturesNV shading_rate_image_features;
39     VkPhysicalDeviceMeshShaderFeaturesNV mesh_shader_features;
40     VkPhysicalDeviceInlineUniformBlockFeaturesEXT inline_uniform_block_features;
41     VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback_features;
42     VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT vtx_attrib_divisor_features;
43     VkPhysicalDeviceBufferDeviceAddressFeaturesEXT buffer_device_address_ext_features;
44     VkPhysicalDeviceCooperativeMatrixFeaturesNV cooperative_matrix_features;
45     VkPhysicalDeviceComputeShaderDerivativesFeaturesNV compute_shader_derivatives_features;
46     VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV fragment_shader_barycentric_features;
47     VkPhysicalDeviceShaderImageFootprintFeaturesNV shader_image_footprint_features;
48     VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT fragment_shader_interlock_features;
49     VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT demote_to_helper_invocation_features;
50     VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT texel_buffer_alignment_features;
51     VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR pipeline_exe_props_features;
52     VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV dedicated_allocation_image_aliasing_features;
53     VkPhysicalDevicePerformanceQueryFeaturesKHR performance_query_features;
54     VkPhysicalDeviceCoherentMemoryFeaturesAMD device_coherent_memory_features;
55     VkPhysicalDeviceYcbcrImageArraysFeaturesEXT ycbcr_image_array_features;
56     VkPhysicalDeviceRayQueryFeaturesKHR ray_query_features;
57     VkPhysicalDeviceRayTracingPipelineFeaturesKHR ray_tracing_pipeline_features;
58     VkPhysicalDeviceAccelerationStructureFeaturesKHR ray_tracing_acceleration_structure_features;
59     VkPhysicalDeviceRobustness2FeaturesEXT robustness2_features;
60     VkPhysicalDeviceFragmentDensityMapFeaturesEXT fragment_density_map_features;
61     VkPhysicalDeviceFragmentDensityMap2FeaturesEXT fragment_density_map2_features;
62     VkPhysicalDeviceASTCDecodeFeaturesEXT astc_decode_features;
63     VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border_color_features;
64     VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT pipeline_creation_cache_control_features;
65     VkPhysicalDeviceExtendedDynamicStateFeaturesEXT extended_dynamic_state_features;
66     VkPhysicalDeviceMultiviewFeatures multiview_features;
67     VkPhysicalDevicePortabilitySubsetFeaturesKHR portability_subset_features;
68     VkPhysicalDeviceFragmentShadingRateFeaturesKHR fragment_shading_rate_features;
69     VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL shader_integer_functions2_features;
70     VkPhysicalDeviceShaderSMBuiltinsFeaturesNV shader_sm_builtins_features;
71     VkPhysicalDeviceShaderAtomicFloatFeaturesEXT shader_atomic_float_features;
72     VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT shader_image_atomic_int64_features;
73     VkPhysicalDeviceShaderClockFeaturesKHR shader_clock_features;
74     VkPhysicalDeviceConditionalRenderingFeaturesEXT conditional_rendering_features;
75     VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR workgroup_memory_explicit_layout_features;
76     VkPhysicalDeviceSynchronization2FeaturesKHR synchronization2_features;
77     VkPhysicalDeviceExtendedDynamicState2FeaturesEXT extended_dynamic_state2_features;
78     VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT vertex_input_dynamic_state_features;
79     VkPhysicalDeviceInheritedViewportScissorFeaturesNV inherited_viewport_scissor_features;
80     VkPhysicalDeviceProvokingVertexFeaturesEXT provoking_vertex_features;
81     VkPhysicalDeviceMultiDrawFeaturesEXT multi_draw_features;
82     VkPhysicalDeviceColorWriteEnableFeaturesEXT color_write_features;
83     VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT shader_atomic_float2_features;
84     VkPhysicalDevicePresentIdFeaturesKHR present_id_features;
85     VkPhysicalDevicePresentWaitFeaturesKHR present_wait_features;
86     VkPhysicalDeviceRayTracingMotionBlurFeaturesNV ray_tracing_motion_blur_features;
87     VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR shader_integer_dot_product_features;
88     VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT primitive_topology_list_restart_features;
89     VkPhysicalDeviceSubgroupSizeControlFeaturesEXT subgroup_size_control_features;
90     VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT rgba10x6_formats_features;
91     VkPhysicalDeviceMaintenance4FeaturesKHR maintenance4_features;
92     VkPhysicalDeviceDynamicRenderingFeaturesKHR dynamic_rendering_features;
93     VkPhysicalDeviceImageViewMinLodFeaturesEXT image_view_min_lod_features;
94     // If a new feature is added here that involves a SPIR-V capability add also in spirv_validation_generator.py
95     // This is known by checking the table in the spec or if the struct is in a <spirvcapability> in vk.xml
96 };
97 
98 class QUEUE_FAMILY_PERF_COUNTERS {
99   public:
100     std::vector<VkPerformanceCounterKHR> counters;
101 };
102 
103 class PHYSICAL_DEVICE_STATE : public BASE_NODE {
104   public:
105     uint32_t queue_family_known_count = 1;  // spec implies one QF must always be supported
106     const std::vector<VkQueueFamilyProperties> queue_family_properties;
107     // TODO These are currently used by CoreChecks, but should probably be refactored
108     bool vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = false;
109     uint32_t display_plane_property_count = 0;
110 
111     // Map of queue family index to QUEUE_FAMILY_PERF_COUNTERS
112     layer_data::unordered_map<uint32_t, std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS>> perf_counters;
113 
PHYSICAL_DEVICE_STATE(VkPhysicalDevice phys_dev)114     PHYSICAL_DEVICE_STATE(VkPhysicalDevice phys_dev)
115         : BASE_NODE(phys_dev, kVulkanObjectTypePhysicalDevice), queue_family_properties(GetQueueFamilyProps(phys_dev)) {}
116 
PhysDev()117     VkPhysicalDevice PhysDev() const { return handle_.Cast<VkPhysicalDevice>(); }
118 
119   private:
GetQueueFamilyProps(VkPhysicalDevice phys_dev)120     const std::vector<VkQueueFamilyProperties> GetQueueFamilyProps(VkPhysicalDevice phys_dev) {
121         std::vector<VkQueueFamilyProperties> result;
122         uint32_t count;
123         DispatchGetPhysicalDeviceQueueFamilyProperties(phys_dev, &count, nullptr);
124         result.resize(count);
125         DispatchGetPhysicalDeviceQueueFamilyProperties(phys_dev, &count, result.data());
126         return result;
127     }
128 };
129 
130 class DISPLAY_MODE_STATE : public BASE_NODE {
131   public:
132     const VkPhysicalDevice physical_device;
133 
DISPLAY_MODE_STATE(VkDisplayModeKHR dm,VkPhysicalDevice phys_dev)134     DISPLAY_MODE_STATE(VkDisplayModeKHR dm, VkPhysicalDevice phys_dev)
135         : BASE_NODE(dm, kVulkanObjectTypeDisplayModeKHR), physical_device(phys_dev) {}
136 
display_mode()137     VkDisplayModeKHR display_mode() const { return handle_.Cast<VkDisplayModeKHR>(); }
138 };
139