https://bugs.winehq.org/show_bug.cgi?id=54832
--- Comment #4 from Ethan Lee flibitijibibo@gmail.com --- Created attachment 74416 --> https://bugs.winehq.org/attachment.cgi?id=74416 Awful non-const patch that sucks
Attached is a very very bad diff that gets non-const offsets to compile. It fails a bunch of "unrelated" unit tests and is riddled with FIXMEs!
It occurred to me that the HLSL compiler might not support this, but the DXBC parser still could - and it does. So I turned this from a compiler task into more of a reverse-engineering task, and this patch is the result.
The core of this feature lives in the TPF emitter; IR_EXPR needs to take a separate path from IR_CONSTANT, doing a number of _very_ specific things:
1. The register being returned by sm4_register_from_deref should something other than TEMP (in our case, CONSTBUFFER) 2. The index, rather than a literal, is a temp register, which is handed to us via deref->offset.node->reg 3. The index information is shoved at the end of the src info; it's basically a nested src info inside a src info 4. With the nested src info, we need to mark the base src as having an additional order with relative addressing enabled; this also means we have to add the nested src length to the total size of the instruction
The big issues with this patch: - I couldn't figure out where some of the data comes from - a lot of these seems like it should be provided by the hlsl_ir_expr, and I'm sure it's in there _somewhere_, but I wasn't able to find it myself - The change to existing tokens is a mess - grep "has_deref" and try not to bleed too much afterward - The added fields to sm4_register seems to have introduced some uninitialized memory issues, which is what I'm guessing is causing all the broken tests (has_deref, as ugly as it is, is there to try and isolate the ugliness to this one specific bit of input data)
I got a whole lot further than I expected, but I still think this will need a maintainer's touch to get all the details right.