#include <sstream>
#include <string>
#include <vector>
#include "dawn/common/Constants.h"
#include "dawn/native/ShaderModule.h"
#include "dawn/tests/unittests/validation/ValidationTest.h"
#include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class ShaderModuleValidationTest : public ValidationTest { … };
#if TINT_BUILD_SPV_READER
TEST_F(ShaderModuleValidationTest, CreationSuccess) {
const char* shader = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %fragColor
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpName %main "main"
OpName %fragColor "fragColor"
OpDecorate %fragColor Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%fragColor = OpVariable %_ptr_Output_v4float Output
%float_1 = OpConstant %float 1
%float_0 = OpConstant %float 0
%12 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%main = OpFunction %void None %3
%5 = OpLabel
OpStore %fragColor %12
OpReturn
OpFunctionEnd)";
utils::CreateShaderModuleFromASM(device, shader);
}
TEST_F(ShaderModuleValidationTest, CombinedTextureAndSampler) {
const char* shader = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %tex "tex"
OpDecorate %tex DescriptorSet 0
OpDecorate %tex Binding 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%7 = OpTypeImage %float 2D 0 0 0 1 Unknown
%8 = OpTypeSampledImage %7
%_ptr_UniformConstant_8 = OpTypePointer UniformConstant %8
%tex = OpVariable %_ptr_UniformConstant_8 UniformConstant
%main = OpFunction %void None %3
%5 = OpLabel
OpReturn
OpFunctionEnd
)";
ASSERT_DEVICE_ERROR(utils::CreateShaderModuleFromASM(device, shader));
}
TEST_F(ShaderModuleValidationTest, MultisampledArrayTexture) {
const char* shader = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %tex "tex"
OpDecorate %tex DescriptorSet 0
OpDecorate %tex Binding 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%7 = OpTypeImage %float 2D 0 1 1 1 Unknown
%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
%tex = OpVariable %_ptr_UniformConstant_7 UniformConstant
%main = OpFunction %void None %3
%5 = OpLabel
OpReturn
OpFunctionEnd
)";
ASSERT_DEVICE_ERROR(utils::CreateShaderModuleFromASM(device, shader));
}
const char* kShaderWithNonUniformDerivative = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %foo "foo" %x
OpExecutionMode %foo OriginUpperLeft
OpDecorate %x Location 0
%float = OpTypeFloat 32
%_ptr_Input_float = OpTypePointer Input %float
%x = OpVariable %_ptr_Input_float Input
%void = OpTypeVoid
%float_0 = OpConstantNull %float
%bool = OpTypeBool
%func_type = OpTypeFunction %void
%foo = OpFunction %void None %func_type
%foo_start = OpLabel
%x_value = OpLoad %float %x
%condition = OpFOrdGreaterThan %bool %x_value %float_0
OpSelectionMerge %merge None
OpBranchConditional %condition %true_branch %merge
%true_branch = OpLabel
%result = OpDPdx %float %x_value
OpBranch %merge
%merge = OpLabel
OpReturn
OpFunctionEnd)";
TEST_F(ShaderModuleValidationTest, NonUniformDerivatives_NoOptions) {
ASSERT_DEVICE_ERROR(utils::CreateShaderModuleFromASM(device, kShaderWithNonUniformDerivative));
}
TEST_F(ShaderModuleValidationTest, NonUniformDerivatives_FlagSetToFalse) {
wgpu::DawnShaderModuleSPIRVOptionsDescriptor spirv_options_desc = {};
spirv_options_desc.allowNonUniformDerivatives = false;
ASSERT_DEVICE_ERROR(utils::CreateShaderModuleFromASM(device, kShaderWithNonUniformDerivative,
&spirv_options_desc));
}
TEST_F(ShaderModuleValidationTest, NonUniformDerivatives_FlagSetToTrue) {
wgpu::DawnShaderModuleSPIRVOptionsDescriptor spirv_options_desc = {};
spirv_options_desc.allowNonUniformDerivatives = true;
utils::CreateShaderModuleFromASM(device, kShaderWithNonUniformDerivative, &spirv_options_desc);
}
#endif
TEST_F(ShaderModuleValidationTest, NoChainedDescriptor) { … }
TEST_F(ShaderModuleValidationTest, MultipleChainedDescriptor_WgslAndSpirv) { … }
TEST_F(ShaderModuleValidationTest, MultipleChainedDescriptor_WgslAndDawnSpirvOptions) { … }
TEST_F(ShaderModuleValidationTest, OnlySpirvOptionsDescriptor) { … }
TEST_F(ShaderModuleValidationTest, ShaderModuleCompilationOptionsNoFeature) { … }
TEST_F(ShaderModuleValidationTest, GetCompilationMessages) { … }
TEST_F(ShaderModuleValidationTest, MaximumShaderIOLocations) { … }
TEST_F(ShaderModuleValidationTest, MaximumInterStageShaderComponents) { … }
TEST_F(ShaderModuleValidationTest, OverridableConstantsNumericIDConflicts) { … }
TEST_F(ShaderModuleValidationTest, MaxBindingNumber) { … }
TEST_F(ShaderModuleValidationTest, MissingDecorations) { … }
TEST_F(ShaderModuleValidationTest, CreateErrorShaderModule) { … }
struct WGSLExtensionInfo { … };
const struct WGSLExtensionInfo kExtensions[] = …;
std::string EnableDependingWGSLExtensions(const WGSLExtensionInfo& extension) { … }
class ShaderModuleExtensionValidationTestBase : public ValidationTest { … };
class ShaderModuleExtensionValidationTestSafeNoFeature
: public ShaderModuleExtensionValidationTestBase { … };
TEST_F(ShaderModuleExtensionValidationTestSafeNoFeature,
OnlyStableExtensionsRequiringNoFeatureAllowed) { … }
class ShaderModuleExtensionValidationTestUnsafeNoFeature
: public ShaderModuleExtensionValidationTestBase { … };
TEST_F(ShaderModuleExtensionValidationTestUnsafeNoFeature,
OnlyExtensionsRequiringNoFeatureAllowed) { … }
class ShaderModuleExtensionValidationTestSafeAllFeatures
: public ShaderModuleExtensionValidationTestBase { … };
TEST_F(ShaderModuleExtensionValidationTestSafeAllFeatures, OnlyStableExtensionsAllowed) { … }
class ShaderModuleExtensionValidationTestUnsafeAllFeatures
: public ShaderModuleExtensionValidationTestBase { … };
TEST_F(ShaderModuleExtensionValidationTestUnsafeAllFeatures, AllExtensionsAllowed) { … }
TEST_F(ShaderModuleExtensionValidationTestUnsafeAllFeatures, ShaderModuleCompilationOptions) { … }
}
}