Code Monkey home page Code Monkey logo

xshade's People

Contributors

bonecrasher avatar vengarioth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

xshade's Issues

Product Types

Syntax proposal : Product Types

Product types to model tuples and units.

examples

a function returning the unit type (empty tuple)

fn main() {
    // implementation
}

a function returning a product type (tuple)

fn main() -> (f32, i32) {
    return (0.0, 1);
}

constructing a product type

this example creates a product type (f32, i32, Foo).

let my_product_type_value = (0.0, 1, Foo::new());

destructuring a product type

both values of the tuple are available as local foo and bar

fn get_foo_bar() -> (Foo, Bar) {
    return (Foo::new(), Bar::new());
}

fn main() {
    let (foo, bar) = get_foo_bar();
}

omitting a value during destructuring

only foo is available since the second value was discarded with the _ operator

fn get_foo_bar() -> (Foo, Bar) {
    return (Foo::new(), Bar::new());
}

fn main() {
    let (foo, _) = get_foo_bar();
}

accessing single values from a product type

let my_product_type_value = (0.0, 1, Foo::new());
let foo = my_product_type_value.2;

Span for BlockDeclaration not properly provided

Feature: Name

parse_function

Summary

Add a short summary.

Each BlockDeclaration has a Span attached to it, which gives the offset, length, line and column of the respective "first character" of the block.
It is default initialized and returned from parsing.

Examples

Give some examples.

//... ],
                                block: BlockDeclaration {
                                    span: Span::new(0, 0, 1, 1),
                                    statements: [
                                        Return(

References

Give some references about research or otherwise relevant information.

Whitepaper

We need to write up a whitepaper describing our goals and non-goals with xshade.

Generate text locations for AST.

We currently use the parser combinator library nom, which doesn't give us spans (text locations) by default. There is one other open source project which uses nom for lexing/parsing: monkey-rust. We should look at how they solve this. We need the spans to give useful compile errors to the user.

New Type Checker: Make TypeEnvironment shared

The old TypeEnvironment was encapsulated inside our SymbolTable for convenience, this lead to an unclear API. We first make the TypeEnvironment shared so old code doesn't break:

invert keyword

Syntax proposal : invert keyword

Summary

Automatically inverts a one-parameter function. This feature can be refined over time, for the start it would be sufficient to only invert simple operations like sin, cos, exp, log or sqrt.

Examples

A conversion function and its inverted variant:

fn main() {
  let to_u = (x) => x * 2.0 - 1.0;
  let from_u = invert to_u;
}

References

TODO

String interning

As talked before, we need a simple string interner. Currently the compiler copies strings all across the place.

Parse errors

Currently the parser returns the smallest valid program, it should provide an error when it's not able to parse the whole input.

Recursion

Recursion is dangerous on the gpu as it quickly leads to diverging executions. It is forbidden in GLSL and HLSL. We will forbid it too and have to make sure the compiler detects it correctly.

import, export & modules syntax

Syntax proposal

We need syntax to make things from other modules accessible. This proposal shows a possible solution.

  • Parser parses import syntax
  • Parser parses export syntax
  • Identifiers in AST need to be replaced with Paths (module path + identifier)
  • Compiler needs to process imported files (once)

implementation

import and export are top-level constructs and cannot exist inside of blocks, however they can be placed at any position within a file. There are no syntax for default exports or imports as this leads to issues when IDEs try to refactor code.

Allowed exports and imports are:

  • Functions
  • Structs

example

index.xs

import { Foo, Bar } from other_module;

struct Foobar {
    x: Foo;
    y: Bar;
}

other_module.xs

struct Foo {
    x: f32,
    y: f32,
}

struct Bar {
    x: f32,
    y: f32,
}

fn doFoo(in: Input) -> Output {
    // ...
}

export { Foo, Bar, doFoo };

export syntax

export a single item

export Foo;

export multiple items

export { Foo, Bar };

import syntax

import a single item

import Foo from bar;

import multiple items

import { Foo, Bar } from bar;

import all

import * from bar;

import from submodules

import * from foo/bar;

file resolution

File resolution is a tricky thing for module systems. How do we resolve the standard library? How do we resolve libraries from a potential package manager?

other module systems

Missing: Assignment statement

Missing: Assignment statement

Summary

We're missing a basic (re-) assignment expression.

Examples

fn test() -> f32 {
    let x = 1.0;
    x = 2.0;
    return x;
}

Loops

Syntax proposal : Loops

Summary

On GPUs loops can quickly cause performance issues by branching or diverging kernels. To avoid such issues xshade limits the power of loop constructs. One of those limitations is the number of iterations needs to be known at compile time.

Examples

for i in 0..16 {
    samples[i] = sample(i);
}

References

  • to be added

testing in shaders

This issue tracks ideas and conversation about posibilities of testing in shaders

Assertions

Often times while developing shaders we want to be sure that our functions return values of a certain range when given input of a certain range, especially when converting from/to uv space into data (we encountered this while implementing procedural sky rendering).

let samples = from_distribution(PlanetHeight, AtmosphereHeight);
let results = samples.map(convert_from_height);
assert_range(results, 0.0, PI);

Where from_distribution returns a list of values within the range of its two parameters, map is your typical mapping function, assert_range asserts that a list of values is within the given range of parameters.

Interpreter

One idea is to build an interpreter for xshade, running xshade code on the CPU.

Compiling into another language, then execute

Another aproach can be to translate xshade code into another CPU language to run the tests.

Try to use compute shaders

It could also be possible to use compute shaders to test xshade code.

Feature: Better Compiler Errors

Feature: Better Compiler Errors

Summary

After all AST nodes have spans we should add nice error messages.

Examples

An example error message.

error: type `vec3` is unknown or not included.
D:\Workspace\xshade\examples\phong.xs:2:15
 1 | struct VertexInput {
 2 |     position: vec3,
   |               ^^^^ unknown type `vec3`
 3 | }
implementations for `vec3` are found in:
* std::vec3 (type alias for `Vector<f32; 3>`)

References

Dependent Types

Syntax proposal : Dependent Types

Summary

Types with terms applied to them.

Examples

A Vector type with type parameter T and term parameter N. N is used to determine the number of components this Vector has. A Vector<f32; 4> for instance is a Vector with 4 components (x, y, z, w), each of type f32.

struct Vector<T; N> {
    values: [T; N],
}

A more extensive example with implementation blocks and limits to types and type terms.

struct Vector<T, N>
    where T: Numeric,
    N <= 4
{
    values: [T; N],
}

impl operator * for Vector<T, 4> {
    #[native_impl] // <- compiler tries to substitute a native implementation instead
    fn mul(self, scalar: T) -> Self {
        // optional implementation
    }

    #[native_impl]
    fn mul(self, other: Self) -> Self {
        // optional implementation
    }

    #[native_impl]
    fn mul(self, other: Matrix<T; 4, 4>) -> Self {
        // optional implementation
    }
}

References

Sum Types

Syntax proposal : Sum Types

Summary

A type representing multiple possible values, like union structs in C, enums in rust. This concept requires pattern matching support from the language to be useful.

This feature should be discussed, as it requires branching which is a bad thing on GPU programs.

Examples

An Option<T> representing the posibility of a value not being present.

enum Option<T> {
    Some(T),
    None,
}

Matching on an Option<T>.

match query_some_api() { 
    Some(my_val) => { //* ... *// },
    None => { //* ... *// },
}

References

Programs

Syntax proposal : Programs

Summary

In the domain of shaders, a program is considered a collection of functions for different shader stages. As a shading language we should implement this concept as a first class citizen.

Stages

The parser should allow for any shader stages, later a program checker (similar to a type checker) should validate that the stage is one of vertex or fragment for now. The syntax is stage <stage name>(<arguments>) { <body> }.

Examples

A shader program with vertex and fragment stages.

program VertexColored {

    stage vertex(in: VertexInput) -> VertexOutput {
        return VertexOutput {
            position: in.position * mvp,
            color: in.color,
        }
    }

    stage fragment(in: VertexOutput) -> vec4 {
        return in.color;
    }
}

References

Precedence in expressions

There is currently no precedence for operations, the parser will parse expressions from right to left (to avoid left recursion). We first need to define precedence for all expressions, then implement it in the compiler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.