dawn-cmake/src/dawn_native/BindingInfo.h
Austin Eng a5f24e590a Validate textures with filtering/non-filtering/comparison samplers
Renames dawn_native::ComponentTypeBit to SampleTypeBit and makes
the bitmask match wgpu::TextureSampleType. wgpu::TextureComponentType
should be removed in a follow-up CL.

The Format table is augmented with float/unfilterable-float information
so that textures can be validated against the BGLEntry's
TextureSampleType.

EntryPointMetadata::ShaderBindingInfo no longer inherits BindingInfo
because the two types are diverging further. Most notably, this CL
reflects from Tint the supported SampleTypeBits for texture bindings.
This bitset is validated against the bind group layout.

Adds an isFiltering getter to SamplerBase. A filtering sampler must
not be used with a non-filtering sampler binding.

Lastly, the CL reflects sampler/texture pairs from Tint and validates
an entrypoint against the pipeline layout that a filtering sampler is
not used with an unfilterable-float texture binding.

Bug: dawn:367
Change-Id: If9f2c0d8fbad5641c2ecc30615a3c68a6ed6150a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/56521
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Commit-Queue: Austin Eng <enga@chromium.org>
2021-07-02 02:29:40 +00:00

99 lines
3.6 KiB
C++

// Copyright 2020 The Dawn 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 DAWNNATIVE_BINDINGINFO_H_
#define DAWNNATIVE_BINDINGINFO_H_
#include "common/Constants.h"
#include "common/ityp_array.h"
#include "dawn_native/Error.h"
#include "dawn_native/Format.h"
#include "dawn_native/IntegerTypes.h"
#include "dawn_native/PerStage.h"
#include "dawn_native/dawn_platform.h"
#include <cstdint>
namespace dawn_native {
// Not a real WebGPU limit, but the sum of the two limits is useful for internal optimizations.
static constexpr uint32_t kMaxDynamicBuffersPerPipelineLayout =
kMaxDynamicUniformBuffersPerPipelineLayout + kMaxDynamicStorageBuffersPerPipelineLayout;
static constexpr BindingIndex kMaxDynamicBuffersPerPipelineLayoutTyped =
BindingIndex(kMaxDynamicBuffersPerPipelineLayout);
// Not a real WebGPU limit, but used to optimize parts of Dawn which expect valid usage of the
// API. There should never be more bindings than the max per stage, for each stage.
static constexpr uint32_t kMaxBindingsPerPipelineLayout =
3 * (kMaxSampledTexturesPerShaderStage + kMaxSamplersPerShaderStage +
kMaxStorageBuffersPerShaderStage + kMaxStorageTexturesPerShaderStage +
kMaxUniformBuffersPerShaderStage);
static constexpr BindingIndex kMaxBindingsPerPipelineLayoutTyped =
BindingIndex(kMaxBindingsPerPipelineLayout);
// TODO(enga): Figure out a good number for this.
static constexpr uint32_t kMaxOptimalBindingsPerGroup = 32;
enum class BindingInfoType { Buffer, Sampler, Texture, StorageTexture, ExternalTexture };
struct BindingInfo {
BindingNumber binding;
wgpu::ShaderStage visibility;
BindingInfoType bindingType;
// TODO(dawn:527): These four values could be made into a union.
BufferBindingLayout buffer;
SamplerBindingLayout sampler;
TextureBindingLayout texture;
StorageTextureBindingLayout storageTexture;
};
struct BindingSlot {
BindGroupIndex group;
BindingNumber binding;
};
struct PerStageBindingCounts {
uint32_t sampledTextureCount;
uint32_t samplerCount;
uint32_t storageBufferCount;
uint32_t storageTextureCount;
uint32_t uniformBufferCount;
uint32_t externalTextureCount;
};
struct BindingCounts {
uint32_t totalCount;
uint32_t bufferCount;
uint32_t unverifiedBufferCount; // Buffers with minimum buffer size unspecified
uint32_t dynamicUniformBufferCount;
uint32_t dynamicStorageBufferCount;
PerStage<PerStageBindingCounts> perStage;
};
void IncrementBindingCounts(BindingCounts* bindingCounts, const BindGroupLayoutEntry& entry);
void AccumulateBindingCounts(BindingCounts* bindingCounts, const BindingCounts& rhs);
MaybeError ValidateBindingCounts(const BindingCounts& bindingCounts);
// For buffer size validation
using RequiredBufferSizes = ityp::array<BindGroupIndex, std::vector<uint64_t>, kMaxBindGroups>;
} // namespace dawn_native
#endif // DAWNNATIVE_BINDINGINFO_H_