#include "dawn/native/ShaderModule.h"
#include <algorithm>
#include <sstream>
#include <utility>
#include "dawn/common/BitSetIterator.h"
#include "dawn/common/Constants.h"
#include "dawn/common/MatchVariant.h"
#include "dawn/native/BindGroupLayoutInternal.h"
#include "dawn/native/ChainUtils.h"
#include "dawn/native/CompilationMessages.h"
#include "dawn/native/Device.h"
#include "dawn/native/Instance.h"
#include "dawn/native/ObjectContentHasher.h"
#include "dawn/native/Pipeline.h"
#include "dawn/native/PipelineLayout.h"
#include "dawn/native/RenderPipeline.h"
#include "dawn/native/Sampler.h"
#include "dawn/native/TintUtils.h"
#ifdef DAWN_ENABLE_SPIRV_VALIDATION
#include "dawn/native/SpirvValidation.h"
#endif
#include "tint/tint.h"
namespace dawn::native {
namespace {
ResultOrError<SingleShaderStage> TintPipelineStageToShaderStage(
tint::inspector::PipelineStage stage) { … }
BindingInfoType TintResourceTypeToBindingInfoType(
tint::inspector::ResourceBinding::ResourceType type) { … }
wgpu::TextureFormat TintImageFormatToTextureFormat(
tint::inspector::ResourceBinding::TexelFormat format) { … }
wgpu::TextureViewDimension TintTextureDimensionToTextureViewDimension(
tint::inspector::ResourceBinding::TextureDimension dim) { … }
wgpu::TextureSampleType TintSampledKindToSampleType(
tint::inspector::ResourceBinding::SampledKind s) { … }
ResultOrError<TextureComponentType> TintComponentTypeToTextureComponentType(
tint::inspector::ComponentType type) { … }
ResultOrError<VertexFormatBaseType> TintComponentTypeToVertexFormatBaseType(
tint::inspector::ComponentType type) { … }
ResultOrError<wgpu::BufferBindingType> TintResourceTypeToBufferBindingType(
tint::inspector::ResourceBinding::ResourceType resource_type) { … }
ResultOrError<wgpu::StorageTextureAccess> TintResourceTypeToStorageTextureAccess(
tint::inspector::ResourceBinding::ResourceType resource_type) { … }
ResultOrError<InterStageComponentType> TintComponentTypeToInterStageComponentType(
tint::inspector::ComponentType type) { … }
ResultOrError<uint32_t> TintCompositionTypeToInterStageComponentCount(
tint::inspector::CompositionType type) { … }
ResultOrError<InterpolationType> TintInterpolationTypeToInterpolationType(
tint::inspector::InterpolationType type) { … }
ResultOrError<InterpolationSampling> TintInterpolationSamplingToInterpolationSamplingType(
tint::inspector::InterpolationSampling type) { … }
EntryPointMetadata::Override::Type FromTintOverrideType(tint::inspector::Override::Type type) { … }
ResultOrError<PixelLocalMemberType> FromTintPixelLocalMemberType(
tint::inspector::PixelLocalMemberType type) { … }
ResultOrError<tint::Program> ParseWGSL(const tint::Source::File* file,
const tint::wgsl::AllowedFeatures& allowedFeatures,
const tint::wgsl::ValidationMode mode,
const std::vector<tint::wgsl::Extension>& internalExtensions,
OwnedCompilationMessages* outMessages) { … }
#if TINT_BUILD_SPV_READER
ResultOrError<tint::Program> ParseSPIRV(const std::vector<uint32_t>& spirv,
const tint::wgsl::AllowedFeatures& allowedFeatures,
OwnedCompilationMessages* outMessages,
const DawnShaderModuleSPIRVOptionsDescriptor* optionsDesc) {
tint::spirv::reader::Options options;
if (optionsDesc) {
options.allow_non_uniform_derivatives = optionsDesc->allowNonUniformDerivatives;
}
options.allowed_features = allowedFeatures;
tint::Program program = tint::spirv::reader::Read(spirv, options);
if (outMessages != nullptr) {
DAWN_TRY(outMessages->AddMessages(program.Diagnostics()));
}
if (!program.IsValid()) {
return DAWN_VALIDATION_ERROR("Error while parsing SPIR-V: %s\n",
program.Diagnostics().Str());
}
return std::move(program);
}
#endif
std::vector<uint64_t> GetBindGroupMinBufferSizes(const BindingGroupInfoMap& shaderBindings,
const BindGroupLayoutInternalBase* layout) { … }
bool IsShaderCompatibleWithPipelineLayoutOnStorageTextureAccess(
const StorageTextureBindingInfo& pipelineBindingLayout,
const StorageTextureBindingInfo& shaderBindingInfo) { … }
BindingInfoType GetShaderBindingType(const ShaderBindingInfo& shaderInfo) { … }
MaybeError ValidateCompatibilityOfSingleBindingWithLayout(const DeviceBase* device,
const BindGroupLayoutInternalBase* layout,
SingleShaderStage entryPointStage,
BindingNumber bindingNumber,
const ShaderBindingInfo& shaderInfo) { … }
MaybeError ValidateCompatibilityWithBindGroupLayout(DeviceBase* device,
BindGroupIndex group,
const EntryPointMetadata& entryPoint,
const BindGroupLayoutInternalBase* layout) { … }
ResultOrError<std::unique_ptr<EntryPointMetadata>> ReflectEntryPointUsingTint(
const DeviceBase* device,
tint::inspector::Inspector* inspector,
const tint::inspector::EntryPoint& entryPoint) { … }
MaybeError ReflectShaderUsingTint(const DeviceBase* device,
const tint::Program* program,
OwnedCompilationMessages* compilationMessages,
EntryPointMetadataTable* entryPointMetadataTable) { … }
}
ResultOrError<Extent3D> ValidateComputeStageWorkgroupSize(
const tint::Program& program,
const char* entryPointName,
const LimitsForCompilationRequest& limits,
std::optional<uint32_t> maxSubgroupSizeForFullSubgroups) { … }
ShaderModuleParseResult::ShaderModuleParseResult() = default;
ShaderModuleParseResult::~ShaderModuleParseResult() = default;
ShaderModuleParseResult::ShaderModuleParseResult(ShaderModuleParseResult&& rhs) = default;
ShaderModuleParseResult& ShaderModuleParseResult::operator=(ShaderModuleParseResult&& rhs) =
default;
bool ShaderModuleParseResult::HasParsedShader() const { … }
MaybeError ValidateAndParseShaderModule(
DeviceBase* device,
const UnpackedPtr<ShaderModuleDescriptor>& descriptor,
const std::vector<tint::wgsl::Extension>& internalExtensions,
ShaderModuleParseResult* parseResult,
OwnedCompilationMessages* outMessages) { … }
RequiredBufferSizes ComputeRequiredBufferSizesForLayout(const EntryPointMetadata& entryPoint,
const PipelineLayoutBase* layout) { … }
ResultOrError<tint::Program> RunTransforms(tint::ast::transform::Manager* transformManager,
const tint::Program* program,
const tint::ast::transform::DataMap& inputs,
tint::ast::transform::DataMap* outputs,
OwnedCompilationMessages* outMessages) { … }
MaybeError ValidateCompatibilityWithPipelineLayout(DeviceBase* device,
const EntryPointMetadata& entryPoint,
const PipelineLayoutBase* layout) { … }
ShaderModuleBase::ShaderModuleBase(DeviceBase* device,
const UnpackedPtr<ShaderModuleDescriptor>& descriptor,
std::vector<tint::wgsl::Extension> internalExtensions,
ApiObjectBase::UntrackedByDeviceTag tag)
: … { … }
ShaderModuleBase::ShaderModuleBase(DeviceBase* device,
const UnpackedPtr<ShaderModuleDescriptor>& descriptor,
std::vector<tint::wgsl::Extension> internalExtensions)
: … { … }
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
: … { … }
ShaderModuleBase::~ShaderModuleBase() = default;
void ShaderModuleBase::DestroyImpl() { … }
Ref<ShaderModuleBase> ShaderModuleBase::MakeError(DeviceBase* device, const char* label) { … }
ObjectType ShaderModuleBase::GetType() const { … }
bool ShaderModuleBase::HasEntryPoint(const std::string& entryPoint) const { … }
ShaderModuleEntryPoint ShaderModuleBase::ReifyEntryPointName(const char* entryPointName,
SingleShaderStage stage) const { … }
std::optional<bool> ShaderModuleBase::GetStrictMath() const { … }
const EntryPointMetadata& ShaderModuleBase::GetEntryPoint(const std::string& entryPoint) const { … }
size_t ShaderModuleBase::ComputeContentHash() { … }
bool ShaderModuleBase::EqualityFunc::operator()(const ShaderModuleBase* a,
const ShaderModuleBase* b) const { … }
ShaderModuleBase::ScopedUseTintProgram ShaderModuleBase::UseTintProgram() { … }
Ref<TintProgram> ShaderModuleBase::GetTintProgram() const { … }
Ref<TintProgram> ShaderModuleBase::GetTintProgramForTesting() const { … }
int ShaderModuleBase::GetTintProgramRecreateCountForTesting() const { … }
namespace {
void DefaultGetCompilationInfoCallback(WGPUCompilationInfoRequestStatus status,
const WGPUCompilationInfo* compilationInfo,
void* callback,
void* userdata) { … }
}
void ShaderModuleBase::APIGetCompilationInfo(wgpu::CompilationInfoCallback callback,
void* userdata) { … }
Future ShaderModuleBase::APIGetCompilationInfoF(const CompilationInfoCallbackInfo& callbackInfo) { … }
Future ShaderModuleBase::APIGetCompilationInfo2(
const WGPUCompilationInfoCallbackInfo2& callbackInfo) { … }
void ShaderModuleBase::InjectCompilationMessages(
std::unique_ptr<OwnedCompilationMessages> compilationMessages) { … }
OwnedCompilationMessages* ShaderModuleBase::GetCompilationMessages() const { … }
MaybeError ShaderModuleBase::InitializeBase(ShaderModuleParseResult* parseResult,
OwnedCompilationMessages* compilationMessages) { … }
void ShaderModuleBase::WillDropLastExternalRef() { … }
}