Comments (5)
The slow compile time is a product of a known bug in LLVM 3.7 where propagation of alias analysis information is really slow. Fixing that bug is not easy. The fixes that went into LLVM 4.0 are massive and complicated which makes it not feasible to backport them to DXC.
As to why you see this with an inout
parameter but not the implicit this
parameter, that is how HLSL is defined. In HLSL function parameters are always passed with value semantics. For inout
parameters that means it is copied in and copied back out. We are tracking a feature proposal to add references in the future, but that change is not coming soon due to technical debt in DXC. You don't see this problem with member functions because the implicit object parameter (this
) is defined to be a true reference, so it isn't copied in and out.
LLVM can generally optimize away the copies at the cost of compile time. Your example here is demonstrating a case where LLVM 3.7 is clearly failing to fully optimize away the copies. This is caused by the loop unroll limit being set to 50. If the size is <50 we optimize it away if it is >50 we don't. You can see a succinct demonstration of that here.
With a slight change to your code to add the [unroll]
attribute before the loop the compiler can handle any size loop as demonstrated here. This does come at a cost of compile time due to the aforementioned bug in alias analysis.
from directxshadercompiler.
We could try a timeboxed investigation into removing the propagation of alias information during inlining, with understanding that the alias analysis will need to be recomputed, but that might be a net win if it avoids this performance cliff.
from directxshadercompiler.
Thank you for the explanation.
That makes a lot of sense.
And I am fine with closing the issue unless you guys want to do more with it.
from directxshadercompiler.
Allowing general references in user code, especially in return values may not be a good idea as it opens up ability to do arbitrary pointer logic in arbitrary memory space, which can be a big can of worms on its own (e.g. passing l-values from buffers, textures, local or global variables to f(a, b)
that may return either a
or b
, and now the address space of your return reference is no longer compile time determinable). It is a lot of work, creates a lot of issues, and has little return.
Instead, given how DXC internally lowers member methods to LLVM, I wonder if it is possible for hlsl to accept something more ligthweight than full references, by just allowing by-ref parameter passing like:
void memberMethod(__ref MyType this) { ... }
from directxshadercompiler.
Allowing general references in user code, especially in return values may not be a good idea as it opens up ability to do arbitrary pointer logic in arbitrary memory space, which can be a big can of worms on its own (e.g. passing l-values from buffers, textures, local or global variables to
f(a, b)
that may return eithera
orb
, and now the address space of your return reference is no longer compile time determinable). It is a lot of work, creates a lot of issues, and has little return.
This is kinda out-of-scope for an issue discussion, but I disagree. Introducing references to the language also requires supporting explicit address space annotations because casing addresses between address spaces needs to be illegal (something we kinda gloss over today in DXC's ASTs). This also will allow us to fix some of the places in the language where we require addresses but don't actually have a way to represent the address or address space.
Instead, given how DXC internally lowers member methods to LLVM, I wonder if it is possible for hlsl to accept something more ligthweight than full references, by just allowing by-ref parameter passing like:
void memberMethod(__ref MyType this) { ... }
I don't see how this solves the problem. Spelling it as __ref
doesn't solve any complication over just spelling it as MyType&
. We have an explicit goal not to introduce syntax that diverges from C/C++ unless there is a really good reason.
The way DXC handles references today is really really broken (especially for the implicit this
object). In most cases we ignore address spaces entirely and just hope the IR optimizer cleans it all up by illegally converting pointer types.
I haven't yet spec'd all the details, but my proposal is to add explicit address space annotations for device
(1), constant
(2) and node
(6) as well as utilities to create explicit temporary expiring references that behave like inout
to map from a non-thread address to a thread address.
It will also be possible to use templates to instantiate per-address-space variants of functions if users wish to avoid copies and not need to duplicate functions by address space.
from directxshadercompiler.
Related Issues (20)
- Erroneous gradients warning when indexing to an array of textures HOT 2
- ftime-trace flag is not respected by the `DxcCompiler3` interface
- [Bug] segfault when using clip
- [Optimization] DXC is missing common factor optimization in some cases
- [Feature Request] Clearer error output when you pass a temporary object into an inout parameter HOT 1
- Typo of register -> registers crashes DXC with segfault HOT 2
- [SPIR-V] Implement WaveMutliPrefix* intrinsic support
- [SPIR-V][Feature Request][SM6.7] Implement GatherRaw in the SPIR-V backend
- [SPIR-V][Feature Request][SM6.7] Implement texture sample/load with a non-constant offset
- [SPIR-V][Feature Request][SM6.7] Implement SampleCmpLevel
- [SPIR-V][Feature Request][SM6.5] Add support for FeedbackTexture2D HOT 2
- DXASSERT condition for failed template specialization needs amending
- [SPIR-V] Address "unsupported" tests
- Attempting to pass a texture in the AS->MS payload struct causes crash HOT 1
- [SPIR-V] Static class member initializer not implemented
- Segfault when trying to use hull shader as lib.
- Missing validation error on DS compilation with no patch constant signature
- Resources in groupshared memory causes internal compiler error
- QuadReadAcross(bool) Fails to Compile HOT 5
- [SPIR-V] Hitting max ID bound
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 directxshadercompiler.