cpt-max / Docs

16 stars 0 forks source link

System.IndexOutOfRangeException: Index was outside the bounds of the array when binding buffers #2

Open k4G17eYWI opened 6 months ago

k4G17eYWI commented 6 months ago

Found a bug (as I think)

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Microsoft.Xna.Framework.Graphics.ShaderResourceCollection.SetResourceForBindingSlot(ShaderResource resource, Int32 bindingSlot, Boolean writeAccess, Boolean useSampler, Int32 bindingSlotForCounter)
   at Microsoft.Xna.Framework.Graphics.EffectPass.SetShaderResources(Shader shader, GraphicsDevice device)
   at Microsoft.Xna.Framework.Graphics.EffectPass.ApplyCompute()

Seems that it tries to bind resource on a 9'th slot of 8.

image

But I have less than 8 writable resources even with append counters. In my shader I have:

StructuredBuffer<particle_type> particle_types;
StructuredBuffer<uint> indirect_args;
RWStructuredBuffer<particle> particles;
AppendStructuredBuffer<particle_to_render> render_particles_transparency;
AppendStructuredBuffer<particle_to_render> render_particles_additive;
AppendStructuredBuffer<particle_to_render> render_particles_max;

And if I look into this._writeableResources I see not all the elements set, some have null values.

image

Btw: is there a better place to submit issues? Seems that issues are disabled at https://github.com/cpt-max/MonoGame

k4G17eYWI commented 6 months ago

UPD: Just discowered that if I put my RW-resources before readable resources it manages to work.

This works:

RWStructuredBuffer<particle> particles;
AppendStructuredBuffer<particle_to_render> render_particles_transparency;
AppendStructuredBuffer<particle_to_render> render_particles_additive;
AppendStructuredBuffer<particle_to_render> render_particles_max;

StructuredBuffer<particle_type> particle_types;
StructuredBuffer<uint> indirect_args;

This rises an Exception:

StructuredBuffer<particle_type> particle_types;
StructuredBuffer<uint> indirect_args;

RWStructuredBuffer<particle> particles;
AppendStructuredBuffer<particle_to_render> render_particles_transparency;
AppendStructuredBuffer<particle_to_render> render_particles_additive;
AppendStructuredBuffer<particle_to_render> render_particles_max;

Seems that there is some issues with addition order

cpt-max commented 6 months ago

Oops, I didn't realize issues were disabled on the main repository. It should work now. The binding slots are assigned by ShaderConductor, not sure there is much I can do about that. I guess at the least an error should be generated when compiling the shader.