1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Reference Renderer
3 * -----------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Multisampled pixel buffer access
22 *//*--------------------------------------------------------------------*/
24 #include "rrMultisamplePixelBufferAccess.hpp"
25 #include "tcuTextureUtil.hpp"
30 MultisamplePixelBufferAccess::MultisamplePixelBufferAccess (const tcu::PixelBufferAccess& rawAccess)
35 MultisamplePixelBufferAccess::MultisamplePixelBufferAccess (void)
36 : m_access(tcu::PixelBufferAccess())
40 const tcu::PixelBufferAccess MultisamplePixelBufferAccess::toSinglesampleAccess (void) const
42 DE_ASSERT(getNumSamples() == 1);
44 return tcu::PixelBufferAccess(m_access.getFormat(),
45 tcu::IVec3(m_access.getHeight(), m_access.getDepth(), 1),
46 tcu::IVec3(m_access.getRowPitch(), m_access.getSlicePitch(), m_access.getSlicePitch() * m_access.getDepth()),
47 m_access.getDataPtr());
50 MultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromSinglesampleAccess (const tcu::PixelBufferAccess& original)
52 return MultisamplePixelBufferAccess(
53 tcu::PixelBufferAccess(
55 tcu::IVec3(1, original.getWidth(), original.getHeight()),
56 tcu::IVec3(original.getPixelPitch(), original.getPixelPitch(), original.getRowPitch()),
57 original.getDataPtr()));
60 MultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromMultisampleAccess (const tcu::PixelBufferAccess& multisampledAccess)
62 return MultisamplePixelBufferAccess(multisampledAccess);
65 MultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (void)
66 : m_access(tcu::ConstPixelBufferAccess())
70 MultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const tcu::ConstPixelBufferAccess& rawAccess)
75 MultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const rr::MultisamplePixelBufferAccess& msAccess)
76 : m_access(msAccess.raw())
80 const tcu::ConstPixelBufferAccess MultisampleConstPixelBufferAccess::toSinglesampleAccess (void) const
82 DE_ASSERT(getNumSamples() == 1);
84 return tcu::ConstPixelBufferAccess(m_access.getFormat(),
85 tcu::IVec3(m_access.getHeight(), m_access.getDepth(), 1),
86 tcu::IVec3(m_access.getRowPitch(), m_access.getSlicePitch(), m_access.getSlicePitch() * m_access.getDepth()),
87 m_access.getDataPtr());
90 MultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromSinglesampleAccess (const tcu::ConstPixelBufferAccess& original)
92 return MultisampleConstPixelBufferAccess(
93 tcu::ConstPixelBufferAccess(
95 tcu::IVec3(1, original.getWidth(), original.getHeight()),
96 tcu::IVec3(original.getPixelPitch(), original.getPixelPitch(), original.getRowPitch()),
97 original.getDataPtr()));
100 MultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromMultisampleAccess (const tcu::ConstPixelBufferAccess& multisampledAccess)
102 return MultisampleConstPixelBufferAccess(multisampledAccess);
105 MultisamplePixelBufferAccess getSubregion (const MultisamplePixelBufferAccess& access, int x, int y, int width, int height)
107 return MultisamplePixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height));
110 MultisampleConstPixelBufferAccess getSubregion (const MultisampleConstPixelBufferAccess& access, int x, int y, int width, int height)
112 return MultisampleConstPixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height));
115 void resolveMultisampleColorBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
117 DE_ASSERT(dst.getWidth() == src.raw().getHeight());
118 DE_ASSERT(dst.getHeight() == src.raw().getDepth());
120 if (src.getNumSamples() == 1)
122 // fast-path for non-multisampled cases
123 tcu::copy(dst, src.toSinglesampleAccess());
127 const float numSamplesInv = 1.0f / (float)src.getNumSamples();
129 for (int y = 0; y < dst.getHeight(); y++)
130 for (int x = 0; x < dst.getWidth(); x++)
133 for (int s = 0; s < src.raw().getWidth(); s++)
134 sum += src.raw().getPixel(s, x, y);
136 dst.setPixel(sum*numSamplesInv, x, y);
141 void resolveMultisampleDepthBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
143 DE_ASSERT(dst.getWidth() == src.raw().getHeight());
144 DE_ASSERT(dst.getHeight() == src.raw().getDepth());
146 const tcu::ConstPixelBufferAccess effectiveSrc = tcu::getEffectiveDepthStencilAccess(src.raw(), tcu::Sampler::MODE_DEPTH);
147 const tcu::PixelBufferAccess effectiveDst = tcu::getEffectiveDepthStencilAccess(dst, tcu::Sampler::MODE_DEPTH);
149 if (src.getNumSamples() == 1)
151 // fast-path for non-multisampled cases
152 tcu::copy(effectiveDst, MultisampleConstPixelBufferAccess::fromMultisampleAccess(effectiveSrc).toSinglesampleAccess());
156 const float numSamplesInv = 1.0f / (float)src.getNumSamples();
158 for (int y = 0; y < dst.getHeight(); y++)
159 for (int x = 0; x < dst.getWidth(); x++)
162 for (int s = 0; s < src.getNumSamples(); s++)
163 sum += effectiveSrc.getPixDepth(s, x, y);
165 effectiveDst.setPixDepth(sum*numSamplesInv, x, y);
170 void resolveMultisampleStencilBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
172 DE_ASSERT(dst.getWidth() == src.raw().getHeight());
173 DE_ASSERT(dst.getHeight() == src.raw().getDepth());
175 const tcu::ConstPixelBufferAccess effectiveSrc = tcu::getEffectiveDepthStencilAccess(src.raw(), tcu::Sampler::MODE_STENCIL);
176 const tcu::PixelBufferAccess effectiveDst = tcu::getEffectiveDepthStencilAccess(dst, tcu::Sampler::MODE_STENCIL);
178 if (src.getNumSamples() == 1)
180 // fast-path for non-multisampled cases
181 tcu::copy(effectiveDst, MultisampleConstPixelBufferAccess::fromMultisampleAccess(effectiveSrc).toSinglesampleAccess());
185 // Resolve by selecting one
186 for (int y = 0; y < dst.getHeight(); y++)
187 for (int x = 0; x < dst.getWidth(); x++)
188 effectiveDst.setPixStencil(effectiveSrc.getPixStencil(0, x, y), x, y);
192 void resolveMultisampleBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
194 switch (src.raw().getFormat().order)
196 case tcu::TextureFormat::D:
197 resolveMultisampleDepthBuffer(dst, src);
200 case tcu::TextureFormat::S:
201 resolveMultisampleStencilBuffer(dst, src);
204 case tcu::TextureFormat::DS:
205 resolveMultisampleDepthBuffer(dst, src);
206 resolveMultisampleStencilBuffer(dst, src);
210 resolveMultisampleColorBuffer(dst, src);
215 tcu::Vec4 resolveMultisamplePixel (const MultisampleConstPixelBufferAccess& access, int x, int y)
218 for (int s = 0; s < access.getNumSamples(); s++)
219 sum += access.raw().getPixel(s, x, y);
221 return sum / (float)access.getNumSamples();
224 void clear (const MultisamplePixelBufferAccess& access, const tcu::Vec4& color)
226 tcu::clear(access.raw(), color);
229 void clear (const MultisamplePixelBufferAccess& access, const tcu::IVec4& color)
231 tcu::clear(access.raw(), color);
234 void clearDepth (const MultisamplePixelBufferAccess& access, float depth)
236 tcu::clearDepth(access.raw(), depth);
239 void clearStencil (const MultisamplePixelBufferAccess& access, int stencil)
241 tcu::clearStencil(access.raw(), stencil);