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

performing layout generation after linking causes non local structs to have no layout information #6437

Closed
expipiplus1 opened this issue Feb 24, 2025 · 1 comment · Fixed by #6450

Comments

@expipiplus1
Copy link
Collaborator

Consider the following

main.slang:

public interface IFoo
{
    public float4 getFoo();
};
public extern struct S : IFoo;

[shader("vertex")]
float4 vs_main(S params) : SV_Position
{
    return params.getFoo();
}

foo.slang:

import main;

export public struct S : IFoo
{
    public float4 getFoo() { return this.foo; }

    float4 foo;
}

When these are compiled and linked, we generate the layout information for S before linking with the definition of S in foo.slang

This is the diff between a good version, in which the definition for S is available, and the bad version above. Observe how the details of the struct layout are missign

11161,11164c11111
< let  %10        : Void  = varLayout(%11, %12, %6)
< let  %11        : Void  = structTypeLayout(%13, %14)
< let  %14        : Void  = fieldLayout(%foo, %15)
< let  %15        : Void  = varLayout(%16, %12, %6)
---
> let  %10        : Void  = varLayout(%11, %6)
11166,11168c11113
< let  %12        : Void  = offset(5 : Int, 0 : Int)
< let  %16        : Void  = typeLayout(%13)
< let  %13        : Void  = size(5 : Int, 1 : Int)
---
> let  %11        : Void  = structTypeLayout
11190c11135
< let  %17        : rtti_type     = rtti_object(%S)
---
> let  %12        : rtti_type     = rtti_object(%S)
11199c11144
< block %18(
---
> block %13(
11202,11203c11147,11148
<         let  %19        : Vec(Float, 4 : Int)   = get_field(%this, %foo)
<         return_val(%19)
---
>         let  %14        : Vec(Float, 4 : Int)   = get_field(%this, %foo)
>         return_val(%14)
11213c11158
< block %20(
---
> block %15(
11217,11219c11162,11164
<         let  %21        : %S    = load(%params)
<         let  %22        : Vec(Float, 4 : Int)   = call %Sx5FgetFoo(%21)
<         return_val(%22)
---
>         let  %16        : %S    = load(%params)
>         let  %17        : Vec(Float, 4 : Int)   = call %Sx5FgetFoo(%16)
>         return_val(%17)
11222,11243c11167
< #version 450
< layout(row_major) uniform;
< layout(row_major) buffer;
< struct S_0
< {
<     vec4 foo_0;
< };
<
< vec4 S_getFoo_0(S_0 this_0)
< {
<     return this_0.foo_0;
< }
<
< layout(location = 0)
< in vec4 params_foo_0;
<
< void main()
< {
<     S_0 _S1 = { params_foo_0 };
<     gl_Position = S_getFoo_0(_S1);
<     return;
< }
---
> (0): error 99999: Slang compilation aborted due to an exception of N5Slang13InternalErrorE: assert failure: structTypeLayout->getFieldCount() == structFieldCount
expipiplus1 added a commit to expipiplus1/slang that referenced this issue Feb 25, 2025

Verified

This commit was signed with the committer’s verified signature.
expipiplus1 Ellie Hermaszewska
expipiplus1 added a commit to expipiplus1/slang that referenced this issue Feb 25, 2025

Verified

This commit was signed with the committer’s verified signature.
expipiplus1 Ellie Hermaszewska
expipiplus1 added a commit to expipiplus1/slang that referenced this issue Feb 26, 2025

Verified

This commit was signed with the committer’s verified signature.
expipiplus1 Ellie Hermaszewska
expipiplus1 added a commit to expipiplus1/slang that referenced this issue Feb 26, 2025

Verified

This commit was signed with the committer’s verified signature.
expipiplus1 Ellie Hermaszewska
expipiplus1 added a commit to expipiplus1/slang that referenced this issue Feb 26, 2025

Verified

This commit was signed with the committer’s verified signature.
expipiplus1 Ellie Hermaszewska
expipiplus1 added a commit to expipiplus1/slang that referenced this issue Feb 26, 2025

Verified

This commit was signed with the committer’s verified signature.
expipiplus1 Ellie Hermaszewska
@bmillsNV
Copy link
Collaborator

Closing this. It's the root cause of #5994

csyonghe added a commit that referenced this issue Feb 28, 2025

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
* Resolve 'extern' types during type layout generation if possible

Closes #5994
Closes #6437

* format code

---------

Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Yong He <yonghe@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants