Add the uAPI for a fast-loading (DMA) 3D LUT colorop. Unlike the existing DRM_COLOROP_3D_LUT, which carries its data inline in a DATA blob, the DMA variant references a framebuffer (FB_ID) whose memory the HW DMAs into its LUT RAM, replacing a large register-write sequence with an address update.
The accepted buffer formats are advertised via a read-only LUT_3D_FORMATS blob - an array of the new struct drm_mode_3dlut_mode describing the grid size, entry encoding (fourcc), memory layout (modifier), row pitch, traversal order and interpolation. Removing the LUT framebuffer with RMFB, or closing the DRM file that owns it, bypasses the colorop and clears FB_ID, so the plane stays visible without the LUT. CLOSEFB leaves the colorop unchanged. Signed-off-by: Harry Wentland <[email protected]> --- drivers/gpu/drm/drm_atomic_uapi.c | 4 ++ drivers/gpu/drm/drm_colorop.c | 2 + include/uapi/drm/drm_mode.h | 79 +++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 1eebcf6f5e05..aca0edb42a5a 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -1374,6 +1374,10 @@ int drm_atomic_set_property(struct drm_atomic_commit *state, * If the Atomic Commit request has the DRM_MODE_ATOMIC_TEST_ONLY flag * it will only check if the Sync File is a valid one. * + * The fence also covers framebuffers referenced by the plane's colorops, + * such as the FB_ID of a DRM_COLOROP_3D_LUT_DMA colorop. Userspace using + * explicit sync for those merges their fences into IN_FENCE_FD. + * * On the driver side the fence is stored on the @fence parameter of * &struct drm_plane_state. Drivers which also support implicit fencing * should extract the implicit fence using drm_gem_plane_helper_prepare_fb(), diff --git a/drivers/gpu/drm/drm_colorop.c b/drivers/gpu/drm/drm_colorop.c index 95da03d6c65c..b30413ad797b 100644 --- a/drivers/gpu/drm/drm_colorop.c +++ b/drivers/gpu/drm/drm_colorop.c @@ -69,6 +69,7 @@ static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = { { DRM_COLOROP_MULTIPLIER, "Multiplier"}, { DRM_COLOROP_3D_LUT, "3D LUT"}, { DRM_COLOROP_FIXED_MATRIX, "Fixed Matrix"}, + { DRM_COLOROP_3D_LUT_DMA, "3D LUT DMA"}, }; static const char * const colorop_curve_1d_type_names[] = { @@ -688,6 +689,7 @@ static const char * const colorop_type_name[] = { [DRM_COLOROP_MULTIPLIER] = "Multiplier", [DRM_COLOROP_3D_LUT] = "3D LUT", [DRM_COLOROP_FIXED_MATRIX] = "Fixed Matrix", + [DRM_COLOROP_3D_LUT_DMA] = "3D LUT DMA", }; static const char * const colorop_lu3d_interpolation_name[] = { diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index ed1a660a3dfd..f788ece18d1f 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -967,6 +967,44 @@ enum drm_colorop_type { */ DRM_COLOROP_FIXED_MATRIX, + /** + * @DRM_COLOROP_3D_LUT_DMA: + * + * enum string "3D LUT DMA" + * + * A 3D LUT whose data is DMA'd from a framebuffer (via the FB_ID + * property) instead of being carried inline in a DATA blob. This lets + * the driver load the LUT with an address update instead of a large + * sequence of register writes. + * + * The accepted buffer formats are advertised via the read-only + * LUT_3D_FORMATS blob property, an array of struct drm_mode_3dlut_mode. + * Userspace selects one entry by index via the LUT_3D_FORMAT property + * and points FB_ID at a matching framebuffer. + * + * Rendering to the LUT framebuffer is synchronized like rendering to a + * plane framebuffer. With implicit sync the commit waits for the write + * fences on the framebuffer's buffer objects. With explicit sync + * userspace merges the fence for the LUT write into the IN_FENCE_FD of + * the colorop's plane. If IN_FENCE_FD is set, implicit write fences on + * the LUT framebuffer are ignored, as they are for the plane framebuffer. + * + * The hardware may read the LUT framebuffer at any time while a colorop + * state referencing it is current, not only for the first frame. + * Userspace must not write to a LUT framebuffer while it is attached. To + * change the LUT, write a different framebuffer and point FB_ID at it. + * The old framebuffer can be reused once the commit that replaced it has + * completed, e.g. after its flip event or OUT_FENCE_PTR fence. + * + * Removing the LUT framebuffer with RMFB, or closing the DRM file that + * owns it, clears FB_ID and sets BYPASS on every colorop using it, so + * the plane is shown without the LUT. Re-enabling the colorop requires + * a new FB_ID. CLOSEFB leaves the colorop unchanged. Closing the GEM + * handle or a DMA-BUF file descriptor of the LUT buffer does not affect + * the framebuffer. + */ + DRM_COLOROP_3D_LUT_DMA, + }; /** @@ -981,6 +1019,47 @@ enum drm_colorop_lut3d_interpolation_type { DRM_COLOROP_LUT3D_INTERPOLATION_TETRAHEDRAL, }; +/** + * enum drm_colorop_lut3d_traversal_order - cube axis enumeration order + * + * The order in which a 3D LUT's entries are to be traversed. + */ +enum drm_colorop_lut3d_traversal_order { + /** + * @DRM_COLOROP_LUT3D_TRAVERSAL_RGB: + * + * R varies fastest, then G, then B (B slowest). + */ + DRM_COLOROP_LUT3D_TRAVERSAL_RGB, +}; + +/** + * struct drm_mode_3dlut_mode - fast-loadable 3D LUT format + * @lut_size: number of entries along one cube edge (e.g. 17 for a 17^3 LUT) + * @format: DRM fourcc describing the encoding of a single entry + * @modifier: DRM format modifier describing how the entries are laid + * out in memory (e.g. DRM_FORMAT_MOD_LINEAR) + * @pitch: row stride in bytes + * @traversal_order: enum drm_colorop_lut3d_traversal_order describing how + * entries are traversed + * @interpolation: enum drm_colorop_lut3d_interpolation_type specifying how + * the HW interpolates between entries + * @flags: reserved, must be zero + * + * One entry of a &DRM_COLOROP_3D_LUT_DMA colorop's read-only LUT_3D_FORMATS + * blob. Userspace selects an entry by index via the LUT_3D_FORMAT property + * and points FB_ID at a matching framebuffer. + */ +struct drm_mode_3dlut_mode { + __u32 lut_size; + __u32 format; + __u64 modifier; + __u32 pitch; + __u16 traversal_order; + __u16 interpolation; + __u32 flags; +}; + /** * enum drm_colorop_lut1d_interpolation_type - type of interpolation for 1D LUTs */ -- 2.56.0
