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.

Reviewed-by: David Heidelberg <david@ixit.cz>
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.

Reviewed-by: David Heidelberg <david@ixit.cz>
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>
Acked-by: David Heidelberg <david@ixit.cz>
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.

Reviewed-by: David Heidelberg <david@ixit.cz>
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>
st/nine: restrict to 256 constants for vs shaders.

This is wine behaviour and apparently the behaviour of dx9 drivers
for dx1x hw.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Drop unused code to handle more constants

We handle maximum 256 float constants, like wine and most dx9 drivers.
It is not possible to get more constants

Reviewed-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Change the calculation of the constant buffer size.

Count separately the number of float, int and bool constants.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: Remove useless optimisations to avoid constant uploads

Previous removed path to upload constants was trying to do as
few uploads as possible.
The path kept doesn't benefit these optimisations, thus remove them.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
st/nine: fix the size of the constant buffer with relative addressing

When relative addressing is on, we have to copy the constants defined in the
shader in the constant file.
The size for the new constant buffer was incorrectly calculated.

Tested-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Axel Davy <axel.davy@ens.fr>