xref: /linux/drivers/gpu/drm/amd/display/dc/dc_spl_translate.c (revision b7a08552e11fb5f1b9544e251f56660fcfee3dc2)
1 // SPDX-License-Identifier: MIT
2 //
3 // Copyright 2024 Advanced Micro Devices, Inc.
4 
5 #include "dc_spl_translate.h"
6 #include "spl/dc_spl_types.h"
7 #include "dcn20/dcn20_dpp.h"
8 #include "dcn32/dcn32_dpp.h"
9 #include "dcn401/dcn401_dpp.h"
10 
11 static struct spl_funcs dcn2_spl_funcs = {
12 	.spl_calc_lb_num_partitions = dscl2_spl_calc_lb_num_partitions,
13 };
14 static struct spl_funcs dcn32_spl_funcs = {
15 	.spl_calc_lb_num_partitions = dscl32_spl_calc_lb_num_partitions,
16 };
17 static struct spl_funcs dcn401_spl_funcs = {
18 	.spl_calc_lb_num_partitions = dscl401_spl_calc_lb_num_partitions,
19 };
20 static void populate_splrect_from_rect(struct spl_rect *spl_rect, const struct rect *rect)
21 {
22 	spl_rect->x = rect->x;
23 	spl_rect->y = rect->y;
24 	spl_rect->width = rect->width;
25 	spl_rect->height = rect->height;
26 }
27 static void populate_rect_from_splrect(struct rect *rect, const struct spl_rect *spl_rect)
28 {
29 	rect->x = spl_rect->x;
30 	rect->y = spl_rect->y;
31 	rect->width = spl_rect->width;
32 	rect->height = spl_rect->height;
33 }
34 static void populate_spltaps_from_taps(struct spl_taps *spl_scaling_quality,
35 		const struct scaling_taps *scaling_quality)
36 {
37 	spl_scaling_quality->h_taps_c = scaling_quality->h_taps_c;
38 	spl_scaling_quality->h_taps = scaling_quality->h_taps;
39 	spl_scaling_quality->v_taps_c = scaling_quality->v_taps_c;
40 	spl_scaling_quality->v_taps = scaling_quality->v_taps;
41 }
42 static void populate_taps_from_spltaps(struct scaling_taps *scaling_quality,
43 		const struct spl_taps *spl_scaling_quality)
44 {
45 	scaling_quality->h_taps_c = spl_scaling_quality->h_taps_c;
46 	scaling_quality->h_taps = spl_scaling_quality->h_taps;
47 	scaling_quality->v_taps_c = spl_scaling_quality->v_taps_c;
48 	scaling_quality->v_taps = spl_scaling_quality->v_taps;
49 }
50 static void populate_ratios_from_splratios(struct scaling_ratios *ratios,
51 		const struct spl_ratios *spl_ratios)
52 {
53 	ratios->horz = spl_ratios->horz;
54 	ratios->vert = spl_ratios->vert;
55 	ratios->horz_c = spl_ratios->horz_c;
56 	ratios->vert_c = spl_ratios->vert_c;
57 }
58 static void populate_inits_from_splinits(struct scl_inits *inits,
59 		const struct spl_inits *spl_inits)
60 {
61 	inits->h = spl_inits->h;
62 	inits->v = spl_inits->v;
63 	inits->h_c = spl_inits->h_c;
64 	inits->v_c = spl_inits->v_c;
65 }
66 /// @brief Translate SPL input parameters from pipe context
67 /// @param pipe_ctx
68 /// @param spl_in
69 void translate_SPL_in_params_from_pipe_ctx(struct pipe_ctx *pipe_ctx, struct spl_in *spl_in)
70 {
71 	const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
72 	const struct dc_stream_state *stream = pipe_ctx->stream;
73 	// Assign the function to calculate the number of partitions in the line buffer
74 	// This is used to determine the vtap support
75 	switch (plane_state->ctx->dce_version)	{
76 	case DCN_VERSION_2_0:
77 		spl_in->funcs = &dcn2_spl_funcs;
78 		break;
79 	case DCN_VERSION_3_2:
80 		spl_in->funcs = &dcn32_spl_funcs;
81 		break;
82 	case DCN_VERSION_4_01:
83 		spl_in->funcs = &dcn401_spl_funcs;
84 		break;
85 	default:
86 		spl_in->funcs = &dcn2_spl_funcs;
87 	}
88 	// Make format field from spl_in point to plane_res scl_data format
89 	spl_in->basic_in.format = (enum spl_pixel_format)pipe_ctx->plane_res.scl_data.format;
90 	// Make view_format from basic_out point to view_format from stream
91 	spl_in->basic_out.view_format = (enum spl_view_3d)stream->view_format;
92 	// Populate spl input basic input clip rect from plane state clip rect
93 	populate_splrect_from_rect(&spl_in->basic_in.clip_rect, &plane_state->clip_rect);
94 	// Populate spl input basic out src rect from stream src rect
95 	populate_splrect_from_rect(&spl_in->basic_out.src_rect, &stream->src);
96 	// Populate spl input basic out dst rect from stream dst rect
97 	populate_splrect_from_rect(&spl_in->basic_out.dst_rect, &stream->dst);
98 	// Make spl input basic input info rotation field point to plane state rotation
99 	spl_in->basic_in.rotation = (enum spl_rotation_angle)plane_state->rotation;
100 	// Populate spl input basic input src rect from plane state src rect
101 	populate_splrect_from_rect(&spl_in->basic_in.src_rect, &plane_state->src_rect);
102 	// Populate spl input basic input dst rect from plane state dst rect
103 	populate_splrect_from_rect(&spl_in->basic_in.dst_rect, &plane_state->dst_rect);
104 	// Make spl input basic input info horiz mirror field point to plane state horz mirror
105 	spl_in->basic_in.horizontal_mirror = plane_state->horizontal_mirror;
106 
107 	// Calculate horizontal splits and split index
108 	spl_in->basic_in.mpc_combine_h = resource_get_mpc_slice_count(pipe_ctx);
109 
110 	if (stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE)
111 		spl_in->basic_in.mpc_combine_v = 0;
112 	else
113 		spl_in->basic_in.mpc_combine_v = resource_get_mpc_slice_index(pipe_ctx);
114 
115 	spl_in->basic_out.odm_combine_factor = resource_get_odm_slice_count(pipe_ctx);
116 	spl_in->odm_slice_index = resource_get_odm_slice_index(pipe_ctx);
117 	// Make spl input basic out info output_size width point to stream h active
118 	spl_in->basic_out.output_size.width =
119 		stream->timing.h_addressable + stream->timing.h_border_left + stream->timing.h_border_right;
120 	// Make spl input basic out info output_size height point to v active
121 	spl_in->basic_out.output_size.height =
122 		stream->timing.v_addressable + stream->timing.v_border_bottom + stream->timing.v_border_top;
123 	spl_in->basic_out.max_downscale_src_width =
124 			pipe_ctx->stream->ctx->dc->debug.max_downscale_src_width;
125 	spl_in->basic_out.always_scale = pipe_ctx->stream->ctx->dc->debug.always_scale;
126 	// Make spl input basic output info alpha_en field point to plane res scl_data lb_params alpha_en
127 	spl_in->basic_out.alpha_en = pipe_ctx->plane_res.scl_data.lb_params.alpha_en;
128 	// Make spl input basic input info scaling quality field point to plane state scaling_quality
129 	populate_spltaps_from_taps(&spl_in->scaling_quality, &plane_state->scaling_quality);
130 	// Translate edge adaptive scaler preference
131 	spl_in->prefer_easf = pipe_ctx->stream->ctx->dc->config.prefer_easf;
132 	spl_in->disable_easf = false;
133 	if (pipe_ctx->stream->ctx->dc->debug.force_easf == 1)
134 		spl_in->prefer_easf = false;
135 	else if (pipe_ctx->stream->ctx->dc->debug.force_easf == 2)
136 		spl_in->disable_easf = true;
137 	/* Translate adaptive sharpening preference */
138 	if (pipe_ctx->stream->ctx->dc->debug.force_sharpness > 0) {
139 		spl_in->adaptive_sharpness.enable = (pipe_ctx->stream->ctx->dc->debug.force_sharpness > 1) ? true : false;
140 		if (pipe_ctx->stream->ctx->dc->debug.force_sharpness == 2)
141 			spl_in->adaptive_sharpness.sharpness = SHARPNESS_LOW;
142 		else if (pipe_ctx->stream->ctx->dc->debug.force_sharpness == 3)
143 			spl_in->adaptive_sharpness.sharpness = SHARPNESS_MID;
144 		else if (pipe_ctx->stream->ctx->dc->debug.force_sharpness >= 4)
145 			spl_in->adaptive_sharpness.sharpness = SHARPNESS_HIGH;
146 	} else {
147 		spl_in->adaptive_sharpness.enable = plane_state->adaptive_sharpness_en;
148 		if (plane_state->sharpnessX1000 == 0)
149 			spl_in->adaptive_sharpness.enable = false;
150 		else if (plane_state->sharpnessX1000 < 999)
151 			spl_in->adaptive_sharpness.sharpness = SHARPNESS_LOW;
152 		else if (plane_state->sharpnessX1000 < 1999)
153 			spl_in->adaptive_sharpness.sharpness = SHARPNESS_MID;
154 		else // Any other value is high sharpness
155 			spl_in->adaptive_sharpness.sharpness = SHARPNESS_HIGH;
156 	}
157 	// Translate linear light scaling preference
158 	if (pipe_ctx->stream->ctx->dc->debug.force_lls > 0)
159 		spl_in->lls_pref = pipe_ctx->stream->ctx->dc->debug.force_lls;
160 	else
161 		spl_in->lls_pref = plane_state->linear_light_scaling;
162 	/* Translate chroma subsampling offset ( cositing ) */
163 	if (pipe_ctx->stream->ctx->dc->debug.force_cositing)
164 		spl_in->basic_in.cositing = pipe_ctx->stream->ctx->dc->debug.force_cositing - 1;
165 	else
166 		spl_in->basic_in.cositing = plane_state->cositing;
167 	/* Translate transfer function */
168 	spl_in->basic_in.tf_type = (enum spl_transfer_func_type) plane_state->in_transfer_func.type;
169 	spl_in->basic_in.tf_predefined_type = (enum spl_transfer_func_predefined) plane_state->in_transfer_func.tf;
170 
171 }
172 
173 /// @brief Translate SPL output parameters to pipe context
174 /// @param pipe_ctx
175 /// @param spl_out
176 void translate_SPL_out_params_to_pipe_ctx(struct pipe_ctx *pipe_ctx, struct spl_out *spl_out)
177 {
178 	// Make scaler data recout point to spl output field recout
179 	populate_rect_from_splrect(&pipe_ctx->plane_res.scl_data.recout, &spl_out->scl_data.recout);
180 	// Make scaler data ratios point to spl output field ratios
181 	populate_ratios_from_splratios(&pipe_ctx->plane_res.scl_data.ratios, &spl_out->scl_data.ratios);
182 	// Make scaler data viewport point to spl output field viewport
183 	populate_rect_from_splrect(&pipe_ctx->plane_res.scl_data.viewport, &spl_out->scl_data.viewport);
184 	// Make scaler data viewport_c point to spl output field viewport_c
185 	populate_rect_from_splrect(&pipe_ctx->plane_res.scl_data.viewport_c, &spl_out->scl_data.viewport_c);
186 	// Make scaler data taps point to spl output field scaling taps
187 	populate_taps_from_spltaps(&pipe_ctx->plane_res.scl_data.taps, &spl_out->scl_data.taps);
188 	// Make scaler data init point to spl output field init
189 	populate_inits_from_splinits(&pipe_ctx->plane_res.scl_data.inits, &spl_out->scl_data.inits);
190 }
191