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

Access Interface through pointer #5677

Closed
fknfilewalker opened this issue Nov 25, 2024 · 5 comments · Fixed by #5793
Closed

Access Interface through pointer #5677

fknfilewalker opened this issue Nov 25, 2024 · 5 comments · Fixed by #5793
Assignees
Labels
goal:client support Feature or fix needed for a current slang user.

Comments

@fknfilewalker
Copy link
Contributor

It is possible to access an Interface through a StructuredBuffer, though it is not possible to do this through a pointer.

interface ITest {};
// works
StructuredBuffer<ITest> buffer;

// does not work
[[vk::push_constant]] ITest* pc;

// also does not work 
struct MyData {
    ITest* ptr;
};
StructuredBuffer<MyData> data;

There should not really be a big difference between these usecases, so I hope this can be allowed soon.

@bmillsNV bmillsNV added this to the Q4 2024 (Fall) milestone Nov 26, 2024
@bmillsNV bmillsNV added the goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang label Nov 26, 2024
@jkwak-work
Copy link
Collaborator

The following two codes are not same,

// Passes "ITest" not pointer value
StructuredBuffer<ITest> buffer;

struct MyData {
   // Passes a pointer value not ITest
    ITest* ptr;
};
StructuredBuffer<MyData> data;

In order to be same, it should be either one of the followings.

StructuredBuffer<ITest*> buffer;
struct MyData {
    ITest* ptr;
};
StructuredBuffer<MyData> data;

or

StructuredBuffer<ITest> buffer;
struct MyData {
    ITest ptr;
};
StructuredBuffer<MyData> data;

The first case, however, is not supported.
The second case doesn't yield errors for me, although I am not sure if that's what you want to do.

@fknfilewalker
Copy link
Contributor Author

fknfilewalker commented Nov 27, 2024

Ok I see. I guess this example was wrong then.

My goal is to be able to access an Interface just via an address.
so something like

struct MyData {
    ITest* ptr;
};
StructuredBuffer<MyData> data;

or

[[vk::push_constant]] ITest* pc;

@jkwak-work
Copy link
Collaborator

I think what you want to do is "Link-time type" described in the Slang User's document.
Or you can also find more details in a new coming document

The reason why I said it is that interface already does the dynamic dispatching at runtime.
I don't see why you want to have double indirection with an extra pointer.

@fknfilewalker
Copy link
Contributor Author

I don't think so, the main point is really to allow to access a buffer that contains interface implementations through a pointer.

struct Mesh {
    // some data
    IMaterial* material;
};
StructuredBuffer<Mesh> meshes;

In this example this would allow to bundle the material with the mesh data

// like so
meshes[0].material.foo()

// instead of
StructuredBuffer<IMaterial> materials;
materials[meshes[0].material_idx].foo()

@fknfilewalker
Copy link
Contributor Author

fknfilewalker commented Dec 2, 2024

doing something like this crashes the compiler without any warnings or errors.

struct Input {
    Ptr<uint8_t> sensors;
}
[[vk::push_constant]] Input pc;

[shader("vertex")]
float4 vertexMain(uint vid : SV_VertexID, uint iid : SV_InstanceID) : SV_Position
{
    let sensor = Ptr<ISensor>(pc.sensors);
    return sensor.splat(float4(1.0))
}

@bmillsNV bmillsNV added goal:client support Feature or fix needed for a current slang user. and removed goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang labels Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Feature or fix needed for a current slang user.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants