mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 04:06:01 +00:00
Improve validation errors for ShaderModule
Bug: dawn:563 Change-Id: I3c0809742f87517456fd8a5f7645005af636fa75 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65801 Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
a1e0aff8b8
commit
5497aad240
@ -21,6 +21,11 @@
|
|||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
|
// TODO(dawn:563):
|
||||||
|
// - Split the file between autogenerated parts and manually written parts.
|
||||||
|
// - Forward declare common Dawn enums and have AbslFormatConvert for them.
|
||||||
|
// - Support AbslFormatConvert for Dawn's typed integers.
|
||||||
|
|
||||||
//
|
//
|
||||||
// Structs (Manually written)
|
// Structs (Manually written)
|
||||||
//
|
//
|
||||||
|
@ -1405,8 +1405,9 @@ namespace dawn_native {
|
|||||||
ShaderModuleParseResult parseResult;
|
ShaderModuleParseResult parseResult;
|
||||||
|
|
||||||
if (IsValidationEnabled()) {
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateShaderModuleDescriptor(this, descriptor, &parseResult,
|
DAWN_TRY_CONTEXT(
|
||||||
compilationMessages));
|
ValidateShaderModuleDescriptor(this, descriptor, &parseResult, compilationMessages),
|
||||||
|
"validating %s", descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetOrCreateShaderModule(descriptor, &parseResult, compilationMessages);
|
return GetOrCreateShaderModule(descriptor, &parseResult, compilationMessages);
|
||||||
|
@ -33,29 +33,8 @@
|
|||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
EntryPointMetadata::OverridableConstant::Type GetDawnOverridableConstantType(
|
|
||||||
tint::inspector::OverridableConstant::Type type) {
|
|
||||||
switch (type) {
|
|
||||||
case tint::inspector::OverridableConstant::Type::kBool:
|
|
||||||
return EntryPointMetadata::OverridableConstant::Type::Boolean;
|
|
||||||
case tint::inspector::OverridableConstant::Type::kFloat32:
|
|
||||||
return EntryPointMetadata::OverridableConstant::Type::Float32;
|
|
||||||
case tint::inspector::OverridableConstant::Type::kInt32:
|
|
||||||
return EntryPointMetadata::OverridableConstant::Type::Int32;
|
|
||||||
case tint::inspector::OverridableConstant::Type::kUint32:
|
|
||||||
return EntryPointMetadata::OverridableConstant::Type::Uint32;
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string GetShaderDeclarationString(BindGroupIndex group, BindingNumber binding) {
|
|
||||||
return absl::StrFormat("the shader module declaration at set %u, binding %u",
|
|
||||||
static_cast<uint32_t>(group), static_cast<uint32_t>(binding));
|
|
||||||
}
|
|
||||||
|
|
||||||
tint::transform::VertexFormat ToTintVertexFormat(wgpu::VertexFormat format) {
|
tint::transform::VertexFormat ToTintVertexFormat(wgpu::VertexFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case wgpu::VertexFormat::Uint8x2:
|
case wgpu::VertexFormat::Uint8x2:
|
||||||
@ -418,21 +397,32 @@ namespace dawn_native {
|
|||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntryPointMetadata::OverridableConstant::Type FromTintOverridableConstantType(
|
||||||
|
tint::inspector::OverridableConstant::Type type) {
|
||||||
|
switch (type) {
|
||||||
|
case tint::inspector::OverridableConstant::Type::kBool:
|
||||||
|
return EntryPointMetadata::OverridableConstant::Type::Boolean;
|
||||||
|
case tint::inspector::OverridableConstant::Type::kFloat32:
|
||||||
|
return EntryPointMetadata::OverridableConstant::Type::Float32;
|
||||||
|
case tint::inspector::OverridableConstant::Type::kInt32:
|
||||||
|
return EntryPointMetadata::OverridableConstant::Type::Int32;
|
||||||
|
case tint::inspector::OverridableConstant::Type::kUint32:
|
||||||
|
return EntryPointMetadata::OverridableConstant::Type::Uint32;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ResultOrError<tint::Program> ParseWGSL(const tint::Source::File* file,
|
ResultOrError<tint::Program> ParseWGSL(const tint::Source::File* file,
|
||||||
OwnedCompilationMessages* outMessages) {
|
OwnedCompilationMessages* outMessages) {
|
||||||
std::ostringstream errorStream;
|
|
||||||
errorStream << "Tint WGSL reader failure:" << std::endl;
|
|
||||||
|
|
||||||
tint::Program program = tint::reader::wgsl::Parse(file);
|
tint::Program program = tint::reader::wgsl::Parse(file);
|
||||||
if (outMessages != nullptr) {
|
if (outMessages != nullptr) {
|
||||||
outMessages->AddMessages(program.Diagnostics());
|
outMessages->AddMessages(program.Diagnostics());
|
||||||
}
|
}
|
||||||
if (!program.IsValid()) {
|
if (!program.IsValid()) {
|
||||||
auto err = program.Diagnostics().str();
|
return DAWN_FORMAT_VALIDATION_ERROR(
|
||||||
errorStream << "Parser: " << err << std::endl
|
"Tint WGSL reader failure:\nParser: %s\nShader:\n%s\n",
|
||||||
<< "Shader: " << std::endl
|
program.Diagnostics().str(), file->content.data);
|
||||||
<< file->content << std::endl;
|
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::move(program);
|
return std::move(program);
|
||||||
@ -440,17 +430,13 @@ namespace dawn_native {
|
|||||||
|
|
||||||
ResultOrError<tint::Program> ParseSPIRV(const std::vector<uint32_t>& spirv,
|
ResultOrError<tint::Program> ParseSPIRV(const std::vector<uint32_t>& spirv,
|
||||||
OwnedCompilationMessages* outMessages) {
|
OwnedCompilationMessages* outMessages) {
|
||||||
std::ostringstream errorStream;
|
|
||||||
errorStream << "Tint SPIRV reader failure:" << std::endl;
|
|
||||||
|
|
||||||
tint::Program program = tint::reader::spirv::Parse(spirv);
|
tint::Program program = tint::reader::spirv::Parse(spirv);
|
||||||
if (outMessages != nullptr) {
|
if (outMessages != nullptr) {
|
||||||
outMessages->AddMessages(program.Diagnostics());
|
outMessages->AddMessages(program.Diagnostics());
|
||||||
}
|
}
|
||||||
if (!program.IsValid()) {
|
if (!program.IsValid()) {
|
||||||
auto err = program.Diagnostics().str();
|
return DAWN_FORMAT_VALIDATION_ERROR("Tint SPIR-V reader failure:\nParser: %s\n",
|
||||||
errorStream << "Parser: " << err << std::endl;
|
program.Diagnostics().str());
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::move(program);
|
return std::move(program);
|
||||||
@ -485,140 +471,138 @@ namespace dawn_native {
|
|||||||
return requiredBufferSizes;
|
return requiredBufferSizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaybeError ValidateCompatibilityOfSingleBindingWithLayout(
|
||||||
|
const DeviceBase* device,
|
||||||
|
const BindGroupLayoutBase* layout,
|
||||||
|
SingleShaderStage entryPointStage,
|
||||||
|
BindingNumber bindingNumber,
|
||||||
|
const ShaderBindingInfo& shaderInfo) {
|
||||||
|
const BindGroupLayoutBase::BindingMap& layoutBindings = layout->GetBindingMap();
|
||||||
|
|
||||||
|
const auto& bindingIt = layoutBindings.find(bindingNumber);
|
||||||
|
DAWN_INVALID_IF(bindingIt == layoutBindings.end(), "Binding doesn't exist in %s.",
|
||||||
|
layout);
|
||||||
|
|
||||||
|
BindingIndex bindingIndex(bindingIt->second);
|
||||||
|
const BindingInfo& layoutInfo = layout->GetBindingInfo(bindingIndex);
|
||||||
|
|
||||||
|
// TODO(dawn:563): Provide info about the binding types.
|
||||||
|
DAWN_INVALID_IF(layoutInfo.bindingType != shaderInfo.bindingType,
|
||||||
|
"Binding type (buffer vs. texture vs. sampler) doesn't match the type "
|
||||||
|
"in the layout.");
|
||||||
|
|
||||||
|
// TODO(dawn:563): Provide info about the visibility.
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
(layoutInfo.visibility & StageBit(entryPointStage)) == 0,
|
||||||
|
"Entry point's stage is not in the binding visibility in the layout (%s)",
|
||||||
|
layoutInfo.visibility);
|
||||||
|
|
||||||
|
switch (layoutInfo.bindingType) {
|
||||||
|
case BindingInfoType::Texture: {
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
layoutInfo.texture.multisampled != shaderInfo.texture.multisampled,
|
||||||
|
"Binding multisampled flag (%u) doesn't match the layout's multisampled "
|
||||||
|
"flag (%u)",
|
||||||
|
layoutInfo.texture.multisampled, shaderInfo.texture.multisampled);
|
||||||
|
|
||||||
|
// TODO(dawn:563): Provide info about the sample types.
|
||||||
|
DAWN_INVALID_IF((SampleTypeToSampleTypeBit(layoutInfo.texture.sampleType) &
|
||||||
|
shaderInfo.texture.compatibleSampleTypes) == 0,
|
||||||
|
"The sample type in the shader is not compatible with the "
|
||||||
|
"sample type of the layout.");
|
||||||
|
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
layoutInfo.texture.viewDimension != shaderInfo.texture.viewDimension,
|
||||||
|
"The shader's binding dimension (%s) doesn't match the shader's binding "
|
||||||
|
"dimension (%s).",
|
||||||
|
layoutInfo.texture.viewDimension, shaderInfo.texture.viewDimension);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BindingInfoType::StorageTexture: {
|
||||||
|
ASSERT(layoutInfo.storageTexture.format != wgpu::TextureFormat::Undefined);
|
||||||
|
ASSERT(shaderInfo.storageTexture.format != wgpu::TextureFormat::Undefined);
|
||||||
|
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
layoutInfo.storageTexture.access != shaderInfo.storageTexture.access,
|
||||||
|
"The layout's binding access (%s) isn't compatible with the shader's "
|
||||||
|
"binding access (%s).",
|
||||||
|
layoutInfo.storageTexture.access, shaderInfo.storageTexture.access);
|
||||||
|
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
layoutInfo.storageTexture.format != shaderInfo.storageTexture.format,
|
||||||
|
"The layout's binding format (%s) doesn't match the shader's binding "
|
||||||
|
"format (%s).",
|
||||||
|
layoutInfo.storageTexture.format, shaderInfo.storageTexture.format);
|
||||||
|
|
||||||
|
DAWN_INVALID_IF(layoutInfo.storageTexture.viewDimension !=
|
||||||
|
shaderInfo.storageTexture.viewDimension,
|
||||||
|
"The layout's binding dimension (%s) doesn't match the "
|
||||||
|
"shader's binding dimension (%s).",
|
||||||
|
layoutInfo.storageTexture.viewDimension,
|
||||||
|
shaderInfo.storageTexture.viewDimension);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BindingInfoType::ExternalTexture: {
|
||||||
|
// Nothing to validate! (yet?)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BindingInfoType::Buffer: {
|
||||||
|
// Binding mismatch between shader and bind group is invalid. For example, a
|
||||||
|
// writable binding in the shader with a readonly storage buffer in the bind
|
||||||
|
// group layout is invalid. However, a readonly binding in the shader with a
|
||||||
|
// writable storage buffer in the bind group layout is valid, a storage
|
||||||
|
// binding in the shader with an internal storage buffer in the bind group
|
||||||
|
// layout is also valid.
|
||||||
|
bool validBindingConversion =
|
||||||
|
(layoutInfo.buffer.type == wgpu::BufferBindingType::Storage &&
|
||||||
|
shaderInfo.buffer.type == wgpu::BufferBindingType::ReadOnlyStorage) ||
|
||||||
|
(layoutInfo.buffer.type == kInternalStorageBufferBinding &&
|
||||||
|
shaderInfo.buffer.type == wgpu::BufferBindingType::Storage);
|
||||||
|
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
layoutInfo.buffer.type != shaderInfo.buffer.type && !validBindingConversion,
|
||||||
|
"The buffer type in the shader (%s) is not compatible with the type in the "
|
||||||
|
"layout (%s).",
|
||||||
|
shaderInfo.buffer.type, layoutInfo.buffer.type);
|
||||||
|
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
layoutInfo.buffer.minBindingSize != 0 &&
|
||||||
|
shaderInfo.buffer.minBindingSize > layoutInfo.buffer.minBindingSize,
|
||||||
|
"The shader uses more bytes of the buffer (%u) than the layout's "
|
||||||
|
"minBindingSize (%u).",
|
||||||
|
shaderInfo.buffer.minBindingSize, layoutInfo.buffer.minBindingSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BindingInfoType::Sampler:
|
||||||
|
DAWN_INVALID_IF(
|
||||||
|
(layoutInfo.sampler.type == wgpu::SamplerBindingType::Comparison) !=
|
||||||
|
shaderInfo.sampler.isComparison,
|
||||||
|
"The sampler type in the shader (comparison: %u) doesn't match the type in "
|
||||||
|
"the layout (comparison: %u).",
|
||||||
|
shaderInfo.sampler.isComparison,
|
||||||
|
layoutInfo.sampler.type == wgpu::SamplerBindingType::Comparison);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
MaybeError ValidateCompatibilityWithBindGroupLayout(DeviceBase* device,
|
MaybeError ValidateCompatibilityWithBindGroupLayout(DeviceBase* device,
|
||||||
BindGroupIndex group,
|
BindGroupIndex group,
|
||||||
const EntryPointMetadata& entryPoint,
|
const EntryPointMetadata& entryPoint,
|
||||||
const BindGroupLayoutBase* layout) {
|
const BindGroupLayoutBase* layout) {
|
||||||
const BindGroupLayoutBase::BindingMap& layoutBindings = layout->GetBindingMap();
|
|
||||||
|
|
||||||
// Iterate over all bindings used by this group in the shader, and find the
|
// Iterate over all bindings used by this group in the shader, and find the
|
||||||
// corresponding binding in the BindGroupLayout, if it exists.
|
// corresponding binding in the BindGroupLayout, if it exists.
|
||||||
for (const auto& it : entryPoint.bindings[group]) {
|
for (const auto& it : entryPoint.bindings[group]) {
|
||||||
BindingNumber bindingNumber = it.first;
|
DAWN_TRY_CONTEXT(ValidateCompatibilityOfSingleBindingWithLayout(
|
||||||
const ShaderBindingInfo& shaderInfo = it.second;
|
device, layout, entryPoint.stage, it.first, it.second),
|
||||||
|
"validating that the entry-point's declaration for [[group(%u), "
|
||||||
const auto& bindingIt = layoutBindings.find(bindingNumber);
|
"binding(%u)]] matches %s",
|
||||||
if (bindingIt == layoutBindings.end()) {
|
static_cast<uint32_t>(group), static_cast<uint32_t>(it.first),
|
||||||
return DAWN_VALIDATION_ERROR("Missing bind group layout entry for " +
|
layout);
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
BindingIndex bindingIndex(bindingIt->second);
|
|
||||||
const BindingInfo& layoutInfo = layout->GetBindingInfo(bindingIndex);
|
|
||||||
|
|
||||||
if (layoutInfo.bindingType != shaderInfo.bindingType) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The binding type of the bind group layout entry conflicts " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((layoutInfo.visibility & StageBit(entryPoint.stage)) == 0) {
|
|
||||||
return DAWN_VALIDATION_ERROR("The bind group layout entry for " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber) +
|
|
||||||
" is not visible for the shader stage");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (layoutInfo.bindingType) {
|
|
||||||
case BindingInfoType::Texture: {
|
|
||||||
if (layoutInfo.texture.multisampled != shaderInfo.texture.multisampled) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The texture multisampled flag of the bind group layout entry is "
|
|
||||||
"different from " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((SampleTypeToSampleTypeBit(layoutInfo.texture.sampleType) &
|
|
||||||
shaderInfo.texture.compatibleSampleTypes) == 0) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The texture sampleType of the bind group layout entry is "
|
|
||||||
"not compatible with " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layoutInfo.texture.viewDimension != shaderInfo.texture.viewDimension) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The texture viewDimension of the bind group layout entry is "
|
|
||||||
"different "
|
|
||||||
"from " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BindingInfoType::StorageTexture: {
|
|
||||||
ASSERT(layoutInfo.storageTexture.format != wgpu::TextureFormat::Undefined);
|
|
||||||
ASSERT(shaderInfo.storageTexture.format != wgpu::TextureFormat::Undefined);
|
|
||||||
|
|
||||||
if (layoutInfo.storageTexture.access != shaderInfo.storageTexture.access) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The storageTexture access mode of the bind group layout entry is "
|
|
||||||
"different from " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layoutInfo.storageTexture.format != shaderInfo.storageTexture.format) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The storageTexture format of the bind group layout entry is "
|
|
||||||
"different from " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
if (layoutInfo.storageTexture.viewDimension !=
|
|
||||||
shaderInfo.storageTexture.viewDimension) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The storageTexture viewDimension of the bind group layout entry "
|
|
||||||
"is different from " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BindingInfoType::ExternalTexture: {
|
|
||||||
if (shaderInfo.bindingType != BindingInfoType::ExternalTexture) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The external texture bind group layout entry conflicts with " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BindingInfoType::Buffer: {
|
|
||||||
// Binding mismatch between shader and bind group is invalid. For example, a
|
|
||||||
// writable binding in the shader with a readonly storage buffer in the bind
|
|
||||||
// group layout is invalid. However, a readonly binding in the shader with a
|
|
||||||
// writable storage buffer in the bind group layout is valid, a storage
|
|
||||||
// binding in the shader with an internal storage buffer in the bind group
|
|
||||||
// layout is also valid.
|
|
||||||
bool validBindingConversion =
|
|
||||||
(layoutInfo.buffer.type == wgpu::BufferBindingType::Storage &&
|
|
||||||
shaderInfo.buffer.type == wgpu::BufferBindingType::ReadOnlyStorage) ||
|
|
||||||
(layoutInfo.buffer.type == kInternalStorageBufferBinding &&
|
|
||||||
shaderInfo.buffer.type == wgpu::BufferBindingType::Storage);
|
|
||||||
|
|
||||||
if (layoutInfo.buffer.type != shaderInfo.buffer.type &&
|
|
||||||
!validBindingConversion) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The buffer type of the bind group layout entry conflicts " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layoutInfo.buffer.minBindingSize != 0 &&
|
|
||||||
shaderInfo.buffer.minBindingSize > layoutInfo.buffer.minBindingSize) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The minimum buffer size of the bind group layout entry is smaller "
|
|
||||||
"than " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BindingInfoType::Sampler:
|
|
||||||
if ((layoutInfo.sampler.type == wgpu::SamplerBindingType::Comparison) !=
|
|
||||||
shaderInfo.sampler.isComparison) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"The sampler type of the bind group layout entry is "
|
|
||||||
"not compatible with " +
|
|
||||||
GetShaderDeclarationString(group, bindingNumber));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@ -630,16 +614,14 @@ namespace dawn_native {
|
|||||||
ASSERT(program->IsValid());
|
ASSERT(program->IsValid());
|
||||||
|
|
||||||
EntryPointMetadataTable result;
|
EntryPointMetadataTable result;
|
||||||
std::ostringstream errorStream;
|
|
||||||
errorStream << "Tint Reflection failure:" << std::endl;
|
|
||||||
|
|
||||||
tint::inspector::Inspector inspector(program);
|
tint::inspector::Inspector inspector(program);
|
||||||
auto entryPoints = inspector.GetEntryPoints();
|
auto entryPoints = inspector.GetEntryPoints();
|
||||||
if (inspector.has_error()) {
|
DAWN_INVALID_IF(inspector.has_error(), "Tint Reflection failure: Inspector: %s\n",
|
||||||
errorStream << "Inspector: " << inspector.error() << std::endl;
|
inspector.error());
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// TODO(dawn:563): use DAWN_TRY_CONTEXT to output the name of the entry point we're
|
||||||
|
// reflecting.
|
||||||
constexpr uint32_t kMaxInterStageShaderLocation = kMaxInterStageShaderVariables - 1;
|
constexpr uint32_t kMaxInterStageShaderLocation = kMaxInterStageShaderVariables - 1;
|
||||||
for (auto& entryPoint : entryPoints) {
|
for (auto& entryPoint : entryPoints) {
|
||||||
ASSERT(result.count(entryPoint.name) == 0);
|
ASSERT(result.count(entryPoint.name) == 0);
|
||||||
@ -651,7 +633,7 @@ namespace dawn_native {
|
|||||||
|
|
||||||
for (auto& c : entryPoint.overridable_constants) {
|
for (auto& c : entryPoint.overridable_constants) {
|
||||||
EntryPointMetadata::OverridableConstant constant = {
|
EntryPointMetadata::OverridableConstant constant = {
|
||||||
name2Id.at(c.name), GetDawnOverridableConstantType(c.type)};
|
name2Id.at(c.name), FromTintOverridableConstantType(c.type)};
|
||||||
metadata->overridableConstants[c.name] = constant;
|
metadata->overridableConstants[c.name] = constant;
|
||||||
// TODO(tint:1155) tint needs ways to differentiate whether a pipeline
|
// TODO(tint:1155) tint needs ways to differentiate whether a pipeline
|
||||||
// constant id is specified explicitly. Now we just store numeric id and
|
// constant id is specified explicitly. Now we just store numeric id and
|
||||||
@ -663,24 +645,14 @@ namespace dawn_native {
|
|||||||
DAWN_TRY_ASSIGN(metadata->stage, TintPipelineStageToShaderStage(entryPoint.stage));
|
DAWN_TRY_ASSIGN(metadata->stage, TintPipelineStageToShaderStage(entryPoint.stage));
|
||||||
|
|
||||||
if (metadata->stage == SingleShaderStage::Compute) {
|
if (metadata->stage == SingleShaderStage::Compute) {
|
||||||
if (entryPoint.workgroup_size_x > kMaxComputeWorkgroupSizeX) {
|
DAWN_INVALID_IF(entryPoint.workgroup_size_x > kMaxComputeWorkgroupSizeX ||
|
||||||
errorStream << "Workgroup X dimension exceeds maximum allowed:"
|
entryPoint.workgroup_size_y > kMaxComputeWorkgroupSizeY ||
|
||||||
<< entryPoint.workgroup_size_x << " > "
|
entryPoint.workgroup_size_z > kMaxComputeWorkgroupSizeZ,
|
||||||
<< kMaxComputeWorkgroupSizeX;
|
"Entry-point uses workgroup_size(%u, %u, %u) that exceeds the "
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str());
|
"maximum allowed (%u, %u, %u).",
|
||||||
}
|
entryPoint.workgroup_size_x, entryPoint.workgroup_size_y,
|
||||||
if (entryPoint.workgroup_size_y > kMaxComputeWorkgroupSizeY) {
|
entryPoint.workgroup_size_z, kMaxComputeWorkgroupSizeX,
|
||||||
errorStream << "Workgroup Y dimension exceeds maximum allowed: "
|
kMaxComputeWorkgroupSizeY, kMaxComputeWorkgroupSizeZ);
|
||||||
<< entryPoint.workgroup_size_y << " > "
|
|
||||||
<< kMaxComputeWorkgroupSizeY;
|
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str());
|
|
||||||
}
|
|
||||||
if (entryPoint.workgroup_size_z > kMaxComputeWorkgroupSizeZ) {
|
|
||||||
errorStream << "Workgroup Z dimension exceeds maximum allowed: "
|
|
||||||
<< entryPoint.workgroup_size_z << " > "
|
|
||||||
<< kMaxComputeWorkgroupSizeZ;
|
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dimensions have already been validated against their individual limits above.
|
// Dimensions have already been validated against their individual limits above.
|
||||||
// This assertion ensures that the product of such limited dimensions cannot
|
// This assertion ensures that the product of such limited dimensions cannot
|
||||||
@ -689,23 +661,20 @@ namespace dawn_native {
|
|||||||
kMaxComputeWorkgroupSizeY * kMaxComputeWorkgroupSizeZ <=
|
kMaxComputeWorkgroupSizeY * kMaxComputeWorkgroupSizeZ <=
|
||||||
std::numeric_limits<uint32_t>::max(),
|
std::numeric_limits<uint32_t>::max(),
|
||||||
"Per-dimension workgroup size limits are too high");
|
"Per-dimension workgroup size limits are too high");
|
||||||
uint32_t num_invocations = entryPoint.workgroup_size_x *
|
uint32_t numInvocations = entryPoint.workgroup_size_x *
|
||||||
entryPoint.workgroup_size_y *
|
entryPoint.workgroup_size_y *
|
||||||
entryPoint.workgroup_size_z;
|
entryPoint.workgroup_size_z;
|
||||||
if (num_invocations > kMaxComputeWorkgroupInvocations) {
|
DAWN_INVALID_IF(numInvocations > kMaxComputeWorkgroupInvocations,
|
||||||
errorStream << "Number of workgroup invocations exceeds maximum allowed: "
|
"The total number of workgroup invocations (%u) exceeds the "
|
||||||
<< num_invocations << " > " << kMaxComputeWorkgroupInvocations;
|
"maximum allowed (%u).",
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str());
|
numInvocations, kMaxComputeWorkgroupInvocations);
|
||||||
}
|
|
||||||
|
|
||||||
const size_t workgroup_storage_size =
|
const size_t workgroupStorageSize =
|
||||||
inspector.GetWorkgroupStorageSize(entryPoint.name);
|
inspector.GetWorkgroupStorageSize(entryPoint.name);
|
||||||
if (workgroup_storage_size > kMaxComputeWorkgroupStorageSize) {
|
DAWN_INVALID_IF(workgroupStorageSize > kMaxComputeWorkgroupStorageSize,
|
||||||
errorStream << "Workgroup shared storage size for " << entryPoint.name
|
"The total use of workgroup storage (%u bytes) is larger than "
|
||||||
<< " exceeds the maximum allowed: " << workgroup_storage_size
|
"the maximum allowed (%u bytes).",
|
||||||
<< " > " << kMaxComputeWorkgroupStorageSize;
|
workgroupStorageSize, kMaxComputeWorkgroupStorageSize);
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata->localWorkgroupSize.x = entryPoint.workgroup_size_x;
|
metadata->localWorkgroupSize.x = entryPoint.workgroup_size_x;
|
||||||
metadata->localWorkgroupSize.y = entryPoint.workgroup_size_y;
|
metadata->localWorkgroupSize.y = entryPoint.workgroup_size_y;
|
||||||
@ -713,96 +682,98 @@ namespace dawn_native {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (metadata->stage == SingleShaderStage::Vertex) {
|
if (metadata->stage == SingleShaderStage::Vertex) {
|
||||||
for (const auto& input_var : entryPoint.input_variables) {
|
for (const auto& inputVar : entryPoint.input_variables) {
|
||||||
if (!input_var.has_location_decoration) {
|
DAWN_INVALID_IF(
|
||||||
return DAWN_VALIDATION_ERROR(
|
!inputVar.has_location_decoration,
|
||||||
"Need Location decoration on Vertex input");
|
"Vertex input variable \"%s\" doesn't have a location decoration.",
|
||||||
}
|
inputVar.name);
|
||||||
uint32_t unsanitizedLocation = input_var.location_decoration;
|
|
||||||
if (DAWN_UNLIKELY(unsanitizedLocation >= kMaxVertexAttributes)) {
|
uint32_t unsanitizedLocation = inputVar.location_decoration;
|
||||||
std::stringstream ss;
|
DAWN_INVALID_IF(unsanitizedLocation >= kMaxVertexAttributes,
|
||||||
ss << "Attribute location (" << unsanitizedLocation << ") over limits";
|
"Vertex input variable \"%s\" has a location (%u) that "
|
||||||
return DAWN_VALIDATION_ERROR(ss.str());
|
"exceeds the maximum (%u)",
|
||||||
}
|
inputVar.name, unsanitizedLocation, kMaxVertexAttributes);
|
||||||
VertexAttributeLocation location(static_cast<uint8_t>(unsanitizedLocation));
|
VertexAttributeLocation location(static_cast<uint8_t>(unsanitizedLocation));
|
||||||
|
|
||||||
DAWN_TRY_ASSIGN(
|
DAWN_TRY_ASSIGN(
|
||||||
metadata->vertexInputBaseTypes[location],
|
metadata->vertexInputBaseTypes[location],
|
||||||
TintComponentTypeToVertexFormatBaseType(input_var.component_type));
|
TintComponentTypeToVertexFormatBaseType(inputVar.component_type));
|
||||||
metadata->usedVertexInputs.set(location);
|
metadata->usedVertexInputs.set(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [[position]] must be declared in a vertex shader.
|
// [[position]] must be declared in a vertex shader but is not exposed as an
|
||||||
|
// output variable by Tint so we directly add its components to the total.
|
||||||
uint32_t totalInterStageShaderComponents = 4;
|
uint32_t totalInterStageShaderComponents = 4;
|
||||||
for (const auto& output_var : entryPoint.output_variables) {
|
for (const auto& outputVar : entryPoint.output_variables) {
|
||||||
if (DAWN_UNLIKELY(!output_var.has_location_decoration)) {
|
DAWN_INVALID_IF(
|
||||||
std::stringstream ss;
|
!outputVar.has_location_decoration,
|
||||||
ss << "Missing location qualifier on vertex output, "
|
"Vertex ouput variable \"%s\" doesn't have a location decoration.",
|
||||||
<< output_var.name;
|
outputVar.name);
|
||||||
return DAWN_VALIDATION_ERROR(ss.str());
|
|
||||||
}
|
uint32_t location = outputVar.location_decoration;
|
||||||
uint32_t location = output_var.location_decoration;
|
DAWN_INVALID_IF(location > kMaxInterStageShaderLocation,
|
||||||
if (DAWN_UNLIKELY(location > kMaxInterStageShaderLocation)) {
|
"Vertex output variable \"%s\" has a location (%u) that "
|
||||||
std::stringstream ss;
|
"exceeds the maximum (%u).",
|
||||||
ss << "Vertex output location (" << location << ") over limits";
|
outputVar.name, location, kMaxInterStageShaderLocation);
|
||||||
return DAWN_VALIDATION_ERROR(ss.str());
|
|
||||||
}
|
|
||||||
metadata->usedInterStageVariables.set(location);
|
metadata->usedInterStageVariables.set(location);
|
||||||
DAWN_TRY_ASSIGN(
|
DAWN_TRY_ASSIGN(
|
||||||
metadata->interStageVariables[location].baseType,
|
metadata->interStageVariables[location].baseType,
|
||||||
TintComponentTypeToInterStageComponentType(output_var.component_type));
|
TintComponentTypeToInterStageComponentType(outputVar.component_type));
|
||||||
DAWN_TRY_ASSIGN(metadata->interStageVariables[location].componentCount,
|
DAWN_TRY_ASSIGN(metadata->interStageVariables[location].componentCount,
|
||||||
TintCompositionTypeToInterStageComponentCount(
|
TintCompositionTypeToInterStageComponentCount(
|
||||||
output_var.composition_type));
|
outputVar.composition_type));
|
||||||
DAWN_TRY_ASSIGN(metadata->interStageVariables[location].interpolationType,
|
DAWN_TRY_ASSIGN(
|
||||||
TintInterpolationTypeToInterpolationType(
|
metadata->interStageVariables[location].interpolationType,
|
||||||
output_var.interpolation_type));
|
TintInterpolationTypeToInterpolationType(outputVar.interpolation_type));
|
||||||
DAWN_TRY_ASSIGN(
|
DAWN_TRY_ASSIGN(
|
||||||
metadata->interStageVariables[location].interpolationSampling,
|
metadata->interStageVariables[location].interpolationSampling,
|
||||||
TintInterpolationSamplingToInterpolationSamplingType(
|
TintInterpolationSamplingToInterpolationSamplingType(
|
||||||
output_var.interpolation_sampling));
|
outputVar.interpolation_sampling));
|
||||||
|
|
||||||
totalInterStageShaderComponents +=
|
totalInterStageShaderComponents +=
|
||||||
metadata->interStageVariables[location].componentCount;
|
metadata->interStageVariables[location].componentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DAWN_UNLIKELY(totalInterStageShaderComponents >
|
DAWN_INVALID_IF(
|
||||||
kMaxInterStageShaderComponents)) {
|
totalInterStageShaderComponents > kMaxInterStageShaderComponents,
|
||||||
return DAWN_VALIDATION_ERROR(
|
"Total vertex output components count (%u) exceeds the maximum (%u).",
|
||||||
"Total vertex output components count exceeds limits");
|
totalInterStageShaderComponents, kMaxInterStageShaderComponents);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metadata->stage == SingleShaderStage::Fragment) {
|
if (metadata->stage == SingleShaderStage::Fragment) {
|
||||||
uint32_t totalInterStageShaderComponents = 0;
|
uint32_t totalInterStageShaderComponents = 0;
|
||||||
for (const auto& input_var : entryPoint.input_variables) {
|
for (const auto& inputVar : entryPoint.input_variables) {
|
||||||
if (!input_var.has_location_decoration) {
|
DAWN_INVALID_IF(
|
||||||
return DAWN_VALIDATION_ERROR(
|
!inputVar.has_location_decoration,
|
||||||
"Need location decoration on fragment input");
|
"Fragment input variable \"%s\" doesn't have a location decoration.",
|
||||||
}
|
inputVar.name);
|
||||||
uint32_t location = input_var.location_decoration;
|
|
||||||
if (DAWN_UNLIKELY(location > kMaxInterStageShaderLocation)) {
|
uint32_t location = inputVar.location_decoration;
|
||||||
std::stringstream ss;
|
DAWN_INVALID_IF(location > kMaxInterStageShaderLocation,
|
||||||
ss << "Fragment input location (" << location << ") over limits";
|
"Fragment input variable \"%s\" has a location (%u) that "
|
||||||
return DAWN_VALIDATION_ERROR(ss.str());
|
"exceeds the maximum (%u).",
|
||||||
}
|
inputVar.name, location, kMaxInterStageShaderLocation);
|
||||||
|
|
||||||
metadata->usedInterStageVariables.set(location);
|
metadata->usedInterStageVariables.set(location);
|
||||||
DAWN_TRY_ASSIGN(
|
DAWN_TRY_ASSIGN(
|
||||||
metadata->interStageVariables[location].baseType,
|
metadata->interStageVariables[location].baseType,
|
||||||
TintComponentTypeToInterStageComponentType(input_var.component_type));
|
TintComponentTypeToInterStageComponentType(inputVar.component_type));
|
||||||
DAWN_TRY_ASSIGN(metadata->interStageVariables[location].componentCount,
|
DAWN_TRY_ASSIGN(metadata->interStageVariables[location].componentCount,
|
||||||
TintCompositionTypeToInterStageComponentCount(
|
TintCompositionTypeToInterStageComponentCount(
|
||||||
input_var.composition_type));
|
inputVar.composition_type));
|
||||||
DAWN_TRY_ASSIGN(
|
DAWN_TRY_ASSIGN(
|
||||||
metadata->interStageVariables[location].interpolationType,
|
metadata->interStageVariables[location].interpolationType,
|
||||||
TintInterpolationTypeToInterpolationType(input_var.interpolation_type));
|
TintInterpolationTypeToInterpolationType(inputVar.interpolation_type));
|
||||||
DAWN_TRY_ASSIGN(
|
DAWN_TRY_ASSIGN(
|
||||||
metadata->interStageVariables[location].interpolationSampling,
|
metadata->interStageVariables[location].interpolationSampling,
|
||||||
TintInterpolationSamplingToInterpolationSamplingType(
|
TintInterpolationSamplingToInterpolationSamplingType(
|
||||||
input_var.interpolation_sampling));
|
inputVar.interpolation_sampling));
|
||||||
|
|
||||||
totalInterStageShaderComponents +=
|
totalInterStageShaderComponents +=
|
||||||
metadata->interStageVariables[location].componentCount;
|
metadata->interStageVariables[location].componentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entryPoint.front_facing_used) {
|
if (entryPoint.front_facing_used) {
|
||||||
totalInterStageShaderComponents += 1;
|
totalInterStageShaderComponents += 1;
|
||||||
}
|
}
|
||||||
@ -815,32 +786,34 @@ namespace dawn_native {
|
|||||||
if (entryPoint.input_position_used) {
|
if (entryPoint.input_position_used) {
|
||||||
totalInterStageShaderComponents += 4;
|
totalInterStageShaderComponents += 4;
|
||||||
}
|
}
|
||||||
if (totalInterStageShaderComponents > kMaxInterStageShaderComponents) {
|
|
||||||
return DAWN_VALIDATION_ERROR(
|
|
||||||
"Total fragment input components count exceeds limits");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& output_var : entryPoint.output_variables) {
|
DAWN_INVALID_IF(
|
||||||
if (!output_var.has_location_decoration) {
|
totalInterStageShaderComponents > kMaxInterStageShaderComponents,
|
||||||
return DAWN_VALIDATION_ERROR(
|
"Total fragment input components count (%u) exceeds the maximum (%u).",
|
||||||
"Need location decoration on fragment output");
|
totalInterStageShaderComponents, kMaxInterStageShaderComponents);
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t unsanitizedAttachment = output_var.location_decoration;
|
for (const auto& outputVar : entryPoint.output_variables) {
|
||||||
if (unsanitizedAttachment >= kMaxColorAttachments) {
|
DAWN_INVALID_IF(
|
||||||
return DAWN_VALIDATION_ERROR(
|
!outputVar.has_location_decoration,
|
||||||
"Fragment output index must be less than max number of color "
|
"Fragment input variable \"%s\" doesn't have a location decoration.",
|
||||||
"attachments");
|
outputVar.name);
|
||||||
}
|
|
||||||
|
uint32_t unsanitizedAttachment = outputVar.location_decoration;
|
||||||
|
DAWN_INVALID_IF(unsanitizedAttachment >= kMaxColorAttachments,
|
||||||
|
"Fragment output variable \"%s\" has a location (%u) that "
|
||||||
|
"exceeds the maximum (%u).",
|
||||||
|
outputVar.name, unsanitizedAttachment,
|
||||||
|
kMaxColorAttachments);
|
||||||
ColorAttachmentIndex attachment(
|
ColorAttachmentIndex attachment(
|
||||||
static_cast<uint8_t>(unsanitizedAttachment));
|
static_cast<uint8_t>(unsanitizedAttachment));
|
||||||
|
|
||||||
DAWN_TRY_ASSIGN(
|
DAWN_TRY_ASSIGN(
|
||||||
metadata->fragmentOutputVariables[attachment].baseType,
|
metadata->fragmentOutputVariables[attachment].baseType,
|
||||||
TintComponentTypeToTextureComponentType(output_var.component_type));
|
TintComponentTypeToTextureComponentType(outputVar.component_type));
|
||||||
uint32_t componentCount;
|
uint32_t componentCount;
|
||||||
DAWN_TRY_ASSIGN(componentCount,
|
DAWN_TRY_ASSIGN(componentCount,
|
||||||
TintCompositionTypeToInterStageComponentCount(
|
TintCompositionTypeToInterStageComponentCount(
|
||||||
output_var.composition_type));
|
outputVar.composition_type));
|
||||||
// componentCount should be no larger than 4u
|
// componentCount should be no larger than 4u
|
||||||
ASSERT(componentCount <= 4u);
|
ASSERT(componentCount <= 4u);
|
||||||
metadata->fragmentOutputVariables[attachment].componentCount =
|
metadata->fragmentOutputVariables[attachment].componentCount =
|
||||||
@ -851,17 +824,20 @@ namespace dawn_native {
|
|||||||
|
|
||||||
for (const tint::inspector::ResourceBinding& resource :
|
for (const tint::inspector::ResourceBinding& resource :
|
||||||
inspector.GetResourceBindings(entryPoint.name)) {
|
inspector.GetResourceBindings(entryPoint.name)) {
|
||||||
|
DAWN_INVALID_IF(resource.bind_group >= kMaxBindGroups,
|
||||||
|
"The entry-point uses a binding with a group decoration (%u) "
|
||||||
|
"that exceeds the maximum (%u).",
|
||||||
|
resource.bind_group, kMaxBindGroups);
|
||||||
|
|
||||||
BindingNumber bindingNumber(resource.binding);
|
BindingNumber bindingNumber(resource.binding);
|
||||||
BindGroupIndex bindGroupIndex(resource.bind_group);
|
BindGroupIndex bindGroupIndex(resource.bind_group);
|
||||||
if (bindGroupIndex >= kMaxBindGroupsTyped) {
|
|
||||||
return DAWN_VALIDATION_ERROR("Shader has bind group index over limits");
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto& it = metadata->bindings[bindGroupIndex].emplace(
|
const auto& it = metadata->bindings[bindGroupIndex].emplace(
|
||||||
bindingNumber, ShaderBindingInfo{});
|
bindingNumber, ShaderBindingInfo{});
|
||||||
if (!it.second) {
|
DAWN_INVALID_IF(
|
||||||
return DAWN_VALIDATION_ERROR("Shader has duplicate bindings");
|
!it.second,
|
||||||
}
|
"Entry-point has a duplicate binding for (group:%u, binding:%u).",
|
||||||
|
resource.binding, resource.bind_group);
|
||||||
|
|
||||||
ShaderBindingInfo* info = &it.first->second;
|
ShaderBindingInfo* info = &it.first->second;
|
||||||
info->bindingType = TintResourceTypeToBindingInfoType(resource.resource_type);
|
info->bindingType = TintResourceTypeToBindingInfoType(resource.resource_type);
|
||||||
@ -974,9 +950,9 @@ namespace dawn_native {
|
|||||||
ASSERT(parseResult != nullptr);
|
ASSERT(parseResult != nullptr);
|
||||||
|
|
||||||
const ChainedStruct* chainedDescriptor = descriptor->nextInChain;
|
const ChainedStruct* chainedDescriptor = descriptor->nextInChain;
|
||||||
if (chainedDescriptor == nullptr) {
|
DAWN_INVALID_IF(chainedDescriptor == nullptr,
|
||||||
return DAWN_VALIDATION_ERROR("Shader module descriptor missing chained descriptor");
|
"Shader module descriptor missing chained descriptor");
|
||||||
}
|
|
||||||
// For now only a single SPIRV or WGSL subdescriptor is allowed.
|
// For now only a single SPIRV or WGSL subdescriptor is allowed.
|
||||||
DAWN_TRY(ValidateSingleSType(chainedDescriptor, wgpu::SType::ShaderModuleSPIRVDescriptor,
|
DAWN_TRY(ValidateSingleSType(chainedDescriptor, wgpu::SType::ShaderModuleSPIRVDescriptor,
|
||||||
wgpu::SType::ShaderModuleWGSLDescriptor));
|
wgpu::SType::ShaderModuleWGSLDescriptor));
|
||||||
@ -999,12 +975,7 @@ namespace dawn_native {
|
|||||||
|
|
||||||
tint::writer::wgsl::Options options;
|
tint::writer::wgsl::Options options;
|
||||||
auto result = tint::writer::wgsl::Generate(&program, options);
|
auto result = tint::writer::wgsl::Generate(&program, options);
|
||||||
if (!result.success) {
|
DAWN_INVALID_IF(!result.success, "Tint WGSL failure: Generator: %s", result.error);
|
||||||
std::ostringstream errorStream;
|
|
||||||
errorStream << "Tint WGSL failure:" << std::endl;
|
|
||||||
errorStream << "Generator: " << result.error << std::endl;
|
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
newWgslCode = std::move(result.wgsl);
|
newWgslCode = std::move(result.wgsl);
|
||||||
newWgslDesc.source = newWgslCode.c_str();
|
newWgslDesc.source = newWgslCode.c_str();
|
||||||
@ -1014,9 +985,8 @@ namespace dawn_native {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (spirvDesc) {
|
if (spirvDesc) {
|
||||||
if (device->IsToggleEnabled(Toggle::DisallowSpirv)) {
|
DAWN_INVALID_IF(device->IsToggleEnabled(Toggle::DisallowSpirv),
|
||||||
return DAWN_VALIDATION_ERROR("SPIR-V is disallowed.");
|
"SPIR-V is disallowed.");
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint32_t> spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize);
|
std::vector<uint32_t> spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize);
|
||||||
tint::Program program;
|
tint::Program program;
|
||||||
@ -1060,10 +1030,8 @@ namespace dawn_native {
|
|||||||
if (outMessages != nullptr) {
|
if (outMessages != nullptr) {
|
||||||
outMessages->AddMessages(output.program.Diagnostics());
|
outMessages->AddMessages(output.program.Diagnostics());
|
||||||
}
|
}
|
||||||
if (!output.program.IsValid()) {
|
DAWN_INVALID_IF(!output.program.IsValid(), "Tint program failure: %s\n",
|
||||||
std::string err = "Tint program failure: " + output.program.Diagnostics().str();
|
output.program.Diagnostics().str());
|
||||||
return DAWN_VALIDATION_ERROR(err.c_str());
|
|
||||||
}
|
|
||||||
if (outputs != nullptr) {
|
if (outputs != nullptr) {
|
||||||
*outputs = std::move(output.data);
|
*outputs = std::move(output.data);
|
||||||
}
|
}
|
||||||
@ -1107,17 +1075,17 @@ namespace dawn_native {
|
|||||||
const EntryPointMetadata& entryPoint,
|
const EntryPointMetadata& entryPoint,
|
||||||
const PipelineLayoutBase* layout) {
|
const PipelineLayoutBase* layout) {
|
||||||
for (BindGroupIndex group : IterateBitSet(layout->GetBindGroupLayoutsMask())) {
|
for (BindGroupIndex group : IterateBitSet(layout->GetBindGroupLayoutsMask())) {
|
||||||
DAWN_TRY(ValidateCompatibilityWithBindGroupLayout(device, group, entryPoint,
|
DAWN_TRY_CONTEXT(ValidateCompatibilityWithBindGroupLayout(
|
||||||
layout->GetBindGroupLayout(group)));
|
device, group, entryPoint, layout->GetBindGroupLayout(group)),
|
||||||
|
"validating the entry-point's compatibility for group %u with %s",
|
||||||
|
static_cast<uint32_t>(group), layout->GetBindGroupLayout(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (BindGroupIndex group : IterateBitSet(~layout->GetBindGroupLayoutsMask())) {
|
for (BindGroupIndex group : IterateBitSet(~layout->GetBindGroupLayoutsMask())) {
|
||||||
if (entryPoint.bindings[group].size() > 0) {
|
DAWN_INVALID_IF(entryPoint.bindings[group].size() > 0,
|
||||||
std::ostringstream ostream;
|
"The entry-point uses bindings in group %u but %s doesn't have a "
|
||||||
ostream << "No bind group layout entry matches the declaration set "
|
"BindGroupLayout for this index",
|
||||||
<< static_cast<uint32_t>(group) << " in the shader module";
|
static_cast<uint32_t>(group), layout);
|
||||||
return DAWN_VALIDATION_ERROR(ostream.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate that filtering samplers are not used with unfilterable textures.
|
// Validate that filtering samplers are not used with unfilterable textures.
|
||||||
@ -1150,11 +1118,15 @@ namespace dawn_native {
|
|||||||
textureInfo.texture.sampleType != wgpu::TextureSampleType::Uint &&
|
textureInfo.texture.sampleType != wgpu::TextureSampleType::Uint &&
|
||||||
textureInfo.texture.sampleType != wgpu::TextureSampleType::Sint);
|
textureInfo.texture.sampleType != wgpu::TextureSampleType::Sint);
|
||||||
|
|
||||||
if (textureInfo.texture.sampleType == wgpu::TextureSampleType::UnfilterableFloat) {
|
DAWN_INVALID_IF(
|
||||||
return DAWN_VALIDATION_ERROR(
|
textureInfo.texture.sampleType == wgpu::TextureSampleType::UnfilterableFloat,
|
||||||
"unfilterable-float texture bindings cannot be sampled with a "
|
"Texture binding (group:%u, binding:%u) is %s but used statically with a sampler "
|
||||||
"filtering sampler");
|
"(group:%u, binding:%u) that's %s",
|
||||||
}
|
static_cast<uint32_t>(pair.texture.group),
|
||||||
|
static_cast<uint32_t>(pair.texture.binding),
|
||||||
|
wgpu::TextureSampleType::UnfilterableFloat,
|
||||||
|
static_cast<uint32_t>(pair.sampler.group),
|
||||||
|
static_cast<uint32_t>(pair.sampler.binding), wgpu::SamplerBindingType::Filtering);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user