st/nine: NineBaseTexture9: update sampler view creation

While previous code was having the correct behaviour in general,
this new code is more readable (without checking all gallium formats
manually) and has a more defined behaviour for depth stencil resources.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: fix crash when deleting non-implicit swapchain

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: clamp color inputs for ps <= 2.0

Nine code is clamping color outputs for vs < 3,
but msdn docs says it is done in the ps.
Wine seems to clamp them at the vs level.

To prevent potential issues, just clamp at both vs
and ps level.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: saturate oFog and oPts vs outputs

According to docs and Wine, these two vs outputs have
to be saturated.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Fix POW implementation

POW doesn't match directly TGSI, since we should
take the absolute value of src0.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Handle RSQ special cases

We should use the absolute value of the input
as input to ureg_RSQ.
An input of 0.0 should return FLT_MAX. To support that
efficiently cap the output of RSQ.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Handle NRM with input of null norm

When the input's xyz are 0.0, the output
should be 0.0. This is due to the fact that
Inf * 0 = 0 for dx9. To handle this case,
cap the result of RSQ to FLT_MAX. We have
FLT_MAX * 0 = 0.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Correct LOG on negative values

LOG, like POW, is applicated on the absolute value of the input.

Also return -FLT_MAX instead of -Inf for an input of 0.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Remove duplicated code for ps texcoord input declaration

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Implement TEXCOORD special behaviours

texcoord for ps < 1_4 should clamp between 0 and 1 the values.

texcrd (texcoord ps 1_4) does not clamp and can be used with
two modifiers _dw and _dz that means the channels are divided
by w or z.
Implement those in shared code, since the same modifiers can be used
for texld ps 1_4.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Implement ps3 advanced input definition feature

ps3 allows definitions of the inputs like:
DCL_TEXCOORD0 v0.xy;
DCL_NORMAL2 v0.z;
DCL_NORMAL3 v0.w;

Nine wouldn't have handled this situation properly.

Apparently very few applications use this feature.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Check if srgb format is supported before trying to use it.

According to msdn, we must act as if user didn't ask srgb if we don't
support it.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: fix DBG typo (trivial)

Signed-off-by: David Heidelberg <david@ixit.cz>
st/nine: generate resource if doesn't exist when used

Hack necessary for the time being.

Fixes Divinity: Original Sin, Blur, Prototype 2.

Acked-by: Axel Davy <axel.davy@ens.fr>
Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
st/nine: correct rules for relative adressing and constants.

relative adressing for constants is possible only for vs float
constants.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: remove unused code for ps

Since constant indirect adressing is not allowed for ps,
we can remove our code to handle that.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Fix sm3 relative addressing for non-debug build

Relative addressing needs the constant buffer to get all
the correct constants, even those defined by the shader.

The code to copy the shader constants to the constant buffer
was enabled only for debug build. Enable it always.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Improve fallback when driver doesn't support user buffers.

For now the path updated is only used by Amd drivers, but a later
patch will make it used by all drivers. Some drivers like llvmpipe
doesn't support the uploading of constants from user buffers, so improve
the path to work for all drivers

Inspired from the gl state tracker.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Drop one path to upload constants

Drop the path to upload constants that was using a resource.
Use only the user_buffer one.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Fix constant buffer reinitialisation

The size used for the memset was incorrect.

Signed-off-by: Axel Davy <axel.davy@ens.fr>