Giter Club home page Giter Club logo

Comments (5)

csyonghe avatar csyonghe commented on May 24, 2024 2

I looked into it and verified that sessionDesc.defaultMatrixLayout is indeed ineffective and fixed that.
Also fixed the typedef issue.

I think the buffer pointer thing is a different issue.

from slang.

Ipotrick avatar Ipotrick commented on May 24, 2024

Correction!
This is actually a buffer pointer bug!
When reading a float3x4 matrix from a buffer pointer by directly dereferencing it, the majorness is respected!
But when reading from the pointer array style it reads it as row major!
Example and repro:

struct Push
{
    float3x4* ptr;
};

[[vk::push_constant]] Push push;
[shader("compute")]
[numthreads(1, 1, 1)]
void main(uint3 dtid : SV_DispatchThreadID)
{    
    // This matrix is in memry column major. Slang respects this here and load it properly!
    float3x4 correctly_read_matrix = *push.ptr;
    printf("(%f,%f,%f,%f)\n(%f,%f,%f,%f)\n",
        correctly_read_matrix[0][0], correctly_read_matrix[0][1], correctly_read_matrix[0][2], correctly_read_matrix[0][3],
        correctly_read_matrix[1][0], correctly_read_matrix[1][1], correctly_read_matrix[1][2], correctly_read_matrix[1][3]
    );
    printf("(%f,%f,%f,%f)\n\n",
        correctly_read_matrix[2][0], correctly_read_matrix[2][1], correctly_read_matrix[2][2], correctly_read_matrix[2][3]
    );
    // With this syntax however, Slang ignores the column major setting and loads it as it it was row major!
    float3x4 broken_matrix = push.ptr[0];
    printf("(%f,%f,%f,%f)\n(%f,%f,%f,%f)\n",
        broken_matrix[0][0], broken_matrix[0][1], broken_matrix[0][2], broken_matrix[0][3],
        broken_matrix[1][0], broken_matrix[1][1], broken_matrix[1][2], broken_matrix[1][3]
    );
    printf("(%f,%f,%f,%f)\n\n",
        broken_matrix[2][0], broken_matrix[2][1], broken_matrix[2][2], broken_matrix[2][3]
    );
}

I wrote the following matrix to a buffer:

buffer_host_ptr =  f32mat3x4{
        // rc = row column
        {11, 21, 31},   // col 1
        {12, 22, 32},   // col 2
        {13, 23, 33},   // col 3
        {14, 24, 34},   // col 4
    };

I get the following output from the minimal repro:

// correct matrix:
(11.000000,12.000000,13.000000,14.000000)
(21.000000,22.000000,23.000000,24.000000)
(31.000000,32.000000,33.000000,34.000000)
// broken matrix:
(11.000000,21.000000,31.000000,12.000000)
(22.000000,32.000000,13.000000,23.000000)
(33.000000,14.000000,24.000000,34.000000)

from slang.

Ipotrick avatar Ipotrick commented on May 24, 2024

Btw, thank you for all the quick fixes. This is very appreciated. I had much worse experience with other shading languages fixing issues.

from slang.

csyonghe avatar csyonghe commented on May 24, 2024

OK, the PR should fix this issue.

from slang.

csyonghe avatar csyonghe commented on May 24, 2024

And thank you for your patience with the compiler so far. The buffer pointer thing and the API around setting compiler options are relatively new and there are still bugs, but we are committed to address any issues quickly.

from slang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.