Skip to content

Commit

Permalink
WGSL: Rewrite input/output variables
Browse files Browse the repository at this point in the history
GLSL builtin variables and in/out variables correspond to WGSL's main
function params and return value, so rewrite them accordingly.

This is done by generating structs to use as main function params and
return values, generating similar global structs, and copying the
former into the latter so the rest of the program can just use the
variables stored in the global structs.

Bug: angleproject:42267100
Change-Id: Ic3e1196f6fb95b963ce03845096a59ea7599d608
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5835347
Reviewed-by: Shahbaz Youssefi <[email protected]>
Reviewed-by: Geoff Lang <[email protected]>
Commit-Queue: Matthew Denton <[email protected]>
  • Loading branch information
mdenton8 authored and Angle LUCI CQ committed Sep 10, 2024
1 parent 9a2b1f1 commit c2a9300
Show file tree
Hide file tree
Showing 17 changed files with 1,392 additions and 230 deletions.
10 changes: 8 additions & 2 deletions src/compiler.gni
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ angle_translator_sources = [
"src/compiler/translator/tree_util/Visit.h",
"src/compiler/translator/util.cpp",
"src/compiler/translator/util.h",
"src/compiler/translator/wgsl/TranslatorWGSL.h",
]
angle_translator_glsl_base_sources = [
"src/compiler/translator/glsl/OutputGLSLBase.cpp",
Expand Down Expand Up @@ -449,8 +450,13 @@ angle_translator_lib_msl_sources = [
"src/compiler/translator/tree_ops/msl/WrapMain.h",
]

angle_translator_lib_wgsl_sources =
[ "src/compiler/translator/wgsl/TranslatorWGSL.cpp" ]
angle_translator_lib_wgsl_sources = [
"src/compiler/translator/wgsl/RewritePipelineVariables.cpp",
"src/compiler/translator/wgsl/RewritePipelineVariables.h",
"src/compiler/translator/wgsl/TranslatorWGSL.cpp",
"src/compiler/translator/wgsl/WriteTypeName.cpp",
"src/compiler/translator/wgsl/WriteTypeName.h",
]

angle_preprocessor_sources = [
"src/compiler/preprocessor/DiagnosticsBase.cpp",
Expand Down
6 changes: 1 addition & 5 deletions src/compiler/translator/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@
# include "compiler/translator/msl/TranslatorMSL.h"
#endif // ANGLE_ENABLE_METAL

#ifdef ANGLE_ENABLE_WEBGPU
# include "compiler/translator/msl/TranslatorMSL.h"
#endif // ANGLE_ENABLE_METAL

#ifdef ANGLE_ENABLE_WGPU
# include "compiler/translator/wgsl/TranslatorWGSL.h"
#endif
#endif // ANGLE_ENABLE_WGPU

#include "compiler/translator/util.h"

Expand Down
41 changes: 41 additions & 0 deletions src/compiler/translator/ImmutableStringBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,47 @@ class ImmutableStringBuilder
// GLSL ES 3.00.6 section 3.9: the maximum length of an identifier is 1024 characters.
constexpr unsigned int kESSLMaxIdentifierLength = 1024u;

namespace impl
{
inline size_t GetArgLength(const ImmutableString &str)
{
return str.length();
}

inline size_t GetArgLength(const char *str)
{
return std::strlen(str);
}

inline size_t GetArgsTotalSize()
{
return 0;
}

template <typename T, typename... Rest>
inline size_t GetArgsTotalSize(const T &firstArg, Rest... rest)
{
return GetArgLength(firstArg) + GetArgsTotalSize(rest...);
}

inline void AppendStrings(ImmutableStringBuilder &builder) {}

template <typename T, typename... Rest>
inline void AppendStrings(ImmutableStringBuilder &builder, const T &firstArg, Rest... rest)
{
builder << firstArg;
AppendStrings(builder, rest...);
}
} // namespace impl

template <typename... Args>
ImmutableString BuildConcatenatedImmutableString(Args... args)
{
ImmutableStringBuilder builder(impl::GetArgsTotalSize(args...));
impl::AppendStrings(builder, args...);
return builder;
}

} // namespace sh

#endif // COMPILER_TRANSLATOR_IMMUTABLESTRINGBUILDER_H_
Loading

0 comments on commit c2a9300

Please sign in to comment.