st/nine: Track formats compatible with FETCH4

FETCH4 is a d3d9 extension not much used, as newer
ones were prefered. However it's support is required
to advertise the DF24 format.

Prepares support by tracking compatible formats.

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
Acked-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9177>
This commit is contained in:
Axel Davy 2019-02-02 19:20:35 +01:00
parent 6a3451e170
commit d097bdcc78
5 changed files with 40 additions and 11 deletions

View file

@ -27,9 +27,9 @@
#include "texture9.h"
#include "cubetexture9.h"
#include "volumetexture9.h"
#include "nine_pipe.h"
#if defined(DEBUG) || !defined(NDEBUG)
#include "nine_pipe.h"
#include "nine_dump.h"
#endif
@ -85,6 +85,7 @@ NineBaseTexture9_ctor( struct NineBaseTexture9 *This,
This->shadow = (This->format != D3DFMT_INTZ && This->format != D3DFMT_DF16 &&
This->format != D3DFMT_DF24) &&
util_format_has_depth(util_format_description(This->base.info.format));
This->fetch4_compatible = fetch4_compatible_format(This->format);
list_inithead(&This->list);
list_inithead(&This->list2);

View file

@ -42,6 +42,7 @@ struct NineBaseTexture9
int16_t bind_count; /* to Device9->state.texture */
boolean shadow;
boolean fetch4_compatible;
uint8_t pstype; /* 0: 2D, 1: 1D, 2: CUBE, 3: 3D */
boolean dirty_mip;

View file

@ -181,6 +181,28 @@ pipe_to_d3d9_format(enum pipe_format format)
return nine_pipe_to_d3d9_format_map[format];
}
static inline boolean
fetch4_compatible_format( D3DFORMAT fmt )
{
/* Basically formats with only red channel are allowed (with some exceptions) */
static const D3DFORMAT allowed[] = { /* TODO: list incomplete */
D3DFMT_L8,
D3DFMT_L16,
D3DFMT_R16F,
D3DFMT_R32F,
D3DFMT_A8,
D3DFMT_DF16,
D3DFMT_DF24,
D3DFMT_INTZ
};
unsigned i;
for (i = 0; i < sizeof(allowed)/sizeof(D3DFORMAT); i++) {
if (fmt == allowed[i]) { return TRUE; }
}
return FALSE;
}
/* ATI1 and ATI2 are not officially compressed in d3d9 */
static inline boolean
compressed_format( D3DFORMAT fmt )

View file

@ -1360,8 +1360,7 @@ NineDevice9_ResolveZ( struct NineDevice9 *device )
static void
nine_context_set_texture_apply(struct NineDevice9 *device,
DWORD stage,
BOOL enabled,
BOOL shadow,
DWORD fetch4_shadow_enabled,
DWORD lod,
D3DRESOURCETYPE type,
uint8_t pstype,
@ -1431,8 +1430,7 @@ CSMT_ITEM_NO_WAIT(nine_context_set_render_state,
CSMT_ITEM_NO_WAIT(nine_context_set_texture_apply,
ARG_VAL(DWORD, stage),
ARG_VAL(BOOL, enabled),
ARG_VAL(BOOL, shadow),
ARG_VAL(DWORD, fetch4_shadow_enabled),
ARG_VAL(DWORD, lod),
ARG_VAL(D3DRESOURCETYPE, type),
ARG_VAL(uint8_t, pstype),
@ -1441,10 +1439,15 @@ CSMT_ITEM_NO_WAIT(nine_context_set_texture_apply,
ARG_BIND_VIEW(struct pipe_sampler_view, view1))
{
struct nine_context *context = &device->context;
uint enabled = fetch4_shadow_enabled & 1;
uint shadow = (fetch4_shadow_enabled >> 1) & 1;
uint fetch4_compatible = (fetch4_shadow_enabled >> 2) & 1;
context->texture[stage].enabled = enabled;
context->samplers_shadow &= ~(1 << stage);
context->samplers_shadow |= shadow << stage;
context->samplers_fetch4 &= ~(1 << stage);
context->samplers_fetch4 |= fetch4_compatible << stage;
context->texture[stage].shadow = shadow;
context->texture[stage].lod = lod;
context->texture[stage].type = type;
@ -1461,8 +1464,7 @@ nine_context_set_texture(struct NineDevice9 *device,
DWORD Stage,
struct NineBaseTexture9 *tex)
{
BOOL enabled = FALSE;
BOOL shadow = FALSE;
DWORD fetch4_shadow_enabled = 0;
DWORD lod = 0;
D3DRESOURCETYPE type = D3DRTYPE_TEXTURE;
uint8_t pstype = 0;
@ -1473,8 +1475,9 @@ nine_context_set_texture(struct NineDevice9 *device,
* In that case, the texture is rebound later
* (in NineBaseTexture9_Validate/NineBaseTexture9_UploadSelf). */
if (tex && tex->base.resource) {
enabled = TRUE;
shadow = tex->shadow;
fetch4_shadow_enabled = 1;
fetch4_shadow_enabled |= tex->shadow << 1;
fetch4_shadow_enabled |= tex->fetch4_compatible << 2;
lod = tex->managed.lod;
type = tex->base.type;
pstype = tex->pstype;
@ -1483,8 +1486,9 @@ nine_context_set_texture(struct NineDevice9 *device,
view1 = NineBaseTexture9_GetSamplerView(tex, 1);
}
nine_context_set_texture_apply(device, Stage, enabled,
shadow, lod, type, pstype,
nine_context_set_texture_apply(device, Stage,
fetch4_shadow_enabled,
lod, type, pstype,
res, view0, view1);
}

View file

@ -297,6 +297,7 @@ struct nine_context {
DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
uint32_t samplers_shadow;
uint32_t samplers_fetch4;
uint8_t bound_samplers_mask_vs;
uint16_t bound_samplers_mask_ps;