2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/ShaderModule.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2019-05-01 13:27:07 +00:00
|
|
|
#include "common/HashUtils.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/BindGroupLayout.h"
|
|
|
|
#include "dawn_native/Device.h"
|
|
|
|
#include "dawn_native/Pipeline.h"
|
|
|
|
#include "dawn_native/PipelineLayout.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-09-06 15:25:46 +00:00
|
|
|
#include <spirv-tools/libspirv.hpp>
|
2019-09-04 08:47:14 +00:00
|
|
|
#include <spirv_cross.hpp>
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2020-05-21 13:42:26 +00:00
|
|
|
#ifdef DAWN_ENABLE_WGSL
|
2020-06-16 19:24:18 +00:00
|
|
|
// Tint include must be after spirv_cross.hpp, because spirv-cross has its own
|
2020-05-21 13:42:26 +00:00
|
|
|
// version of spirv_headers.
|
|
|
|
// clang-format off
|
2020-06-16 19:24:18 +00:00
|
|
|
#include <tint/tint.h>
|
2020-05-21 13:42:26 +00:00
|
|
|
// clang-format on
|
|
|
|
#endif // DAWN_ENABLE_WGSL
|
|
|
|
|
2019-04-11 14:52:55 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2019-09-26 00:12:41 +00:00
|
|
|
namespace {
|
|
|
|
Format::Type SpirvCrossBaseTypeToFormatType(spirv_cross::SPIRType::BaseType spirvBaseType) {
|
|
|
|
switch (spirvBaseType) {
|
|
|
|
case spirv_cross::SPIRType::Float:
|
|
|
|
return Format::Float;
|
|
|
|
case spirv_cross::SPIRType::Int:
|
|
|
|
return Format::Sint;
|
|
|
|
case spirv_cross::SPIRType::UInt:
|
|
|
|
return Format::Uint;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return Format::Other;
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 16:40:22 +00:00
|
|
|
|
|
|
|
wgpu::TextureViewDimension SpirvDimToTextureViewDimension(spv::Dim dim, bool arrayed) {
|
|
|
|
switch (dim) {
|
|
|
|
case spv::Dim::Dim1D:
|
|
|
|
return wgpu::TextureViewDimension::e1D;
|
|
|
|
case spv::Dim::Dim2D:
|
|
|
|
if (arrayed) {
|
|
|
|
return wgpu::TextureViewDimension::e2DArray;
|
|
|
|
} else {
|
|
|
|
return wgpu::TextureViewDimension::e2D;
|
|
|
|
}
|
|
|
|
case spv::Dim::Dim3D:
|
|
|
|
return wgpu::TextureViewDimension::e3D;
|
|
|
|
case spv::Dim::DimCube:
|
|
|
|
if (arrayed) {
|
|
|
|
return wgpu::TextureViewDimension::CubeArray;
|
|
|
|
} else {
|
|
|
|
return wgpu::TextureViewDimension::Cube;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return wgpu::TextureViewDimension::Undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 16:29:41 +00:00
|
|
|
wgpu::TextureViewDimension ToWGPUTextureViewDimension(
|
|
|
|
shaderc_spvc_texture_view_dimension dim) {
|
|
|
|
switch (dim) {
|
|
|
|
case shaderc_spvc_texture_view_dimension_undefined:
|
|
|
|
return wgpu::TextureViewDimension::Undefined;
|
|
|
|
case shaderc_spvc_texture_view_dimension_e1D:
|
|
|
|
return wgpu::TextureViewDimension::e1D;
|
|
|
|
case shaderc_spvc_texture_view_dimension_e2D:
|
|
|
|
return wgpu::TextureViewDimension::e2D;
|
|
|
|
case shaderc_spvc_texture_view_dimension_e2D_array:
|
|
|
|
return wgpu::TextureViewDimension::e2DArray;
|
|
|
|
case shaderc_spvc_texture_view_dimension_cube:
|
|
|
|
return wgpu::TextureViewDimension::Cube;
|
|
|
|
case shaderc_spvc_texture_view_dimension_cube_array:
|
|
|
|
return wgpu::TextureViewDimension::CubeArray;
|
|
|
|
case shaderc_spvc_texture_view_dimension_e3D:
|
|
|
|
return wgpu::TextureViewDimension::e3D;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
Format::Type ToDawnFormatType(shaderc_spvc_texture_format_type type) {
|
|
|
|
switch (type) {
|
|
|
|
case shaderc_spvc_texture_format_type_float:
|
|
|
|
return Format::Type::Float;
|
|
|
|
case shaderc_spvc_texture_format_type_sint:
|
|
|
|
return Format::Type::Sint;
|
|
|
|
case shaderc_spvc_texture_format_type_uint:
|
|
|
|
return Format::Type::Uint;
|
|
|
|
case shaderc_spvc_texture_format_type_other:
|
|
|
|
return Format::Type::Other;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
wgpu::BindingType ToWGPUBindingType(shaderc_spvc_binding_type type) {
|
|
|
|
switch (type) {
|
|
|
|
case shaderc_spvc_binding_type_uniform_buffer:
|
|
|
|
return wgpu::BindingType::UniformBuffer;
|
|
|
|
case shaderc_spvc_binding_type_storage_buffer:
|
|
|
|
return wgpu::BindingType::StorageBuffer;
|
|
|
|
case shaderc_spvc_binding_type_readonly_storage_buffer:
|
|
|
|
return wgpu::BindingType::ReadonlyStorageBuffer;
|
|
|
|
case shaderc_spvc_binding_type_sampler:
|
2020-04-20 17:21:52 +00:00
|
|
|
return wgpu::BindingType::Sampler;
|
2020-04-20 23:43:20 +00:00
|
|
|
case shaderc_spvc_binding_type_comparison_sampler:
|
|
|
|
return wgpu::BindingType::ComparisonSampler;
|
2020-01-14 16:29:41 +00:00
|
|
|
case shaderc_spvc_binding_type_sampled_texture:
|
|
|
|
return wgpu::BindingType::SampledTexture;
|
2020-03-18 16:33:58 +00:00
|
|
|
case shaderc_spvc_binding_type_readonly_storage_texture:
|
|
|
|
return wgpu::BindingType::ReadonlyStorageTexture;
|
|
|
|
case shaderc_spvc_binding_type_writeonly_storage_texture:
|
|
|
|
return wgpu::BindingType::WriteonlyStorageTexture;
|
2020-01-14 16:29:41 +00:00
|
|
|
case shaderc_spvc_binding_type_storage_texture:
|
|
|
|
return wgpu::BindingType::StorageTexture;
|
2020-04-07 21:53:37 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-23 15:08:41 +00:00
|
|
|
SingleShaderStage ToSingleShaderStage(shaderc_spvc_execution_model execution_model) {
|
2020-01-14 16:29:41 +00:00
|
|
|
switch (execution_model) {
|
|
|
|
case shaderc_spvc_execution_model_vertex:
|
2020-03-23 15:08:41 +00:00
|
|
|
return SingleShaderStage::Vertex;
|
2020-01-14 16:29:41 +00:00
|
|
|
case shaderc_spvc_execution_model_fragment:
|
2020-03-23 15:08:41 +00:00
|
|
|
return SingleShaderStage::Fragment;
|
2020-01-14 16:29:41 +00:00
|
|
|
case shaderc_spvc_execution_model_glcompute:
|
2020-03-23 15:08:41 +00:00
|
|
|
return SingleShaderStage::Compute;
|
2020-01-14 16:29:41 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 10:28:07 +00:00
|
|
|
|
|
|
|
wgpu::TextureFormat ToWGPUTextureFormat(spv::ImageFormat format) {
|
|
|
|
switch (format) {
|
|
|
|
case spv::ImageFormatR8:
|
|
|
|
return wgpu::TextureFormat::R8Unorm;
|
|
|
|
case spv::ImageFormatR8Snorm:
|
|
|
|
return wgpu::TextureFormat::R8Snorm;
|
|
|
|
case spv::ImageFormatR8ui:
|
|
|
|
return wgpu::TextureFormat::R8Uint;
|
|
|
|
case spv::ImageFormatR8i:
|
|
|
|
return wgpu::TextureFormat::R8Sint;
|
|
|
|
case spv::ImageFormatR16ui:
|
|
|
|
return wgpu::TextureFormat::R16Uint;
|
|
|
|
case spv::ImageFormatR16i:
|
|
|
|
return wgpu::TextureFormat::R16Sint;
|
|
|
|
case spv::ImageFormatR16f:
|
|
|
|
return wgpu::TextureFormat::R16Float;
|
|
|
|
case spv::ImageFormatRg8:
|
|
|
|
return wgpu::TextureFormat::RG8Unorm;
|
|
|
|
case spv::ImageFormatRg8Snorm:
|
|
|
|
return wgpu::TextureFormat::RG8Snorm;
|
|
|
|
case spv::ImageFormatRg8ui:
|
|
|
|
return wgpu::TextureFormat::RG8Uint;
|
|
|
|
case spv::ImageFormatRg8i:
|
|
|
|
return wgpu::TextureFormat::RG8Sint;
|
|
|
|
case spv::ImageFormatR32f:
|
|
|
|
return wgpu::TextureFormat::R32Float;
|
|
|
|
case spv::ImageFormatR32ui:
|
|
|
|
return wgpu::TextureFormat::R32Uint;
|
|
|
|
case spv::ImageFormatR32i:
|
|
|
|
return wgpu::TextureFormat::R32Sint;
|
|
|
|
case spv::ImageFormatRg16ui:
|
|
|
|
return wgpu::TextureFormat::RG16Uint;
|
|
|
|
case spv::ImageFormatRg16i:
|
|
|
|
return wgpu::TextureFormat::RG16Sint;
|
|
|
|
case spv::ImageFormatRg16f:
|
|
|
|
return wgpu::TextureFormat::RG16Float;
|
|
|
|
case spv::ImageFormatRgba8:
|
|
|
|
return wgpu::TextureFormat::RGBA8Unorm;
|
|
|
|
case spv::ImageFormatRgba8Snorm:
|
|
|
|
return wgpu::TextureFormat::RGBA8Snorm;
|
|
|
|
case spv::ImageFormatRgba8ui:
|
|
|
|
return wgpu::TextureFormat::RGBA8Uint;
|
|
|
|
case spv::ImageFormatRgba8i:
|
|
|
|
return wgpu::TextureFormat::RGBA8Sint;
|
|
|
|
case spv::ImageFormatRgb10A2:
|
|
|
|
return wgpu::TextureFormat::RGB10A2Unorm;
|
|
|
|
case spv::ImageFormatR11fG11fB10f:
|
|
|
|
return wgpu::TextureFormat::RG11B10Float;
|
|
|
|
case spv::ImageFormatRg32f:
|
|
|
|
return wgpu::TextureFormat::RG32Float;
|
|
|
|
case spv::ImageFormatRg32ui:
|
|
|
|
return wgpu::TextureFormat::RG32Uint;
|
|
|
|
case spv::ImageFormatRg32i:
|
|
|
|
return wgpu::TextureFormat::RG32Sint;
|
|
|
|
case spv::ImageFormatRgba16ui:
|
|
|
|
return wgpu::TextureFormat::RGBA16Uint;
|
|
|
|
case spv::ImageFormatRgba16i:
|
|
|
|
return wgpu::TextureFormat::RGBA16Sint;
|
|
|
|
case spv::ImageFormatRgba16f:
|
|
|
|
return wgpu::TextureFormat::RGBA16Float;
|
|
|
|
case spv::ImageFormatRgba32f:
|
|
|
|
return wgpu::TextureFormat::RGBA32Float;
|
|
|
|
case spv::ImageFormatRgba32ui:
|
|
|
|
return wgpu::TextureFormat::RGBA32Uint;
|
|
|
|
case spv::ImageFormatRgba32i:
|
|
|
|
return wgpu::TextureFormat::RGBA32Sint;
|
|
|
|
default:
|
|
|
|
return wgpu::TextureFormat::Undefined;
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 14:25:51 +00:00
|
|
|
|
|
|
|
wgpu::TextureFormat ToWGPUTextureFormat(shaderc_spvc_storage_texture_format format) {
|
|
|
|
switch (format) {
|
|
|
|
case shaderc_spvc_storage_texture_format_r8unorm:
|
|
|
|
return wgpu::TextureFormat::R8Unorm;
|
|
|
|
case shaderc_spvc_storage_texture_format_r8snorm:
|
|
|
|
return wgpu::TextureFormat::R8Snorm;
|
|
|
|
case shaderc_spvc_storage_texture_format_r8uint:
|
|
|
|
return wgpu::TextureFormat::R8Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_r8sint:
|
|
|
|
return wgpu::TextureFormat::R8Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_r16uint:
|
|
|
|
return wgpu::TextureFormat::R16Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_r16sint:
|
|
|
|
return wgpu::TextureFormat::R16Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_r16float:
|
|
|
|
return wgpu::TextureFormat::R16Float;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg8unorm:
|
|
|
|
return wgpu::TextureFormat::RG8Unorm;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg8snorm:
|
|
|
|
return wgpu::TextureFormat::RG8Snorm;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg8uint:
|
|
|
|
return wgpu::TextureFormat::RG8Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg8sint:
|
|
|
|
return wgpu::TextureFormat::RG8Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_r32float:
|
|
|
|
return wgpu::TextureFormat::R32Float;
|
|
|
|
case shaderc_spvc_storage_texture_format_r32uint:
|
|
|
|
return wgpu::TextureFormat::R32Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_r32sint:
|
|
|
|
return wgpu::TextureFormat::R32Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg16uint:
|
|
|
|
return wgpu::TextureFormat::RG16Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg16sint:
|
|
|
|
return wgpu::TextureFormat::RG16Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg16float:
|
|
|
|
return wgpu::TextureFormat::RG16Float;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba8unorm:
|
|
|
|
return wgpu::TextureFormat::RGBA8Unorm;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba8snorm:
|
|
|
|
return wgpu::TextureFormat::RGBA8Snorm;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba8uint:
|
|
|
|
return wgpu::TextureFormat::RGBA8Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba8sint:
|
|
|
|
return wgpu::TextureFormat::RGBA8Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgb10a2unorm:
|
|
|
|
return wgpu::TextureFormat::RGB10A2Unorm;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg11b10float:
|
|
|
|
return wgpu::TextureFormat::RG11B10Float;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg32float:
|
|
|
|
return wgpu::TextureFormat::RG32Float;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg32uint:
|
|
|
|
return wgpu::TextureFormat::RG32Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rg32sint:
|
|
|
|
return wgpu::TextureFormat::RG32Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba16uint:
|
|
|
|
return wgpu::TextureFormat::RGBA16Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba16sint:
|
|
|
|
return wgpu::TextureFormat::RGBA16Sint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba16float:
|
|
|
|
return wgpu::TextureFormat::RGBA16Float;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba32float:
|
|
|
|
return wgpu::TextureFormat::RGBA32Float;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba32uint:
|
|
|
|
return wgpu::TextureFormat::RGBA32Uint;
|
|
|
|
case shaderc_spvc_storage_texture_format_rgba32sint:
|
|
|
|
return wgpu::TextureFormat::RGBA32Sint;
|
|
|
|
default:
|
|
|
|
return wgpu::TextureFormat::Undefined;
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 17:06:04 +00:00
|
|
|
|
|
|
|
std::string GetShaderDeclarationString(size_t group, uint32_t binding) {
|
|
|
|
std::ostringstream ostream;
|
|
|
|
ostream << "the shader module declaration at set " << group << " binding " << binding;
|
|
|
|
return ostream.str();
|
|
|
|
}
|
2019-09-26 00:12:41 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2020-04-21 08:04:48 +00:00
|
|
|
MaybeError ValidateSpirv(DeviceBase*, const uint32_t* code, uint32_t codeSize) {
|
2018-11-28 16:54:31 +00:00
|
|
|
spvtools::SpirvTools spirvTools(SPV_ENV_VULKAN_1_1);
|
2018-09-06 15:25:46 +00:00
|
|
|
|
|
|
|
std::ostringstream errorStream;
|
|
|
|
errorStream << "SPIRV Validation failure:" << std::endl;
|
|
|
|
|
|
|
|
spirvTools.SetMessageConsumer([&errorStream](spv_message_level_t level, const char*,
|
|
|
|
const spv_position_t& position,
|
|
|
|
const char* message) {
|
|
|
|
switch (level) {
|
|
|
|
case SPV_MSG_FATAL:
|
|
|
|
case SPV_MSG_INTERNAL_ERROR:
|
|
|
|
case SPV_MSG_ERROR:
|
|
|
|
errorStream << "error: line " << position.index << ": " << message << std::endl;
|
|
|
|
break;
|
|
|
|
case SPV_MSG_WARNING:
|
|
|
|
errorStream << "warning: line " << position.index << ": " << message
|
|
|
|
<< std::endl;
|
|
|
|
break;
|
|
|
|
case SPV_MSG_INFO:
|
|
|
|
errorStream << "info: line " << position.index << ": " << message << std::endl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-21 08:04:48 +00:00
|
|
|
if (!spirvTools.Validate(code, codeSize)) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
2018-09-06 15:25:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 08:04:48 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-05-21 13:42:26 +00:00
|
|
|
#ifdef DAWN_ENABLE_WGSL
|
|
|
|
MaybeError ValidateWGSL(const char* source) {
|
|
|
|
std::ostringstream errorStream;
|
|
|
|
errorStream << "Tint WGSL failure:" << std::endl;
|
|
|
|
|
|
|
|
tint::Context context;
|
|
|
|
tint::reader::wgsl::Parser parser(&context, source);
|
|
|
|
|
|
|
|
if (!parser.Parse()) {
|
|
|
|
errorStream << "Parser: " << parser.error() << std::endl;
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
tint::ast::Module module = parser.module();
|
|
|
|
if (!module.IsValid()) {
|
|
|
|
errorStream << "Invalid module generated..." << std::endl;
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
tint::TypeDeterminer type_determiner(&context, &module);
|
|
|
|
if (!type_determiner.Determine()) {
|
|
|
|
errorStream << "Type Determination: " << type_determiner.error();
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
tint::Validator validator;
|
|
|
|
if (!validator.Validate(module)) {
|
|
|
|
errorStream << "Validation: " << validator.error() << std::endl;
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultOrError<std::vector<uint32_t>> ConvertWGSLToSPIRV(const char* source) {
|
|
|
|
std::ostringstream errorStream;
|
|
|
|
errorStream << "Tint WGSL->SPIR-V failure:" << std::endl;
|
|
|
|
|
|
|
|
tint::Context context;
|
|
|
|
tint::reader::wgsl::Parser parser(&context, source);
|
|
|
|
|
|
|
|
// TODO: This is a duplicate parse with ValidateWGSL, need to store
|
|
|
|
// state between calls to avoid this.
|
|
|
|
if (!parser.Parse()) {
|
|
|
|
errorStream << "Parser: " << parser.error() << std::endl;
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
tint::ast::Module module = parser.module();
|
|
|
|
if (!module.IsValid()) {
|
|
|
|
errorStream << "Invalid module generated..." << std::endl;
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
tint::TypeDeterminer type_determiner(&context, &module);
|
|
|
|
if (!type_determiner.Determine()) {
|
|
|
|
errorStream << "Type Determination: " << type_determiner.error();
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
tint::writer::spirv::Generator generator(std::move(module));
|
|
|
|
if (!generator.Generate()) {
|
|
|
|
errorStream << "Generator: " << generator.error() << std::endl;
|
|
|
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<uint32_t> spirv = generator.result();
|
|
|
|
return std::move(spirv);
|
|
|
|
}
|
|
|
|
#endif // DAWN_ENABLE_WGSL
|
|
|
|
|
2020-04-21 08:04:48 +00:00
|
|
|
MaybeError ValidateShaderModuleDescriptor(DeviceBase* device,
|
|
|
|
const ShaderModuleDescriptor* descriptor) {
|
|
|
|
const ChainedStruct* chainedDescriptor = descriptor->nextInChain;
|
2020-05-08 18:05:19 +00:00
|
|
|
if (chainedDescriptor == nullptr) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Shader module descriptor missing chained descriptor");
|
|
|
|
}
|
|
|
|
// For now only a single SPIRV or WGSL subdescriptor is allowed.
|
2020-04-21 08:04:48 +00:00
|
|
|
if (chainedDescriptor->nextInChain != nullptr) {
|
2020-05-08 18:05:19 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Shader module descriptor chained nextInChain must be nullptr");
|
2020-04-21 08:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (chainedDescriptor->sType) {
|
|
|
|
case wgpu::SType::ShaderModuleSPIRVDescriptor: {
|
2020-05-21 13:42:26 +00:00
|
|
|
const auto* spirvDesc =
|
2020-04-21 08:04:48 +00:00
|
|
|
static_cast<const ShaderModuleSPIRVDescriptor*>(chainedDescriptor);
|
|
|
|
DAWN_TRY(ValidateSpirv(device, spirvDesc->code, spirvDesc->codeSize));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case wgpu::SType::ShaderModuleWGSLDescriptor: {
|
2020-05-21 13:42:26 +00:00
|
|
|
#ifdef DAWN_ENABLE_WGSL
|
|
|
|
const auto* wgslDesc =
|
|
|
|
static_cast<const ShaderModuleWGSLDescriptor*>(chainedDescriptor);
|
|
|
|
DAWN_TRY(ValidateWGSL(wgslDesc->source));
|
2020-04-21 08:04:48 +00:00
|
|
|
break;
|
2020-05-21 13:42:26 +00:00
|
|
|
#else
|
|
|
|
return DAWN_VALIDATION_ERROR("WGSL not supported (yet)");
|
|
|
|
#endif // DAWN_ENABLE_WGSL
|
2020-04-21 08:04:48 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return DAWN_VALIDATION_ERROR("Unsupported sType");
|
|
|
|
}
|
|
|
|
|
2018-08-20 15:01:20 +00:00
|
|
|
return {};
|
2020-03-17 10:28:07 +00:00
|
|
|
} // namespace
|
2018-08-20 15:01:20 +00:00
|
|
|
|
|
|
|
// ShaderModuleBase
|
|
|
|
|
2019-10-30 00:20:03 +00:00
|
|
|
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor)
|
2020-05-21 13:42:26 +00:00
|
|
|
: CachedObject(device), mType(Type::Undefined) {
|
2020-05-13 17:23:35 +00:00
|
|
|
ASSERT(descriptor->nextInChain != nullptr);
|
2020-05-21 13:42:26 +00:00
|
|
|
switch (descriptor->nextInChain->sType) {
|
|
|
|
case wgpu::SType::ShaderModuleSPIRVDescriptor: {
|
|
|
|
mType = Type::Spirv;
|
|
|
|
const auto* spirvDesc =
|
|
|
|
static_cast<const ShaderModuleSPIRVDescriptor*>(descriptor->nextInChain);
|
|
|
|
mSpirv.assign(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wgpu::SType::ShaderModuleWGSLDescriptor: {
|
|
|
|
mType = Type::Wgsl;
|
|
|
|
const auto* wgslDesc =
|
|
|
|
static_cast<const ShaderModuleWGSLDescriptor*>(descriptor->nextInChain);
|
|
|
|
mWgsl = std::string(wgslDesc->source);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2020-04-21 08:04:48 +00:00
|
|
|
|
2019-09-26 00:12:41 +00:00
|
|
|
mFragmentOutputFormatBaseTypes.fill(Format::Other);
|
2020-02-07 16:30:27 +00:00
|
|
|
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvcParser)) {
|
|
|
|
mSpvcContext.SetUseSpvcParser(true);
|
|
|
|
}
|
2017-07-26 16:35:35 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
2020-05-21 13:42:26 +00:00
|
|
|
: CachedObject(device, tag), mType(Type::Undefined) {
|
2019-02-13 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:27:07 +00:00
|
|
|
ShaderModuleBase::~ShaderModuleBase() {
|
2019-10-30 00:20:03 +00:00
|
|
|
if (IsCachedReference()) {
|
2019-05-01 13:27:07 +00:00
|
|
|
GetDevice()->UncacheShaderModule(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
// static
|
|
|
|
ShaderModuleBase* ShaderModuleBase::MakeError(DeviceBase* device) {
|
|
|
|
return new ShaderModuleBase(device, ObjectBase::kError);
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:56:22 +00:00
|
|
|
MaybeError ShaderModuleBase::ExtractSpirvInfo(const spirv_cross::Compiler& compiler) {
|
2019-02-13 13:09:18 +00:00
|
|
|
ASSERT(!IsError());
|
2020-01-14 16:29:41 +00:00
|
|
|
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(ExtractSpirvInfoWithSpvc());
|
2020-01-14 16:29:41 +00:00
|
|
|
} else {
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(ExtractSpirvInfoWithSpirvCross(compiler));
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
return {};
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:56:22 +00:00
|
|
|
MaybeError ShaderModuleBase::ExtractSpirvInfoWithSpvc() {
|
2020-01-14 16:29:41 +00:00
|
|
|
shaderc_spvc_execution_model execution_model;
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.GetExecutionModel(&execution_model),
|
|
|
|
"Unable to get execution model for shader."));
|
2020-03-23 15:08:41 +00:00
|
|
|
mExecutionModel = ToSingleShaderStage(execution_model);
|
2020-01-14 16:29:41 +00:00
|
|
|
|
|
|
|
size_t push_constant_buffers_count;
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(
|
|
|
|
CheckSpvcSuccess(mSpvcContext.GetPushConstantBufferCount(&push_constant_buffers_count),
|
|
|
|
"Unable to get push constant buffer count for shader."));
|
2020-01-14 16:29:41 +00:00
|
|
|
|
|
|
|
// TODO(rharrison): This should be handled by spirv-val pass in spvc,
|
|
|
|
// but need to confirm.
|
|
|
|
if (push_constant_buffers_count > 0) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Push constants aren't supported.");
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fill in bindingInfo with the SPIRV bindings
|
2020-01-15 14:56:22 +00:00
|
|
|
auto ExtractResourcesBinding =
|
|
|
|
[this](std::vector<shaderc_spvc_binding_info> bindings) -> MaybeError {
|
2020-01-14 16:29:41 +00:00
|
|
|
for (const auto& binding : bindings) {
|
2020-03-20 21:56:30 +00:00
|
|
|
if (binding.set >= kMaxBindGroups) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Bind group index over limits in the SPIRV");
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 21:56:30 +00:00
|
|
|
const auto& it = mBindingInfo[binding.set].emplace(BindingNumber(binding.binding),
|
2020-03-27 18:54:03 +00:00
|
|
|
ShaderBindingInfo{});
|
2020-03-20 21:56:30 +00:00
|
|
|
if (!it.second) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Shader has duplicate bindings");
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:54:03 +00:00
|
|
|
ShaderBindingInfo* info = &it.first->second;
|
2020-01-14 16:29:41 +00:00
|
|
|
info->id = binding.id;
|
|
|
|
info->base_type_id = binding.base_type_id;
|
|
|
|
info->type = ToWGPUBindingType(binding.binding_type);
|
2020-03-19 14:25:51 +00:00
|
|
|
|
|
|
|
switch (info->type) {
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
case wgpu::BindingType::SampledTexture: {
|
|
|
|
info->multisampled = binding.multisampled;
|
2020-04-20 08:10:10 +00:00
|
|
|
info->viewDimension = ToWGPUTextureViewDimension(binding.texture_dimension);
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
info->textureComponentType =
|
|
|
|
ToDawnFormatType(binding.texture_component_type);
|
2020-04-02 16:45:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-03-19 14:25:51 +00:00
|
|
|
case wgpu::BindingType::StorageTexture:
|
|
|
|
case wgpu::BindingType::ReadonlyStorageTexture:
|
|
|
|
case wgpu::BindingType::WriteonlyStorageTexture: {
|
|
|
|
wgpu::TextureFormat storageTextureFormat =
|
|
|
|
ToWGPUTextureFormat(binding.storage_texture_format);
|
|
|
|
if (storageTextureFormat == wgpu::TextureFormat::Undefined) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Invalid image format declaration on storage image");
|
|
|
|
}
|
|
|
|
const Format& format =
|
|
|
|
GetDevice()->GetValidInternalFormat(storageTextureFormat);
|
|
|
|
if (!format.supportsStorageUsage) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The storage texture format is not supported");
|
|
|
|
}
|
2020-03-26 00:46:38 +00:00
|
|
|
info->multisampled = binding.multisampled;
|
2020-03-19 14:25:51 +00:00
|
|
|
info->storageTextureFormat = storageTextureFormat;
|
2020-04-20 08:10:10 +00:00
|
|
|
info->viewDimension = ToWGPUTextureViewDimension(binding.texture_dimension);
|
2020-04-02 16:45:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-03-19 14:25:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
return {};
|
2020-01-14 16:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<shaderc_spvc_binding_info> resource_bindings;
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.GetBindingInfo(
|
|
|
|
shaderc_spvc_shader_resource_uniform_buffers,
|
|
|
|
shaderc_spvc_binding_type_uniform_buffer, &resource_bindings),
|
|
|
|
"Unable to get binding info for uniform buffers from shader"));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resource_bindings));
|
|
|
|
|
|
|
|
DAWN_TRY(CheckSpvcSuccess(
|
|
|
|
mSpvcContext.GetBindingInfo(shaderc_spvc_shader_resource_separate_images,
|
|
|
|
shaderc_spvc_binding_type_sampled_texture,
|
|
|
|
&resource_bindings),
|
|
|
|
"Unable to get binding info for sampled textures from shader"));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resource_bindings));
|
|
|
|
|
|
|
|
DAWN_TRY(CheckSpvcSuccess(
|
|
|
|
mSpvcContext.GetBindingInfo(shaderc_spvc_shader_resource_separate_samplers,
|
|
|
|
shaderc_spvc_binding_type_sampler, &resource_bindings),
|
|
|
|
"Unable to get binding info for samples from shader"));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resource_bindings));
|
|
|
|
|
|
|
|
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.GetBindingInfo(
|
|
|
|
shaderc_spvc_shader_resource_storage_buffers,
|
|
|
|
shaderc_spvc_binding_type_storage_buffer, &resource_bindings),
|
|
|
|
"Unable to get binding info for storage buffers from shader"));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resource_bindings));
|
2020-01-14 16:29:41 +00:00
|
|
|
|
2020-03-18 16:33:58 +00:00
|
|
|
DAWN_TRY(CheckSpvcSuccess(
|
|
|
|
mSpvcContext.GetBindingInfo(shaderc_spvc_shader_resource_storage_images,
|
|
|
|
shaderc_spvc_binding_type_storage_texture,
|
|
|
|
&resource_bindings),
|
|
|
|
"Unable to get binding info for storage textures from shader"));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resource_bindings));
|
|
|
|
|
2020-01-14 16:29:41 +00:00
|
|
|
std::vector<shaderc_spvc_resource_location_info> input_stage_locations;
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.GetInputStageLocationInfo(&input_stage_locations),
|
|
|
|
"Unable to get input stage location information from shader"));
|
2019-02-13 13:09:18 +00:00
|
|
|
|
2020-01-14 16:29:41 +00:00
|
|
|
for (const auto& input : input_stage_locations) {
|
|
|
|
if (mExecutionModel == SingleShaderStage::Vertex) {
|
|
|
|
if (input.location >= kMaxVertexAttributes) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Attribute location over limits in the SPIRV");
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
mUsedVertexAttributes.set(input.location);
|
|
|
|
} else if (mExecutionModel == SingleShaderStage::Fragment) {
|
|
|
|
// Without a location qualifier on vertex inputs, spirv_cross::CompilerMSL gives
|
|
|
|
// them all the location 0, causing a compile error.
|
|
|
|
if (!input.has_location) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Need location qualifier on fragment input");
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<shaderc_spvc_resource_location_info> output_stage_locations;
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.GetOutputStageLocationInfo(&output_stage_locations),
|
|
|
|
"Unable to get output stage location information from shader"));
|
2020-01-14 16:29:41 +00:00
|
|
|
|
|
|
|
for (const auto& output : output_stage_locations) {
|
|
|
|
if (mExecutionModel == SingleShaderStage::Vertex) {
|
|
|
|
// Without a location qualifier on vertex outputs, spirv_cross::CompilerMSL
|
|
|
|
// gives them all the location 0, causing a compile error.
|
|
|
|
if (!output.has_location) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Need location qualifier on vertex output");
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
} else if (mExecutionModel == SingleShaderStage::Fragment) {
|
|
|
|
if (output.location >= kMaxColorAttachments) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Fragment output location over limits in the SPIRV");
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mExecutionModel == SingleShaderStage::Fragment) {
|
|
|
|
std::vector<shaderc_spvc_resource_type_info> output_types;
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.GetOutputStageTypeInfo(&output_types),
|
|
|
|
"Unable to get output stage type information from shader"));
|
2020-01-14 16:29:41 +00:00
|
|
|
|
|
|
|
for (const auto& output : output_types) {
|
2020-01-15 14:56:22 +00:00
|
|
|
if (output.type == shaderc_spvc_texture_format_type_other) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Unexpected Fragment output type");
|
|
|
|
}
|
2020-01-14 16:29:41 +00:00
|
|
|
mFragmentOutputFormatBaseTypes[output.location] = ToDawnFormatType(output.type);
|
|
|
|
}
|
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
return {};
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:56:22 +00:00
|
|
|
MaybeError ShaderModuleBase::ExtractSpirvInfoWithSpirvCross(
|
|
|
|
const spirv_cross::Compiler& compiler) {
|
2019-04-01 21:48:38 +00:00
|
|
|
// TODO(cwallez@chromium.org): make errors here creation errors
|
2017-06-05 20:23:18 +00:00
|
|
|
// currently errors here do not prevent the shadermodule from being used
|
2017-04-20 18:38:20 +00:00
|
|
|
const auto& resources = compiler.get_shader_resources();
|
|
|
|
|
|
|
|
switch (compiler.get_execution_model()) {
|
|
|
|
case spv::ExecutionModelVertex:
|
2019-08-27 08:42:29 +00:00
|
|
|
mExecutionModel = SingleShaderStage::Vertex;
|
2017-04-20 18:38:20 +00:00
|
|
|
break;
|
|
|
|
case spv::ExecutionModelFragment:
|
2019-08-27 08:42:29 +00:00
|
|
|
mExecutionModel = SingleShaderStage::Fragment;
|
2017-04-20 18:38:20 +00:00
|
|
|
break;
|
|
|
|
case spv::ExecutionModelGLCompute:
|
2019-08-27 08:42:29 +00:00
|
|
|
mExecutionModel = SingleShaderStage::Compute;
|
2017-04-20 18:38:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-07-11 01:48:12 +00:00
|
|
|
UNREACHABLE();
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Unexpected shader execution model");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resources.push_constant_buffers.size() > 0) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Push constants aren't supported.");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 10:38:36 +00:00
|
|
|
if (resources.sampled_images.size() > 0) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Combined images and samplers aren't supported.");
|
|
|
|
}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
// Fill in bindingInfo with the SPIRV bindings
|
2020-01-14 16:29:41 +00:00
|
|
|
auto ExtractResourcesBinding =
|
|
|
|
[this](const spirv_cross::SmallVector<spirv_cross::Resource>& resources,
|
2020-01-15 14:56:22 +00:00
|
|
|
const spirv_cross::Compiler& compiler,
|
|
|
|
wgpu::BindingType bindingType) -> MaybeError {
|
|
|
|
for (const auto& resource : resources) {
|
|
|
|
if (!compiler.get_decoration_bitset(resource.id).get(spv::DecorationBinding)) {
|
|
|
|
return DAWN_VALIDATION_ERROR("No Binding decoration set for resource");
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2020-01-15 14:56:22 +00:00
|
|
|
if (!compiler.get_decoration_bitset(resource.id)
|
|
|
|
.get(spv::DecorationDescriptorSet)) {
|
|
|
|
return DAWN_VALIDATION_ERROR("No Descriptor Decoration set for resource");
|
|
|
|
}
|
|
|
|
|
2020-03-20 21:56:30 +00:00
|
|
|
BindingNumber bindingNumber(
|
|
|
|
compiler.get_decoration(resource.id, spv::DecorationBinding));
|
2020-01-15 14:56:22 +00:00
|
|
|
uint32_t set = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet);
|
|
|
|
|
2020-03-20 21:56:30 +00:00
|
|
|
if (set >= kMaxBindGroups) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Bind group index over limits in the SPIRV");
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:54:03 +00:00
|
|
|
const auto& it = mBindingInfo[set].emplace(bindingNumber, ShaderBindingInfo{});
|
2020-03-20 21:56:30 +00:00
|
|
|
if (!it.second) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Shader has duplicate bindings");
|
2020-01-15 14:56:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:54:03 +00:00
|
|
|
ShaderBindingInfo* info = &it.first->second;
|
2020-01-15 14:56:22 +00:00
|
|
|
info->id = resource.id;
|
|
|
|
info->base_type_id = resource.base_type_id;
|
2020-03-27 18:54:03 +00:00
|
|
|
|
2020-01-15 14:56:22 +00:00
|
|
|
switch (bindingType) {
|
|
|
|
case wgpu::BindingType::SampledTexture: {
|
|
|
|
spirv_cross::SPIRType::ImageType imageType =
|
|
|
|
compiler.get_type(info->base_type_id).image;
|
|
|
|
spirv_cross::SPIRType::BaseType textureComponentType =
|
|
|
|
compiler.get_type(imageType.type).basetype;
|
|
|
|
|
|
|
|
info->multisampled = imageType.ms;
|
2020-04-20 08:10:10 +00:00
|
|
|
info->viewDimension =
|
2020-01-15 14:56:22 +00:00
|
|
|
SpirvDimToTextureViewDimension(imageType.dim, imageType.arrayed);
|
|
|
|
info->textureComponentType =
|
|
|
|
SpirvCrossBaseTypeToFormatType(textureComponentType);
|
|
|
|
info->type = bindingType;
|
2020-04-02 16:45:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
case wgpu::BindingType::StorageBuffer: {
|
|
|
|
// Differentiate between readonly storage bindings and writable ones
|
|
|
|
// based on the NonWritable decoration
|
|
|
|
spirv_cross::Bitset flags = compiler.get_buffer_block_flags(resource.id);
|
|
|
|
if (flags.get(spv::DecorationNonWritable)) {
|
|
|
|
info->type = wgpu::BindingType::ReadonlyStorageBuffer;
|
|
|
|
} else {
|
|
|
|
info->type = wgpu::BindingType::StorageBuffer;
|
|
|
|
}
|
2020-04-02 16:45:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-03-11 01:28:48 +00:00
|
|
|
case wgpu::BindingType::StorageTexture: {
|
|
|
|
spirv_cross::Bitset flags = compiler.get_decoration_bitset(resource.id);
|
|
|
|
if (flags.get(spv::DecorationNonReadable)) {
|
|
|
|
info->type = wgpu::BindingType::WriteonlyStorageTexture;
|
|
|
|
} else if (flags.get(spv::DecorationNonWritable)) {
|
|
|
|
info->type = wgpu::BindingType::ReadonlyStorageTexture;
|
|
|
|
} else {
|
|
|
|
info->type = wgpu::BindingType::StorageTexture;
|
|
|
|
}
|
2020-03-17 10:28:07 +00:00
|
|
|
|
|
|
|
spirv_cross::SPIRType::ImageType imageType =
|
|
|
|
compiler.get_type(info->base_type_id).image;
|
|
|
|
wgpu::TextureFormat storageTextureFormat =
|
|
|
|
ToWGPUTextureFormat(imageType.format);
|
|
|
|
if (storageTextureFormat == wgpu::TextureFormat::Undefined) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Invalid image format declaration on storage image");
|
|
|
|
}
|
|
|
|
const Format& format =
|
|
|
|
GetDevice()->GetValidInternalFormat(storageTextureFormat);
|
|
|
|
if (!format.supportsStorageUsage) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The storage texture format is not supported");
|
|
|
|
}
|
2020-03-26 00:46:38 +00:00
|
|
|
info->multisampled = imageType.ms;
|
2020-03-17 10:28:07 +00:00
|
|
|
info->storageTextureFormat = storageTextureFormat;
|
2020-04-20 08:10:10 +00:00
|
|
|
info->viewDimension =
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
SpirvDimToTextureViewDimension(imageType.dim, imageType.arrayed);
|
2020-04-02 16:45:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
default:
|
|
|
|
info->type = bindingType;
|
2019-10-31 09:51:11 +00:00
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
};
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2020-01-15 14:56:22 +00:00
|
|
|
DAWN_TRY(ExtractResourcesBinding(resources.uniform_buffers, compiler,
|
|
|
|
wgpu::BindingType::UniformBuffer));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resources.separate_images, compiler,
|
|
|
|
wgpu::BindingType::SampledTexture));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resources.separate_samplers, compiler,
|
|
|
|
wgpu::BindingType::Sampler));
|
|
|
|
DAWN_TRY(ExtractResourcesBinding(resources.storage_buffers, compiler,
|
|
|
|
wgpu::BindingType::StorageBuffer));
|
2020-03-11 01:28:48 +00:00
|
|
|
DAWN_TRY(ExtractResourcesBinding(resources.storage_images, compiler,
|
|
|
|
wgpu::BindingType::StorageTexture));
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
// Extract the vertex attributes
|
2019-08-27 08:42:29 +00:00
|
|
|
if (mExecutionModel == SingleShaderStage::Vertex) {
|
2017-04-20 18:38:20 +00:00
|
|
|
for (const auto& attrib : resources.stage_inputs) {
|
2020-01-15 14:56:22 +00:00
|
|
|
if (!(compiler.get_decoration_bitset(attrib.id).get(spv::DecorationLocation))) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Unable to find Location decoration for Vertex input");
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
uint32_t location = compiler.get_decoration(attrib.id, spv::DecorationLocation);
|
|
|
|
|
|
|
|
if (location >= kMaxVertexAttributes) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Attribute location over limits in the SPIRV");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
mUsedVertexAttributes.set(location);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 16:29:41 +00:00
|
|
|
// Without a location qualifier on vertex outputs, spirv_cross::CompilerMSL gives
|
|
|
|
// them all the location 0, causing a compile error.
|
2017-04-20 18:38:20 +00:00
|
|
|
for (const auto& attrib : resources.stage_outputs) {
|
2018-08-24 12:51:21 +00:00
|
|
|
if (!compiler.get_decoration_bitset(attrib.id).get(spv::DecorationLocation)) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Need location qualifier on vertex output");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 08:42:29 +00:00
|
|
|
if (mExecutionModel == SingleShaderStage::Fragment) {
|
2020-01-14 16:29:41 +00:00
|
|
|
// Without a location qualifier on vertex inputs, spirv_cross::CompilerMSL gives
|
|
|
|
// them all the location 0, causing a compile error.
|
2017-04-20 18:38:20 +00:00
|
|
|
for (const auto& attrib : resources.stage_inputs) {
|
2018-08-24 12:51:21 +00:00
|
|
|
if (!compiler.get_decoration_bitset(attrib.id).get(spv::DecorationLocation)) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Need location qualifier on fragment input");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 01:21:28 +00:00
|
|
|
|
|
|
|
for (const auto& fragmentOutput : resources.stage_outputs) {
|
2020-01-15 14:56:22 +00:00
|
|
|
if (!compiler.get_decoration_bitset(fragmentOutput.id)
|
|
|
|
.get(spv::DecorationLocation)) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Unable to find Location decoration for Fragment output");
|
|
|
|
}
|
2019-09-25 01:21:28 +00:00
|
|
|
uint32_t location =
|
|
|
|
compiler.get_decoration(fragmentOutput.id, spv::DecorationLocation);
|
|
|
|
if (location >= kMaxColorAttachments) {
|
2020-01-15 14:56:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Fragment output location over limits in the SPIRV");
|
2019-09-25 01:21:28 +00:00
|
|
|
}
|
2019-09-26 00:12:41 +00:00
|
|
|
|
|
|
|
spirv_cross::SPIRType::BaseType shaderFragmentOutputBaseType =
|
|
|
|
compiler.get_type(fragmentOutput.base_type_id).basetype;
|
|
|
|
Format::Type formatType =
|
|
|
|
SpirvCrossBaseTypeToFormatType(shaderFragmentOutputBaseType);
|
2020-01-15 14:56:22 +00:00
|
|
|
if (formatType == Format::Type::Other) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Unexpected Fragment output type");
|
2020-04-11 03:22:33 +00:00
|
|
|
}
|
2019-09-26 00:12:41 +00:00
|
|
|
mFragmentOutputFormatBaseTypes[location] = formatType;
|
2019-09-25 01:21:28 +00:00
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
return {};
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ShaderModuleBase::ModuleBindingInfo& ShaderModuleBase::GetBindingInfo() const {
|
2019-02-13 13:09:18 +00:00
|
|
|
ASSERT(!IsError());
|
2017-11-23 18:32:51 +00:00
|
|
|
return mBindingInfo;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::bitset<kMaxVertexAttributes>& ShaderModuleBase::GetUsedVertexAttributes() const {
|
2019-02-13 13:09:18 +00:00
|
|
|
ASSERT(!IsError());
|
2017-11-23 18:32:51 +00:00
|
|
|
return mUsedVertexAttributes;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 00:12:41 +00:00
|
|
|
const ShaderModuleBase::FragmentOutputBaseTypes& ShaderModuleBase::GetFragmentOutputBaseTypes()
|
|
|
|
const {
|
|
|
|
ASSERT(!IsError());
|
|
|
|
return mFragmentOutputFormatBaseTypes;
|
|
|
|
}
|
|
|
|
|
2019-08-27 08:42:29 +00:00
|
|
|
SingleShaderStage ShaderModuleBase::GetExecutionModel() const {
|
2019-02-13 13:09:18 +00:00
|
|
|
ASSERT(!IsError());
|
2017-11-23 18:32:51 +00:00
|
|
|
return mExecutionModel;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 17:06:04 +00:00
|
|
|
MaybeError ShaderModuleBase::ValidateCompatibilityWithPipelineLayout(
|
|
|
|
const PipelineLayoutBase* layout) const {
|
2019-02-13 13:09:18 +00:00
|
|
|
ASSERT(!IsError());
|
|
|
|
|
2019-02-11 23:35:33 +00:00
|
|
|
for (uint32_t group : IterateBitSet(layout->GetBindGroupLayoutsMask())) {
|
2020-06-09 17:06:04 +00:00
|
|
|
DAWN_TRY(
|
|
|
|
ValidateCompatibilityWithBindGroupLayout(group, layout->GetBindGroupLayout(group)));
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
2019-02-11 23:35:33 +00:00
|
|
|
|
|
|
|
for (uint32_t group : IterateBitSet(~layout->GetBindGroupLayoutsMask())) {
|
2020-03-20 21:56:30 +00:00
|
|
|
if (mBindingInfo[group].size() > 0) {
|
2020-06-09 17:06:04 +00:00
|
|
|
std::ostringstream ostream;
|
|
|
|
ostream << "No bind group layout entry matches the declaration set " << group
|
|
|
|
<< " in the shader module";
|
|
|
|
return DAWN_VALIDATION_ERROR(ostream.str());
|
2019-02-11 23:35:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 17:06:04 +00:00
|
|
|
return {};
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 17:06:04 +00:00
|
|
|
MaybeError ShaderModuleBase::ValidateCompatibilityWithBindGroupLayout(
|
2019-11-22 17:02:22 +00:00
|
|
|
size_t group,
|
|
|
|
const BindGroupLayoutBase* layout) const {
|
2019-02-13 13:09:18 +00:00
|
|
|
ASSERT(!IsError());
|
|
|
|
|
2020-03-20 21:56:30 +00:00
|
|
|
const BindGroupLayoutBase::BindingMap& bindingMap = layout->GetBindingMap();
|
|
|
|
|
|
|
|
// Iterate over all bindings used by this group in the shader, and find the
|
|
|
|
// corresponding binding in the BindGroupLayout, if it exists.
|
|
|
|
for (const auto& it : mBindingInfo[group]) {
|
|
|
|
BindingNumber bindingNumber = it.first;
|
2020-03-27 18:54:03 +00:00
|
|
|
const ShaderBindingInfo& moduleInfo = it.second;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2020-03-20 21:56:30 +00:00
|
|
|
const auto& bindingIt = bindingMap.find(bindingNumber);
|
|
|
|
if (bindingIt == bindingMap.end()) {
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Missing bind group layout entry for " +
|
|
|
|
GetShaderDeclarationString(group, bindingNumber));
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
2020-03-20 21:56:30 +00:00
|
|
|
BindingIndex bindingIndex(bindingIt->second);
|
|
|
|
|
2020-03-27 18:54:03 +00:00
|
|
|
const BindingInfo& bindingInfo = layout->GetBindingInfo(bindingIndex);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2020-03-27 18:54:03 +00:00
|
|
|
if (bindingInfo.type != moduleInfo.type) {
|
2019-11-11 20:05:28 +00:00
|
|
|
// 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.
|
|
|
|
bool validBindingConversion =
|
2020-03-27 18:54:03 +00:00
|
|
|
bindingInfo.type == wgpu::BindingType::StorageBuffer &&
|
2019-11-11 20:05:28 +00:00
|
|
|
moduleInfo.type == wgpu::BindingType::ReadonlyStorageBuffer;
|
2020-04-20 23:43:20 +00:00
|
|
|
|
|
|
|
// TODO(crbug.com/dawn/367): Temporarily allow using either a sampler or a
|
|
|
|
// comparison sampler until we can perform the proper shader analysis of what type
|
|
|
|
// is used in the shader module.
|
|
|
|
validBindingConversion |= (bindingInfo.type == wgpu::BindingType::Sampler &&
|
|
|
|
moduleInfo.type == wgpu::BindingType::ComparisonSampler);
|
|
|
|
validBindingConversion |=
|
|
|
|
(bindingInfo.type == wgpu::BindingType::ComparisonSampler &&
|
|
|
|
moduleInfo.type == wgpu::BindingType::Sampler);
|
|
|
|
|
2019-11-11 20:05:28 +00:00
|
|
|
if (!validBindingConversion) {
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The binding type of the bind group layout entry conflicts " +
|
|
|
|
GetShaderDeclarationString(group, bindingNumber));
|
2019-11-11 20:05:28 +00:00
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
2019-05-17 02:05:37 +00:00
|
|
|
|
2020-03-26 17:22:14 +00:00
|
|
|
if ((bindingInfo.visibility & StageBit(mExecutionModel)) == 0) {
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("The bind group layout entry for " +
|
|
|
|
GetShaderDeclarationString(group, bindingNumber) +
|
|
|
|
" is not visible for the shader stage");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
2019-10-31 09:51:11 +00:00
|
|
|
|
2020-03-27 18:54:03 +00:00
|
|
|
switch (bindingInfo.type) {
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
case wgpu::BindingType::SampledTexture: {
|
2020-03-27 18:54:03 +00:00
|
|
|
if (bindingInfo.textureComponentType != moduleInfo.textureComponentType) {
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The textureComponentType of the bind group layout entry is different "
|
|
|
|
"from " +
|
|
|
|
GetShaderDeclarationString(group, bindingNumber));
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 08:10:10 +00:00
|
|
|
if (bindingInfo.viewDimension != moduleInfo.viewDimension) {
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The viewDimension of the bind group layout entry is different "
|
|
|
|
"from " +
|
|
|
|
GetShaderDeclarationString(group, bindingNumber));
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
}
|
2020-04-02 16:45:17 +00:00
|
|
|
break;
|
|
|
|
}
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
|
|
|
|
case wgpu::BindingType::ReadonlyStorageTexture:
|
|
|
|
case wgpu::BindingType::WriteonlyStorageTexture: {
|
2020-03-26 17:22:14 +00:00
|
|
|
ASSERT(bindingInfo.storageTextureFormat != wgpu::TextureFormat::Undefined);
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
ASSERT(moduleInfo.storageTextureFormat != wgpu::TextureFormat::Undefined);
|
2020-03-26 17:22:14 +00:00
|
|
|
if (bindingInfo.storageTextureFormat != moduleInfo.storageTextureFormat) {
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The storageTextureFormat of the bind group layout entry is different "
|
|
|
|
"from " +
|
|
|
|
GetShaderDeclarationString(group, bindingNumber));
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
}
|
2020-04-20 08:10:10 +00:00
|
|
|
if (bindingInfo.viewDimension != moduleInfo.viewDimension) {
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The viewDimension of the bind group layout entry is different "
|
|
|
|
"from " +
|
|
|
|
GetShaderDeclarationString(group, bindingNumber));
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
}
|
2020-04-02 16:45:17 +00:00
|
|
|
break;
|
|
|
|
}
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
|
|
|
|
case wgpu::BindingType::UniformBuffer:
|
|
|
|
case wgpu::BindingType::ReadonlyStorageBuffer:
|
|
|
|
case wgpu::BindingType::StorageBuffer:
|
|
|
|
case wgpu::BindingType::Sampler:
|
2020-04-20 23:43:20 +00:00
|
|
|
case wgpu::BindingType::ComparisonSampler:
|
Reland "Check bind group layout with storage texture in pipeline descriptors"
This reverts commit 7c24b6b2ff192927720a2cfa0fdd2dae1614ee96.
Reason for revert: We can reland this CL now as the fix in shaderc has
been merged.
Note that the declaration whether a storage texture is multisampled or not
cannot be extracted correctly in SPVC. The fix in Dawn will be added after
it is fixed in shaderc.
Original change's description:
> Revert "Check bind group layout with storage texture in pipeline descriptors"
>
> This reverts commit 63f2666ee77c987a56c6be5bfc6bbb10d12a9f63.
>
> Reason for revert: causes failures in dawn_unittests after Dawn uses SPVC by default. We need a fix in both SPVC and this CL before re-landing.
>
> Original change's description:
> > Check bind group layout with storage texture in pipeline descriptors
> >
> > This patch adds all the validations on the use of bind group layout with
> > read-only storage texture and write-only storage texture in the creation
> > of pipeline objects.
> >
> > 1. GPUBindGroupLayout.bindingType must match the type of the storage
> > texture variable (read-only or write-only) in shader.
> > 2. GPUBindGroupLayout.storageTextureFormat must be a valid texture
> > format that supports STORAGE usage.
> > 3. GPUBindGroupLayout.storageTextureFormat must match the storage
> > texture format declaration in shader.
> > 4. GPUBindGroupLayout.textureDimension must match the storage texture
> > dimension declared in shader.
> >
> > BUG=dawn:267
> > TEST=dawn_unittests
> >
> > Change-Id: Ifa3c2194dc76de14f790a0a73868e69bbb31c814
> > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17167
> > Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
> > Reviewed-by: Kai Ninomiya <kainino@chromium.org>
>
> TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
>
> Change-Id: Idb4083b11f22fa7e4c5c8477bc4b65b58900746e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: dawn:267
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17380
> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
TBR=cwallez@chromium.org,kainino@chromium.org,yunchao.he@intel.com,jiawei.shao@intel.com,shaobo.yan@intel.com,hao.x.li@intel.com,enga@chromium.org,jiajie.hu@intel.com
Bug: dawn:267, chromium:1063570
Change-Id: If762cbb206e738f4e54e75c88d506fdf3a44f280
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17461
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2020-03-24 00:56:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wgpu::BindingType::StorageTexture:
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2020-06-09 17:06:04 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Unsupported binding type");
|
2019-10-31 09:51:11 +00:00
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 17:06:04 +00:00
|
|
|
return {};
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:27:07 +00:00
|
|
|
size_t ShaderModuleBase::HashFunc::operator()(const ShaderModuleBase* module) const {
|
|
|
|
size_t hash = 0;
|
|
|
|
|
2020-04-21 07:57:30 +00:00
|
|
|
for (uint32_t word : module->mSpirv) {
|
2019-05-01 13:27:07 +00:00
|
|
|
HashCombine(&hash, word);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderModuleBase::EqualityFunc::operator()(const ShaderModuleBase* a,
|
|
|
|
const ShaderModuleBase* b) const {
|
2020-04-21 07:57:30 +00:00
|
|
|
return a->mSpirv == b->mSpirv;
|
2019-05-01 13:27:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:56:22 +00:00
|
|
|
MaybeError ShaderModuleBase::CheckSpvcSuccess(shaderc_spvc_status status,
|
|
|
|
const char* error_msg) {
|
2020-01-14 16:29:41 +00:00
|
|
|
if (status != shaderc_spvc_status_success) {
|
2020-03-23 15:08:41 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(error_msg);
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
2020-01-15 14:56:22 +00:00
|
|
|
return {};
|
2020-01-14 16:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 07:57:30 +00:00
|
|
|
shaderc_spvc::Context* ShaderModuleBase::GetContext() {
|
|
|
|
return &mSpvcContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<uint32_t>& ShaderModuleBase::GetSpirv() const {
|
|
|
|
return mSpirv;
|
|
|
|
}
|
|
|
|
|
|
|
|
shaderc_spvc::CompileOptions ShaderModuleBase::GetCompileOptions() const {
|
2020-02-06 17:26:46 +00:00
|
|
|
shaderc_spvc::CompileOptions options;
|
|
|
|
options.SetValidate(GetDevice()->IsValidationEnabled());
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2020-05-21 13:42:26 +00:00
|
|
|
MaybeError ShaderModuleBase::InitializeBase() {
|
|
|
|
if (mType == Type::Wgsl) {
|
|
|
|
#ifdef DAWN_ENABLE_WGSL
|
|
|
|
DAWN_TRY_ASSIGN(mSpirv, ConvertWGSLToSPIRV(mWgsl.c_str()));
|
|
|
|
#else
|
|
|
|
return DAWN_VALIDATION_ERROR("WGSL not supported (yet)");
|
|
|
|
#endif // DAWN_ENABLE_WGSL
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|