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 directx backend support for ASSIGN_AND #207

Merged

Conversation

MashyBasker
Copy link
Contributor

PR Description

Implementation details:

  • Add ASSIGN_AND token to lexer
  • Implement ASSIGN_AND parsing in directx parser

Test details:

  • Add parser and codegen tests for ASSIGN_AND
  • Add lexer tests for ASSIGN_AND and ASSIGN_OR

Related Issue

Fixes #185

shader Sample

shader main {
    // Fragment Shader
    fragment {
       PSOutput PSMain(PSInput input )  {
        PSOutput output;
        output.out_color = vec4(0.0, 0.0, 0.0, 1.0);
        if (input.in_position.r > 0.5) {
            output.out_color += input.in_position;
        }
        if (input.in_position.r < 0.5) {
            output.out_color -= vec4(0.1, 0.1, 0.1, 0.1);
        }
        if (input.in_position.g > 0.5) {
            output.out_color *= 2.0;
        }
        if (input.in_position.b > 0.5) {
            out_color /= 2.0;
        }
        if (input.in_position.r == 0.5) {
            uint redValue = asuint(output.out_color.r);
            output.redValue ^= 0 x1;
            output.out_color.r = asfloat( redValue);
            output.redValue |= 0 x2;
            output.redValue &= 0 x3;
        }
        return  output;
    }

    }

}

The above CrossGL code was generated from the following Directx HLSL code

PSOutput PSMain(PSInput input) {
        PSOutput output;
        output.out_color = float4(0.0, 0.0, 0.0, 1.0);

        if (input.in_position.r > 0.5) {
            output.out_color += input.in_position;
        }

        if (input.in_position.r < 0.5) {
            output.out_color -= float4(0.1, 0.1, 0.1, 0.1);
        }

        if (input.in_position.g > 0.5) {
            output.out_color *= 2.0;
        }

        if (input.in_position.b > 0.5) {
            out_color /= 2.0;
        }

        if (input.in_position.r == 0.5) {
            uint redValue = asuint(output.out_color.r);
            output.redValue ^= 0x1;
            output.out_color.r = asfloat(redValue);

            output.redValue |= 0x2;

            output.redValue &= 0x3;

        }

        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:

- Add ASSIGN_AND token to lexer
- Implement ASSIGN_AND parsing in directx parser

Test details:

- Add parser and codegen tests for ASSIGN_AND
- Add lexer tests for ASSIGN_AND and ASSIGN_OR

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 🚀

@samthakur587 samthakur587 added enhancement New feature or request Directx backend issue at directx backend hacktoberfest labels Oct 21, 2024
@samthakur587 samthakur587 merged commit 6ee42fb into CrossGL:main Oct 21, 2024
106 checks passed
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.

ASSIGN_AND : &=
2 participants