• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_INSPECTOR_RESOURCE_BINDING_H_
16 #define SRC_INSPECTOR_RESOURCE_BINDING_H_
17 
18 #include <cstdint>
19 
20 #include "src/ast/storage_texture.h"
21 #include "src/ast/texture.h"
22 
23 namespace tint {
24 namespace inspector {
25 
26 /// Container for information about how a resource is bound
27 struct ResourceBinding {
28   /// The dimensionality of a texture
29   enum class TextureDimension {
30     /// Invalid texture
31     kNone = -1,
32     /// 1 dimensional texture
33     k1d,
34     /// 2 dimensional texture
35     k2d,
36     /// 2 dimensional array texture
37     k2dArray,
38     /// 3 dimensional texture
39     k3d,
40     /// cube texture
41     kCube,
42     /// cube array texture
43     kCubeArray,
44   };
45 
46   /// Component type of the texture's data. Same as the Sampled Type parameter
47   /// in SPIR-V OpTypeImage.
48   enum class SampledKind { kUnknown = -1, kFloat, kUInt, kSInt };
49 
50   /// Enumerator of texture image formats
51   enum class ImageFormat {
52     kNone = -1,
53     kR8Unorm,
54     kR8Snorm,
55     kR8Uint,
56     kR8Sint,
57     kR16Uint,
58     kR16Sint,
59     kR16Float,
60     kRg8Unorm,
61     kRg8Snorm,
62     kRg8Uint,
63     kRg8Sint,
64     kR32Uint,
65     kR32Sint,
66     kR32Float,
67     kRg16Uint,
68     kRg16Sint,
69     kRg16Float,
70     kRgba8Unorm,
71     kRgba8UnormSrgb,
72     kRgba8Snorm,
73     kRgba8Uint,
74     kRgba8Sint,
75     kBgra8Unorm,
76     kBgra8UnormSrgb,
77     kRgb10A2Unorm,
78     kRg11B10Float,
79     kRg32Uint,
80     kRg32Sint,
81     kRg32Float,
82     kRgba16Uint,
83     kRgba16Sint,
84     kRgba16Float,
85     kRgba32Uint,
86     kRgba32Sint,
87     kRgba32Float,
88   };
89 
90   /// kXXX maps to entries returned by GetXXXResourceBindings call.
91   enum class ResourceType {
92     kUniformBuffer,
93     kStorageBuffer,
94     kReadOnlyStorageBuffer,
95     kSampler,
96     kComparisonSampler,
97     kSampledTexture,
98     kMultisampledTexture,
99     kWriteOnlyStorageTexture,
100     kDepthTexture,
101     kDepthMultisampledTexture,
102     kExternalTexture
103   };
104 
105   /// Type of resource that is bound.
106   ResourceType resource_type;
107   /// Bind group the binding belongs
108   uint32_t bind_group;
109   /// Identifier to identify this binding within the bind group
110   uint32_t binding;
111   /// Size for this binding, in bytes, if defined.
112   uint64_t size;
113   /// Size for this binding without trailing structure padding, in bytes, if
114   /// defined.
115   uint64_t size_no_padding;
116   /// Dimensionality of this binding, if defined.
117   TextureDimension dim;
118   /// Kind of data being sampled, if defined.
119   SampledKind sampled_kind;
120   /// Format of data, if defined.
121   ImageFormat image_format;
122 };
123 
124 /// Convert from internal ast::TextureDimension to public
125 /// ResourceBinding::TextureDimension
126 /// @param type_dim internal value to convert from
127 /// @returns the publicly visible equivalent
128 ResourceBinding::TextureDimension
129 TypeTextureDimensionToResourceBindingTextureDimension(
130     const ast::TextureDimension& type_dim);
131 
132 /// Infer ResourceBinding::SampledKind for a given sem::Type
133 /// @param base_type internal type to infer from
134 /// @returns the publicly visible equivalent
135 ResourceBinding::SampledKind BaseTypeToSampledKind(const sem::Type* base_type);
136 
137 /// Convert from internal ast::ImageFormat to public
138 /// ResourceBinding::ImageFormat
139 /// @param image_format internal value to convert from
140 /// @returns the publicly visible equivalent
141 ResourceBinding::ImageFormat TypeImageFormatToResourceBindingImageFormat(
142     const ast::ImageFormat& image_format);
143 
144 }  // namespace inspector
145 }  // namespace tint
146 
147 #endif  // SRC_INSPECTOR_RESOURCE_BINDING_H_
148