-
Notifications
You must be signed in to change notification settings - Fork 713
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
[Feature Request] Ability to use [vk::ext_reference]
attribute on any function (not just inline SPIR-V) argument to indicate to treat is a reference
#5675
Comments
[vk::ext_reference]
attribute on any function argument to indicate to treat is a reference[vk::ext_reference]
attribute on any function (not just inline SPIR-V) argument to indicate to treat is a reference
Sounds good we will try to not remove this functionality. To make sure we do not, we need to add a test. Once we add a test, we can consider this closed. |
Below is a full test for what I expect is wanted. It does not currently pass. The However, this is out of scope for what was expected from vk::ext_reference originally. The fact that it was silently ignored instead of giving an error is more of an oversight. From the initial description, I thought that
|
we can assign someone and implement it |
Actually there's another thing I noticed I can do which is pretty nasty struct PSInput
{
float4 position : SV_Position;
float4 color : COLOR0;
};
namespace impl
{
template<typename T>
struct declval
{
static declval<T> create()
{
return declval<T>();
}
// must be an array, otherwise __decltype doesn't turn into a reference!
T member[1];
};
}
template<typename T>
struct add_lvalue_reference
{
using type = __decltype(impl::declval<T>::create().member[0]);
};
void SetRef(add_lvalue_reference<float>::type t)
{
t = 9.f;
}
float4 PSMain(PSInput input) : SV_Target0
{
float b = 6.f;
SetRef(b);
return input.color * float(b);
} Neither SPIR-V or DXIL output know what to do with a reference type though. But its useful enough to template on (type_traits), so things like |
I'm actualy trying to implement this with Proposal 0011 #6578 |
I'm going to close this, but I'd appreciate #6578 getting reopened because there's no way to "link up" the inline SPIR-V A And because Note: a |
I'm unsure whether this should be opened here or in https://github.com/microsoft/hlsl-specs because the attribute already exists and can be applied to any function argument without the compiler complaining (no diagnostics emitted).
Is your feature request related to a problem? Please describe.
Unless something changed w.r.t
vk::ext_reference
in microsoft/hlsl-specs#59 then after the merge of #5249 it will become impossible for me to implement certain load types and atomics if I want to "default" certain OpCode operands, for example.Currently it works beautifully on
RWStructuredBuffer
( https://godbolt.org/z/1j3hczKcT ),groupshared
( https://godbolt.org/z/9qso3Y7eW ) and might even work with the new current implementation of BDA withvk::BufferPointer<T,A>::Get()
.However this relies on
inout
working as a reference, which is a bug (is contrary to the HLSL spec, and this will be fixed in #5249).One that behaviour of
inout
goes away, the only way to achieve this is to replace any function in the call chain with a Preprocessor Macro Function which copy-pastes a scope with block of code. This brings us back to the feature parity with GLSL as:return
within the macro (would need to wrap it in a weirddo-while(false)
and usecontinue
instead ofreturn
)TL;DR Its possible to work around, but leads to completely unmaintainable code.
This is especially important for things like atomic operations and atomic load/store which depending on the Vulkan environment you're targetting (with or without Vulkan Memory Model) you'd want to differentiate and "hide"/default some of the
ext_literal
operands.Other DXC users have ran into this before ( #5077 ) when attempting to shim GLSL-compatible code, albeit without SPIR-V intrinsics like I'm doing.
Describe the solution you'd like
The ability to mark arguments in the the non-intrinsic functions (i.e.
volatile_load
and `` in the examples above).Describe alternatives you've considered
Waiting for HLSL proposal 0006 to go under review, get approved, implemented in DXC.
Additional context
Currently
inout
works like a reference "by accident" but this behaviour will go away after #5377 gets merged.Actually Alexander Sannikov @Raikiri (working on Path of Exile) mentioned to me that they were "considering writing our code generator that automatically inlines all our shader functions before compiling them, just to avoid relying on inout being sane" and his definition of "sane" was for
inout
to act as a reference.However as we know both HLSL and GLSL use "value return" calling conventions and
inout
is specified to be exactly "copy-in copy-out".From my limited knowledge and investigations, it does seem that as long as spirv-opt and DXC's own DXIL opimizers work properly and after optimization (inlining and temporary store elimination) a true reference vs "copy-in copy-out" shouldn't differ at all in code emitted... unless we're dealing with temporal effects like volatile reads/writes and atomics.
However my example & problem clearly demonstrate the need for references and atomic/volatile access.
This touches microsoft/hlsl-specs#83
The text was updated successfully, but these errors were encountered: