• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2015-2016 The Khronos Group Inc.
2  * Copyright (c) 2015-2016 Valve Corporation
3  * Copyright (c) 2015-2016 LunarG, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Author: Mark Lobodzinski <mark@lunarg.com>
18  *
19  */
20 
21 #include <string.h>
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include "vulkan/vulkan.h"
26 #include "vk_layer_config.h"
27 #include "vk_layer_utils.h"
28 
29 struct VULKAN_FORMAT_INFO {
30     size_t size;
31     uint32_t channel_count;
32     VkFormatCompatibilityClass format_class;
33 };
34 
35 // Set up data structure with number of bytes and number of channels for each Vulkan format
36 const std::map<VkFormat, VULKAN_FORMAT_INFO> vk_format_table = {
37     {VK_FORMAT_UNDEFINED,                   {0, 0, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT }},
38     {VK_FORMAT_R4G4_UNORM_PACK8,            {1, 2, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
39     {VK_FORMAT_R4G4B4A4_UNORM_PACK16,       {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
40     {VK_FORMAT_B4G4R4A4_UNORM_PACK16,       {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
41     {VK_FORMAT_R5G6B5_UNORM_PACK16,         {2, 3, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
42     {VK_FORMAT_B5G6R5_UNORM_PACK16,         {2, 3, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
43     {VK_FORMAT_R5G5B5A1_UNORM_PACK16,       {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
44     {VK_FORMAT_B5G5R5A1_UNORM_PACK16,       {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
45     {VK_FORMAT_A1R5G5B5_UNORM_PACK16,       {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
46     {VK_FORMAT_R8_UNORM,                    {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
47     {VK_FORMAT_R8_SNORM,                    {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
48     {VK_FORMAT_R8_USCALED,                  {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
49     {VK_FORMAT_R8_SSCALED,                  {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
50     {VK_FORMAT_R8_UINT,                     {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
51     {VK_FORMAT_R8_SINT,                     {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
52     {VK_FORMAT_R8_SRGB,                     {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}},
53     {VK_FORMAT_R8G8_UNORM,                  {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
54     {VK_FORMAT_R8G8_SNORM,                  {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
55     {VK_FORMAT_R8G8_USCALED,                {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
56     {VK_FORMAT_R8G8_SSCALED,                {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
57     {VK_FORMAT_R8G8_UINT,                   {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
58     {VK_FORMAT_R8G8_SINT,                   {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
59     {VK_FORMAT_R8G8_SRGB,                   {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
60     {VK_FORMAT_R8G8B8_UNORM,                {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
61     {VK_FORMAT_R8G8B8_SNORM,                {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
62     {VK_FORMAT_R8G8B8_USCALED,              {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
63     {VK_FORMAT_R8G8B8_SSCALED,              {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
64     {VK_FORMAT_R8G8B8_UINT,                 {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
65     {VK_FORMAT_R8G8B8_SINT,                 {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
66     {VK_FORMAT_R8G8B8_SRGB,                 {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
67     {VK_FORMAT_B8G8R8_UNORM,                {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
68     {VK_FORMAT_B8G8R8_SNORM,                {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
69     {VK_FORMAT_B8G8R8_USCALED,              {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
70     {VK_FORMAT_B8G8R8_SSCALED,              {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
71     {VK_FORMAT_B8G8R8_UINT,                 {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
72     {VK_FORMAT_B8G8R8_SINT,                 {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
73     {VK_FORMAT_B8G8R8_SRGB,                 {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}},
74     {VK_FORMAT_R8G8B8A8_UNORM,              {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
75     {VK_FORMAT_R8G8B8A8_SNORM,              {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
76     {VK_FORMAT_R8G8B8A8_USCALED,            {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
77     {VK_FORMAT_R8G8B8A8_SSCALED,            {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
78     {VK_FORMAT_R8G8B8A8_UINT,               {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
79     {VK_FORMAT_R8G8B8A8_SINT,               {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
80     {VK_FORMAT_R8G8B8A8_SRGB,               {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
81     {VK_FORMAT_B8G8R8A8_UNORM,              {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
82     {VK_FORMAT_B8G8R8A8_SNORM,              {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
83     {VK_FORMAT_B8G8R8A8_USCALED,            {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
84     {VK_FORMAT_B8G8R8A8_SSCALED,            {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
85     {VK_FORMAT_B8G8R8A8_UINT,               {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
86     {VK_FORMAT_B8G8R8A8_SINT,               {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
87     {VK_FORMAT_B8G8R8A8_SRGB,               {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
88     {VK_FORMAT_A8B8G8R8_UNORM_PACK32,       {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
89     {VK_FORMAT_A8B8G8R8_SNORM_PACK32,       {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
90     {VK_FORMAT_A8B8G8R8_USCALED_PACK32,     {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
91     {VK_FORMAT_A8B8G8R8_SSCALED_PACK32,     {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
92     {VK_FORMAT_A8B8G8R8_UINT_PACK32,        {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
93     {VK_FORMAT_A8B8G8R8_SINT_PACK32,        {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
94     {VK_FORMAT_A8B8G8R8_SRGB_PACK32,        {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
95     {VK_FORMAT_A2R10G10B10_UNORM_PACK32,    {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
96     {VK_FORMAT_A2R10G10B10_SNORM_PACK32,    {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
97     {VK_FORMAT_A2R10G10B10_USCALED_PACK32,  {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
98     {VK_FORMAT_A2R10G10B10_SSCALED_PACK32,  {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
99     {VK_FORMAT_A2R10G10B10_UINT_PACK32,     {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
100     {VK_FORMAT_A2R10G10B10_SINT_PACK32,     {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
101     {VK_FORMAT_A2B10G10R10_UNORM_PACK32,    {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
102     {VK_FORMAT_A2B10G10R10_SNORM_PACK32,    {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
103     {VK_FORMAT_A2B10G10R10_USCALED_PACK32,  {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
104     {VK_FORMAT_A2B10G10R10_SSCALED_PACK32,  {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
105     {VK_FORMAT_A2B10G10R10_UINT_PACK32,     {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
106     {VK_FORMAT_A2B10G10R10_SINT_PACK32,     {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
107     {VK_FORMAT_R16_UNORM,                   {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
108     {VK_FORMAT_R16_SNORM,                   {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
109     {VK_FORMAT_R16_USCALED,                 {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
110     {VK_FORMAT_R16_SSCALED,                 {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
111     {VK_FORMAT_R16_UINT,                    {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
112     {VK_FORMAT_R16_SINT,                    {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
113     {VK_FORMAT_R16_SFLOAT,                  {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}},
114     {VK_FORMAT_R16G16_UNORM,                {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
115     {VK_FORMAT_R16G16_SNORM,                {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
116     {VK_FORMAT_R16G16_USCALED,              {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
117     {VK_FORMAT_R16G16_SSCALED,              {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
118     {VK_FORMAT_R16G16_UINT,                 {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
119     {VK_FORMAT_R16G16_SINT,                 {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
120     {VK_FORMAT_R16G16_SFLOAT,               {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
121     {VK_FORMAT_R16G16B16_UNORM,             {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}},
122     {VK_FORMAT_R16G16B16_SNORM,             {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}},
123     {VK_FORMAT_R16G16B16_USCALED,           {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}},
124     {VK_FORMAT_R16G16B16_SSCALED,           {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}},
125     {VK_FORMAT_R16G16B16_UINT,              {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}},
126     {VK_FORMAT_R16G16B16_SINT,              {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}},
127     {VK_FORMAT_R16G16B16_SFLOAT,            {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}},
128     {VK_FORMAT_R16G16B16A16_UNORM,          {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
129     {VK_FORMAT_R16G16B16A16_SNORM,          {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
130     {VK_FORMAT_R16G16B16A16_USCALED,        {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
131     {VK_FORMAT_R16G16B16A16_SSCALED,        {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
132     {VK_FORMAT_R16G16B16A16_UINT,           {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
133     {VK_FORMAT_R16G16B16A16_SINT,           {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
134     {VK_FORMAT_R16G16B16A16_SFLOAT,         {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
135     {VK_FORMAT_R32_UINT,                    {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
136     {VK_FORMAT_R32_SINT,                    {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
137     {VK_FORMAT_R32_SFLOAT,                  {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
138     {VK_FORMAT_R32G32_UINT,                 {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
139     {VK_FORMAT_R32G32_SINT,                 {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
140     {VK_FORMAT_R32G32_SFLOAT,               {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
141     {VK_FORMAT_R32G32B32_UINT,              {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}},
142     {VK_FORMAT_R32G32B32_SINT,              {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}},
143     {VK_FORMAT_R32G32B32_SFLOAT,            {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}},
144     {VK_FORMAT_R32G32B32A32_UINT,           {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}},
145     {VK_FORMAT_R32G32B32A32_SINT,           {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}},
146     {VK_FORMAT_R32G32B32A32_SFLOAT,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}},
147     {VK_FORMAT_R64_UINT,                    {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
148     {VK_FORMAT_R64_SINT,                    {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
149     {VK_FORMAT_R64_SFLOAT,                  {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}},
150     {VK_FORMAT_R64G64_UINT,                 {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}},
151     {VK_FORMAT_R64G64_SINT,                 {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}},
152     {VK_FORMAT_R64G64_SFLOAT,               {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}},
153     {VK_FORMAT_R64G64B64_UINT,              {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}},
154     {VK_FORMAT_R64G64B64_SINT,              {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}},
155     {VK_FORMAT_R64G64B64_SFLOAT,            {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}},
156     {VK_FORMAT_R64G64B64A64_UINT,           {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}},
157     {VK_FORMAT_R64G64B64A64_SINT,           {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}},
158     {VK_FORMAT_R64G64B64A64_SFLOAT,         {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}},
159     {VK_FORMAT_B10G11R11_UFLOAT_PACK32,     {4, 3, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
160     {VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,      {4, 3, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}},
161     {VK_FORMAT_D16_UNORM,                   {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
162     {VK_FORMAT_X8_D24_UNORM_PACK32,         {3, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
163     {VK_FORMAT_D32_SFLOAT,                  {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
164     {VK_FORMAT_S8_UINT,                     {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
165     {VK_FORMAT_D16_UNORM_S8_UINT,           {3, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
166     {VK_FORMAT_D24_UNORM_S8_UINT,           {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
167     {VK_FORMAT_D32_SFLOAT_S8_UINT,          {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
168     {VK_FORMAT_BC1_RGB_UNORM_BLOCK,         {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}},
169     {VK_FORMAT_BC1_RGB_SRGB_BLOCK,          {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}},
170     {VK_FORMAT_BC1_RGBA_UNORM_BLOCK,        {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT}},
171     {VK_FORMAT_BC1_RGBA_SRGB_BLOCK,         {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT}},
172     {VK_FORMAT_BC2_UNORM_BLOCK,             {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT}},
173     {VK_FORMAT_BC2_SRGB_BLOCK,              {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT}},
174     {VK_FORMAT_BC3_UNORM_BLOCK,             {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT}},
175     {VK_FORMAT_BC3_SRGB_BLOCK,              {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT}},
176     {VK_FORMAT_BC4_UNORM_BLOCK,             {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT}},
177     {VK_FORMAT_BC4_SNORM_BLOCK,             {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT}},
178     {VK_FORMAT_BC5_UNORM_BLOCK,             {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT}},
179     {VK_FORMAT_BC5_SNORM_BLOCK,             {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT}},
180     {VK_FORMAT_BC6H_UFLOAT_BLOCK,           {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT}},
181     {VK_FORMAT_BC6H_SFLOAT_BLOCK,           {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT}},
182     {VK_FORMAT_BC7_UNORM_BLOCK,             {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT}},
183     {VK_FORMAT_BC7_SRGB_BLOCK,              {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT}},
184     {VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,     {8, 3, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT}},
185     {VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,      {8, 3, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT}},
186     {VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,   {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT}},
187     {VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,    {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT}},
188     {VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,   {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT}},
189     {VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,    {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT}},
190     {VK_FORMAT_EAC_R11_UNORM_BLOCK,         {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT}},
191     {VK_FORMAT_EAC_R11_SNORM_BLOCK,         {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT}},
192     {VK_FORMAT_EAC_R11G11_UNORM_BLOCK,      {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT}},
193     {VK_FORMAT_EAC_R11G11_SNORM_BLOCK,      {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT}},
194     {VK_FORMAT_ASTC_4x4_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT}},
195     {VK_FORMAT_ASTC_4x4_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT}},
196     {VK_FORMAT_ASTC_5x4_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT}},
197     {VK_FORMAT_ASTC_5x4_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT}},
198     {VK_FORMAT_ASTC_5x5_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT}},
199     {VK_FORMAT_ASTC_5x5_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT}},
200     {VK_FORMAT_ASTC_6x5_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT}},
201     {VK_FORMAT_ASTC_6x5_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT}},
202     {VK_FORMAT_ASTC_6x6_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT}},
203     {VK_FORMAT_ASTC_6x6_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT}},
204     {VK_FORMAT_ASTC_8x5_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT}},
205     {VK_FORMAT_ASTC_8x5_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT}},
206     {VK_FORMAT_ASTC_8x6_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT}},
207     {VK_FORMAT_ASTC_8x6_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT}},
208     {VK_FORMAT_ASTC_8x8_UNORM_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT}},
209     {VK_FORMAT_ASTC_8x8_SRGB_BLOCK,         {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT}},
210     {VK_FORMAT_ASTC_10x5_UNORM_BLOCK,       {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT}},
211     {VK_FORMAT_ASTC_10x5_SRGB_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT}},
212     {VK_FORMAT_ASTC_10x6_UNORM_BLOCK,       {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}},
213     {VK_FORMAT_ASTC_10x6_SRGB_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}},
214     {VK_FORMAT_ASTC_10x8_UNORM_BLOCK,       {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}},
215     {VK_FORMAT_ASTC_10x8_SRGB_BLOCK,        {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}},
216     {VK_FORMAT_ASTC_10x10_UNORM_BLOCK,      {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}},
217     {VK_FORMAT_ASTC_10x10_SRGB_BLOCK,       {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}},
218     {VK_FORMAT_ASTC_12x10_UNORM_BLOCK,      {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}},
219     {VK_FORMAT_ASTC_12x10_SRGB_BLOCK,       {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}},
220     {VK_FORMAT_ASTC_12x12_UNORM_BLOCK,      {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT}},
221     {VK_FORMAT_ASTC_12x12_SRGB_BLOCK,       {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT}},
222     {VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT }},
223     {VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}},
224     {VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}},
225     {VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}},
226     {VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG,  {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}},
227     {VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG,  {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}},
228     {VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG,  {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}},
229     {VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG,  {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}},
230 };
231 
232 // Return true if format is a depth or stencil format
vk_format_is_depth_or_stencil(VkFormat format)233 VK_LAYER_EXPORT bool vk_format_is_depth_or_stencil(VkFormat format) {
234     return (vk_format_is_depth_and_stencil(format) || vk_format_is_depth_only(format) || vk_format_is_stencil_only(format));
235 }
236 
237 // Return true if format contains depth and stencil information
vk_format_is_depth_and_stencil(VkFormat format)238 VK_LAYER_EXPORT bool vk_format_is_depth_and_stencil(VkFormat format) {
239     bool is_ds = false;
240 
241     switch (format) {
242     case VK_FORMAT_D16_UNORM_S8_UINT:
243     case VK_FORMAT_D24_UNORM_S8_UINT:
244     case VK_FORMAT_D32_SFLOAT_S8_UINT:
245         is_ds = true;
246         break;
247     default:
248         break;
249     }
250     return is_ds;
251 }
252 
253 // Return true if format is a stencil-only format
vk_format_is_stencil_only(VkFormat format)254 VK_LAYER_EXPORT bool vk_format_is_stencil_only(VkFormat format) { return (format == VK_FORMAT_S8_UINT); }
255 
256 // Return true if format is a depth-only format
vk_format_is_depth_only(VkFormat format)257 VK_LAYER_EXPORT bool vk_format_is_depth_only(VkFormat format) {
258     bool is_depth = false;
259 
260     switch (format) {
261     case VK_FORMAT_D16_UNORM:
262     case VK_FORMAT_X8_D24_UNORM_PACK32:
263     case VK_FORMAT_D32_SFLOAT:
264         is_depth = true;
265         break;
266     default:
267         break;
268     }
269 
270     return is_depth;
271 }
272 
273 // Return true if format is of time UNORM
vk_format_is_norm(VkFormat format)274 VK_LAYER_EXPORT bool vk_format_is_norm(VkFormat format) {
275     bool is_norm = false;
276 
277     switch (format) {
278     case VK_FORMAT_R4G4_UNORM_PACK8:
279     case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
280     case VK_FORMAT_R5G6B5_UNORM_PACK16:
281     case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
282     case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
283     case VK_FORMAT_R8_UNORM:
284     case VK_FORMAT_R8_SNORM:
285     case VK_FORMAT_R8G8_UNORM:
286     case VK_FORMAT_R8G8_SNORM:
287     case VK_FORMAT_R8G8B8_UNORM:
288     case VK_FORMAT_R8G8B8_SNORM:
289     case VK_FORMAT_R8G8B8A8_UNORM:
290     case VK_FORMAT_R8G8B8A8_SNORM:
291     case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
292     case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
293     case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
294     case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
295     case VK_FORMAT_R16_UNORM:
296     case VK_FORMAT_R16_SNORM:
297     case VK_FORMAT_R16G16_UNORM:
298     case VK_FORMAT_R16G16_SNORM:
299     case VK_FORMAT_R16G16B16_UNORM:
300     case VK_FORMAT_R16G16B16_SNORM:
301     case VK_FORMAT_R16G16B16A16_UNORM:
302     case VK_FORMAT_R16G16B16A16_SNORM:
303     case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
304     case VK_FORMAT_BC2_UNORM_BLOCK:
305     case VK_FORMAT_BC3_UNORM_BLOCK:
306     case VK_FORMAT_BC4_UNORM_BLOCK:
307     case VK_FORMAT_BC4_SNORM_BLOCK:
308     case VK_FORMAT_BC5_UNORM_BLOCK:
309     case VK_FORMAT_BC5_SNORM_BLOCK:
310     case VK_FORMAT_BC7_UNORM_BLOCK:
311     case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
312     case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
313     case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
314     case VK_FORMAT_EAC_R11_UNORM_BLOCK:
315     case VK_FORMAT_EAC_R11_SNORM_BLOCK:
316     case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
317     case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
318     case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
319     case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
320     case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
321     case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
322     case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
323     case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
324     case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
325     case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
326     case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
327     case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
328     case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
329     case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
330     case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
331     case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
332     case VK_FORMAT_B5G6R5_UNORM_PACK16:
333     case VK_FORMAT_B8G8R8_UNORM:
334     case VK_FORMAT_B8G8R8_SNORM:
335     case VK_FORMAT_B8G8R8A8_UNORM:
336     case VK_FORMAT_B8G8R8A8_SNORM:
337     case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
338     case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
339         is_norm = true;
340         break;
341     default:
342         break;
343     }
344 
345     return is_norm;
346 };
347 
348 // Return true if format is an integer format
vk_format_is_int(VkFormat format)349 VK_LAYER_EXPORT bool vk_format_is_int(VkFormat format) { return (vk_format_is_sint(format) || vk_format_is_uint(format)); }
350 
351 // Return true if format is an unsigned integer format
vk_format_is_uint(VkFormat format)352 VK_LAYER_EXPORT bool vk_format_is_uint(VkFormat format) {
353     bool is_uint = false;
354 
355     switch (format) {
356     case VK_FORMAT_R8_UINT:
357     case VK_FORMAT_R8G8_UINT:
358     case VK_FORMAT_R8G8B8_UINT:
359     case VK_FORMAT_R8G8B8A8_UINT:
360     case VK_FORMAT_A8B8G8R8_UINT_PACK32:
361     case VK_FORMAT_A2B10G10R10_UINT_PACK32:
362     case VK_FORMAT_R16_UINT:
363     case VK_FORMAT_R16G16_UINT:
364     case VK_FORMAT_R16G16B16_UINT:
365     case VK_FORMAT_R16G16B16A16_UINT:
366     case VK_FORMAT_R32_UINT:
367     case VK_FORMAT_R32G32_UINT:
368     case VK_FORMAT_R32G32B32_UINT:
369     case VK_FORMAT_R32G32B32A32_UINT:
370     case VK_FORMAT_R64_UINT:
371     case VK_FORMAT_R64G64_UINT:
372     case VK_FORMAT_R64G64B64_UINT:
373     case VK_FORMAT_R64G64B64A64_UINT:
374     case VK_FORMAT_B8G8R8_UINT:
375     case VK_FORMAT_B8G8R8A8_UINT:
376     case VK_FORMAT_A2R10G10B10_UINT_PACK32:
377         is_uint = true;
378         break;
379     default:
380         break;
381     }
382 
383     return is_uint;
384 }
385 
386 // Return true if format is a signed integer format
vk_format_is_sint(VkFormat format)387 VK_LAYER_EXPORT bool vk_format_is_sint(VkFormat format) {
388     bool is_sint = false;
389 
390     switch (format) {
391     case VK_FORMAT_R8_SINT:
392     case VK_FORMAT_R8G8_SINT:
393     case VK_FORMAT_R8G8B8_SINT:
394     case VK_FORMAT_R8G8B8A8_SINT:
395     case VK_FORMAT_A8B8G8R8_SINT_PACK32:
396     case VK_FORMAT_A2B10G10R10_SINT_PACK32:
397     case VK_FORMAT_R16_SINT:
398     case VK_FORMAT_R16G16_SINT:
399     case VK_FORMAT_R16G16B16_SINT:
400     case VK_FORMAT_R16G16B16A16_SINT:
401     case VK_FORMAT_R32_SINT:
402     case VK_FORMAT_R32G32_SINT:
403     case VK_FORMAT_R32G32B32_SINT:
404     case VK_FORMAT_R32G32B32A32_SINT:
405     case VK_FORMAT_R64_SINT:
406     case VK_FORMAT_R64G64_SINT:
407     case VK_FORMAT_R64G64B64_SINT:
408     case VK_FORMAT_R64G64B64A64_SINT:
409     case VK_FORMAT_B8G8R8_SINT:
410     case VK_FORMAT_B8G8R8A8_SINT:
411     case VK_FORMAT_A2R10G10B10_SINT_PACK32:
412         is_sint = true;
413         break;
414     default:
415         break;
416     }
417 
418     return is_sint;
419 }
420 
421 // Return true if format is a floating-point format
vk_format_is_float(VkFormat format)422 VK_LAYER_EXPORT bool vk_format_is_float(VkFormat format) {
423     bool is_float = false;
424 
425     switch (format) {
426     case VK_FORMAT_R16_SFLOAT:
427     case VK_FORMAT_R16G16_SFLOAT:
428     case VK_FORMAT_R16G16B16_SFLOAT:
429     case VK_FORMAT_R16G16B16A16_SFLOAT:
430     case VK_FORMAT_R32_SFLOAT:
431     case VK_FORMAT_R32G32_SFLOAT:
432     case VK_FORMAT_R32G32B32_SFLOAT:
433     case VK_FORMAT_R32G32B32A32_SFLOAT:
434     case VK_FORMAT_R64_SFLOAT:
435     case VK_FORMAT_R64G64_SFLOAT:
436     case VK_FORMAT_R64G64B64_SFLOAT:
437     case VK_FORMAT_R64G64B64A64_SFLOAT:
438     case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
439     case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
440     case VK_FORMAT_BC6H_UFLOAT_BLOCK:
441     case VK_FORMAT_BC6H_SFLOAT_BLOCK:
442         is_float = true;
443         break;
444     default:
445         break;
446     }
447 
448     return is_float;
449 }
450 
451 // Return true if format is in the SRGB colorspace
vk_format_is_srgb(VkFormat format)452 VK_LAYER_EXPORT bool vk_format_is_srgb(VkFormat format) {
453     bool is_srgb = false;
454 
455     switch (format) {
456     case VK_FORMAT_R8_SRGB:
457     case VK_FORMAT_R8G8_SRGB:
458     case VK_FORMAT_R8G8B8_SRGB:
459     case VK_FORMAT_R8G8B8A8_SRGB:
460     case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
461     case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
462     case VK_FORMAT_BC2_SRGB_BLOCK:
463     case VK_FORMAT_BC3_SRGB_BLOCK:
464     case VK_FORMAT_BC7_SRGB_BLOCK:
465     case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
466     case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
467     case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
468     case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
469     case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
470     case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
471     case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
472     case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
473     case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
474     case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
475     case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
476     case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
477     case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
478     case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
479     case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
480     case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
481     case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
482     case VK_FORMAT_B8G8R8_SRGB:
483     case VK_FORMAT_B8G8R8A8_SRGB:
484         is_srgb = true;
485         break;
486     default:
487         break;
488     }
489 
490     return is_srgb;
491 }
492 
493 // Return true if format is compressed
vk_format_is_compressed(VkFormat format)494 VK_LAYER_EXPORT bool vk_format_is_compressed(VkFormat format) {
495     switch (format) {
496     case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
497     case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
498     case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
499     case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
500     case VK_FORMAT_BC2_UNORM_BLOCK:
501     case VK_FORMAT_BC2_SRGB_BLOCK:
502     case VK_FORMAT_BC3_UNORM_BLOCK:
503     case VK_FORMAT_BC3_SRGB_BLOCK:
504     case VK_FORMAT_BC4_UNORM_BLOCK:
505     case VK_FORMAT_BC4_SNORM_BLOCK:
506     case VK_FORMAT_BC5_UNORM_BLOCK:
507     case VK_FORMAT_BC5_SNORM_BLOCK:
508     case VK_FORMAT_BC6H_UFLOAT_BLOCK:
509     case VK_FORMAT_BC6H_SFLOAT_BLOCK:
510     case VK_FORMAT_BC7_UNORM_BLOCK:
511     case VK_FORMAT_BC7_SRGB_BLOCK:
512     case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
513     case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
514     case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
515     case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
516     case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
517     case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
518     case VK_FORMAT_EAC_R11_UNORM_BLOCK:
519     case VK_FORMAT_EAC_R11_SNORM_BLOCK:
520     case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
521     case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
522     case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
523     case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
524     case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
525     case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
526     case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
527     case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
528     case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
529     case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
530     case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
531     case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
532     case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
533     case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
534     case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
535     case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
536     case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
537     case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
538     case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
539     case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
540     case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
541     case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
542     case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
543     case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
544     case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
545     case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
546     case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
547     case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
548     case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
549     case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
550         return true;
551     default:
552         return false;
553     }
554 }
555 
556 // Return compressed block sizes for block compressed formats
vk_format_compressed_block_size(VkFormat format)557 VK_LAYER_EXPORT VkExtent2D vk_format_compressed_block_size(VkFormat format) {
558     VkExtent2D block_size = { 1, 1 };
559     switch (format) {
560     case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
561     case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
562     case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
563     case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
564     case VK_FORMAT_BC2_UNORM_BLOCK:
565     case VK_FORMAT_BC2_SRGB_BLOCK:
566     case VK_FORMAT_BC3_UNORM_BLOCK:
567     case VK_FORMAT_BC3_SRGB_BLOCK:
568     case VK_FORMAT_BC4_UNORM_BLOCK:
569     case VK_FORMAT_BC4_SNORM_BLOCK:
570     case VK_FORMAT_BC5_UNORM_BLOCK:
571     case VK_FORMAT_BC5_SNORM_BLOCK:
572     case VK_FORMAT_BC6H_UFLOAT_BLOCK:
573     case VK_FORMAT_BC6H_SFLOAT_BLOCK:
574     case VK_FORMAT_BC7_UNORM_BLOCK:
575     case VK_FORMAT_BC7_SRGB_BLOCK:
576     case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
577     case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
578     case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
579     case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
580     case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
581     case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
582     case VK_FORMAT_EAC_R11_UNORM_BLOCK:
583     case VK_FORMAT_EAC_R11_SNORM_BLOCK:
584     case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
585     case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
586     case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
587     case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
588         block_size = { 4, 4 };
589         break;
590     case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
591     case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
592         block_size = { 5, 4 };
593         break;
594     case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
595     case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
596         block_size = { 5, 5 };
597         break;
598     case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
599     case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
600         block_size = { 6, 5 };
601         break;
602     case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
603     case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
604         block_size = { 6, 6 };
605         break;
606     case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
607     case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
608         block_size = { 8, 5 };
609         break;
610     case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
611     case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
612         block_size = { 8, 6 };
613         break;
614     case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
615     case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
616         block_size = { 8, 8 };
617         break;
618     case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
619     case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
620         block_size = { 10, 5 };
621         break;
622     case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
623     case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
624         block_size = { 10, 6 };
625         break;
626     case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
627     case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
628         block_size = { 10, 8 };
629         break;
630     case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
631     case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
632         block_size = { 10, 10 };
633         break;
634     case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
635     case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
636         block_size = { 12, 10 };
637         break;
638     case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
639     case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
640         block_size = { 12, 12 };
641         break;
642     default:
643         break;
644     }
645     return block_size;
646 }
647 
648 // Return format class of the specified format
vk_format_get_compatibility_class(VkFormat format)649 VK_LAYER_EXPORT VkFormatCompatibilityClass vk_format_get_compatibility_class(VkFormat format) {
650     auto item = vk_format_table.find(format);
651     if (item != vk_format_table.end()) {
652         return item->second.format_class;
653     }
654     return VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT;
655 }
656 
657 // Return size, in bytes, of a pixel of the specified format
vk_format_get_size(VkFormat format)658 VK_LAYER_EXPORT size_t vk_format_get_size(VkFormat format) {
659     auto item = vk_format_table.find(format);
660     if (item != vk_format_table.end()) {
661         return item->second.size;
662     }
663     return 0;
664 }
665 
666 // Return the number of channels for a given format
vk_format_get_channel_count(VkFormat format)667 unsigned int vk_format_get_channel_count(VkFormat format) {
668     auto item = vk_format_table.find(format);
669     if (item != vk_format_table.end()) {
670         return item->second.channel_count;
671     }
672     return 0;
673 }
674 
675 // Perform a zero-tolerant modulo operation
vk_safe_modulo(VkDeviceSize dividend,VkDeviceSize divisor)676 VK_LAYER_EXPORT VkDeviceSize vk_safe_modulo(VkDeviceSize dividend, VkDeviceSize divisor) {
677     VkDeviceSize result = 0;
678     if (divisor != 0) {
679         result = dividend % divisor;
680     }
681     return result;
682 }
683 
684 static const uint8_t UTF8_ONE_BYTE_CODE = 0xC0;
685 static const uint8_t UTF8_ONE_BYTE_MASK = 0xE0;
686 static const uint8_t UTF8_TWO_BYTE_CODE = 0xE0;
687 static const uint8_t UTF8_TWO_BYTE_MASK = 0xF0;
688 static const uint8_t UTF8_THREE_BYTE_CODE = 0xF0;
689 static const uint8_t UTF8_THREE_BYTE_MASK = 0xF8;
690 static const uint8_t UTF8_DATA_BYTE_CODE = 0x80;
691 static const uint8_t UTF8_DATA_BYTE_MASK = 0xC0;
692 
vk_string_validate(const int max_length,const char * utf8)693 VK_LAYER_EXPORT VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) {
694     VkStringErrorFlags result = VK_STRING_ERROR_NONE;
695     int num_char_bytes = 0;
696     int i, j;
697 
698     for (i = 0; i < max_length; i++) {
699         if (utf8[i] == 0) {
700             break;
701         } else if ((utf8[i] >= 0xa) && (utf8[i] < 0x7f)) {
702             num_char_bytes = 0;
703         } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) {
704             num_char_bytes = 1;
705         } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) {
706             num_char_bytes = 2;
707         } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) {
708             num_char_bytes = 3;
709         } else {
710             result = VK_STRING_ERROR_BAD_DATA;
711         }
712 
713         // Validate the following num_char_bytes of data
714         for (j = 0; (j < num_char_bytes) && (i < max_length); j++) {
715             if (++i == max_length) {
716                 result |= VK_STRING_ERROR_LENGTH;
717                 break;
718             }
719             if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) {
720                 result |= VK_STRING_ERROR_BAD_DATA;
721             }
722         }
723     }
724     return result;
725 }
726 
727 // Utility function for finding a text string in another string
white_list(const char * item,const char * list)728 VK_LAYER_EXPORT bool white_list(const char *item, const char *list) {
729     std::string candidate(item);
730     std::string white_list(list);
731     return (white_list.find(candidate) != std::string::npos);
732 }
733 
734 // Debug callbacks get created in three ways:
735 //   o  Application-defined debug callbacks
736 //   o  Through settings in a vk_layer_settings.txt file
737 //   o  By default, if neither an app-defined debug callback nor a vk_layer_settings.txt file is present
738 //
739 // At layer initialization time, default logging callbacks are created to output layer error messages.
740 // If a vk_layer_settings.txt file is present its settings will override any default settings.
741 //
742 // If a vk_layer_settings.txt file is present and an application defines a debug callback, both callbacks
743 // will be active.  If no vk_layer_settings.txt file is present, creating an application-defined debug
744 // callback will cause the default callbacks to be unregisterd and removed.
layer_debug_actions(debug_report_data * report_data,std::vector<VkDebugReportCallbackEXT> & logging_callback,const VkAllocationCallbacks * pAllocator,const char * layer_identifier)745 VK_LAYER_EXPORT void layer_debug_actions(debug_report_data *report_data, std::vector<VkDebugReportCallbackEXT> &logging_callback,
746                                          const VkAllocationCallbacks *pAllocator, const char *layer_identifier) {
747 
748     VkDebugReportCallbackEXT callback = VK_NULL_HANDLE;
749 
750     std::string report_flags_key = layer_identifier;
751     std::string debug_action_key = layer_identifier;
752     std::string log_filename_key = layer_identifier;
753     report_flags_key.append(".report_flags");
754     debug_action_key.append(".debug_action");
755     log_filename_key.append(".log_filename");
756 
757     // Initialize layer options
758     VkDebugReportFlagsEXT report_flags = GetLayerOptionFlags(report_flags_key, report_flags_option_definitions, 0);
759     VkLayerDbgActionFlags debug_action = GetLayerOptionFlags(debug_action_key, debug_actions_option_definitions, 0);
760     // Flag as default if these settings are not from a vk_layer_settings.txt file
761     bool default_layer_callback = (debug_action & VK_DBG_LAYER_ACTION_DEFAULT) ? true : false;
762 
763     if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) {
764         const char *log_filename = getLayerOption(log_filename_key.c_str());
765         FILE *log_output = getLayerLogOutput(log_filename, layer_identifier);
766         VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
767         memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
768         dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
769         dbgCreateInfo.flags = report_flags;
770         dbgCreateInfo.pfnCallback = log_callback;
771         dbgCreateInfo.pUserData = (void *)log_output;
772         layer_create_msg_callback(report_data, default_layer_callback, &dbgCreateInfo, pAllocator, &callback);
773         logging_callback.push_back(callback);
774     }
775 
776     callback = VK_NULL_HANDLE;
777 
778     if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
779         VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
780         memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
781         dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
782         dbgCreateInfo.flags = report_flags;
783         dbgCreateInfo.pfnCallback = win32_debug_output_msg;
784         dbgCreateInfo.pUserData = NULL;
785         layer_create_msg_callback(report_data, default_layer_callback, &dbgCreateInfo, pAllocator, &callback);
786         logging_callback.push_back(callback);
787     }
788 }
789