aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/i915/i915_state_static.c
blob: 20cd23f8f736cf833d5fced426f4763028d856cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**************************************************************************
 *
 * Copyright © 2010 Jakob Bornecrantz
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/


#include "i915_reg.h"
#include "i915_context.h"
#include "i915_state.h"
#include "i915_resource.h"



/***********************************************************************
 * Update framebuffer state
 */
static unsigned translate_format(enum pipe_format format)
{
   switch (format) {
   case PIPE_FORMAT_B8G8R8A8_UNORM:
      return COLOR_BUF_ARGB8888;
   case PIPE_FORMAT_B5G6R5_UNORM:
      return COLOR_BUF_RGB565;
   default:
      assert(0);
      return 0;
   }
}

static unsigned translate_depth_format(enum pipe_format zformat)
{
   switch (zformat) {
   case PIPE_FORMAT_Z24X8_UNORM:
   case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
      return DEPTH_FRMT_24_FIXED_8_OTHER;
   case PIPE_FORMAT_Z16_UNORM:
      return DEPTH_FRMT_16_FIXED;
   default:
      assert(0);
      return 0;
   }
}

static inline uint32_t
buf_3d_tiling_bits(enum i915_winsys_buffer_tile tiling)
{
   uint32_t tiling_bits = 0;

   switch (tiling) {
   case I915_TILE_Y:
      tiling_bits |= BUF_3D_TILE_WALK_Y;
   case I915_TILE_X:
      tiling_bits |= BUF_3D_TILED_SURFACE;
   case I915_TILE_NONE:
      break;
   }

   return tiling_bits;
}

/**
 * Examine framebuffer state to determine width, height.
 */
static boolean
framebuffer_size(const struct pipe_framebuffer_state *fb,
                 uint *width, uint *height)
{
   if (fb->cbufs[0]) {
      *width = fb->cbufs[0]->width;
      *height = fb->cbufs[0]->height;
      return TRUE;
   }
   else if (fb->zsbuf) {
      *width = fb->zsbuf->width;
      *height = fb->zsbuf->height;
      return TRUE;
   }
   else {
      *width = *height = 0;
      return FALSE;
   }
}

static void update_framebuffer(struct i915_context *i915)
{
   struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
   struct pipe_surface *depth_surface = i915->framebuffer.zsbuf;
   unsigned cformat, zformat;
   unsigned x, y, w, h;
   int layer;
   uint32_t draw_offset;
   boolean ret;

   if (cbuf_surface) {
      struct i915_texture *tex = i915_texture(cbuf_surface->texture);
      assert(tex);

      i915->current.cbuf_bo = tex->buffer;
      i915->current.cbuf_flags = BUF_3D_ID_COLOR_BACK |
                                 BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
                                 buf_3d_tiling_bits(tex->tiling);
      cformat = cbuf_surface->format;

      layer = cbuf_surface->u.tex.first_layer;

      x = tex->image_offset[cbuf_surface->u.tex.level][layer].nblocksx;
      y = tex->image_offset[cbuf_surface->u.tex.level][layer].nblocksy;
   } else {
      i915->current.cbuf_bo = NULL;
      cformat = PIPE_FORMAT_B8G8R8A8_UNORM; /* arbitrary */
      x = y = 0;
   }
   cformat = translate_format(cformat);

   /* What happens if no zbuf??
    */
   if (depth_surface) {
      struct i915_texture *tex = i915_texture(depth_surface->texture);
      unsigned offset = i915_texture_offset(tex, depth_surface->u.tex.level,
                                            depth_surface->u.tex.first_layer);
      assert(tex);
      assert(offset == 0);

      i915->current.depth_bo = tex->buffer;
      i915->current.depth_flags = BUF_3D_ID_DEPTH |
                                  BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
                                  buf_3d_tiling_bits(tex->tiling);
      zformat = translate_depth_format(depth_surface->format);
   } else {
      i915->current.depth_bo = NULL;
      zformat = 0;
   }

   i915->current.dst_buf_vars = DSTORG_HORT_BIAS(0x8) | /* .5 */
                                DSTORG_VERT_BIAS(0x8) | /* .5 */
                                LOD_PRECLAMP_OGL |
                                TEX_DEFAULT_COLOR_OGL |
                                cformat |
                                zformat;

   /* drawing rect calculations */
   draw_offset = x | (y << 16);
   ret = framebuffer_size(&i915->framebuffer, &w, &h);
   assert(ret);
   if (i915->current.draw_offset != draw_offset) {
      i915->current.draw_offset = draw_offset;
      i915_set_flush_dirty(i915, I915_PIPELINE_FLUSH);
   }
   i915->current.draw_size = (w - 1 + x) | ((h - 1 + y) << 16);

   i915->hardware_dirty |= I915_HW_STATIC;

   /* flush the cache in case we sample from the old renderbuffers */
   i915_set_flush_dirty(i915, I915_FLUSH_CACHE);
}

struct i915_tracked_state i915_hw_framebuffer = {
   "framebuffer",
   update_framebuffer,
   I915_NEW_FRAMEBUFFER
};