brw_blorp_blit.cpp revision 8b1f467cce34340637e9baca4847fc5273cf7541
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 53506d70be21cd3469118de89297cba0c0f709c1aePaul Berrystatic bool 54506d70be21cd3469118de89297cba0c0f709c1aePaul Berrytry_blorp_blit(struct intel_context *intel, 55506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, 56506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 57506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLenum filter, GLbitfield buffer_bit) 58506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 59506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct gl_context *ctx = &intel->ctx; 60506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 61506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Sync up the state of window system buffers. We need to do this before 62506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * we go looking for the buffers. 63506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 64506d70be21cd3469118de89297cba0c0f709c1aePaul Berry intel_prepare_render(intel); 65506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 66506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Find buffers */ 67506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const struct gl_framebuffer *read_fb = ctx->ReadBuffer; 68506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const struct gl_framebuffer *draw_fb = ctx->DrawBuffer; 69506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct gl_renderbuffer *src_rb; 70506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct gl_renderbuffer *dst_rb; 71506d70be21cd3469118de89297cba0c0f709c1aePaul Berry switch (buffer_bit) { 72506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case GL_COLOR_BUFFER_BIT: 73506d70be21cd3469118de89297cba0c0f709c1aePaul Berry src_rb = read_fb->_ColorReadBuffer; 74506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dst_rb = 75506d70be21cd3469118de89297cba0c0f709c1aePaul Berry draw_fb->Attachment[ 76506d70be21cd3469118de89297cba0c0f709c1aePaul Berry draw_fb->_ColorDrawBufferIndexes[0]].Renderbuffer; 77506d70be21cd3469118de89297cba0c0f709c1aePaul Berry break; 78506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case GL_DEPTH_BUFFER_BIT: 79506d70be21cd3469118de89297cba0c0f709c1aePaul Berry src_rb = read_fb->Attachment[BUFFER_DEPTH].Renderbuffer; 80506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dst_rb = draw_fb->Attachment[BUFFER_DEPTH].Renderbuffer; 81506d70be21cd3469118de89297cba0c0f709c1aePaul Berry break; 82506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case GL_STENCIL_BUFFER_BIT: 83506d70be21cd3469118de89297cba0c0f709c1aePaul Berry src_rb = read_fb->Attachment[BUFFER_STENCIL].Renderbuffer; 84506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dst_rb = draw_fb->Attachment[BUFFER_STENCIL].Renderbuffer; 85506d70be21cd3469118de89297cba0c0f709c1aePaul Berry break; 86506d70be21cd3469118de89297cba0c0f709c1aePaul Berry default: 87506d70be21cd3469118de89297cba0c0f709c1aePaul Berry assert(false); 88506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 89506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 90506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Validate source */ 91506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!src_rb) return false; 92506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct intel_renderbuffer *src_irb = intel_renderbuffer(src_rb); 93506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct intel_mipmap_tree *src_mt = src_irb->mt; 94506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!src_mt) return false; 95506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (buffer_bit == GL_STENCIL_BUFFER_BIT && src_mt->stencil_mt) 96506d70be21cd3469118de89297cba0c0f709c1aePaul Berry src_mt = src_mt->stencil_mt; 97506d70be21cd3469118de89297cba0c0f709c1aePaul Berry switch (src_mt->format) { 98506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case MESA_FORMAT_ARGB8888: 99506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case MESA_FORMAT_X8_Z24: 100506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case MESA_FORMAT_S8: 101506d70be21cd3469118de89297cba0c0f709c1aePaul Berry break; /* Supported */ 102506d70be21cd3469118de89297cba0c0f709c1aePaul Berry default: 103506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Unsupported format. 104506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 105506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * TODO: need to support all formats that are allowed as multisample 106506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * render targets. 107506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 108506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return false; 109506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 110506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 111506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Validate destination */ 112506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!dst_rb) return false; 113506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct intel_renderbuffer *dst_irb = intel_renderbuffer(dst_rb); 114506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct intel_mipmap_tree *dst_mt = dst_irb->mt; 115506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!dst_mt) return false; 116506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (buffer_bit == GL_STENCIL_BUFFER_BIT && dst_mt->stencil_mt) 117506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dst_mt = dst_mt->stencil_mt; 118506d70be21cd3469118de89297cba0c0f709c1aePaul Berry switch (dst_mt->format) { 119506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case MESA_FORMAT_ARGB8888: 120506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case MESA_FORMAT_X8_Z24: 121506d70be21cd3469118de89297cba0c0f709c1aePaul Berry case MESA_FORMAT_S8: 122506d70be21cd3469118de89297cba0c0f709c1aePaul Berry break; /* Supported */ 123506d70be21cd3469118de89297cba0c0f709c1aePaul Berry default: 124506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Unsupported format. 125506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 126506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * TODO: need to support all formats that are allowed as multisample 127506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * render targets. 128506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 129506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return false; 130506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 131506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 132506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Account for the fact that in the system framebuffer, the origin is at 133506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * the lower left. 134506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 135506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (read_fb->Name == 0) { 136506d70be21cd3469118de89297cba0c0f709c1aePaul Berry srcY0 = read_fb->Height - srcY0; 137506d70be21cd3469118de89297cba0c0f709c1aePaul Berry srcY1 = read_fb->Height - srcY1; 138506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 139506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (draw_fb->Name == 0) { 140506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dstY0 = draw_fb->Height - dstY0; 141506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dstY1 = draw_fb->Height - dstY1; 142506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 143506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 144506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Detect if the blit needs to be mirrored */ 145506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool mirror_x = false, mirror_y = false; 146506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_x, srcX0, srcX1); 147506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_x, dstX0, dstX1); 148506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_y, srcY0, srcY1); 149506d70be21cd3469118de89297cba0c0f709c1aePaul Berry fixup_mirroring(mirror_y, dstY0, dstY1); 150506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 151506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Make sure width and height match */ 152506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLsizei width = srcX1 - srcX0; 153506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLsizei height = srcY1 - srcY0; 154506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (width != dstX1 - dstX0) return false; 155506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (height != dstY1 - dstY0) return false; 156506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 157506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Make sure width and height don't need to be clipped or scissored. 158506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * TODO: support clipping and scissoring. 159506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 160506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (srcX0 < 0 || (GLuint) srcX1 > read_fb->Width) return false; 161506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (srcY0 < 0 || (GLuint) srcY1 > read_fb->Height) return false; 162506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (dstX0 < 0 || (GLuint) dstX1 > draw_fb->Width) return false; 163506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (dstY0 < 0 || (GLuint) dstY1 > draw_fb->Height) return false; 164506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (ctx->Scissor.Enabled) return false; 165506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 166506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Get ready to blit. This includes depth resolving the src and dst 167506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * buffers if necessary. 168506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 169506d70be21cd3469118de89297cba0c0f709c1aePaul Berry intel_renderbuffer_resolve_depth(intel, src_irb); 170506d70be21cd3469118de89297cba0c0f709c1aePaul Berry intel_renderbuffer_resolve_depth(intel, dst_irb); 171506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 172506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Do the blit */ 1738b1f467cce34340637e9baca4847fc5273cf7541Paul Berry brw_blorp_blit_params params(brw_context(ctx), src_mt, dst_mt, 174506d70be21cd3469118de89297cba0c0f709c1aePaul Berry srcX0, srcY0, dstX0, dstY0, dstX1, dstY1, 175506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mirror_x, mirror_y); 1766335e0b0738a6e466f0b712e30ad9fe506f67a6cPaul Berry brw_blorp_exec(intel, ¶ms); 177506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 178506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Mark the dst buffer as needing a HiZ resolve if necessary. */ 179506d70be21cd3469118de89297cba0c0f709c1aePaul Berry intel_renderbuffer_set_needs_hiz_resolve(dst_irb); 180506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 181506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return true; 182506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 183506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 184506d70be21cd3469118de89297cba0c0f709c1aePaul BerryGLbitfield 185506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_framebuffer(struct intel_context *intel, 186506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, 187506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 188506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLbitfield mask, GLenum filter) 189506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 190b08545199ac8a01392a805f158d22cc03060a6fbPaul Berry /* BLORP is not supported before Gen6. */ 191b08545199ac8a01392a805f158d22cc03060a6fbPaul Berry if (intel->gen < 6) 192506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return mask; 193506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 194506d70be21cd3469118de89297cba0c0f709c1aePaul Berry static GLbitfield buffer_bits[] = { 195506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GL_COLOR_BUFFER_BIT, 196506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GL_DEPTH_BUFFER_BIT, 197506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GL_STENCIL_BUFFER_BIT, 198506d70be21cd3469118de89297cba0c0f709c1aePaul Berry }; 199506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 200506d70be21cd3469118de89297cba0c0f709c1aePaul Berry for (unsigned int i = 0; i < ARRAY_SIZE(buffer_bits); ++i) { 201506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if ((mask & buffer_bits[i]) && 202506d70be21cd3469118de89297cba0c0f709c1aePaul Berry try_blorp_blit(intel, 203506d70be21cd3469118de89297cba0c0f709c1aePaul Berry srcX0, srcY0, srcX1, srcY1, 204506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dstX0, dstY0, dstX1, dstY1, 205506d70be21cd3469118de89297cba0c0f709c1aePaul Berry filter, buffer_bits[i])) { 206506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mask &= ~buffer_bits[i]; 207506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 208506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 209506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 210506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return mask; 211506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 212506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 213665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 214665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry/** 215665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry * Enum to specify the order of arguments in a sampler message 216665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry */ 217665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berryenum sampler_message_arg 218665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry{ 219665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_FLOAT, 220665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_V_FLOAT, 221665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 222665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_V_INT, 223233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_SI_INT, 224233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, 225665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry}; 226665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 227506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 228506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Generator for WM programs used in BLORP blits. 229506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 230506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * The bulk of the work done by the WM program is to wrap and unwrap the 231506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinate transformations used by the hardware to store surfaces in 23219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * memory. The hardware transforms a pixel location (X, Y, S) (where S is the 23319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * sample index for a multisampled surface) to a memory offset by the 23419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * following formulas: 235506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 2368b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * offset = tile(tiling_format, encode_msaa(num_samples, layout, X, Y, S)) 2378b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X, Y, S) = decode_msaa(num_samples, layout, detile(tiling_format, offset)) 23819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 2398b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * For a single-sampled surface, or for a multisampled surface that stores 2408b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * each sample in a different array slice, encode_msaa() and decode_msaa are 2418b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * the identity function: 24219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 2438b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * encode_msaa(1, N/A, X, Y, 0) = (X, Y, 0) 2448b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * decode_msaa(1, N/A, X, Y, 0) = (X, Y, 0) 2458b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * encode_msaa(n, sliced, X, Y, S) = (X, Y, S) 2468b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * decode_msaa(n, sliced, X, Y, S) = (X, Y, S) 24719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 2488b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * For a 4x interleaved multisampled surface, encode_msaa() embeds the sample 2498b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * number into bit 1 of the X and Y coordinates: 25019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 2518b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * encode_msaa(4, interleaved, X, Y, S) = (X', Y', 0) 25219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b1) << 1 | (S & 0b1) << 1 | (X & 0b1) 25319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b1 ) << 1 | (S & 0b10) | (Y & 0b1) 2548b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * decode_msaa(4, interleaved, X, Y, 0) = (X', Y', S) 25519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b11) >> 1 | (X & 0b1) 25619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b11) >> 1 | (Y & 0b1) 25719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * S = (Y & 0b10) | (X & 0b10) >> 1 258506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 259506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * For X tiling, tile() combines together the low-order bits of the X and Y 260506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates in the pattern 0byyyxxxxxxxxx, creating 4k tiles that are 512 261506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * bytes wide and 8 rows high: 262506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 2638b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(x_tiled, X, Y, S) = A 264506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = tile_num << 12 | offset 2658b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile_num = (Y' >> 3) * tile_pitch + (X' >> 9) 2668b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * offset = (Y' & 0b111) << 9 267506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X & 0b111111111) 268506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp 2698b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 2708b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(x_tiled, A) = (X, Y, S) 271506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp 2728b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch 2738b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y' / qpitch 2748b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = (tile_num / tile_pitch) << 3 2758b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b111000000000) >> 9 276506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (tile_num % tile_pitch) << 9 277506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b111111111) 278506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 279506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (In all tiling formulas, cpp is the number of bytes occupied by a single 2808b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * sample ("chars per pixel"), tile_pitch is the number of 4k tiles required 2818b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * to fill the width of the surface, and qpitch is the spacing (in rows) 2828b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * between array slices). 283506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 284506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * For Y tiling, tile() combines together the low-order bits of the X and Y 285506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates in the pattern 0bxxxyyyyyxxxx, creating 4k tiles that are 128 286506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * bytes wide and 32 rows high: 287506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 2888b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(y_tiled, X, Y, S) = A 289506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = tile_num << 12 | offset 2908b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile_num = (Y' >> 5) * tile_pitch + (X' >> 7) 291506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * offset = (X' & 0b1110000) << 5 292506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (Y' & 0b11111) << 4 293506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b1111) 294506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp 2958b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 2968b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(y_tiled, A) = (X, Y, S) 297506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp 2988b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch 2998b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y' / qpitch 3008b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = (tile_num / tile_pitch) << 5 3018b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b111110000) >> 4 302506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (tile_num % tile_pitch) << 7 303506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b111000000000) >> 5 304506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b1111) 305506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 306506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * For W tiling, tile() combines together the low-order bits of the X and Y 307506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates in the pattern 0bxxxyyyyxyxyx, creating 4k tiles that are 64 308506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * bytes wide and 64 rows high (note that W tiling is only used for stencil 3098b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * buffers, which always have cpp = 1 and S=0): 310506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 3118b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(w_tiled, X, Y, S) = A 312506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = tile_num << 12 | offset 3138b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile_num = (Y' >> 6) * tile_pitch + (X' >> 6) 314506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * offset = (X' & 0b111000) << 6 3158b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (Y' & 0b111100) << 3 316506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b100) << 2 3178b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (Y' & 0b10) << 2 318506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b10) << 1 3198b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (Y' & 0b1) << 1 320506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (X' & 0b1) 321506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp = X 3228b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 3238b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(w_tiled, A) = (X, Y, S) 324506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp = X' 3258b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch = Y' 3268b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y / qpitch = 0 3278b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = (tile_num / tile_pitch) << 6 3288b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b111100000) >> 3 3298b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b1000) >> 2 3308b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * | (A & 0b10) >> 1 331506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (tile_num % tile_pitch) << 6 332506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b111000000000) >> 6 333506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b10000) >> 2 334506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b100) >> 1 335506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * | (A & 0b1) 336506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 337506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Finally, for a non-tiled surface, tile() simply combines together the X and 338506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y coordinates in the natural way: 339506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 3408b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tile(untiled, X, Y, S) = A 341506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where A = Y * pitch + X' 342506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = X * cpp 3438b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = Y + S * qpitch 3448b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * detile(untiled, A) = (X, Y, S) 345506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * where X = X' / cpp 3468b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y = Y' % qpitch 3478b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * S = Y' / qpitch 348506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = A % pitch 3498b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Y' = A / pitch 350506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 351506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (In these formulas, pitch is the number of bytes occupied by a single row 35219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * of samples). 353506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 354506d70be21cd3469118de89297cba0c0f709c1aePaul Berryclass brw_blorp_blit_program 355506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 356506d70be21cd3469118de89297cba0c0f709c1aePaul Berrypublic: 357506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_blit_program(struct brw_context *brw, 358506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const brw_blorp_blit_prog_key *key); 359506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ~brw_blorp_blit_program(); 360506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 361506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const GLuint *compile(struct brw_context *brw, GLuint *program_size); 362506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 363506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_prog_data prog_data; 364506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 365506d70be21cd3469118de89297cba0c0f709c1aePaul Berryprivate: 366506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void alloc_regs(); 367506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void alloc_push_const_regs(int base_reg); 368506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void compute_frag_coords(); 369506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void translate_tiling(bool old_tiled_w, bool new_tiled_w); 3708b1f467cce34340637e9baca4847fc5273cf7541Paul Berry void encode_msaa(unsigned num_samples, bool interleaved); 3718b1f467cce34340637e9baca4847fc5273cf7541Paul Berry void decode_msaa(unsigned num_samples, bool interleaved); 372506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void kill_if_outside_dst_rect(); 373506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void translate_dst_to_src(); 37419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry void single_to_blend(); 37519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry void sample(); 376506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void texel_fetch(); 377665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry void expand_to_32_bits(struct brw_reg src, struct brw_reg dst); 378665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry void texture_lookup(GLuint msg_type, const sampler_message_arg *args, 379665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry int num_args); 380506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void render_target_write(); 381506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 382506d70be21cd3469118de89297cba0c0f709c1aePaul Berry void *mem_ctx; 383506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_context *brw; 384506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const brw_blorp_blit_prog_key *key; 385506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_compile func; 386506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 387506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Thread dispatch header */ 388506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg R0; 389506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 390506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Pixel X/Y coordinates (always in R1). */ 391506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg R1; 392506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 393506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Push constants */ 394506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_x0; 395506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_x1; 396506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_y0; 397506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg dst_y1; 398506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct { 399506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg multiplier; 400506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg offset; 401506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } x_transform, y_transform; 402506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 403506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Data returned from texture lookup (4 vec16's) */ 404506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg Rdata; 405506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 406506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* X coordinates. We have two of them so that we can perform coordinate 407506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * transformations easily. 408506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 409506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg x_coords[2]; 410506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 411506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Y coordinates. We have two of them so that we can perform coordinate 412506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * transformations easily. 413506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 414506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg y_coords[2]; 415506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 416506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Which element of x_coords and y_coords is currently in use. 417506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 418506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int xy_coord_index; 419506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 42019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* True if, at the point in the program currently being compiled, the 42119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * sample index is known to be zero. 42219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 42319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry bool s_is_zero; 42419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 42519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Register storing the sample index when s_is_zero is false. */ 42619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry struct brw_reg sample_index; 42719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 428506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Temporaries */ 429506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg t1; 430506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg t2; 431506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 432665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry /* MRF used for sampling and render target writes */ 433506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint base_mrf; 434506d70be21cd3469118de89297cba0c0f709c1aePaul Berry}; 435506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 436506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::brw_blorp_blit_program( 437506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_context *brw, 438506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const brw_blorp_blit_prog_key *key) 439506d70be21cd3469118de89297cba0c0f709c1aePaul Berry : mem_ctx(ralloc_context(NULL)), 440506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw(brw), 441506d70be21cd3469118de89297cba0c0f709c1aePaul Berry key(key) 442506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 443506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_init_compile(brw, &func, mem_ctx); 444506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 445506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 446506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::~brw_blorp_blit_program() 447506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 448506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ralloc_free(mem_ctx); 449506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 450506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 451506d70be21cd3469118de89297cba0c0f709c1aePaul Berryconst GLuint * 452506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::compile(struct brw_context *brw, 453506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint *program_size) 454506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 4558b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Since blorp uses color textures and render targets to do all its work 4568b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (even when blitting stencil and depth data), we always have to configure 4578b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * the Gen7 GPU to use sliced layout on Gen7. On Gen6, the MSAA layout is 4588b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * always interleaved. 4598b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 4608b1f467cce34340637e9baca4847fc5273cf7541Paul Berry const bool rt_interleaved = key->rt_samples > 0 && brw->intel.gen == 6; 4618b1f467cce34340637e9baca4847fc5273cf7541Paul Berry const bool tex_interleaved = key->tex_samples > 0 && brw->intel.gen == 6; 4628b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 46319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Sanity checks */ 46434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (key->dst_tiled_w && key->rt_samples > 0) { 46534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* If the destination image is W tiled and multisampled, then the thread 46634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * must be dispatched once per sample, not once per pixel. This is 46734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * necessary because after conversion between W and Y tiling, there's no 46819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * guarantee that all samples corresponding to a single pixel will still 46919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * be together. 47019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 47134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry assert(key->persample_msaa_dispatch); 47219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 47319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 47419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (key->blend) { 47519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We are blending, which means we'll be using a SAMPLE message, which 47619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * causes the hardware to pick up the all of the samples corresponding 47719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * to this pixel and average them together. Since we'll be relying on 47819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the hardware to find all of the samples and combine them together, 47919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the surface state for the texture must be configured with the correct 48019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * tiling and sample count. 48119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 48219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry assert(!key->src_tiled_w); 48319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry assert(key->tex_samples == key->src_samples); 4848b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(tex_interleaved == key->src_interleaved); 48519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry assert(key->tex_samples > 0); 48619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 48719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 48834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (key->persample_msaa_dispatch) { 48934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* It only makes sense to do persample dispatch if the render target is 49034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * configured as multisampled. 49134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry */ 49234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry assert(key->rt_samples > 0); 49334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } 49434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry 4958b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Interleaved only makes sense on MSAA surfaces */ 4968b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (tex_interleaved) assert(key->tex_samples > 0); 4978b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (key->src_interleaved) assert(key->src_samples > 0); 4988b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (key->dst_interleaved) assert(key->dst_samples > 0); 4998b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 50034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* Set up prog_data */ 50134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry memset(&prog_data, 0, sizeof(prog_data)); 50234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry prog_data.persample_msaa_dispatch = key->persample_msaa_dispatch; 50334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry 504506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_compression_control(&func, BRW_COMPRESSION_NONE); 505506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 506506d70be21cd3469118de89297cba0c0f709c1aePaul Berry alloc_regs(); 507506d70be21cd3469118de89297cba0c0f709c1aePaul Berry compute_frag_coords(); 508506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 509506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Render target and texture hardware don't support W tiling. */ 510506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const bool rt_tiled_w = false; 511506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const bool tex_tiled_w = false; 512506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 513506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* The address that data will be written to is determined by the 51419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * coordinates supplied to the WM thread and the tiling and sample count of 51519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the render target, according to the formula: 516506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 51719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (X, Y, S) = decode_msaa(rt_samples, detile(rt_tiling, offset)) 518506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 51919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * If the actual tiling and sample count of the destination surface are not 52019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the same as the configuration of the render target, then these 52119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * coordinates are wrong and we have to adjust them to compensate for the 52219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * difference. 523506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 52419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (rt_tiled_w != key->dst_tiled_w || 5258b1f467cce34340637e9baca4847fc5273cf7541Paul Berry key->rt_samples != key->dst_samples || 5268b1f467cce34340637e9baca4847fc5273cf7541Paul Berry rt_interleaved != key->dst_interleaved) { 5278b1f467cce34340637e9baca4847fc5273cf7541Paul Berry encode_msaa(key->rt_samples, rt_interleaved); 5288b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(rt_tiling, offset) */ 529506d70be21cd3469118de89297cba0c0f709c1aePaul Berry translate_tiling(rt_tiled_w, key->dst_tiled_w); 5308b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(dst_tiling, offset) */ 5318b1f467cce34340637e9baca4847fc5273cf7541Paul Berry decode_msaa(key->dst_samples, key->dst_interleaved); 53219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 533506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 53419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Now (X, Y, S) = decode_msaa(dst_samples, detile(dst_tiling, offset)). 535506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 53619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * That is: X, Y and S now contain the true coordinates and sample index of 53719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the data that the WM thread should output. 538506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 539506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * If we need to kill pixels that are outside the destination rectangle, 540506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * now is the time to do it. 541506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 542506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 543506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (key->use_kill) 544506d70be21cd3469118de89297cba0c0f709c1aePaul Berry kill_if_outside_dst_rect(); 545506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 546506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Next, apply a translation to obtain coordinates in the source image. */ 547506d70be21cd3469118de89297cba0c0f709c1aePaul Berry translate_dst_to_src(); 548506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 54919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* If the source image is not multisampled, then we want to fetch sample 55019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * number 0, because that's the only sample there is. 551506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 55219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (key->src_samples == 0) 55319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry s_is_zero = true; 554506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 55519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* X, Y, and S are now the coordinates of the pixel in the source image 55619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * that we want to texture from. Exception: if we are blending, then S is 55719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * irrelevant, because we are going to fetch all samples. 558506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 55919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (key->blend) { 56019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry single_to_blend(); 56119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry sample(); 56219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } else { 56319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We aren't blending, which means we just want to fetch a single sample 56419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * from the source surface. The address that we want to fetch from is 56519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * related to the X, Y and S values according to the formula: 56619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 56719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (X, Y, S) = decode_msaa(src_samples, detile(src_tiling, offset)). 56819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 56919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * If the actual tiling and sample count of the source surface are not 57019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the same as the configuration of the texture, then we need to adjust 57119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the coordinates to compensate for the difference. 57219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 57319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (tex_tiled_w != key->src_tiled_w || 5748b1f467cce34340637e9baca4847fc5273cf7541Paul Berry key->tex_samples != key->src_samples || 5758b1f467cce34340637e9baca4847fc5273cf7541Paul Berry tex_interleaved != key->src_interleaved) { 5768b1f467cce34340637e9baca4847fc5273cf7541Paul Berry encode_msaa(key->src_samples, key->src_interleaved); 5778b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(src_tiling, offset) */ 57819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry translate_tiling(key->src_tiled_w, tex_tiled_w); 5798b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Now (X, Y, S) = detile(tex_tiling, offset) */ 5808b1f467cce34340637e9baca4847fc5273cf7541Paul Berry decode_msaa(key->tex_samples, tex_interleaved); 58119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 582506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 58319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Now (X, Y, S) = decode_msaa(tex_samples, detile(tex_tiling, offset)). 58419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 58519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * In other words: X, Y, and S now contain values which, when passed to 58619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the texturing unit, will cause data to be read from the correct 58719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * memory location. So we can fetch the texel now. 58819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 58919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry texel_fetch(); 59019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 59119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 59219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* Finally, write the fetched (or blended) value to the render target and 59319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * terminate the thread. 594506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 595506d70be21cd3469118de89297cba0c0f709c1aePaul Berry render_target_write(); 596506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return brw_get_program(&func, program_size); 597506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 598506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 599506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 600506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::alloc_push_const_regs(int base_reg) 601506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 602506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define CONST_LOC(name) offsetof(brw_blorp_wm_push_constants, name) 603506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define ALLOC_REG(name) \ 604506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->name = \ 605506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, base_reg, CONST_LOC(name) / 2) 606506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 607506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_x0); 608506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_x1); 609506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_y0); 610506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(dst_y1); 611506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(x_transform.multiplier); 612506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(x_transform.offset); 613506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(y_transform.multiplier); 614506d70be21cd3469118de89297cba0c0f709c1aePaul Berry ALLOC_REG(y_transform.offset); 615506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef CONST_LOC 616506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef ALLOC_REG 617506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 618506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 619506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 620506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::alloc_regs() 621506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 622506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int reg = 0; 623506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->R0 = retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW); 624506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->R1 = retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW); 625506d70be21cd3469118de89297cba0c0f709c1aePaul Berry prog_data.first_curbe_grf = reg; 626506d70be21cd3469118de89297cba0c0f709c1aePaul Berry alloc_push_const_regs(reg); 627506d70be21cd3469118de89297cba0c0f709c1aePaul Berry reg += BRW_BLORP_NUM_PUSH_CONST_REGS; 628506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->Rdata = vec16(brw_vec8_grf(reg, 0)); reg += 8; 629506d70be21cd3469118de89297cba0c0f709c1aePaul Berry for (int i = 0; i < 2; ++i) { 630506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->x_coords[i] 631506d70be21cd3469118de89297cba0c0f709c1aePaul Berry = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 632506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->y_coords[i] 633506d70be21cd3469118de89297cba0c0f709c1aePaul Berry = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 634506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 635506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->xy_coord_index = 0; 63619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry this->sample_index 63719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 638506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->t1 = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 639506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->t2 = vec16(retype(brw_vec8_grf(reg++, 0), BRW_REGISTER_TYPE_UW)); 640506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 641506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int mrf = 2; 642506d70be21cd3469118de89297cba0c0f709c1aePaul Berry this->base_mrf = mrf; 643506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 644506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 645506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/* In the code that follows, X and Y can be used to quickly refer to the 646506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * active elements of x_coords and y_coords, and Xp and Yp ("X prime" and "Y 647506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * prime") to the inactive elements. 64819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 64919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * S can be used to quickly refer to sample_index. 650506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 651506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define X x_coords[xy_coord_index] 652506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define Y y_coords[xy_coord_index] 653506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define Xp x_coords[!xy_coord_index] 654506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define Yp y_coords[!xy_coord_index] 65519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry#define S sample_index 656506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 657506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/* Quickly swap the roles of (X, Y) and (Xp, Yp). Saves us from having to do 658506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * MOVs to transfor (Xp, Yp) to (X, Y) after a coordinate transformation. 659506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 660506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#define SWAP_XY_AND_XPYP() xy_coord_index = !xy_coord_index; 661506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 662506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 663506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to compute the X and Y coordinates of the pixels being rendered 664506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * by this WM invocation. 665506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 666506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Assuming the render target is set up for Y tiling, these (X, Y) values are 667506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * related to the address offset where outputs will be written by the formula: 668506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 669506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (X, Y, S) = decode_msaa(detile(offset)). 670506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 671506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (See brw_blorp_blit_program). 672506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 673506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 674506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::compute_frag_coords() 675506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 676506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* R1.2[15:0] = X coordinate of upper left pixel of subspan 0 (pixel 0) 677506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.3[15:0] = X coordinate of upper left pixel of subspan 1 (pixel 4) 678506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.4[15:0] = X coordinate of upper left pixel of subspan 2 (pixel 8) 679506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.5[15:0] = X coordinate of upper left pixel of subspan 3 (pixel 12) 680506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 681506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Pixels within a subspan are laid out in this arrangement: 682506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 0 1 683506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 2 3 684506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 685506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * So, to compute the coordinates of each pixel, we need to read every 2nd 686506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 16-bit value (vstride=2) from R1, starting at the 4th 16-bit value 687506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (suboffset=4), and duplicate each value 4 times (hstride=0, width=4). 688506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * In other words, the data we want to access is R1.4<2;4,0>UW. 689506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 690506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Then, we need to add the repeating sequence (0, 1, 0, 1, ...) to the 691506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * result, since pixels n+1 and n+3 are in the right half of the subspan. 692506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 693506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, X, stride(suboffset(R1, 4), 2, 4, 0), brw_imm_v(0x10101010)); 694506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 695506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Similarly, Y coordinates for subspans come from R1.2[31:16] through 696506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.5[31:16], so to get pixel Y coordinates we need to start at the 5th 697506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 16-bit value instead of the 4th (R1.5<2;4,0>UW instead of 698506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * R1.4<2;4,0>UW). 699506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 700506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * And we need to add the repeating sequence (0, 0, 1, 1, ...), since 701506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * pixels n+2 and n+3 are in the bottom half of the subspan. 702506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 703506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, Y, stride(suboffset(R1, 5), 2, 4, 0), brw_imm_v(0x11001100)); 70419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 70534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (key->persample_msaa_dispatch) { 70634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* The WM will be run in MSDISPMODE_PERSAMPLE with num_samples > 0. 70734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * Therefore, subspan 0 will represent sample 0, subspan 1 will 70834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * represent sample 1, and so on. 70934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 71034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * So we need to populate S with the sequence (0, 0, 0, 0, 1, 1, 1, 1, 71134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 2, 2, 2, 2, 3, 3, 3, 3). The easiest way to do this is to populate a 71234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * temporary variable with the sequence (0, 1, 2, 3), and then copy from 71334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * it using vstride=1, width=4, hstride=0. 71434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 71534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * TODO: implement the necessary calculation for 8x multisampling. 71634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry */ 71734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry brw_MOV(&func, t1, brw_imm_v(0x3210)); 71834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry brw_MOV(&func, S, stride(t1, 1, 4, 0)); 71934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry s_is_zero = false; 72034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } else { 72134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* Either the destination surface is single-sampled, or the WM will be 72234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * run in MSDISPMODE_PERPIXEL (which causes a single fragment dispatch 72334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * per pixel). In either case, it's not meaningful to compute a sample 72434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * value. Just set it to 0. 72534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry */ 72634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry s_is_zero = true; 72734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } 728506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 729506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 730506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 731506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to compensate for the difference between Y and W tiling. 732506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 733506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * This code modifies the X and Y coordinates according to the formula: 734506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 7358b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X', Y', S') = detile(new_tiling, tile(old_tiling, X, Y, S)) 736506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 737506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (See brw_blorp_blit_program). 738506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 739506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * It can only translate between W and Y tiling, so new_tiling and old_tiling 740506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * are booleans where true represents W tiling and false represents Y tiling. 741506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 742506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 743506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::translate_tiling(bool old_tiled_w, bool new_tiled_w) 744506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 745506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (old_tiled_w == new_tiled_w) 746506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return; 747506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 7488b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* In the code that follows, we can safely assume that S = 0, because W 7498b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * tiling formats always use interleaved encoding. 7508b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 7518b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 7528b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 753506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (new_tiled_w) { 754506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Given X and Y coordinates that describe an address using Y tiling, 755506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * translate to the X and Y coordinates that describe the same address 756506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * using W tiling. 757506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 758506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * If we break down the low order bits of X and Y, using a 759506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * single letter to represent each low-order bit: 760506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 761506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X = A << 7 | 0bBCDEFGH 762506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y = J << 5 | 0bKLMNP (1) 763506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 764506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Then we can apply the Y tiling formula to see the memory offset being 765506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * addressed: 766506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 767506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * offset = (J * tile_pitch + A) << 12 | 0bBCDKLMNPEFGH (2) 768506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 769506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * If we apply the W detiling formula to this memory location, that the 770506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * corresponding X' and Y' coordinates are: 771506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 772506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = A << 6 | 0bBCDPFH (3) 773506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y' = J << 6 | 0bKLMNEG 774506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 775506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Combining (1) and (3), we see that to transform (X, Y) to (X', Y'), 776506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * we need to make the following computation: 777506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 778506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (X & ~0b1011) >> 1 | (Y & 0b1) << 2 | X & 0b1 (4) 779506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y' = (Y & ~0b1) << 1 | (X & 0b1000) >> 2 | (X & 0b10) >> 1 780506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 781506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfff4)); /* X & ~0b1011 */ 782506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b1011) >> 1 */ 783506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); /* Y & 0b1 */ 784506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t2, t2, brw_imm_uw(2)); /* (Y & 0b1) << 2 */ 785506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b1011) >> 1 | (Y & 0b1) << 2 */ 786506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 787506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Xp, t1, t2); 788506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffe)); /* Y & ~0b1 */ 789506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b1) << 1 */ 790506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(8)); /* X & 0b1000 */ 791506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(2)); /* (X & 0b1000) >> 2 */ 792506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (Y & ~0b1) << 1 | (X & 0b1000) >> 2 */ 793506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(2)); /* X & 0b10 */ 794506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(1)); /* (X & 0b10) >> 1 */ 795506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Yp, t1, t2); 796506d70be21cd3469118de89297cba0c0f709c1aePaul Berry SWAP_XY_AND_XPYP(); 797506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } else { 798506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Applying the same logic as above, but in reverse, we obtain the 799506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * formulas: 800506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * 801506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * X' = (X & ~0b101) << 1 | (Y & 0b10) << 2 | (Y & 0b1) << 1 | X & 0b1 802506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Y' = (Y & ~0b11) >> 1 | (X & 0b100) >> 2 803506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 804506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfffa)); /* X & ~0b101 */ 805506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b101) << 1 */ 806506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, Y, brw_imm_uw(2)); /* Y & 0b10 */ 807506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t2, t2, brw_imm_uw(2)); /* (Y & 0b10) << 2 */ 808506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b101) << 1 | (Y & 0b10) << 2 */ 809506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); /* Y & 0b1 */ 810506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHL(&func, t2, t2, brw_imm_uw(1)); /* (Y & 0b1) << 1 */ 811506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b101) << 1 | (Y & 0b10) << 2 812506d70be21cd3469118de89297cba0c0f709c1aePaul Berry | (Y & 0b1) << 1 */ 813506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 814506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Xp, t1, t2); 815506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffc)); /* Y & ~0b11 */ 816506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b11) >> 1 */ 817506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, t2, X, brw_imm_uw(4)); /* X & 0b100 */ 818506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(2)); /* (X & 0b100) >> 2 */ 819506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_OR(&func, Yp, t1, t2); 820506d70be21cd3469118de89297cba0c0f709c1aePaul Berry SWAP_XY_AND_XPYP(); 821506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 822506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 823506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 824506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 82519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to compensate for the difference between MSAA and non-MSAA 82619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * surfaces. 82719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 82819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * This code modifies the X and Y coordinates according to the formula: 82919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 8308b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X', Y', S') = encode_msaa_4x(X, Y, S) 83119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 83219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (See brw_blorp_blit_program). 83319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 83419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 8358b1f467cce34340637e9baca4847fc5273cf7541Paul Berrybrw_blorp_blit_program::encode_msaa(unsigned num_samples, bool interleaved) 83619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 83719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (num_samples == 0) { 8388b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* No translation necessary, and S should already be zero. */ 8398b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 8408b1f467cce34340637e9baca4847fc5273cf7541Paul Berry } else if (!interleaved) { 84119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* No translation necessary. */ 84219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } else { 8438b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* encode_msaa(4, interleaved, X, Y, S) = (X', Y', 0) 84419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b1) << 1 | (S & 0b1) << 1 | (X & 0b1) 84519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b1 ) << 1 | (S & 0b10) | (Y & 0b1) 84619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 84719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfffe)); /* X & ~0b1 */ 84819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (!s_is_zero) { 84919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, S, brw_imm_uw(1)); /* S & 0b1 */ 85019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, t1, t1, t2); /* (X & ~0b1) | (S & 0b1) */ 85119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 85219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b1) << 1 85319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry | (S & 0b1) << 1 */ 85419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 85519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Xp, t1, t2); 85619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffe)); /* Y & ~0b1 */ 85719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b1) << 1 */ 85819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (!s_is_zero) { 85919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, S, brw_imm_uw(2)); /* S & 0b10 */ 86019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, t1, t1, t2); /* (Y & ~0b1) << 1 | (S & 0b10) */ 86119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 86219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); 86319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Yp, t1, t2); 86419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry SWAP_XY_AND_XPYP(); 8658b1f467cce34340637e9baca4847fc5273cf7541Paul Berry s_is_zero = true; 86619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 86719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 86819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 86919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 87019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to compensate for the difference between MSAA and non-MSAA 87119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * surfaces. 87219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 87319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * This code modifies the X and Y coordinates according to the formula: 87419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 8758b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * (X', Y', S) = decode_msaa(num_samples, X, Y, S) 87619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 87719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * (See brw_blorp_blit_program). 87819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 87919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 8808b1f467cce34340637e9baca4847fc5273cf7541Paul Berrybrw_blorp_blit_program::decode_msaa(unsigned num_samples, bool interleaved) 88119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 88219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (num_samples == 0) { 8838b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* No translation necessary, and S should already be zero. */ 8848b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 8858b1f467cce34340637e9baca4847fc5273cf7541Paul Berry } else if (!interleaved) { 88619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* No translation necessary. */ 88719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } else { 8888b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* decode_msaa(4, interleaved, X, Y, 0) = (X', Y', S) 88919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * where X' = (X & ~0b11) >> 1 | (X & 0b1) 89019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Y' = (Y & ~0b11) >> 1 | (Y & 0b1) 89119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * S = (Y & 0b10) | (X & 0b10) >> 1 89219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 8938b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(s_is_zero); 89419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, X, brw_imm_uw(0xfffc)); /* X & ~0b11 */ 89519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (X & ~0b11) >> 1 */ 89619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, X, brw_imm_uw(1)); /* X & 0b1 */ 89719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Xp, t1, t2); 89819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, Y, brw_imm_uw(0xfffc)); /* Y & ~0b11 */ 89919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHR(&func, t1, t1, brw_imm_uw(1)); /* (Y & ~0b11) >> 1 */ 90019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, Y, brw_imm_uw(1)); /* Y & 0b1 */ 90119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, Yp, t1, t2); 90219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t1, Y, brw_imm_uw(2)); /* Y & 0b10 */ 90319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_AND(&func, t2, X, brw_imm_uw(2)); /* X & 0b10 */ 90419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHR(&func, t2, t2, brw_imm_uw(1)); /* (X & 0b10) >> 1 */ 90519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_OR(&func, S, t1, t2); 90619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry s_is_zero = false; 90719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry SWAP_XY_AND_XPYP(); 90819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 90919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 91019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 91119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 912506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code that kills pixels whose X and Y coordinates are outside the 913506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * boundary of the rectangle defined by the push constants (dst_x0, dst_y0, 914506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * dst_x1, dst_y1). 915506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 916506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 917506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::kill_if_outside_dst_rect() 918506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 919506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg f0 = brw_flag_reg(); 920506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg g1 = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW); 921506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg null16 = vec16(retype(brw_null_reg(), BRW_REGISTER_TYPE_UW)); 922506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 923506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_GE, X, dst_x0); 924506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_GE, Y, dst_y0); 925506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_L, X, dst_x1); 926506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_CMP(&func, null16, BRW_CONDITIONAL_L, Y, dst_y1); 927506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 928506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_predicate_control(&func, BRW_PREDICATE_NONE); 929506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_push_insn_state(&func); 930506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_mask_control(&func, BRW_MASK_DISABLE); 931506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_AND(&func, g1, f0, g1); 932506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_pop_insn_state(&func); 933506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 934506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 935506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 936506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to translate from destination (X, Y) coordinates to source (X, Y) 937506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * coordinates. 938506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 939506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 940506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::translate_dst_to_src() 941506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 942506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_MUL(&func, Xp, X, x_transform.multiplier); 943506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_MUL(&func, Yp, Y, y_transform.multiplier); 944506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, Xp, Xp, x_transform.offset); 945506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_ADD(&func, Yp, Yp, y_transform.offset); 946506d70be21cd3469118de89297cba0c0f709c1aePaul Berry SWAP_XY_AND_XPYP(); 947506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 948506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 949506d70be21cd3469118de89297cba0c0f709c1aePaul Berry/** 95019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to transform the X and Y coordinates as needed for blending 95119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * together the different samples in an MSAA texture. 95219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 95319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 95419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berrybrw_blorp_blit_program::single_to_blend() 95519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 95619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* When looking up samples in an MSAA texture using the SAMPLE message, 95719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Gen6 requires the texture coordinates to be odd integers (so that they 95819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * correspond to the center of a 2x2 block representing the four samples 95919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * that maxe up a pixel). So we need to multiply our X and Y coordinates 96019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * each by 2 and then add 1. 96119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 96219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t1, X, brw_imm_w(1)); 96319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_SHL(&func, t2, Y, brw_imm_w(1)); 96419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_ADD(&func, Xp, t1, brw_imm_w(1)); 96519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry brw_ADD(&func, Yp, t2, brw_imm_w(1)); 96619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry SWAP_XY_AND_XPYP(); 96719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 96819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 96919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 97019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Emit code to look up a value in the texture using the SAMPLE message (which 97119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * does blending of MSAA surfaces). 97219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 97319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 97419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berrybrw_blorp_blit_program::sample() 97519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 976665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry static const sampler_message_arg args[2] = { 977665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_FLOAT, 978665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_V_FLOAT 979665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry }; 980665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 981665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry texture_lookup(GEN5_SAMPLER_MESSAGE_SAMPLE, args, ARRAY_SIZE(args)); 98219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 98319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 98419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 985506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Emit code to look up a value in the texture using the SAMPLE_LD message 986506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * (which does a simple texel fetch). 987506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 988506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 989506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::texel_fetch() 990506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 9911c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry static const sampler_message_arg gen6_args[5] = { 992665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 993233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_V_INT, 994233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, /* R */ 995233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, /* LOD */ 996233c207e9e477b6b0a5c6705e727129b92989073Paul Berry SAMPLER_MESSAGE_ARG_SI_INT 997665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry }; 9981c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry static const sampler_message_arg gen7_ld_args[3] = { 9991c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 10001c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_ZERO_INT, /* LOD */ 10011c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_V_INT 10021c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry }; 10031c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry static const sampler_message_arg gen7_ld2dss_args[3] = { 10041c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_SI_INT, 10051c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_U_INT, 10061c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry SAMPLER_MESSAGE_ARG_V_INT 10071c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry }; 1008665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 10091c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry switch (brw->intel.gen) { 10101c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry case 6: 10111c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry texture_lookup(GEN5_SAMPLER_MESSAGE_SAMPLE_LD, gen6_args, 10121c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry s_is_zero ? 2 : 5); 10131c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry break; 10141c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry case 7: 10151c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry if (key->tex_samples > 0) { 10161c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry texture_lookup(GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS, 10171c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry gen7_ld2dss_args, ARRAY_SIZE(gen7_ld2dss_args)); 10181c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry } else { 10191c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry assert(s_is_zero); 10201c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry texture_lookup(GEN5_SAMPLER_MESSAGE_SAMPLE_LD, gen7_ld_args, 10211c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry ARRAY_SIZE(gen7_ld_args)); 10221c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry } 10231c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry break; 10241c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry default: 10251c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry assert(!"Should not get here."); 10261c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry break; 10271c73c705fadf164d61003415e3380f2d06f2e7b3Paul Berry }; 1028506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1029506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1030506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 1031665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berrybrw_blorp_blit_program::expand_to_32_bits(struct brw_reg src, 1032665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry struct brw_reg dst) 1033506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1034665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry brw_MOV(&func, vec8(dst), vec8(src)); 1035506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_compression_control(&func, BRW_COMPRESSION_2NDHALF); 1036665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry brw_MOV(&func, offset(vec8(dst), 1), suboffset(vec8(src), 8)); 1037506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_set_compression_control(&func, BRW_COMPRESSION_NONE); 1038665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry} 1039665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 1040665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berryvoid 1041665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berrybrw_blorp_blit_program::texture_lookup(GLuint msg_type, 1042665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry const sampler_message_arg *args, 1043665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry int num_args) 1044665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry{ 1045665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry struct brw_reg mrf = 1046665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry retype(vec16(brw_message_reg(base_mrf)), BRW_REGISTER_TYPE_UD); 1047665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry for (int arg = 0; arg < num_args; ++arg) { 1048665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry switch (args[arg]) { 1049665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_U_FLOAT: 1050665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(X, retype(mrf, BRW_REGISTER_TYPE_F)); 1051665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1052665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_V_FLOAT: 1053665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(Y, retype(mrf, BRW_REGISTER_TYPE_F)); 1054665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1055665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_U_INT: 1056665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(X, mrf); 1057665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1058665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry case SAMPLER_MESSAGE_ARG_V_INT: 1059665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry expand_to_32_bits(Y, mrf); 1060665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry break; 1061233c207e9e477b6b0a5c6705e727129b92989073Paul Berry case SAMPLER_MESSAGE_ARG_SI_INT: 1062233c207e9e477b6b0a5c6705e727129b92989073Paul Berry /* Note: on Gen7, this code may be reached with s_is_zero==true 1063233c207e9e477b6b0a5c6705e727129b92989073Paul Berry * because in Gen7's ld2dss message, the sample index is the first 1064233c207e9e477b6b0a5c6705e727129b92989073Paul Berry * argument. When this happens, we need to move a 0 into the 1065233c207e9e477b6b0a5c6705e727129b92989073Paul Berry * appropriate message register. 1066233c207e9e477b6b0a5c6705e727129b92989073Paul Berry */ 1067233c207e9e477b6b0a5c6705e727129b92989073Paul Berry if (s_is_zero) 1068233c207e9e477b6b0a5c6705e727129b92989073Paul Berry brw_MOV(&func, mrf, brw_imm_ud(0)); 1069233c207e9e477b6b0a5c6705e727129b92989073Paul Berry else 1070233c207e9e477b6b0a5c6705e727129b92989073Paul Berry expand_to_32_bits(S, mrf); 1071233c207e9e477b6b0a5c6705e727129b92989073Paul Berry break; 1072233c207e9e477b6b0a5c6705e727129b92989073Paul Berry case SAMPLER_MESSAGE_ARG_ZERO_INT: 1073233c207e9e477b6b0a5c6705e727129b92989073Paul Berry brw_MOV(&func, mrf, brw_imm_ud(0)); 1074233c207e9e477b6b0a5c6705e727129b92989073Paul Berry break; 1075665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry } 1076665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry mrf.nr += 2; 1077665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry } 1078506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1079506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_SAMPLE(&func, 1080506d70be21cd3469118de89297cba0c0f709c1aePaul Berry retype(Rdata, BRW_REGISTER_TYPE_UW) /* dest */, 1081506d70be21cd3469118de89297cba0c0f709c1aePaul Berry base_mrf /* msg_reg_nr */, 1082665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry brw_message_reg(base_mrf) /* src0 */, 1083506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_BLORP_TEXTURE_BINDING_TABLE_INDEX, 1084665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry 0 /* sampler */, 1085506d70be21cd3469118de89297cba0c0f709c1aePaul Berry WRITEMASK_XYZW, 1086506d70be21cd3469118de89297cba0c0f709c1aePaul Berry msg_type, 1087506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 8 /* response_length. TODO: should be smaller for non-RGBA formats? */, 1088665dc82bdc0e83854dd0f700ec264021bfb5cb39Paul Berry mrf.nr - base_mrf /* msg_length */, 1089506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 0 /* header_present */, 1090506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_SAMPLER_SIMD_MODE_SIMD16, 1091506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_SAMPLER_RETURN_FORMAT_FLOAT32); 1092506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1093506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1094506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef X 1095506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef Y 1096506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef U 1097506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef V 1098506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef S 1099506d70be21cd3469118de89297cba0c0f709c1aePaul Berry#undef SWAP_XY_AND_XPYP 1100506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1101506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 1102506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_program::render_target_write() 1103506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1104506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct brw_reg mrf_rt_write = vec16(brw_message_reg(base_mrf)); 1105506d70be21cd3469118de89297cba0c0f709c1aePaul Berry int mrf_offset = 0; 1106506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1107506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* If we may have killed pixels, then we need to send R0 and R1 in a header 1108506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * so that the render target knows which pixels we killed. 1109506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1110506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool use_header = key->use_kill; 1111506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (use_header) { 1112506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Copy R0/1 to MRF */ 1113506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_MOV(&func, retype(mrf_rt_write, BRW_REGISTER_TYPE_UD), 1114506d70be21cd3469118de89297cba0c0f709c1aePaul Berry retype(R0, BRW_REGISTER_TYPE_UD)); 1115506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_offset += 2; 1116506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1117506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1118506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Copy texture data to MRFs */ 1119506d70be21cd3469118de89297cba0c0f709c1aePaul Berry for (int i = 0; i < 4; ++i) { 1120506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* E.g. mov(16) m2.0<1>:f r2.0<8;8,1>:f { Align1, H1 } */ 1121506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_MOV(&func, offset(mrf_rt_write, mrf_offset), offset(vec8(Rdata), 2*i)); 1122506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_offset += 2; 1123506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1124506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1125506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* Now write to the render target and terminate the thread */ 1126506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_fb_WRITE(&func, 1127506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 16 /* dispatch_width */, 1128506d70be21cd3469118de89297cba0c0f709c1aePaul Berry base_mrf /* msg_reg_nr */, 1129506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_rt_write /* src0 */, 113029362875f2613ad87abe7725ce3c56c36d16cf9bEric Anholt BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE, 1131506d70be21cd3469118de89297cba0c0f709c1aePaul Berry BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX, 1132506d70be21cd3469118de89297cba0c0f709c1aePaul Berry mrf_offset /* msg_length. TODO: Should be smaller for non-RGBA formats. */, 1133506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 0 /* response_length */, 1134506d70be21cd3469118de89297cba0c0f709c1aePaul Berry true /* eot */, 1135506d70be21cd3469118de89297cba0c0f709c1aePaul Berry use_header); 1136506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1137506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1138506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1139506d70be21cd3469118de89297cba0c0f709c1aePaul Berryvoid 1140506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_coord_transform_params::setup(GLuint src0, GLuint dst0, GLuint dst1, 1141506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool mirror) 1142506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1143506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!mirror) { 1144506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* When not mirroring a coordinate (say, X), we need: 1145506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' - src_x0 = x - dst_x0 1146506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Therefore: 1147506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' = 1*x + (src_x0 - dst_x0) 1148506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1149506d70be21cd3469118de89297cba0c0f709c1aePaul Berry multiplier = 1; 1150506d70be21cd3469118de89297cba0c0f709c1aePaul Berry offset = src0 - dst0; 1151506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } else { 1152506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* When mirroring X we need: 1153506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' - src_x0 = dst_x1 - x - 1 1154506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * Therefore: 1155506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * x' = -1*x + (src_x0 + dst_x1 - 1) 1156506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 1157506d70be21cd3469118de89297cba0c0f709c1aePaul Berry multiplier = -1; 1158506d70be21cd3469118de89297cba0c0f709c1aePaul Berry offset = src0 + dst1 - 1; 1159506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1160506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1161506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1162506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 11638b1f467cce34340637e9baca4847fc5273cf7541Paul Berrybrw_blorp_blit_params::brw_blorp_blit_params(struct brw_context *brw, 11648b1f467cce34340637e9baca4847fc5273cf7541Paul Berry struct intel_mipmap_tree *src_mt, 1165506d70be21cd3469118de89297cba0c0f709c1aePaul Berry struct intel_mipmap_tree *dst_mt, 1166506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint src_x0, GLuint src_y0, 1167506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint dst_x0, GLuint dst_y0, 1168506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint dst_x1, GLuint dst_y1, 1169506d70be21cd3469118de89297cba0c0f709c1aePaul Berry bool mirror_x, bool mirror_y) 1170506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1171506d70be21cd3469118de89297cba0c0f709c1aePaul Berry src.set(src_mt, 0, 0); 1172506d70be21cd3469118de89297cba0c0f709c1aePaul Berry dst.set(dst_mt, 0, 0); 1173506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1174506d70be21cd3469118de89297cba0c0f709c1aePaul Berry use_wm_prog = true; 1175506d70be21cd3469118de89297cba0c0f709c1aePaul Berry memset(&wm_prog_key, 0, sizeof(wm_prog_key)); 1176506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 11778b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (brw->intel.gen > 6) { 11788b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Gen7 only supports interleaved MSAA surfaces for texturing with the 11798b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * ld2dms instruction (which blorp doesn't use). So if the source is 11808b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * interleaved MSAA, we'll have to map it as a single-sampled texture 11818b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * and de-interleave the samples ourselves. 11828b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 11838b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (src.num_samples > 0 && src_mt->msaa_is_interleaved) 11848b1f467cce34340637e9baca4847fc5273cf7541Paul Berry src.num_samples = 0; 11858b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 11868b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* Similarly, Gen7 only supports interleaved MSAA surfaces for depth and 11878b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * stencil render targets. Blorp always maps its destination surface as 11888b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * a color render target (even if it's actually a depth or stencil 11898b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * buffer). So if the destination is interleaved MSAA, we'll have to 11908b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * map it as a single-sampled texture and interleave the samples 11918b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * ourselves. 11928b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 11938b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (dst.num_samples > 0 && dst_mt->msaa_is_interleaved) 11948b1f467cce34340637e9baca4847fc5273cf7541Paul Berry dst.num_samples = 0; 11958b1f467cce34340637e9baca4847fc5273cf7541Paul Berry } 11968b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 119734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (dst.map_stencil_as_y_tiled && dst.num_samples > 0) { 119834a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry /* If the destination surface is a W-tiled multisampled stencil buffer 119934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * that we're mapping as Y tiled, then we need to arrange for the WM 120034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * program to run once per sample rather than once per pixel, because 120134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * the memory layout of related samples doesn't match between W and Y 120234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * tiling. 1203233c207e9e477b6b0a5c6705e727129b92989073Paul Berry */ 120434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry wm_prog_key.persample_msaa_dispatch = true; 1205233c207e9e477b6b0a5c6705e727129b92989073Paul Berry } 1206233c207e9e477b6b0a5c6705e727129b92989073Paul Berry 120734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry if (src.num_samples > 0 && dst.num_samples > 0) { 120819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We are blitting from a multisample buffer to a multisample buffer, so 120919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * we must preserve samples within a pixel. This means we have to 121034a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * arrange for the WM program to run once per sample rather than once 121134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * per pixel. 121219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 121334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry wm_prog_key.persample_msaa_dispatch = true; 121419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 121519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 121619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* The render path must be configured to use the same number of samples as 121719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the destination buffer. 121819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 121919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry num_samples = dst.num_samples; 122019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 122119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry GLenum base_format = _mesa_get_format_base_format(src_mt->format); 122219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (base_format != GL_DEPTH_COMPONENT && /* TODO: what about depth/stencil? */ 122319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry base_format != GL_STENCIL_INDEX && 122419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry src_mt->num_samples > 0 && dst_mt->num_samples == 0) { 122519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We are downsampling a color buffer, so blend. */ 122619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.blend = true; 122719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 122819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 122919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* src_samples and dst_samples are the true sample counts */ 123019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.src_samples = src_mt->num_samples; 123119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.dst_samples = dst_mt->num_samples; 123219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 123319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* tex_samples and rt_samples are the sample counts that are set up in 123419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * SURFACE_STATE. 123519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 123619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.tex_samples = src.num_samples; 123719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.rt_samples = dst.num_samples; 123819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 12398b1f467cce34340637e9baca4847fc5273cf7541Paul Berry /* src_interleaved and dst_interleaved indicate whether src and dst are 12408b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * truly interleaved. 12418b1f467cce34340637e9baca4847fc5273cf7541Paul Berry */ 12428b1f467cce34340637e9baca4847fc5273cf7541Paul Berry wm_prog_key.src_interleaved = src_mt->msaa_is_interleaved; 12438b1f467cce34340637e9baca4847fc5273cf7541Paul Berry wm_prog_key.dst_interleaved = dst_mt->msaa_is_interleaved; 12448b1f467cce34340637e9baca4847fc5273cf7541Paul Berry 1245506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_prog_key.src_tiled_w = src.map_stencil_as_y_tiled; 1246506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_prog_key.dst_tiled_w = dst.map_stencil_as_y_tiled; 1247506d70be21cd3469118de89297cba0c0f709c1aePaul Berry x0 = wm_push_consts.dst_x0 = dst_x0; 1248506d70be21cd3469118de89297cba0c0f709c1aePaul Berry y0 = wm_push_consts.dst_y0 = dst_y0; 1249506d70be21cd3469118de89297cba0c0f709c1aePaul Berry x1 = wm_push_consts.dst_x1 = dst_x1; 1250506d70be21cd3469118de89297cba0c0f709c1aePaul Berry y1 = wm_push_consts.dst_y1 = dst_y1; 1251506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_push_consts.x_transform.setup(src_x0, dst_x0, dst_x1, mirror_x); 1252506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_push_consts.y_transform.setup(src_y0, dst_y0, dst_y1, mirror_y); 1253506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 125419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (dst.num_samples == 0 && dst_mt->num_samples > 0) { 125519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* We must expand the rectangle we send through the rendering pipeline, 125619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * to account for the fact that we are mapping the destination region as 125719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * single-sampled when it is in fact multisampled. We must also align 125819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * it to a multiple of the multisampling pattern, because the 125919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * differences between multisampled and single-sampled surface formats 126019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * will mean that pixels are scrambled within the multisampling pattern. 126119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * TODO: what if this makes the coordinates too large? 12628b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * 12638b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Note: this only works if the destination surface's MSAA layout is 12648b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * interleaved. If it's sliced, then we have no choice but to set up 12658b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * the rendering pipeline as multisampled. 126619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 12678b1f467cce34340637e9baca4847fc5273cf7541Paul Berry assert(dst_mt->msaa_is_interleaved); 126819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry x0 = (x0 * 2) & ~3; 126919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry y0 = (y0 * 2) & ~3; 127019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry x1 = ALIGN(x1 * 2, 4); 127119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry y1 = ALIGN(y1 * 2, 4); 127219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry wm_prog_key.use_kill = true; 127319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry } 127419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 1275506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (dst.map_stencil_as_y_tiled) { 1276506d70be21cd3469118de89297cba0c0f709c1aePaul Berry /* We must modify the rectangle we send through the rendering pipeline, 1277506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * to account for the fact that we are mapping it as Y-tiled when it is 1278506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * in fact W-tiled. Y tiles have dimensions 128x32 whereas W tiles have 1279506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * dimensions 64x64. We must also align it to a multiple of the tile 1280506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * size, because the differences between W and Y tiling formats will 1281506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * mean that pixels are scrambled within the tile. 128234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 12838b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * Note: if the destination surface configured as an interleaved MSAA 12848b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * surface, then the effective tile size we need to align it to is 12858b1f467cce34340637e9baca4847fc5273cf7541Paul Berry * smaller, because each pixel covers a 2x2 or a 4x2 block of samples. 128634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry * 1287506d70be21cd3469118de89297cba0c0f709c1aePaul Berry * TODO: what if this makes the coordinates too large? 1288506d70be21cd3469118de89297cba0c0f709c1aePaul Berry */ 128934a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry unsigned x_align = 64, y_align = 64; 12908b1f467cce34340637e9baca4847fc5273cf7541Paul Berry if (dst_mt->num_samples > 0 && dst_mt->msaa_is_interleaved) { 129134a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry x_align /= (dst_mt->num_samples == 4 ? 2 : 4); 129234a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry y_align /= 2; 129334a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry } 129434a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry x0 = (x0 & ~(x_align - 1)) * 2; 129534a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry y0 = (y0 & ~(y_align - 1)) / 2; 129634a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry x1 = ALIGN(x1, x_align) * 2; 129734a5f12e35dd4a5aff6683a8286d4582ba17df14Paul Berry y1 = ALIGN(y1, y_align) / 2; 1298506d70be21cd3469118de89297cba0c0f709c1aePaul Berry wm_prog_key.use_kill = true; 1299506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1300506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1301506d70be21cd3469118de89297cba0c0f709c1aePaul Berry 1302506d70be21cd3469118de89297cba0c0f709c1aePaul Berryuint32_t 1303506d70be21cd3469118de89297cba0c0f709c1aePaul Berrybrw_blorp_blit_params::get_wm_prog(struct brw_context *brw, 1304506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_prog_data **prog_data) const 1305506d70be21cd3469118de89297cba0c0f709c1aePaul Berry{ 1306506d70be21cd3469118de89297cba0c0f709c1aePaul Berry uint32_t prog_offset; 1307506d70be21cd3469118de89297cba0c0f709c1aePaul Berry if (!brw_search_cache(&brw->cache, BRW_BLORP_BLIT_PROG, 1308506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &this->wm_prog_key, sizeof(this->wm_prog_key), 1309506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &prog_offset, prog_data)) { 1310506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_blorp_blit_program prog(brw, &this->wm_prog_key); 1311506d70be21cd3469118de89297cba0c0f709c1aePaul Berry GLuint program_size; 1312506d70be21cd3469118de89297cba0c0f709c1aePaul Berry const GLuint *program = prog.compile(brw, &program_size); 1313506d70be21cd3469118de89297cba0c0f709c1aePaul Berry brw_upload_cache(&brw->cache, BRW_BLORP_BLIT_PROG, 1314506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &this->wm_prog_key, sizeof(this->wm_prog_key), 1315506d70be21cd3469118de89297cba0c0f709c1aePaul Berry program, program_size, 1316506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &prog.prog_data, sizeof(prog.prog_data), 1317506d70be21cd3469118de89297cba0c0f709c1aePaul Berry &prog_offset, prog_data); 1318506d70be21cd3469118de89297cba0c0f709c1aePaul Berry } 1319506d70be21cd3469118de89297cba0c0f709c1aePaul Berry return prog_offset; 1320506d70be21cd3469118de89297cba0c0f709c1aePaul Berry} 1321