tint: Implement uniformity analaysis
This implements the uniformity analysis as currently described in the WGSL specification. Uniformity issues are presented as warnings, and will be switched to errors in a future release. A follow-up patch will improve the error messages, which currently just show the point at which a uniformity was detected. In a future release, once we have obtained initial feedback from users, uniformity issues will become errors. Bug: tint:880 Change-Id: I7d0b3080932c786c5d50b55720fec6d19f00d356 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88368 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Alan Baker <alanbaker@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
3683c46b57
commit
be656f7984
|
@ -1,5 +1,12 @@
|
|||
# Tint changes during Origin Trial
|
||||
|
||||
## Changes for M103
|
||||
|
||||
### New features
|
||||
|
||||
* Produce warnings for when calling barriers, textureSample, and derivative
|
||||
builtins in non-uniform control flow [tint:880](crbug.com/tint/880)
|
||||
|
||||
## Changes for M102
|
||||
|
||||
### New Features
|
||||
|
|
|
@ -375,6 +375,8 @@ libtint_source_set("libtint_core_all_src") {
|
|||
"resolver/resolver_constants.cc",
|
||||
"resolver/sem_helper.cc",
|
||||
"resolver/sem_helper.h",
|
||||
"resolver/uniformity.cc",
|
||||
"resolver/uniformity.h",
|
||||
"resolver/validator.cc",
|
||||
"resolver/validator.h",
|
||||
"scope_stack.h",
|
||||
|
|
|
@ -256,6 +256,8 @@ set(TINT_LIB_SRCS
|
|||
resolver/resolver.h
|
||||
resolver/sem_helper.cc
|
||||
resolver/sem_helper.h
|
||||
resolver/uniformity.cc
|
||||
resolver/uniformity.h
|
||||
resolver/validator.cc
|
||||
resolver/validator.h
|
||||
scope_stack.h
|
||||
|
@ -833,6 +835,13 @@ if(TINT_BUILD_TESTS)
|
|||
writer/text_generator_test.cc
|
||||
)
|
||||
|
||||
# Uniformity analysis tests depend on WGSL reader
|
||||
if(${TINT_BUILD_WGSL_READER})
|
||||
list(APPEND TINT_TEST_SRCS
|
||||
resolver/uniformity_test.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
# Inspector tests depend on WGSL reader
|
||||
if(${TINT_BUILD_WGSL_READER})
|
||||
list(APPEND TINT_TEST_SRCS
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "src/tint/ast/variable_decl_statement.h"
|
||||
#include "src/tint/ast/vector.h"
|
||||
#include "src/tint/ast/workgroup_attribute.h"
|
||||
#include "src/tint/resolver/uniformity.h"
|
||||
#include "src/tint/sem/array.h"
|
||||
#include "src/tint/sem/atomic.h"
|
||||
#include "src/tint/sem/call.h"
|
||||
|
@ -145,6 +146,10 @@ bool Resolver::ResolveInternal() {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!AnalyzeUniformity(builder_, dependencies_)) {
|
||||
// TODO(jrprice): Reject programs that fail uniformity analysis.
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
for (auto* node : builder_->ASTNodes().Objects()) {
|
||||
if (marked_.count(node) == 0) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2022 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_RESOLVER_UNIFORMITY_H_
|
||||
#define SRC_TINT_RESOLVER_UNIFORMITY_H_
|
||||
|
||||
// Forward declarations.
|
||||
namespace tint {
|
||||
namespace resolver {
|
||||
struct DependencyGraph;
|
||||
} // namespace resolver
|
||||
class ProgramBuilder;
|
||||
} // namespace tint
|
||||
|
||||
namespace tint::resolver {
|
||||
|
||||
/// Analyze the uniformity of a program.
|
||||
/// @param builder the program to analyze
|
||||
/// @param dependency_graph the dependency-ordered module-scope declarations
|
||||
/// @returns true if there are no uniformity issues, false otherwise
|
||||
bool AnalyzeUniformity(ProgramBuilder* builder, const resolver::DependencyGraph& dependency_graph);
|
||||
|
||||
} // namespace tint::resolver
|
||||
|
||||
#endif // SRC_TINT_RESOLVER_UNIFORMITY_H_
|
File diff suppressed because it is too large
Load Diff
|
@ -71,6 +71,16 @@ class ScopeStack {
|
|||
return V{};
|
||||
}
|
||||
|
||||
/// Return the top scope of the stack.
|
||||
/// @returns the top scope of the stack
|
||||
const std::unordered_map<K, V>& Top() const { return stack_.back(); }
|
||||
|
||||
/// Clear the scope stack.
|
||||
void Clear() {
|
||||
stack_.clear();
|
||||
stack_.push_back({});
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unordered_map<K, V>> stack_;
|
||||
};
|
||||
|
|
|
@ -67,5 +67,25 @@ TEST_F(ScopeStackTest, Set) {
|
|||
EXPECT_EQ(s.Get(b), 25u);
|
||||
}
|
||||
|
||||
TEST_F(ScopeStackTest, Clear) {
|
||||
ScopeStack<Symbol, uint32_t> s;
|
||||
Symbol a(1, ID());
|
||||
Symbol b(2, ID());
|
||||
|
||||
EXPECT_EQ(s.Set(a, 5u), 0u);
|
||||
EXPECT_EQ(s.Get(a), 5u);
|
||||
|
||||
s.Push();
|
||||
|
||||
EXPECT_EQ(s.Set(b, 10u), 0u);
|
||||
EXPECT_EQ(s.Get(b), 10u);
|
||||
|
||||
s.Push();
|
||||
|
||||
s.Clear();
|
||||
EXPECT_EQ(s.Get(a), 0u);
|
||||
EXPECT_EQ(s.Get(b), 0u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
|
|
@ -272,6 +272,7 @@ tint_unittests_source_set("tint_unittests_resolver_src") {
|
|||
"../../src/tint/resolver/struct_storage_class_use_test.cc",
|
||||
"../../src/tint/resolver/type_constructor_validation_test.cc",
|
||||
"../../src/tint/resolver/type_validation_test.cc",
|
||||
"../../src/tint/resolver/uniformity_test.cc",
|
||||
"../../src/tint/resolver/validation_test.cc",
|
||||
"../../src/tint/resolver/validator_is_storeable_test.cc",
|
||||
"../../src/tint/resolver/var_let_test.cc",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,7 @@
|
|||
bug/dawn/947.wgsl:59:20 warning: 'textureSample' must only be called from uniform control flow
|
||||
var srcColor = textureSample(myTexture, mySampler, texcoord);
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
#version 310 es
|
||||
|
||||
layout(location = 0) out vec2 texcoords_1;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/dawn/947.wgsl:59:20 warning: 'textureSample' must only be called from uniform control flow
|
||||
var srcColor = textureSample(myTexture, mySampler, texcoord);
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
cbuffer cbuffer_uniforms : register(b0, space0) {
|
||||
uint4 uniforms[1];
|
||||
};
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/dawn/947.wgsl:59:20 warning: 'textureSample' must only be called from uniform control flow
|
||||
var srcColor = textureSample(myTexture, mySampler, texcoord);
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/dawn/947.wgsl:59:20 warning: 'textureSample' must only be called from uniform control flow
|
||||
var srcColor = textureSample(myTexture, mySampler, texcoord);
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/dawn/947.wgsl:59:20 warning: 'textureSample' must only be called from uniform control flow
|
||||
var srcColor = textureSample(myTexture, mySampler, texcoord);
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
struct Uniforms {
|
||||
u_scale : vec2<f32>,
|
||||
u_offset : vec2<f32>,
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/fxc/gradient_in_varying_loop/1112.wgsl:23:33 warning: 'textureSample' must only be called from uniform control flow
|
||||
let sampleDepth : f32 = textureSample(depthTexture, Sampler, offset.xy).r;
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/fxc/gradient_in_varying_loop/1112.wgsl:23:33 warning: 'textureSample' must only be called from uniform control flow
|
||||
let sampleDepth : f32 = textureSample(depthTexture, Sampler, offset.xy).r;
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
SamplerState tint_symbol : register(s0, space0);
|
||||
Texture2D<float4> randomTexture : register(t1, space0);
|
||||
Texture2D<float4> depthTexture : register(t2, space0);
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/fxc/gradient_in_varying_loop/1112.wgsl:23:33 warning: 'textureSample' must only be called from uniform control flow
|
||||
let sampleDepth : f32 = textureSample(depthTexture, Sampler, offset.xy).r;
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/fxc/gradient_in_varying_loop/1112.wgsl:23:33 warning: 'textureSample' must only be called from uniform control flow
|
||||
let sampleDepth : f32 = textureSample(depthTexture, Sampler, offset.xy).r;
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/fxc/gradient_in_varying_loop/1112.wgsl:23:33 warning: 'textureSample' must only be called from uniform control flow
|
||||
let sampleDepth : f32 = textureSample(depthTexture, Sampler, offset.xy).r;
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
@group(0) @binding(0) var Sampler : sampler;
|
||||
|
||||
@group(0) @binding(1) var randomTexture : texture_2d<f32>;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/1118.wgsl:64:31 warning: 'dpdx' must only be called from uniform control flow
|
||||
normalW = normalize(-(cross(dpdx(x_62), dpdy(x_64))));
|
||||
^^^^
|
||||
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/1118.wgsl:64:31 warning: 'dpdx' must only be called from uniform control flow
|
||||
normalW = normalize(-(cross(dpdx(x_62), dpdy(x_64))));
|
||||
^^^^
|
||||
|
||||
static float fClipDistance3 = 0.0f;
|
||||
static float fClipDistance4 = 0.0f;
|
||||
cbuffer cbuffer_x_29 : register(b0, space0) {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/1118.wgsl:64:31 warning: 'dpdx' must only be called from uniform control flow
|
||||
normalW = normalize(-(cross(dpdx(x_62), dpdy(x_64))));
|
||||
^^^^
|
||||
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/1118.wgsl:64:31 warning: 'dpdx' must only be called from uniform control flow
|
||||
normalW = normalize(-(cross(dpdx(x_62), dpdy(x_64))));
|
||||
^^^^
|
||||
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/1118.wgsl:64:31 warning: 'dpdx' must only be called from uniform control flow
|
||||
normalW = normalize(-(cross(dpdx(x_62), dpdy(x_64))));
|
||||
^^^^
|
||||
|
||||
struct Scene {
|
||||
vEyePosition : vec4<f32>,
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
warning: parameter 'dimInner' of 'mm_matMul_i1_i1_i1_' must be uniform
|
||||
#version 310 es
|
||||
|
||||
struct Uniforms {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
warning: parameter 'dimInner' of 'mm_matMul_i1_i1_i1_' must be uniform
|
||||
static int dimAOuter_1 = 0;
|
||||
cbuffer cbuffer_x_48 : register(b3, space0) {
|
||||
uint4 x_48[5];
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
warning: parameter 'dimInner' of 'mm_matMul_i1_i1_i1_' must be uniform
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
warning: parameter 'dimInner' of 'mm_matMul_i1_i1_i1_' must be uniform
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
warning: parameter 'dimInner' of 'mm_matMul_i1_i1_i1_' must be uniform
|
||||
struct Uniforms {
|
||||
NAN : f32,
|
||||
@size(12)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/948.wgsl:146:33 warning: 'textureSampleBias' must only be called from uniform control flow
|
||||
let x_217 : vec4<f32> = textureSampleBias(animationMapTexture, animationMapSampler, vec2<f32>(((x_208 + 0.5) / x_211), (0.125 * x_214)), 0.0);
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/948.wgsl:146:33 warning: 'textureSampleBias' must only be called from uniform control flow
|
||||
let x_217 : vec4<f32> = textureSampleBias(animationMapTexture, animationMapSampler, vec2<f32>(((x_208 + 0.5) / x_211), (0.125 * x_214)), 0.0);
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
cbuffer cbuffer_x_20 : register(b9, space2) {
|
||||
uint4 x_20[8];
|
||||
};
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/948.wgsl:146:33 warning: 'textureSampleBias' must only be called from uniform control flow
|
||||
let x_217 : vec4<f32> = textureSampleBias(animationMapTexture, animationMapSampler, vec2<f32>(((x_208 + 0.5) / x_211), (0.125 * x_214)), 0.0);
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/948.wgsl:146:33 warning: 'textureSampleBias' must only be called from uniform control flow
|
||||
let x_217 : vec4<f32> = textureSampleBias(animationMapTexture, animationMapSampler, vec2<f32>(((x_208 + 0.5) / x_211), (0.125 * x_214)), 0.0);
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/948.wgsl:146:33 warning: 'textureSampleBias' must only be called from uniform control flow
|
||||
let x_217 : vec4<f32> = textureSampleBias(animationMapTexture, animationMapSampler, vec2<f32>(((x_208 + 0.5) / x_211), (0.125 * x_214)), 0.0);
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
struct LeftOver {
|
||||
time : f32,
|
||||
@size(12)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/949.wgsl:326:29 warning: 'textureSample' must only be called from uniform control flow
|
||||
let x_397 : vec4<f32> = textureSample(TextureSamplerTexture, TextureSamplerSampler, (x_394 + x_395));
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/949.wgsl:326:29 warning: 'textureSample' must only be called from uniform control flow
|
||||
let x_397 : vec4<f32> = textureSample(TextureSamplerTexture, TextureSamplerSampler, (x_394 + x_395));
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
struct lightingInfo {
|
||||
float3 diffuse;
|
||||
float3 specular;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/949.wgsl:326:29 warning: 'textureSample' must only be called from uniform control flow
|
||||
let x_397 : vec4<f32> = textureSample(TextureSamplerTexture, TextureSamplerSampler, (x_394 + x_395));
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/949.wgsl:326:29 warning: 'textureSample' must only be called from uniform control flow
|
||||
let x_397 : vec4<f32> = textureSample(TextureSamplerTexture, TextureSamplerSampler, (x_394 + x_395));
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
bug/tint/949.wgsl:326:29 warning: 'textureSample' must only be called from uniform control flow
|
||||
let x_397 : vec4<f32> = textureSample(TextureSamplerTexture, TextureSamplerSampler, (x_394 + x_395));
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
struct lightingInfo {
|
||||
diffuse : vec3<f32>,
|
||||
specular : vec3<f32>,
|
||||
|
|
Loading…
Reference in New Issue