nine: Add state tracker nine for Direct3D9

Work of Joakim Sindholt (zhasha) and Christoph Bumiller (chrisbmr).
v2 Small fixies and sync with latest Mesa by David Heidelberger (okias).
v3 Build improvements by Emil Velikov (xexaxo).
v4 Modified to use directly PIPE_CAP_VIDEO_MEMORY
instead of PIPE_CAP_DEVICE_MEMORY_SIZE.
v5 Merged few small fixes by okias
v6 define to not use indirect drawing
v7 allow D3DLOCK_NOOVERWRITE for LockRect, make Osu game works
v8 build fixes by okias
v9 build fix without opencl by mannerov
v10 build fix after configure.ac changes by okias

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: fixed problems with using more buffers than available

Hardcoded value 32 worked on nv50+ and r600, but on radeonsi or
others with <= 16 failed and asserted in debug mode.

Reported-and-tested-by: Nick Sarnie (sarnex) on IRC
Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: deal with D3DFMT_NULL

Fixed CS:GO on r600g.
More information about NULL format here aras-p.info/texts/D3D9GPUHacks.html

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: correctly divide maximum constant numbers

We get from driver number already multiplied by sizeof(float[4]) = 16.
This patch shouldn't affect any modern card with
PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE > 256

Reported-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: get real MaxStreamStride

At this moment, most gallium drivers set 2048.
Wine set default value 1024.

Reported-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: prevent assert on Shader Model 2.0 cards

Fixed r300g and other non-SM3.0 cards.

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: always allocate maximum space for constant registers

On SM3.0 cards (>r600g, nv50+) doesn't matter (always NINE_MAX_CONST_ALL),
but on SM2.0 (r300g) causes segfault even for simplest demos.

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nv50,nvc0: add missing depth/stencil formats to tile flag selection

Reported-by: David Heidelberger <david.heidelberger@ixit.cz>
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
nv50,nvc0: fix 3d blit logic for odd depth/stencil formats

Reported-by: David Heidelberger <david.heidelberger@ixit.cz>
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
nine: correct D24 <-> Z24 format conversion

This change behaviour only for transfer_map().
Also fixes Unigine Sanctuary loading on RS690 (r300g).

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: fix D3DTOP_DOTPRODUCT3

Fixes Dot3 Per-Pixel Bump Mapping sample
http://www.codesampler.com/dx9src/dx9src_4.htm#dx9_dot3_bump_mapping

Wine handle this same way.

Tested-by: David Heidelberger <david.heidelberger@ixit.cz>
Signed-off-by: Tiziano Bacocco <tizbac2@gmail.com>
nine: always set info.const_{i,b}_base

This caused wrong TGSI code generation, because undefined values.

Fixes: https://github.com/iXit/Mesa-3D/issues/6
Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
ilo: Build pipe-loader for ilo

Trivial patch to create the pipe loader for ilo. All the code was already there.

Signed-off-by: Nick Sarnie <commendsarnex@gmail.com>
nine: improve handling of get_shader_param unsigned output

ILO driver get_shader_param return UINT_MAX.
Unfortunately get_shader_param return value is defined as signed int.
This cause getting negative signed value, which later result in assertion.

Catch all negative numbers and handle them as > MAX.

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: workaround missing CLAMP in drivers for FF

Fixes errors about unsupported instruction on r600g.

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: fix indexbuffer locking, add debugging and always return D3D_OK

In our country full of dragons, there exist people from one unnamed
company, who thinks it's smart to try lock indexbuffer twice.
You know, you can't be never sure, if it's locked propertly ;)
And except that, they also unlock indexbuffer twice.
Yes, our great creators of d3dx9_27 and d3dx9_36.

With wine version of these files, it work.

Also make _Lock and _Unlock always return D3D_OK as is expected.

Wine handle this similiar way.

This fixes demo: dx9_view_ports from
http://www.codesampler.com/dx9src/dx9src_1.htm
Tested on: r300g, r600g and radeonsi

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: Fixed uninitialized value on UpdateSamplerView

Fixes: dx9_shadow_volume on NVC0
Tested-by: David Heidelberger <david.heidelberger@ixit.cz>
Signed-off-by: Tiziano Bacocco <tizbac2@gmail.com>
nine: fix write into array in TEXM3x3

Fix warning:
nine_shader.c:2134:9: warning: array index 4 is past the
end of the array (which contains 4 elements) [-Warray-bounds]

No visible changes.

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
Signed-off-by: Tiziano Bacocco <tizbac2@gmail.com>
nine: make ccc-analyzer happier

No functional changes, only added user_assert in case of null pointer.

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
nine: vertexdeclaration: fix return value

In case of Lock or mapping failure, hr is now passed to return.

Reported by: ccc-analyzer
Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>