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(),
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_access.getHeight(),
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_access.getDepth(),
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  1,
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_access.getSlicePitch(),
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_access.getSlicePitch() * m_access.getDepth(),
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_access.getDataPtr());
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
533c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromSinglesampleAccess (const tcu::PixelBufferAccess& original)
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return MultisamplePixelBufferAccess(
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::PixelBufferAccess(
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getFormat(),
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								1,
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getWidth(),
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getHeight(),
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getFormat().getPixelSize(),
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getRowPitch(),
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getDataPtr()));
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
663c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromMultisampleAccess (const tcu::PixelBufferAccess& multisampledAccess)
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return MultisamplePixelBufferAccess(multisampledAccess);
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
713c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (void)
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_access(tcu::ConstPixelBufferAccess(tcu::TextureFormat(), 0, 0, 0, 0, 0, DE_NULL))
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const tcu::ConstPixelBufferAccess& rawAccess)
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_access(rawAccess)
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const rr::MultisamplePixelBufferAccess& msAccess)
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_access(msAccess.raw())
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst tcu::ConstPixelBufferAccess MultisampleConstPixelBufferAccess::toSinglesampleAccess (void) const
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(getNumSamples() == 1);
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::ConstPixelBufferAccess(m_access.getFormat(),
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									   m_access.getHeight(),
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									   m_access.getDepth(),
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									   1,
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									   m_access.getSlicePitch(),
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									   m_access.getSlicePitch() * m_access.getDepth(),
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									   m_access.getDataPtr());
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromSinglesampleAccess (const tcu::ConstPixelBufferAccess& original)
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return MultisampleConstPixelBufferAccess(
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::ConstPixelBufferAccess(
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getFormat(),
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								1,
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getWidth(),
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getHeight(),
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getFormat().getPixelSize(),
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getRowPitch(),
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								original.getDataPtr()));
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromMultisampleAccess (const tcu::ConstPixelBufferAccess& multisampledAccess)
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return MultisampleConstPixelBufferAccess(multisampledAccess);
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisamplePixelBufferAccess getSubregion (const MultisamplePixelBufferAccess& access, int x, int y, int width, int height)
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return MultisamplePixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height));
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMultisampleConstPixelBufferAccess getSubregion (const MultisampleConstPixelBufferAccess& access, int x, int y, int width, int height)
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return MultisampleConstPixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height));
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid resolveMultisampleColorBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(dst.getWidth() == src.raw().getHeight());
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(dst.getHeight() == src.raw().getDepth());
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float numSamplesInv = 1.0f / (float)src.getNumSamples();
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int y = 0; y < dst.getHeight(); y++)
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x = 0; x < dst.getWidth(); x++)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::Vec4 sum;
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int s = 0; s < src.raw().getWidth(); s++)
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				sum += src.raw().getPixel(s, x, y);
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			dst.setPixel(sum*numSamplesInv, x, y);
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::Vec4 resolveMultisamplePixel (const MultisampleConstPixelBufferAccess& access, int x, int y)
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Vec4 sum;
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int s = 0; s < access.getNumSamples(); s++)
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sum += access.raw().getPixel(s, x, y);
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return sum / (float)access.getNumSamples();
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const MultisamplePixelBufferAccess& access, const tcu::Vec4& color)
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::clear(access.raw(), color);
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const MultisamplePixelBufferAccess& access, const tcu::IVec4& color)
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::clear(access.raw(), color);
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearDepth (const MultisamplePixelBufferAccess& access, float depth)
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::clearDepth(access.raw(), depth);
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearStencil (const MultisamplePixelBufferAccess& access, int stencil)
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::clearStencil(access.raw(), stencil);
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rr
177