Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/*
2
 * Mesa 3-D graphics library
3
 *
4
 * Copyright (C) 2012-2013 LunarG, Inc.
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 shall be included
14
 * in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
23
 *
24
 * Authors:
25
 *    Chia-I Wu 
26
 */
27
 
28
#ifndef ILO_BLIT_H
29
#define ILO_BLIT_H
30
 
31
#include "ilo_common.h"
32
#include "ilo_context.h"
33
#include "ilo_state.h"
34
#include "ilo_resource.h"
35
 
36
void
37
ilo_blit_resolve_slices_for_hiz(struct ilo_context *ilo,
38
                                struct pipe_resource *res, unsigned level,
39
                                unsigned first_slice, unsigned num_slices,
40
                                unsigned resolve_flags);
41
 
42
static inline void
43
ilo_blit_resolve_slices(struct ilo_context *ilo,
44
                        struct pipe_resource *res, unsigned level,
45
                        unsigned first_slice, unsigned num_slices,
46
                        unsigned resolve_flags)
47
{
48
   struct ilo_texture *tex;
49
   unsigned slice_mask;
50
 
51
   if (res->target == PIPE_BUFFER)
52
      return;
53
 
54
   tex = ilo_texture(res);
55
 
56
   /*
57
    * This function is called frequently and we need to make it run faster.
58
    * As it is only used to resolve HiZ right now, return early when there is
59
    * no HiZ.
60
    */
61
   if (!ilo_image_can_enable_aux(&tex->image, level))
62
      return;
63
 
64
   if (ilo_image_can_enable_aux(&tex->image, level)) {
65
      ilo_blit_resolve_slices_for_hiz(ilo, res, level,
66
            first_slice, num_slices, resolve_flags);
67
   }
68
 
69
   slice_mask =
70
      ILO_TEXTURE_CPU_WRITE |
71
      ILO_TEXTURE_BLT_WRITE |
72
      ILO_TEXTURE_RENDER_WRITE;
73
   /* when there is a new writer, we may need to clear ILO_TEXTURE_CLEAR */
74
   if (resolve_flags & slice_mask)
75
      slice_mask |= ILO_TEXTURE_CLEAR;
76
 
77
   ilo_texture_set_slice_flags(tex, level,
78
         first_slice, num_slices, slice_mask, resolve_flags);
79
}
80
 
81
static inline void
82
ilo_blit_resolve_resource(struct ilo_context *ilo,
83
                          struct pipe_resource *res,
84
                          unsigned resolve_flags)
85
{
86
   unsigned lv;
87
 
88
   for (lv = 0; lv <= res->last_level; lv++) {
89
      const unsigned num_slices = (res->target == PIPE_TEXTURE_3D) ?
90
         u_minify(res->depth0, lv) : res->array_size;
91
 
92
      ilo_blit_resolve_slices(ilo, res, lv, 0, num_slices, resolve_flags);
93
   }
94
}
95
 
96
static inline void
97
ilo_blit_resolve_surface(struct ilo_context *ilo,
98
                         struct pipe_surface *surf,
99
                         unsigned resolve_flags)
100
{
101
   if (surf->texture->target == PIPE_BUFFER)
102
      return;
103
 
104
   ilo_blit_resolve_slices(ilo, surf->texture,
105
         surf->u.tex.level, surf->u.tex.first_layer,
106
         surf->u.tex.last_layer - surf->u.tex.first_layer + 1,
107
         resolve_flags);
108
}
109
 
110
static inline void
111
ilo_blit_resolve_transfer(struct ilo_context *ilo,
112
                          const struct pipe_transfer *xfer)
113
{
114
   unsigned resolve_flags = 0;
115
 
116
   if (xfer->resource->target == PIPE_BUFFER)
117
      return;
118
 
119
   if (xfer->usage & PIPE_TRANSFER_READ)
120
      resolve_flags |= ILO_TEXTURE_CPU_READ;
121
   if (xfer->usage & PIPE_TRANSFER_WRITE)
122
      resolve_flags |= ILO_TEXTURE_CPU_WRITE;
123
 
124
   ilo_blit_resolve_slices(ilo, xfer->resource, xfer->level,
125
         xfer->box.z, xfer->box.depth, resolve_flags);
126
}
127
 
128
static inline void
129
ilo_blit_resolve_view(struct ilo_context *ilo,
130
                      const struct pipe_sampler_view *view)
131
{
132
   const unsigned resolve_flags = ILO_TEXTURE_RENDER_READ;
133
   unsigned lv;
134
 
135
   if (view->texture->target == PIPE_BUFFER)
136
      return;
137
 
138
   for (lv = view->u.tex.first_level; lv <= view->u.tex.last_level; lv++) {
139
      unsigned first_slice, num_slices;
140
 
141
      if (view->texture->target == PIPE_TEXTURE_3D) {
142
         first_slice = 0;
143
         num_slices = u_minify(view->texture->depth0, lv);
144
      }
145
      else {
146
         first_slice = view->u.tex.first_layer;
147
         num_slices = view->u.tex.last_layer - view->u.tex.first_layer + 1;
148
      }
149
 
150
      ilo_blit_resolve_slices(ilo, view->texture,
151
            lv, first_slice, num_slices, resolve_flags);
152
   }
153
}
154
 
155
static inline void
156
ilo_blit_resolve_framebuffer(struct ilo_context *ilo)
157
{
158
   struct ilo_state_vector *vec = &ilo->state_vector;
159
   const struct pipe_framebuffer_state *fb = &vec->fb.state;
160
   unsigned sh, i;
161
 
162
   /* Not all bound views are sampled by the shaders.  How do we tell? */
163
   for (sh = 0; sh < Elements(vec->view); sh++) {
164
      for (i = 0; i < vec->view[sh].count; i++) {
165
         if (vec->view[sh].states[i])
166
            ilo_blit_resolve_view(ilo, vec->view[sh].states[i]);
167
      }
168
   }
169
 
170
   for (i = 0; i < fb->nr_cbufs; i++) {
171
      struct pipe_surface *surf = fb->cbufs[i];
172
      if (surf)
173
         ilo_blit_resolve_surface(ilo, surf, ILO_TEXTURE_RENDER_WRITE);
174
   }
175
 
176
   if (fb->zsbuf)
177
      ilo_blit_resolve_surface(ilo, fb->zsbuf, ILO_TEXTURE_RENDER_WRITE);
178
}
179
 
180
void
181
ilo_init_blit_functions(struct ilo_context *ilo);
182
 
183
#endif /* ILO_BLIT_H */