i965/miptree: Replace is_lossless_compressed with mt->aux_usage checks
[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
36 (void) target;
37 (void) internalFormat;
38
39 switch (brw->gen) {
40 case 10:
41 case 9:
42 samples[0] = 16;
43 samples[1] = 8;
44 samples[2] = 4;
45 samples[3] = 2;
46 return 4;
47
48 case 8:
49 samples[0] = 8;
50 samples[1] = 4;
51 samples[2] = 2;
52 return 3;
53
54 case 7:
55 if (internalFormat == GL_RGBA32F && _mesa_is_gles(ctx)) {
56 /* For GLES, we are allowed to return a smaller number of samples for
57 * GL_RGBA32F. See OpenGLES 3.2 spec, section 20.3.1 Internal Format
58 * Query Parameters, under SAMPLES:
59 *
60 * "A value less than or equal to the value of MAX_SAMPLES, if
61 * internalformat is RGBA16F, R32F, RG32F, or RGBA32F."
62 *
63 * In brw_render_target_supported, we prevent formats with a size
64 * greater than 8 bytes from using 8x MSAA on gen7.
65 */
66 samples[0] = 4;
67 return 1;
68 } else {
69 samples[0] = 8;
70 samples[1] = 4;
71 return 2;
72 }
73
74 case 6:
75 samples[0] = 4;
76 return 1;
77
78 default:
79 assert(brw->gen < 6);
80 samples[0] = 1;
81 return 1;
82 }
83 }
84
85 void
86 brw_query_internal_format(struct gl_context *ctx, GLenum target,
87 GLenum internalFormat, GLenum pname, GLint *params)
88 {
89 /* The Mesa layer gives us a temporary params buffer that is guaranteed
90 * to be non-NULL, and have at least 16 elements.
91 */
92 assert(params != NULL);
93
94 switch (pname) {
95 case GL_SAMPLES:
96 brw_query_samples_for_format(ctx, target, internalFormat, params);
97 break;
98
99 case GL_NUM_SAMPLE_COUNTS: {
100 size_t num_samples;
101 GLint dummy_buffer[16];
102
103 num_samples = brw_query_samples_for_format(ctx, target, internalFormat,
104 dummy_buffer);
105 params[0] = (GLint) num_samples;
106 break;
107 }
108
109 default:
110 /* By default, we call the driver hook's fallback function from the frontend,
111 * which has generic implementation for all pnames.
112 */
113 _mesa_query_internal_format_default(ctx, target, internalFormat, pname,
114 params);
115 break;
116 }
117 }