2 * Copyright (c) 2014 Intel Corporation
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:
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
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
25 #include "main/context.h"
26 #include "main/blend.h"
27 #include "main/mtypes.h"
28 #include "main/samplerobj.h"
29 #include "main/texformat.h"
30 #include "program/prog_parameter.h"
32 #include "intel_mipmap_tree.h"
33 #include "intel_batchbuffer.h"
34 #include "intel_tex.h"
35 #include "intel_fbo.h"
36 #include "intel_buffer_objects.h"
38 #include "brw_context.h"
39 #include "brw_state.h"
40 #include "brw_defines.h"
44 * Sets up a surface state structure to point at the given region.
45 * While it is only used for the front/back buffer currently, it should be
46 * usable for further buffers when doing ARB_draw_buffer support.
49 gen6_update_renderbuffer_surface(struct brw_context
*brw
,
50 struct gl_renderbuffer
*rb
,
51 bool layered
, unsigned unit
/* unused */,
54 struct gl_context
*ctx
= &brw
->ctx
;
55 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
56 struct intel_mipmap_tree
*mt
= irb
->mt
;
61 mesa_format rb_format
= _mesa_get_render_format(ctx
, intel_rb_format(irb
));
63 int depth
= MAX2(irb
->layer_count
, 1);
64 const GLenum gl_target
=
65 rb
->TexImage
? rb
->TexImage
->TexObject
->Target
: GL_TEXTURE_2D
;
67 intel_miptree_used_for_rendering(irb
->mt
);
69 surf
= brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
, 6 * 4, 32, &offset
);
71 format
= brw
->render_target_format
[rb_format
];
72 if (unlikely(!brw
->format_supported_as_render_target
[rb_format
])) {
73 _mesa_problem(ctx
, "%s: renderbuffer format %s unsupported\n",
74 __func__
, _mesa_get_format_name(rb_format
));
78 case GL_TEXTURE_CUBE_MAP_ARRAY
:
79 case GL_TEXTURE_CUBE_MAP
:
80 surftype
= BRW_SURFACE_2D
;
84 depth
= MAX2(irb
->mt
->logical_depth0
, 1);
87 surftype
= translate_tex_target(gl_target
);
91 const int min_array_element
= irb
->mt_layer
;
92 assert(!layered
|| irb
->mt_layer
== 0);
94 surf
[0] = SET_FIELD(surftype
, BRW_SURFACE_TYPE
) |
95 SET_FIELD(format
, BRW_SURFACE_FORMAT
);
98 assert(mt
->offset
% mt
->cpp
== 0);
99 surf
[1] = mt
->bo
->offset64
+ mt
->offset
;
101 /* In the gen6 PRM Volume 1 Part 1: Graphics Core, Section 7.18.3.7.1
102 * (Surface Arrays For all surfaces other than separate stencil buffer):
104 * "[DevSNB] Errata: Sampler MSAA Qpitch will be 4 greater than the value
105 * calculated in the equation above , for every other odd Surface Height
106 * starting from 1 i.e. 1,5,9,13"
108 * Since this Qpitch errata only impacts the sampler, we have to adjust the
109 * input for the rendering surface to achieve the same qpitch. For the
110 * affected heights, we increment the height by 1 for the rendering
113 int height0
= irb
->mt
->logical_height0
;
114 if (brw
->gen
== 6 && irb
->mt
->num_samples
> 1 && (height0
% 4) == 1)
117 surf
[2] = SET_FIELD(mt
->logical_width0
- 1, BRW_SURFACE_WIDTH
) |
118 SET_FIELD(height0
- 1, BRW_SURFACE_HEIGHT
) |
119 SET_FIELD(irb
->mt_level
- irb
->mt
->first_level
, BRW_SURFACE_LOD
);
121 surf
[3] = brw_get_surface_tiling_bits(mt
->tiling
) |
122 SET_FIELD(depth
- 1, BRW_SURFACE_DEPTH
) |
123 SET_FIELD(mt
->pitch
- 1, BRW_SURFACE_PITCH
);
125 surf
[4] = brw_get_surface_num_multisamples(mt
->num_samples
) |
126 SET_FIELD(min_array_element
, BRW_SURFACE_MIN_ARRAY_ELEMENT
) |
127 SET_FIELD(depth
- 1, BRW_SURFACE_RENDER_TARGET_VIEW_EXTENT
);
129 surf
[5] = (mt
->align_h
== 4 ? BRW_SURFACE_VERTICAL_ALIGN_ENABLE
: 0);
131 drm_intel_bo_emit_reloc(brw
->batch
.bo
,
134 surf
[1] - mt
->bo
->offset64
,
135 I915_GEM_DOMAIN_RENDER
,
136 I915_GEM_DOMAIN_RENDER
);
142 gen6_init_vtable_surface_functions(struct brw_context
*brw
)
144 gen4_init_vtable_surface_functions(brw
);
145 brw
->vtbl
.update_renderbuffer_surface
= gen6_update_renderbuffer_surface
;