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

Always add vtable to struct? #5629

Closed
fknfilewalker opened this issue Nov 21, 2024 · 4 comments · Fixed by #5645
Closed

Always add vtable to struct? #5629

fknfilewalker opened this issue Nov 21, 2024 · 4 comments · Fixed by #5645
Assignees
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should

Comments

@fknfilewalker
Copy link
Contributor

fknfilewalker commented Nov 21, 2024

Is there a way to always add a vtable to structs that implement an interface?

When such a type is directly used (without an interface or second type implementing this interface) in some shader this vtable space is often removed. This makes it hard to reuse buffers in cases with and without vtable. Is there an option to always add the vtable for interface implementations?

interface IShape {}

struct Sphere : IShape {
    float radius;
};
struct Cube : IShape {
    float size;
};
StructuredBuffer<IShape> shapes;
// if typeconformance includes Sphere and Cube -> radius/size starts at offset 16 bytes (vtable)
// if typeconformance includes just Sphere -> radius starts at offset 0 bytes (no vtable)

StructuredBuffer<Sphere> spheres;
// radius starts at offset 0 bytes (no vtable)

This makes it really hard to manage the backend buffer of shapes/spheres, would be nice if interface types would always include the vtable.

@csyonghe
Copy link
Collaborator

I think this is a bug and the data layout should be stable by always include the 16byte header.

@bmillsNV bmillsNV added this to the Q4 2024 (Fall) milestone Nov 21, 2024
@bmillsNV bmillsNV added kind:bug something doesn't work like it should goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang labels Nov 21, 2024
@fknfilewalker
Copy link
Contributor Author

Shouldn't Sphere or Cube also have the header (since they implement an Interface), even if their types are used directly?

Right now something like StructuredBuffer<Sphere> does not have the 16 bit header. What if I call a function that wants an IShape with this?

@csyonghe
Copy link
Collaborator

No, concrete types should not have the header. Interface conformance is not the same as inheritance.

when passing a concrete type value to IShape, slang will”box” the value by appending the header, and pass the composite to the callee.

@fknfilewalker
Copy link
Contributor Author

Ok good to know that this will not change, then I will work around that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants