Code Monkey home page Code Monkey logo

Comments (31)

JCapucho avatar JCapucho commented on August 17, 2024 4

I've tested the provided shaders in this issue and with #898 they are all parsed, validated and emitted successfully, so when it lands I'll close this issue.

from naga.

pjoe avatar pjoe commented on August 17, 2024 2

I'd prefer to have it as a separate step in front of the parser (maybe combined with #include support).

There was 1 or 2 pre-processor implementations suggested already (one is from old glsl-in).

Anyway needs some investigation to figure out how best to do.

from naga.

Napokue avatar Napokue commented on August 17, 2024 2

Thank you for this! I have found the issue, and we always try to set OpName when the debug flag is enabled. As uniform variables can be unnamed, this caused the crash.

However, your shader will still not work yet, as AccessIndex is not yet implemented. I have created a PR yesterday to support AccessIndex and Access expresions, see #224. Should be finished today hopefully, and I expect it to be merged into the main branch soon.

I will use your shader as test data for the SPIR-V back-end.

from naga.

enfipy avatar enfipy commented on August 17, 2024 2

@Napokue Currently, Bevy doesn't use Naga because of luck some main features. But as cart said in this PR Bevy wants to migrate to Naga. Also, there're some forks that added Naga to Bevy.

from naga.

mrk-its avatar mrk-its commented on August 17, 2024 2

Question: is Bevy already using Naga for all their shader compilations or for their examples? If so, it will be a great source of test cases for us to test.

As @enfipy said bevy plans to migrate to naga as soon as possible. In the meantime I'm considering naga for webgl2 rendering backend (and for that I don't need spirv conversion, only parsing / reflection of glsl shaders, especially '#version 300 es')

from naga.

enfipy avatar enfipy commented on August 17, 2024 1

@kvark Thank you for the quick reply!

Here is the GLSL Vertex code:

#version 450

layout(location = 0) in vec3 Vertex_Position;
layout(location = 1) in vec3 Vertex_Normal;
layout(location = 2) in vec2 Vertex_Uv;

layout(location = 0) out vec3 v_Position;
layout(location = 1) out vec3 v_Normal;
layout(location = 2) out vec2 v_Uv;

layout(set = 0, binding = 0) uniform Camera {
    mat4 ViewProj;
};

layout(set = 2, binding = 0) uniform Transform {
    mat4 Model;
};

void main() {
    v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;
    v_Normal = mat3(Model) * Vertex_Normal;
    v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;
    v_Uv = Vertex_Uv;
    gl_Position = ViewProj * vec4(v_Position, 1.0);
}

This is from bevy repository. I think there are some more examples of simple vertex shaders that also don't work.

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

I think the specific issue here is that the uniforms are without a named instance - which I haven't implemented yet. Maybe can change the title to include this info.

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

I think this got closed mistakenly, by me writing partly fixes #210 in a commit msg. I don't think GitHub understood the partly. Feel free to re-open, or file a more specific issue, e.g. about swizzles.

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

@enfipy that error is because of missing swizzle support, working on it - stay tuned :)

about spirv-out, better check with @Napokue

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

FYI: looked up how shader_defs are handled in bevy through glsl_to_spirv.

They are just passed to glslang as cli params with -D <shader_def>. I think this would be equivalent to prepending the source with #define <shader_def> - though I guess the #version still need to be first

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

It will take a bit to implement pre-processor. Meanwhile you can take a look at #132.

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

Dunno, but could be related to #219

from naga.

Napokue avatar Napokue commented on August 17, 2024 1

I will take a look, you use the shader that you have posted at the top of this issue, right?

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

FWIW: the frag shader now parser, when COLORMATERIAL_TEXTURE is not defined. I'll try taking a look at the texture stuff next.

from naga.

pjoe avatar pjoe commented on August 17, 2024 1

After #257, the frag shader now also parses with COLORMATERIAL_TEXTURE.

There is however still some issues with outputting spv from the resulting naga IR.

from naga.

kvark avatar kvark commented on August 17, 2024

GLSL front-end is a work in progress. We actually had 2 different GLSL front-ends, and we decided to remove the older one and proceed with newer one, which was less feature complete. Missing features in it are expected. Please provide the concrete shader so that @pjoe or other folks can make necessary fixes and additions.

from naga.

pjoe avatar pjoe commented on August 17, 2024

Looking some more at the shader, swizzles like .xyz are also missing - need to figure out how to handle those

from naga.

enfipy avatar enfipy commented on August 17, 2024

@pjoe It looks like a new error after your changes: ParseError { kind: SemanticError("Can\'t lookup field on this type") }.

Maybe this is a dumb question but why there are no options in naga for spir-v? It looks like bevy sending some "STANDARDMATERIAL_SHADED" option that was used as CompileOptions for shaderc.

from naga.

kvark avatar kvark commented on August 17, 2024

@enfipy what is STANDARDMATERIAL_SHADED, and how does it relate to SPIR-V?

from naga.

enfipy avatar enfipy commented on August 17, 2024

@kvark I'm not sure about it but I think it's more for .frag - like here (it looks like vars passed to files). And here is the struct with 2 more props. As I understood naga::front::glsl::parse_str can parse 3 shader stages at once - so it's maybe needless for ".vert" or ".comp".

from naga.

pjoe avatar pjoe commented on August 17, 2024

Maybe I don't understand, but looks like normal pre-processor defines to me?

FYI: pre-processor is not yet working in new glsl-in

from naga.

enfipy avatar enfipy commented on August 17, 2024

@pjoe I think yes. Is it hard/time consuming to add preprocessor support with pomelo?

from naga.

enfipy avatar enfipy commented on August 17, 2024

@pjoe Any updates?

from naga.

enfipy avatar enfipy commented on August 17, 2024

@pjoe There is some weird error on SPV backend. I'm using the latest naga commit.

10-04 14:20:36.639 31339 31409 I RustStdoutStderr: RustStdoutStderr: ####### "#version 450\n\nlayout(location = 0) in vec3 Vertex_Position;\nlayout(location = 1) in vec3 Vertex_Normal;\nlayout(location = 2) in vec2 Vertex_Uv;\n\nlayout(location = 0) out vec3 v_Position;\nlayout(location = 1) out vec3 v_Normal;\nlayout(location = 2) out vec2 v_Uv;\n\nlayout(set = 0, binding = 0) uniform Camera {\n    mat4 ViewProj;\n};\n\nlayout(set = 2, binding = 0) uniform Transform {\n    mat4 Model;\n};\n\nvoid main() {\n    v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;\n    v_Normal = mat3(Model) * Vertex_Normal;\n    v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;\n    v_Uv = Vertex_Uv;\n    gl_Position = ViewProj * vec4(v_Position, 1.0);\n}\n"
10-04 14:20:36.645 31339 31409 I RustStdoutStderr: thread 'Compute Task Pool (0)' panicked at 'called `Option::unwrap()` on a `None` value', /Users/enfipy/.cargo/git/checkouts/naga-dbb2b19faed49210/90c56ac/src/back/spv/writer.rs:675:47

I'm not sure that this error linked to the pre-processor.

from naga.

pjoe avatar pjoe commented on August 17, 2024

Maybe @Napokue would know more about this error.

from naga.

enfipy avatar enfipy commented on August 17, 2024

I tried this PR from #219 but nothing changed

from naga.

enfipy avatar enfipy commented on August 17, 2024

@Napokue Yes, and got the error above

from naga.

Napokue avatar Napokue commented on August 17, 2024

Question: is Bevy already using Naga for all their shader compilations or for their examples? If so, it will be a great source of test cases for us to test.

from naga.

mrk-its avatar mrk-its commented on August 17, 2024

Today I was playing with bevy+naga, trying to run simple 2d sprite example. Good news is this vertex shader was parsed:

#version 450

layout(location = 0) in vec3 Vertex_Position;
layout(location = 1) in vec3 Vertex_Normal;
layout(location = 2) in vec2 Vertex_Uv;

layout(location = 0) out vec2 v_Uv;

layout(set = 0, binding = 0) uniform Camera {
    mat4 ViewProj;
};

layout(set = 2, binding = 0) uniform Transform {
    mat4 Model;
};
layout(set = 2, binding = 1) uniform Sprite_size {
    vec2 size;
};

void main() {
    v_Uv = Vertex_Uv;
    vec3 position = Vertex_Position * vec3(size, 1.0);
    gl_Position = ViewProj * Model * vec4(position, 1.0);
}

but if failed on spirv conversion.

Fragment shader failed on parsing - it seems that texture2D and sampler types were not recognized, after commenting it out it failed inside main on texture function call
Fragment shader source:

#version 450

layout(location = 0) in vec2 v_Uv;

layout(location = 0) out vec4 o_Target;

layout(set = 1, binding = 0) uniform ColorMaterial_color {
    vec4 Color;
};

# ifdef COLORMATERIAL_TEXTURE 
layout(set = 1, binding = 1) uniform texture2D ColorMaterial_texture;
layout(set = 1, binding = 2) uniform sampler ColorMaterial_texture_sampler;
# endif

void main() {
    vec4 color = Color;
# ifdef COLORMATERIAL_TEXTURE
    color *= texture(
        sampler2D(ColorMaterial_texture, ColorMaterial_texture_sampler),
        v_Uv);
# endif
    o_Target = color;
}

from naga.

Napokue avatar Napokue commented on August 17, 2024

Yes sorry for my slacking the last couple of weeks, there have been some private matters the last couple of weeks, which led me to having to take some time off from contributing. I think I will be able to pickup the work this week again.

from naga.

pjoe avatar pjoe commented on August 17, 2024

@Napokue: no worries, I also have times where 'life' (day job, family, etc.) gets 'in the way' 😄

from naga.

Related Issues (20)

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.