From 9b2dae79b1be1f57e7b6bcf80d500ab4190aa3d3 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Mon, 2 Oct 2017 23:10:52 +1100 Subject: vo_gpu: d3d11: add RA caps for ra_d3d11 ra_d3d11 uses the SPIR-V compiler to translate GLSL to SPIR-V, which is then translated to HLSL. This means it always exposes the same GLSL version that the SPIR-V compiler supports (4.50 for shaderc/glslang.) Despite claiming to support GLSL 4.50, some features that are tied to the GLSL version in OpenGL are not supported by ra_d3d11 when targeting legacy Direct3D feature levels. This includes two features that mpv relies on: - Reading from gl_FragCoord in the fragment shader (requires FL 10_0) - textureGather from any texture component (requires FL 11_0) These features have been exposed as new RA caps. --- video/out/d3d11/ra_d3d11.c | 5 +++++ video/out/gpu/ra.h | 2 ++ video/out/gpu/video.c | 16 +++++++++++++++- video/out/gpu/video_shaders.c | 5 ++--- video/out/gpu/video_shaders.h | 2 +- video/out/opengl/ra_gl.c | 5 +++++ video/out/vulkan/ra_vk.c | 6 +++++- 7 files changed, 35 insertions(+), 6 deletions(-) (limited to 'video') diff --git a/video/out/d3d11/ra_d3d11.c b/video/out/d3d11/ra_d3d11.c index 372b65d49f..806ce9ad52 100644 --- a/video/out/d3d11/ra_d3d11.c +++ b/video/out/d3d11/ra_d3d11.c @@ -2161,6 +2161,11 @@ struct ra *ra_d3d11_create(ID3D11Device *dev, struct mp_log *log, ra->max_texture_wh = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION; } + if (p->fl >= D3D_FEATURE_LEVEL_11_0) + ra->caps |= RA_CAP_GATHER; + if (p->fl >= D3D_FEATURE_LEVEL_10_0) + ra->caps |= RA_CAP_FRAGCOORD; + // Some 10_0 hardware has compute shaders, but only 11_0 has image load/store if (p->fl >= D3D_FEATURE_LEVEL_11_0) { ra->caps |= RA_CAP_COMPUTE | RA_CAP_BUF_RW; diff --git a/video/out/gpu/ra.h b/video/out/gpu/ra.h index b10ab76124..934e5db844 100644 --- a/video/out/gpu/ra.h +++ b/video/out/gpu/ra.h @@ -51,6 +51,8 @@ enum { RA_CAP_BUF_RW = 1 << 6, // supports RA_VARTYPE_BUF_RW RA_CAP_NESTED_ARRAY = 1 << 7, // supports nested arrays RA_CAP_GLOBAL_UNIFORM = 1 << 8, // supports using "naked" uniforms (not UBO) + RA_CAP_GATHER = 1 << 9, // supports textureGather in GLSL + RA_CAP_FRAGCOORD = 1 << 10, // supports reading from gl_FragCoord }; enum ra_ctype { diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index fd870a2ffc..9cc889b401 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -1719,7 +1719,8 @@ static void pass_dispatch_sample_polar(struct gl_video *p, struct scaler *scaler fallback: // Fall back to regular polar shader when compute shaders are unsupported // or the kernel is too big for shmem - pass_sample_polar(p->sc, scaler, img.components, p->ra->glsl_version); + pass_sample_polar(p->sc, scaler, img.components, + p->ra->caps & RA_CAP_GATHER); } // Sample from image, with the src rectangle given by it. @@ -3465,6 +3466,19 @@ static void check_gl_features(struct gl_video *p) p->opts.compute_hdr_peak = 0; MP_WARN(p, "Disabling HDR peak computation (no compute shaders).\n"); } + if (!(ra->caps & RA_CAP_FRAGCOORD) && p->opts.dither_depth >= 0 && + p->opts.dither_algo != DITHER_NONE) + { + p->opts.dither_algo = DITHER_NONE; + MP_WARN(p, "Disabling dithering (no gl_FragCoord).\n"); + } + if (!(ra->caps & RA_CAP_FRAGCOORD) && + p->opts.alpha_mode == ALPHA_BLEND_TILES) + { + p->opts.alpha_mode = ALPHA_BLEND; + // Verbose, since this is the default setting + MP_VERBOSE(p, "Disabling alpha checkerboard (no gl_FragCoord).\n"); + } } static void init_gl(struct gl_video *p) diff --git a/video/out/gpu/video_shaders.c b/video/out/gpu/video_shaders.c index 02f27b1bdb..3e71c31369 100644 --- a/video/out/gpu/video_shaders.c +++ b/video/out/gpu/video_shaders.c @@ -143,7 +143,7 @@ static void polar_sample(struct gl_shader_cache *sc, struct scaler *scaler, } void pass_sample_polar(struct gl_shader_cache *sc, struct scaler *scaler, - int components, int glsl_version) + int components, bool sup_gather) { GLSL(color = vec4(0.0);) GLSLF("{\n"); @@ -167,8 +167,7 @@ void pass_sample_polar(struct gl_shader_cache *sc, struct scaler *scaler, // exactly when all four texels are within bounds bool use_gather = sqrt(x*x + y*y) < scaler->kernel->radius_cutoff; - // textureGather is only supported in GLSL 400+ - if (glsl_version < 400) + if (!sup_gather) use_gather = false; if (use_gather) { diff --git a/video/out/gpu/video_shaders.h b/video/out/gpu/video_shaders.h index 8345e4c598..2ae2ac3fa9 100644 --- a/video/out/gpu/video_shaders.h +++ b/video/out/gpu/video_shaders.h @@ -30,7 +30,7 @@ void sampler_prelude(struct gl_shader_cache *sc, int tex_num); void pass_sample_separated_gen(struct gl_shader_cache *sc, struct scaler *scaler, int d_x, int d_y); void pass_sample_polar(struct gl_shader_cache *sc, struct scaler *scaler, - int components, int glsl_version); + int components, bool sup_gather); void pass_compute_polar(struct gl_shader_cache *sc, struct scaler *scaler, int components, int bw, int bh, int iw, int ih); void pass_sample_bicubic_fast(struct gl_shader_cache *sc); diff --git a/video/out/opengl/ra_gl.c b/video/out/opengl/ra_gl.c index 61ac2c2bbb..60e667bf05 100644 --- a/video/out/opengl/ra_gl.c +++ b/video/out/opengl/ra_gl.c @@ -97,6 +97,7 @@ static int ra_init_gl(struct ra *ra, GL *gl) static const int caps_map[][2] = { {RA_CAP_DIRECT_UPLOAD, 0}, {RA_CAP_GLOBAL_UNIFORM, 0}, + {RA_CAP_FRAGCOORD, 0}, {RA_CAP_TEX_1D, MPGL_CAP_1D_TEX}, {RA_CAP_TEX_3D, MPGL_CAP_3D_TEX}, {RA_CAP_COMPUTE, MPGL_CAP_COMPUTE_SHADER}, @@ -115,6 +116,10 @@ static int ra_init_gl(struct ra *ra, GL *gl) ra->caps |= RA_CAP_BUF_RW; } + // textureGather is only supported in GLSL 400+ + if (ra->glsl_version >= 400) + ra->caps |= RA_CAP_GATHER; + if (gl->BlitFramebuffer) ra->caps |= RA_CAP_BLIT; diff --git a/video/out/vulkan/ra_vk.c b/video/out/vulkan/ra_vk.c index 58213bd0e9..f85e30e21c 100644 --- a/video/out/vulkan/ra_vk.c +++ b/video/out/vulkan/ra_vk.c @@ -202,7 +202,11 @@ struct ra *ra_create_vk(struct mpvk_ctx *vk, struct mp_log *log) goto error; // UBO support is required - ra->caps |= RA_CAP_BUF_RO; + ra->caps |= RA_CAP_BUF_RO | RA_CAP_FRAGCOORD; + + // textureGather is only supported in GLSL 400+ + if (ra->glsl_version >= 400) + ra->caps |= RA_CAP_GATHER; // Try creating a shader storage buffer struct ra_buf_params ssbo_params = { -- cgit v1.2.3