Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(directx): Add do-while loop support to DirectX backend #206

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

MashyBasker
Copy link
Contributor

@MashyBasker MashyBasker commented Oct 17, 2024

PR Description

Implementation details:

  • Added "DO" token in lexer.
  • Implemented DoWhileNode in DirectxAst.py to create do-while node in the AST
  • Added logic to parse do-while statement when "DO" token is read
  • Implemented do-while code generation from CrossGL

Test details:

  • Added parser test for do-while
  • Added code generation test for do-while

Related Issue

Fixes #192

shader Sample

shader main {
    struct VSInput {
        vec4 position @ POSITION;
        vec4 color @ TEXCOORD0;
    }
    struct VSOutput {
        vec4 out_position @ TEXCOORD0;
    }
    struct PSInput {
        vec4 in_position @ TEXCOORD0;
    }
    struct PSOutput {
        vec4 out_color @ gl_FragColor0;
    }
    // Vertex Shader
    vertex {
       VSOutput VSMain(VSInput input )  {
        VSOutput output;
        output.out_position = input.position;
        int i = 0;
        do {
            output.out_position = input.color;
            i =  i + 1;
        } while ( i < 10);
        return  output;
    }

    }

    // Fragment Shader
    fragment {
       PSOutput PSMain(PSInput input )  {
        PSOutput output;
        output.out_color = input.in_position;
        int i = 0;
        do {
            output.out_color = vec4(1.0, 1.0, 1.0, 1.0);
            i =  i + 1;
        } while ( i < 10);
        return  output;
    }

    }

}

The above CrossGL code was generated from the following DirectX code:

struct VSInput {
        float4 position : POSITION;
        float4 color : TEXCOORD0;
    };
    struct VSOutput {
        float4 out_position : TEXCOORD0;
    };
    VSOutput VSMain(VSInput input) {
        VSOutput output;
        output.out_position = input.position;
        int i = 0;
        do {
            output.out_position = input.color;
            i = i + 1;  // Increment the loop variable
        } while (i < 10);
        return output;
    }
    struct PSInput {
        float4 in_position : TEXCOORD0;
    };
    struct PSOutput {
        float4 out_color : SV_TARGET0;
    };
    PSOutput PSMain(PSInput input) {
        PSOutput output;
        output.out_color = input.in_position;
        int i = 0;
        do {
            output.out_color = float4(1.0, 1.0, 1.0, 1.0);
            i = i + 1;  // Increment the loop variable
        } while (i < 10);
        return output;
    }

Checklist

  • Have you added the necessary tests?
  • Only modified the files mentioned in the related issue(s)?
  • Are all tests passing?

Implementation details:

- Added "DO" token in lexer.
- Implemented DoWhileNode in DirectxAst.py to create do-while node in the AST
- Added logic to parse do-while statement when "DO" token is read
- Implemented do-while code generation from CrossGL

Test details:

- Added parser test for do-while
- Added code generation test for do-while

Signed-off-by: Maharshi Basu <[email protected]>
Copy link
Contributor

@samthakur587 samthakur587 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀
great work @MashyBasker thanks for contributing here.

@samthakur587 samthakur587 merged commit 676f901 into CrossGL:main Oct 21, 2024
106 checks passed
@samthakur587 samthakur587 added enhancement New feature or request Directx backend issue at directx backend hacktoberfest labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Directx backend issue at directx backend enhancement New feature or request hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

do-while loop
2 participants