Comments (5)
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.
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.
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.
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.
Closing. The examples are fine. Doc needs to be updated which was done ine #4248
from slang.
Related Issues (20)
- Unable to use vectors in initialization list of other vectors HOT 1
- Initializers example in the Slang User Guide does not compile. HOT 1
- Metal: Function return type incorrectly checked when assigning address space
- Incorrect initializers when using interfaces HOT 1
- Variant of `GatherAlpha()` that takes a `status` argument is not supported
- Properly handle the mismatching "mutating" signature for implementing interfaces HOT 1
- Metal: `legalizeArrayReturnType` leads to missing address space for `Out` parameter
- AD Cleanup: Fix inconsistency between `ForwardDerivativeDecoration` and `UserDefinedBackwardDerivativeDecoration`
- Multidimensional `ConstantBuffer` array usage triggers assert
- Will Slang support `using` for type aliasing? HOT 3
- Unable to use `const` in `typedef` statement HOT 3
- Unexpected ambiguous call. HOT 2
- There is no way to emit WGSL HOT 4
- Metal: Opaque type return/inout-param/out-param either infinitely-loops or crashes
- Metal: atomic instructions for buffers HOT 2
- Add Tint as a downstream compiler HOT 3
- Add WGSL as an output target
- Extraneous type conformances causes compiler error. HOT 2
- Metal: Slang does not legalize `[[color(n)]]`/`[[attribute(n)]]` attributes correctly HOT 4
- tests/cpu-program/gfx-smoke.slang fails on local test HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slang.