gen6_multisample_state.c revision 9ea60ce58f8494e0b79771f93227f4b8181731de
119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/* 219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Copyright © 2012 Intel Corporation 319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Permission is hereby granted, free of charge, to any person obtaining a 519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * copy of this software and associated documentation files (the "Software"), 619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * to deal in the Software without restriction, including without limitation 719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * the rights to use, copy, modify, merge, publish, distribute, sublicense, 819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * and/or sell copies of the Software, and to permit persons to whom the 919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Software is furnished to do so, subject to the following conditions: 1019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 1119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * The above copyright notice and this permission notice (including the next 1219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * paragraph) shall be included in all copies or substantial portions of the 1319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * Software. 1419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 1519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * IN THE SOFTWARE. 2219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 2319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 2419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry#include "intel_batchbuffer.h" 2519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 2619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry#include "brw_context.h" 2719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry#include "brw_defines.h" 2819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 2919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 3019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 3119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 3DSTATE_MULTISAMPLE 3219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 3319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 3419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berrygen6_emit_3dstate_multisample(struct brw_context *brw, 3519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry unsigned num_samples) 3619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 3719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry struct intel_context *intel = &brw->intel; 3819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 39ab014adaed14a9ca213447dc913d0dce7906be56Paul Berry /* TODO: 8x MSAA not implemented */ 40ab014adaed14a9ca213447dc913d0dce7906be56Paul Berry assert(num_samples <= 4); 4119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 4219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry int len = intel->gen >= 7 ? 4 : 3; 4319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry BEGIN_BATCH(len); 4419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry OUT_BATCH(_3DSTATE_MULTISAMPLE << 16 | (len - 2)); 4519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry OUT_BATCH(MS_PIXEL_LOCATION_CENTER | 4619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry (num_samples > 0 ? MS_NUMSAMPLES_4 : MS_NUMSAMPLES_1)); 4719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry OUT_BATCH(num_samples > 0 ? 0xae2ae662 : 0); /* positions for 4/8-sample */ 4819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (intel->gen >= 7) 4919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry OUT_BATCH(0); 5019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry ADVANCE_BATCH(); 5119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 5219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 5319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 5419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry/** 5519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry * 3DSTATE_SAMPLE_MASK 5619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry */ 5719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryvoid 5819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berrygen6_emit_3dstate_sample_mask(struct brw_context *brw, 599ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry unsigned num_samples, float coverage, 609ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry bool coverage_invert) 6119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 6219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry struct intel_context *intel = &brw->intel; 6319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 64ab014adaed14a9ca213447dc913d0dce7906be56Paul Berry /* TODO: 8x MSAA not implemented */ 65ab014adaed14a9ca213447dc913d0dce7906be56Paul Berry assert(num_samples <= 4); 6619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 6719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry BEGIN_BATCH(2); 6819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry OUT_BATCH(_3DSTATE_SAMPLE_MASK << 16 | (2 - 2)); 699ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry if (num_samples > 0) { 709ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry int coverage_int = (int) (num_samples * coverage + 0.5); 719ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry uint32_t coverage_bits = (1 << coverage_int) - 1; 729ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry if (coverage_invert) 739ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry coverage_bits ^= (1 << num_samples) - 1; 749ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry OUT_BATCH(coverage_bits); 759ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry } else { 769ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry OUT_BATCH(1); 779ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry } 7819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry ADVANCE_BATCH(); 7919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 8019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 8119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 8219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berrystatic void upload_multisample_state(struct brw_context *brw) 8319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry{ 8419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry struct intel_context *intel = &brw->intel; 8519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry struct gl_context *ctx = &intel->ctx; 8619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry unsigned num_samples = 0; 879ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry float coverage = 1.0; 889ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry float coverage_invert = false; 899ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry 909ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry /* _NEW_MULTISAMPLE */ 919ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry if (ctx->Multisample._Enabled && ctx->Multisample.SampleCoverage) { 929ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry coverage = ctx->Multisample.SampleCoverageValue; 939ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry coverage_invert = ctx->Multisample.SampleCoverageInvert; 949ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry } 9519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 9619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* _NEW_BUFFERS */ 9719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry if (ctx->DrawBuffer->_ColorDrawBuffers[0]) 9819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry num_samples = ctx->DrawBuffer->_ColorDrawBuffers[0]->NumSamples; 9919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 10019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry /* 3DSTATE_MULTISAMPLE is nonpipelined. */ 10119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry intel_emit_post_sync_nonzero_flush(intel); 10219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 10319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry gen6_emit_3dstate_multisample(brw, num_samples); 1049ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry gen6_emit_3dstate_sample_mask(brw, num_samples, coverage, coverage_invert); 10519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry} 10619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 10719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry 10819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berryconst struct brw_tracked_state gen6_multisample_state = { 10919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry .dirty = { 1109ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry .mesa = _NEW_BUFFERS | 1119ea60ce58f8494e0b79771f93227f4b8181731dePaul Berry _NEW_MULTISAMPLE, 11219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry .brw = BRW_NEW_CONTEXT, 11319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry .cache = 0 11419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry }, 11519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry .emit = upload_multisample_state 11619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry}; 117