Home | History | Annotate | Download | only in a3xx
      1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
      2 
      3 /*
      4  * Copyright (C) 2013 Rob Clark <robclark (at) freedesktop.org>
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice (including the next
     14  * paragraph) shall be included in all copies or substantial portions of the
     15  * Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     23  * SOFTWARE.
     24  *
     25  * Authors:
     26  *    Rob Clark <robclark (at) freedesktop.org>
     27  */
     28 
     29 #include "pipe/p_screen.h"
     30 #include "util/u_format.h"
     31 
     32 #include "fd3_screen.h"
     33 #include "fd3_context.h"
     34 #include "fd3_format.h"
     35 #include "ir3_compiler.h"
     36 
     37 static boolean
     38 fd3_screen_is_format_supported(struct pipe_screen *pscreen,
     39 		enum pipe_format format,
     40 		enum pipe_texture_target target,
     41 		unsigned sample_count,
     42 		unsigned usage)
     43 {
     44 	unsigned retval = 0;
     45 
     46 	if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
     47 			(sample_count > 1) || /* TODO add MSAA */
     48 			!util_format_is_supported(format, usage)) {
     49 		DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
     50 				util_format_name(format), target, sample_count, usage);
     51 		return FALSE;
     52 	}
     53 
     54 	if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
     55 			(fd3_pipe2vtx(format) != (enum a3xx_vtx_fmt)~0)) {
     56 		retval |= PIPE_BIND_VERTEX_BUFFER;
     57 	}
     58 
     59 	if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
     60 			(fd3_pipe2tex(format) != (enum a3xx_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 				PIPE_BIND_BLENDABLE)) &&
     69 			(fd3_pipe2color(format) != (enum a3xx_color_fmt)~0) &&
     70 			(fd3_pipe2tex(format) != (enum a3xx_tex_fmt)~0)) {
     71 		retval |= usage & (PIPE_BIND_RENDER_TARGET |
     72 				PIPE_BIND_DISPLAY_TARGET |
     73 				PIPE_BIND_SCANOUT |
     74 				PIPE_BIND_SHARED);
     75 		if (!util_format_is_pure_integer(format))
     76 			retval |= usage & PIPE_BIND_BLENDABLE;
     77 	}
     78 
     79 	if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
     80 			(fd_pipe2depth(format) != (enum adreno_rb_depth_format)~0) &&
     81 			(fd3_pipe2tex(format) != (enum a3xx_tex_fmt)~0)) {
     82 		retval |= PIPE_BIND_DEPTH_STENCIL;
     83 	}
     84 
     85 	if ((usage & PIPE_BIND_INDEX_BUFFER) &&
     86 			(fd_pipe2index(format) != (enum pc_di_index_size)~0)) {
     87 		retval |= PIPE_BIND_INDEX_BUFFER;
     88 	}
     89 
     90 	if (retval != usage) {
     91 		DBG("not supported: format=%s, target=%d, sample_count=%d, "
     92 				"usage=%x, retval=%x", util_format_name(format),
     93 				target, sample_count, usage, retval);
     94 	}
     95 
     96 	return retval == usage;
     97 }
     98 
     99 void
    100 fd3_screen_init(struct pipe_screen *pscreen)
    101 {
    102 	struct fd_screen *screen = fd_screen(pscreen);
    103 	screen->max_rts = A3XX_MAX_RENDER_TARGETS;
    104 	screen->compiler = ir3_compiler_create(screen->dev, screen->gpu_id);
    105 	pscreen->context_create = fd3_context_create;
    106 	pscreen->is_format_supported = fd3_screen_is_format_supported;
    107 }
    108