Code Monkey home page Code Monkey logo

Comments (6)

Mike-Leo-Smith avatar Mike-Leo-Smith commented on September 21, 2024

Hi, @swfly

Thanks for reporting this. I tried to fix the alignment issue with vector3 arrays in the DX backend in 38abe63, which should now pass the test code you provided.

For other alignment issues with structures,

Actually I think it's not only a problem of using array in this structure. In my actual code I have a camera struct to pass to kernels and it apparently has alignment problem even without arrays.

Would you please provide the struct that causes the problem? Thanks!

from luisacompute.

swfly avatar swfly commented on September 21, 2024

Hi @Mike-Leo-Smith, great work yes it solves the problem!
For another case I just tested and still buggy... In the following code I just use the a similar struct with an extra bool variable instead, and it breaks the alignment immediately. When I saw the generated hlsl with ":8" I can feel the risk there (maybe I was wrong tho)!

#include <luisa-compute.h>
#include <dsl/sugar.h>

using namespace luisa;
using namespace luisa::compute;

struct foo
{
    bool bar = false;
    luisa::float3 test1 = { 0,0,0 };
};
LUISA_STRUCT(foo, bar, test1) {};

int main(int args, char* argv[])
{
    std::vector<std::array<uint8_t, 4u>> download_image(1280 * 720);
    {
        Context context{ argv[0] };
        auto device = context.create_device("dx");
        auto stream = device.create_stream();
        auto device_image = device.create_image<float>(PixelStorage::BYTE4, 1280, 720, 0u);

        Kernel2D fill_image_kernel = [&](Var<foo> bar) noexcept
        {
            Var coord = dispatch_id().xy();
            device_image.write(coord, make_float4(bar.test1, 1.f));
        };
        auto fill_image = device.compile(fill_image_kernel);

        foo b;
        b.test1 = { 0,1,0 };

        stream
            << fill_image(b).dispatch(1280, 720)
            << device_image.copy_to(download_image.data())
            << synchronize();// Step 5: Synchronize the stream
    }

    Window window{ "Display", uint2{ 1280,720 } };
    window.set_key_callback([&](int key, int action) noexcept
    {
        if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
        {
            window.set_should_close();
        }
    });
    auto frame_count = 0u;
    window.run([&]
    {
        window.set_background(download_image.data(), uint2{ 1280,720 });
    });
}

I think by looking at your mentioned commit I should be able to fix this myself since the problems look similar. But you are a lot more familiar with luisa, so if you happen to have time to fix, it'll be the best.

from luisacompute.

Mike-Leo-Smith avatar Mike-Leo-Smith commented on September 21, 2024

so if you happen to have time to fix, it'll be the best.

OK! I'll look into this.

from luisacompute.

Mike-Leo-Smith avatar Mike-Leo-Smith commented on September 21, 2024

Hi, @swfly

I think I've fixed the struct padding bug with bool members in 35b8ef6. Would you please verify if it now works with your structures?

from luisacompute.

swfly avatar swfly commented on September 21, 2024

Thanks @Mike-Leo-Smith
Now my camera struct finally works and I don't need to use any workaround anymore. Let's close this issue.

from luisacompute.

Mike-Leo-Smith avatar Mike-Leo-Smith commented on September 21, 2024

Great!

from luisacompute.

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.