Home | History | Annotate | Download | only in a5xx
      1 /*
      2  * Copyright (C) 2016 Rob Clark <robclark (at) freedesktop.org>
      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 FROM,
     20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21  * SOFTWARE.
     22  *
     23  * Authors:
     24  *    Rob Clark <robclark (at) freedesktop.org>
     25  */
     26 
     27 #include "pipe/p_screen.h"
     28 #include "util/u_format.h"
     29 
     30 #include "fd5_screen.h"
     31 #include "fd5_context.h"
     32 #include "fd5_format.h"
     33 #include "ir3_compiler.h"
     34 
     35 static boolean
     36 fd5_screen_is_format_supported(struct pipe_screen *pscreen,
     37 		enum pipe_format format,
     38 		enum pipe_texture_target target,
     39 		unsigned sample_count,
     40 		unsigned usage)
     41 {
     42 	unsigned retval = 0;
     43 
     44 	if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
     45 			(sample_count > 1) || /* TODO add MSAA */
     46 			!util_format_is_supported(format, usage)) {
     47 		DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
     48 				util_format_name(format), target, sample_count, usage);
     49 		return FALSE;
     50 	}
     51 
     52 	if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
     53 			(fd5_pipe2vtx(format) != (enum a5xx_vtx_fmt)~0)) {
     54 		retval |= PIPE_BIND_VERTEX_BUFFER;
     55 	}
     56 
     57 	if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
     58 			(target == PIPE_BUFFER ||
     59 			 util_format_get_blocksize(format) != 12) &&
     60 			(fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
     61 		retval |= PIPE_BIND_SAMPLER_VIEW;
     62 	}
     63 
     64 	if ((usage & (PIPE_BIND_RENDER_TARGET |
     65 				PIPE_BIND_DISPLAY_TARGET |
     66 				PIPE_BIND_SCANOUT |
     67 				PIPE_BIND_SHARED)) &&
     68 			(fd5_pipe2color(format) != (enum a5xx_color_fmt)~0) &&
     69 			(fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
     70 		retval |= usage & (PIPE_BIND_RENDER_TARGET |
     71 				PIPE_BIND_DISPLAY_TARGET |
     72 				PIPE_BIND_SCANOUT |
     73 				PIPE_BIND_SHARED);
     74 	}
     75 
     76 	if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
     77 			(fd5_pipe2depth(format) != (enum a5xx_depth_format)~0) &&
     78 			(fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
     79 		retval |= PIPE_BIND_DEPTH_STENCIL;
     80 	}
     81 
     82 	if ((usage & PIPE_BIND_INDEX_BUFFER) &&
     83 			(fd_pipe2index(format) != (enum pc_di_index_size)~0)) {
     84 		retval |= PIPE_BIND_INDEX_BUFFER;
     85 	}
     86 
     87 	if (retval != usage) {
     88 		DBG("not supported: format=%s, target=%d, sample_count=%d, "
     89 				"usage=%x, retval=%x", util_format_name(format),
     90 				target, sample_count, usage, retval);
     91 	}
     92 
     93 	return retval == usage;
     94 }
     95 
     96 void
     97 fd5_screen_init(struct pipe_screen *pscreen)
     98 {
     99 	struct fd_screen *screen = fd_screen(pscreen);
    100 	screen->max_rts = A5XX_MAX_RENDER_TARGETS;
    101 	screen->compiler = ir3_compiler_create(screen->dev, screen->gpu_id);
    102 	pscreen->context_create = fd5_context_create;
    103 	pscreen->is_format_supported = fd5_screen_is_format_supported;
    104 }
    105