dawn-cmake/src/tint/inspector/resource_binding.h
Ben Clayton 1131d31761 tint/ast: Remove ast::StorageTexture
Instead use ast::TypeName.

Also improve the validation and diagnostics around providing template
arguments to types that do not accept them.

Bug: tint:1810
Change-Id: I4241d50ce0425ab721157686889e918993482876
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119284
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2023-02-10 19:24:24 +00:00

129 lines
3.9 KiB
C++

// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_INSPECTOR_RESOURCE_BINDING_H_
#define SRC_TINT_INSPECTOR_RESOURCE_BINDING_H_
#include <cstdint>
#include "src/tint/type/texel_format.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/type/type.h"
namespace tint::inspector {
/// Container for information about how a resource is bound
struct ResourceBinding {
/// The dimensionality of a texture
enum class TextureDimension {
/// Invalid texture
kNone = -1,
/// 1 dimensional texture
k1d,
/// 2 dimensional texture
k2d,
/// 2 dimensional array texture
k2dArray,
/// 3 dimensional texture
k3d,
/// cube texture
kCube,
/// cube array texture
kCubeArray,
};
/// Component type of the texture's data. Same as the Sampled Type parameter
/// in SPIR-V OpTypeImage.
enum class SampledKind { kUnknown = -1, kFloat, kUInt, kSInt };
/// Enumerator of texel image formats
enum class TexelFormat {
kNone = -1,
kBgra8Unorm,
kRgba8Unorm,
kRgba8Snorm,
kRgba8Uint,
kRgba8Sint,
kRgba16Uint,
kRgba16Sint,
kRgba16Float,
kR32Uint,
kR32Sint,
kR32Float,
kRg32Uint,
kRg32Sint,
kRg32Float,
kRgba32Uint,
kRgba32Sint,
kRgba32Float,
};
/// kXXX maps to entries returned by GetXXXResourceBindings call.
enum class ResourceType {
kUniformBuffer,
kStorageBuffer,
kReadOnlyStorageBuffer,
kSampler,
kComparisonSampler,
kSampledTexture,
kMultisampledTexture,
kWriteOnlyStorageTexture,
kDepthTexture,
kDepthMultisampledTexture,
kExternalTexture
};
/// Type of resource that is bound.
ResourceType resource_type;
/// Bind group the binding belongs
uint32_t bind_group;
/// Identifier to identify this binding within the bind group
uint32_t binding;
/// Size for this binding, in bytes, if defined.
uint64_t size;
/// Size for this binding without trailing structure padding, in bytes, if
/// defined.
uint64_t size_no_padding;
/// Dimensionality of this binding, if defined.
TextureDimension dim;
/// Kind of data being sampled, if defined.
SampledKind sampled_kind;
/// Format of data, if defined.
TexelFormat image_format;
};
/// Convert from internal type::TextureDimension to public
/// ResourceBinding::TextureDimension
/// @param type_dim internal value to convert from
/// @returns the publicly visible equivalent
ResourceBinding::TextureDimension TypeTextureDimensionToResourceBindingTextureDimension(
const type::TextureDimension& type_dim);
/// Infer ResourceBinding::SampledKind for a given type::Type
/// @param base_type internal type to infer from
/// @returns the publicly visible equivalent
ResourceBinding::SampledKind BaseTypeToSampledKind(const type::Type* base_type);
/// Convert from internal type::TexelFormat to public
/// ResourceBinding::TexelFormat
/// @param image_format internal value to convert from
/// @returns the publicly visible equivalent
ResourceBinding::TexelFormat TypeTexelFormatToResourceBindingTexelFormat(
const type::TexelFormat& image_format);
} // namespace tint::inspector
#endif // SRC_TINT_INSPECTOR_RESOURCE_BINDING_H_