WGSL: Replace last uses of var<in> and var<out>

Bug: dawn:755

Change-Id: Idaca6965fd2b5d0f2e0028d8edfff6c507050a45
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/48240
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Commit-Queue: Brandon Jones <bajones@chromium.org>
This commit is contained in:
Corentin Wallez
2021-04-21 16:40:50 +00:00
committed by Commit Bot service account
parent a584ae7770
commit bda3796da9
7 changed files with 109 additions and 103 deletions

View File

@@ -538,16 +538,15 @@ class VertexFormatDeprecationTests : public DeprecationTests {
protected:
// Runs the test
void DoTest(const wgpu::VertexFormat vertexFormat, bool deprecated) {
std::string attribute = "[[location(0)]] var<in> a : ";
std::string attribute = "[[location(0)]] a : ";
attribute += dawn::GetWGSLVertexFormatType(vertexFormat);
attribute += ";";
std::string attribAccess = dawn::VertexFormatNumComponents(vertexFormat) > 1
? "vec4<f32>(f32(a.x), 0.0, 0.0, 1.0)"
: "vec4<f32>(f32(a), 0.0, 0.0, 1.0)";
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, (attribute + R"(
[[stage(vertex)]] fn main() -> [[builtin(position)]] vec4<f32> {
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, (R"(
[[stage(vertex)]] fn main()" + attribute + R"() -> [[builtin(position)]] vec4<f32> {
return )" + attribAccess + R"(;
}
)")

View File

@@ -73,6 +73,7 @@ class DepthStencilSamplingTest : public DawnTest {
utils::ComboRenderPipelineDescriptor2 pipelineDescriptor;
std::ostringstream shaderSource;
std::ostringstream shaderOutputStruct;
std::ostringstream shaderBody;
uint32_t index = 0;
@@ -82,10 +83,10 @@ class DepthStencilSamplingTest : public DawnTest {
shaderSource << "[[group(0), binding(" << index << ")]] var tex" << index
<< " : texture_2d<f32>;\n";
shaderSource << "[[location(" << index << ")]] var<out> result" << index
<< " : f32;\n";
shaderOutputStruct << " [[location(" << index << ")]] result" << index
<< " : f32;\n";
shaderBody << "\nresult" << index << " = textureLoad(tex" << index
shaderBody << "\n output.result" << index << " = textureLoad(tex" << index
<< ", vec2<i32>(0, 0), 0)[" << componentIndex << "];\n";
pipelineDescriptor.cTargets[index].format = wgpu::TextureFormat::R32Float;
break;
@@ -93,10 +94,10 @@ class DepthStencilSamplingTest : public DawnTest {
shaderSource << "[[group(0), binding(" << index << ")]] var tex" << index
<< " : texture_2d<u32>;\n";
shaderSource << "[[location(" << index << ")]] var<out> result" << index
<< " : u32;\n";
shaderOutputStruct << " [[location(" << index << ")]] result" << index
<< " : u32;\n";
shaderBody << "\nresult" << index << " = textureLoad(tex" << index
shaderBody << "\n output.result" << index << " = textureLoad(tex" << index
<< ", vec2<i32>(0, 0), 0)[" << componentIndex << "];\n";
pipelineDescriptor.cTargets[index].format = wgpu::TextureFormat::R8Uint;
break;
@@ -105,7 +106,10 @@ class DepthStencilSamplingTest : public DawnTest {
index++;
}
shaderSource << "[[stage(fragment)]] fn main() { " << shaderBody.str() << "\n}";
shaderSource << "struct FragOutputs {\n" << shaderOutputStruct.str() << "};\n";
shaderSource << "[[stage(fragment)]] fn main() -> FragOutputs {\n";
shaderSource << " var output : FragOutputs;\n"
<< shaderBody.str() << " return output;\n}";
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, shaderSource.str().c_str());
pipelineDescriptor.vertex.module = vsModule;

View File

@@ -86,77 +86,68 @@ void FirstIndexOffsetTests::TestImpl(DrawMode mode,
uint32_t firstVertex,
uint32_t firstInstance) {
using wgpu::operator&;
std::stringstream vertexShader;
std::stringstream fragmentShader;
std::stringstream vertexInputs;
std::stringstream vertexOutputs;
std::stringstream vertexBody;
std::stringstream fragmentInputs;
std::stringstream fragmentBody;
vertexInputs << " [[location(0)]] position : vec4<f32>;\n";
vertexOutputs << " [[builtin(position)]] position : vec4<f32>;\n";
if ((checkIndex & CheckIndex::Vertex) != 0) {
vertexShader << R"(
[[builtin(vertex_index)]] var<in> vertex_index : u32;
[[location(1)]] var<out> out_vertex_index : u32;
)";
fragmentShader << R"(
[[location(1)]] var<in> in_vertex_index : u32;
)";
vertexInputs << " [[builtin(vertex_index)]] vertex_index : u32;\n";
vertexOutputs << " [[location(1)]] vertex_index : u32;\n";
vertexBody << " output.vertex_index = input.vertex_index;\n";
fragmentInputs << " [[location(1)]] vertex_index : u32;\n";
fragmentBody << " idx_vals.vertex_index = input.vertex_index;\n";
}
if ((checkIndex & CheckIndex::Instance) != 0) {
vertexShader << R"(
[[builtin(instance_index)]] var<in> instance_index : u32;
[[location(2)]] var<out> out_instance_index : u32;
)";
fragmentShader << R"(
[[location(2)]] var<in> in_instance_index : u32;
)";
vertexInputs << " [[builtin(instance_index)]] instance_index : u32;\n";
vertexOutputs << " [[location(2)]] instance_index : u32;\n";
vertexBody << " output.instance_index = input.instance_index;\n";
fragmentInputs << " [[location(2)]] instance_index : u32;\n";
fragmentBody << " idx_vals.instance_index = input.instance_index;\n";
}
vertexShader << R"(
[[builtin(position)]] var<out> position : vec4<f32>;
[[location(0)]] var<in> pos : vec4<f32>;
std::string vertexShader = R"(
struct VertexInputs {
)" + vertexInputs.str() + R"(
};
struct VertexOutputs {
)" + vertexOutputs.str() + R"(
};
[[stage(vertex)]] fn main(input : VertexInputs) -> VertexOutputs {
var output : VertexOutputs;
)" + vertexBody.str() + R"(
output.position = input.position;
return output;
})";
[[stage(vertex)]] fn main() {)";
fragmentShader << R"(
[[block]] struct IndexVals {
vertex_index : u32;
instance_index : u32;
};
std::string fragmentShader = R"(
[[block]] struct IndexVals {
vertex_index : u32;
instance_index : u32;
};
[[group(0), binding(0)]] var<storage> idx_vals : [[access(read_write)]] IndexVals;
[[group(0), binding(0)]] var<storage> idx_vals : [[access(read_write)]] IndexVals;
[[stage(fragment)]] fn main() {
)";
if ((checkIndex & CheckIndex::Vertex) != 0) {
vertexShader << R"(
out_vertex_index = vertex_index;
)";
fragmentShader << R"(
idx_vals.vertex_index = in_vertex_index;
)";
}
if ((checkIndex & CheckIndex::Instance) != 0) {
vertexShader << R"(
out_instance_index = instance_index;
)";
fragmentShader << R"(
idx_vals.instance_index = in_instance_index;
)";
}
vertexShader << R"(
position = pos;
return;
})";
fragmentShader << R"(
return;
})";
struct FragInputs {
)" + fragmentInputs.str() + R"(
};
[[stage(fragment)]] fn main(input : FragInputs) {
)" + fragmentBody.str() + R"(
})";
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
constexpr uint32_t kComponentsPerVertex = 4;
utils::ComboRenderPipelineDescriptor2 pipelineDesc;
pipelineDesc.vertex.module = utils::CreateShaderModule(device, vertexShader.str().c_str());
pipelineDesc.cFragment.module = utils::CreateShaderModule(device, fragmentShader.str().c_str());
pipelineDesc.vertex.module = utils::CreateShaderModule(device, vertexShader.c_str());
pipelineDesc.cFragment.module = utils::CreateShaderModule(device, fragmentShader.c_str());
pipelineDesc.primitive.topology = wgpu::PrimitiveTopology::PointList;
pipelineDesc.vertex.bufferCount = 1;
pipelineDesc.cBuffers[0].arrayStride = kComponentsPerVertex * sizeof(float);

View File

@@ -30,10 +30,12 @@ class VertexBufferRobustnessTest : public DawnTest {
// Creates a vertex module that tests an expression with given attributes. If successful, the
// point drawn would be moved out of the viewport. On failure, the point is kept inside the
// viewport.
wgpu::ShaderModule CreateVertexModule(const std::string& attributes,
wgpu::ShaderModule CreateVertexModule(const std::string& attribute,
const std::string& successExpression) {
return utils::CreateShaderModule(device, (attributes + R"(
[[stage(vertex)]] fn main() -> [[builtin(position)]] vec4<f32> {
return utils::CreateShaderModule(device, (R"(
[[stage(vertex)]] fn main(
)" + attribute + R"(
) -> [[builtin(position)]] vec4<f32> {
if ()" + successExpression + R"() {
// Success case, move the vertex out of the viewport
return vec4<f32>(-10.0, 0.0, 0.0, 1.0);
@@ -102,7 +104,7 @@ TEST_P(VertexBufferRobustnessTest, DetectInvalidValues) {
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
wgpu::BufferUsage::Vertex);
DoTest("[[location(0)]] var<in> a : f32;", "a == 473.0", vertexState, vertexBuffer, 0, false);
DoTest("[[location(0)]] a : f32", "a == 473.0", vertexState, vertexBuffer, 0, false);
}
TEST_P(VertexBufferRobustnessTest, FloatClamp) {
@@ -119,7 +121,7 @@ TEST_P(VertexBufferRobustnessTest, FloatClamp) {
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
wgpu::BufferUsage::Vertex);
DoTest("[[location(0)]] var<in> a : f32;", "a == 473.0", vertexState, vertexBuffer, 4, true);
DoTest("[[location(0)]] a : f32", "a == 473.0", vertexState, vertexBuffer, 4, true);
}
TEST_P(VertexBufferRobustnessTest, IntClamp) {
@@ -136,7 +138,7 @@ TEST_P(VertexBufferRobustnessTest, IntClamp) {
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
wgpu::BufferUsage::Vertex);
DoTest("[[location(0)]] var<in> a : i32;", "a == 473", vertexState, vertexBuffer, 4, true);
DoTest("[[location(0)]] a : i32", "a == 473", vertexState, vertexBuffer, 4, true);
}
TEST_P(VertexBufferRobustnessTest, UIntClamp) {
@@ -153,7 +155,7 @@ TEST_P(VertexBufferRobustnessTest, UIntClamp) {
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
wgpu::BufferUsage::Vertex);
DoTest("[[location(0)]] var<in> a : u32;", "a == 473u", vertexState, vertexBuffer, 4, true);
DoTest("[[location(0)]] a : u32", "a == 473u", vertexState, vertexBuffer, 4, true);
}
TEST_P(VertexBufferRobustnessTest, Float2Clamp) {
@@ -170,7 +172,7 @@ TEST_P(VertexBufferRobustnessTest, Float2Clamp) {
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
wgpu::BufferUsage::Vertex);
DoTest("[[location(0)]] var<in> a : vec2<f32>;", "a[0] == 473.0 && a[1] == 473.0",
DoTest("[[location(0)]] a : vec2<f32>", "a[0] == 473.0 && a[1] == 473.0",
std::move(vertexState), vertexBuffer, 8, true);
}
@@ -188,7 +190,7 @@ TEST_P(VertexBufferRobustnessTest, Float3Clamp) {
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
wgpu::BufferUsage::Vertex);
DoTest("[[location(0)]] var<in> a : vec3<f32>;",
DoTest("[[location(0)]] a : vec3<f32>",
"a[0] == 473.0 && a[1] == 473.0 && a[2] == 473.0", vertexState, vertexBuffer, 12, true);
}
@@ -206,7 +208,7 @@ TEST_P(VertexBufferRobustnessTest, Float4Clamp) {
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
wgpu::BufferUsage::Vertex);
DoTest("[[location(0)]] var<in> a : vec4<f32>;",
DoTest("[[location(0)]] a : vec4<f32>",
"a[0] == 473.0 && a[1] == 473.0 && a[2] == 473.0 && a[3] == 473.0", vertexState,
vertexBuffer, 16, true);
}

View File

@@ -448,10 +448,9 @@ TEST_P(D3D12DescriptorHeapTests, EncodeManyUBO) {
heapSize : f32;
};
[[group(0), binding(0)]] var<uniform> buffer0 : U;
[[location(0)]] var<out> FragColor : f32;
[[stage(fragment)]] fn main() {
FragColor = buffer0.heapSize;
[[stage(fragment)]] fn main() -> [[location(0)]] f32 {
return buffer0.heapSize;
})");
wgpu::BlendState blend;