src/tests/compiler_tests/WGSLOutput_test.cpp


Log

Author Commit Date CI Message
Matthew Denton b1a0d60f 2025-01-08T15:10:41 WGSL: Fix accidentally overloaded functions Small-stride arrays in uniforms with the same element type, but different array sizes, would cause the WGSL generator to produce conversion functions with the same name but different array sizes. This CL puts the array size in the name of the function to avoid overloading, which is unsupported in WGSL. Bug: angleproject:376553328 Change-Id: I446e91ccb9da2872c88f1a4e05283aacc9d6f8b1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6160334 Commit-Queue: Matt Denton <mpdenton@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Auto-Submit: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Matt Denton <mpdenton@google.com> Reviewed-by: Liza Burakova <liza@chromium.org>
Matthew Denton 363f6264 2025-01-07T10:35:09 WGSL: unwrap single array element from uniform ...instead of unwrapping the entire array when only one element is being accessed. The is step #4 from the implementation plan in https://docs.google.com/document/d/17Qku1QEbLDhvJS-JJ9lPQAbnuZtLxWhG-ha5eCUhtEY/edit?tab=t.0#bookmark=id.dt9vmixnpdvo Bug: angleproject:376553328 Change-Id: I6c559f44b75cd1d3c4a478141c11f65a33d76bdf Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6102117 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Matt Denton <mpdenton@google.com> Reviewed-by: Matt Denton <mpdenton@google.com> Reviewed-by: Liza Burakova <liza@chromium.org>
Matthew Denton 53ec86ab 2024-12-17T14:40:31 WGSL: support small stride arrays in uniforms WGSL requires arrays in the uniform address space to have a stride a multiple of 16. This CL makes WGSL translator emit wrapper structs for array element types used in the uniform address space, when the array stride is not a multiple of 16. The exception is for structs that aren't an aligned size of 16n, and for any types matCx2, since they are (or will be) handled in different ways that ensure alignment to 16. This should leave only f32, i32, u32, and vec2. See https://www.w3.org/TR/WGSL/#example-67da5de6 for an example of using a wrapper struct. This requires converting arrays with a wrapper struct element type to arrays with an unwrapped element type when they are first used; this can be "optimized" later for the common case of accessing a single array element, which can then be unwrapped immediately. This CL generates WGSL conversion functions when necessary. After this, the only types that can't yet be used in a uniform are matCx2 and bools. This is #2 in https://docs.google.com/document/d/17Qku1QEbLDhvJS-JJ9lPQAbnuZtLxWhG-ha5eCUhtEY/edit?tab=t.0#bookmark=id.rt3slgehd4te Bug: angleproject:376553328 Change-Id: I1edfa7f481a6cbf5b595643aae8728e67bc4b770 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6092038 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org> Reviewed-by: Matt Denton <mpdenton@google.com> Commit-Queue: Matt Denton <mpdenton@google.com>
Matthew Denton 473798bf 2024-11-28T00:38:36 WGSL: @align appropriate struct members in uniforms. Structs used in the uniform address space need to have certain members aligned according to the uniform address space layout constraints (substantially similar to std140). This CL adds @align annotations where necessary, in structs used in the uniform address space. Strictly speaking, it's okay to apply @align annotations to all structs used in the WGSL program, but this CL uses a pre-pass AST traverser to records all the structs used in the uniform address space. This is to avoid more unreadable generated code, and when more transformations are applied to these structs in future CLs, less generated code overall. After this, the only types that can't yet be used in a uniform are matCx2, arrays with stride not divisble by 16 (except when the array element type is a struct), and bools. This is #1 in struct translation in https://docs.google.com/document/d/17Qku1QEbLDhvJS-JJ9lPQAbnuZtLxWhG-ha5eCUhtEY/edit?tab=t.0#bookmark=id.rudfrn2o6jv1 Bug: angleproject:376553328 Change-Id: Ibff3414043a6ecb4a01ef8e3e71dad9c1066ddfd Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6056951 Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Matthew Denton 4a835cf2 2024-11-01T13:31:00 WebGPU: send uniforms to GPU for use in shader Basic uniforms should now be accessible in the shader during a draw call, rather than just via glGetUniform*(). This is unoptimized and creates a new GPU-side copy of all the uniforms, every time any uniform changes. This sets up the bind group layout for a pipeline and sets the bind groups in the renderer pass. Right now these bind groups only contain the default uniform blocks, but in the future will need to contain textures, samplers, and non-default uniform blocks (UBOs). Bug: angleproject:376553328 Change-Id: I50891b81ab2ee374d674213257f76319c0222120 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5980972 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Matthew Denton a6ee4641 2024-09-25T11:41:47 WGSL: Output default uniform block and accesses to it Default uniforms are put into a WGSL struct, and all accesses of those uniforms now output struct accesses. Similarly to I/O vars and builtins, these are outputted in a pre-pass, but in the future it might make sense to do what Vulkan does and do an AST transformation to put the default uniforms into a UBO which should be outputted similarly. This does not handle bool, matCx2, or array of element size < 16. Bug: angleproject:42267100 Change-Id: If29e2895a8aba3212b581813316af87273c1515c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5878759 Reviewed-by: Liza Burakova <liza@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Matthew Denton 7e462c22 2024-09-17T15:32:41 WGPU: Implement SetUniform() enough so GetUniform() works Lays out a shadow buffer for basic uniforms per-shadertype in std140, which is close to matching WGPU's layout. This does not actually pass the buffer to WGPU as a uniform buffer. GetUniform() just reads from the shadow buffer. This is copied from the VK backend and so some code is deduplicated. Bug: angleproject:42267100 Change-Id: I727dc9e09a7ccabbb617f148dd68590469883b07 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5867444 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org>
Matthew Denton c2a9300c 2024-09-10T19:33:33 WGSL: Rewrite input/output variables 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 <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Matthew Denton 35f01e7f 2024-06-26T14:30:27 ESSL -> WGSL: Support basic control flow If/else, while, do/while, for. Return, break, continue, discard Bug: angleproject:42267100 Change-Id: I0c8ef30b45aec639a07323e333db970d4c42dec0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5661103 Reviewed-by: Liza Burakova <liza@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Matthew Denton 89ef2812 2024-06-26T11:19:54 ESSL -> WGSL: unary and binary exprs, operators, array access Array indexing is always checked to be within bounds. For runtime-sized arrays, this requires emitting a clamp(). For now this includes a bug the left-side-expression (the array itself) has any side effects, which shouldn't actually be possible but may be in future versions of WGSL. Implementing unary, binary, and remaining aggregate expressions requires implementing operators, many of which do not have exact corresponding versions between GLSL and WGSL. This implements many operators but for simplicity leaves some unimplemented and some half-implemented. See WGSLOutput_test.cpp for some code examples. Bug: angleproject:42267100 Change-Id: I3737abb5dffd156deba0429fa86570270d711d3c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5651994 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Matthew Denton 7ca9f46a 2024-06-21T13:09:24 ESSL -> WGSL: Emit func calls, struct access, constants Also includes constructor calls, swizzles, and a slightly incorrect version of the ternary operator. The ternary operator doesn't exist in WGSL, only a non-short-circuiting select() builtin. For now the ternary is implemented with select() but that isn't correct if any of the true/false expressions have side effects, and may have perf implications by computing both true/false expressions. Constants are mostly done after this, however NaN and infinity are not valid constants in WGSL and it's unclear what we can do about this as WGPU implementations are allowed to assume NaNs and infinities are never operated on. Bug: angleproject:42267100 Change-Id: Ie6190091a7b95d3d372736ab7cea45868846e7be Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5648990 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Matthew Denton a04239d8 2024-06-18T11:38:52 ESSL -> WGSL: Emit most types and function params This emits struct declarations, as well as array/matrix/vec types. As a result this also emits function parameters. Bug: angleproject:42267100 Change-Id: Ib9c7e543fd38f7c1dfa64d8e63b054fc5111b336 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5598298 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Matthew Denton af72bf7f 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>
Matthew Denton d68395fe 2024-05-24T15:14:46 ESSL->WGSL: Emit basic function signatures ...signatures don't yet include types or parameters. See WGSLOutput_test.cpp for a sample translation. Bug: angleproject:8662 Change-Id: I93273156f72ba193441e737074bd1a8a054f2ea9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5582949 Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org>