brw_blorp_blit.cpp revision 082874e3891e588f674508be6578f600b35852c4
1506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/* 2506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Copyright © 2012 Intel Corporation 3506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 4506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Permission is hereby granted, free of charge, to any person obtaining a 5506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * copy of this software and associated documentation files (the "Software"), 6506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * to deal in the Software without restriction, including without limitation 7506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * and/or sell copies of the Software, and to permit persons to whom the 9506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Software is furnished to do so, subject to the following conditions: 10506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 11506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * The above copyright notice and this permission notice (including the next 12506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * paragraph) shall be included in all copies or substantial portions of the 13506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Software. 14506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 15506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * IN THE SOFTWARE. 22506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 23506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 24506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#include "main/teximage.h" 25506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 26506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#include "glsl/ralloc.h" 27506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 28506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#include "intel_fbo.h" 29506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 30506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#include "brw_blorp.h" 31506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#include "brw_context.h" 32506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#include "brw_eu.h" 33506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#include "brw_state.h" 34506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 35506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 36506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 37506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Helper function for handling mirror image blits. 38506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 39506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * If coord0 > coord1, swap them and invert the "mirror" boolean. 40506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 41506d70be21cd3469118de89297cba0c0f709c1aePaul Berrystatic inline void 42506d70be21cd3469118de89297cba0c0f709c1aePaul Berryfixup_mirroring(bool &mirror, GLint &coord0, GLint &coord1) 43506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 44506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (coord0 > coord1) { 45506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mirror = !mirror; 46506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint tmp = coord0; 47506d70be21cd3469118de89297cba0c0f709c1aePaul Berry coord0 = coord1; 48506d70be21cd3469118de89297cba0c0f709c1aePaul Berry coord1 = tmp; 49506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 50506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 51506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 52506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 5347b64c9290d54f78e5a20e378593977cd47e285fPaul Berry/** 5447b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * Adjust {src,dst}_x{0,1} to account for clipping and scissoring of 5547b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * destination coordinates. 5647b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * 5747b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * Return true if there is still blitting to do, false if all pixels got 5847b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * rejected by the clip and/or scissor. 5947b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * 6047b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * For clarity, the nomenclature of this function assumes we are clipping and 6147b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * scissoring the X coordinate; the exact same logic applies for Y 6247b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * coordinates. 6375f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry * 6475f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry * Note: this function may also be used to account for clipping of source 6575f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry * coordinates, by swapping the roles of src and dst. 6647b64c9290d54f78e5a20e378593977cd47e285fPaul Berry */ 6747b64c9290d54f78e5a20e378593977cd47e285fPaul Berrystatic inline bool 6847b64c9290d54f78e5a20e378593977cd47e285fPaul Berryclip_or_scissor(bool mirror, GLint &src_x0, GLint &src_x1, GLint &dst_x0, 6947b64c9290d54f78e5a20e378593977cd47e285fPaul Berry GLint &dst_x1, GLint fb_xmin, GLint fb_xmax) 7047b64c9290d54f78e5a20e378593977cd47e285fPaul Berry{ 7147b64c9290d54f78e5a20e378593977cd47e285fPaul Berry /* If we are going to scissor everything away, stop. */ 7247b64c9290d54f78e5a20e378593977cd47e285fPaul Berry if (!(fb_xmin < fb_xmax && 7347b64c9290d54f78e5a20e378593977cd47e285fPaul Berry dst_x0 < fb_xmax && 7447b64c9290d54f78e5a20e378593977cd47e285fPaul Berry fb_xmin < dst_x1 && 7547b64c9290d54f78e5a20e378593977cd47e285fPaul Berry dst_x0 < dst_x1)) { 7647b64c9290d54f78e5a20e378593977cd47e285fPaul Berry return false; 7747b64c9290d54f78e5a20e378593977cd47e285fPaul Berry } 7847b64c9290d54f78e5a20e378593977cd47e285fPaul Berry 7947b64c9290d54f78e5a20e378593977cd47e285fPaul Berry /* Clip the destination rectangle, and keep track of how many pixels we 8047b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * clipped off of the left and right sides of it. 8147b64c9290d54f78e5a20e378593977cd47e285fPaul Berry */ 8247b64c9290d54f78e5a20e378593977cd47e285fPaul Berry GLint pixels_clipped_left = 0; 8347b64c9290d54f78e5a20e378593977cd47e285fPaul Berry GLint pixels_clipped_right = 0; 8447b64c9290d54f78e5a20e378593977cd47e285fPaul Berry if (dst_x0 < fb_xmin) { 8547b64c9290d54f78e5a20e378593977cd47e285fPaul Berry pixels_clipped_left = fb_xmin - dst_x0; 8647b64c9290d54f78e5a20e378593977cd47e285fPaul Berry dst_x0 = fb_xmin; 8747b64c9290d54f78e5a20e378593977cd47e285fPaul Berry } 8847b64c9290d54f78e5a20e378593977cd47e285fPaul Berry if (fb_xmax < dst_x1) { 8947b64c9290d54f78e5a20e378593977cd47e285fPaul Berry pixels_clipped_right = dst_x1 - fb_xmax; 9047b64c9290d54f78e5a20e378593977cd47e285fPaul Berry dst_x1 = fb_xmax; 9147b64c9290d54f78e5a20e378593977cd47e285fPaul Berry } 9247b64c9290d54f78e5a20e378593977cd47e285fPaul Berry 9347b64c9290d54f78e5a20e378593977cd47e285fPaul Berry /* If we are mirrored, then before applying pixels_clipped_{left,right} to 9447b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * the source coordinates, we need to flip them to account for the 9547b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * mirroring. 9647b64c9290d54f78e5a20e378593977cd47e285fPaul Berry */ 9747b64c9290d54f78e5a20e378593977cd47e285fPaul Berry if (mirror) { 9847b64c9290d54f78e5a20e378593977cd47e285fPaul Berry GLint tmp = pixels_clipped_left; 9947b64c9290d54f78e5a20e378593977cd47e285fPaul Berry pixels_clipped_left = pixels_clipped_right; 10047b64c9290d54f78e5a20e378593977cd47e285fPaul Berry pixels_clipped_right = tmp; 10147b64c9290d54f78e5a20e378593977cd47e285fPaul Berry } 10247b64c9290d54f78e5a20e378593977cd47e285fPaul Berry 10347b64c9290d54f78e5a20e378593977cd47e285fPaul Berry /* Adjust the source rectangle to remove the pixels corresponding to those 10447b64c9290d54f78e5a20e378593977cd47e285fPaul Berry * that were clipped/scissored out of the destination rectangle. 10547b64c9290d54f78e5a20e378593977cd47e285fPaul Berry */ 10647b64c9290d54f78e5a20e378593977cd47e285fPaul Berry src_x0 += pixels_clipped_left; 10747b64c9290d54f78e5a20e378593977cd47e285fPaul Berry src_x1 -= pixels_clipped_right; 10847b64c9290d54f78e5a20e378593977cd47e285fPaul Berry 10947b64c9290d54f78e5a20e378593977cd47e285fPaul Berry return true; 11047b64c9290d54f78e5a20e378593977cd47e285fPaul Berry} 11147b64c9290d54f78e5a20e378593977cd47e285fPaul Berry 11247b64c9290d54f78e5a20e378593977cd47e285fPaul Berry 113fa1d267beb4adb542ea90b805306599f602c38d2Paul Berrystatic struct intel_mipmap_tree * 114fa1d267beb4adb542ea90b805306599f602c38d2Paul Berryfind_miptree(GLbitfield buffer_bit, struct gl_renderbuffer *rb) 115fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry{ 116fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct intel_renderbuffer *irb = intel_renderbuffer(rb); 117fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct intel_mipmap_tree *mt = irb->mt; 118fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry if (buffer_bit == GL_STENCIL_BUFFER_BIT && mt->stencil_mt) 119fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry mt = mt->stencil_mt; 120fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry return mt; 121fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry} 122fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 123fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 124fa1d267beb4adb542ea90b805306599f602c38d2Paul Berrystatic void 125fa1d267beb4adb542ea90b805306599f602c38d2Paul Berrydo_blorp_blit(struct intel_context *intel, GLbitfield buffer_bit, 126fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct gl_renderbuffer *src_rb, struct gl_renderbuffer *dst_rb, 127fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry GLint srcX0, GLint srcY0, 128fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 129fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry bool mirror_x, bool mirror_y) 130fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry{ 131fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct gl_context *ctx = &intel->ctx; 132fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 133fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry /* Find source/dst miptrees */ 134fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct intel_mipmap_tree *src_mt = find_miptree(buffer_bit, src_rb); 135fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct intel_mipmap_tree *dst_mt = find_miptree(buffer_bit, dst_rb); 136fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 137fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry /* Get ready to blit. This includes depth resolving the src and dst 138fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry * buffers if necessary. 139fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry */ 140fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry intel_renderbuffer_resolve_depth(intel, intel_renderbuffer(src_rb)); 141fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry intel_renderbuffer_resolve_depth(intel, intel_renderbuffer(dst_rb)); 142fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 143fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry /* Do the blit */ 144fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry brw_blorp_blit_params params(brw_context(ctx), src_mt, dst_mt, 145fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry srcX0, srcY0, dstX0, dstY0, dstX1, dstY1, 146fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry mirror_x, mirror_y); 147fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry brw_blorp_exec(intel, ¶ms); 148fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 149fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry /* Mark the dst buffer as needing a HiZ resolve if necessary. */ 150fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry intel_renderbuffer_set_needs_hiz_resolve(intel_renderbuffer(dst_rb)); 151fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry} 152fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 153fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 154fa1d267beb4adb542ea90b805306599f602c38d2Paul Berrystatic bool 155fa1d267beb4adb542ea90b805306599f602c38d2Paul Berryformats_match(GLbitfield buffer_bit, struct gl_renderbuffer *src_rb, 156fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct gl_renderbuffer *dst_rb) 157fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry{ 158fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry /* Note: don't just check gl_renderbuffer::Format, because in some cases 159fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry * multiple gl_formats resolve to the same native type in the miptree (for 160fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry * example MESA_FORMAT_X8_Z24 and MESA_FORMAT_S8_Z24), and we can blit 161fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry * between those formats. 162fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry */ 163fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry return find_miptree(buffer_bit, src_rb)->format == 164fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry find_miptree(buffer_bit, dst_rb)->format; 165fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry} 166fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 167fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry 168506d70be21cd3469118de89297cba0c0f709c1aePaul Berrystatic bool 169506d70be21cd3469118de89297cba0c0f709c1aePaul Berrytry_blorp_blit(struct intel_context *intel, 170506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, 171506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 172506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLenum filter, GLbitfield buffer_bit) 173506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 174506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct gl_context *ctx = &intel->ctx; 175506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 176506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Sync up the state of window system buffers. We need to do this before 177506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * we go looking for the buffers. 178506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 179506d70be21cd3469118de89297cba0c0f709c1aePaul Berry intel_prepare_render(intel); 180506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 181506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const struct gl_framebuffer *read_fb = ctx->ReadBuffer; 182506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const struct gl_framebuffer *draw_fb = ctx->DrawBuffer; 183506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 184506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Detect if the blit needs to be mirrored */ 185506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool mirror_x = false, mirror_y = false; 186506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_x, srcX0, srcX1); 187506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_x, dstX0, dstX1); 188506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_y, srcY0, srcY1); 189506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_y, dstY0, dstY1); 190506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 191506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Make sure width and height match */ 192da54d2e576426122009be083ecbfb9eefd8a3799Paul Berry if (srcX1 - srcX0 != dstX1 - dstX0) return false; 193da54d2e576426122009be083ecbfb9eefd8a3799Paul Berry if (srcY1 - srcY0 != dstY1 - dstY0) return false; 194506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 19547b64c9290d54f78e5a20e378593977cd47e285fPaul Berry /* If the destination rectangle needs to be clipped or scissored, do so. 196506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 19747b64c9290d54f78e5a20e378593977cd47e285fPaul Berry if (!(clip_or_scissor(mirror_x, srcX0, srcX1, dstX0, dstX1, 19847b64c9290d54f78e5a20e378593977cd47e285fPaul Berry draw_fb->_Xmin, draw_fb->_Xmax) && 19947b64c9290d54f78e5a20e378593977cd47e285fPaul Berry clip_or_scissor(mirror_y, srcY0, srcY1, dstY0, dstY1, 20047b64c9290d54f78e5a20e378593977cd47e285fPaul Berry draw_fb->_Ymin, draw_fb->_Ymax))) { 20147b64c9290d54f78e5a20e378593977cd47e285fPaul Berry /* Everything got clipped/scissored away, so the blit was successful. */ 20247b64c9290d54f78e5a20e378593977cd47e285fPaul Berry return true; 20347b64c9290d54f78e5a20e378593977cd47e285fPaul Berry } 20447b64c9290d54f78e5a20e378593977cd47e285fPaul Berry 20575f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry /* If the source rectangle needs to be clipped or scissored, do so. */ 20675f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry if (!(clip_or_scissor(mirror_x, dstX0, dstX1, srcX0, srcX1, 20775f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry 0, read_fb->Width) && 20875f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry clip_or_scissor(mirror_y, dstY0, dstY1, srcY0, srcY1, 20975f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry 0, read_fb->Height))) { 21075f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry /* Everything got clipped/scissored away, so the blit was successful. */ 21175f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry return true; 21275f409d75cacf90df2d6f1d718251a5d5cd92f7fPaul Berry } 213506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 2140dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry /* Account for the fact that in the system framebuffer, the origin is at 2150dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry * the lower left. 2160dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry */ 2170dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry if (read_fb->Name == 0) { 2180dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry GLint tmp = read_fb->Height - srcY0; 2190dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry srcY0 = read_fb->Height - srcY1; 2200dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry srcY1 = tmp; 2210dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry mirror_y = !mirror_y; 2220dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry } 2230dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry if (draw_fb->Name == 0) { 2240dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry GLint tmp = draw_fb->Height - dstY0; 2250dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry dstY0 = draw_fb->Height - dstY1; 2260dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry dstY1 = tmp; 2270dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry mirror_y = !mirror_y; 2280dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry } 2290dbec6ae07e7b3d566cc397ab09caa413e412846Paul Berry 230fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry /* Find buffers */ 231fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct gl_renderbuffer *src_rb; 232fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry struct gl_renderbuffer *dst_rb; 233fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry switch (buffer_bit) { 234fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry case GL_COLOR_BUFFER_BIT: 235fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry src_rb = read_fb->_ColorReadBuffer; 236ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry for (unsigned i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; ++i) { 237ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry dst_rb = ctx->DrawBuffer->_ColorDrawBuffers[i]; 238ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry if (dst_rb && !formats_match(buffer_bit, src_rb, dst_rb)) 239ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry return false; 240ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry } 241ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry for (unsigned i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; ++i) { 242ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry dst_rb = ctx->DrawBuffer->_ColorDrawBuffers[i]; 243ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry do_blorp_blit(intel, buffer_bit, src_rb, dst_rb, srcX0, srcY0, 244ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry dstX0, dstY0, dstX1, dstY1, mirror_x, mirror_y); 245ff9313fac70fa85d051dd4d2b9d3402d39f67ceaPaul Berry } 246fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry break; 247fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry case GL_DEPTH_BUFFER_BIT: 248fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry src_rb = read_fb->Attachment[BUFFER_DEPTH].Renderbuffer; 249fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry dst_rb = draw_fb->Attachment[BUFFER_DEPTH].Renderbuffer; 250fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry if (!formats_match(buffer_bit, src_rb, dst_rb)) 251fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry return false; 252fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry do_blorp_blit(intel, buffer_bit, src_rb, dst_rb, srcX0, srcY0, 253fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry dstX0, dstY0, dstX1, dstY1, mirror_x, mirror_y); 254fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry break; 255fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry case GL_STENCIL_BUFFER_BIT: 256fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry src_rb = read_fb->Attachment[BUFFER_STENCIL].Renderbuffer; 257fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry dst_rb = draw_fb->Attachment[BUFFER_STENCIL].Renderbuffer; 258fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry if (!formats_match(buffer_bit, src_rb, dst_rb)) 259fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry return false; 260fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry do_blorp_blit(intel, buffer_bit, src_rb, dst_rb, srcX0, srcY0, 261fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry dstX0, dstY0, dstX1, dstY1, mirror_x, mirror_y); 262fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry break; 263fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry default: 264fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry assert(false); 265fa1d267beb4adb542ea90b805306599f602c38d2Paul Berry } 266506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 267506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return true; 268506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 269506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 270506d70be21cd3469118de89297cba0c0f709c1aePaul BerryGLbitfield 271506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_framebuffer(struct intel_context *intel, 272506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, 273506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 274506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLbitfield mask, GLenum filter) 275506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 276b08545199ac8a01392a805f158d22cc03060a6fbPaul Berry /* BLORP is not supported before Gen6. */ 277b08545199ac8a01392a805f158d22cc03060a6fbPaul Berry if (intel->gen < 6) 278506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return mask; 279506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 280506d70be21cd3469118de89297cba0c0f709c1aePaul Berry static GLbitfield buffer_bits[] = { 281506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GL_COLOR_BUFFER_BIT, 282506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GL_DEPTH_BUFFER_BIT, 283506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GL_STENCIL_BUFFER_BIT, 284506d70be21cd3469118de89297cba0c0f709c1aePaul Berry }; 285506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 286506d70be21cd3469118de89297cba0c0f709c1aePaul Berry for (unsigned int i = 0; i < ARRAY_SIZE(buffer_bits); ++i) { 287506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if ((mask & buffer_bits[i]) && 288506d70be21cd3469118de89297cba0c0f709c1aePaul Berry try_blorp_blit(intel, 289506d70be21cd3469118de89297cba0c0f709c1aePaul Berry srcX0, srcY0, srcX1, srcY1, 290506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dstX0, dstY0, dstX1, dstY1, 291506d70be21cd3469118de89297cba0c0f709c1aePaul Berry filter, buffer_bits[i])) { 292506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mask &= ~buffer_bits[i]; 293506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 294506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 295506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 296506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return mask; 297506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 298506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 299665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 300665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry/** 301665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry * Enum to specify the order of arguments in a sampler message 302665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry */ 303665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berryenum sampler_message_arg 304665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry{ 305665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_FLOAT, 306665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_V_FLOAT, 307665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 308665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_V_INT, 309233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_SI_INT, 3104ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry SAMPLER_MESSAGE_ARG_MCS_INT, 311233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, 312665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry}; 313665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 314506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 315506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Generator for WM programs used in BLORP blits. 316506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 317506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * The bulk of the work done by the WM program is to wrap and unwrap the 318506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinate transformations used by the hardware to store surfaces in 31919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * memory. The hardware transforms a pixel location (X, Y, S) (where S is the 32019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * sample index for a multisampled surface) to a memory offset by the 32119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * following formulas: 322506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 3238b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * offset = tile(tiling_format, encode_msaa(num_samples, layout, X, Y, S)) 3248b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X, Y, S) = decode_msaa(num_samples, layout, detile(tiling_format, offset)) 32519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 3261bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * For a single-sampled surface, or for a multisampled surface using 3271bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * INTEL_MSAA_LAYOUT_UMS, encode_msaa() and decode_msaa are the identity 3281bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * function: 32919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 3301bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * encode_msaa(1, NONE, X, Y, 0) = (X, Y, 0) 3311bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * decode_msaa(1, NONE, X, Y, 0) = (X, Y, 0) 3321bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * encode_msaa(n, UMS, X, Y, S) = (X, Y, S) 3331bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * decode_msaa(n, UMS, X, Y, S) = (X, Y, S) 33419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 3351bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * For a 4x multisampled surface using INTEL_MSAA_LAYOUT_IMS, encode_msaa() 3361bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * embeds the sample number into bit 1 of the X and Y coordinates: 33719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 3381bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * encode_msaa(4, IMS, X, Y, S) = (X', Y', 0) 33919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b1) << 1 | (S & 0b1) << 1 | (X & 0b1) 34019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b1 ) << 1 | (S & 0b10) | (Y & 0b1) 3411bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * decode_msaa(4, IMS, X, Y, 0) = (X', Y', S) 34219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b11) >> 1 | (X & 0b1) 34319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b11) >> 1 | (Y & 0b1) 34419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * S = (Y & 0b10) | (X & 0b10) >> 1 345506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 346506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * For X tiling, tile() combines together the low-order bits of the X and Y 347506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates in the pattern 0byyyxxxxxxxxx, creating 4k tiles that are 512 348506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * bytes wide and 8 rows high: 349506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 3508b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(x_tiled, X, Y, S) = A 351506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = tile_num << 12 | offset 3528b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile_num = (Y' >> 3) * tile_pitch + (X' >> 9) 3538b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * offset = (Y' & 0b111) << 9 354506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X & 0b111111111) 355506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp 3568b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 3578b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(x_tiled, A) = (X, Y, S) 358506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp 3598b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch 3608b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y' / qpitch 3618b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = (tile_num / tile_pitch) << 3 3628b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b111000000000) >> 9 363506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (tile_num % tile_pitch) << 9 364506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b111111111) 365506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 366506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (In all tiling formulas, cpp is the number of bytes occupied by a single 3678b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * sample ("chars per pixel"), tile_pitch is the number of 4k tiles required 3688b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * to fill the width of the surface, and qpitch is the spacing (in rows) 3698b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * between array slices). 370506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 371506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * For Y tiling, tile() combines together the low-order bits of the X and Y 372506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates in the pattern 0bxxxyyyyyxxxx, creating 4k tiles that are 128 373506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * bytes wide and 32 rows high: 374506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 3758b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(y_tiled, X, Y, S) = A 376506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = tile_num << 12 | offset 3778b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile_num = (Y' >> 5) * tile_pitch + (X' >> 7) 378506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * offset = (X' & 0b1110000) << 5 379506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (Y' & 0b11111) << 4 380506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b1111) 381506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp 3828b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 3838b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(y_tiled, A) = (X, Y, S) 384506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp 3858b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch 3868b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y' / qpitch 3878b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = (tile_num / tile_pitch) << 5 3888b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b111110000) >> 4 389506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (tile_num % tile_pitch) << 7 390506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b111000000000) >> 5 391506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b1111) 392506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 393506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * For W tiling, tile() combines together the low-order bits of the X and Y 394506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates in the pattern 0bxxxyyyyxyxyx, creating 4k tiles that are 64 395506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * bytes wide and 64 rows high (note that W tiling is only used for stencil 3968b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * buffers, which always have cpp = 1 and S=0): 397506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 3988b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(w_tiled, X, Y, S) = A 399506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = tile_num << 12 | offset 4008b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile_num = (Y' >> 6) * tile_pitch + (X' >> 6) 401506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * offset = (X' & 0b111000) << 6 4028b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (Y' & 0b111100) << 3 403506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b100) << 2 4048b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (Y' & 0b10) << 2 405506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b10) << 1 4068b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (Y' & 0b1) << 1 407506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b1) 408506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp = X 4098b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 4108b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(w_tiled, A) = (X, Y, S) 411506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp = X' 4128b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch = Y' 4138b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y / qpitch = 0 4148b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = (tile_num / tile_pitch) << 6 4158b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b111100000) >> 3 4168b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b1000) >> 2 4178b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b10) >> 1 418506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (tile_num % tile_pitch) << 6 419506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b111000000000) >> 6 420506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b10000) >> 2 421506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b100) >> 1 422506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b1) 423506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 424506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Finally, for a non-tiled surface, tile() simply combines together the X and 425506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y coordinates in the natural way: 426506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 4278b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(untiled, X, Y, S) = A 428506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = Y * pitch + X' 429506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp 4308b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 4318b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(untiled, A) = (X, Y, S) 432506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp 4338b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch 4348b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y' / qpitch 435506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = A % pitch 4368b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = A / pitch 437506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 438506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (In these formulas, pitch is the number of bytes occupied by a single row 43919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * of samples). 440506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 441506d70be21cd3469118de89297cba0c0f709c1aePaul Berryclass brw_blorp_blit_program 442506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 443506d70be21cd3469118de89297cba0c0f709c1aePaul Berrypublic: 444506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_blit_program(struct brw_context *brw, 445506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const brw_blorp_blit_prog_key *key); 446506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ~brw_blorp_blit_program(); 447506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 448506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const GLuint *compile(struct brw_context *brw, GLuint *program_size); 449506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 450506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_prog_data prog_data; 451506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 452506d70be21cd3469118de89297cba0c0f709c1aePaul Berryprivate: 453506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void alloc_regs(); 454506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void alloc_push_const_regs(int base_reg); 455506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void compute_frag_coords(); 456506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void translate_tiling(bool old_tiled_w, bool new_tiled_w); 4571bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry void encode_msaa(unsigned num_samples, intel_msaa_layout layout); 4581bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry void decode_msaa(unsigned num_samples, intel_msaa_layout layout); 459506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void kill_if_outside_dst_rect(); 460506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void translate_dst_to_src(); 46119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry void single_to_blend(); 46217eae9762cdd6cfa69a060001e26113dfc0d7c86Paul Berry void manual_blend(unsigned num_samples); 4634725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry void sample(struct brw_reg dst); 4644725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry void texel_fetch(struct brw_reg dst); 4654ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry void mcs_fetch(); 466665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry void expand_to_32_bits(struct brw_reg src, struct brw_reg dst); 4674725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry void texture_lookup(struct brw_reg dst, GLuint msg_type, 4684725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry const sampler_message_arg *args, int num_args); 469506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void render_target_write(); 470506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 471b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /** 472b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * Base-2 logarithm of the maximum number of samples that can be blended. 473b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry */ 47417eae9762cdd6cfa69a060001e26113dfc0d7c86Paul Berry static const unsigned LOG2_MAX_BLEND_SAMPLES = 3; 475b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 476506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void *mem_ctx; 477506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_context *brw; 478506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const brw_blorp_blit_prog_key *key; 479506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_compile func; 480506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 481506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Thread dispatch header */ 482506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg R0; 483506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 484506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Pixel X/Y coordinates (always in R1). */ 485506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg R1; 486506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 487506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Push constants */ 488506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_x0; 489506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_x1; 490506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_y0; 491506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_y1; 492506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct { 493506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg multiplier; 494506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg offset; 495506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } x_transform, y_transform; 496506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 497b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /* Data read from texture (4 vec16's per array element) */ 498b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry struct brw_reg texture_data[LOG2_MAX_BLEND_SAMPLES + 1]; 499506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 5004ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry /* Auxiliary storage for the contents of the MCS surface. 5014ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry * 5024ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry * Since the sampler always returns 8 registers worth of data, this is 8 5034ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry * registers wide, even though we only use the first 2 registers of it. 5044ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry */ 5054ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry struct brw_reg mcs_data; 5064ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry 507506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* X coordinates. We have two of them so that we can perform coordinate 508506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * transformations easily. 509506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 510506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg x_coords[2]; 511506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 512506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Y coordinates. We have two of them so that we can perform coordinate 513506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * transformations easily. 514506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 515506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg y_coords[2]; 516506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 517506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Which element of x_coords and y_coords is currently in use. 518506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 519506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int xy_coord_index; 520506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 52119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* True if, at the point in the program currently being compiled, the 52219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * sample index is known to be zero. 52319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 52419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry bool s_is_zero; 52519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 52619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Register storing the sample index when s_is_zero is false. */ 52719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry struct brw_reg sample_index; 52819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 529506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Temporaries */ 530506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg t1; 531506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg t2; 532506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 533665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry /* MRF used for sampling and render target writes */ 534506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint base_mrf; 535506d70be21cd3469118de89297cba0c0f709c1aePaul Berry}; 536506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 537506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::brw_blorp_blit_program( 538506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_context *brw, 539506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const brw_blorp_blit_prog_key *key) 540506d70be21cd3469118de89297cba0c0f709c1aePaul Berry : mem_ctx(ralloc_context(NULL)), 541506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw(brw), 542506d70be21cd3469118de89297cba0c0f709c1aePaul Berry key(key) 543506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 544506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_init_compile(brw, &func, mem_ctx); 545506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 546506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 547506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::~brw_blorp_blit_program() 548506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 549506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ralloc_free(mem_ctx); 550506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 551506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 552506d70be21cd3469118de89297cba0c0f709c1aePaul Berryconst GLuint * 553506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::compile(struct brw_context *brw, 554506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint *program_size) 555506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 55619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Sanity checks */ 55734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (key->dst_tiled_w && key->rt_samples > 0) { 55834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* If the destination image is W tiled and multisampled, then the thread 55934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * must be dispatched once per sample, not once per pixel. This is 56034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * necessary because after conversion between W and Y tiling, there's no 56119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * guarantee that all samples corresponding to a single pixel will still 56219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * be together. 56319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 56434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry assert(key->persample_msaa_dispatch); 56519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 56619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 56719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (key->blend) { 5684725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry /* We are blending, which means we won't have an opportunity to 5694725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry * translate the tiling and sample count for the texture surface. So 57019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the surface state for the texture must be configured with the correct 57119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * tiling and sample count. 57219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 57319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry assert(!key->src_tiled_w); 57419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry assert(key->tex_samples == key->src_samples); 5751bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert(key->tex_layout == key->src_layout); 57619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry assert(key->tex_samples > 0); 57719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 57819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 57934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (key->persample_msaa_dispatch) { 58034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* It only makes sense to do persample dispatch if the render target is 58134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * configured as multisampled. 58234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry */ 58334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry assert(key->rt_samples > 0); 58434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } 58534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry 5861bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* Make sure layout is consistent with sample count */ 5871bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert((key->tex_layout == INTEL_MSAA_LAYOUT_NONE) == 5881bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry (key->tex_samples == 0)); 5891bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert((key->rt_layout == INTEL_MSAA_LAYOUT_NONE) == 5901bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry (key->rt_samples == 0)); 5911bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert((key->src_layout == INTEL_MSAA_LAYOUT_NONE) == 5921bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry (key->src_samples == 0)); 5931bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert((key->dst_layout == INTEL_MSAA_LAYOUT_NONE) == 5941bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry (key->dst_samples == 0)); 5958b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 59634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* Set up prog_data */ 59734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry memset(&prog_data, 0, sizeof(prog_data)); 59834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry prog_data.persample_msaa_dispatch = key->persample_msaa_dispatch; 59934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry 600506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_compression_control(&func, BRW_COMPRESSION_NONE); 601506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 602506d70be21cd3469118de89297cba0c0f709c1aePaul Berry alloc_regs(); 603506d70be21cd3469118de89297cba0c0f709c1aePaul Berry compute_frag_coords(); 604506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 605506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Render target and texture hardware don't support W tiling. */ 606506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const bool rt_tiled_w = false; 607506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const bool tex_tiled_w = false; 608506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 609506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* The address that data will be written to is determined by the 61019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * coordinates supplied to the WM thread and the tiling and sample count of 61119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the render target, according to the formula: 612506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 61319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (X, Y, S) = decode_msaa(rt_samples, detile(rt_tiling, offset)) 614506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 61519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * If the actual tiling and sample count of the destination surface are not 61619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the same as the configuration of the render target, then these 61719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * coordinates are wrong and we have to adjust them to compensate for the 61819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * difference. 619506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 62019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (rt_tiled_w != key->dst_tiled_w || 6218b1f467cce34340637e9baca4847fc5273cf7541Paul Berry key->rt_samples != key->dst_samples || 6221bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry key->rt_layout != key->dst_layout) { 6231bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry encode_msaa(key->rt_samples, key->rt_layout); 6248b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(rt_tiling, offset) */ 625506d70be21cd3469118de89297cba0c0f709c1aePaul Berry translate_tiling(rt_tiled_w, key->dst_tiled_w); 6268b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(dst_tiling, offset) */ 6271bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry decode_msaa(key->dst_samples, key->dst_layout); 62819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 629506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 63019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Now (X, Y, S) = decode_msaa(dst_samples, detile(dst_tiling, offset)). 631506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 63219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * That is: X, Y and S now contain the true coordinates and sample index of 63319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the data that the WM thread should output. 634506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 635506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * If we need to kill pixels that are outside the destination rectangle, 636506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * now is the time to do it. 637506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 638506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 639506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (key->use_kill) 640506d70be21cd3469118de89297cba0c0f709c1aePaul Berry kill_if_outside_dst_rect(); 641506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 642506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Next, apply a translation to obtain coordinates in the source image. */ 643506d70be21cd3469118de89297cba0c0f709c1aePaul Berry translate_dst_to_src(); 644506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 64519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* If the source image is not multisampled, then we want to fetch sample 64619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * number 0, because that's the only sample there is. 647506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 64819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (key->src_samples == 0) 64919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry s_is_zero = true; 650506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 65119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* X, Y, and S are now the coordinates of the pixel in the source image 65219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * that we want to texture from. Exception: if we are blending, then S is 65319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * irrelevant, because we are going to fetch all samples. 654506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 65519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (key->blend) { 6564725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry if (brw->intel.gen == 6) { 6574725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry /* Gen6 hardware an automatically blend using the SAMPLE message */ 6584725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry single_to_blend(); 659b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry sample(texture_data[0]); 6604725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry } else { 6614725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry /* Gen7+ hardware doesn't automaticaly blend. */ 66217eae9762cdd6cfa69a060001e26113dfc0d7c86Paul Berry manual_blend(key->src_samples); 6634725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry } 66419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } else { 66519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We aren't blending, which means we just want to fetch a single sample 66619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * from the source surface. The address that we want to fetch from is 66719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * related to the X, Y and S values according to the formula: 66819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 66919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (X, Y, S) = decode_msaa(src_samples, detile(src_tiling, offset)). 67019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 67119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * If the actual tiling and sample count of the source surface are not 67219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the same as the configuration of the texture, then we need to adjust 67319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the coordinates to compensate for the difference. 67419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 67519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (tex_tiled_w != key->src_tiled_w || 6768b1f467cce34340637e9baca4847fc5273cf7541Paul Berry key->tex_samples != key->src_samples || 6771bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry key->tex_layout != key->src_layout) { 6781bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry encode_msaa(key->src_samples, key->src_layout); 6798b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(src_tiling, offset) */ 68019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry translate_tiling(key->src_tiled_w, tex_tiled_w); 6818b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(tex_tiling, offset) */ 6821bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry decode_msaa(key->tex_samples, key->tex_layout); 68319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 684506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 68519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Now (X, Y, S) = decode_msaa(tex_samples, detile(tex_tiling, offset)). 68619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 68719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * In other words: X, Y, and S now contain values which, when passed to 68819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the texturing unit, will cause data to be read from the correct 68919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * memory location. So we can fetch the texel now. 69019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 6914ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry if (key->tex_layout == INTEL_MSAA_LAYOUT_CMS) 6924ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry mcs_fetch(); 693b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry texel_fetch(texture_data[0]); 69419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 69519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 69619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Finally, write the fetched (or blended) value to the render target and 69719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * terminate the thread. 698506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 699506d70be21cd3469118de89297cba0c0f709c1aePaul Berry render_target_write(); 700506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return brw_get_program(&func, program_size); 701506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 702506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 703506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 704506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::alloc_push_const_regs(int base_reg) 705506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 706506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define CONST_LOC(name) offsetof(brw_blorp_wm_push_constants, name) 707506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define ALLOC_REG(name) \ 708506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->name = \ 709506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, base_reg, CONST_LOC(name) / 2) 710506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 711506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_x0); 712506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_x1); 713506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_y0); 714506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_y1); 715506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(x_transform.multiplier); 716506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(x_transform.offset); 717506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(y_transform.multiplier); 718506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(y_transform.offset); 719506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef CONST_LOC 720506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef ALLOC_REG 721506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 722506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 723506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 724506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::alloc_regs() 725506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 726506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int reg = 0; 727506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->R0 = retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW); 728506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->R1 = retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW); 729506d70be21cd3469118de89297cba0c0f709c1aePaul Berry prog_data.first_curbe_grf = reg; 730506d70be21cd3469118de89297cba0c0f709c1aePaul Berry alloc_push_const_regs(reg); 731506d70be21cd3469118de89297cba0c0f709c1aePaul Berry reg += BRW_BLORP_NUM_PUSH_CONST_REGS; 732b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry for (unsigned i = 0; i < ARRAY_SIZE(texture_data); ++i) { 733e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry this->texture_data[i] = 734e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry retype(vec16(brw_vec8_grf(reg, 0)), key->texture_data_type); 735e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry reg += 8; 736b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry } 7374ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry this->mcs_data = 7384ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry retype(brw_vec8_grf(reg, 0), BRW_REGISTER_TYPE_UD); reg += 8; 739506d70be21cd3469118de89297cba0c0f709c1aePaul Berry for (int i = 0; i < 2; ++i) { 740506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->x_coords[i] 741506d70be21cd3469118de89297cba0c0f709c1aePaul Berry = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 742506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->y_coords[i] 743506d70be21cd3469118de89297cba0c0f709c1aePaul Berry = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 744506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 745506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->xy_coord_index = 0; 74619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry this->sample_index 74719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 748506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->t1 = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 749506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->t2 = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 750506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 751b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /* Make sure we didn't run out of registers */ 752b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry assert(reg <= GEN7_MRF_HACK_START); 753b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 754506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int mrf = 2; 755506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->base_mrf = mrf; 756506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 757506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 758506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/* In the code that follows, X and Y can be used to quickly refer to the 759506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * active elements of x_coords and y_coords, and Xp and Yp ("X prime" and "Y 760506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * prime") to the inactive elements. 76119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 76219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * S can be used to quickly refer to sample_index. 763506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 764506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define X x_coords[xy_coord_index] 765506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define Y y_coords[xy_coord_index] 766506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define Xp x_coords[!xy_coord_index] 767506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define Yp y_coords[!xy_coord_index] 76819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry#define S sample_index 769506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 770506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/* Quickly swap the roles of (X, Y) and (Xp, Yp). Saves us from having to do 771506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * MOVs to transfor (Xp, Yp) to (X, Y) after a coordinate transformation. 772506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 773506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define SWAP_XY_AND_XPYP() xy_coord_index = !xy_coord_index; 774506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 775506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 776506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to compute the X and Y coordinates of the pixels being rendered 777506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * by this WM invocation. 778506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 779506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Assuming the render target is set up for Y tiling, these (X, Y) values are 780506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * related to the address offset where outputs will be written by the formula: 781506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 782506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (X, Y, S) = decode_msaa(detile(offset)). 783506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 784506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (See brw_blorp_blit_program). 785506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 786506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 787506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::compute_frag_coords() 788506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 789506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* R1.2[15:0] = X coordinate of upper left pixel of subspan 0 (pixel 0) 790506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.3[15:0] = X coordinate of upper left pixel of subspan 1 (pixel 4) 791506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.4[15:0] = X coordinate of upper left pixel of subspan 2 (pixel 8) 792506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.5[15:0] = X coordinate of upper left pixel of subspan 3 (pixel 12) 793506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 794506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Pixels within a subspan are laid out in this arrangement: 795506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 0 1 796506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 2 3 797506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 798506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * So, to compute the coordinates of each pixel, we need to read every 2nd 799506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 16-bit value (vstride=2) from R1, starting at the 4th 16-bit value 800506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (suboffset=4), and duplicate each value 4 times (hstride=0, width=4). 801506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * In other words, the data we want to access is R1.4<2;4,0>UW. 802506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 803506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Then, we need to add the repeating sequence (0, 1, 0, 1, ...) to the 804506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * result, since pixels n+1 and n+3 are in the right half of the subspan. 805506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 806506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, X, stride(suboffset(R1, 4), 2, 4, 0), brw_imm_v(0x10101010)); 807506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 808506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Similarly, Y coordinates for subspans come from R1.2[31:16] through 809506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.5[31:16], so to get pixel Y coordinates we need to start at the 5th 810506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 16-bit value instead of the 4th (R1.5<2;4,0>UW instead of 811506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.4<2;4,0>UW). 812506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 813506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * And we need to add the repeating sequence (0, 0, 1, 1, ...), since 814506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * pixels n+2 and n+3 are in the bottom half of the subspan. 815506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 816506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, Y, stride(suboffset(R1, 5), 2, 4, 0), brw_imm_v(0x11001100)); 81719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 81834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (key->persample_msaa_dispatch) { 81934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* The WM will be run in MSDISPMODE_PERSAMPLE with num_samples > 0. 82034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * Therefore, subspan 0 will represent sample 0, subspan 1 will 82134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * represent sample 1, and so on. 82234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 82334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * So we need to populate S with the sequence (0, 0, 0, 0, 1, 1, 1, 1, 82434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 2, 2, 2, 2, 3, 3, 3, 3). The easiest way to do this is to populate a 82534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * temporary variable with the sequence (0, 1, 2, 3), and then copy from 82634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * it using vstride=1, width=4, hstride=0. 82734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 82834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * TODO: implement the necessary calculation for 8x multisampling. 82934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry */ 83034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry brw_MOV(&func, t1, brw_imm_v(0x3210)); 83134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry brw_MOV(&func, S, stride(t1, 1, 4, 0)); 83234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry s_is_zero = false; 83334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } else { 83434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* Either the destination surface is single-sampled, or the WM will be 83534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * run in MSDISPMODE_PERPIXEL (which causes a single fragment dispatch 83634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * per pixel). In either case, it's not meaningful to compute a sample 83734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * value. Just set it to 0. 83834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry */ 83934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry s_is_zero = true; 84034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } 841506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 842506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 843506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 844506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to compensate for the difference between Y and W tiling. 845506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 846506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * This code modifies the X and Y coordinates according to the formula: 847506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 8488b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X', Y', S') = detile(new_tiling, tile(old_tiling, X, Y, S)) 849506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 850506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (See brw_blorp_blit_program). 851506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 852506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * It can only translate between W and Y tiling, so new_tiling and old_tiling 853506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * are booleans where true represents W tiling and false represents Y tiling. 854506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 855506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 856506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::translate_tiling(bool old_tiled_w, bool new_tiled_w) 857506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 858506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (old_tiled_w == new_tiled_w) 859506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return; 860506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 8618b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* In the code that follows, we can safely assume that S = 0, because W 8621bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * tiling formats always use IMS layout. 8638b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 8648b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 8658b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 866506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (new_tiled_w) { 867506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Given X and Y coordinates that describe an address using Y tiling, 868506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * translate to the X and Y coordinates that describe the same address 869506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * using W tiling. 870506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 871506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * If we break down the low order bits of X and Y, using a 872506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * single letter to represent each low-order bit: 873506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 874506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X = A << 7 | 0bBCDEFGH 875506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y = J << 5 | 0bKLMNP (1) 876506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 877506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Then we can apply the Y tiling formula to see the memory offset being 878506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * addressed: 879506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 880506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * offset = (J * tile_pitch + A) << 12 | 0bBCDKLMNPEFGH (2) 881506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 882506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * If we apply the W detiling formula to this memory location, that the 883506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * corresponding X' and Y' coordinates are: 884506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 885506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = A << 6 | 0bBCDPFH (3) 886506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y' = J << 6 | 0bKLMNEG 887506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 888506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Combining (1) and (3), we see that to transform (X, Y) to (X', Y'), 889506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * we need to make the following computation: 890506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 891506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (X & ~0b1011) >> 1 | (Y & 0b1) << 2 | X & 0b1 (4) 892506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y' = (Y & ~0b1) << 1 | (X & 0b1000) >> 2 | (X & 0b10) >> 1 893506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 894506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfff4)); /* X & ~0b1011 */ 895506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b1011) >> 1 */ 896506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); /* Y & 0b1 */ 897506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t2, t2, brw_imm_uw(2)); /* (Y & 0b1) << 2 */ 898506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b1011) >> 1 | (Y & 0b1) << 2 */ 899506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 900506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Xp, t1, t2); 901506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffe)); /* Y & ~0b1 */ 902506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b1) << 1 */ 903506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(8)); /* X & 0b1000 */ 904506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(2)); /* (X & 0b1000) >> 2 */ 905506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (Y & ~0b1) << 1 | (X & 0b1000) >> 2 */ 906506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(2)); /* X & 0b10 */ 907506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(1)); /* (X & 0b10) >> 1 */ 908506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Yp, t1, t2); 909506d70be21cd3469118de89297cba0c0f709c1aePaul Berry SWAP_XY_AND_XPYP(); 910506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } else { 911506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Applying the same logic as above, but in reverse, we obtain the 912506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * formulas: 913506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 914506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (X & ~0b101) << 1 | (Y & 0b10) << 2 | (Y & 0b1) << 1 | X & 0b1 915506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y' = (Y & ~0b11) >> 1 | (X & 0b100) >> 2 916506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 917506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfffa)); /* X & ~0b101 */ 918506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b101) << 1 */ 919506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, Y, brw_imm_uw(2)); /* Y & 0b10 */ 920506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t2, t2, brw_imm_uw(2)); /* (Y & 0b10) << 2 */ 921506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b101) << 1 | (Y & 0b10) << 2 */ 922506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); /* Y & 0b1 */ 923506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t2, t2, brw_imm_uw(1)); /* (Y & 0b1) << 1 */ 924506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b101) << 1 | (Y & 0b10) << 2 925506d70be21cd3469118de89297cba0c0f709c1aePaul Berry | (Y & 0b1) << 1 */ 926506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 927506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Xp, t1, t2); 928506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffc)); /* Y & ~0b11 */ 929506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b11) >> 1 */ 930506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(4)); /* X & 0b100 */ 931506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(2)); /* (X & 0b100) >> 2 */ 932506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Yp, t1, t2); 933506d70be21cd3469118de89297cba0c0f709c1aePaul Berry SWAP_XY_AND_XPYP(); 934506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 935506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 936506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 937506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 93819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to compensate for the difference between MSAA and non-MSAA 93919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * surfaces. 94019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 94119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * This code modifies the X and Y coordinates according to the formula: 94219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 9438b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X', Y', S') = encode_msaa_4x(X, Y, S) 94419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 94519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (See brw_blorp_blit_program). 94619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 94719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 9481bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berrybrw_blorp_blit_program::encode_msaa(unsigned num_samples, 9491bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry intel_msaa_layout layout) 95019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 9511bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry switch (layout) { 9521bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_NONE: 9538b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* No translation necessary, and S should already be zero. */ 9548b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 9551bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 9561bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_CMS: 9571bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* We can't compensate for compressed layout since at this point in the 9581bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * program we haven't read from the MCS buffer. 9591bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry */ 9601bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert(!"Bad layout in encode_msaa"); 9611bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 9621bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_UMS: 96319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* No translation necessary. */ 9641bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 9651bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_IMS: 9661bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* encode_msaa(4, IMS, X, Y, S) = (X', Y', 0) 96719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b1) << 1 | (S & 0b1) << 1 | (X & 0b1) 96819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b1 ) << 1 | (S & 0b10) | (Y & 0b1) 96919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 97019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfffe)); /* X & ~0b1 */ 97119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (!s_is_zero) { 97219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, S, brw_imm_uw(1)); /* S & 0b1 */ 97319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b1) | (S & 0b1) */ 97419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 97519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b1) << 1 97619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry | (S & 0b1) << 1 */ 97719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 97819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Xp, t1, t2); 97919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffe)); /* Y & ~0b1 */ 98019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b1) << 1 */ 98119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (!s_is_zero) { 98219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, S, brw_imm_uw(2)); /* S & 0b10 */ 98319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, t1, t1, t2); /* (Y & ~0b1) << 1 | (S & 0b10) */ 98419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 98519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); 98619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Yp, t1, t2); 98719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry SWAP_XY_AND_XPYP(); 9888b1f467cce34340637e9baca4847fc5273cf7541Paul Berry s_is_zero = true; 9891bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 99019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 99119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 99219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 99319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 99419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to compensate for the difference between MSAA and non-MSAA 99519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * surfaces. 99619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 99719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * This code modifies the X and Y coordinates according to the formula: 99819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 9998b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X', Y', S) = decode_msaa(num_samples, X, Y, S) 100019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 100119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (See brw_blorp_blit_program). 100219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 100319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 10041bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berrybrw_blorp_blit_program::decode_msaa(unsigned num_samples, 10051bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry intel_msaa_layout layout) 100619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 10071bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry switch (layout) { 10081bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_NONE: 10098b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* No translation necessary, and S should already be zero. */ 10108b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 10111bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 10121bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_CMS: 10131bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* We can't compensate for compressed layout since at this point in the 10141bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * program we don't have access to the MCS buffer. 10151bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry */ 10161bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert(!"Bad layout in encode_msaa"); 10171bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 10181bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_UMS: 101919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* No translation necessary. */ 10201bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 10211bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry case INTEL_MSAA_LAYOUT_IMS: 10221bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* decode_msaa(4, IMS, X, Y, 0) = (X', Y', S) 102319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b11) >> 1 | (X & 0b1) 102419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b11) >> 1 | (Y & 0b1) 102519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * S = (Y & 0b10) | (X & 0b10) >> 1 102619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 10278b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 102819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfffc)); /* X & ~0b11 */ 102919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b11) >> 1 */ 103019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 103119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Xp, t1, t2); 103219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffc)); /* Y & ~0b11 */ 103319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b11) >> 1 */ 103419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); /* Y & 0b1 */ 103519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Yp, t1, t2); 103619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, Y, brw_imm_uw(2)); /* Y & 0b10 */ 103719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, X, brw_imm_uw(2)); /* X & 0b10 */ 103819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(1)); /* (X & 0b10) >> 1 */ 103919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, S, t1, t2); 104019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry s_is_zero = false; 104119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry SWAP_XY_AND_XPYP(); 10421bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry break; 104319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 104419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 104519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 104619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 1047506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code that kills pixels whose X and Y coordinates are outside the 1048506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * boundary of the rectangle defined by the push constants (dst_x0, dst_y0, 1049506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * dst_x1, dst_y1). 1050506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1051506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 1052506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::kill_if_outside_dst_rect() 1053506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1054506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg f0 = brw_flag_reg(); 1055506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg g1 = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW); 1056506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg null16 = vec16(retype(brw_null_reg(), BRW_REGISTER_TYPE_UW)); 1057506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1058506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_GE, X, dst_x0); 1059506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_GE, Y, dst_y0); 1060506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_L, X, dst_x1); 1061506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_L, Y, dst_y1); 1062506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1063506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_predicate_control(&func, BRW_PREDICATE_NONE); 1064506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_push_insn_state(&func); 1065506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_mask_control(&func, BRW_MASK_DISABLE); 1066506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, g1, f0, g1); 1067506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_pop_insn_state(&func); 1068506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1069506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1070506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 1071506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to translate from destination (X, Y) coordinates to source (X, Y) 1072506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates. 1073506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1074506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 1075506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::translate_dst_to_src() 1076506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1077506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_MUL(&func, Xp, X, x_transform.multiplier); 1078506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_MUL(&func, Yp, Y, y_transform.multiplier); 1079506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, Xp, Xp, x_transform.offset); 1080506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, Yp, Yp, y_transform.offset); 1081506d70be21cd3469118de89297cba0c0f709c1aePaul Berry SWAP_XY_AND_XPYP(); 1082506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1083506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1084506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 108519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to transform the X and Y coordinates as needed for blending 108619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * together the different samples in an MSAA texture. 108719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 108819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 108919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berrybrw_blorp_blit_program::single_to_blend() 109019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 109119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* When looking up samples in an MSAA texture using the SAMPLE message, 109219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Gen6 requires the texture coordinates to be odd integers (so that they 109319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * correspond to the center of a 2x2 block representing the four samples 109419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * that maxe up a pixel). So we need to multiply our X and Y coordinates 109519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * each by 2 and then add 1. 109619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 109719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t1, X, brw_imm_w(1)); 109819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t2, Y, brw_imm_w(1)); 109919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_ADD(&func, Xp, t1, brw_imm_w(1)); 110019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_ADD(&func, Yp, t2, brw_imm_w(1)); 110119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry SWAP_XY_AND_XPYP(); 110219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 110319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 1104b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 1105b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry/** 1106b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * Count the number of trailing 1 bits in the given value. For example: 1107b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * 1108b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * count_trailing_one_bits(0) == 0 1109b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * count_trailing_one_bits(7) == 3 1110b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * count_trailing_one_bits(11) == 2 1111b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry */ 1112b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berryinline int count_trailing_one_bits(unsigned value) 1113b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry{ 1114b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) /* gcc 3.4 or later */ 1115b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry return __builtin_ctz(~value); 1116b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry#else 1117b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry return _mesa_bitcount(value & ~(value + 1)); 1118b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry#endif 1119b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry} 1120b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 1121b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 11224725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berryvoid 112317eae9762cdd6cfa69a060001e26113dfc0d7c86Paul Berrybrw_blorp_blit_program::manual_blend(unsigned num_samples) 11244725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry{ 11254ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry if (key->tex_layout == INTEL_MSAA_LAYOUT_CMS) 11264ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry mcs_fetch(); 11274ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry 1128b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /* We add together samples using a binary tree structure, e.g. for 4x MSAA: 1129b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * 1130b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * result = ((sample[0] + sample[1]) + (sample[2] + sample[3])) / 4 1131b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * 1132b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * This ensures that when all samples have the same value, no numerical 1133b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * precision is lost, since each addition operation always adds two equal 1134b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * values, and summing two equal floating point values does not lose 1135b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * precision. 1136b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * 1137b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * We perform this computation by treating the texture_data array as a 1138b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * stack and performing the following operations: 1139b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * 1140b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - push sample 0 onto stack 1141b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - push sample 1 onto stack 1142b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - add top two stack entries 1143b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - push sample 2 onto stack 1144b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - push sample 3 onto stack 1145b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - add top two stack entries 1146b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - add top two stack entries 1147b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * - divide top stack entry by 4 1148b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * 1149b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * Note that after pushing sample i onto the stack, the number of add 1150b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * operations we do is equal to the number of trailing 1 bits in i. This 1151b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * works provided the total number of samples is a power of two, which it 1152b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry * always is for i965. 1153e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry * 1154e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry * For integer formats, we replace the add operations with average 1155e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry * operations and skip the final division. 1156b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry */ 1157e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry typedef struct brw_instruction *(*brw_op2_ptr)(struct brw_compile *, 1158e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry struct brw_reg, 1159e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry struct brw_reg, 1160e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry struct brw_reg); 1161e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry brw_op2_ptr combine_op = 1162e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry key->texture_data_type == BRW_REGISTER_TYPE_F ? brw_ADD : brw_AVG; 1163b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry unsigned stack_depth = 0; 116417eae9762cdd6cfa69a060001e26113dfc0d7c86Paul Berry for (unsigned i = 0; i < num_samples; ++i) { 1165b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry assert(stack_depth == _mesa_bitcount(i)); /* Loop invariant */ 1166b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 1167b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /* Push sample i onto the stack */ 1168b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry assert(stack_depth < ARRAY_SIZE(texture_data)); 1169b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry if (i == 0) { 1170b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry s_is_zero = true; 1171b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry } else { 1172b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry s_is_zero = false; 1173b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry brw_MOV(&func, S, brw_imm_uw(i)); 1174b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry } 1175b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry texel_fetch(texture_data[stack_depth++]); 1176b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 1177f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry if (i == 0 && key->tex_layout == INTEL_MSAA_LAYOUT_CMS) { 1178f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry /* The Ivy Bridge PRM, Vol4 Part1 p27 (Multisample Control Surface) 1179f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * suggests an optimization: 1180f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * 1181f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * "A simple optimization with probable large return in 1182f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * performance is to compare the MCS value to zero (indicating 1183f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * all samples are on sample slice 0), and sample only from 1184f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * sample slice 0 using ld2dss if MCS is zero." 1185f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * 1186f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * Note that in the case where the MCS value is zero, sampling from 1187f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * sample slice 0 using ld2dss and sampling from sample 0 using 1188f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * ld2dms are equivalent (since all samples are on sample slice 0). 1189f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * Since we have already sampled from sample 0, all we need to do is 1190f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry * skip the remaining fetches and averaging if MCS is zero. 1191f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry */ 1192f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry brw_CMP(&func, vec16(brw_null_reg()), BRW_CONDITIONAL_NZ, 1193f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry mcs_data, brw_imm_ud(0)); 1194f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry brw_IF(&func, BRW_EXECUTE_16); 1195f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry } 1196f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry 1197b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /* Do count_trailing_one_bits(i) times */ 1198b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry for (int j = count_trailing_one_bits(i); j-- > 0; ) { 1199b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry assert(stack_depth >= 2); 1200b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry --stack_depth; 1201b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 1202b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /* TODO: should use a smaller loop bound for non_RGBA formats */ 1203b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry for (int k = 0; k < 4; ++k) { 1204e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry combine_op(&func, offset(texture_data[stack_depth - 1], 2*k), 1205e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry offset(vec8(texture_data[stack_depth - 1]), 2*k), 1206e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry offset(vec8(texture_data[stack_depth]), 2*k)); 1207b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry } 12084725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry } 12094725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry } 12104725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry 1211b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry /* We should have just 1 sample on the stack now. */ 1212b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry assert(stack_depth == 1); 1213b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry 1214e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry if (key->texture_data_type == BRW_REGISTER_TYPE_F) { 1215e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry /* Scale the result down by a factor of num_samples */ 1216e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry /* TODO: should use a smaller loop bound for non-RGBA formats */ 1217e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry for (int j = 0; j < 4; ++j) { 1218e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry brw_MUL(&func, offset(texture_data[0], 2*j), 1219e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry offset(vec8(texture_data[0]), 2*j), 1220e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry brw_imm_f(1.0/num_samples)); 1221e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry } 12224725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry } 1223f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry 1224f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry if (key->tex_layout == INTEL_MSAA_LAYOUT_CMS) 1225f91b4d92b97664e6354f66138705e93bec363ba0Paul Berry brw_ENDIF(&func); 12264725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry} 12274725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry 122819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 122919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to look up a value in the texture using the SAMPLE message (which 123019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * does blending of MSAA surfaces). 123119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 123219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 12334725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berrybrw_blorp_blit_program::sample(struct brw_reg dst) 123419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 1235665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry static const sampler_message_arg args[2] = { 1236665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_FLOAT, 1237665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_V_FLOAT 1238665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry }; 1239665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 12404725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry texture_lookup(dst, GEN5_SAMPLER_MESSAGE_SAMPLE, args, ARRAY_SIZE(args)); 124119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 124219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 124319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 1244506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to look up a value in the texture using the SAMPLE_LD message 1245506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (which does a simple texel fetch). 1246506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1247506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 12484725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berrybrw_blorp_blit_program::texel_fetch(struct brw_reg dst) 1249506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 12501c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry static const sampler_message_arg gen6_args[5] = { 1251665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 1252233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_V_INT, 1253233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, /* R */ 1254233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, /* LOD */ 1255233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_SI_INT 1256665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry }; 12571c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry static const sampler_message_arg gen7_ld_args[3] = { 12581c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 12591c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, /* LOD */ 12601c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_V_INT 12611c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry }; 12621c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry static const sampler_message_arg gen7_ld2dss_args[3] = { 12631c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_SI_INT, 12641c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 12651c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_V_INT 12661c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry }; 12674ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry static const sampler_message_arg gen7_ld2dms_args[4] = { 12684ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry SAMPLER_MESSAGE_ARG_SI_INT, 12694ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry SAMPLER_MESSAGE_ARG_MCS_INT, 12704ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 12714ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry SAMPLER_MESSAGE_ARG_V_INT 12724ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry }; 1273665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 12741c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry switch (brw->intel.gen) { 12751c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry case 6: 12764725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry texture_lookup(dst, GEN5_SAMPLER_MESSAGE_SAMPLE_LD, gen6_args, 12771c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry s_is_zero ? 2 : 5); 12781c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry break; 12791c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry case 7: 128060c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry switch (key->tex_layout) { 128160c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry case INTEL_MSAA_LAYOUT_IMS: 128260c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry /* From the Ivy Bridge PRM, Vol4 Part1 p72 (Multisampled Surface Storage 128360c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * Format): 128460c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * 128560c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * If this field is MSFMT_DEPTH_STENCIL 128660c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * [a.k.a. INTEL_MSAA_LAYOUT_IMS], the only sampling engine 128760c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * messages allowed are "ld2dms", "resinfo", and "sampleinfo". 128860c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * 128960c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * So fall through to emit the same message as we use for 129060c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * INTEL_MSAA_LAYOUT_CMS. 129160c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry */ 129260c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry case INTEL_MSAA_LAYOUT_CMS: 129360c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry texture_lookup(dst, GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS, 129460c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry gen7_ld2dms_args, ARRAY_SIZE(gen7_ld2dms_args)); 129560c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry break; 129660c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry case INTEL_MSAA_LAYOUT_UMS: 129760c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry texture_lookup(dst, GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS, 129860c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry gen7_ld2dss_args, ARRAY_SIZE(gen7_ld2dss_args)); 129960c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry break; 130060c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry case INTEL_MSAA_LAYOUT_NONE: 13011c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry assert(s_is_zero); 13024725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry texture_lookup(dst, GEN5_SAMPLER_MESSAGE_SAMPLE_LD, gen7_ld_args, 13031c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry ARRAY_SIZE(gen7_ld_args)); 130460c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry break; 13051c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry } 13061c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry break; 13071c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry default: 13081c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry assert(!"Should not get here."); 13091c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry break; 13101c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry }; 1311506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1312506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1313506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 13144ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berrybrw_blorp_blit_program::mcs_fetch() 13154ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry{ 13164ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry static const sampler_message_arg gen7_ld_mcs_args[2] = { 13174ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 13184ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry SAMPLER_MESSAGE_ARG_V_INT 13194ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry }; 13204ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry texture_lookup(vec16(mcs_data), GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS, 13214ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry gen7_ld_mcs_args, ARRAY_SIZE(gen7_ld_mcs_args)); 13224ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry} 13234ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry 13244ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berryvoid 1325665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berrybrw_blorp_blit_program::expand_to_32_bits(struct brw_reg src, 1326665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry struct brw_reg dst) 1327506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1328665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry brw_MOV(&func, vec8(dst), vec8(src)); 1329506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_compression_control(&func, BRW_COMPRESSION_2NDHALF); 1330665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry brw_MOV(&func, offset(vec8(dst), 1), suboffset(vec8(src), 8)); 1331506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_compression_control(&func, BRW_COMPRESSION_NONE); 1332665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry} 1333665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 1334665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berryvoid 13354725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berrybrw_blorp_blit_program::texture_lookup(struct brw_reg dst, 13364725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry GLuint msg_type, 1337665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry const sampler_message_arg *args, 1338665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry int num_args) 1339665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry{ 1340665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry struct brw_reg mrf = 1341665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry retype(vec16(brw_message_reg(base_mrf)), BRW_REGISTER_TYPE_UD); 1342665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry for (int arg = 0; arg < num_args; ++arg) { 1343665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry switch (args[arg]) { 1344665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_U_FLOAT: 1345665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(X, retype(mrf, BRW_REGISTER_TYPE_F)); 1346665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1347665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_V_FLOAT: 1348665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(Y, retype(mrf, BRW_REGISTER_TYPE_F)); 1349665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1350665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_U_INT: 1351665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(X, mrf); 1352665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1353665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_V_INT: 1354665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(Y, mrf); 1355665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1356233c207e9e477b6b0a5c6705e727129b92989073Paul Berry case SAMPLER_MESSAGE_ARG_SI_INT: 1357233c207e9e477b6b0a5c6705e727129b92989073Paul Berry /* Note: on Gen7, this code may be reached with s_is_zero==true 1358233c207e9e477b6b0a5c6705e727129b92989073Paul Berry * because in Gen7's ld2dss message, the sample index is the first 1359233c207e9e477b6b0a5c6705e727129b92989073Paul Berry * argument. When this happens, we need to move a 0 into the 1360233c207e9e477b6b0a5c6705e727129b92989073Paul Berry * appropriate message register. 1361233c207e9e477b6b0a5c6705e727129b92989073Paul Berry */ 1362233c207e9e477b6b0a5c6705e727129b92989073Paul Berry if (s_is_zero) 1363233c207e9e477b6b0a5c6705e727129b92989073Paul Berry brw_MOV(&func, mrf, brw_imm_ud(0)); 1364233c207e9e477b6b0a5c6705e727129b92989073Paul Berry else 1365233c207e9e477b6b0a5c6705e727129b92989073Paul Berry expand_to_32_bits(S, mrf); 1366233c207e9e477b6b0a5c6705e727129b92989073Paul Berry break; 13674ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry case SAMPLER_MESSAGE_ARG_MCS_INT: 136860c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry switch (key->tex_layout) { 136960c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry case INTEL_MSAA_LAYOUT_CMS: 137060c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry brw_MOV(&func, mrf, mcs_data); 137160c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry break; 137260c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry case INTEL_MSAA_LAYOUT_IMS: 137360c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry /* When sampling from an IMS surface, MCS data is not relevant, 137460c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * and the hardware ignores it. So don't bother populating it. 137560c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry */ 137660c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry break; 137760c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry default: 137860c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry /* We shouldn't be trying to send MCS data with any other 137960c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * layouts. 138060c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry */ 138160c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry assert (!"Unsupported layout for MCS data"); 138260c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry break; 138360c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry } 13844ebbc766210190cb1f03fa4fc762bf7ecc0c7f90Paul Berry break; 1385233c207e9e477b6b0a5c6705e727129b92989073Paul Berry case SAMPLER_MESSAGE_ARG_ZERO_INT: 1386233c207e9e477b6b0a5c6705e727129b92989073Paul Berry brw_MOV(&func, mrf, brw_imm_ud(0)); 1387233c207e9e477b6b0a5c6705e727129b92989073Paul Berry break; 1388665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry } 1389665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry mrf.nr += 2; 1390665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry } 1391506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1392506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SAMPLE(&func, 13934725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry retype(dst, BRW_REGISTER_TYPE_UW) /* dest */, 1394506d70be21cd3469118de89297cba0c0f709c1aePaul Berry base_mrf /* msg_reg_nr */, 1395665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry brw_message_reg(base_mrf) /* src0 */, 1396506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_BLORP_TEXTURE_BINDING_TABLE_INDEX, 1397665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 0 /* sampler */, 1398506d70be21cd3469118de89297cba0c0f709c1aePaul Berry WRITEMASK_XYZW, 1399506d70be21cd3469118de89297cba0c0f709c1aePaul Berry msg_type, 1400506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 8 /* response_length. TODO: should be smaller for non-RGBA formats? */, 1401665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry mrf.nr - base_mrf /* msg_length */, 1402506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 0 /* header_present */, 1403506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_SAMPLER_SIMD_MODE_SIMD16, 1404506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_SAMPLER_RETURN_FORMAT_FLOAT32); 1405506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1406506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1407506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef X 1408506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef Y 1409506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef U 1410506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef V 1411506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef S 1412506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef SWAP_XY_AND_XPYP 1413506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1414506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 1415506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::render_target_write() 1416506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1417e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry struct brw_reg mrf_rt_write = 1418e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry retype(vec16(brw_message_reg(base_mrf)), key->texture_data_type); 1419506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int mrf_offset = 0; 1420506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1421506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* If we may have killed pixels, then we need to send R0 and R1 in a header 1422506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * so that the render target knows which pixels we killed. 1423506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1424506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool use_header = key->use_kill; 1425506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (use_header) { 1426506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Copy R0/1 to MRF */ 1427506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_MOV(&func, retype(mrf_rt_write, BRW_REGISTER_TYPE_UD), 1428506d70be21cd3469118de89297cba0c0f709c1aePaul Berry retype(R0, BRW_REGISTER_TYPE_UD)); 1429506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_offset += 2; 1430506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1431506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1432506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Copy texture data to MRFs */ 1433506d70be21cd3469118de89297cba0c0f709c1aePaul Berry for (int i = 0; i < 4; ++i) { 1434506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* E.g. mov(16) m2.0<1>:f r2.0<8;8,1>:f { Align1, H1 } */ 14354725ba03cae87ddbf1fa10feaca3d42f24115f91Paul Berry brw_MOV(&func, offset(mrf_rt_write, mrf_offset), 1436b961d37e613b8b14927c42e09d16d09d70ebcb77Paul Berry offset(vec8(texture_data[0]), 2*i)); 1437506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_offset += 2; 1438506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1439506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1440506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Now write to the render target and terminate the thread */ 1441506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_fb_WRITE(&func, 1442506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 16 /* dispatch_width */, 1443506d70be21cd3469118de89297cba0c0f709c1aePaul Berry base_mrf /* msg_reg_nr */, 1444506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_rt_write /* src0 */, 144529362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE, 1446506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX, 1447506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_offset /* msg_length. TODO: Should be smaller for non-RGBA formats. */, 1448506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 0 /* response_length */, 1449506d70be21cd3469118de89297cba0c0f709c1aePaul Berry true /* eot */, 1450506d70be21cd3469118de89297cba0c0f709c1aePaul Berry use_header); 1451506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1452506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1453506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1454506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 1455506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_coord_transform_params::setup(GLuint src0, GLuint dst0, GLuint dst1, 1456506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool mirror) 1457506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1458506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!mirror) { 1459506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* When not mirroring a coordinate (say, X), we need: 1460506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' - src_x0 = x - dst_x0 1461506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Therefore: 1462506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' = 1*x + (src_x0 - dst_x0) 1463506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1464506d70be21cd3469118de89297cba0c0f709c1aePaul Berry multiplier = 1; 1465506d70be21cd3469118de89297cba0c0f709c1aePaul Berry offset = src0 - dst0; 1466506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } else { 1467506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* When mirroring X we need: 1468506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' - src_x0 = dst_x1 - x - 1 1469506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Therefore: 1470506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' = -1*x + (src_x0 + dst_x1 - 1) 1471506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1472506d70be21cd3469118de89297cba0c0f709c1aePaul Berry multiplier = -1; 1473506d70be21cd3469118de89297cba0c0f709c1aePaul Berry offset = src0 + dst1 - 1; 1474506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1475506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1476506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1477506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 14781bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry/** 14791bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * Determine which MSAA layout the GPU pipeline should be configured for, 14801bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * based on the chip generation, the number of samples, and the true layout of 14811bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * the image in memory. 14821bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry */ 14831bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berryinline intel_msaa_layout 14841bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berrycompute_msaa_layout_for_pipeline(struct brw_context *brw, unsigned num_samples, 14851bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry intel_msaa_layout true_layout) 14861bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry{ 14871bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry if (num_samples == 0) { 14881bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* When configuring the GPU for non-MSAA, we can still accommodate IMS 14891bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * format buffers, by transforming coordinates appropriately. 14901bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry */ 14911bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert(true_layout == INTEL_MSAA_LAYOUT_NONE || 14921bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry true_layout == INTEL_MSAA_LAYOUT_IMS); 14931bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry return INTEL_MSAA_LAYOUT_NONE; 14940dd5e98aa5c146ef21ab44b34fb7714206d5ec08Paul Berry } else { 14950dd5e98aa5c146ef21ab44b34fb7714206d5ec08Paul Berry assert(true_layout != INTEL_MSAA_LAYOUT_NONE); 14961bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry } 14971bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry 14981bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* Prior to Gen7, all MSAA surfaces use IMS layout. */ 14991bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry if (brw->intel.gen == 6) { 15001bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert(true_layout == INTEL_MSAA_LAYOUT_IMS); 15011bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry } 15021bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry 15031bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry return true_layout; 15041bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry} 15051bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry 15061bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry 15078b1f467cce34340637e9baca4847fc5273cf7541Paul Berrybrw_blorp_blit_params::brw_blorp_blit_params(struct brw_context *brw, 15088b1f467cce34340637e9baca4847fc5273cf7541Paul Berry struct intel_mipmap_tree *src_mt, 1509506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct intel_mipmap_tree *dst_mt, 1510506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint src_x0, GLuint src_y0, 1511506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint dst_x0, GLuint dst_y0, 1512506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint dst_x1, GLuint dst_y1, 1513506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool mirror_x, bool mirror_y) 1514506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1515530bda2aacf77b1e4661e5e5dd05cf108640e657Paul Berry src.set(brw, src_mt, 0, 0); 1516530bda2aacf77b1e4661e5e5dd05cf108640e657Paul Berry dst.set(brw, dst_mt, 0, 0); 1517506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1518506d70be21cd3469118de89297cba0c0f709c1aePaul Berry use_wm_prog = true; 1519506d70be21cd3469118de89297cba0c0f709c1aePaul Berry memset(&wm_prog_key, 0, sizeof(wm_prog_key)); 1520506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1521e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry /* texture_data_type indicates the register type that should be used to 1522e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry * manipulate texture data. 1523e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry */ 1524e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry switch (_mesa_get_format_datatype(src_mt->format)) { 1525e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry case GL_UNSIGNED_NORMALIZED: 1526e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry case GL_SIGNED_NORMALIZED: 1527e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry case GL_FLOAT: 1528e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry wm_prog_key.texture_data_type = BRW_REGISTER_TYPE_F; 1529e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry break; 1530e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry case GL_UNSIGNED_INT: 1531e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry if (src_mt->format == MESA_FORMAT_S8) { 1532e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry /* We process stencil as though it's an unsigned normalized color */ 1533e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry wm_prog_key.texture_data_type = BRW_REGISTER_TYPE_F; 1534e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry } else { 1535e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry wm_prog_key.texture_data_type = BRW_REGISTER_TYPE_UD; 1536e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry } 1537e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry break; 1538e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry case GL_INT: 1539e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry wm_prog_key.texture_data_type = BRW_REGISTER_TYPE_D; 1540e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry break; 1541e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry default: 1542e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry assert(!"Unrecognized blorp format"); 1543e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry break; 1544e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry } 1545e5d983267a98bf9f73f0ea981eaca339b975a8dbPaul Berry 15468b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (brw->intel.gen > 6) { 154760c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry /* Gen7's rendering hardware only supports the IMS layout for depth and 154860c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * stencil render targets. Blorp always maps its destination surface as 154960c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * a color render target (even if it's actually a depth or stencil 155060c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * buffer). So if the destination is IMS, we'll have to map it as a 155160c3e69dbf297426c42e4b8f94c5f0493bd9be5fPaul Berry * single-sampled texture and interleave the samples ourselves. 15528b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 15531bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry if (dst_mt->msaa_layout == INTEL_MSAA_LAYOUT_IMS) 15548b1f467cce34340637e9baca4847fc5273cf7541Paul Berry dst.num_samples = 0; 15558b1f467cce34340637e9baca4847fc5273cf7541Paul Berry } 15568b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 155734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (dst.map_stencil_as_y_tiled && dst.num_samples > 0) { 155834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* If the destination surface is a W-tiled multisampled stencil buffer 155934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * that we're mapping as Y tiled, then we need to arrange for the WM 156034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * program to run once per sample rather than once per pixel, because 156134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * the memory layout of related samples doesn't match between W and Y 156234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * tiling. 1563233c207e9e477b6b0a5c6705e727129b92989073Paul Berry */ 156434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry wm_prog_key.persample_msaa_dispatch = true; 1565233c207e9e477b6b0a5c6705e727129b92989073Paul Berry } 1566233c207e9e477b6b0a5c6705e727129b92989073Paul Berry 156734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (src.num_samples > 0 && dst.num_samples > 0) { 156819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We are blitting from a multisample buffer to a multisample buffer, so 156919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * we must preserve samples within a pixel. This means we have to 157034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * arrange for the WM program to run once per sample rather than once 157134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * per pixel. 157219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 157334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry wm_prog_key.persample_msaa_dispatch = true; 157419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 157519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 157619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* The render path must be configured to use the same number of samples as 157719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the destination buffer. 157819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 157919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry num_samples = dst.num_samples; 158019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 158119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry GLenum base_format = _mesa_get_format_base_format(src_mt->format); 158219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (base_format != GL_DEPTH_COMPONENT && /* TODO: what about depth/stencil? */ 158319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry base_format != GL_STENCIL_INDEX && 158419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry src_mt->num_samples > 0 && dst_mt->num_samples == 0) { 158519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We are downsampling a color buffer, so blend. */ 158619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.blend = true; 158719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 158819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 158919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* src_samples and dst_samples are the true sample counts */ 159019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.src_samples = src_mt->num_samples; 159119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.dst_samples = dst_mt->num_samples; 159219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 159319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* tex_samples and rt_samples are the sample counts that are set up in 159419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * SURFACE_STATE. 159519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 159619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.tex_samples = src.num_samples; 159719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.rt_samples = dst.num_samples; 159819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 15991bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* tex_layout and rt_layout indicate the MSAA layout the GPU pipeline will 16001bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * use to access the source and destination surfaces. 160167b0f7c7dddeb92ee4d24ed3977e20b70f5674f6Paul Berry */ 16021bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry wm_prog_key.tex_layout = 16031bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry compute_msaa_layout_for_pipeline(brw, src.num_samples, src.msaa_layout); 16041bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry wm_prog_key.rt_layout = 16051bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry compute_msaa_layout_for_pipeline(brw, dst.num_samples, dst.msaa_layout); 160667b0f7c7dddeb92ee4d24ed3977e20b70f5674f6Paul Berry 16071bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry /* src_layout and dst_layout indicate the true MSAA layout used by src and 16081bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * dst. 16098b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 16101bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry wm_prog_key.src_layout = src_mt->msaa_layout; 16111bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry wm_prog_key.dst_layout = dst_mt->msaa_layout; 16128b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 1613506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_prog_key.src_tiled_w = src.map_stencil_as_y_tiled; 1614506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_prog_key.dst_tiled_w = dst.map_stencil_as_y_tiled; 1615506d70be21cd3469118de89297cba0c0f709c1aePaul Berry x0 = wm_push_consts.dst_x0 = dst_x0; 1616506d70be21cd3469118de89297cba0c0f709c1aePaul Berry y0 = wm_push_consts.dst_y0 = dst_y0; 1617506d70be21cd3469118de89297cba0c0f709c1aePaul Berry x1 = wm_push_consts.dst_x1 = dst_x1; 1618506d70be21cd3469118de89297cba0c0f709c1aePaul Berry y1 = wm_push_consts.dst_y1 = dst_y1; 1619506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_push_consts.x_transform.setup(src_x0, dst_x0, dst_x1, mirror_x); 1620506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_push_consts.y_transform.setup(src_y0, dst_y0, dst_y1, mirror_y); 1621506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 162219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (dst.num_samples == 0 && dst_mt->num_samples > 0) { 162319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We must expand the rectangle we send through the rendering pipeline, 162419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * to account for the fact that we are mapping the destination region as 162519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * single-sampled when it is in fact multisampled. We must also align 162619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * it to a multiple of the multisampling pattern, because the 162719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * differences between multisampled and single-sampled surface formats 162819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * will mean that pixels are scrambled within the multisampling pattern. 162919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * TODO: what if this makes the coordinates too large? 16308b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * 16311bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * Note: this only works if the destination surface uses the IMS layout. 16321bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * If it's UMS, then we have no choice but to set up the rendering 16331bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * pipeline as multisampled. 163419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 16351bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry assert(dst_mt->msaa_layout == INTEL_MSAA_LAYOUT_IMS); 1636082874e3891e588f674508be6578f600b35852c4Paul Berry switch (dst_mt->num_samples) { 1637082874e3891e588f674508be6578f600b35852c4Paul Berry case 4: 1638082874e3891e588f674508be6578f600b35852c4Paul Berry x0 = (x0 * 2) & ~3; 1639082874e3891e588f674508be6578f600b35852c4Paul Berry y0 = (y0 * 2) & ~3; 1640082874e3891e588f674508be6578f600b35852c4Paul Berry x1 = ALIGN(x1 * 2, 4); 1641082874e3891e588f674508be6578f600b35852c4Paul Berry y1 = ALIGN(y1 * 2, 4); 1642082874e3891e588f674508be6578f600b35852c4Paul Berry break; 1643082874e3891e588f674508be6578f600b35852c4Paul Berry case 8: 1644082874e3891e588f674508be6578f600b35852c4Paul Berry x0 = (x0 * 4) & ~7; 1645082874e3891e588f674508be6578f600b35852c4Paul Berry y0 = (y0 * 2) & ~3; 1646082874e3891e588f674508be6578f600b35852c4Paul Berry x1 = ALIGN(x1 * 4, 8); 1647082874e3891e588f674508be6578f600b35852c4Paul Berry y1 = ALIGN(y1 * 2, 4); 1648082874e3891e588f674508be6578f600b35852c4Paul Berry break; 1649082874e3891e588f674508be6578f600b35852c4Paul Berry default: 1650082874e3891e588f674508be6578f600b35852c4Paul Berry assert(!"Unrecognized sample count in brw_blorp_blit_params ctor"); 1651082874e3891e588f674508be6578f600b35852c4Paul Berry break; 1652082874e3891e588f674508be6578f600b35852c4Paul Berry } 165319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.use_kill = true; 165419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 165519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 1656506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (dst.map_stencil_as_y_tiled) { 1657506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* We must modify the rectangle we send through the rendering pipeline, 1658506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * to account for the fact that we are mapping it as Y-tiled when it is 1659506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * in fact W-tiled. Y tiles have dimensions 128x32 whereas W tiles have 1660506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * dimensions 64x64. We must also align it to a multiple of the tile 1661506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * size, because the differences between W and Y tiling formats will 1662506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * mean that pixels are scrambled within the tile. 166334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 16641bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * Note: if the destination surface configured to use IMS layout, then 16651bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * the effective tile size we need to align it to is smaller, because 16661bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * each pixel covers a 2x2 or a 4x2 block of samples. 166734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 1668506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * TODO: what if this makes the coordinates too large? 1669506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 167034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry unsigned x_align = 64, y_align = 64; 16711bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry if (dst_mt->msaa_layout == INTEL_MSAA_LAYOUT_IMS) { 167234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry x_align /= (dst_mt->num_samples == 4 ? 2 : 4); 167334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry y_align /= 2; 167434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } 167534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry x0 = (x0 & ~(x_align - 1)) * 2; 167634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry y0 = (y0 & ~(y_align - 1)) / 2; 167734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry x1 = ALIGN(x1, x_align) * 2; 167834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry y1 = ALIGN(y1, y_align) / 2; 1679506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_prog_key.use_kill = true; 1680506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1681506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1682506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1683506d70be21cd3469118de89297cba0c0f709c1aePaul Berryuint32_t 1684506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_params::get_wm_prog(struct brw_context *brw, 1685506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_prog_data **prog_data) const 1686506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1687506d70be21cd3469118de89297cba0c0f709c1aePaul Berry uint32_t prog_offset; 1688506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!brw_search_cache(&brw->cache, BRW_BLORP_BLIT_PROG, 1689506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &this->wm_prog_key, sizeof(this->wm_prog_key), 1690506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &prog_offset, prog_data)) { 1691506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_blit_program prog(brw, &this->wm_prog_key); 1692506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint program_size; 1693506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const GLuint *program = prog.compile(brw, &program_size); 1694506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_upload_cache(&brw->cache, BRW_BLORP_BLIT_PROG, 1695506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &this->wm_prog_key, sizeof(this->wm_prog_key), 1696506d70be21cd3469118de89297cba0c0f709c1aePaul Berry program, program_size, 1697506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &prog.prog_data, sizeof(prog.prog_data), 1698506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &prog_offset, prog_data); 1699506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1700506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return prog_offset; 1701506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1702