iris: comment everything
[mesa.git] / src / gallium / drivers / iris / iris_clear.c
1 /*
2 * Copyright © 2017 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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include <stdio.h>
24 #include <errno.h>
25 #include "pipe/p_defines.h"
26 #include "pipe/p_state.h"
27 #include "pipe/p_context.h"
28 #include "pipe/p_screen.h"
29 #include "util/u_inlines.h"
30 #include "util/u_format.h"
31 #include "util/u_upload_mgr.h"
32 #include "util/ralloc.h"
33 #include "iris_context.h"
34 #include "iris_resource.h"
35 #include "iris_screen.h"
36 #include "intel/compiler/brw_compiler.h"
37
38 /**
39 * The pipe->clear() driver hook.
40 *
41 * This clears buffers attached to the current draw framebuffer.
42 */
43 static void
44 iris_clear(struct pipe_context *ctx,
45 unsigned buffers,
46 const union pipe_color_union *p_color,
47 double depth,
48 unsigned stencil)
49 {
50 struct iris_context *ice = (void *) ctx;
51 struct pipe_framebuffer_state *cso_fb = &ice->state.framebuffer;
52 assert(buffers != 0);
53
54 struct iris_batch *batch = &ice->render_batch;
55
56 iris_batch_maybe_flush(batch, 1500);
57
58 struct blorp_batch blorp_batch;
59 blorp_batch_init(&ice->blorp, &blorp_batch, batch, 0);
60
61 if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
62 struct pipe_surface *psurf = cso_fb->zsbuf;
63 struct blorp_surf z_surf;
64 const unsigned num_layers =
65 psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1;
66
67 iris_blorp_surf_for_resource(&z_surf, psurf->texture,
68 ISL_AUX_USAGE_NONE, true);
69
70 blorp_clear_depth_stencil(&blorp_batch, &z_surf, NULL /* XXX */,
71 psurf->u.tex.level, psurf->u.tex.first_layer,
72 num_layers, 0, 0, psurf->width, psurf->height,
73 (buffers & PIPE_CLEAR_DEPTH) != 0,
74 depth, 0 /* XXX */, stencil);
75
76 if (buffers & PIPE_CLEAR_STENCIL)
77 fprintf(stderr, "XXX: stencil clears not implemented\n");
78 }
79
80 if (buffers & PIPE_CLEAR_COLOR) {
81 /* pipe_color_union and isl_color_value are interchangeable */
82 union isl_color_value *clear_color = (void *) p_color;
83 bool color_write_disable[4] = { false, false, false, false };
84
85 for (unsigned i = 0; i < cso_fb->nr_cbufs; i++) {
86 if (buffers & (PIPE_CLEAR_COLOR0 << i)) {
87 struct pipe_surface *psurf = cso_fb->cbufs[i];
88 struct iris_surface *isurf = (void *) psurf;
89 struct blorp_surf surf;
90
91 iris_blorp_surf_for_resource(&surf, psurf->texture,
92 ISL_AUX_USAGE_NONE, true);
93
94 blorp_clear(&blorp_batch, &surf, isurf->view.format,
95 ISL_SWIZZLE_IDENTITY,
96 psurf->u.tex.level, psurf->u.tex.first_layer,
97 psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1,
98 0, 0, psurf->width, psurf->height,
99 *clear_color, color_write_disable);
100 }
101 }
102 }
103
104 blorp_batch_finish(&blorp_batch);
105 }
106
107 static void
108 iris_clear_render_target(struct pipe_context *ctx,
109 struct pipe_surface *dst,
110 const union pipe_color_union *color,
111 unsigned dst_x, unsigned dst_y,
112 unsigned width, unsigned height,
113 bool render_condition_enabled)
114 {
115 fprintf(stderr, "XXX: iris_clear_render_target\n");
116 }
117
118 static void
119 iris_clear_depth_stencil(struct pipe_context *ctx,
120 struct pipe_surface *dst,
121 unsigned clear_flags,
122 double depth,
123 unsigned stencil,
124 unsigned dst_x, unsigned dst_y,
125 unsigned width, unsigned height,
126 bool render_condition_enabled)
127 {
128 fprintf(stderr, "XXX: iris_clear_depth_stencil\n");
129 }
130
131 void
132 iris_init_clear_functions(struct pipe_context *ctx)
133 {
134 ctx->clear = iris_clear;
135 ctx->clear_render_target = iris_clear_render_target;
136 ctx->clear_depth_stencil = iris_clear_depth_stencil;
137 }