Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opengl: infer fbo format name in gl_fb_query #267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 79 additions & 51 deletions src/gpu/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,69 +277,92 @@ struct glsl_fmt {
enum pl_fmt_type type;
int num_components;
int depth[4];
const char *glsl_format;
const char *format;
bool glsl;
};

// List taken from the GLSL specification. (Yes, GLSL supports only exactly
// these formats with exactly these names)
static const struct glsl_fmt pl_glsl_fmts[] = {
{PL_FMT_FLOAT, 1, {16}, "r16f"},
{PL_FMT_FLOAT, 1, {32}, "r32f"},
{PL_FMT_FLOAT, 2, {16, 16}, "rg16f"},
{PL_FMT_FLOAT, 2, {32, 32}, "rg32f"},
{PL_FMT_FLOAT, 4, {16, 16, 16, 16}, "rgba16f"},
{PL_FMT_FLOAT, 4, {32, 32, 32, 32}, "rgba32f"},
{PL_FMT_FLOAT, 3, {11, 11, 10}, "r11f_g11f_b10f"},

{PL_FMT_UNORM, 1, {8}, "r8"},
{PL_FMT_UNORM, 1, {16}, "r16"},
{PL_FMT_UNORM, 2, {8, 8}, "rg8"},
{PL_FMT_UNORM, 2, {16, 16}, "rg16"},
{PL_FMT_UNORM, 4, {8, 8, 8, 8}, "rgba8"},
{PL_FMT_UNORM, 4, {16, 16, 16, 16}, "rgba16"},
{PL_FMT_UNORM, 4, {10, 10, 10, 2}, "rgb10_a2"},

{PL_FMT_SNORM, 1, {8}, "r8_snorm"},
{PL_FMT_SNORM, 1, {16}, "r16_snorm"},
{PL_FMT_SNORM, 2, {8, 8}, "rg8_snorm"},
{PL_FMT_SNORM, 2, {16, 16}, "rg16_snorm"},
{PL_FMT_SNORM, 4, {8, 8, 8, 8}, "rgba8_snorm"},
{PL_FMT_SNORM, 4, {16, 16, 16, 16}, "rgba16_snorm"},

{PL_FMT_UINT, 1, {8}, "r8ui"},
{PL_FMT_UINT, 1, {16}, "r16ui"},
{PL_FMT_UINT, 1, {32}, "r32ui"},
{PL_FMT_UINT, 2, {8, 8}, "rg8ui"},
{PL_FMT_UINT, 2, {16, 16}, "rg16ui"},
{PL_FMT_UINT, 2, {32, 32}, "rg32ui"},
{PL_FMT_UINT, 4, {8, 8, 8, 8}, "rgba8ui"},
{PL_FMT_UINT, 4, {16, 16, 16, 16}, "rgba16ui"},
{PL_FMT_UINT, 4, {32, 32, 32, 32}, "rgba32ui"},
{PL_FMT_UINT, 4, {10, 10, 10, 2}, "rgb10_a2ui"},

{PL_FMT_SINT, 1, {8}, "r8i"},
{PL_FMT_SINT, 1, {16}, "r16i"},
{PL_FMT_SINT, 1, {32}, "r32i"},
{PL_FMT_SINT, 2, {8, 8}, "rg8i"},
{PL_FMT_SINT, 2, {16, 16}, "rg16i"},
{PL_FMT_SINT, 2, {32, 32}, "rg32i"},
{PL_FMT_SINT, 4, {8, 8, 8, 8}, "rgba8i"},
{PL_FMT_SINT, 4, {16, 16, 16, 16}, "rgba16i"},
{PL_FMT_SINT, 4, {32, 32, 32, 32}, "rgba32i"},
// List taken from the OpenGL specification (4.6, table 8.12).
static const struct glsl_fmt pl_color_fmts[] = {
{PL_FMT_UNORM, 1, {8}, "r8", true},
{PL_FMT_SNORM, 1, {8}, "r8_snorm", true},
{PL_FMT_UNORM, 1, {16}, "r16", true},
{PL_FMT_SNORM, 1, {16}, "r16_snorm", true},
{PL_FMT_UNORM, 2, {8, 8}, "rg8", true},
{PL_FMT_SNORM, 2, {8, 8}, "rg8_snorm", true},
{PL_FMT_UNORM, 2, {16, 16}, "rg16", true},
{PL_FMT_SNORM, 2, {16, 16}, "rg16_snorm", true},
{PL_FMT_UNORM, 3, {3, 3, 2}, "r3_g3_b2"},
{PL_FMT_UNORM, 3, {4, 4, 4}, "rgb4"},
{PL_FMT_UNORM, 3, {5, 5, 5}, "rgb5"},
{PL_FMT_UNORM, 3, {5, 6, 5}, "rgb565"},
{PL_FMT_UNORM, 3, {8, 8, 8}, "rgb8"},
{PL_FMT_SNORM, 3, {8, 8, 8}, "rgb8_snorm"},
{PL_FMT_UNORM, 3, {10, 10, 10}, "rgb10"},
{PL_FMT_UNORM, 3, {12, 12, 12}, "rgb12"},
{PL_FMT_UNORM, 3, {16, 16, 16}, "rgb16"},
{PL_FMT_SNORM, 3, {16, 16, 16}, "rgb16_snorm"},
{PL_FMT_UNORM, 4, {2, 2, 2, 2}, "rgba2"},
{PL_FMT_UNORM, 4, {4, 4, 4, 4}, "rgba4"},
{PL_FMT_UNORM, 4, {5, 5, 5, 1}, "rgb5_a1"},
{PL_FMT_UNORM, 4, {8, 8, 8, 8}, "rgba8", true},
{PL_FMT_SNORM, 4, {8, 8, 8, 8}, "rgba8_snorm", true},
{PL_FMT_UNORM, 4, {10, 10, 10, 2}, "rgb10_a2", true},
{PL_FMT_UINT, 4, {10, 10, 10, 2}, "rgb10_a2ui", true},
{PL_FMT_UNORM, 4, {12, 12, 12, 12}, "rgba12"},
{PL_FMT_UNORM, 4, {16, 16, 16, 16}, "rgba16", true},
{PL_FMT_SNORM, 4, {16, 16, 16, 16}, "rgba16_snorm", true},
// SRGB8 is omitted
// SRGB8_ALPHA8 is omitted
{PL_FMT_FLOAT, 1, {16}, "r16f", true},
{PL_FMT_FLOAT, 2, {16, 16}, "rg16f", true},
{PL_FMT_FLOAT, 3, {16, 16, 16}, "rgb16f"},
{PL_FMT_FLOAT, 4, {16, 16, 16, 16}, "rgba16f", true},
{PL_FMT_FLOAT, 1, {32}, "r32f", true},
{PL_FMT_FLOAT, 2, {32, 32}, "rg32f", true},
{PL_FMT_FLOAT, 3, {32, 32, 32}, "rgb32f"},
{PL_FMT_FLOAT, 4, {32, 32, 32, 32}, "rgba32f", true},
{PL_FMT_FLOAT, 3, {11, 11, 10}, "r11f_g11f_b10f", true},
// RGB9_E5 is omitted
{PL_FMT_SINT, 1, {8}, "r8i", true},
{PL_FMT_UINT, 1, {8}, "r8ui", true},
{PL_FMT_SINT, 1, {16}, "r16i", true},
{PL_FMT_UINT, 1, {16}, "r16ui", true},
{PL_FMT_SINT, 1, {32}, "r32i", true},
{PL_FMT_UINT, 1, {32}, "r32ui", true},
{PL_FMT_SINT, 2, {8, 8}, "rg8i", true},
{PL_FMT_UINT, 2, {8, 8}, "rg8ui", true},
{PL_FMT_SINT, 2, {16, 16}, "rg16i", true},
{PL_FMT_UINT, 2, {16, 16}, "rg16ui", true},
{PL_FMT_SINT, 2, {32, 32}, "rg32i", true},
{PL_FMT_UINT, 2, {32, 32}, "rg32ui", true},
{PL_FMT_SINT, 3, {8, 8, 8}, "rgb8i"},
{PL_FMT_UINT, 3, {8, 8, 8}, "rgb8ui"},
{PL_FMT_SINT, 3, {16, 16, 16}, "rgb16i"},
{PL_FMT_UINT, 3, {16, 16, 16}, "rgb16ui"},
{PL_FMT_SINT, 3, {32, 32, 32}, "rgb32i"},
{PL_FMT_UINT, 3, {32, 32, 32}, "rgb32ui"},
{PL_FMT_SINT, 4, {8, 8, 8, 8}, "rgba8i", true},
{PL_FMT_UINT, 4, {8, 8, 8, 8}, "rgba8ui", true},
{PL_FMT_SINT, 4, {16, 16, 16, 16}, "rgba16i", true},
{PL_FMT_UINT, 4, {16, 16, 16, 16}, "rgba16ui", true},
{PL_FMT_SINT, 4, {32, 32, 32, 32}, "rgba32i", true},
{PL_FMT_UINT, 4, {32, 32, 32, 32}, "rgba32ui", true},
};

const char *pl_fmt_glsl_format(pl_fmt fmt, int components)
const char *pl_fmt_color_format(pl_fmt fmt, int components, bool only_glsl)
{
if (fmt->opaque)
return NULL;

for (int n = 0; n < PL_ARRAY_SIZE(pl_glsl_fmts); n++) {
const struct glsl_fmt *gfmt = &pl_glsl_fmts[n];
for (int n = 0; n < PL_ARRAY_SIZE(pl_color_fmts); n++) {
const struct glsl_fmt *gfmt = &pl_color_fmts[n];

if (fmt->type != gfmt->type)
continue;
if (components != gfmt->num_components)
continue;
if (only_glsl && !gfmt->glsl)
continue;

// The component order is irrelevant, so we need to sort the depth
// based on the component's index
Expand All @@ -356,14 +379,19 @@ const char *pl_fmt_glsl_format(pl_fmt fmt, int components)
goto next_fmt;
}

return gfmt->glsl_format;
return gfmt->format;

next_fmt: ; // equivalent to `continue`
}

return NULL;
}

const char *pl_fmt_glsl_format(pl_fmt fmt, int components)
{
return pl_fmt_color_format(fmt, components, true);
}

#define FOURCC(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))

Expand Down
4 changes: 4 additions & 0 deletions src/opengl/gpu_tex.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ pl_tex gl_tex_create(pl_gpu gpu, const struct pl_tex_params *params)
return NULL;
}

const char *pl_fmt_color_format(pl_fmt fmt, int components, bool only_glsl);

static bool gl_fb_query(pl_gpu gpu, int fbo, struct pl_fmt_t *fmt,
struct gl_format *glfmt)
{
Expand Down Expand Up @@ -570,6 +572,8 @@ static bool gl_fb_query(pl_gpu gpu, int fbo, struct pl_fmt_t *fmt,
fmt->host_bits[i] = 8 * host_size;
fmt->caps |= PL_FMT_CAP_HOST_READABLE;

fmt->name = pl_fmt_color_format(fmt, fmt->num_components, false);

return true;
}

Expand Down