feat: port the client to MyGo native UI (0.3.0)

Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
This commit is contained in:
OpenChamber committed 2026-11-18 13:22:59 +08:00
1 parent 2fb4a8ea79
commit 6c0ee61750
2538 files changed
+675779 -4792

No files matched your search

+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+207
View File
@@ -0,0 +1,207 @@
package shader
import (
"bytes"
"fmt"
"strings"
"github.com/egoist/mygo/internal/shaderir"
)
// MaxImages is how many images a shader reads, image0 to image3.
const MaxImages = 4
// Entry is the name of a shader's entry point, which returns the color
// of a pixel, premultiplied:
//
// func Fragment(dst vec4, pos vec2) vec4
//
// dst is the pixel's center in the target, in its pixels from its top
// left corner, and pos the same point in DIPs from the top left corner of
// the rectangle the shader fills. It may take dst alone, or nothing.
const Entry = "Fragment"
// The uniform variables the bridge declares, which renderers set, before
// the shader's own: the images' sizes in pixels, the size of the
// rectangle the shader fills in DIPs, the pixels a DIP, and, for an
// effect's shader, where the corner of the element's box lies in its
// content (LayerImage), in its pixels.
const (
ImageSizesUniform = "__imageSizes"
RectSizeUniform = "__rectSize"
ScaleUniform = "__scale"
LayerInsetUniform = "__layerInset"
// The backdrop of a shader reading it (BackdropImage): the rows of the
// map from its positions to the frame's pixels, and where its texels
// start in the frame, with how many pixels each covers across.
BackdropRow0Uniform = "__backdropRow0"
BackdropRow1Uniform = "__backdropRow1"
BackdropAreaUniform = "__backdropArea"
// InstanceUniform is what a shader reads of the instance it draws,
// among many that one draw draws (ui/shader's DrawInstances), which
// renderers set for each instance rather than with the uniforms:
// [5]vec4, the instance's data (instanceData) in the first four, then
// its index, the size of its rectangle in DIPs, and 1, or zero for a
// draw of one rectangle.
InstanceUniform = "__instance"
)
// MaxInstanceData is how many floats of its own an instance gives its
// shader, which instanceData reads.
const MaxInstanceData = 16
// BackdropImage is the image a shader reads its backdrop from, through
// backdropAt and backdropSample: what the window drew behind it, which the
// renderers capture and blur as for effects reading their backdrop.
const BackdropImage = MaxImages - 2
// LayerImage is the image an effect's shader reads its element's content
// from, through layerAt and layerSample: the last, which its own images
// leave free.
const LayerImage = MaxImages - 1
// bridge is the source appended to a shader: the uniform variables that
// only renderers set, the functions that read them and the images, and
// the vertex entry point, which only gives the fragment entry point its
// arguments: renderers draw with vertex stages of their own.
var bridge = func() string {
var b strings.Builder
fmt.Fprintf(&b, `
%s
var %s [%d]vec2
var %s vec2
var %s float
var %s vec2
var %[8]s vec3
var %[9]s vec3
var %[10]s vec4
var %[12]s [5]vec4
// rectSize returns the size of the rectangle the shader fills, in DIPs:
// the instance's, for a shader drawing instances.
func rectSize() vec2 {
if %[12]s[4].w > 0 {
return %[12]s[4].yz
}
return %[4]s
}
// instanceIndex returns the index of the instance the shader draws, among
// those of one draw, or 0.
func instanceIndex() int {
return int(%[12]s[4].x)
}
// instanceData returns float i of the instance's own, from 0, or 0 beyond
// them.
func instanceData(i int) float {
if i < 0 || i >= %[13]d {
return 0
}
return %[12]s[i/4][i%%4]
}
// pixelScale returns how many pixels of the target make a DIP.
func pixelScale() float {
return %[5]s
}
// layerAt returns the pixel of the content of the element an effect
// draws at p, in DIPs from the corner of its box, premultiplied:
// transparent beyond what renders.
func layerAt(p vec2) vec4 {
return image%[7]dAt(p*%[5]s + %[6]s)
}
// layerSample returns the content of the element an effect draws at p,
// in DIPs from the corner of its box, blended between the centers of the
// four pixels around p, premultiplied: transparent beyond what renders.
func layerSample(p vec2) vec4 {
q := p*%[5]s + %[6]s
in := step(vec2(0), q) - step(%[2]s[%[7]d], q)
return image%[7]dSample(q) * in.x * in.y
}
// __backdropTexel returns where p, in DIPs from the corner of the box the
// shader fills, lies in the backdrop's texels.
func __backdropTexel(p vec2) vec2 {
q := vec2(dot(%[8]s, vec3(p, 1)), dot(%[9]s, vec3(p, 1)))
return (q - %[10]s.xy) / %[10]s.z
}
// backdropAt returns the backdrop's texel at p, in DIPs from the corner of
// the box the shader fills, premultiplied: what the window drew behind it,
// blurred as Options.BackdropBlur says.
func backdropAt(p vec2) vec4 {
return image%[11]dAt(__backdropTexel(p))
}
// backdropSample returns the backdrop at p, in DIPs from the corner of the
// box the shader fills, blended between the texels around it.
func backdropSample(p vec2) vec4 {
return image%[11]dSample(__backdropTexel(p))
}
`, InternalRegionBegin, ImageSizesUniform, MaxImages, RectSizeUniform, ScaleUniform, LayerInsetUniform, LayerImage,
BackdropRow0Uniform, BackdropRow1Uniform, BackdropAreaUniform, BackdropImage, InstanceUniform, MaxInstanceData)
for i := range MaxImages {
fmt.Fprintf(&b, `
// image%[1]dSize returns the size of image %[1]d, in its pixels.
func image%[1]dSize() vec2 {
return %[2]s[%[1]d]
}
// image%[1]dAt returns the pixel of image %[1]d at p, in its pixels from its
// top left corner, premultiplied: transparent outside the image.
func image%[1]dAt(p vec2) vec4 {
in := step(vec2(0), p) - step(%[2]s[%[1]d], p)
return __texelAt(__t%[1]d, p) * in.x * in.y
}
// image%[1]dSample returns image %[1]d at p, in its pixels from its top left
// corner, blended between the centers of the four pixels around p, and
// clamped to its edges, as linear filtering samples a texture.
func image%[1]dSample(p vec2) vec4 {
q := p - 0.5
f := floor(q)
w := q - f
hi := %[2]s[%[1]d] - 1
a := __texelAt(__t%[1]d, clamp(f, vec2(0), hi))
b := __texelAt(__t%[1]d, clamp(f+vec2(1, 0), vec2(0), hi))
c := __texelAt(__t%[1]d, clamp(f+vec2(0, 1), vec2(0), hi))
d := __texelAt(__t%[1]d, clamp(f+vec2(1), vec2(0), hi))
return mix(mix(a, b, w.x), mix(c, d, w.x), w.y)
}
`, i, ImageSizesUniform)
}
fmt.Fprintf(&b, `
func %s(dst vec2, pos vec2) (vec4, vec2) {
return vec4(dst, 0, 1), pos
}
%s
`, vertexEntry, InternalRegionEnd)
return b.String()
}()
const vertexEntry = "__vertex"
// CompileFragment compiles a MyGo shader: Go's syntax in package main,
// with uniform variables (exported, package level) that the app sets and
// the entry point Fragment, which may call functions of its own and read
// images through the functions image0At to image3At, image0Sample to
// image3Sample and image0Size to image3Size.
func CompileFragment(src []byte) (*shaderir.Program, error) {
var b bytes.Buffer
b.Write(src)
b.WriteString(bridge)
p, err := Compile(b.Bytes(), vertexEntry, Entry, MaxImages)
if err != nil {
return nil, err
}
if p.FragmentFunc.Block == nil {
return nil, fmt.Errorf("shader: no entry point %s", Entry)
}
p.FragmentSource = bytes.Clone(src)
return p, nil
}
+10
View File
@@ -0,0 +1,10 @@
// Package shader compiles shaders written in Go's syntax into the
// intermediate representation of package shaderir, which its backends
// translate for each GPU renderer.
//
// It is Ebitengine's Kage compiler (github.com/hajimehoshi/ebiten,
// internal/shader and internal/shaderir at commit 16f18b0), under the
// Apache License 2.0 in LICENSE, forked to compile MyGo's shaders: files
// that came from Ebitengine keep its copyright notice, and say so where
// MyGo changed them.
package shader
+258
View File
@@ -0,0 +1,258 @@
// Copyright 2022 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is Ebitengine's internal/graphics/shader.go, which the tests
// of the Kage compiler forked here use as their bridge. Modified by the
// MyGo contributors: renamed, and moved into a test.
package shader_test
import (
"bytes"
"fmt"
"io"
"regexp"
"github.com/egoist/mygo/internal/shader"
"github.com/egoist/mygo/internal/shaderir"
)
// Go's whitespace is U+0020 (SP), U+0009 (\t), U+000d (\r), and U+000A (\n).
// See https://go.dev/ref/spec#Tokens
var reUnit = regexp.MustCompile(`^[ \t\r\n]*//kage:unit\s+([^ \t\r\n]+)[ \t\r\n]*$`)
// ParseKageUnitDirective returns the value of the //kage:unit directive in src, or an empty string if
// the directive is absent. A duplicated directive is an error.
func parseKageUnitDirective(src []byte) (string, error) {
var value string
var parsed bool
for line := range bytes.Lines(src) {
m := reUnit.FindSubmatch(line)
if m == nil {
continue
}
if parsed {
return "", fmt.Errorf("graphics: at most one //kage:unit can exist in a shader")
}
value = string(m[1])
parsed = true
}
return value, nil
}
// writeShaderBridge writes to w the Kage source appended to a user's fragment shader, bridging the user's
// builtin functions to the engine's __-prefixed uniforms and textures. The bridge operates in the pixel
// unit: the region uniforms hold pixels, and __texelAt fetches a texel by its integer pixel coordinates.
// The bridge is an internal region, where the __-prefixed uniform variables can be declared.
func writeShaderBridge(w io.Writer) error {
if _, err := io.WriteString(w, "\n"+shader.InternalRegionBegin+"\n"); err != nil {
return err
}
if _, err := fmt.Fprintf(w, `
var __imageDstTextureSize vec2
// imageDstTextureSize returns the destination image's texture size in pixels.
//
// As an image is a part of internal texture, the texture is usually bigger than the image.
func imageDstTextureSize() vec2 {
return __imageDstTextureSize
}
var __imageSrcTextureSizes [%[1]d]vec2
// imageSrcTextureSize returns the 0th source image's texture size in pixels.
//
// Deprecated: as of v2.6. Use imageSrc0TextureSize instead.
func imageSrcTextureSize() vec2 {
return __imageSrcTextureSizes[0]
}
`, ebitenSrcImageCount); err != nil {
return err
}
if _, err := io.WriteString(w, `
// The unit is the destination texture's pixel or texel.
var __imageDstRegionOrigin vec2
// The unit is the destination texture's pixel or texel.
var __imageDstRegionSize vec2
// imageDstRegionOnTexture returns the destination image's region (the origin and the size) on its texture.
// The unit is the destination texture's pixel or texel.
//
// As an image is a part of internal texture, the image can be located at an arbitrary position on the texture.
//
// Deprecated: as of v2.6. Use imageDstOrigin or imageDstSize.
func imageDstRegionOnTexture() (vec2, vec2) {
return __imageDstRegionOrigin, __imageDstRegionSize
}
// imageDstOrigin returns the destination image's origin on its texture.
// The unit is the destination texture's pixel or texel.
//
// As an image is a part of internal texture, the image can be located at an arbitrary position on the texture.
func imageDstOrigin() vec2 {
return __imageDstRegionOrigin
}
// imageDstSize returns the destination image's size.
// The unit is the destination texture's pixel or texel.
func imageDstSize() vec2 {
return __imageDstRegionSize
}
`); err != nil {
return err
}
if _, err := fmt.Fprintf(w, `
// The unit is the source texture's pixel or texel.
var __imageSrcRegionOrigins [%[1]d]vec2
// The unit is the source texture's pixel or texel.
var __imageSrcRegionSizes [%[1]d]vec2
// imageSrcRegionOnTexture returns the 0th source image's region (the origin and the size) on its texture.
// The unit is the source texture's pixel or texel.
//
// As an image is a part of internal texture, the image can be located at an arbitrary position on the texture.
//
// Deprecated: as of v2.6. Use imageSrc0Origin or imageSrc0Size instead.
func imageSrcRegionOnTexture() (vec2, vec2) {
return __imageSrcRegionOrigins[0], __imageSrcRegionSizes[0]
}
`, ebitenSrcImageCount); err != nil {
return err
}
for i := range ebitenSrcImageCount {
if _, err := fmt.Fprintf(w, `
// imageSrc%[1]dOrigin returns the source image's region origin on its texture.
// The unit is the source texture's pixel or texel.
//
// As an image is a part of internal texture, the image can be located at an arbitrary position on the texture.
func imageSrc%[1]dOrigin() vec2 {
return __imageSrcRegionOrigins[%[1]d]
}
// imageSrc%[1]dSize returns the source image's size.
// The unit is the source texture's pixel or texel.
func imageSrc%[1]dSize() vec2 {
return __imageSrcRegionSizes[%[1]d]
}
// imageSrc%[1]dTextureSize returns the source image's texture size in pixels.
//
// As an image is a part of internal texture, the texture is usually bigger than the image.
func imageSrc%[1]dTextureSize() vec2 {
return __imageSrcTextureSizes[%[1]d]
}
`, i); err != nil {
return err
}
// pos is in pixels of the 0th texture. Convert it to the i-th texture's pixels.
// pos is floored first, as __texelAt does, so that the conversion adds only integers and is exact.
// Adding the origins to a fractional pos can round it to the next pixel.
// The 0th source image needs no conversion, so its functions have no suffix.
texPos := "pos"
var suffix string
if i >= 1 {
texPos = fmt.Sprintf("floor(pos) - __imageSrcRegionOrigins[0] + __imageSrcRegionOrigins[%d]", i)
suffix = "FromSrc0Pos"
}
// __t%d is a special variable for a texture variable.
if _, err := fmt.Fprintf(w, `
// imageSrc%[1]dUnsafeAt%[3]s returns the source image's color at the given position.
// The position is in the 0th source image's texture.
// The result is undefined when the position is outside the image.
func imageSrc%[1]dUnsafeAt%[3]s(pos vec2) vec4 {
return __texelAt(__t%[1]d, %[2]s)
}
// imageSrc%[1]dAt%[3]s returns the source image's color at the given position.
// The position is in the 0th source image's texture.
// The result is transparent when the position is outside the image.
func imageSrc%[1]dAt%[3]s(pos vec2) vec4 {
// If pos is in the region, in is (1, 1). Otherwise, either element is 0.
in := step(__imageSrcRegionOrigins[0], pos) - step(__imageSrcRegionOrigins[0] + __imageSrcRegionSizes[%[1]d], pos)
return __texelAt(__t%[1]d, %[2]s) * in.x * in.y
}
`, i, texPos, suffix); err != nil {
return err
}
}
if _, err := io.WriteString(w, `
var __projectionMatrix mat4
func __vertex(dstPos vec2, srcPos vec2, color vec4, custom vec4) (vec4, vec2, vec4, vec4) {
return __projectionMatrix * vec4(dstPos, 0, 1), srcPos, color, custom
}
`); err != nil {
return err
}
if _, err := io.WriteString(w, shader.InternalRegionEnd+"\n"); err != nil {
return err
}
return nil
}
// completeShaderSource returns a complete shader source: the fragment shader source followed by the bridge.
func completeShaderSource(fragmentSrc []byte) []byte {
var buf bytes.Buffer
// Writing to a bytes.Buffer never fails.
_, _ = buf.Write(fragmentSrc)
_ = writeShaderBridge(&buf)
return buf.Bytes()
}
// CompileShader compiles a pixel-unit fragment shader source into an intermediate representation.
// The source must select the pixel unit with the `//kage:unit pixels` directive.
// The returned program's FragmentSource holds the given source.
func compileEbitenShader(fragmentSrc []byte) (*shaderir.Program, error) {
value, err := parseKageUnitDirective(fragmentSrc)
if err != nil {
return nil, err
}
if value != "pixels" {
return nil, fmt.Errorf("graphics: the `//kage:unit pixels` directive is required")
}
const (
vert = "__vertex"
frag = "Fragment"
)
ir, err := shader.Compile(completeShaderSource(fragmentSrc), vert, frag, ebitenSrcImageCount)
if err != nil {
return nil, err
}
if ir.VertexFunc.Block == nil {
return nil, fmt.Errorf("graphics: vertex shader entry point '%s' is missing", vert)
}
if ir.FragmentFunc.Block == nil {
return nil, fmt.Errorf("graphics: fragment shader entry point '%s' is missing", frag)
}
ir.FragmentSource = bytes.Clone(fragmentSrc)
return ir, nil
}
const ebitenSrcImageCount = 4
File diff suppressed because it is too large. Load diff
+149
View File
@@ -0,0 +1,149 @@
package shader_test
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/egoist/mygo/internal/shader"
"github.com/egoist/mygo/internal/shaderir/glsl"
"github.com/egoist/mygo/internal/shaderir/hlsl"
"github.com/egoist/mygo/internal/shaderir/msl"
)
// The backends write a shader as a function for the renderers to call,
// as the files beside testdata/mygo/fragment.go hold, which MYGO_UPDATE_SHADERS
// writes anew, reading what it draws of an instance (InstanceUniform) from
// the renderer's code, as ui/shader has them.
func TestFragment(t *testing.T) {
src, err := os.ReadFile(filepath.Join("testdata", "mygo", "fragment.go"))
if err != nil {
t.Fatal(err)
}
p, err := shader.CompileFragment(src)
if err != nil {
t.Fatal(err)
}
for ext, got := range map[string]string{
"metal": msl.Fragment(p, "shaderFragment", shader.InstanceUniform),
"glsl": glsl.Fragment(p, "shaderFragment", glsl.Options{FlipY: "flipY", FlipRows: "flipRowsOf", Instance: shader.InstanceUniform}),
"hlsl": hlsl.Fragment(p, "shaderFragment", 2, 6, shader.InstanceUniform),
} {
name := filepath.Join("testdata", "mygo", "fragment.expected."+ext)
if os.Getenv("MYGO_UPDATE_SHADERS") != "" {
if err := os.WriteFile(name, []byte(got), 0o644); err != nil {
t.Fatal(err)
}
continue
}
want, err := os.ReadFile(name)
if err != nil {
t.Fatal(err)
}
if got != string(want) {
t.Errorf("%s: got\n%s", name, got)
}
// A uint loop steps by a uint, and HLSL makes a vector of one scalar
// by a cast, as it does not spread one.
if !strings.Contains(got, "+= 2u") {
t.Errorf("%s: the uint loop does not step by 2u", name)
}
if ext == "hlsl" && !strings.Contains(got, "(uint3)(") {
t.Errorf("%s: uvec3 of a scalar is not a cast", name)
}
}
}
// Shaders read uints and ints as two kinds of integer, which mix only in
// shifts, and constants must fit theirs.
func TestUint(t *testing.T) {
for _, c := range []struct {
body, err string
}{
{"var x uint = 0xFFFFFFFF; _ = x", ""},
{"var a uint; x := a * 2654435769; _ = x", ""},
{"x := uint(3) * 2654435769; _ = x", "overflows uint"},
{"var x uint = 1 << 32; _ = x", "overflows uint"},
{"x := uint(-1); _ = x", "cannot convert"},
{"var a int; var b uint; _ = a + b", "types don't match"},
{"var a uint; _ = a << 3; _ = a >> int(dst.x); _ = 1 << a", ""},
{"var v uvec2; v.x ^= 7; v %= 3; _ = v.yx + uvec2(dst.xy)", ""},
{"x := int(2654435769); _ = x", "overflows int"},
{"_ = max(uint(1), 2, 3); _ = clamp(uvec2(1), uint(0), 4)", ""},
{"x := ^uint(0); y := ^N; _, _ = x, y", ""},
{"x := -uint(1); _ = x", "overflows uint"},
{"i := 5; var u uint = 1; i >>= u; i <<= N; _ = i", ""},
{"s := uint(0); for i := uint(0); i < 3000000000; i++ { s += i }; _ = s", ""},
{"s := uint(0); for i := uint(4000000000); i > 3000000000; i -= 3000000000 { s += i }; _ = s", ""},
{"s := uint(0); for i := uint(0); i < 5000000000; i++ { s += i }; _ = s", "overflows uint"},
{"var n uint; s := uint(0); for i := range n { s += i }; for i := range N { s += i }; _ = s", ""},
{"var a [4]float; var u uint; _ = a[u]", ""},
{"var m int; var x uint = 1 << m; y := N & (1 << m); x |= 1 << m; _, _ = x, y", ""},
{"var m int; var f float = 1 << m; _ = f", "cannot use type int as type float"},
{"var m int; x := 1 << m; var u uint; _ = x + u", "types don't match"},
} {
src := "package main\n\nconst N uint = 7\n\nfunc Fragment(dst vec4, pos vec2) vec4 {\n\t" + c.body + "\n\treturn dst\n}\n"
_, err := shader.CompileFragment([]byte(src))
switch {
case c.err == "" && err != nil:
t.Errorf("%s: %v", c.body, err)
case c.err != "" && (err == nil || !strings.Contains(err.Error(), c.err)):
t.Errorf("%s: %v, want an error saying %q", c.body, err, c.err)
}
}
}
// Integer constants are written as uints exactly where they are: a shift
// of an untyped constant by a count that is not one takes the type of its
// context, as in Go, and int where it has none.
func TestUntypedShift(t *testing.T) {
src := `package main
const N uint = 7
func top(m int) uint {
return 1 << m
}
func Fragment(dst vec4, pos vec2) vec4 {
m := int(pos.x)
var x uint = 1 << m
y := N & ^(1 << m)
i := 1 << m
return vec4(float(x), float(y), float(i), float(top(m)))
}
`
p, err := shader.CompileFragment([]byte(src))
if err != nil {
t.Fatal(err)
}
got := glsl.Fragment(p, "shaderFragment", glsl.Options{FlipY: "flipY"})
for _, want := range []string{
"return (1u) << (l0);",
" = (1u) << (l2);",
" = (7u) & (~((1u) << (l2)));",
" = (1) << (l2);",
} {
if !strings.Contains(got, want) {
t.Errorf("no %q in\n%s", want, got)
}
}
}
// Redeclaring a function MyGo declares for shaders is an error at the
// shader's declaration, not in MyGo's source after it.
func TestRedeclaredBridge(t *testing.T) {
src := "package main\n\nfunc rectSize() vec2 {\n\treturn vec2(0)\n}\n\nfunc Fragment(dst vec4, pos vec2) vec4 {\n\treturn dst\n}\n"
_, err := shader.CompileFragment([]byte(src))
if err == nil || !strings.HasPrefix(err.Error(), "3:6: rectSize redeclared") {
t.Errorf("%v, want an error at 3:6", err)
}
}
// A shader needs its entry point.
func TestNoEntry(t *testing.T) {
if _, err := shader.CompileFragment([]byte("package main\n\nfunc main() {}\n")); err == nil {
t.Error("a shader without Fragment compiled")
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+267
View File
@@ -0,0 +1,267 @@
// Copyright 2026 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shader_test
import (
"fmt"
"reflect"
"slices"
"strings"
"testing"
"text/template"
"github.com/egoist/mygo/internal/shaderir"
"github.com/egoist/mygo/internal/shaderir/glsl"
"github.com/egoist/mygo/internal/shaderir/hlsl"
"github.com/egoist/mygo/internal/shaderir/msl"
)
func walkSwizzlingExprs(p *shaderir.Program, f func(e *shaderir.Expr)) {
var walkExpr func(e *shaderir.Expr)
walkExpr = func(e *shaderir.Expr) {
if e.Type == shaderir.SwizzlingExpr {
f(e)
}
for i := range e.Exprs {
walkExpr(&e.Exprs[i])
}
}
var walkBlock func(b *shaderir.Block)
walkBlock = func(b *shaderir.Block) {
if b == nil {
return
}
for i := range b.Stmts {
for j := range b.Stmts[i].Exprs {
walkExpr(&b.Stmts[i].Exprs[j])
}
for _, child := range b.Stmts[i].Blocks {
walkBlock(child)
}
}
}
walkBlock(p.VertexFunc.Block)
walkBlock(p.FragmentFunc.Block)
for _, fn := range p.Funcs {
walkBlock(fn.Block)
}
}
func TestSwizzlingCanonical(t *testing.T) {
const source = `//kage:unit pixels
package main
func swizzle(v vec4) vec4 {
v.{{.X}}{{.Y}} = v.{{.Y}}{{.X}}
v.{{.Z}}{{.W}} += v.{{.X}}{{.Y}}
v.{{.X}}, v.{{.Y}} = v.{{.Y}}, v.{{.X}}
v.{{.W}}{{.Z}}{{.Y}}{{.X}}.xy = v.{{.Z}}{{.W}}
return v.{{.W}}{{.Z}}{{.Y}}{{.X}}.rgba.stpq + v.{{.X}}{{.X}}{{.Y}}{{.Y}}
}
func Fragment(position vec4) vec4 {
v := ivec4(1, 2, 3, 4)
v.{{.X}}{{.Y}} = v.{{.Y}}{{.X}}
v.{{.Z}}{{.W}} += v.{{.X}}{{.Y}}
v.{{.X}}, v.{{.Y}} = v.{{.Y}}, v.{{.X}}
v.{{.W}}{{.Z}}{{.Y}}{{.X}}.xy = v.{{.Z}}{{.W}}
return swizzle(position) + vec4(v.{{.W}}{{.Z}}{{.Y}}{{.X}}.rgba.stpq + v.{{.X}}{{.X}}{{.Y}}{{.Y}})
}`
tmpl, err := template.New("swizzling").Parse(source)
if err != nil {
t.Fatal(err)
}
compile := func(t *testing.T, set string) *shaderir.Program {
t.Helper()
var src strings.Builder
if err := tmpl.Execute(&src, struct {
X, Y, Z, W string
}{
X: set[0:1],
Y: set[1:2],
Z: set[2:3],
W: set[3:4],
}); err != nil {
t.Fatal(err)
}
p, err := compileToIR([]byte(src.String()))
if err != nil {
t.Fatal(err)
}
return p
}
outputs := func(p *shaderir.Program) []string {
vs, fs := glsl.Compile(p, glsl.GLSLVersionDefault, -1)
esVS, esFS := glsl.Compile(p, glsl.GLSLVersionES300, -1)
hvs, hfs, _, _ := hlsl.Compile(p)
return []string{vs, fs, esVS, esFS, hvs, hfs, msl.Compile(p)}
}
clearSwizzlingSet := func(e *shaderir.Expr) {
e.SwizzlingSet = shaderir.SwizzlingSetXYZW
}
want := compile(t, "xyzw")
walkSwizzlingExprs(want, func(e *shaderir.Expr) {
if len(e.Swizzling) < 1 || len(e.Swizzling) > 4 || strings.Trim(e.Swizzling, "xyzw") != "" {
t.Errorf("noncanonical IR swizzle: %q", e.Swizzling)
}
})
wantOutputs := outputs(want)
walkSwizzlingExprs(want, clearSwizzlingSet)
for _, set := range []string{"xyzw", "rgba", "stpq"} {
t.Run(set, func(t *testing.T) {
got := compile(t, set)
gotOutputs := outputs(got)
walkSwizzlingExprs(got, clearSwizzlingSet)
if !reflect.DeepEqual(got.FragmentFunc, want.FragmentFunc) || !reflect.DeepEqual(got.Funcs, want.Funcs) {
t.Error("equivalent swizzles produced different IR")
}
for i, output := range gotOutputs {
if output != wantOutputs[i] {
t.Errorf("backend output %d differs for equivalent swizzles", i)
}
}
})
}
}
func TestSwizzlingSet(t *testing.T) {
testCases := []struct {
Selectors string
Swizzlings []string
Sets []shaderir.SwizzlingSet
}{
{
Selectors: "xyzw",
Swizzlings: []string{"xyzw"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetXYZW},
},
{
Selectors: "rgba",
Swizzlings: []string{"xyzw"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetRGBA},
},
{
Selectors: "stpq",
Swizzlings: []string{"xyzw"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetSTPQ},
},
{
Selectors: "x",
Swizzlings: []string{"x"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetXYZW},
},
{
Selectors: "rgr",
Swizzlings: []string{"xyx"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetRGBA},
},
{
Selectors: "qpts",
Swizzlings: []string{"wzyx"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetSTPQ},
},
{
Selectors: "xy.ts",
Swizzlings: []string{"xy", "yx"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetXYZW, shaderir.SwizzlingSetSTPQ},
},
{
Selectors: "rg.yx",
Swizzlings: []string{"xy", "yx"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetRGBA, shaderir.SwizzlingSetXYZW},
},
{
Selectors: "st.gr",
Swizzlings: []string{"xy", "yx"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetSTPQ, shaderir.SwizzlingSetRGBA},
},
{
Selectors: "wzyx.rgba.stpq",
Swizzlings: []string{"wzyx", "xyzw", "xyzw"},
Sets: []shaderir.SwizzlingSet{shaderir.SwizzlingSetXYZW, shaderir.SwizzlingSetRGBA, shaderir.SwizzlingSetSTPQ},
},
}
for _, tc := range testCases {
t.Run(tc.Selectors, func(t *testing.T) {
p, err := compileToIR([]byte(fmt.Sprintf(`//kage:unit pixels
package main
func Fragment() vec4 {
var v vec4
w := v.%s
_ = w
return v
}`, tc.Selectors)))
if err != nil {
t.Fatal(err)
}
var swizzlings, sources []string
var sets []shaderir.SwizzlingSet
walkSwizzlingExprs(p, func(e *shaderir.Expr) {
swizzlings = append(swizzlings, e.Swizzling)
sets = append(sets, e.SwizzlingSet)
sources = append(sources, e.SourceSwizzling())
})
if !slices.Equal(swizzlings, tc.Swizzlings) {
t.Errorf("Swizzling: got: %q, want: %q", swizzlings, tc.Swizzlings)
}
if !slices.Equal(sets, tc.Sets) {
t.Errorf("SwizzlingSet: got: %v, want: %v", sets, tc.Sets)
}
if want := strings.Split(tc.Selectors, "."); !slices.Equal(sources, want) {
t.Errorf("SourceSwizzling: got: %q, want: %q", sources, want)
}
})
}
}
func TestSwizzlingValidation(t *testing.T) {
check := func(t *testing.T, typ, swizzle string, valid bool) {
t.Helper()
for _, statement := range []string{
"_ = v." + swizzle,
"v." + swizzle + " = v." + swizzle,
} {
source := fmt.Sprintf(`//kage:unit pixels
package main
func Fragment() vec4 {
var v %s
%s
return vec4(0)
}`, typ, statement)
_, err := compileToIR([]byte(source))
if (err == nil) != valid {
t.Errorf("%s: %s: success = %t, want %t (error: %v)", typ, statement, err == nil, valid, err)
}
}
}
for _, prefix := range []string{"vec", "ivec"} {
for size := 2; size <= 4; size++ {
typ := fmt.Sprintf("%s%d", prefix, size)
t.Run(typ, func(t *testing.T) {
for _, set := range []string{"xyzw", "rgba", "stpq"} {
for i := range set {
check(t, typ, set[i:i+1], i < size)
}
}
for _, swizzle := range []string{"rx", "sr", "strq", "xs", "rt", "pqx", "xyzwx", "xy.p", "rg.b", "st.z"} {
check(t, typ, swizzle, false)
}
for _, swizzle := range []string{"xy.ts", "rg.yx", "st.gr"} {
check(t, typ, swizzle, true)
}
})
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,29 @@
uniform vec2 U0[4];
void F0(out vec2 l0[2]);
void F1(out vec2 l0[2]);
void F0(out vec2 l0[2]) {
vec2 l1[2];
l1[0] = vec2(0);
l1[1] = vec2(0);
l0[0] = l1[0];
l0[1] = l1[1];
return;
}
void F1(out vec2 l0[2]) {
vec2 l1[2];
l1[0] = vec2(0);
l1[1] = vec2(0);
vec2 l2[2];
l2[0] = vec2(0);
l2[1] = vec2(0);
(l1)[0] = vec2(1.0);
l2[0] = l1[0];
l2[1] = l1[1];
(l2)[1] = vec2(2.0);
l0[0] = l2[0];
l0[1] = l2[1];
return;
}
+14
View File
@@ -0,0 +1,14 @@
package main
var Array [4]vec2
func Foo() [2]vec2 {
var x [2]vec2
return x
}
func Bar() [2]vec2 {
x := [2]vec2{vec2(1)}
x[1] = vec2(2)
return x
}
@@ -0,0 +1,12 @@
void F0(bool front_facing, thread array<float2, 3>& l0);
void F0(bool front_facing, thread array<float2, 3>& l0) {
array<float2, 2> l1 = {};
array<float2, 3> l2 = {};
{
array<float2, 2> l2 = {};
l2 = l1;
}
l0 = l2;
return;
}
@@ -0,0 +1,22 @@
void F0(out vec2 l0[3]);
void F0(out vec2 l0[3]) {
vec2 l1[2];
l1[0] = vec2(0);
l1[1] = vec2(0);
vec2 l2[3];
l2[0] = vec2(0);
l2[1] = vec2(0);
l2[2] = vec2(0);
{
vec2 l2[2];
l2[0] = vec2(0);
l2[1] = vec2(0);
l2[0] = l1[0];
l2[1] = l1[1];
}
l0[0] = l2[0];
l0[1] = l2[1];
l0[2] = l2[2];
return;
}
+12
View File
@@ -0,0 +1,12 @@
package main
func Foo() [3]vec2 {
var a [2]vec2
{
var b [2]vec2
b = a
_ = b
}
var c [3]vec2
return c
}
@@ -0,0 +1,14 @@
void F0(void);
void F0(void) {
float l0[2];
l0[0] = float(0);
l0[1] = float(0);
float l1[2];
l1[0] = float(0);
l1[1] = float(0);
(l0)[0] = 1.0;
l1[0] = l0[0];
l1[1] = l0[1];
return;
}
+7
View File
@@ -0,0 +1,7 @@
package main
func Foo() {
a := [2]float{1}
_ = a
return
}
@@ -0,0 +1,8 @@
vec4 F0(in vec2 l0);
vec4 F0(in vec2 l0) {
float l1 = float(0);
l1 = 0.0;
l1 = (l1) + (1.0);
return vec4(l0, l1, l1);
}
+8
View File
@@ -0,0 +1,8 @@
package main
func Foo(foo vec2) vec4 {
var r1 float
r1 = 0.0
r1 += 1.0
return vec4(foo, r1, r1)
}
@@ -0,0 +1,19 @@
vec4 F0(in vec2 l0);
void F1(out float l0, out float l1);
vec4 F0(in vec2 l0) {
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
float l4 = float(0);
F1(l3, l4);
l1 = l3;
l2 = l4;
return vec4(l0, l1, l2);
}
void F1(out float l0, out float l1) {
l0 = 0.0;
l1 = 0.0;
return;
}
@@ -0,0 +1,11 @@
package main
func Foo(foo vec2) vec4 {
var r1, r2 float
r1, r2 = Bar()
return vec4(foo, r1, r2)
}
func Bar() (float, float) {
return 0, 0
}
@@ -0,0 +1,13 @@
vec2 F0(void);
vec2 F0(void) {
float l0 = float(0);
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
l1 = 1.0;
l3 = 2.0;
l0 = l1;
l2 = l3;
return vec2(l0, l2);
}
@@ -0,0 +1,6 @@
package main
func Foo() vec2 {
r1, r2 := 1.0, 2.0
return vec2(r1, r2)
}
@@ -0,0 +1,9 @@
bool F0(bool front_facing, float l0, float l1);
bool F0(bool front_facing, float l0, float l1) {
float l2 = float(0);
float l3 = float(0);
l2 = atan((l1) / (l0));
l3 = atan2(l1, l0);
return (l2) == (l3);
}
@@ -0,0 +1,9 @@
bool F0(in float l0, in float l1);
bool F0(in float l0, in float l1) {
float l2 = float(0);
float l3 = float(0);
l2 = atan((l1) / (l0));
l3 = atan(l1, l0);
return (l2) == (l3);
}
+7
View File
@@ -0,0 +1,7 @@
package main
func Foo(x, y float) bool {
a := atan(y / x)
b := atan2(y, x)
return a == b
}
@@ -0,0 +1,26 @@
void F0(out int l0, out int l1);
void F1(void);
void F0(out int l0, out int l1) {
l0 = 1;
l1 = 1;
return;
}
void F1(void) {
int l0 = 0;
int l1 = 0;
int l2 = 0;
int l3 = 0;
int l4 = 0;
int l5 = 0;
int l6 = 0;
int l7 = 0;
int l8 = 0;
int l9 = 0;
F0(l0, l1);
F0(l2, l3);
l4 = l2;
F0(l6, l7);
l9 = l7;
}
+12
View File
@@ -0,0 +1,12 @@
package main
func Foo() (int, int) {
return 1, 1
}
func Bar() {
_, _ = Foo()
a, _ := Foo()
_, b := Foo()
_, _ = a, b
}
@@ -0,0 +1,20 @@
vec4 F0(in vec2 l0);
vec4 F0(in vec2 l0) {
vec4 l1 = vec4(0);
{
vec3 l2 = vec3(0);
(l1).x = (l0).x;
{
vec4 l3 = vec4(0);
(l1).y = (l2).y;
(l1).z = (l3).z;
}
{
vec4 l3 = vec4(0);
(l1).y = (l2).y;
(l1).z = (l3).z;
}
}
return l1;
}
+20
View File
@@ -0,0 +1,20 @@
package main
func Foo(foo vec2) vec4 {
var r vec4
{
r.x = foo.x
var foo vec3
{
r.y = foo.y
var foo vec4
r.z = foo.z
}
{
r.y = foo.y
var foo vec4
r.z = foo.z
}
}
return r
}
@@ -0,0 +1,12 @@
vec2 F0(void);
vec2 F0(void) {
bool l0 = false;
l0 = true;
{
int l1 = 0;
l1 = 0;
return vec2(float(l1));
}
return vec2(1.0);
}
+11
View File
@@ -0,0 +1,11 @@
package main
func Foo() vec2 {
x := true
{
x := 0
return vec2(float(x))
}
_ = x
return vec2(1)
}
@@ -0,0 +1,21 @@
vec4 F0(in vec2 l0);
vec4 F0(in vec2 l0) {
vec4 l1 = vec4(0);
{
vec3 l2 = vec3(0);
vec3 l3 = vec3(0);
(l1).x = (l0).x;
{
vec4 l3 = vec4(0);
(l1).y = (l2).y;
(l1).z = (l3).z;
}
{
vec4 l4 = vec4(0);
(l1).y = (l2).y;
(l1).z = (l3).z;
}
}
return l1;
}
+22
View File
@@ -0,0 +1,22 @@
package main
func Foo(foo vec2) vec4 {
var r vec4
{
r.x = foo.x
var foo vec3
{
r.y = foo.y
var foo vec4
r.z = foo.z
}
var bar vec3
{
r.y = foo.y
var foo vec4
r.z = bar.z
_ = foo
}
}
return r
}
@@ -0,0 +1,5 @@
bool F0(void);
bool F0(void) {
return true;
}
+5
View File
@@ -0,0 +1,5 @@
package main
func Foo() bool {
return 1.0 == 1.0
}
@@ -0,0 +1,10 @@
vec2 F0(in vec2 l0);
vec2 F1(in vec2 l0);
vec2 F0(in vec2 l0) {
return F1(l0);
}
vec2 F1(in vec2 l0) {
return l0;
}
+9
View File
@@ -0,0 +1,9 @@
package main
func Foo(x vec2) vec2 {
return Bar(x)
}
func Bar(x vec2) vec2 {
return x
}
@@ -0,0 +1,19 @@
vec2 F0(in vec2 l0);
void F1(in float l0, out float l1, out float l2);
vec2 F0(in vec2 l0) {
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
float l4 = float(0);
F1((l0).x, l1, l2);
l3 = l1;
l4 = l2;
return vec2(l3, l4);
}
void F1(in float l0, out float l1, out float l2) {
l1 = l0;
l2 = l0;
return;
}
@@ -0,0 +1,10 @@
package main
func Foo(x vec2) vec2 {
var xx, yx float = Bar(x.x)
return vec2(xx, yx)
}
func Bar(x float) (float, float) {
return x, x
}
@@ -0,0 +1,17 @@
void F0(in vec2 l0);
void F1(in float l0, in float l1, out float l2, out float l3);
void F0(in vec2 l0) {
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
float l4 = float(0);
F1((l0).x, (l0).y, l1, l2);
F1(l1, l2, l3, l4);
}
void F1(in float l0, in float l1, out float l2, out float l3) {
l2 = l0;
l3 = l1;
return;
}
@@ -0,0 +1,9 @@
package main
func Foo(x vec2) {
Bar(Bar(x.x, x.y))
}
func Bar(x, y float) (float, float) {
return x, y
}
@@ -0,0 +1,5 @@
vec2 F0(void);
vec2 F0(void) {
return vec2(3.5000000000e+00);
}
+8
View File
@@ -0,0 +1,8 @@
package main
const a = 1
const b = 2 + 0.5
func Foo() vec2 {
return vec2(a + b)
}
@@ -0,0 +1,5 @@
vec2 F0(void);
vec2 F0(void) {
return vec2(3.5000000000e+00);
}
+7
View File
@@ -0,0 +1,7 @@
package main
func Foo() vec2 {
const a = 1
const b = a + 2 + 0.5
return vec2(b)
}
@@ -0,0 +1,22 @@
void F0(void);
void F0(void) {
int l0 = 0;
int l1 = 0;
float l2 = float(0);
int l3 = 0;
int l4 = 0;
int l5 = 0;
float l6 = float(0);
float l7 = float(0);
bool l8 = false;
l0 = 1;
l1 = 1;
l2 = 1.0;
l3 = 1;
l5 = 1;
l7 = 1.0;
l4 = l5;
l6 = l7;
l8 = false;
}
+23
View File
@@ -0,0 +1,23 @@
package main
const a = 1
const b float = 1
const c int = 1
const d, e = 1, 1.0
const f = false
func Foo() {
l0 := 1
la := a
lb := b
lc := c
ld, le := d, e
lf := f
_ = l0
_ = la
_ = lb
_ = lc
_ = ld
_ = le
_ = lf
}
@@ -0,0 +1,20 @@
int F0(in int l0);
float F1(in float l0);
int F2(void);
float F3(void);
int F0(in int l0) {
return (1) + (l0);
}
float F1(in float l0) {
return (1.0) + (l0);
}
int F2(void) {
return F0(1);
}
float F3(void) {
return F1(1.0);
}
+21
View File
@@ -0,0 +1,21 @@
package main
func Foo(x int) int {
const a = 1
return a + x
}
func Bar(x float) float {
const a = 1
return a + x
}
func Baz() int {
const a = 1
return Foo(a)
}
func Qux() float {
const a = 1
return Bar(a)
}
@@ -0,0 +1,7 @@
vec4 F0(in vec2 l0);
vec4 F0(in vec2 l0) {
vec4 l1 = vec4(0);
l1 = vec4(l0, 0.0, 1.0);
return l1;
}
+6
View File
@@ -0,0 +1,6 @@
package main
func Foo(foo vec2) vec4 {
r := vec4(foo, 0, 1)
return r
}
@@ -0,0 +1,14 @@
vec2 F0(void);
vec2 F1(void);
vec2 F0(void) {
vec2 l0 = vec2(0);
vec2 l1 = vec2(0);
l0 = (1.0) * (F1());
l1 = (F1()) * (1.0);
return l0;
}
vec2 F1(void) {
return vec2(0.0);
}
+12
View File
@@ -0,0 +1,12 @@
package main
func Foo() vec2 {
x0 := 1 * Bar()
x1 := Bar() * 1
_ = x1
return x0
}
func Bar() vec2 {
return vec2(0)
}
@@ -0,0 +1,19 @@
vec4 F0(in vec2 l0);
void F1(out float l0, out float l1);
vec4 F0(in vec2 l0) {
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
float l4 = float(0);
F1(l1, l2);
l3 = l1;
l4 = l2;
return vec4(l0, l3, l3);
}
void F1(out float l0, out float l1) {
l0 = 0.0;
l1 = 0.0;
return;
}
@@ -0,0 +1,11 @@
package main
func Foo(foo vec2) vec4 {
r1, r2 := Bar()
_ = r2
return vec4(foo, r1, r1)
}
func Bar() (float, float) {
return 0, 0
}
@@ -0,0 +1,60 @@
vec2 F0(in float l0);
vec2 F1(void);
float F2(in float l0);
void F3(out float l0);
void F4(out float l0, out float l1);
vec2 F0(in float l0) {
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
float l4 = float(0);
l1 = l0;
l2 = 1.0;
l4 = l1;
l1 = l2;
l3 = l4;
return vec2(l1, l3);
}
vec2 F1(void) {
float l0 = float(0);
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
l0 = 1.0;
F4(l1, l2);
l3 = l1;
l0 = l2;
return vec2(l0, l3);
}
float F2(in float l0) {
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
l1 = 2.0;
l3 = l0;
l0 = l1;
l2 = l3;
return (l0) + (l2);
}
void F3(out float l0) {
float l1 = float(0);
float l2 = float(0);
float l3 = float(0);
l0 = float(0);
l1 = 1.0;
l3 = 2.0;
l0 = l1;
l2 = l3;
l0 = (l0) + (l2);
return;
}
void F4(out float l0, out float l1) {
l0 = 0.0;
l1 = 0.0;
return;
}
@@ -0,0 +1,28 @@
package main
func Foo(x float) vec2 {
a := x
a, b := 1.0, a
return vec2(a, b)
}
func Foo2() vec2 {
a := 1.0
b, a := Bar()
return vec2(a, b)
}
func Foo3(x float) float {
x, y := 2.0, x
return x + y
}
func Foo4() (r float) {
r, s := 1.0, 2.0
r += s
return
}
func Bar() (float, float) {
return 0, 0
}
@@ -0,0 +1,18 @@
float F0(in float l0);
float F0(in float l0) {
float l1 = float(0);
l1 = 0.0;
{
float l2 = float(0);
float l3 = float(0);
float l4 = float(0);
float l5 = float(0);
l3 = 1.0;
l5 = l0;
l2 = l3;
l4 = l5;
l1 = (l2) + (l4);
}
return l1;
}
@@ -0,0 +1,10 @@
package main
func Foo(x float) float {
y := 0.0
{
x, z := 1.0, x
y = x + z
}
return y
}
@@ -0,0 +1,7 @@
vec4 F0(in vec2 l0);
vec4 F0(in vec2 l0) {
vec4 l1 = vec4(0);
l1 = (vec4(0.0)) * (vec4(0.0));
return l1;
}
@@ -0,0 +1,6 @@
package main
func Foo(foo vec2) vec4 {
r := vec4(0.0) * vec4(0.0)
return r
}
@@ -0,0 +1,15 @@
vec2 F0(void);
vec2 F0(void) {
vec2 l0 = vec2(0);
vec2 l2 = vec2(0);
l0 = vec2(0.0);
for (int l1 = 0; l1 < 100; l1++) {
(l0).x = ((l0).x) + (float(l1));
}
l2 = vec2(0.0);
for (float l3 = 10.0; l3 >= 0.0; l3 -= 2.0) {
(l2).x = ((l2).x) + (float(l3));
}
return l0;
}
+14
View File
@@ -0,0 +1,14 @@
package main
func Foo() vec2 {
v := vec2(0)
for i := 0; i < 100; i++ {
v.x += float(i)
}
v2 := vec2(0)
for i := 10.0; i >= 0; i -= 2 {
v2.x += float(i)
}
_ = v2
return v
}
@@ -0,0 +1,21 @@
vec2 F0(void);
vec2 F0(void) {
vec2 l0 = vec2(0);
vec2 l2 = vec2(0);
l0 = vec2(0.0);
for (int l1 = 0; l1 < 100; l1++) {
(l0).x = ((l0).x) + (float(l1));
if (((l0).x) >= (100.0)) {
break;
}
}
l2 = vec2(0.0);
for (float l3 = 10.0; l3 >= 0.0; l3 -= 2.0) {
if (((l2).x) < (100.0)) {
continue;
}
(l2).x = ((l2).x) + (l3);
}
return l0;
}
+19
View File
@@ -0,0 +1,19 @@
package main
func Foo() vec2 {
v := vec2(0)
for i := 0; i < 100; i++ {
v.x += float(i)
if v.x >= 100 {
break
}
}
v2 := vec2(0)
for i := 10.0; i >= 0; i -= 2 {
if v2.x < 100 {
continue
}
v2.x += i
}
return v
}
@@ -0,0 +1,19 @@
vec2 F0(void);
vec2 F0(void) {
vec2 l0 = vec2(0);
vec2 l2 = vec2(0);
l0 = vec2(0.0);
for (int l1 = 0; l1 < 100; l1++) {
vec2 l2 = vec2(0);
l2 = vec2(0.0);
l0 = l2;
}
l2 = vec2(0.0);
for (int l3 = 0; l3 < 100; l3++) {
vec2 l4 = vec2(0);
l4 = vec2(0.0);
l2 = l4;
}
return l0;
}
+16
View File
@@ -0,0 +1,16 @@
package main
func Foo() vec2 {
v := vec2(0)
for i := 0; i < 100; i++ {
v2 := vec2(0)
v = v2
}
v3 := vec2(0)
for i := 0; i < 100; i++ {
v4 := vec2(0)
v3 = v4
}
_ = v3
return v
}
@@ -0,0 +1,20 @@
int F0(in int l0);
int F1(void);
int F0(in int l0) {
return l0;
}
int F1(void) {
int l0 = 0;
int l2 = 0;
l0 = 0;
for (int l1 = 0; l1 < 10; l1++) {
int l2 = 0;
l2 = F0(l1);
l0 = (l0) + (l2);
}
l2 = 0;
l0 = (l0) + (l2);
return l0;
}
+16
View File
@@ -0,0 +1,16 @@
package main
func Ident(x int) int {
return x
}
func Foo() int {
sum := 0
for i := 0; i < 10; i++ {
x := Ident(i)
sum += x
}
y := 0
sum += y
return sum
}
@@ -0,0 +1,33 @@
uniform float U0;
uniform float U1;
uniform float U2;
int F0(in int l0);
vec4 F1(in vec4 l0);
int F0(in int l0) {
return l0;
}
vec4 F1(in vec4 l0) {
int l1 = 0;
int l3 = 0;
l1 = 0;
for (int l2 = 0; l2 < 10; l2++) {
int l3 = 0;
l3 = F0(l2);
l1 = (l1) + (l3);
for (int l4 = 0; l4 < 10; l4++) {
int l5 = 0;
l5 = F0(l4);
l1 = (l1) + (l5);
}
}
l3 = 0;
l1 = (l1) + (l3);
return vec4(float(l1));
}
void main(void) {
fragColor = F1(gl_FragCoord);
}
@@ -0,0 +1,30 @@
uniform float U0;
uniform float U1;
uniform float U2;
in vec2 A0;
int F0(in int l0);
int F0(in int l0) {
return l0;
}
void main(void) {
int l0 = 0;
int l2 = 0;
l0 = 0;
for (int l1 = 0; l1 < 10; l1++) {
int l2 = 0;
l2 = F0(l1);
l0 = (l0) + (l2);
for (int l3 = 0; l3 < 10; l3++) {
int l4 = 0;
l4 = F0(l3);
l0 = (l0) + (l4);
}
}
l2 = 0;
l0 = (l0) + (l2);
gl_Position = vec4(float(l0));
return;
}
+41
View File
@@ -0,0 +1,41 @@
package main
var (
U0 float
U1 float
U2 float
)
func Ident(x int) int {
return x
}
func Vertex(pos vec2) vec4 {
sum := 0
for i := 0; i < 10; i++ {
x := Ident(i)
sum += x
for j := 0; j < 10; j++ {
x := Ident(j)
sum += x
}
}
y := 0
sum += y
return vec4(float(sum))
}
func Fragment(pos vec4) vec4 {
sum := 0
for i := 0; i < 10; i++ {
x := Ident(i)
sum += x
for j := 0; j < 10; j++ {
x := Ident(j)
sum += x
}
}
y := 0
sum += y
return vec4(float(sum))
}
@@ -0,0 +1,48 @@
#version 150
int modInt(int x, int y) {
return x - y*(x/y);
}
ivec2 modInt(ivec2 x, int y) {
return x - y*(x/y);
}
ivec3 modInt(ivec3 x, int y) {
return x - y*(x/y);
}
ivec4 modInt(ivec4 x, int y) {
return x - y*(x/y);
}
ivec2 modInt(ivec2 x, ivec2 y) {
return x - y*(x/y);
}
ivec3 modInt(ivec3 x, ivec3 y) {
return x - y*(x/y);
}
ivec4 modInt(ivec4 x, ivec4 y) {
return x - y*(x/y);
}
int F0(void);
int F0(void) {
int l0 = 0;
l0 = 0;
for (int l1 = 0; l1 < 10; l1++) {
l0 = (l0) + (l1);
}
for (int l2 = 0; l2 < 4; l2++) {
for (int l3 = 0; l3 < 4; l3++) {
l0 = (l0) + ((l2) * (l3));
}
}
for (int l3 = 0; l3 < 3; l3++) {
l0 = (l0) + (1);
}
return l0;
}
+18
View File
@@ -0,0 +1,18 @@
package main
func Foo() int {
sum := 0
for i := range 10 {
sum += i
}
const n = 4
for i := range n {
for j := range n {
sum += i * j
}
}
for range 3 {
sum++
}
return sum
}
@@ -0,0 +1,59 @@
#version 150
int modInt(int x, int y) {
return x - y*(x/y);
}
ivec2 modInt(ivec2 x, int y) {
return x - y*(x/y);
}
ivec3 modInt(ivec3 x, int y) {
return x - y*(x/y);
}
ivec4 modInt(ivec4 x, int y) {
return x - y*(x/y);
}
ivec2 modInt(ivec2 x, ivec2 y) {
return x - y*(x/y);
}
ivec3 modInt(ivec3 x, ivec3 y) {
return x - y*(x/y);
}
ivec4 modInt(ivec4 x, ivec4 y) {
return x - y*(x/y);
}
uniform vec2 U0[4];
float F0(void);
float F0(void) {
float l0[3];
l0[0] = float(0);
l0[1] = float(0);
l0[2] = float(0);
float l1 = float(0);
float l5 = float(0);
vec2 l7 = vec2(0);
l1 = 0.0;
for (int l2 = 0; l2 < 3; l2++) {
l1 = (l1) + (1.0);
}
for (int l3 = 0; l3 < 3; l3++) {
l1 = (l1) + ((l0)[l3]);
}
for (int l4 = 0; l4 < 3; l4++) {
l5 = (l0)[l4];
l1 = (l1) + ((float(l4)) * (l5));
}
for (int l6 = 0; l6 < 4; l6++) {
l7 = (U0)[l6];
l1 = (l1) + ((l7).x);
}
return l1;
}
@@ -0,0 +1,21 @@
package main
var U [4]vec2
func Foo() float {
var a [3]float
sum := 0.0
for range a {
sum += 1
}
for i := range a {
sum += a[i]
}
for i, v := range a {
sum += float(i) * v
}
for _, v := range U {
sum += v.x
}
return sum
}
@@ -0,0 +1,5 @@
vec4 F0(in vec2 l0);
vec4 F0(in vec2 l0) {
return vec4(0.0);
}
+5
View File
@@ -0,0 +1,5 @@
package main
func Foo(foo vec2) vec4 {
return vec4(0)
}
@@ -0,0 +1,5 @@
vec4 F0(in vec2 l0);
vec4 F0(in vec2 l0) {
return vec4(l0, 0.0, 1.0);
}
@@ -0,0 +1,5 @@
package main
func Foo(foo vec2) vec4 {
return vec4(foo, 0, 1)
}
@@ -0,0 +1,9 @@
void F0(in vec4 l0, out float l1, out float l2, out float l3, out float l4);
void F0(in vec4 l0, out float l1, out float l2, out float l3, out float l4) {
l1 = (l0).x;
l2 = (l0).y;
l3 = (l0).z;
l4 = (l0).w;
return;
}
@@ -0,0 +1,5 @@
package main
func Foo(foo vec4) (float, float, float, float) {
return foo.x, foo.y, foo.z, foo.w
}
@@ -0,0 +1,10 @@
vec2 F0(void);
vec2 F0(void) {
bool l0 = false;
l0 = true;
if (l0) {
return vec2(0.0);
}
return vec2(1.0);
}
+9
View File
@@ -0,0 +1,9 @@
package main
func Foo() vec2 {
x := true
if x {
return vec2(0)
}
return vec2(1)
}
@@ -0,0 +1,11 @@
vec2 F0(void);
vec2 F0(void) {
bool l0 = false;
l0 = true;
if (l0) {
return vec2(0.0);
} else {
return vec2(1.0);
}
}
+10
View File
@@ -0,0 +1,10 @@
package main
func Foo() vec2 {
x := true
if x {
return vec2(0)
} else {
return vec2(1)
}
}
@@ -0,0 +1,14 @@
vec2 F0(in vec2 l0);
vec2 F0(in vec2 l0) {
vec2 l1 = vec2(0);
l1 = vec2(0.0);
{
vec2 l2 = vec2(0);
l2 = vec2(1.0);
if (((l2).x) == (1.0)) {
return l2;
}
}
return l1;
}
+9
View File
@@ -0,0 +1,9 @@
package main
func Foo(x vec2) vec2 {
v := vec2(0)
if v := vec2(1); v.x == 1 {
return v
}
return v
}
@@ -0,0 +1,11 @@
vec2 F0(void);
vec2 F0(void) {
int l0 = 0;
int l1 = 0;
l0 = 0;
l0 = (l0) + (1);
l1 = 1;
l1 = (l1) - (1);
return vec2(float(l0), float(l1));
}
+9
View File
@@ -0,0 +1,9 @@
package main
func Foo() vec2 {
l0 := 0
l0++
l1 := 1
l1--
return vec2(float(l0), float(l1))
}
@@ -0,0 +1,7 @@
float4 F0(in float4 l0);
float4 F0(in float4 l0) {
float4 l1 = 0.0;
l1 = mul(l0, float4x4FromScalar(1.0));
return l1;
}
@@ -0,0 +1,7 @@
vec4 F0(in vec4 l0);
vec4 F0(in vec4 l0) {
vec4 l1 = vec4(0);
l1 = (mat4(1.0)) * (l0);
return l1;
}
@@ -0,0 +1,6 @@
package main
func Foo(v vec4) vec4 {
v2 := mat4(1) * v
return v2
}
@@ -0,0 +1,12 @@
vec4 F0(in vec4 l0);
vec4 F0(in vec4 l0) {
if (true) {
return l0;
}
return l0;
}
void main(void) {
fragColor = F0(gl_FragCoord);
}
@@ -0,0 +1,10 @@
in vec2 A0;
void main(void) {
if (true) {
gl_Position = vec4(A0, 0.0, 1.0);
return;
}
gl_Position = vec4(A0, 0.0, 1.0);
return;
}
+15
View File
@@ -0,0 +1,15 @@
package main
func Vertex(position vec2) vec4 {
if true {
return vec4(position, 0, 1)
}
return vec4(position, 0, 1)
}
func Fragment(position vec4) vec4 {
if true {
return position
}
return position
}
@@ -0,0 +1,13 @@
vec4 F0(in vec4 l0);
vec4 F0(in vec4 l0) {
vec4 l1 = vec4(0);
for (float l2 = 0.0; l2 < 4.0; l2++) {
(l1).x = ((l1).x) + ((l2) * (1.0000000000e-02));
}
return l1;
}
void main(void) {
fragColor = F0(gl_FragCoord);
}
@@ -0,0 +1,10 @@
in vec2 A0;
void main(void) {
vec4 l0 = vec4(0);
for (float l1 = 0.0; l1 < 4.0; l1++) {
(l0).x = ((l0).x) + ((l1) * (1.0000000000e-02));
}
gl_Position = l0;
return;
}
Loaded 100 of 2538 files, more files were not shown because too many files have changed in this diff. Show more