Commit 0fb35100 authored by Louis-Francis Ratté-Boulianne's avatar Louis-Francis Ratté-Boulianne Committed by Erik Faye-Lund
Browse files

d3d12: Use native DXGI format for A8_UNORM support

The only caveat is that, when casting buffers, we need to use
R8_UNORM instead of A8_UNORM.
parent 4caa0de5
......@@ -126,7 +126,7 @@ blit_resolve(struct d3d12_context *ctx, const struct pipe_blit_info *info)
d3d12_batch_reference_resource(batch, src);
d3d12_batch_reference_resource(batch, dst);
DXGI_FORMAT dxgi_format = d3d12_get_resource_srv_format(src->base.format);
DXGI_FORMAT dxgi_format = d3d12_get_resource_srv_format(src->base.format, src->base.target);
assert(src->dxgi_format == dst->dxgi_format);
ctx->cmdlist->ResolveSubresource(
......
......@@ -811,7 +811,7 @@ d3d12_create_sampler_view(struct pipe_context *pctx,
sampler_view->swizzle_override_b = swizzle[2];
sampler_view->swizzle_override_a = swizzle[3];
desc.Format = d3d12_get_resource_srv_format(state->format);
desc.Format = d3d12_get_resource_srv_format(state->format, state->target);
desc.ViewDimension = view_dimension(state->target, texture->nr_samples);
/* Integer cube textures are not really supported, because TextureLoad doesn't exist
......
......@@ -42,11 +42,13 @@ static const DXGI_FORMAT formats[PIPE_FORMAT_COUNT] = {
#define MAP_FORMAT_FLOAT(FMT) \
[PIPE_FORMAT_ ## FMT ## _FLOAT] = DXGI_FORMAT_ ## FMT ## _FLOAT,
#define MAP_EMU_FORMAT(BITS, TYPE) \
#define MAP_EMU_FORMAT_NO_ALPHA(BITS, TYPE) \
[PIPE_FORMAT_L ## BITS ## _ ## TYPE] = DXGI_FORMAT_R ## BITS ## _ ## TYPE, \
[PIPE_FORMAT_I ## BITS ## _ ## TYPE] = DXGI_FORMAT_R ## BITS ## _ ## TYPE, \
[PIPE_FORMAT_L ## BITS ## A ## BITS ## _ ## TYPE] = \
DXGI_FORMAT_R ## BITS ## G ## BITS ## _ ## TYPE,
#define MAP_EMU_FORMAT(BITS, TYPE) \
[PIPE_FORMAT_A ## BITS ## _ ## TYPE] = DXGI_FORMAT_R ## BITS ## _ ## TYPE, \
MAP_EMU_FORMAT_NO_ALPHA(BITS, TYPE)
......@@ -86,7 +88,8 @@ static const DXGI_FORMAT formats[PIPE_FORMAT_COUNT] = {
MAP_FORMAT_INT(R16G16B16A16)
MAP_FORMAT_FLOAT(R16G16B16A16)
MAP_EMU_FORMAT(8, UNORM)
[PIPE_FORMAT_A8_UNORM] = DXGI_FORMAT_A8_UNORM,
MAP_EMU_FORMAT_NO_ALPHA(8, UNORM)
MAP_EMU_FORMAT(8, SNORM)
MAP_EMU_FORMAT(8, SNORM)
MAP_EMU_FORMAT(8, SINT)
......@@ -148,7 +151,7 @@ d3d12_get_resource_rt_format(enum pipe_format f)
}
DXGI_FORMAT
d3d12_get_resource_srv_format(enum pipe_format f)
d3d12_get_resource_srv_format(enum pipe_format f, enum pipe_texture_target target)
{
switch (f) {
case PIPE_FORMAT_Z16_UNORM:
......@@ -164,6 +167,10 @@ d3d12_get_resource_srv_format(enum pipe_format f)
return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
case PIPE_FORMAT_X32_S8X24_UINT:
return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
case PIPE_FORMAT_A8_UNORM:
if (target == PIPE_BUFFER)
return DXGI_FORMAT_R8_UNORM; /* A8_UNORM is not supported for buffer SRV */
/* passthrough */
default:
return d3d12_get_format(f);
}
......@@ -194,6 +201,8 @@ d3d12_get_format_info(enum pipe_format pformat, enum pipe_texture_target target)
if (!util_format_is_srgb(pformat)) {
if (target == PIPE_BUFFER && util_format_is_alpha(pformat)) {
swizzle = BUFFER_SWIZZLE;
} else if (pformat == PIPE_FORMAT_A8_UNORM) {
/* no need to swizzle, it's natively supported */
} else if (util_format_is_intensity(pformat)) {
swizzle = INTENSITY_SWIZZLE;
} else if (util_format_is_luminance(pformat)) {
......
......@@ -37,7 +37,7 @@ DXGI_FORMAT
d3d12_get_format(enum pipe_format format);
DXGI_FORMAT
d3d12_get_resource_srv_format(enum pipe_format f);
d3d12_get_resource_srv_format(enum pipe_format f, enum pipe_texture_target target);
DXGI_FORMAT
d3d12_get_resource_rt_format(enum pipe_format f);
......
......@@ -500,10 +500,11 @@ d3d12_is_format_supported(struct pipe_screen *pscreen,
}
/* Don't advertise alpha/luminance_alpha formats because they can't be used
* for render targets and can't be emulated by R/RG formats. Let the state
* tracker choose an RGBA format instead. */
if (util_format_is_alpha(format) ||
util_format_is_luminance_alpha(format))
* for render targets (except A8_UNORM) and can't be emulated by R/RG formats.
* Let the state tracker choose an RGBA format instead. */
if (format != PIPE_FORMAT_A8_UNORM &&
(util_format_is_alpha(format) ||
util_format_is_luminance_alpha(format)))
return false;
DXGI_FORMAT dxgi_format = d3d12_get_format(format);
......@@ -567,7 +568,7 @@ d3d12_is_format_supported(struct pipe_screen *pscreen,
D3D12_FEATURE_DATA_FORMAT_SUPPORT fmt_info_sv;
if (util_format_is_depth_or_stencil(format)) {
fmt_info_sv.Format = d3d12_get_resource_srv_format(format);
fmt_info_sv.Format = d3d12_get_resource_srv_format(format, target);
if (FAILED(screen->dev->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT,
&fmt_info_sv, sizeof(fmt_info_sv))))
return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment