13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Reference Renderer 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Multisampled pixel buffer access 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrMultisamplePixelBufferAccess.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace rr 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess::MultisamplePixelBufferAccess (const tcu::PixelBufferAccess& rawAccess) 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_access(rawAccess) 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess::MultisamplePixelBufferAccess (void) 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_access(tcu::PixelBufferAccess(tcu::TextureFormat(), 0, 0, 0, 0, 0, DE_NULL)) 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst tcu::PixelBufferAccess MultisamplePixelBufferAccess::toSinglesampleAccess (void) const 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(getNumSamples() == 1); 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::PixelBufferAccess(m_access.getFormat(), 455f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(m_access.getHeight(), m_access.getDepth(), 1), 465f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(m_access.getRowPitch(), m_access.getSlicePitch(), m_access.getSlicePitch() * m_access.getDepth()), 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_access.getDataPtr()); 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromSinglesampleAccess (const tcu::PixelBufferAccess& original) 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return MultisamplePixelBufferAccess( 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::PixelBufferAccess( 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry original.getFormat(), 555f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(1, original.getWidth(), original.getHeight()), 565f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(original.getPixelPitch(), original.getPixelPitch(), original.getRowPitch()), 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry original.getDataPtr())); 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromMultisampleAccess (const tcu::PixelBufferAccess& multisampledAccess) 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return MultisamplePixelBufferAccess(multisampledAccess); 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 653c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (void) 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_access(tcu::ConstPixelBufferAccess(tcu::TextureFormat(), 0, 0, 0, 0, 0, DE_NULL)) 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 703c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const tcu::ConstPixelBufferAccess& rawAccess) 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_access(rawAccess) 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const rr::MultisamplePixelBufferAccess& msAccess) 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_access(msAccess.raw()) 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst tcu::ConstPixelBufferAccess MultisampleConstPixelBufferAccess::toSinglesampleAccess (void) const 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(getNumSamples() == 1); 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::ConstPixelBufferAccess(m_access.getFormat(), 855f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(m_access.getHeight(), m_access.getDepth(), 1), 865f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(m_access.getRowPitch(), m_access.getSlicePitch(), m_access.getSlicePitch() * m_access.getDepth()), 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_access.getDataPtr()); 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromSinglesampleAccess (const tcu::ConstPixelBufferAccess& original) 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return MultisampleConstPixelBufferAccess( 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::ConstPixelBufferAccess( 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry original.getFormat(), 955f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(1, original.getWidth(), original.getHeight()), 965f69470fe8597d811df06deb940cc5b54529fb4eJarkko Pöyry tcu::IVec3(original.getPixelPitch(), original.getPixelPitch(), original.getRowPitch()), 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry original.getDataPtr())); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromMultisampleAccess (const tcu::ConstPixelBufferAccess& multisampledAccess) 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return MultisampleConstPixelBufferAccess(multisampledAccess); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess getSubregion (const MultisamplePixelBufferAccess& access, int x, int y, int width, int height) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return MultisamplePixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height)); 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1103c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess getSubregion (const MultisampleConstPixelBufferAccess& access, int x, int y, int width, int height) 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return MultisampleConstPixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height)); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid resolveMultisampleColorBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src) 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(dst.getWidth() == src.raw().getHeight()); 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(dst.getHeight() == src.raw().getDepth()); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 12006beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry if (src.getNumSamples() == 1) 12106beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry { 12206beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry // fast-path for non-multisampled cases 12306beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry tcu::copy(dst, src.toSinglesampleAccess()); 12406beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry } 12506beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry else 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 12706beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry const float numSamplesInv = 1.0f / (float)src.getNumSamples(); 12806beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry 12906beb4d23816942e7ccc49c81530bb8702a6f336Jarkko Pöyry for (int y = 0; y < dst.getHeight(); y++) 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < dst.getWidth(); x++) 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 sum; 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int s = 0; s < src.raw().getWidth(); s++) 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sum += src.raw().getPixel(s, x, y); 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(sum*numSamplesInv, x, y); 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::Vec4 resolveMultisamplePixel (const MultisampleConstPixelBufferAccess& access, int x, int y) 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 sum; 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int s = 0; s < access.getNumSamples(); s++) 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sum += access.raw().getPixel(s, x, y); 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return sum / (float)access.getNumSamples(); 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const MultisamplePixelBufferAccess& access, const tcu::Vec4& color) 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clear(access.raw(), color); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const MultisamplePixelBufferAccess& access, const tcu::IVec4& color) 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clear(access.raw(), color); 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearDepth (const MultisamplePixelBufferAccess& access, float depth) 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clearDepth(access.raw(), depth); 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearStencil (const MultisamplePixelBufferAccess& access, int stencil) 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::clearStencil(access.raw(), stencil); 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rr 171