Check value validity and mimick Win behaviour.
Signed-off-by: Axel Davy <axel.davy@ens.fr>
if (Sampler >= D3DDMAPSAMPLER)
Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
- *pValue = This->state.samp[Sampler][Type];
+ *pValue = This->state.samp_advertised[Sampler][Type];
return D3D_OK;
}
if (Sampler >= D3DDMAPSAMPLER)
Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
- if (state->samp[Sampler][Type] != Value || unlikely(This->is_recording)) {
- state->samp[Sampler][Type] = Value;
+ if (state->samp_advertised[Sampler][Type] != Value || unlikely(This->is_recording)) {
+ /* Contrary to render states, old value is kept if new value is wrong (except intel + Value == 0) */
+ if (likely(nine_check_sampler_state_value(Type, Value)))
+ state->samp[Sampler][Type] = Value;
+ state->samp_advertised[Sampler][Type] = Value;
state->changed.group |= NINE_STATE_SAMPLER;
state->changed.sampler[Sampler] |= 1 << Type;
}
return Value;
}
+struct nine_limits
+{
+ unsigned min;
+ unsigned max;
+};
+
+#define __VALUE_SAMP(o, m, M) \
+ [D3DSAMP_##o] = {m, M}
+
+static const struct nine_limits
+sampler_state_limits_table[D3DRS_BLENDOPALPHA + 1] = {
+ __VALUE_SAMP(ADDRESSU, 1, 5),
+ __VALUE_SAMP(ADDRESSV, 1, 5),
+ __VALUE_SAMP(ADDRESSW, 1, 5),
+ __VALUE_SAMP(BORDERCOLOR, 0, 0xFFFFFFFF),
+ __VALUE_SAMP(MAGFILTER, 0, 8), /* 4-5 should be forbidden */
+ __VALUE_SAMP(MINFILTER, 0, 8), /* same */
+ __VALUE_SAMP(MIPFILTER, 0, 8), /* same */
+ __VALUE_SAMP(MIPMAPLODBIAS, 0, 0xFFFFFFFF),
+ __VALUE_SAMP(MAXMIPLEVEL, 0, 0xFFFFFFFF),
+ __VALUE_SAMP(MAXANISOTROPY, 1, 0xFFFFFFFF), /* Max value should be pCaps->MaxAnisotropy */
+ __VALUE_SAMP(SRGBTEXTURE, 0, 1),
+ __VALUE_SAMP(ELEMENTINDEX, 0, 0xFFFFFFFF),
+ __VALUE_SAMP(DMAPOFFSET, 0, 0xFFFFFFFF)
+};
+
+static BOOL inline
+nine_check_sampler_state_value(D3DSAMPLERSTATETYPE State,
+ DWORD Value)
+{
+ struct nine_limits limit;
+
+ limit = sampler_state_limits_table[State];
+ return (limit.min <= Value && Value <= limit.max);
+}
+
#endif /* _NINE_HELPERS_H_ */
for (s = 0; s < ARRAY_SIZE(state->samp); ++s) {
memcpy(&state->samp[s], nine_samp_state_defaults,
sizeof(state->samp[s]));
+ memcpy(&state->samp_advertised[s], nine_samp_state_defaults,
+ sizeof(state->samp_advertised[s]));
}
if (state->vs_const_f)
struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS]; /* PS, DMAP, VS */
DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
+ DWORD samp_advertised[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
uint32_t samplers_shadow;
uint8_t bound_samplers_mask_vs;
uint16_t bound_samplers_mask_ps;
for (s = 0; s < NINE_MAX_SAMPLERS; ++s) {
if (mask->changed.sampler[s] == 0x3ffe) {
memcpy(&dst->samp[s], &src->samp[s], sizeof(dst->samp[s]));
+ memcpy(&dst->samp_advertised[s], &src->samp_advertised[s], sizeof(dst->samp_advertised[s]));
} else {
uint32_t m = mask->changed.sampler[s];
while (m) {
const int i = ffs(m) - 1;
m &= ~(1 << i);
dst->samp[s][i] = src->samp[s][i];
+ dst->samp_advertised[s][i] = src->samp_advertised[s][i];
}
}
if (apply)
/* Sampler state. */
memcpy(dst->samp, src->samp, sizeof(dst->samp));
+ memcpy(dst->samp_advertised, src->samp_advertised, sizeof(dst->samp_advertised));
if (apply)
memcpy(dst->changed.sampler,
src->changed.sampler, sizeof(dst->changed.sampler));