blob: dcecd83dc0acc9bed98062d15f7375771dda4358 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Corentin Wallezf07e3bd2017-04-20 14:38:20 -04002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <gtest/gtest.h>
16
Corentin Wallezd37523f2018-07-24 13:53:51 +020017#include "dawn_native/PerStage.h"
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040018
Corentin Wallez49a65d02018-07-24 16:45:45 +020019using namespace dawn_native;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040020
21// Tests for StageBit
22TEST(PerStage, StageBit) {
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000023 ASSERT_EQ(StageBit(SingleShaderStage::Vertex), wgpu::ShaderStage::Vertex);
24 ASSERT_EQ(StageBit(SingleShaderStage::Fragment), wgpu::ShaderStage::Fragment);
25 ASSERT_EQ(StageBit(SingleShaderStage::Compute), wgpu::ShaderStage::Compute);
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040026}
27
28// Basic test for the PerStage container
29TEST(PerStage, PerStage) {
30 PerStage<int> data;
31
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000032 // Store data using wgpu::ShaderStage
Corentin Wallezb9b088f2019-08-27 08:42:29 +000033 data[SingleShaderStage::Vertex] = 42;
34 data[SingleShaderStage::Fragment] = 3;
35 data[SingleShaderStage::Compute] = -1;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040036
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000037 // Load it using wgpu::ShaderStage
38 ASSERT_EQ(data[wgpu::ShaderStage::Vertex], 42);
39 ASSERT_EQ(data[wgpu::ShaderStage::Fragment], 3);
40 ASSERT_EQ(data[wgpu::ShaderStage::Compute], -1);
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040041}
42
43// Test IterateStages with kAllStages
44TEST(PerStage, IterateAllStages) {
45 PerStage<int> counts;
Corentin Wallezb9b088f2019-08-27 08:42:29 +000046 counts[SingleShaderStage::Vertex] = 0;
47 counts[SingleShaderStage::Fragment] = 0;
48 counts[SingleShaderStage::Compute] = 0;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040049
50 for (auto stage : IterateStages(kAllStages)) {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000051 counts[stage]++;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040052 }
53
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000054 ASSERT_EQ(counts[wgpu::ShaderStage::Vertex], 1);
55 ASSERT_EQ(counts[wgpu::ShaderStage::Fragment], 1);
56 ASSERT_EQ(counts[wgpu::ShaderStage::Compute], 1);
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040057}
58
59// Test IterateStages with one stage
60TEST(PerStage, IterateOneStage) {
61 PerStage<int> counts;
Corentin Wallezb9b088f2019-08-27 08:42:29 +000062 counts[SingleShaderStage::Vertex] = 0;
63 counts[SingleShaderStage::Fragment] = 0;
64 counts[SingleShaderStage::Compute] = 0;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040065
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000066 for (auto stage : IterateStages(wgpu::ShaderStage::Fragment)) {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000067 counts[stage]++;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040068 }
69
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000070 ASSERT_EQ(counts[wgpu::ShaderStage::Vertex], 0);
71 ASSERT_EQ(counts[wgpu::ShaderStage::Fragment], 1);
72 ASSERT_EQ(counts[wgpu::ShaderStage::Compute], 0);
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040073}
74
75// Test IterateStages with no stage
76TEST(PerStage, IterateNoStages) {
77 PerStage<int> counts;
Corentin Wallezb9b088f2019-08-27 08:42:29 +000078 counts[SingleShaderStage::Vertex] = 0;
79 counts[SingleShaderStage::Fragment] = 0;
80 counts[SingleShaderStage::Compute] = 0;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040081
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000082 for (auto stage : IterateStages(wgpu::ShaderStage::Fragment & wgpu::ShaderStage::Vertex)) {
Kai Ninomiya2afea0c2020-07-10 20:33:08 +000083 counts[stage]++;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040084 }
85
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000086 ASSERT_EQ(counts[wgpu::ShaderStage::Vertex], 0);
87 ASSERT_EQ(counts[wgpu::ShaderStage::Fragment], 0);
88 ASSERT_EQ(counts[wgpu::ShaderStage::Compute], 0);
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040089}