radeonsi: allow fewer input SGPRs in 2nd shader of merged shaders
[mesa.git] / src / gallium / state_trackers / va / picture_mjpeg.c
1 /**************************************************************************
2 *
3 * Copyright 2017 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "va_private.h"
29
30 void vlVaHandlePictureParameterBufferMJPEG(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
31 {
32 VAPictureParameterBufferJPEGBaseline *mjpeg = buf->data;
33 unsigned sf;
34 int i;
35
36 assert(buf->size >= sizeof(VAPictureParameterBufferJPEGBaseline) && buf->num_elements == 1);
37
38 context->desc.mjpeg.picture_parameter.picture_width = mjpeg->picture_width;
39 context->desc.mjpeg.picture_parameter.picture_height = mjpeg->picture_height;
40
41 for (i = 0; i < mjpeg->num_components; ++i) {
42 context->desc.mjpeg.picture_parameter.components[i].component_id =
43 mjpeg->components[i].component_id;
44 context->desc.mjpeg.picture_parameter.components[i].h_sampling_factor =
45 mjpeg->components[i].h_sampling_factor;
46 context->desc.mjpeg.picture_parameter.components[i].v_sampling_factor =
47 mjpeg->components[i].v_sampling_factor;
48 context->desc.mjpeg.picture_parameter.components[i].quantiser_table_selector =
49 mjpeg->components[i].quantiser_table_selector;
50
51 sf = mjpeg->components[i].h_sampling_factor << 4 | mjpeg->components[i].v_sampling_factor;
52 context->mjpeg.sampling_factor <<= 8;
53 context->mjpeg.sampling_factor |= sf;
54 }
55
56 context->desc.mjpeg.picture_parameter.num_components = mjpeg->num_components;
57 }
58
59 void vlVaHandleIQMatrixBufferMJPEG(vlVaContext *context, vlVaBuffer *buf)
60 {
61 VAIQMatrixBufferJPEGBaseline *mjpeg = buf->data;
62
63 assert(buf->size >= sizeof(VAIQMatrixBufferJPEGBaseline) && buf->num_elements == 1);
64
65 memcpy(&context->desc.mjpeg.quantization_table.load_quantiser_table, mjpeg->load_quantiser_table, 4);
66 memcpy(&context->desc.mjpeg.quantization_table.quantiser_table, mjpeg->quantiser_table, 4 * 64);
67 }
68
69 void vlVaHandleHuffmanTableBufferType(vlVaContext *context, vlVaBuffer *buf)
70 {
71 VAHuffmanTableBufferJPEGBaseline *mjpeg = buf->data;
72 int i;
73
74 assert(buf->size >= sizeof(VASliceParameterBufferJPEGBaseline) && buf->num_elements == 1);
75
76 for (i = 0; i < 2; ++i) {
77 context->desc.mjpeg.huffman_table.load_huffman_table[i] = mjpeg->load_huffman_table[i];
78
79 memcpy(&context->desc.mjpeg.huffman_table.table[i].num_dc_codes,
80 mjpeg->huffman_table[i].num_dc_codes, 16);
81 memcpy(&context->desc.mjpeg.huffman_table.table[i].dc_values,
82 mjpeg->huffman_table[i].dc_values, 12);
83 memcpy(&context->desc.mjpeg.huffman_table.table[i].num_ac_codes,
84 mjpeg->huffman_table[i].num_ac_codes, 16);
85 memcpy(&context->desc.mjpeg.huffman_table.table[i].ac_values,
86 mjpeg->huffman_table[i].ac_values, 162);
87 memcpy(&context->desc.mjpeg.huffman_table.table[i].pad, mjpeg->huffman_table[i].pad, 2);
88 }
89 }
90
91 void vlVaHandleSliceParameterBufferMJPEG(vlVaContext *context, vlVaBuffer *buf)
92 {
93 VASliceParameterBufferJPEGBaseline *mjpeg = buf->data;
94 int i;
95
96 assert(buf->size >= sizeof(VASliceParameterBufferJPEGBaseline) && buf->num_elements == 1);
97
98 context->desc.mjpeg.slice_parameter.slice_data_size = mjpeg->slice_data_size;
99 context->desc.mjpeg.slice_parameter.slice_data_offset = mjpeg->slice_data_offset;
100 context->desc.mjpeg.slice_parameter.slice_data_flag = mjpeg->slice_data_flag;
101 context->desc.mjpeg.slice_parameter.slice_horizontal_position = mjpeg->slice_horizontal_position;
102 context->desc.mjpeg.slice_parameter.slice_vertical_position = mjpeg->slice_vertical_position;
103
104 for (i = 0; i < mjpeg->num_components; ++i) {
105 context->desc.mjpeg.slice_parameter.components[i].component_selector =
106 mjpeg->components[i].component_selector;
107 context->desc.mjpeg.slice_parameter.components[i].dc_table_selector =
108 mjpeg->components[i].dc_table_selector;
109 context->desc.mjpeg.slice_parameter.components[i].ac_table_selector =
110 mjpeg->components[i].ac_table_selector;
111 }
112
113 context->desc.mjpeg.slice_parameter.num_components = mjpeg->num_components;
114 context->desc.mjpeg.slice_parameter.restart_interval = mjpeg->restart_interval;
115 context->desc.mjpeg.slice_parameter.num_mcus = mjpeg->num_mcus;
116 }