1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Reference Renderer
3 * -----------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief Multisampled pixel buffer access
22 *//*--------------------------------------------------------------------*/
23
24 #include "rrMultisamplePixelBufferAccess.hpp"
25 #include "tcuTextureUtil.hpp"
26
27 namespace rr
28 {
29
MultisamplePixelBufferAccess(const tcu::PixelBufferAccess & rawAccess)30 MultisamplePixelBufferAccess::MultisamplePixelBufferAccess (const tcu::PixelBufferAccess& rawAccess)
31 : m_access(rawAccess)
32 {
33 }
34
MultisamplePixelBufferAccess(void)35 MultisamplePixelBufferAccess::MultisamplePixelBufferAccess (void)
36 : m_access(tcu::PixelBufferAccess(tcu::TextureFormat(), 0, 0, 0, 0, 0, DE_NULL))
37 {
38 }
39
toSinglesampleAccess(void) const40 const tcu::PixelBufferAccess MultisamplePixelBufferAccess::toSinglesampleAccess (void) const
41 {
42 DE_ASSERT(getNumSamples() == 1);
43
44 return tcu::PixelBufferAccess(m_access.getFormat(),
45 m_access.getHeight(),
46 m_access.getDepth(),
47 1,
48 m_access.getSlicePitch(),
49 m_access.getSlicePitch() * m_access.getDepth(),
50 m_access.getDataPtr());
51 }
52
fromSinglesampleAccess(const tcu::PixelBufferAccess & original)53 MultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromSinglesampleAccess (const tcu::PixelBufferAccess& original)
54 {
55 return MultisamplePixelBufferAccess(
56 tcu::PixelBufferAccess(
57 original.getFormat(),
58 1,
59 original.getWidth(),
60 original.getHeight(),
61 original.getFormat().getPixelSize(),
62 original.getRowPitch(),
63 original.getDataPtr()));
64 }
65
fromMultisampleAccess(const tcu::PixelBufferAccess & multisampledAccess)66 MultisamplePixelBufferAccess MultisamplePixelBufferAccess::fromMultisampleAccess (const tcu::PixelBufferAccess& multisampledAccess)
67 {
68 return MultisamplePixelBufferAccess(multisampledAccess);
69 }
70
MultisampleConstPixelBufferAccess(void)71 MultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (void)
72 : m_access(tcu::ConstPixelBufferAccess(tcu::TextureFormat(), 0, 0, 0, 0, 0, DE_NULL))
73 {
74 }
75
MultisampleConstPixelBufferAccess(const tcu::ConstPixelBufferAccess & rawAccess)76 MultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const tcu::ConstPixelBufferAccess& rawAccess)
77 : m_access(rawAccess)
78 {
79 }
80
MultisampleConstPixelBufferAccess(const rr::MultisamplePixelBufferAccess & msAccess)81 MultisampleConstPixelBufferAccess::MultisampleConstPixelBufferAccess (const rr::MultisamplePixelBufferAccess& msAccess)
82 : m_access(msAccess.raw())
83 {
84 }
85
toSinglesampleAccess(void) const86 const tcu::ConstPixelBufferAccess MultisampleConstPixelBufferAccess::toSinglesampleAccess (void) const
87 {
88 DE_ASSERT(getNumSamples() == 1);
89
90 return tcu::ConstPixelBufferAccess(m_access.getFormat(),
91 m_access.getHeight(),
92 m_access.getDepth(),
93 1,
94 m_access.getSlicePitch(),
95 m_access.getSlicePitch() * m_access.getDepth(),
96 m_access.getDataPtr());
97 }
98
fromSinglesampleAccess(const tcu::ConstPixelBufferAccess & original)99 MultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromSinglesampleAccess (const tcu::ConstPixelBufferAccess& original)
100 {
101 return MultisampleConstPixelBufferAccess(
102 tcu::ConstPixelBufferAccess(
103 original.getFormat(),
104 1,
105 original.getWidth(),
106 original.getHeight(),
107 original.getFormat().getPixelSize(),
108 original.getRowPitch(),
109 original.getDataPtr()));
110 }
111
fromMultisampleAccess(const tcu::ConstPixelBufferAccess & multisampledAccess)112 MultisampleConstPixelBufferAccess MultisampleConstPixelBufferAccess::fromMultisampleAccess (const tcu::ConstPixelBufferAccess& multisampledAccess)
113 {
114 return MultisampleConstPixelBufferAccess(multisampledAccess);
115 }
116
getSubregion(const MultisamplePixelBufferAccess & access,int x,int y,int width,int height)117 MultisamplePixelBufferAccess getSubregion (const MultisamplePixelBufferAccess& access, int x, int y, int width, int height)
118 {
119 return MultisamplePixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height));
120 }
121
getSubregion(const MultisampleConstPixelBufferAccess & access,int x,int y,int width,int height)122 MultisampleConstPixelBufferAccess getSubregion (const MultisampleConstPixelBufferAccess& access, int x, int y, int width, int height)
123 {
124 return MultisampleConstPixelBufferAccess::fromMultisampleAccess(tcu::getSubregion(access.raw(), 0, x, y, access.getNumSamples(), width, height));
125 }
126
resolveMultisampleColorBuffer(const tcu::PixelBufferAccess & dst,const MultisampleConstPixelBufferAccess & src)127 void resolveMultisampleColorBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
128 {
129 DE_ASSERT(dst.getWidth() == src.raw().getHeight());
130 DE_ASSERT(dst.getHeight() == src.raw().getDepth());
131
132 float numSamplesInv = 1.0f / (float)src.getNumSamples();
133
134 for (int y = 0; y < dst.getHeight(); y++)
135 {
136 for (int x = 0; x < dst.getWidth(); x++)
137 {
138 tcu::Vec4 sum;
139 for (int s = 0; s < src.raw().getWidth(); s++)
140 sum += src.raw().getPixel(s, x, y);
141
142 dst.setPixel(sum*numSamplesInv, x, y);
143 }
144 }
145 }
146
resolveMultisamplePixel(const MultisampleConstPixelBufferAccess & access,int x,int y)147 tcu::Vec4 resolveMultisamplePixel (const MultisampleConstPixelBufferAccess& access, int x, int y)
148 {
149 tcu::Vec4 sum;
150 for (int s = 0; s < access.getNumSamples(); s++)
151 sum += access.raw().getPixel(s, x, y);
152
153 return sum / (float)access.getNumSamples();
154 }
155
clear(const MultisamplePixelBufferAccess & access,const tcu::Vec4 & color)156 void clear (const MultisamplePixelBufferAccess& access, const tcu::Vec4& color)
157 {
158 tcu::clear(access.raw(), color);
159 }
160
clear(const MultisamplePixelBufferAccess & access,const tcu::IVec4 & color)161 void clear (const MultisamplePixelBufferAccess& access, const tcu::IVec4& color)
162 {
163 tcu::clear(access.raw(), color);
164 }
165
clearDepth(const MultisamplePixelBufferAccess & access,float depth)166 void clearDepth (const MultisamplePixelBufferAccess& access, float depth)
167 {
168 tcu::clearDepth(access.raw(), depth);
169 }
170
clearStencil(const MultisamplePixelBufferAccess & access,int stencil)171 void clearStencil (const MultisamplePixelBufferAccess& access, int stencil)
172 {
173 tcu::clearStencil(access.raw(), stencil);
174 }
175
176 } // rr
177