[v2 1/2] d3dx9: Support relative addressing in preshader.

Paul Gofman gofmanp at gmail.com
Mon Apr 3 12:50:55 CDT 2017


On 04/03/2017 06:35 PM, Matteo Bruni wrote:
> 2017-03-29 20:17 GMT+02:00 Matteo Bruni <matteo.mystral at gmail.com>:
>> Yeah and temporaries are supposed to be written before being read so
>> in theory you can entirely skip the update_table_size() calls for
>> source arguments.
> I haven't looked in detail but this still works for me (i.e.
> commenting out those calls doesn't break the tests here, on 32 bits at
> least). How does the accidental CTAB overwriting you mention happen
> exactly?
     Yes, if to just comment out it won't break any test, it will break 
that one though if you replace table update with input operand offset 
range check with failure return (after moving table size update from 
input parameters above the loop of course, otherwise it will break many 
tests).
     I actually spotted the accidental CTAB overwrite before that by 
watching warn/trace output of tests and investigating why there are 
'uninitialized input' warnings on preshader operations testing, and had 
in mind to fix this test at some point. Overwriting happens in 
test_preshader_op() function for 2 argumemts op case. The function 
thinks there are 4 per-component operations (which is the case in test 
blob for 1 argument test preshader but actually not the case for 2 
argument preshader blob), and puts opcode there, while the last opcode 
fall after the actual end of preshader code to the CTAB of the next 
preshader.
     I agree that this part with table size update based on input 
operands actual offset looks a bit ugly and can be most likely made 
better. I just suspect that the better solution which won't break 
anything that can work now same as native needs a bit more investigation 
of how native code handles out of bound access in this case. Just 
dropping it without failing will lead to crash or undefined behaviour if 
index register's offset is out of bound now (which should not normally 
happen in my current understanding though without broken bytecode, as 
well as the need to update table size based on input operands as well). 
This of course can be mitigated by also checking index register offsets 
at runtime (now the check done for value register offsets only which can 
now include index register value), but I am not sure that moving this 
extra check to execution time is much nicer. So maybe this improvement 
can wait until we get all the remaining major pieces in place (that 
pieces are, in my understanding, are state manager support and effect 
pools/shared parameters, which make d3dx9 effect framework usable with 
the majority of applications)? Or a simple solution is to fix the test 
and add the checks instead of table update, ignoring compatibility with 
native behaviour for such cases, which we consider possible on broken 
bytecode only, at least based on what I've tested so far.

>> Hmm, I've never seen any effect with a number of immediates not
>> multiple of 4. Can you point me to one?
> Do you have one of those?
     I somehow was sure that there are such cases in our present tests, 
though could not find them now. I pretty sure I saw the values of '6' as 
immediate constant table size, maybe they were present in some previous 
versions of blobs when there was less immediate constants used in 
relative addressing test, or during my extensive testing of out of 
bounds indexes. Anyway, I found such a case (18 immediate constants) in 
one of real apps I am also testing this on, I am attaching a text file 
with that preshader dump (it also has an immediate constants count 
display which I temporary added to the preshader dump code, the same way 
you do in your patch, without the values dump though).

-------------- next part --------------
trace:d3dx:dump_bytecode 0xffff0300,0x00ccfffe,0x42415443,0x0000001c,0x000002f9,0xffff0300,0x0000000f,0x0000001c,
trace:d3dx:dump_bytecode 0x20000000,0x000002f2,0x00000148,0x000a0002,0x00000001,0x00000154,0x00000164,0x00000174,
trace:d3dx:dump_bytecode 0x00090002,0x00000001,0x00000154,0x0000018c,0x0000019c,0x00080002,0x00000001,0x000001b0,
trace:d3dx:dump_bytecode 0x0000018c,0x000001c0,0x00030002,0x00000001,0x000001d4,0x00000164,0x000001e4,0x00000003,
trace:d3dx:dump_bytecode 0x00020001,0x000001f8,0x00000000,0x00000208,0x00050003,0x00160001,0x00000220,0x00000000,
trace:d3dx:dump_bytecode 0x00000230,0x00030003,0x000e0001,0x000001f8,0x00000000,0x00000240,0x00070003,0x001e0001,
trace:d3dx:dump_bytecode 0x000001f8,0x00000000,0x00000257,0x00060003,0x001a0001,0x000001f8,0x00000000,0x00000273,
trace:d3dx:dump_bytecode 0x000a0003,0x002a0001,0x000001f8,0x00000000,0x00000287,0x00050002,0x00000001,0x00000154,
trace:d3dx:dump_bytecode 0x0000018c,0x0000029f,0x00070002,0x00000001,0x00000154,0x00000164,0x000002b2,0x00040002,
trace:d3dx:dump_bytecode 0x00000001,0x00000154,0x0000018c,0x000002c6,0x00060002,0x00000001,0x00000154,0x00000164,
trace:d3dx:dump_bytecode 0x000002de,0x00010003,0x00060001,0x000001f8,0x00000000,0x68706c41,0x66655261,0xababab00,
trace:d3dx:dump_bytecode 0x00030000,0x00010001,0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
trace:d3dx:dump_bytecode 0x66666944,0x54657375,0x75747865,0x6c416572,0x4d616870,0xab007861,0x3f800000,0x00000000,
trace:d3dx:dump_bytecode 0x00000000,0x00000000,0x68706c61,0x42734161,0x6d6f6f6c,0x756f6d41,0xab00746e,0x00030001,
trace:d3dx:dump_bytecode 0x00020001,0x00000001,0x00000000,0x66666964,0x4c657375,0x74686769,0x6f6c6f43,0xabab0072,
trace:d3dx:dump_bytecode 0x00030001,0x00040001,0x00000001,0x00000000,0x66666964,0x4d657375,0x61537061,0x656c706d,
trace:d3dx:dump_bytecode 0xabab0072,0x000c0004,0x00010001,0x00000001,0x00000000,0x69766e65,0x6d6e6f72,0x4d746e65,
trace:d3dx:dump_bytecode 0x61537061,0x656c706d,0xabab0072,0x000e0004,0x00010001,0x00000001,0x00000000,0x736f6c67,
trace:d3dx:dump_bytecode 0x70614d73,0x706d6153,0x0072656c,0x6867696c,0x6c614674,0x66666f6c,0x5370614d,0x6c706d61,
trace:d3dx:dump_bytecode 0x6c007265,0x74686769,0x756c6c49,0x616e696d,0x6e6f6974,0x5370614d,0x6c706d61,0x72007265,
trace:d3dx:dump_bytecode 0x4c706d61,0x74686769,0x5370614d,0x6c706d61,0x72007265,0x656c6665,0x6f697463,0x756c426e,
trace:d3dx:dump_bytecode 0x746e4972,0x69736e65,0x72007974,0x656c6665,0x6f697463,0x6e6f436e,0x73617274,0x65720074,
trace:d3dx:dump_bytecode 0x63656c66,0x6e6f6974,0x65746e49,0x7469736e,0x65720079,0x63656c66,0x6e6f6974,0x63657053,
trace:d3dx:dump_bytecode 0x6c666e49,0x636e6575,0x6f720065,0x69746174,0x614d6e6f,0x61533170,0x656c706d,0x73700072,
trace:d3dx:dump_bytecode 0x305f335f,0x63694d00,0x6f736f72,0x28207466,0x48202952,0x204c534c,0x64616853,0x43207265,
trace:d3dx:dump_bytecode 0x69706d6f,0x2072656c,0x33322e39,0x3934392e,0x3733322e,0xabab0038,0x00f1fffe,0x53455250,
trace:d3dx:dump_bytecode 0x46580201,0x0044fffe,0x42415443,0x0000001c,0x000000db,0x46580201,0x00000003,0x0000001c,
trace:d3dx:dump_bytecode 0x20000100,0x000000d8,0x00000058,0x00020002,0x00000001,0x00000070,0x00000080,0x00000090,
trace:d3dx:dump_bytecode 0x00010002,0x00000001,0x000000a4,0x00000080,0x000000b4,0x00000002,0x00000001,0x000000a4,
trace:d3dx:dump_bytecode 0x000000c8,0x66666964,0x46657375,0x4374616c,0x726f6c6f,0x706f7250,0xababab00,0x00030001,
trace:d3dx:dump_bytecode 0x00040001,0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x6c666572,
trace:d3dx:dump_bytecode 0x69746365,0x6f436e6f,0x6172746e,0xab007473,0x00030000,0x00010001,0x00000001,0x00000000,
trace:d3dx:dump_bytecode 0x6c666572,0x69746365,0x6e496e6f,0x736e6574,0x00797469,0x3f800000,0x00000000,0x00000000,
trace:d3dx:dump_bytecode 0x00000000,0x4d007874,0x6f726369,0x74666f73,0x29522820,0x534c4820,0x6853204c,0x72656461,
trace:d3dx:dump_bytecode 0x6d6f4320,0x656c6970,0x2e392072,0x392e3332,0x322e3934,0x00383733,0x000cfffe,0x49535250,
trace:d3dx:dump_bytecode 0x00000000,0x00000000,0x00000000,0x00000003,0x00000000,0x00000000,0x00000001,0x00000000,
trace:d3dx:dump_bytecode 0x00000003,0x00000000,0x00000000,0x0022fffe,0x54494c43,0x00000010,0x00000000,0x00000000,
trace:d3dx:dump_bytecode 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
trace:d3dx:dump_bytecode 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
trace:d3dx:dump_bytecode 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xdb8bac71,0x3ff00068,
trace:d3dx:dump_bytecode 0x00000000,0x00000000,0x00000000,0xbff00000,0x00000000,0x3ff00000,0x0078fffe,0x434c5846,
trace:d3dx:dump_bytecode 0x0000000a,0x10100001,0x00000001,0x00000000,0x00000002,0x00000004,0x00000000,0x00000007,
trace:d3dx:dump_bytecode 0x00000000,0xa0400001,0x00000002,0x00000000,0x00000007,0x00000000,0x00000000,0x00000001,
trace:d3dx:dump_bytecode 0x0000000c,0x00000000,0x00000007,0x00000004,0x10300001,0x00000001,0x00000000,0x00000007,
trace:d3dx:dump_bytecode 0x00000004,0x00000000,0x00000004,0x00000000,0x30000001,0x00000003,0x00000000,0x00000002,
trace:d3dx:dump_bytecode 0x00000000,0x00000000,0x00000002,0x00000000,0x00000000,0x00000001,0x0000000d,0x00000000,
trace:d3dx:dump_bytecode 0x00000007,0x00000000,0xa0400001,0x00000002,0x00000000,0x00000007,0x00000000,0x00000000,
trace:d3dx:dump_bytecode 0x00000001,0x0000000e,0x00000000,0x00000007,0x00000004,0x30000001,0x00000003,0x00000000,
trace:d3dx:dump_bytecode 0x00000007,0x00000004,0x00000000,0x00000001,0x0000000f,0x00000000,0x00000007,0x00000000,
trace:d3dx:dump_bytecode 0x00000000,0x00000004,0x00000004,0xd0000003,0x00000002,0x00000000,0x00000001,0x0000000f,
trace:d3dx:dump_bytecode 0x00000000,0x00000002,0x00000008,0x00000000,0x00000007,0x00000000,0x30000001,0x00000003,
trace:d3dx:dump_bytecode 0x00000000,0x00000007,0x00000000,0x00000000,0x00000007,0x00000000,0x00000000,0x00000001,
trace:d3dx:dump_bytecode 0x0000000d,0x00000000,0x00000007,0x00000004,0xa0400001,0x00000002,0x00000000,0x00000007,
trace:d3dx:dump_bytecode 0x00000004,0x00000000,0x00000001,0x0000000e,0x00000000,0x00000007,0x00000000,0x30000001,
trace:d3dx:dump_bytecode 0x00000003,0x00000000,0x00000007,0x00000000,0x00000000,0x00000001,0x0000000f,0x00000000,
trace:d3dx:dump_bytecode 0x00000007,0x00000004,0x00000000,0x00000004,0x00000008,0xf0f0f0f0,0x0f0f0f0f,0x0000ffff,
trace:d3dx:dump_bytecode 0x05000051,0xa00f000b,0x3f800000,0x00000000,0xbc000000,0xc0000000,0x05000051,0xa00f000c,
trace:d3dx:dump_bytecode 0x3e991687,0x3f1645a2,0x3de978d5,0x3f000000,0x05000051,0xa00f000d,0x42800000,0x3f800000,
trace:d3dx:dump_bytecode 0x3fc00000,0x40e00000,0x05000051,0xa00f000e,0x3e99999a,0x3f170a3d,0x3de147ae,0x00000000,
trace:d3dx:dump_bytecode 0x0200001f,0x80000005,0x900f0000,0x0200001f,0x80010005,0x900f0001,0x0200001f,0x80020005,
trace:d3dx:dump_bytecode 0x900f0002,0x0200001f,0x80030005,0x900f0003,0x0200001f,0x80040005,0x900b0004,0x0200001f,
trace:d3dx:dump_bytecode 0x80050005,0x900f0005,0x0200001f,0x80060005,0x900f0006,0x0200001f,0x90000000,0xa00f0800,
trace:d3dx:dump_bytecode 0x0200001f,0x90000000,0xa00f0801,0x0200001f,0x90000000,0xa00f0803,0x0200001f,0x98000000,
trace:d3dx:dump_bytecode 0xa00f0805,0x0200001f,0x90000000,0xa00f0806,0x0200001f,0x90000000,0xa00f0807,0x0200001f,
trace:d3dx:dump_bytecode 0x90000000,0xa00f080a,0x03000005,0x800f0000,0xa010000b,0x90c40004,0x03010042,0x800f0000,
trace:d3dx:dump_bytecode 0x80e40000,0xa0e40806,0x03000002,0x800f0001,0x80550000,0xa0aa000b,0x01000041,0x800f0001,
trace:d3dx:dump_bytecode 0x03010042,0x800f0001,0x90e40006,0xa0e40807,0x03000005,0x80070000,0x80e40000,0x80e40001,
trace:d3dx:dump_bytecode 0x03000008,0x80080000,0xa0e4000c,0x80e40000,0x03000002,0x800f0001,0x80ff0000,0xa0aa000b,
trace:d3dx:dump_bytecode 0x01000041,0x800f0001,0x02000001,0x80010001,0x90ff0000,0x02000001,0x80020001,0x90ff0001,
trace:d3dx:dump_bytecode 0x03000042,0x800f0002,0x80e40001,0xa0e40801,0x03000002,0x80080000,0x81000002,0xa000000b,
trace:d3dx:dump_bytecode 0x03000002,0x800f0003,0x80ff0000,0xa100000a,0x0300000a,0x80040001,0x80ff0000,0xa0000009,
trace:d3dx:dump_bytecode 0x03000005,0x80080800,0x80aa0001,0xa0550008,0x01000041,0x800f0003,0x02000001,0x80020003,
trace:d3dx:dump_bytecode 0xa000000b,0x03000005,0x80050004,0xa0d4000b,0x90ff0002,0x02000001,0x80020004,0x90ff0003,
trace:d3dx:dump_bytecode 0x04000004,0x800c0001,0x80740002,0xa1ff000b,0xa100000b,0x02000001,0x80010002,0xa000000b,
trace:d3dx:dump_bytecode 0x04000004,0x80080000,0xa0000002,0x81aa0002,0x80000002,0x03000005,0x800e0002,0x80900004,
trace:d3dx:dump_bytecode 0x80ff0001,0x04000004,0x800e0002,0x80aa0001,0x90900001,0x80e40002,0x0400005a,0x80040001,
trace:d3dx:dump_bytecode 0x80ee0001,0x81ee0001,0xa000000b,0x02000007,0x80040001,0x80aa0001,0x02000006,0x80040001,
trace:d3dx:dump_bytecode 0x80aa0001,0x04000004,0x800e0002,0x80aa0001,0x90900000,0x80e40002,0x02000024,0x80070004,
trace:d3dx:dump_bytecode 0x80f90002,0x02000024,0x80070005,0x90e40002,0x03000008,0x80040001,0x80e40004,0x80e40005,
trace:d3dx:dump_bytecode 0x04000004,0x80010003,0x80aa0001,0xa0ff000c,0xa0ff000c,0x03000042,0x800f0003,0x80e40003,
trace:d3dx:dump_bytecode 0xa0e4080a,0x03000005,0x800e0002,0x80900003,0xa0900003,0x03000005,0x80070000,0x80e40000,
trace:d3dx:dump_bytecode 0x80f90002,0x03000008,0x80040001,0xa0e4000c,0x80e40000,0x03000002,0x800f0003,0x80aa0001,
trace:d3dx:dump_bytecode 0xa0aa000b,0x01000041,0x800f0003,0x03000008,0x80040001,0x81e40005,0x80e40004,0x03000002,
trace:d3dx:dump_bytecode 0x80040001,0x80aa0001,0x80aa0001,0x04000004,0x800e0002,0x80900004,0x81aa0001,0x81900005,
trace:d3dx:dump_bytecode 0x02000024,0x80070003,0x90e40003,0x03000008,0x80140001,0x80f90002,0x80e40003,0x03000042,
trace:d3dx:dump_bytecode 0x800f0005,0x80e40001,0xa0e40803,0x03000042,0x800f0006,0x80e40001,0xa0e40800,0x04000004,
trace:d3dx:dump_bytecode 0x80010001,0x80ff0005,0xa000000d,0xa055000d,0x03000020,0x80020002,0x80aa0001,0x80000001,
trace:d3dx:dump_bytecode 0x03000005,0x80070001,0x80e40005,0x80550002,0x03000002,0x800e0002,0x80900005,0xa100000b,
trace:d3dx:dump_bytecode 0x03000005,0x80080001,0x80ff0005,0xa0000005,0x0300000a,0x80080003,0x80ff0001,0xa0aa000d,
trace:d3dx:dump_bytecode 0x03000002,0x80080001,0x81ff0003,0xa000000b,0x03000005,0x80080005,0x80ff0001,0xa0ff000d,
trace:d3dx:dump_bytecode 0x04000004,0x800e0002,0xa0000006,0x80e40002,0x80000002,0x03000005,0x800e0002,0x80ff0006,
trace:d3dx:dump_bytecode 0x80e40002,0x03000005,0x80080001,0x80ff0006,0xa0000001,0x04000004,0x80080001,0x80ff0001,
trace:d3dx:dump_bytecode 0x81550002,0xa000000b,0x03000005,0x800e0002,0x80e40002,0xa0000004,0x04000004,0x80070001,
trace:d3dx:dump_bytecode 0x80e40006,0x80ff0001,0x80e40001,0x03000008,0x80080001,0x81e40003,0x80e40004,0x03000002,
trace:d3dx:dump_bytecode 0x80080001,0x80ff0001,0x80ff0001,0x04000004,0x80070005,0x80e40004,0x81ff0001,0x81e40003,
trace:d3dx:dump_bytecode 0x0300005f,0x800f0003,0x80e40005,0xa0e40805,0x03000008,0x80080001,0x80e40003,0xa0e4000e,
trace:d3dx:dump_bytecode 0x03000002,0x80080001,0x80ff0001,0xa100000b,0x04000004,0x80080001,0xa0000007,0x80ff0001,
trace:d3dx:dump_bytecode 0x80000002,0x03000002,0x80080001,0x80ff0001,0xa1000007,0x03000005,0x80180001,0x80ff0001,
trace:d3dx:dump_bytecode 0xa0000000,0x04000012,0x80070004,0xa0000007,0x80ff0001,0x80e40003,0x03000005,0x80070002,
trace:d3dx:dump_bytecode 0x80f90002,0x80e40004,0x04000004,0x80070000,0x80e40001,0x80e40000,0x80e40002,0x03000005,
trace:d3dx:dump_bytecode 0x80070001,0x80ff0000,0x80e40000,0x04000004,0x80070000,0x80e40000,0x81ff0000,0x90e40005,
trace:d3dx:dump_bytecode 0x04000004,0x80070800,0x90ff0005,0x80e40000,0x80e40001,0x0000ffff,
trace:d3dx:dump_preshader // Preshader registers:
trace:d3dx:dump_registers //   diffuseFlatColorProp c2    1
trace:d3dx:dump_registers //   reflectionContrast c1    1
trace:d3dx:dump_registers //   reflectionIntensity c0    1
trace:d3dx:dump_preshader // Immed const count 18.
trace:d3dx:dump_preshader     preshader
trace:d3dx:dump_ins     neg r0.x, c1.x
trace:d3dx:dump_ins     add r1.x, r0.x, (1.0001000000000000e+00)
trace:d3dx:dump_ins     rcp oc0.x, r1.x
trace:d3dx:dump_ins     cmp r0.x, c0.x, c0.x, (0.0000000000000000e+00)
trace:d3dx:dump_ins     add r1.x, r0.x, (-1.0000000000000000e+00)
trace:d3dx:dump_ins     cmp oc1.x, r1.x, (1.0000000000000000e+00), r0.x
trace:d3dx:dump_ins     dot r0.x, (1.0000000000000000e+00), c2.xyz
trace:d3dx:dump_ins     cmp r1.x, r0.x, r0.x, (0.0000000000000000e+00)
trace:d3dx:dump_ins     add r0.x, r1.x, (-1.0000000000000000e+00)
trace:d3dx:dump_ins     cmp oc2.x, r0.x, (1.0000000000000000e+00), r1.x
trace:d3dx:d3dx_create_param_eval // Shader registers:
trace:d3dx:dump_registers //   AlphaRef     oc10   1
trace:d3dx:dump_registers //   DiffuseTextureAlphaMax oc9    1
trace:d3dx:dump_registers //   alphaAsBloomAmount oc8    1
trace:d3dx:dump_registers //   diffuseLightColor oc3    1
trace:d3dx:dump_registers //   diffuseMapSampler (null)0    1
trace:d3dx:dump_registers //   environmentMapSampler (null)5    1
trace:d3dx:dump_registers //   glossMapSampler (null)3    1
trace:d3dx:dump_registers //   lightFalloffMapSampler (null)7    1
trace:d3dx:dump_registers //   lightIlluminationMapSampler (null)6    1
trace:d3dx:dump_registers //   rampLightMapSampler (null)10   1
trace:d3dx:dump_registers //   reflectionBlurIntensity oc5    1
trace:d3dx:dump_registers //   reflectionContrast oc7    1
trace:d3dx:dump_registers //   reflectionIntensity oc4    1
trace:d3dx:dump_registers //   reflectionSpecInfluence oc6    1
trace:d3dx:dump_registers //   rotationMap1Sampler (null)1    1


More information about the wine-devel mailing list