Hash :
af72bf7f
Author :
Date :
2024-05-24T15:00:44
ESSL -> WGSL: emit basic types This emits dimensionless types (no vectors, matrices, arrays). Function signatures will emit their return type (assuming it is dimensionless). Bug: angleproject:42267100 Change-Id: I0d2479f71408eb20b9c329a99c70a6bf6426a72f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5590384 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WGSLOutput_test.cpp:
// Tests for corect WGSL translations.
//
#include <regex>
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "tests/test_utils/compiler_test.h"
using namespace sh;
class WGSLVertexOutputTest : public MatchOutputCodeTest
{
public:
WGSLVertexOutputTest() : MatchOutputCodeTest(GL_VERTEX_SHADER, SH_WGSL_OUTPUT)
{
ShCompileOptions defaultCompileOptions = {};
defaultCompileOptions.validateAST = true;
setDefaultCompileOptions(defaultCompileOptions);
}
};
class WGSLOutputTest : public MatchOutputCodeTest
{
public:
WGSLOutputTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, SH_WGSL_OUTPUT)
{
ShCompileOptions defaultCompileOptions = {};
defaultCompileOptions.validateAST = true;
setDefaultCompileOptions(defaultCompileOptions);
}
};
TEST_F(WGSLOutputTest, BasicTranslation)
{
const std::string &shaderString =
R"(#version 300 es
precision highp float;
out vec4 outColor;
struct Foo {
float x;
float y;
};
void doFoo(Foo foo, float zw);
void doFoo(Foo foo, float zw)
{
foo.x = foo.y;
outColor = vec4(foo.x, foo.y, zw, zw);
}
Foo returnFoo(Foo foo) {
return foo;
}
float returnFloat(float x) {
return x;
}
void main()
{
Foo foo;
foo.x = 2.0;
foo.y = 2.0;
doFoo(returnFoo(foo), returnFloat(3.0));
})";
const std::string &outputString =
R"(
FAKE_DECLARATION;
FAKE_DECLARATION;
fn _udoFoo(FAKE_FUNCTION_PARAMETER, FAKE_FUNCTION_PARAMETER);
fn _udoFoo(FAKE_FUNCTION_PARAMETER, FAKE_FUNCTION_PARAMETER)
{
;
;
}
fn _ureturnFoo(FAKE_FUNCTION_PARAMETER) -> _uFoo
{
;
}
fn _ureturnFloat(FAKE_FUNCTION_PARAMETER) -> f32
{
;
}
fn _umain()
{
FAKE_DECLARATION;
;
;
;
}
)";
compile(shaderString);
EXPECT_TRUE(foundInCode(outputString.c_str()));
}