• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * Copyright (C) 2015 Intel Corporation.   All Rights Reserved.
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 "swr_context.h"
25 #include "swr_query.h"
26 
27 static void
swr_clear(struct pipe_context * pipe,unsigned buffers,const union pipe_color_union * color,double depth,unsigned stencil)28 swr_clear(struct pipe_context *pipe,
29           unsigned buffers,
30           const union pipe_color_union *color,
31           double depth,
32           unsigned stencil)
33 {
34    struct swr_context *ctx = swr_context(pipe);
35    struct pipe_framebuffer_state *fb = &ctx->framebuffer;
36 
37    UINT clearMask = 0;
38    unsigned layers = 0;
39 
40    if (!swr_check_render_cond(pipe))
41       return;
42 
43    swr_update_derived(pipe);
44 
45    if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {
46       for (unsigned i = 0; i < fb->nr_cbufs; ++i)
47          if (fb->cbufs[i] && (buffers & (PIPE_CLEAR_COLOR0 << i))) {
48             clearMask |= (SWR_ATTACHMENT_COLOR0_BIT << i);
49             layers = std::max(layers, fb->cbufs[i]->u.tex.last_layer -
50                                       fb->cbufs[i]->u.tex.first_layer + 1u);
51          }
52    }
53 
54    if (buffers & PIPE_CLEAR_DEPTH && fb->zsbuf) {
55       clearMask |= SWR_ATTACHMENT_DEPTH_BIT;
56       layers = std::max(layers, fb->zsbuf->u.tex.last_layer -
57                                 fb->zsbuf->u.tex.first_layer + 1u);
58    }
59 
60    if (buffers & PIPE_CLEAR_STENCIL && fb->zsbuf) {
61       clearMask |= SWR_ATTACHMENT_STENCIL_BIT;
62       layers = std::max(layers, fb->zsbuf->u.tex.last_layer -
63                                 fb->zsbuf->u.tex.first_layer + 1u);
64    }
65 
66 #if 0 // XXX HACK, override clear color alpha. On ubuntu, clears are
67       // transparent.
68    ((union pipe_color_union *)color)->f[3] = 1.0; /* cast off your const'd-ness */
69 #endif
70 
71    for (unsigned i = 0; i < layers; ++i) {
72       swr_update_draw_context(ctx);
73       SwrClearRenderTarget(ctx->swrContext, clearMask, i,
74                            color->f, depth, stencil,
75                            ctx->swr_scissor);
76 
77       // Mask out the attachments that are out of layers.
78       if (fb->zsbuf &&
79           (fb->zsbuf->u.tex.last_layer <= fb->zsbuf->u.tex.first_layer + i))
80          clearMask &= ~(SWR_ATTACHMENT_DEPTH_BIT | SWR_ATTACHMENT_STENCIL_BIT);
81       for (unsigned c = 0; c < fb->nr_cbufs; ++c) {
82          const struct pipe_surface *sf = fb->cbufs[c];
83          if (sf && (sf->u.tex.last_layer <= sf->u.tex.first_layer + i))
84             clearMask &= ~(SWR_ATTACHMENT_COLOR0_BIT << c);
85       }
86    }
87 }
88 
89 
90 #if 0 // XXX, these don't get called. how to get these called?  Do we need
91       // them?  Docs?
92 static void
93 swr_clear_render_target(struct pipe_context *pipe, struct pipe_surface *ps,
94                         const union pipe_color_union *color,
95                         unsigned x, unsigned y, unsigned w, unsigned h,
96                         bool render_condition_enabled)
97 {
98    struct swr_context *ctx = swr_context(pipe);
99    fprintf(stderr, "SWR swr_clear_render_target!\n");
100 
101    ctx->dirty |= SWR_NEW_FRAMEBUFFER | SWR_NEW_SCISSOR;
102 }
103 
104 static void
105 swr_clear_depth_stencil(struct pipe_context *pipe, struct pipe_surface *ps,
106                         unsigned buffers, double depth, unsigned stencil,
107                         unsigned x, unsigned y, unsigned w, unsigned h,
108                         bool render_condition_enabled)
109 {
110    struct swr_context *ctx = swr_context(pipe);
111    fprintf(stderr, "SWR swr_clear_depth_stencil!\n");
112 
113    ctx->dirty |= SWR_NEW_FRAMEBUFFER | SWR_NEW_SCISSOR;
114 }
115 
116 static void
117 swr_clear_buffer(struct pipe_context *pipe,
118                  struct pipe_resource *res,
119                  unsigned offset, unsigned size,
120                  const void *data, int data_size)
121 {
122    fprintf(stderr, "SWR swr_clear_buffer!\n");
123    struct swr_context *ctx = swr_context(pipe);
124    struct swr_resource *buf = swr_resource(res);
125    union pipe_color_union color;
126    enum pipe_format dst_fmt;
127    unsigned width, height, elements;
128 
129    assert(res->target == PIPE_BUFFER);
130    assert(buf);
131    assert(size % data_size == 0);
132 
133    SWR_SURFACE_STATE &swr_buffer = buf->swr;
134 
135    ctx->dirty |= SWR_NEW_FRAMEBUFFER | SWR_NEW_SCISSOR;
136 }
137 #endif
138 
139 
140 void
swr_clear_init(struct pipe_context * pipe)141 swr_clear_init(struct pipe_context *pipe)
142 {
143    pipe->clear = swr_clear;
144 #if 0 // XXX, these don't get called. how to get these called?  Do we need
145       // them?  Docs?
146    pipe->clear_render_target = swr_clear_render_target;
147    pipe->clear_depth_stencil = swr_clear_depth_stencil;
148    pipe->clear_buffer = swr_clear_buffer;
149 #endif
150 }
151