chromium/third_party/dawn/src/dawn/native/IntegerTypes.h

// Copyright 2020 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef SRC_DAWN_NATIVE_INTEGERTYPES_H_
#define SRC_DAWN_NATIVE_INTEGERTYPES_H_

#include <cstdint>

#include "dawn/common/Constants.h"
#include "dawn/common/TypedInteger.h"

namespace dawn::ityp {
template <typename Index, typename Value, size_t Size>
class array;

template <typename Index, size_t N>
class bitset;
}  // namespace dawn::ityp

// This files creates a number of integer types using ityp to represent the zoo of indices used all
// over the codebase, so that the semantic of numbers is clear from the types, but also so it is
// harder to use the wrong type to index into array, bitsets and other containers.
//
// In addition various container type aliases are declared so that they have a consistent name
// everywhere and don't need explicit sizing with the kMaxStuff constants. Respective ityp::
// headers still need to be #included in the files using them though.

namespace dawn::native {

// Binding numbers in the shader and BindGroup/BindGroupLayoutDescriptors
BindingNumber;
constexpr BindingNumber kMaxBindingsPerBindGroupTyped =;

// Binding numbers get mapped to a packed range of indices
BindingIndex;

// Bind group indinces represent the index in the SetBindGroup, the index in
// wgpu::PipelineLayoutDescriptor::bindGroupLayouts and friends.
BindGroupIndex;
constexpr BindGroupIndex kMaxBindGroupsTyped =;

BindGroupMask;
PerBindGroup;

// Color attachment indices represent the index in the wgpu::FragmentState::targets array, the
// wgpu::RenderPassDescriptor::colorAttachments arry and other similar arrays.
ColorAttachmentIndex;
constexpr ColorAttachmentIndex kMaxColorAttachmentsTyped =;

ColorAttachmentMask;
PerColorAttachment;

// Vertex buffer slots represent the `slot` passed in calls to SetVertexBuffer or the index in the
// wgpu::VertexState::vertexBuffers array.
VertexBufferSlot;
constexpr VertexBufferSlot kMaxVertexBuffersTyped =;

VertexBufferMask;
PerVertexBuffer;

// Vertex attribute locations represent the "shaderLocation" in wgpu::VertexAttribute.
VertexAttributeLocation;
constexpr VertexAttributeLocation kMaxVertexAttributesTyped =;

VertexAttributeMask;
PerVertexAttribute;

// Serials are 64bit integers that are incremented by one each time to produce unique values.
// Some serials (like queue serials) are compared numerically to know which one is before
// another, while some serials are only checked for equality. We call serials only checked
// for equality IDs.

// Buffer mapping requests are stored outside of the buffer while they are being processed and
// cannot be invalidated. Instead they are associated with an ID, and when a map request is
// finished, the mapping callback is fired only if its ID matches the ID if the last request
// that was sent.
MapRequestID;

// The type for the WebGPU API fence serial values.
FenceAPISerial;

// A serial used to watch the progression of GPU execution on a queue, each time operations
// that need to be followed individually are scheduled for execution on a queue, the serial
// is incremented by one. This way to know if something is done executing, we just need to
// compare its serial with the currently completed serial.
ExecutionSerial;
constexpr ExecutionSerial kMaxExecutionSerial =;
constexpr ExecutionSerial kBeginningOfGPUTime =;

// An identifier that indicates which Pipeline a BindGroupLayout is compatible with. Pipelines
// created with a default layout will produce BindGroupLayouts with a non-zero compatibility
// token, which prevents them (and any BindGroups created with them) from being used with any
// other pipelines.
PipelineCompatibilityToken;
constexpr PipelineCompatibilityToken kExplicitPCT =;

Nanoseconds;

}  // namespace dawn::native

#endif  // SRC_DAWN_NATIVE_INTEGERTYPES_H_