i965: Delete the intel_regions.c code.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_meta_updownsample.c
1 /*
2 * Copyright © 2014 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 * 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 "brw_context.h"
25 #include "intel_batchbuffer.h"
26 #include "intel_fbo.h"
27
28 #include "main/blit.h"
29 #include "main/buffers.h"
30 #include "main/fbobject.h"
31
32 #include "drivers/common/meta.h"
33
34 /**
35 * @file brw_meta_updownsample.c
36 *
37 * Implements upsampling and downsampling of miptrees for window system
38 * framebuffers.
39 */
40
41 /**
42 * Creates a new named renderbuffer that wraps the first slice
43 * of an existing miptree.
44 *
45 * Clobbers the current renderbuffer binding (ctx->CurrentRenderbuffer).
46 */
47 static GLuint
48 brw_get_rb_for_first_slice(struct brw_context *brw, struct intel_mipmap_tree *mt)
49 {
50 struct gl_context *ctx = &brw->ctx;
51 GLuint rbo;
52 struct gl_renderbuffer *rb;
53 struct intel_renderbuffer *irb;
54
55 /* This turns the GenRenderbuffers name into an actual struct
56 * intel_renderbuffer.
57 */
58 _mesa_GenRenderbuffers(1, &rbo);
59 _mesa_BindRenderbuffer(GL_RENDERBUFFER, rbo);
60
61 rb = ctx->CurrentRenderbuffer;
62 irb = intel_renderbuffer(rb);
63
64 rb->Format = mt->format;
65 rb->_BaseFormat = _mesa_base_fbo_format(ctx, mt->format);
66
67 rb->NumSamples = mt->num_samples;
68 rb->Width = mt->logical_width0;
69 rb->Height = mt->logical_height0;
70
71 intel_miptree_reference(&irb->mt, mt);
72
73 return rbo;
74 }
75
76 /**
77 * Implementation of up or downsampling for window-system MSAA miptrees.
78 */
79 void
80 brw_meta_updownsample(struct brw_context *brw,
81 struct intel_mipmap_tree *src_mt,
82 struct intel_mipmap_tree *dst_mt)
83 {
84 struct gl_context *ctx = &brw->ctx;
85 GLuint fbos[2], src_rbo, dst_rbo, src_fbo, dst_fbo;
86 GLenum drawbuffer;
87 GLbitfield attachment, blit_bit;
88
89 if (_mesa_get_format_base_format(src_mt->format) == GL_DEPTH_COMPONENT ||
90 _mesa_get_format_base_format(src_mt->format) == GL_DEPTH_STENCIL) {
91 attachment = GL_DEPTH_ATTACHMENT;
92 drawbuffer = GL_NONE;
93 blit_bit = GL_DEPTH_BUFFER_BIT;
94 } else {
95 attachment = GL_COLOR_ATTACHMENT0;
96 drawbuffer = GL_COLOR_ATTACHMENT0;
97 blit_bit = GL_COLOR_BUFFER_BIT;
98 }
99
100 intel_batchbuffer_emit_mi_flush(brw);
101
102 _mesa_meta_begin(ctx, MESA_META_ALL);
103 _mesa_GenFramebuffers(2, fbos);
104 src_rbo = brw_get_rb_for_first_slice(brw, src_mt);
105 dst_rbo = brw_get_rb_for_first_slice(brw, dst_mt);
106 src_fbo = fbos[0];
107 dst_fbo = fbos[1];
108
109 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, src_fbo);
110 _mesa_FramebufferRenderbuffer(GL_READ_FRAMEBUFFER, attachment,
111 GL_RENDERBUFFER, src_rbo);
112 _mesa_ReadBuffer(drawbuffer);
113
114 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, dst_fbo);
115 _mesa_FramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, attachment,
116 GL_RENDERBUFFER, dst_rbo);
117 _mesa_DrawBuffer(drawbuffer);
118
119 _mesa_BlitFramebuffer(0, 0,
120 src_mt->logical_width0, src_mt->logical_height0,
121 0, 0,
122 dst_mt->logical_width0, dst_mt->logical_height0,
123 blit_bit, GL_NEAREST);
124
125 _mesa_DeleteRenderbuffers(1, &src_rbo);
126 _mesa_DeleteRenderbuffers(1, &dst_rbo);
127 _mesa_DeleteFramebuffers(2, fbos);
128
129 _mesa_meta_end(ctx);
130
131 intel_batchbuffer_emit_mi_flush(brw);
132 }