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

Converting ShaderGen to work as a Roslyn Source Generator #107

Open
ScottKane opened this issue Dec 16, 2022 · 0 comments
Open

Converting ShaderGen to work as a Roslyn Source Generator #107

ScottKane opened this issue Dec 16, 2022 · 0 comments

Comments

@ScottKane
Copy link

I am trying to strip all of the build functionality of ShaderGen into a source generator that can produce SPIR-V byte code at compile time for a ShaderGen shader.

I have created this small project to test if I can get the backend code to generate: https://github.com/ScottKane/ShaderGenTest

For some reason the following code doesn't produce any shader sets:

var hlsl      = new HlslBackend(compilation);
var glsl330   = new Glsl330Backend(compilation);
var glsles300 = new GlslEs300Backend(compilation);
var glsl450   = new Glsl450Backend(compilation);
var metal     = new MetalBackend(compilation);

var languages = new LanguageBackend[]
{
    hlsl,
    glsl330,
    glsles300,
    glsl450,
    metal,
};
    
var generator = new ShaderGen.ShaderGenerator(compilation, languages);
var result    = generator.GenerateShaders();

foreach (var language in languages)
{
    var extension = BackendExtension(language);
    var sets      = result.GetOutput(language);

    foreach (var set in sets)
    {
        var name = set.Name;
        if (set.VertexShaderCode != null)
        {
            name = name + "-vertex." + extension;
            c.AddSource(name, ToCommented(set.VertexShaderCode));
        }
        if (set.FragmentShaderCode != null)
        {
            name = name + "-fragment." + extension;
            c.AddSource(name, ToCommented(set.FragmentShaderCode));
        }
        if (set.ComputeShaderCode != null)
        {
            name = name + "-compute." + extension;
            c.AddSource(name, ToCommented(set.ComputeShaderCode));
        }
    }
}

@mellinoe If you have any capacity to take a quick look, any help would be greatly appreciated. The DebugRoslynComponent run profile should allow you to debug the generator to see what's going on if you run it from Visual Studio (Rider doesn't support debugging roslyn components yet).

I think if I can get this working as a generator it could breathe new life into the project.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant