Giter Club home page Giter Club logo

Comments (5)

csyonghe avatar csyonghe commented on September 22, 2024

Your repro code, we are taking address of a local variable, and this is not allowed.
We can only accept pointers that are defined as shader parameters (e.g. as a constant buffer field), we can produce pointers using the & operator from something that is not in global memory.

from slang.

csyonghe avatar csyonghe commented on September 22, 2024

In the future, we can extend our legalization passes to properly propagate pointer address space and specialize functions based on the address space of the argument, but this isn't implemented for SPIRV yet.

Our metal backend has logic for propagating and specializing address spaces, and we should generalize that logic to be shared among both spirv and metal backends.

Even when we have the IR pass support, we still want to decide whether or not to expose the ability to take address off a local variable. That usually leads to bad things so my preference is not to allow that.

from slang.

jkwak-work avatar jkwak-work commented on September 22, 2024

Your repro code, we are taking address of a local variable, and this is not allowed. We can only accept pointers that are defined as shader parameters (e.g. as a constant buffer field), we can produce pointers using the & operator from something that is not in global memory.

Thank you for the reply.
Based on your comment, I made some adjustment and it started working.

//TEST(compute, vulkan):SIMPLE(filecheck=SPV): -stage compute -entry computeMain -target spirv -emit-spirv-directly

//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;

struct MyType
{
    float a;
};

float test(MyType* pObj)
{
    MyType* pNext = pObj + 1;
    MyType* pNext2 = &pNext[1];
    return pNext.a + pNext->a + (*pNext2).a + pNext2[0].a;
}

cbuffer Constants
{
    MyType *ptr; // <===== pointers defined as shader parameter
};

[numthreads(1,1,1)]
void computeMain()
{
    outputBuffer[0] = test(ptr);
}

It reminded me that Adam put "limitation" to the document, which I forgot to actually read until now.

  • Slang supports pointers to global memory, but not shared or local memory. For example, it is invalid to define a pointer to a local variable.
  • Coherent load/stores are unsupported
  • Custom alignment specification is unsupported.
  • Slang currently does not support pointers to immutable values, i.e. const T*.

I think we may need to add more to the document to include the information you mentioned.

  • Slang supports pointers that are defined as shader parameters (e.g. as a constant buffer field)
  • Slang can produce pointers using the & operator from something that is not in global memory

One thing that is little unclear to me is about the "not in global memory" part.
That sounds conflict to the other statement, "Slang supports pointers to global memory".
I am guessing, the pointer can point "to" global memory, but we cannot "produce" from global memory?
The repro code, which came from the User Guide, has the following line that produces a pointer,

    MyType* pNext2 = &pNext[1];

Isn't the pointer produced from the global memory?
I think pNext[1] without & is on the global memory because ptr from cbuffer was pointing to a global memory.
And an address is produced from pNext[1], which is a global memory, isn't it?

from slang.

csyonghe avatar csyonghe commented on September 22, 2024

I think you want to say:

Slang can produce pointers using the & operator from things in global memory.

Basically, we have & operator, but the thing after & must be in global memory, and cannot be a local variable.

from slang.

bmillsNV avatar bmillsNV commented on September 22, 2024

Closing. The examples are fine. Doc needs to be updated which was done ine #4248

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.