i965: Use force_compat_profile driconf option
[mesa.git] / src / mesa / drivers / dri / i965 / brw_formatquery.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "brw_context.h"
25 #include "brw_state.h"
26 #include "main/context.h"
27 #include "main/formatquery.h"
28 #include "main/glformats.h"
29
30 static size_t
31 brw_query_samples_for_format(struct gl_context *ctx, GLenum target,
32 GLenum internalFormat, int samples[16])
33 {
34 struct brw_context *brw = brw_context(ctx);
35 const struct gen_device_info *devinfo = &brw->screen->devinfo;
36
37 (void) target;
38 (void) internalFormat;
39
40 switch (devinfo->gen) {
41 case 11:
42 case 10:
43 case 9:
44 samples[0] = 16;
45 samples[1] = 8;
46 samples[2] = 4;
47 samples[3] = 2;
48 return 4;
49
50 case 8:
51 samples[0] = 8;
52 samples[1] = 4;
53 samples[2] = 2;
54 return 3;
55
56 case 7:
57 if (internalFormat == GL_RGBA32F && _mesa_is_gles(ctx)) {
58 /* For GLES, we are allowed to return a smaller number of samples for
59 * GL_RGBA32F. See OpenGLES 3.2 spec, section 20.3.1 Internal Format
60 * Query Parameters, under SAMPLES:
61 *
62 * "A value less than or equal to the value of MAX_SAMPLES, if
63 * internalformat is RGBA16F, R32F, RG32F, or RGBA32F."
64 *
65 * In brw_render_target_supported, we prevent formats with a size
66 * greater than 8 bytes from using 8x MSAA on gen7.
67 */
68 samples[0] = 4;
69 return 1;
70 } else {
71 samples[0] = 8;
72 samples[1] = 4;
73 return 2;
74 }
75
76 case 6:
77 samples[0] = 4;
78 return 1;
79
80 default:
81 assert(devinfo->gen < 6);
82 samples[0] = 1;
83 return 1;
84 }
85 }
86
87 void
88 brw_query_internal_format(struct gl_context *ctx, GLenum target,
89 GLenum internalFormat, GLenum pname, GLint *params)
90 {
91 /* The Mesa layer gives us a temporary params buffer that is guaranteed
92 * to be non-NULL, and have at least 16 elements.
93 */
94 assert(params != NULL);
95
96 switch (pname) {
97 case GL_SAMPLES:
98 brw_query_samples_for_format(ctx, target, internalFormat, params);
99 break;
100
101 case GL_NUM_SAMPLE_COUNTS: {
102 size_t num_samples;
103 GLint dummy_buffer[16];
104
105 num_samples = brw_query_samples_for_format(ctx, target, internalFormat,
106 dummy_buffer);
107 params[0] = (GLint) num_samples;
108 break;
109 }
110
111 default:
112 /* By default, we call the driver hook's fallback function from the frontend,
113 * which has generic implementation for all pnames.
114 */
115 _mesa_query_internal_format_default(ctx, target, internalFormat, pname,
116 params);
117 break;
118 }
119 }