diff options
author | Nanley Chery <nanley.g.chery@intel.com> | 2022-01-20 14:45:22 -0500 |
---|---|---|
committer | Nanley Chery <nanley.g.chery@intel.com> | 2023-10-25 09:15:46 -0400 |
commit | 3d37330962c6181e864958d0475c7625efceec26 (patch) | |
tree | bab48aed675969990443ffb9261f2210279544ad | |
parent | fc0ea4746622f18c72a6b95929adc48a4f3ea090 (diff) |
modifiers: Try to autogenerate dmabufs
Provide surfaces to test in the absence of binaries. We don't attempt
this for external-only modifiers.
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/846>
-rw-r--r-- | tests/spec/ext_image_dma_buf_import/modifiers.c | 103 |
1 files changed, 89 insertions, 14 deletions
diff --git a/tests/spec/ext_image_dma_buf_import/modifiers.c b/tests/spec/ext_image_dma_buf_import/modifiers.c index 8cece21f9..d6d387c67 100644 --- a/tests/spec/ext_image_dma_buf_import/modifiers.c +++ b/tests/spec/ext_image_dma_buf_import/modifiers.c @@ -21,6 +21,7 @@ * IN THE SOFTWARE. */ +#include "piglit-util-compressed-grays.h" #include "sample_common.h" #include "image_common.h" #include "drm-uapi/drm_fourcc.h" @@ -75,6 +76,25 @@ destroy_img(EGLImageKHR *img) } } +static int +cpp_for_fourcc(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_R8: + return 1; + case DRM_FORMAT_R16: + return 2; + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_ARGB8888: + return 4; + default: + fprintf(stderr, "invalid fourcc: %.4s\n", (char *)&format); + return 0; + } +} + static const char * modifier_str(EGLuint64KHR mod) @@ -129,18 +149,21 @@ format_no_space(int fmt) } static void -report_result(enum piglit_result res, int fmt, EGLuint64KHR mod, +report_result(enum piglit_result res, int fmt, EGLuint64KHR mod, bool autogen, const char *fn) { const char *mod_str = modifier_str(mod); const int fmt_no_space = format_no_space(fmt); + const char *gen_str = autogen ? "autogen" : "pregen"; if (mod_str) - piglit_report_subtest_result(res, "%.4s-%s-%s", - (char*)&fmt_no_space, mod_str, fn); + piglit_report_subtest_result(res, "%s-%.4s-%s-%s", + gen_str, (char*)&fmt_no_space, + mod_str, fn); else - piglit_report_subtest_result(res, "%.4s-0x%"PRIx64"-%s", - (char*)&fmt_no_space, mod, fn); + piglit_report_subtest_result(res, "%s-%.4s-0x%"PRIx64"-%s", + gen_str, (char*)&fmt_no_space, + mod, fn); } static enum piglit_result @@ -235,17 +258,61 @@ load_dma_buf_from_file(uint32_t format, EGLuint64KHR modifier, } static bool -get_dma_buf(uint32_t format, EGLuint64KHR modifier, bool external_only, - struct dma_buf_info *buf) +create_dma_buf(uint32_t format, EGLuint64KHR modifier, + struct dma_buf_info *buf) { - if (load_dma_buf_from_file(format, modifier, buf)) - return true; + /* Use 4KB worth of interesting data to initialize the dmabuf. */ + assert(sizeof(piglit_fxt1_grayscale_blocks) == 4 * 1024); + const char *src_data = (const char*)piglit_fxt1_grayscale_blocks; + const int num_pixels = sizeof(piglit_fxt1_grayscale_blocks) / + cpp_for_fourcc(format); + const int dim = sqrt((double)num_pixels); + + struct piglit_dma_buf *drm_buf = NULL; + enum piglit_result result = + piglit_drm_create_dma_buf_modifiers(dim, dim, format, + modifier, src_data, + &drm_buf); + + if (result != PIGLIT_PASS) { + piglit_drm_destroy_dma_buf(drm_buf); + return false; + } - return false; + buf->n_planes = drm_buf->n_planes; + assert(buf->n_planes <= ARRAY_SIZE(drm_buf->offset)); + for (int i = 0; i < buf->n_planes; i++) { + buf->offset[i] = drm_buf->offset[i]; + buf->stride[i] = drm_buf->stride[i]; + } + buf->fd = drm_buf->fd; + buf->w = drm_buf->w; + buf->h = drm_buf->h; + + piglit_drm_destroy_dma_buf(drm_buf); + return true; +} + +static bool +get_dma_buf(uint32_t format, EGLuint64KHR modifier, bool external_only, + struct dma_buf_info *buf, bool autogen) +{ + if (autogen) { + /* GL drivers are generally unable to create external-only + * images. We can load them from external sources, however. + */ + if (external_only) + return false; + + return create_dma_buf(format, modifier, buf); + } else { + return load_dma_buf_from_file(format, modifier, buf); + } } static enum piglit_result -modifier_test(uint32_t format, EGLuint64KHR modifier, bool external_only) +modifier_test(uint32_t format, EGLuint64KHR modifier, bool external_only, + bool autogen) { GLuint tex = 0; EGLImageKHR img = EGL_NO_IMAGE_KHR; @@ -253,7 +320,7 @@ modifier_test(uint32_t format, EGLuint64KHR modifier, bool external_only) enum piglit_result res = PIGLIT_SKIP; /* Create dma_buf_info. */ - if (!get_dma_buf(format, modifier, external_only, &buf)) { + if (!get_dma_buf(format, modifier, external_only, &buf, autogen)) { piglit_logd("No data found"); return PIGLIT_SKIP; } @@ -340,6 +407,12 @@ piglit_display(void) enum piglit_result result = PIGLIT_SKIP; + bool autogen[] = { false, true }; + + for (unsigned g = 0; g < ARRAY_SIZE(autogen); g++) { + printf(autogen[g] ? + "\n\nTesting with autogenerated dmabufs\n\n" : + "\n\nTesting with pregenerated binaries\n\n"); for (unsigned i = 0; i < num_formats; i++) { if (skip_format(formats[i])) continue; @@ -358,11 +431,13 @@ piglit_display(void) enum piglit_result r; r = modifier_test(fmt, modifiers[j], - external_only[j]); - report_result(r, fmt, modifiers[j], "modifiers_test"); + external_only[j], autogen[g]); + report_result(r, fmt, modifiers[j], + autogen[g], "modifiers_test"); piglit_merge_result(&result, r); } } + } return result; } |