https://github.com/shader-slang/slang
Revision 384df864fdd2c518924d32295a13894f16295d43 authored by Tim Foley on 02 May 2018, 21:44:13 UTC, committed by GitHub on 02 May 2018, 21:44:13 UTC
This was a known issue in our IR representation, which was now biting a user. The basic problem is that in code like the following: ```hlsl RWStructureBuffer<float4> buffer; ... buffer[index].xz = value; ``` we ideally want to be able to reproduce the original HLSL code exactly, but that requires directly encoding the way that this code writes to two elements of a vector, but not the others. The currently lowering strategy we had produced IR something like: ```hlsl float4 tmp = buffer[index]; tmp.xz = value; buffer[index] = tmp; ``` That transformation might seem valid, but it has some big problems: * It generates UAV reads that are not needed, which could impact performance * It performs read-modify-write operations on memory that the programmer didn't explicitly write, which could create data races The fix here is somewhat obvious: if the "base" of a swizzle operation on a left-hand side resolves to a pointer in our IR, then we can output a "swizzled store" instead of the read-modify-write dance. We currently keep the read-modify-write around since it is potentially needed as a fallback in the general case. Along the way I also tried to make sure that we handle the case where we have a swizzle of a swizzle on the left-hand side: ```hlsl buffer[index].xz.y = value; ``` That code should behave the same as `buffer[index].z = value`. I am currently detecting and cleaning up this logic in the lowering path for `SwizzleExpr`, because that is the only place in the lowering logic that "swizzled l-values" currently get created.
1 parent 60bcc68
Tip revision: 384df864fdd2c518924d32295a13894f16295d43 authored by Tim Foley on 02 May 2018, 21:44:13 UTC
Add support for "swizzled stores" (#544)
Add support for "swizzled stores" (#544)
Tip revision: 384df86
File | Mode | Size |
---|---|---|
build | ||
docs | ||
examples | ||
external | ||
source | ||
tests | ||
tools | ||
.editorconfig | -rw-r--r-- | 937 bytes |
.gitattributes | -rw-r--r-- | 95 bytes |
.gitignore | -rw-r--r-- | 398 bytes |
.gitmodules | -rw-r--r-- | 107 bytes |
.travis.yml | -rw-r--r-- | 1.6 KB |
CODE_OF_CONDUCT.md | -rw-r--r-- | 3.1 KB |
LICENSE | -rw-r--r-- | 1.1 KB |
Makefile | -rw-r--r-- | 6.3 KB |
README.md | -rw-r--r-- | 4.9 KB |
appveyor.yml | -rw-r--r-- | 3.5 KB |
slang.h | -rw-r--r-- | 42.9 KB |
slang.sln | -rw-r--r-- | 9.1 KB |
test.bat | -rw-r--r-- | 1.4 KB |
Computing file changes ...