floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.54k stars 469 forks source link

Mutliple `sg_apply_uniforms` in a pipeline influence other render target #986

Closed pratamabayu closed 5 months ago

pratamabayu commented 5 months ago

Hi @floooh ,

I'm not sure this is bug or not. But i have issue with multiple sg_apply_uniforms when creating multiple render target. I just test on metal.

This's my logic

// render target 1
sg_begin_pass(...);
sg_apply_pipeline(...);
sg_apply_bindings(...);
sg_apply_uniforms(...); // in vertex stage
sg_draw(...);
sg_end_pass();

// render target 2
sg_begin_pass(...);
sg_apply_pipeline(...);
sg_apply_bindings(...);
sg_apply_uniforms(...); // in vertex stage
sg_apply_uniforms(...); // in fragment stage, ub 0
sg_apply_uniforms(...); // in fragment stage, ub 1
sg_draw(...);
sg_end_pass();

// default pass ...

They result clear color only. If I remove the whole of render target 2 code block or sg_apply_uniforms(...); // in fragment stage, ub 0, render target 1 works fine.

This is my UB shade part in render target 2

uniform light_params {

    vec2 halfPixel;
    vec3 cameraPosition;

    vec3 lightDirection;
    vec3 lightColor;
};

uniform transform_params {
    mat4 view;
    mat4 inverseViewProjection;
};

Below is the issue, all render targets just render clear color :

Screenshot 2024-01-29 at 22 03 54

Below is the screenshot when i remove the render target 2 code block or sg_apply_uniforms(...); // in fragment stage, ub 0 :

Screenshot 2024-01-29 at 22 05 00

In my opinion, if my mesh or shader is broken in render target 2. It shouldn't affect render target 1 right?

floooh commented 5 months ago

Do you see any validation layer messages from sokol-gfx or the Metal validation layer?

pratamabayu commented 5 months ago

Unfortunetly, I didn't see anything about sokol-gfx or metal validation output.

floooh commented 5 months ago

Couple more questions:

pratamabayu commented 5 months ago

Oh, my bad. It's my fault. I forgot to get the right pipeline from the cache when rendering offscreen. So this issue just in my framework, the sokol_gfx works well.