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