1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // serialize.cpp:
7*8975f5c5SAndroid Build Coastguard Worker // ANGLE GL state serialization.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/capture/serialize.h"
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker #include "common/Color.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "common/MemoryBuffer.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "common/angleutils.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "common/gl_enum_utils.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "common/serializer/JsonSerializer.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Buffer.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Caps.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Context.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Framebuffer.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Query.h"
22*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/RefCountObject.h"
23*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/ResourceMap.h"
24*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Sampler.h"
25*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/State.h"
26*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/TransformFeedback.h"
27*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/VertexAttribute.h"
28*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/angletypes.h"
29*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/FramebufferImpl.h"
30*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/RenderbufferImpl.h"
31*8975f5c5SAndroid Build Coastguard Worker
32*8975f5c5SAndroid Build Coastguard Worker #include <vector>
33*8975f5c5SAndroid Build Coastguard Worker
34*8975f5c5SAndroid Build Coastguard Worker #if !ANGLE_CAPTURE_ENABLED
35*8975f5c5SAndroid Build Coastguard Worker # error Frame capture must be enabled to build this file.
36*8975f5c5SAndroid Build Coastguard Worker #endif // !ANGLE_CAPTURE_ENABLED
37*8975f5c5SAndroid Build Coastguard Worker
38*8975f5c5SAndroid Build Coastguard Worker // Note: when diagnosing serialization comparison failures, you can disable the unused function
39*8975f5c5SAndroid Build Coastguard Worker // compiler warning to allow bisecting the comparison function. One first check is to disable
40*8975f5c5SAndroid Build Coastguard Worker // Framebuffer Attachment pixel comparison which includes the pixel contents of the default FBO.
41*8975f5c5SAndroid Build Coastguard Worker // ANGLE_DISABLE_UNUSED_FUNCTION_WARNING
42*8975f5c5SAndroid Build Coastguard Worker
43*8975f5c5SAndroid Build Coastguard Worker namespace angle
44*8975f5c5SAndroid Build Coastguard Worker {
45*8975f5c5SAndroid Build Coastguard Worker namespace
46*8975f5c5SAndroid Build Coastguard Worker {
47*8975f5c5SAndroid Build Coastguard Worker template <typename ArgT>
ToString(const ArgT & arg)48*8975f5c5SAndroid Build Coastguard Worker std::string ToString(const ArgT &arg)
49*8975f5c5SAndroid Build Coastguard Worker {
50*8975f5c5SAndroid Build Coastguard Worker std::ostringstream strstr;
51*8975f5c5SAndroid Build Coastguard Worker strstr << arg;
52*8975f5c5SAndroid Build Coastguard Worker return strstr.str();
53*8975f5c5SAndroid Build Coastguard Worker }
54*8975f5c5SAndroid Build Coastguard Worker
55*8975f5c5SAndroid Build Coastguard Worker #define ENUM_TO_STRING(C, M) \
56*8975f5c5SAndroid Build Coastguard Worker case C ::M: \
57*8975f5c5SAndroid Build Coastguard Worker return #M
58*8975f5c5SAndroid Build Coastguard Worker
InitStateToString(gl::InitState state)59*8975f5c5SAndroid Build Coastguard Worker const char *InitStateToString(gl::InitState state)
60*8975f5c5SAndroid Build Coastguard Worker {
61*8975f5c5SAndroid Build Coastguard Worker switch (state)
62*8975f5c5SAndroid Build Coastguard Worker {
63*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::InitState, Initialized);
64*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::InitState, MayNeedInit);
65*8975f5c5SAndroid Build Coastguard Worker default:
66*8975f5c5SAndroid Build Coastguard Worker return "invalid";
67*8975f5c5SAndroid Build Coastguard Worker }
68*8975f5c5SAndroid Build Coastguard Worker }
69*8975f5c5SAndroid Build Coastguard Worker
SrgbOverrideToString(gl::SrgbOverride value)70*8975f5c5SAndroid Build Coastguard Worker const char *SrgbOverrideToString(gl::SrgbOverride value)
71*8975f5c5SAndroid Build Coastguard Worker {
72*8975f5c5SAndroid Build Coastguard Worker switch (value)
73*8975f5c5SAndroid Build Coastguard Worker {
74*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::SrgbOverride, Default);
75*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::SrgbOverride, SRGB);
76*8975f5c5SAndroid Build Coastguard Worker default:
77*8975f5c5SAndroid Build Coastguard Worker return "invalid";
78*8975f5c5SAndroid Build Coastguard Worker }
79*8975f5c5SAndroid Build Coastguard Worker }
80*8975f5c5SAndroid Build Coastguard Worker
ColorGenericTypeToString(gl::ColorGeneric::Type type)81*8975f5c5SAndroid Build Coastguard Worker const char *ColorGenericTypeToString(gl::ColorGeneric::Type type)
82*8975f5c5SAndroid Build Coastguard Worker {
83*8975f5c5SAndroid Build Coastguard Worker switch (type)
84*8975f5c5SAndroid Build Coastguard Worker {
85*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::ColorGeneric::Type, Float);
86*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::ColorGeneric::Type, Int);
87*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::ColorGeneric::Type, UInt);
88*8975f5c5SAndroid Build Coastguard Worker default:
89*8975f5c5SAndroid Build Coastguard Worker return "invalid";
90*8975f5c5SAndroid Build Coastguard Worker }
91*8975f5c5SAndroid Build Coastguard Worker }
92*8975f5c5SAndroid Build Coastguard Worker
CompileStatusToString(gl::CompileStatus status)93*8975f5c5SAndroid Build Coastguard Worker const char *CompileStatusToString(gl::CompileStatus status)
94*8975f5c5SAndroid Build Coastguard Worker {
95*8975f5c5SAndroid Build Coastguard Worker switch (status)
96*8975f5c5SAndroid Build Coastguard Worker {
97*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::CompileStatus, NOT_COMPILED);
98*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::CompileStatus, COMPILE_REQUESTED);
99*8975f5c5SAndroid Build Coastguard Worker ENUM_TO_STRING(gl::CompileStatus, COMPILED);
100*8975f5c5SAndroid Build Coastguard Worker default:
101*8975f5c5SAndroid Build Coastguard Worker return "invalid";
102*8975f5c5SAndroid Build Coastguard Worker }
103*8975f5c5SAndroid Build Coastguard Worker }
104*8975f5c5SAndroid Build Coastguard Worker
105*8975f5c5SAndroid Build Coastguard Worker #undef ENUM_TO_STRING
106*8975f5c5SAndroid Build Coastguard Worker
107*8975f5c5SAndroid Build Coastguard Worker class [[nodiscard]] GroupScope
108*8975f5c5SAndroid Build Coastguard Worker {
109*8975f5c5SAndroid Build Coastguard Worker public:
GroupScope(JsonSerializer * json,const std::string & name)110*8975f5c5SAndroid Build Coastguard Worker GroupScope(JsonSerializer *json, const std::string &name) : mJson(json)
111*8975f5c5SAndroid Build Coastguard Worker {
112*8975f5c5SAndroid Build Coastguard Worker mJson->startGroup(name);
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker
GroupScope(JsonSerializer * json,const std::string & name,int index)115*8975f5c5SAndroid Build Coastguard Worker GroupScope(JsonSerializer *json, const std::string &name, int index) : mJson(json)
116*8975f5c5SAndroid Build Coastguard Worker {
117*8975f5c5SAndroid Build Coastguard Worker constexpr size_t kBufSize = 255;
118*8975f5c5SAndroid Build Coastguard Worker char buf[kBufSize + 1] = {};
119*8975f5c5SAndroid Build Coastguard Worker snprintf(buf, kBufSize, "%s%s%03d", name.c_str(), name.empty() ? "" : " ", index);
120*8975f5c5SAndroid Build Coastguard Worker mJson->startGroup(buf);
121*8975f5c5SAndroid Build Coastguard Worker }
122*8975f5c5SAndroid Build Coastguard Worker
GroupScope(JsonSerializer * json,int index)123*8975f5c5SAndroid Build Coastguard Worker GroupScope(JsonSerializer *json, int index) : GroupScope(json, "", index) {}
124*8975f5c5SAndroid Build Coastguard Worker
~GroupScope()125*8975f5c5SAndroid Build Coastguard Worker ~GroupScope() { mJson->endGroup(); }
126*8975f5c5SAndroid Build Coastguard Worker
127*8975f5c5SAndroid Build Coastguard Worker private:
128*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *mJson;
129*8975f5c5SAndroid Build Coastguard Worker };
130*8975f5c5SAndroid Build Coastguard Worker
SerializeColorF(JsonSerializer * json,const ColorF & color)131*8975f5c5SAndroid Build Coastguard Worker void SerializeColorF(JsonSerializer *json, const ColorF &color)
132*8975f5c5SAndroid Build Coastguard Worker {
133*8975f5c5SAndroid Build Coastguard Worker json->addScalar("red", color.red);
134*8975f5c5SAndroid Build Coastguard Worker json->addScalar("green", color.green);
135*8975f5c5SAndroid Build Coastguard Worker json->addScalar("blue", color.blue);
136*8975f5c5SAndroid Build Coastguard Worker json->addScalar("alpha", color.alpha);
137*8975f5c5SAndroid Build Coastguard Worker }
138*8975f5c5SAndroid Build Coastguard Worker
SerializeColorFWithGroup(JsonSerializer * json,const char * groupName,const ColorF & color)139*8975f5c5SAndroid Build Coastguard Worker void SerializeColorFWithGroup(JsonSerializer *json, const char *groupName, const ColorF &color)
140*8975f5c5SAndroid Build Coastguard Worker {
141*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, groupName);
142*8975f5c5SAndroid Build Coastguard Worker SerializeColorF(json, color);
143*8975f5c5SAndroid Build Coastguard Worker }
144*8975f5c5SAndroid Build Coastguard Worker
SerializeColorI(JsonSerializer * json,const ColorI & color)145*8975f5c5SAndroid Build Coastguard Worker void SerializeColorI(JsonSerializer *json, const ColorI &color)
146*8975f5c5SAndroid Build Coastguard Worker {
147*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Red", color.red);
148*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Green", color.green);
149*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Blue", color.blue);
150*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Alpha", color.alpha);
151*8975f5c5SAndroid Build Coastguard Worker }
152*8975f5c5SAndroid Build Coastguard Worker
SerializeColorUI(JsonSerializer * json,const ColorUI & color)153*8975f5c5SAndroid Build Coastguard Worker void SerializeColorUI(JsonSerializer *json, const ColorUI &color)
154*8975f5c5SAndroid Build Coastguard Worker {
155*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Red", color.red);
156*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Green", color.green);
157*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Blue", color.blue);
158*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Alpha", color.alpha);
159*8975f5c5SAndroid Build Coastguard Worker }
160*8975f5c5SAndroid Build Coastguard Worker
SerializeExtents(JsonSerializer * json,const gl::Extents & extents)161*8975f5c5SAndroid Build Coastguard Worker void SerializeExtents(JsonSerializer *json, const gl::Extents &extents)
162*8975f5c5SAndroid Build Coastguard Worker {
163*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Width", extents.width);
164*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Height", extents.height);
165*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Depth", extents.depth);
166*8975f5c5SAndroid Build Coastguard Worker }
167*8975f5c5SAndroid Build Coastguard Worker
168*8975f5c5SAndroid Build Coastguard Worker template <class ObjectType>
SerializeOffsetBindingPointerVector(JsonSerializer * json,const char * groupName,const std::vector<gl::OffsetBindingPointer<ObjectType>> & offsetBindingPointerVector)169*8975f5c5SAndroid Build Coastguard Worker void SerializeOffsetBindingPointerVector(
170*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
171*8975f5c5SAndroid Build Coastguard Worker const char *groupName,
172*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::OffsetBindingPointer<ObjectType>> &offsetBindingPointerVector)
173*8975f5c5SAndroid Build Coastguard Worker {
174*8975f5c5SAndroid Build Coastguard Worker GroupScope vectorGroup(json, groupName);
175*8975f5c5SAndroid Build Coastguard Worker
176*8975f5c5SAndroid Build Coastguard Worker for (size_t i = 0; i < offsetBindingPointerVector.size(); i++)
177*8975f5c5SAndroid Build Coastguard Worker {
178*8975f5c5SAndroid Build Coastguard Worker GroupScope itemGroup(json, static_cast<int>(i));
179*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Value", offsetBindingPointerVector[i].id().value);
180*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Offset", offsetBindingPointerVector[i].getOffset());
181*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Size", offsetBindingPointerVector[i].getSize());
182*8975f5c5SAndroid Build Coastguard Worker }
183*8975f5c5SAndroid Build Coastguard Worker }
184*8975f5c5SAndroid Build Coastguard Worker
185*8975f5c5SAndroid Build Coastguard Worker template <class ObjectType>
SerializeBindingPointerVector(JsonSerializer * json,const std::vector<gl::BindingPointer<ObjectType>> & bindingPointerVector)186*8975f5c5SAndroid Build Coastguard Worker void SerializeBindingPointerVector(
187*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
188*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::BindingPointer<ObjectType>> &bindingPointerVector)
189*8975f5c5SAndroid Build Coastguard Worker {
190*8975f5c5SAndroid Build Coastguard Worker for (size_t i = 0; i < bindingPointerVector.size(); i++)
191*8975f5c5SAndroid Build Coastguard Worker {
192*8975f5c5SAndroid Build Coastguard Worker const gl::BindingPointer<ObjectType> &obj = bindingPointerVector[i];
193*8975f5c5SAndroid Build Coastguard Worker
194*8975f5c5SAndroid Build Coastguard Worker // Do not serialize zero bindings, as this will create unwanted diffs
195*8975f5c5SAndroid Build Coastguard Worker if (obj.id().value != 0)
196*8975f5c5SAndroid Build Coastguard Worker {
197*8975f5c5SAndroid Build Coastguard Worker std::ostringstream s;
198*8975f5c5SAndroid Build Coastguard Worker s << std::setfill('0') << std::setw(3) << i;
199*8975f5c5SAndroid Build Coastguard Worker json->addScalar(s.str().c_str(), obj.id().value);
200*8975f5c5SAndroid Build Coastguard Worker }
201*8975f5c5SAndroid Build Coastguard Worker }
202*8975f5c5SAndroid Build Coastguard Worker }
203*8975f5c5SAndroid Build Coastguard Worker
204*8975f5c5SAndroid Build Coastguard Worker template <class T>
SerializeRange(JsonSerializer * json,const gl::Range<T> & range)205*8975f5c5SAndroid Build Coastguard Worker void SerializeRange(JsonSerializer *json, const gl::Range<T> &range)
206*8975f5c5SAndroid Build Coastguard Worker {
207*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Range");
208*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Low", range.low());
209*8975f5c5SAndroid Build Coastguard Worker json->addScalar("High", range.high());
210*8975f5c5SAndroid Build Coastguard Worker }
211*8975f5c5SAndroid Build Coastguard Worker
IsValidColorAttachmentBinding(GLenum binding,size_t colorAttachmentsCount)212*8975f5c5SAndroid Build Coastguard Worker bool IsValidColorAttachmentBinding(GLenum binding, size_t colorAttachmentsCount)
213*8975f5c5SAndroid Build Coastguard Worker {
214*8975f5c5SAndroid Build Coastguard Worker return binding == GL_BACK || (binding >= GL_COLOR_ATTACHMENT0 &&
215*8975f5c5SAndroid Build Coastguard Worker (binding - GL_COLOR_ATTACHMENT0) < colorAttachmentsCount);
216*8975f5c5SAndroid Build Coastguard Worker }
217*8975f5c5SAndroid Build Coastguard Worker
SerializeFormat(JsonSerializer * json,GLenum glFormat)218*8975f5c5SAndroid Build Coastguard Worker void SerializeFormat(JsonSerializer *json, GLenum glFormat)
219*8975f5c5SAndroid Build Coastguard Worker {
220*8975f5c5SAndroid Build Coastguard Worker json->addCString("InternalFormat", gl::GLenumToString(gl::GLESEnum::InternalFormat, glFormat));
221*8975f5c5SAndroid Build Coastguard Worker }
222*8975f5c5SAndroid Build Coastguard Worker
SerializeInternalFormat(JsonSerializer * json,const gl::InternalFormat * internalFormat)223*8975f5c5SAndroid Build Coastguard Worker void SerializeInternalFormat(JsonSerializer *json, const gl::InternalFormat *internalFormat)
224*8975f5c5SAndroid Build Coastguard Worker {
225*8975f5c5SAndroid Build Coastguard Worker SerializeFormat(json, internalFormat->internalFormat);
226*8975f5c5SAndroid Build Coastguard Worker }
227*8975f5c5SAndroid Build Coastguard Worker
SerializeANGLEFormat(JsonSerializer * json,const angle::Format * format)228*8975f5c5SAndroid Build Coastguard Worker void SerializeANGLEFormat(JsonSerializer *json, const angle::Format *format)
229*8975f5c5SAndroid Build Coastguard Worker {
230*8975f5c5SAndroid Build Coastguard Worker SerializeFormat(json, format->glInternalFormat);
231*8975f5c5SAndroid Build Coastguard Worker }
232*8975f5c5SAndroid Build Coastguard Worker
SerializeGLFormat(JsonSerializer * json,const gl::Format & format)233*8975f5c5SAndroid Build Coastguard Worker void SerializeGLFormat(JsonSerializer *json, const gl::Format &format)
234*8975f5c5SAndroid Build Coastguard Worker {
235*8975f5c5SAndroid Build Coastguard Worker SerializeInternalFormat(json, format.info);
236*8975f5c5SAndroid Build Coastguard Worker }
237*8975f5c5SAndroid Build Coastguard Worker
ReadPixelsFromAttachment(const gl::Context * context,gl::Framebuffer * framebuffer,const gl::FramebufferAttachment & framebufferAttachment,ScratchBuffer * scratchBuffer,MemoryBuffer ** pixels)238*8975f5c5SAndroid Build Coastguard Worker Result ReadPixelsFromAttachment(const gl::Context *context,
239*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer,
240*8975f5c5SAndroid Build Coastguard Worker const gl::FramebufferAttachment &framebufferAttachment,
241*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer,
242*8975f5c5SAndroid Build Coastguard Worker MemoryBuffer **pixels)
243*8975f5c5SAndroid Build Coastguard Worker {
244*8975f5c5SAndroid Build Coastguard Worker gl::Extents extents = framebufferAttachment.getSize();
245*8975f5c5SAndroid Build Coastguard Worker GLenum binding = framebufferAttachment.getBinding();
246*8975f5c5SAndroid Build Coastguard Worker gl::InternalFormat format = *framebufferAttachment.getFormat().info;
247*8975f5c5SAndroid Build Coastguard Worker if (IsValidColorAttachmentBinding(binding,
248*8975f5c5SAndroid Build Coastguard Worker framebuffer->getState().getColorAttachments().size()))
249*8975f5c5SAndroid Build Coastguard Worker {
250*8975f5c5SAndroid Build Coastguard Worker format = framebuffer->getImplementation()->getImplementationColorReadFormat(context);
251*8975f5c5SAndroid Build Coastguard Worker }
252*8975f5c5SAndroid Build Coastguard Worker ANGLE_CHECK_GL_ALLOC(const_cast<gl::Context *>(context),
253*8975f5c5SAndroid Build Coastguard Worker scratchBuffer->getInitialized(
254*8975f5c5SAndroid Build Coastguard Worker format.pixelBytes * extents.width * extents.height, pixels, 0));
255*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(framebuffer->readPixels(context, gl::Rectangle{0, 0, extents.width, extents.height},
256*8975f5c5SAndroid Build Coastguard Worker format.format, format.type, gl::PixelPackState{}, nullptr,
257*8975f5c5SAndroid Build Coastguard Worker (*pixels)->data()));
258*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
259*8975f5c5SAndroid Build Coastguard Worker }
SerializeImageIndex(JsonSerializer * json,const gl::ImageIndex & imageIndex)260*8975f5c5SAndroid Build Coastguard Worker void SerializeImageIndex(JsonSerializer *json, const gl::ImageIndex &imageIndex)
261*8975f5c5SAndroid Build Coastguard Worker {
262*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Image");
263*8975f5c5SAndroid Build Coastguard Worker json->addString("ImageType", ToString(imageIndex.getType()));
264*8975f5c5SAndroid Build Coastguard Worker json->addScalar("LevelIndex", imageIndex.getLevelIndex());
265*8975f5c5SAndroid Build Coastguard Worker json->addScalar("LayerIndex", imageIndex.getLayerIndex());
266*8975f5c5SAndroid Build Coastguard Worker json->addScalar("LayerCount", imageIndex.getLayerCount());
267*8975f5c5SAndroid Build Coastguard Worker }
268*8975f5c5SAndroid Build Coastguard Worker
SerializeFramebufferAttachment(const gl::Context * context,JsonSerializer * json,ScratchBuffer * scratchBuffer,gl::Framebuffer * framebuffer,const gl::FramebufferAttachment & framebufferAttachment,gl::GLESEnum enumGroup)269*8975f5c5SAndroid Build Coastguard Worker Result SerializeFramebufferAttachment(const gl::Context *context,
270*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
271*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer,
272*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer,
273*8975f5c5SAndroid Build Coastguard Worker const gl::FramebufferAttachment &framebufferAttachment,
274*8975f5c5SAndroid Build Coastguard Worker gl::GLESEnum enumGroup)
275*8975f5c5SAndroid Build Coastguard Worker {
276*8975f5c5SAndroid Build Coastguard Worker if (framebufferAttachment.type() == GL_TEXTURE ||
277*8975f5c5SAndroid Build Coastguard Worker framebufferAttachment.type() == GL_RENDERBUFFER)
278*8975f5c5SAndroid Build Coastguard Worker {
279*8975f5c5SAndroid Build Coastguard Worker json->addScalar("AttachedResourceID", framebufferAttachment.id());
280*8975f5c5SAndroid Build Coastguard Worker }
281*8975f5c5SAndroid Build Coastguard Worker json->addCString(
282*8975f5c5SAndroid Build Coastguard Worker "Type", gl::GLenumToString(gl::GLESEnum::ObjectIdentifier, framebufferAttachment.type()));
283*8975f5c5SAndroid Build Coastguard Worker // serialize target variable
284*8975f5c5SAndroid Build Coastguard Worker json->addString("Binding", gl::GLenumToString(enumGroup, framebufferAttachment.getBinding()));
285*8975f5c5SAndroid Build Coastguard Worker if (framebufferAttachment.type() == GL_TEXTURE)
286*8975f5c5SAndroid Build Coastguard Worker {
287*8975f5c5SAndroid Build Coastguard Worker SerializeImageIndex(json, framebufferAttachment.getTextureImageIndex());
288*8975f5c5SAndroid Build Coastguard Worker }
289*8975f5c5SAndroid Build Coastguard Worker json->addScalar("NumViews", framebufferAttachment.getNumViews());
290*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Multiview", framebufferAttachment.isMultiview());
291*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ViewIndex", framebufferAttachment.getBaseViewIndex());
292*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Samples", framebufferAttachment.getRenderToTextureSamples());
293*8975f5c5SAndroid Build Coastguard Worker
294*8975f5c5SAndroid Build Coastguard Worker {
295*8975f5c5SAndroid Build Coastguard Worker GroupScope extentsGroup(json, "Extents");
296*8975f5c5SAndroid Build Coastguard Worker SerializeExtents(json, framebufferAttachment.getSize());
297*8975f5c5SAndroid Build Coastguard Worker }
298*8975f5c5SAndroid Build Coastguard Worker
299*8975f5c5SAndroid Build Coastguard Worker if (framebufferAttachment.type() != GL_TEXTURE &&
300*8975f5c5SAndroid Build Coastguard Worker framebufferAttachment.type() != GL_RENDERBUFFER)
301*8975f5c5SAndroid Build Coastguard Worker {
302*8975f5c5SAndroid Build Coastguard Worker GLenum prevReadBufferState = framebuffer->getReadBufferState();
303*8975f5c5SAndroid Build Coastguard Worker GLenum binding = framebufferAttachment.getBinding();
304*8975f5c5SAndroid Build Coastguard Worker if (IsValidColorAttachmentBinding(binding,
305*8975f5c5SAndroid Build Coastguard Worker framebuffer->getState().getColorAttachments().size()))
306*8975f5c5SAndroid Build Coastguard Worker {
307*8975f5c5SAndroid Build Coastguard Worker framebuffer->setReadBuffer(framebufferAttachment.getBinding());
308*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(framebuffer->syncState(context, GL_FRAMEBUFFER, gl::Command::Other));
309*8975f5c5SAndroid Build Coastguard Worker }
310*8975f5c5SAndroid Build Coastguard Worker
311*8975f5c5SAndroid Build Coastguard Worker if (framebufferAttachment.initState() == gl::InitState::Initialized)
312*8975f5c5SAndroid Build Coastguard Worker {
313*8975f5c5SAndroid Build Coastguard Worker MemoryBuffer *pixelsPtr = nullptr;
314*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(ReadPixelsFromAttachment(context, framebuffer, framebufferAttachment,
315*8975f5c5SAndroid Build Coastguard Worker scratchBuffer, &pixelsPtr));
316*8975f5c5SAndroid Build Coastguard Worker json->addBlob("Data", pixelsPtr->data(), pixelsPtr->size());
317*8975f5c5SAndroid Build Coastguard Worker }
318*8975f5c5SAndroid Build Coastguard Worker else
319*8975f5c5SAndroid Build Coastguard Worker {
320*8975f5c5SAndroid Build Coastguard Worker json->addCString("Data", "Not initialized");
321*8975f5c5SAndroid Build Coastguard Worker }
322*8975f5c5SAndroid Build Coastguard Worker // Reset framebuffer state
323*8975f5c5SAndroid Build Coastguard Worker framebuffer->setReadBuffer(prevReadBufferState);
324*8975f5c5SAndroid Build Coastguard Worker }
325*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
326*8975f5c5SAndroid Build Coastguard Worker }
327*8975f5c5SAndroid Build Coastguard Worker
SerializeFramebufferState(const gl::Context * context,JsonSerializer * json,ScratchBuffer * scratchBuffer,gl::Framebuffer * framebuffer,const gl::FramebufferState & framebufferState)328*8975f5c5SAndroid Build Coastguard Worker Result SerializeFramebufferState(const gl::Context *context,
329*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
330*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer,
331*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer,
332*8975f5c5SAndroid Build Coastguard Worker const gl::FramebufferState &framebufferState)
333*8975f5c5SAndroid Build Coastguard Worker {
334*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Framebuffer", framebufferState.id().value);
335*8975f5c5SAndroid Build Coastguard Worker
336*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", framebufferState.getLabel());
337*8975f5c5SAndroid Build Coastguard Worker json->addVector("DrawStates", framebufferState.getDrawBufferStates());
338*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ReadBufferState", framebufferState.getReadBufferState());
339*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DefaultWidth", framebufferState.getDefaultWidth());
340*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DefaultHeight", framebufferState.getDefaultHeight());
341*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DefaultSamples", framebufferState.getDefaultSamples());
342*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DefaultFixedSampleLocation",
343*8975f5c5SAndroid Build Coastguard Worker framebufferState.getDefaultFixedSampleLocations());
344*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DefaultLayers", framebufferState.getDefaultLayers());
345*8975f5c5SAndroid Build Coastguard Worker json->addScalar("FlipY", framebufferState.getFlipY());
346*8975f5c5SAndroid Build Coastguard Worker
347*8975f5c5SAndroid Build Coastguard Worker {
348*8975f5c5SAndroid Build Coastguard Worker GroupScope attachmentsGroup(json, "Attachments");
349*8975f5c5SAndroid Build Coastguard Worker const gl::DrawBuffersVector<gl::FramebufferAttachment> &colorAttachments =
350*8975f5c5SAndroid Build Coastguard Worker framebufferState.getColorAttachments();
351*8975f5c5SAndroid Build Coastguard Worker for (size_t attachmentIndex = 0; attachmentIndex < colorAttachments.size();
352*8975f5c5SAndroid Build Coastguard Worker ++attachmentIndex)
353*8975f5c5SAndroid Build Coastguard Worker {
354*8975f5c5SAndroid Build Coastguard Worker const gl::FramebufferAttachment &colorAttachment = colorAttachments[attachmentIndex];
355*8975f5c5SAndroid Build Coastguard Worker if (colorAttachment.isAttached())
356*8975f5c5SAndroid Build Coastguard Worker {
357*8975f5c5SAndroid Build Coastguard Worker GroupScope colorAttachmentgroup(json, "ColorAttachment",
358*8975f5c5SAndroid Build Coastguard Worker static_cast<int>(attachmentIndex));
359*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeFramebufferAttachment(context, json, scratchBuffer, framebuffer,
360*8975f5c5SAndroid Build Coastguard Worker colorAttachment,
361*8975f5c5SAndroid Build Coastguard Worker gl::GLESEnum::ColorBuffer));
362*8975f5c5SAndroid Build Coastguard Worker }
363*8975f5c5SAndroid Build Coastguard Worker }
364*8975f5c5SAndroid Build Coastguard Worker if (framebuffer->getDepthStencilAttachment())
365*8975f5c5SAndroid Build Coastguard Worker {
366*8975f5c5SAndroid Build Coastguard Worker GroupScope dsAttachmentgroup(json, "DepthStencilAttachment");
367*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeFramebufferAttachment(context, json, scratchBuffer, framebuffer,
368*8975f5c5SAndroid Build Coastguard Worker *framebuffer->getDepthStencilAttachment(),
369*8975f5c5SAndroid Build Coastguard Worker gl::GLESEnum::AllEnums));
370*8975f5c5SAndroid Build Coastguard Worker }
371*8975f5c5SAndroid Build Coastguard Worker else
372*8975f5c5SAndroid Build Coastguard Worker {
373*8975f5c5SAndroid Build Coastguard Worker if (framebuffer->getDepthAttachment())
374*8975f5c5SAndroid Build Coastguard Worker {
375*8975f5c5SAndroid Build Coastguard Worker GroupScope depthAttachmentgroup(json, "DepthAttachment");
376*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeFramebufferAttachment(context, json, scratchBuffer, framebuffer,
377*8975f5c5SAndroid Build Coastguard Worker *framebuffer->getDepthAttachment(),
378*8975f5c5SAndroid Build Coastguard Worker gl::GLESEnum::FramebufferAttachment));
379*8975f5c5SAndroid Build Coastguard Worker }
380*8975f5c5SAndroid Build Coastguard Worker if (framebuffer->getStencilAttachment())
381*8975f5c5SAndroid Build Coastguard Worker {
382*8975f5c5SAndroid Build Coastguard Worker GroupScope stencilAttachmengroup(json, "StencilAttachment");
383*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeFramebufferAttachment(context, json, scratchBuffer, framebuffer,
384*8975f5c5SAndroid Build Coastguard Worker *framebuffer->getStencilAttachment(),
385*8975f5c5SAndroid Build Coastguard Worker gl::GLESEnum::AllEnums));
386*8975f5c5SAndroid Build Coastguard Worker }
387*8975f5c5SAndroid Build Coastguard Worker }
388*8975f5c5SAndroid Build Coastguard Worker }
389*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
390*8975f5c5SAndroid Build Coastguard Worker }
391*8975f5c5SAndroid Build Coastguard Worker
SerializeFramebuffer(const gl::Context * context,JsonSerializer * json,ScratchBuffer * scratchBuffer,gl::Framebuffer * framebuffer)392*8975f5c5SAndroid Build Coastguard Worker Result SerializeFramebuffer(const gl::Context *context,
393*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
394*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer,
395*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebuffer)
396*8975f5c5SAndroid Build Coastguard Worker {
397*8975f5c5SAndroid Build Coastguard Worker return SerializeFramebufferState(context, json, scratchBuffer, framebuffer,
398*8975f5c5SAndroid Build Coastguard Worker framebuffer->getState());
399*8975f5c5SAndroid Build Coastguard Worker }
400*8975f5c5SAndroid Build Coastguard Worker
SerializeRasterizerState(JsonSerializer * json,const gl::RasterizerState & rasterizerState)401*8975f5c5SAndroid Build Coastguard Worker void SerializeRasterizerState(JsonSerializer *json, const gl::RasterizerState &rasterizerState)
402*8975f5c5SAndroid Build Coastguard Worker {
403*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Rasterizer");
404*8975f5c5SAndroid Build Coastguard Worker json->addScalar("CullFace", rasterizerState.cullFace);
405*8975f5c5SAndroid Build Coastguard Worker json->addString("CullMode", ToString(rasterizerState.cullMode));
406*8975f5c5SAndroid Build Coastguard Worker json->addScalar("FrontFace", rasterizerState.frontFace);
407*8975f5c5SAndroid Build Coastguard Worker json->addString("PolygonMode", ToString(rasterizerState.polygonMode));
408*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PolygonOffsetPoint", rasterizerState.polygonOffsetPoint);
409*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PolygonOffsetLine", rasterizerState.polygonOffsetLine);
410*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PolygonOffsetFill", rasterizerState.polygonOffsetFill);
411*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PolygonOffsetFactor", rasterizerState.polygonOffsetFactor);
412*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PolygonOffsetUnits", rasterizerState.polygonOffsetUnits);
413*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PolygonOffsetClamp", rasterizerState.polygonOffsetClamp);
414*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DepthClamp", rasterizerState.depthClamp);
415*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PointDrawMode", rasterizerState.pointDrawMode);
416*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MultiSample", rasterizerState.multiSample);
417*8975f5c5SAndroid Build Coastguard Worker json->addScalar("RasterizerDiscard", rasterizerState.rasterizerDiscard);
418*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Dither", rasterizerState.dither);
419*8975f5c5SAndroid Build Coastguard Worker }
420*8975f5c5SAndroid Build Coastguard Worker
SerializeRectangle(JsonSerializer * json,const std::string & name,const gl::Rectangle & rectangle)421*8975f5c5SAndroid Build Coastguard Worker void SerializeRectangle(JsonSerializer *json,
422*8975f5c5SAndroid Build Coastguard Worker const std::string &name,
423*8975f5c5SAndroid Build Coastguard Worker const gl::Rectangle &rectangle)
424*8975f5c5SAndroid Build Coastguard Worker {
425*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, name);
426*8975f5c5SAndroid Build Coastguard Worker json->addScalar("x", rectangle.x);
427*8975f5c5SAndroid Build Coastguard Worker json->addScalar("y", rectangle.y);
428*8975f5c5SAndroid Build Coastguard Worker json->addScalar("w", rectangle.width);
429*8975f5c5SAndroid Build Coastguard Worker json->addScalar("h", rectangle.height);
430*8975f5c5SAndroid Build Coastguard Worker }
431*8975f5c5SAndroid Build Coastguard Worker
SerializeBlendStateExt(JsonSerializer * json,const gl::BlendStateExt & blendStateExt)432*8975f5c5SAndroid Build Coastguard Worker void SerializeBlendStateExt(JsonSerializer *json, const gl::BlendStateExt &blendStateExt)
433*8975f5c5SAndroid Build Coastguard Worker {
434*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "BlendStateExt");
435*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DrawBufferCount", blendStateExt.getDrawBufferCount());
436*8975f5c5SAndroid Build Coastguard Worker json->addScalar("EnableMask", blendStateExt.getEnabledMask().bits());
437*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DstColor", blendStateExt.getDstColorBits());
438*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DstAlpha", blendStateExt.getDstAlphaBits());
439*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SrcColor", blendStateExt.getSrcColorBits());
440*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SrcAlpha", blendStateExt.getSrcAlphaBits());
441*8975f5c5SAndroid Build Coastguard Worker json->addScalar("EquationColor", blendStateExt.getEquationColorBits());
442*8975f5c5SAndroid Build Coastguard Worker json->addScalar("EquationAlpha", blendStateExt.getEquationAlphaBits());
443*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ColorMask", blendStateExt.getColorMaskBits());
444*8975f5c5SAndroid Build Coastguard Worker }
445*8975f5c5SAndroid Build Coastguard Worker
SerializeDepthStencilState(JsonSerializer * json,const gl::DepthStencilState & depthStencilState)446*8975f5c5SAndroid Build Coastguard Worker void SerializeDepthStencilState(JsonSerializer *json,
447*8975f5c5SAndroid Build Coastguard Worker const gl::DepthStencilState &depthStencilState)
448*8975f5c5SAndroid Build Coastguard Worker {
449*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "DepthStencilState");
450*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DepthTest", depthStencilState.depthTest);
451*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DepthFunc", depthStencilState.depthFunc);
452*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DepthMask", depthStencilState.depthMask);
453*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilTest", depthStencilState.stencilTest);
454*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilFunc", depthStencilState.stencilFunc);
455*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilMask", depthStencilState.stencilMask);
456*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilFail", depthStencilState.stencilFail);
457*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilPassDepthFail", depthStencilState.stencilPassDepthFail);
458*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilPassDepthPass", depthStencilState.stencilPassDepthPass);
459*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilWritemask", depthStencilState.stencilWritemask);
460*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilBackFunc", depthStencilState.stencilBackFunc);
461*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilBackMask", depthStencilState.stencilBackMask);
462*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilBackFail", depthStencilState.stencilBackFail);
463*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilBackPassDepthFail", depthStencilState.stencilBackPassDepthFail);
464*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilBackPassDepthPass", depthStencilState.stencilBackPassDepthPass);
465*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilBackWritemask", depthStencilState.stencilBackWritemask);
466*8975f5c5SAndroid Build Coastguard Worker }
467*8975f5c5SAndroid Build Coastguard Worker
SerializeVertexAttribCurrentValueData(JsonSerializer * json,const gl::VertexAttribCurrentValueData & vertexAttribCurrentValueData)468*8975f5c5SAndroid Build Coastguard Worker void SerializeVertexAttribCurrentValueData(
469*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
470*8975f5c5SAndroid Build Coastguard Worker const gl::VertexAttribCurrentValueData &vertexAttribCurrentValueData)
471*8975f5c5SAndroid Build Coastguard Worker {
472*8975f5c5SAndroid Build Coastguard Worker ASSERT(vertexAttribCurrentValueData.Type == gl::VertexAttribType::Float ||
473*8975f5c5SAndroid Build Coastguard Worker vertexAttribCurrentValueData.Type == gl::VertexAttribType::Int ||
474*8975f5c5SAndroid Build Coastguard Worker vertexAttribCurrentValueData.Type == gl::VertexAttribType::UnsignedInt);
475*8975f5c5SAndroid Build Coastguard Worker if (vertexAttribCurrentValueData.Type == gl::VertexAttribType::Float)
476*8975f5c5SAndroid Build Coastguard Worker {
477*8975f5c5SAndroid Build Coastguard Worker json->addScalar("0", vertexAttribCurrentValueData.Values.FloatValues[0]);
478*8975f5c5SAndroid Build Coastguard Worker json->addScalar("1", vertexAttribCurrentValueData.Values.FloatValues[1]);
479*8975f5c5SAndroid Build Coastguard Worker json->addScalar("2", vertexAttribCurrentValueData.Values.FloatValues[2]);
480*8975f5c5SAndroid Build Coastguard Worker json->addScalar("3", vertexAttribCurrentValueData.Values.FloatValues[3]);
481*8975f5c5SAndroid Build Coastguard Worker }
482*8975f5c5SAndroid Build Coastguard Worker else if (vertexAttribCurrentValueData.Type == gl::VertexAttribType::Int)
483*8975f5c5SAndroid Build Coastguard Worker {
484*8975f5c5SAndroid Build Coastguard Worker json->addScalar("0", vertexAttribCurrentValueData.Values.IntValues[0]);
485*8975f5c5SAndroid Build Coastguard Worker json->addScalar("1", vertexAttribCurrentValueData.Values.IntValues[1]);
486*8975f5c5SAndroid Build Coastguard Worker json->addScalar("2", vertexAttribCurrentValueData.Values.IntValues[2]);
487*8975f5c5SAndroid Build Coastguard Worker json->addScalar("3", vertexAttribCurrentValueData.Values.IntValues[3]);
488*8975f5c5SAndroid Build Coastguard Worker }
489*8975f5c5SAndroid Build Coastguard Worker else
490*8975f5c5SAndroid Build Coastguard Worker {
491*8975f5c5SAndroid Build Coastguard Worker json->addScalar("0", vertexAttribCurrentValueData.Values.UnsignedIntValues[0]);
492*8975f5c5SAndroid Build Coastguard Worker json->addScalar("1", vertexAttribCurrentValueData.Values.UnsignedIntValues[1]);
493*8975f5c5SAndroid Build Coastguard Worker json->addScalar("2", vertexAttribCurrentValueData.Values.UnsignedIntValues[2]);
494*8975f5c5SAndroid Build Coastguard Worker json->addScalar("3", vertexAttribCurrentValueData.Values.UnsignedIntValues[3]);
495*8975f5c5SAndroid Build Coastguard Worker }
496*8975f5c5SAndroid Build Coastguard Worker }
497*8975f5c5SAndroid Build Coastguard Worker
SerializePixelPackState(JsonSerializer * json,const gl::PixelPackState & pixelPackState)498*8975f5c5SAndroid Build Coastguard Worker void SerializePixelPackState(JsonSerializer *json, const gl::PixelPackState &pixelPackState)
499*8975f5c5SAndroid Build Coastguard Worker {
500*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "PixelPackState");
501*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Alignment", pixelPackState.alignment);
502*8975f5c5SAndroid Build Coastguard Worker json->addScalar("RowLength", pixelPackState.rowLength);
503*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SkipRows", pixelPackState.skipRows);
504*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SkipPixels", pixelPackState.skipPixels);
505*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ImageHeight", pixelPackState.imageHeight);
506*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SkipImages", pixelPackState.skipImages);
507*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ReverseRowOrder", pixelPackState.reverseRowOrder);
508*8975f5c5SAndroid Build Coastguard Worker }
509*8975f5c5SAndroid Build Coastguard Worker
SerializePixelUnpackState(JsonSerializer * json,const gl::PixelUnpackState & pixelUnpackState)510*8975f5c5SAndroid Build Coastguard Worker void SerializePixelUnpackState(JsonSerializer *json, const gl::PixelUnpackState &pixelUnpackState)
511*8975f5c5SAndroid Build Coastguard Worker {
512*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "PixelUnpackState");
513*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Alignment", pixelUnpackState.alignment);
514*8975f5c5SAndroid Build Coastguard Worker json->addScalar("RowLength", pixelUnpackState.rowLength);
515*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SkipRows", pixelUnpackState.skipRows);
516*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SkipPixels", pixelUnpackState.skipPixels);
517*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ImageHeight", pixelUnpackState.imageHeight);
518*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SkipImages", pixelUnpackState.skipImages);
519*8975f5c5SAndroid Build Coastguard Worker }
520*8975f5c5SAndroid Build Coastguard Worker
SerializeImageUnit(JsonSerializer * json,const gl::ImageUnit & imageUnit,int imageUnitIndex)521*8975f5c5SAndroid Build Coastguard Worker void SerializeImageUnit(JsonSerializer *json, const gl::ImageUnit &imageUnit, int imageUnitIndex)
522*8975f5c5SAndroid Build Coastguard Worker {
523*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "ImageUnit", imageUnitIndex);
524*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Level", imageUnit.level);
525*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Layered", imageUnit.layered);
526*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Layer", imageUnit.layer);
527*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Access", imageUnit.access);
528*8975f5c5SAndroid Build Coastguard Worker json->addCString("Format", gl::GLinternalFormatToString(imageUnit.format));
529*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TextureID", imageUnit.texture.id().value);
530*8975f5c5SAndroid Build Coastguard Worker }
531*8975f5c5SAndroid Build Coastguard Worker
532*8975f5c5SAndroid Build Coastguard Worker template <typename ResourceType>
SerializeResourceID(JsonSerializer * json,const char * name,const ResourceType * resource)533*8975f5c5SAndroid Build Coastguard Worker void SerializeResourceID(JsonSerializer *json, const char *name, const ResourceType *resource)
534*8975f5c5SAndroid Build Coastguard Worker {
535*8975f5c5SAndroid Build Coastguard Worker json->addScalar(name, resource ? resource->id().value : 0);
536*8975f5c5SAndroid Build Coastguard Worker }
537*8975f5c5SAndroid Build Coastguard Worker
SerializeContextState(JsonSerializer * json,const gl::State & state)538*8975f5c5SAndroid Build Coastguard Worker void SerializeContextState(JsonSerializer *json, const gl::State &state)
539*8975f5c5SAndroid Build Coastguard Worker {
540*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "ContextState");
541*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Priority", state.getContextPriority());
542*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Major", state.getClientMajorVersion());
543*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Minor", state.getClientMinorVersion());
544*8975f5c5SAndroid Build Coastguard Worker SerializeColorFWithGroup(json, "ColorClearValue", state.getColorClearValue());
545*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DepthClearValue", state.getDepthClearValue());
546*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilClearValue", state.getStencilClearValue());
547*8975f5c5SAndroid Build Coastguard Worker SerializeRasterizerState(json, state.getRasterizerState());
548*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ScissorTestEnabled", state.isScissorTestEnabled());
549*8975f5c5SAndroid Build Coastguard Worker SerializeRectangle(json, "Scissors", state.getScissor());
550*8975f5c5SAndroid Build Coastguard Worker SerializeBlendStateExt(json, state.getBlendStateExt());
551*8975f5c5SAndroid Build Coastguard Worker SerializeColorFWithGroup(json, "BlendColor", state.getBlendColor());
552*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SampleAlphaToCoverageEnabled", state.isSampleAlphaToCoverageEnabled());
553*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SampleCoverageEnabled", state.isSampleCoverageEnabled());
554*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SampleCoverageValue", state.getSampleCoverageValue());
555*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SampleCoverageInvert", state.getSampleCoverageInvert());
556*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SampleMaskEnabled", state.isSampleMaskEnabled());
557*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MaxSampleMaskWords", state.getMaxSampleMaskWords());
558*8975f5c5SAndroid Build Coastguard Worker {
559*8975f5c5SAndroid Build Coastguard Worker const auto &sampleMaskValues = state.getSampleMaskValues();
560*8975f5c5SAndroid Build Coastguard Worker GroupScope maskGroup(json, "SampleMaskValues");
561*8975f5c5SAndroid Build Coastguard Worker for (size_t i = 0; i < sampleMaskValues.size(); i++)
562*8975f5c5SAndroid Build Coastguard Worker {
563*8975f5c5SAndroid Build Coastguard Worker json->addScalar(ToString(i), sampleMaskValues[i]);
564*8975f5c5SAndroid Build Coastguard Worker }
565*8975f5c5SAndroid Build Coastguard Worker }
566*8975f5c5SAndroid Build Coastguard Worker SerializeDepthStencilState(json, state.getDepthStencilState());
567*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilRef", state.getStencilRef());
568*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StencilBackRef", state.getStencilBackRef());
569*8975f5c5SAndroid Build Coastguard Worker json->addScalar("LineWidth", state.getLineWidth());
570*8975f5c5SAndroid Build Coastguard Worker json->addScalar("GenerateMipmapHint", state.getGenerateMipmapHint());
571*8975f5c5SAndroid Build Coastguard Worker json->addScalar("FragmentShaderDerivativeHint", state.getFragmentShaderDerivativeHint());
572*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BindGeneratesResourceEnabled", state.isBindGeneratesResourceEnabled());
573*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ClientArraysEnabled", state.areClientArraysEnabled());
574*8975f5c5SAndroid Build Coastguard Worker SerializeRectangle(json, "Viewport", state.getViewport());
575*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Near", state.getNearPlane());
576*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Far", state.getFarPlane());
577*8975f5c5SAndroid Build Coastguard Worker json->addString("ClipOrigin", ToString(state.getClipOrigin()));
578*8975f5c5SAndroid Build Coastguard Worker json->addString("ClipDepthMode", ToString(state.getClipDepthMode()));
579*8975f5c5SAndroid Build Coastguard Worker SerializeResourceID(json, "ReadFramebufferID", state.getReadFramebuffer());
580*8975f5c5SAndroid Build Coastguard Worker SerializeResourceID(json, "DrawFramebufferID", state.getDrawFramebuffer());
581*8975f5c5SAndroid Build Coastguard Worker json->addScalar("RenderbufferID", state.getRenderbufferId().value);
582*8975f5c5SAndroid Build Coastguard Worker SerializeResourceID(json, "CurrentProgramID", state.getProgram());
583*8975f5c5SAndroid Build Coastguard Worker SerializeResourceID(json, "CurrentProgramPipelineID", state.getProgramPipeline());
584*8975f5c5SAndroid Build Coastguard Worker json->addString("ProvokingVertex", ToString(state.getProvokingVertex()));
585*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::VertexAttribCurrentValueData> &vertexAttribCurrentValues =
586*8975f5c5SAndroid Build Coastguard Worker state.getVertexAttribCurrentValues();
587*8975f5c5SAndroid Build Coastguard Worker for (size_t i = 0; i < vertexAttribCurrentValues.size(); i++)
588*8975f5c5SAndroid Build Coastguard Worker {
589*8975f5c5SAndroid Build Coastguard Worker GroupScope vagroup(json, "VertexAttribCurrentValue", static_cast<int>(i));
590*8975f5c5SAndroid Build Coastguard Worker SerializeVertexAttribCurrentValueData(json, vertexAttribCurrentValues[i]);
591*8975f5c5SAndroid Build Coastguard Worker }
592*8975f5c5SAndroid Build Coastguard Worker ASSERT(state.getVertexArray());
593*8975f5c5SAndroid Build Coastguard Worker json->addScalar("VertexArrayID", state.getVertexArray()->id().value);
594*8975f5c5SAndroid Build Coastguard Worker json->addScalar("CurrentValuesTypeMask", state.getCurrentValuesTypeMask().to_ulong());
595*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ActiveSampler", state.getActiveSampler());
596*8975f5c5SAndroid Build Coastguard Worker {
597*8975f5c5SAndroid Build Coastguard Worker GroupScope boundTexturesGroup(json, "BoundTextures");
598*8975f5c5SAndroid Build Coastguard Worker const gl::TextureBindingMap &boundTexturesMap = state.getBoundTexturesForCapture();
599*8975f5c5SAndroid Build Coastguard Worker for (gl::TextureType textureType : AllEnums<gl::TextureType>())
600*8975f5c5SAndroid Build Coastguard Worker {
601*8975f5c5SAndroid Build Coastguard Worker const gl::TextureBindingVector &textures = boundTexturesMap[textureType];
602*8975f5c5SAndroid Build Coastguard Worker GroupScope texturesGroup(json, ToString(textureType));
603*8975f5c5SAndroid Build Coastguard Worker SerializeBindingPointerVector<gl::Texture>(json, textures);
604*8975f5c5SAndroid Build Coastguard Worker }
605*8975f5c5SAndroid Build Coastguard Worker }
606*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TexturesIncompatibleWithSamplers",
607*8975f5c5SAndroid Build Coastguard Worker state.getTexturesIncompatibleWithSamplers().to_ulong());
608*8975f5c5SAndroid Build Coastguard Worker
609*8975f5c5SAndroid Build Coastguard Worker {
610*8975f5c5SAndroid Build Coastguard Worker GroupScope texturesCacheGroup(json, "ActiveTexturesCache");
611*8975f5c5SAndroid Build Coastguard Worker
612*8975f5c5SAndroid Build Coastguard Worker const gl::ActiveTexturesCache &texturesCache = state.getActiveTexturesCache();
613*8975f5c5SAndroid Build Coastguard Worker for (GLuint textureIndex = 0; textureIndex < texturesCache.size(); ++textureIndex)
614*8975f5c5SAndroid Build Coastguard Worker {
615*8975f5c5SAndroid Build Coastguard Worker const gl::Texture *tex = texturesCache[textureIndex];
616*8975f5c5SAndroid Build Coastguard Worker std::stringstream strstr;
617*8975f5c5SAndroid Build Coastguard Worker strstr << "Tex " << std::setfill('0') << std::setw(2) << textureIndex;
618*8975f5c5SAndroid Build Coastguard Worker json->addScalar(strstr.str(), tex ? tex->id().value : 0);
619*8975f5c5SAndroid Build Coastguard Worker }
620*8975f5c5SAndroid Build Coastguard Worker }
621*8975f5c5SAndroid Build Coastguard Worker
622*8975f5c5SAndroid Build Coastguard Worker {
623*8975f5c5SAndroid Build Coastguard Worker GroupScope samplersGroupScope(json, "Samplers");
624*8975f5c5SAndroid Build Coastguard Worker SerializeBindingPointerVector<gl::Sampler>(json, state.getSamplers());
625*8975f5c5SAndroid Build Coastguard Worker }
626*8975f5c5SAndroid Build Coastguard Worker
627*8975f5c5SAndroid Build Coastguard Worker {
628*8975f5c5SAndroid Build Coastguard Worker GroupScope imageUnitsGroup(json, "BoundImageUnits");
629*8975f5c5SAndroid Build Coastguard Worker
630*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::ImageUnit> &imageUnits = state.getImageUnits();
631*8975f5c5SAndroid Build Coastguard Worker for (size_t imageUnitIndex = 0; imageUnitIndex < imageUnits.size(); ++imageUnitIndex)
632*8975f5c5SAndroid Build Coastguard Worker {
633*8975f5c5SAndroid Build Coastguard Worker const gl::ImageUnit &imageUnit = imageUnits[imageUnitIndex];
634*8975f5c5SAndroid Build Coastguard Worker SerializeImageUnit(json, imageUnit, static_cast<int>(imageUnitIndex));
635*8975f5c5SAndroid Build Coastguard Worker }
636*8975f5c5SAndroid Build Coastguard Worker }
637*8975f5c5SAndroid Build Coastguard Worker
638*8975f5c5SAndroid Build Coastguard Worker {
639*8975f5c5SAndroid Build Coastguard Worker const gl::ActiveQueryMap &activeQueries = state.getActiveQueriesForCapture();
640*8975f5c5SAndroid Build Coastguard Worker GroupScope activeQueriesGroup(json, "ActiveQueries");
641*8975f5c5SAndroid Build Coastguard Worker for (gl::QueryType queryType : AllEnums<gl::QueryType>())
642*8975f5c5SAndroid Build Coastguard Worker {
643*8975f5c5SAndroid Build Coastguard Worker const gl::BindingPointer<gl::Query> &query = activeQueries[queryType];
644*8975f5c5SAndroid Build Coastguard Worker std::stringstream strstr;
645*8975f5c5SAndroid Build Coastguard Worker strstr << queryType;
646*8975f5c5SAndroid Build Coastguard Worker json->addScalar(strstr.str(), query.id().value);
647*8975f5c5SAndroid Build Coastguard Worker }
648*8975f5c5SAndroid Build Coastguard Worker }
649*8975f5c5SAndroid Build Coastguard Worker
650*8975f5c5SAndroid Build Coastguard Worker {
651*8975f5c5SAndroid Build Coastguard Worker const gl::BoundBufferMap &boundBuffers = state.getBoundBuffersForCapture();
652*8975f5c5SAndroid Build Coastguard Worker GroupScope boundBuffersGroup(json, "BoundBuffers");
653*8975f5c5SAndroid Build Coastguard Worker for (gl::BufferBinding bufferBinding : AllEnums<gl::BufferBinding>())
654*8975f5c5SAndroid Build Coastguard Worker {
655*8975f5c5SAndroid Build Coastguard Worker const gl::BindingPointer<gl::Buffer> &buffer = boundBuffers[bufferBinding];
656*8975f5c5SAndroid Build Coastguard Worker std::stringstream strstr;
657*8975f5c5SAndroid Build Coastguard Worker strstr << bufferBinding;
658*8975f5c5SAndroid Build Coastguard Worker json->addScalar(strstr.str(), buffer.id().value);
659*8975f5c5SAndroid Build Coastguard Worker }
660*8975f5c5SAndroid Build Coastguard Worker }
661*8975f5c5SAndroid Build Coastguard Worker
662*8975f5c5SAndroid Build Coastguard Worker SerializeOffsetBindingPointerVector<gl::Buffer>(json, "UniformBufferBindings",
663*8975f5c5SAndroid Build Coastguard Worker state.getOffsetBindingPointerUniformBuffers());
664*8975f5c5SAndroid Build Coastguard Worker SerializeOffsetBindingPointerVector<gl::Buffer>(
665*8975f5c5SAndroid Build Coastguard Worker json, "AtomicCounterBufferBindings", state.getOffsetBindingPointerAtomicCounterBuffers());
666*8975f5c5SAndroid Build Coastguard Worker SerializeOffsetBindingPointerVector<gl::Buffer>(
667*8975f5c5SAndroid Build Coastguard Worker json, "ShaderStorageBufferBindings", state.getOffsetBindingPointerShaderStorageBuffers());
668*8975f5c5SAndroid Build Coastguard Worker if (state.getCurrentTransformFeedback())
669*8975f5c5SAndroid Build Coastguard Worker {
670*8975f5c5SAndroid Build Coastguard Worker json->addScalar("CurrentTransformFeedback",
671*8975f5c5SAndroid Build Coastguard Worker state.getCurrentTransformFeedback()->id().value);
672*8975f5c5SAndroid Build Coastguard Worker }
673*8975f5c5SAndroid Build Coastguard Worker SerializePixelUnpackState(json, state.getUnpackState());
674*8975f5c5SAndroid Build Coastguard Worker SerializePixelPackState(json, state.getPackState());
675*8975f5c5SAndroid Build Coastguard Worker json->addScalar("PrimitiveRestartEnabled", state.isPrimitiveRestartEnabled());
676*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MultisamplingEnabled", state.isMultisamplingEnabled());
677*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SampleAlphaToOneEnabled", state.isSampleAlphaToOneEnabled());
678*8975f5c5SAndroid Build Coastguard Worker json->addScalar("CoverageModulation", state.getCoverageModulation());
679*8975f5c5SAndroid Build Coastguard Worker json->addScalar("FramebufferSRGB", state.getFramebufferSRGB());
680*8975f5c5SAndroid Build Coastguard Worker json->addScalar("RobustResourceInitEnabled", state.isRobustResourceInitEnabled());
681*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ProgramBinaryCacheEnabled", state.isProgramBinaryCacheEnabled());
682*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TextureRectangleEnabled", state.isTextureRectangleEnabled());
683*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MaxShaderCompilerThreads", state.getMaxShaderCompilerThreads());
684*8975f5c5SAndroid Build Coastguard Worker json->addScalar("EnabledClipDistances", state.getEnabledClipDistances().to_ulong());
685*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BlendFuncConstantAlphaDrawBuffers",
686*8975f5c5SAndroid Build Coastguard Worker state.getBlendFuncConstantAlphaDrawBuffers().to_ulong());
687*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BlendFuncConstantColorDrawBuffers",
688*8975f5c5SAndroid Build Coastguard Worker state.getBlendFuncConstantColorDrawBuffers().to_ulong());
689*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SimultaneousConstantColorAndAlphaBlendFunc",
690*8975f5c5SAndroid Build Coastguard Worker state.noSimultaneousConstantColorAndAlphaBlendFunc());
691*8975f5c5SAndroid Build Coastguard Worker }
692*8975f5c5SAndroid Build Coastguard Worker
SerializeBufferState(JsonSerializer * json,const gl::BufferState & bufferState)693*8975f5c5SAndroid Build Coastguard Worker void SerializeBufferState(JsonSerializer *json, const gl::BufferState &bufferState)
694*8975f5c5SAndroid Build Coastguard Worker {
695*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", bufferState.getLabel());
696*8975f5c5SAndroid Build Coastguard Worker json->addString("Usage", ToString(bufferState.getUsage()));
697*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Size", bufferState.getSize());
698*8975f5c5SAndroid Build Coastguard Worker json->addScalar("AccessFlags", bufferState.getAccessFlags());
699*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Access", bufferState.getAccess());
700*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Mapped", bufferState.isMapped());
701*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MapOffset", bufferState.getMapOffset());
702*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MapLength", bufferState.getMapLength());
703*8975f5c5SAndroid Build Coastguard Worker }
704*8975f5c5SAndroid Build Coastguard Worker
SerializeBuffer(const gl::Context * context,JsonSerializer * json,ScratchBuffer * scratchBuffer,gl::Buffer * buffer)705*8975f5c5SAndroid Build Coastguard Worker Result SerializeBuffer(const gl::Context *context,
706*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
707*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer,
708*8975f5c5SAndroid Build Coastguard Worker gl::Buffer *buffer)
709*8975f5c5SAndroid Build Coastguard Worker {
710*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Buffer", buffer->id().value);
711*8975f5c5SAndroid Build Coastguard Worker SerializeBufferState(json, buffer->getState());
712*8975f5c5SAndroid Build Coastguard Worker if (buffer->getSize() > 0)
713*8975f5c5SAndroid Build Coastguard Worker {
714*8975f5c5SAndroid Build Coastguard Worker MemoryBuffer *dataPtr = nullptr;
715*8975f5c5SAndroid Build Coastguard Worker ANGLE_CHECK_GL_ALLOC(
716*8975f5c5SAndroid Build Coastguard Worker const_cast<gl::Context *>(context),
717*8975f5c5SAndroid Build Coastguard Worker scratchBuffer->getInitialized(static_cast<size_t>(buffer->getSize()), &dataPtr, 0));
718*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(buffer->getSubData(context, 0, dataPtr->size(), dataPtr->data()));
719*8975f5c5SAndroid Build Coastguard Worker json->addBlob("data", dataPtr->data(), dataPtr->size());
720*8975f5c5SAndroid Build Coastguard Worker }
721*8975f5c5SAndroid Build Coastguard Worker else
722*8975f5c5SAndroid Build Coastguard Worker {
723*8975f5c5SAndroid Build Coastguard Worker json->addCString("data", "null");
724*8975f5c5SAndroid Build Coastguard Worker }
725*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
726*8975f5c5SAndroid Build Coastguard Worker }
727*8975f5c5SAndroid Build Coastguard Worker
SerializeColorGeneric(JsonSerializer * json,const std::string & name,const ColorGeneric & colorGeneric)728*8975f5c5SAndroid Build Coastguard Worker void SerializeColorGeneric(JsonSerializer *json,
729*8975f5c5SAndroid Build Coastguard Worker const std::string &name,
730*8975f5c5SAndroid Build Coastguard Worker const ColorGeneric &colorGeneric)
731*8975f5c5SAndroid Build Coastguard Worker {
732*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, name);
733*8975f5c5SAndroid Build Coastguard Worker ASSERT(colorGeneric.type == ColorGeneric::Type::Float ||
734*8975f5c5SAndroid Build Coastguard Worker colorGeneric.type == ColorGeneric::Type::Int ||
735*8975f5c5SAndroid Build Coastguard Worker colorGeneric.type == ColorGeneric::Type::UInt);
736*8975f5c5SAndroid Build Coastguard Worker json->addCString("Type", ColorGenericTypeToString(colorGeneric.type));
737*8975f5c5SAndroid Build Coastguard Worker if (colorGeneric.type == ColorGeneric::Type::Float)
738*8975f5c5SAndroid Build Coastguard Worker {
739*8975f5c5SAndroid Build Coastguard Worker SerializeColorF(json, colorGeneric.colorF);
740*8975f5c5SAndroid Build Coastguard Worker }
741*8975f5c5SAndroid Build Coastguard Worker else if (colorGeneric.type == ColorGeneric::Type::Int)
742*8975f5c5SAndroid Build Coastguard Worker {
743*8975f5c5SAndroid Build Coastguard Worker SerializeColorI(json, colorGeneric.colorI);
744*8975f5c5SAndroid Build Coastguard Worker }
745*8975f5c5SAndroid Build Coastguard Worker else
746*8975f5c5SAndroid Build Coastguard Worker {
747*8975f5c5SAndroid Build Coastguard Worker SerializeColorUI(json, colorGeneric.colorUI);
748*8975f5c5SAndroid Build Coastguard Worker }
749*8975f5c5SAndroid Build Coastguard Worker }
750*8975f5c5SAndroid Build Coastguard Worker
SerializeSamplerState(JsonSerializer * json,const gl::SamplerState & samplerState)751*8975f5c5SAndroid Build Coastguard Worker void SerializeSamplerState(JsonSerializer *json, const gl::SamplerState &samplerState)
752*8975f5c5SAndroid Build Coastguard Worker {
753*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MinFilter", samplerState.getMinFilter());
754*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MagFilter", samplerState.getMagFilter());
755*8975f5c5SAndroid Build Coastguard Worker json->addScalar("WrapS", samplerState.getWrapS());
756*8975f5c5SAndroid Build Coastguard Worker json->addScalar("WrapT", samplerState.getWrapT());
757*8975f5c5SAndroid Build Coastguard Worker json->addScalar("WrapR", samplerState.getWrapR());
758*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MaxAnisotropy", samplerState.getMaxAnisotropy());
759*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MinLod", samplerState.getMinLod());
760*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MaxLod", samplerState.getMaxLod());
761*8975f5c5SAndroid Build Coastguard Worker json->addScalar("CompareMode", samplerState.getCompareMode());
762*8975f5c5SAndroid Build Coastguard Worker json->addScalar("CompareFunc", samplerState.getCompareFunc());
763*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SRGBDecode", samplerState.getSRGBDecode());
764*8975f5c5SAndroid Build Coastguard Worker SerializeColorGeneric(json, "BorderColor", samplerState.getBorderColor());
765*8975f5c5SAndroid Build Coastguard Worker }
766*8975f5c5SAndroid Build Coastguard Worker
SerializeSampler(JsonSerializer * json,gl::Sampler * sampler)767*8975f5c5SAndroid Build Coastguard Worker void SerializeSampler(JsonSerializer *json, gl::Sampler *sampler)
768*8975f5c5SAndroid Build Coastguard Worker {
769*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Sampler", sampler->id().value);
770*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", sampler->getLabel());
771*8975f5c5SAndroid Build Coastguard Worker SerializeSamplerState(json, sampler->getSamplerState());
772*8975f5c5SAndroid Build Coastguard Worker }
773*8975f5c5SAndroid Build Coastguard Worker
SerializeSwizzleState(JsonSerializer * json,const gl::SwizzleState & swizzleState)774*8975f5c5SAndroid Build Coastguard Worker void SerializeSwizzleState(JsonSerializer *json, const gl::SwizzleState &swizzleState)
775*8975f5c5SAndroid Build Coastguard Worker {
776*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SwizzleRed", swizzleState.swizzleRed);
777*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SwizzleGreen", swizzleState.swizzleGreen);
778*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SwizzleBlue", swizzleState.swizzleBlue);
779*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SwizzleAlpha", swizzleState.swizzleAlpha);
780*8975f5c5SAndroid Build Coastguard Worker }
781*8975f5c5SAndroid Build Coastguard Worker
SerializeRenderbufferState(JsonSerializer * json,const gl::RenderbufferState & renderbufferState)782*8975f5c5SAndroid Build Coastguard Worker void SerializeRenderbufferState(JsonSerializer *json,
783*8975f5c5SAndroid Build Coastguard Worker const gl::RenderbufferState &renderbufferState)
784*8975f5c5SAndroid Build Coastguard Worker {
785*8975f5c5SAndroid Build Coastguard Worker GroupScope wg(json, "State");
786*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Width", renderbufferState.getWidth());
787*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Height", renderbufferState.getHeight());
788*8975f5c5SAndroid Build Coastguard Worker SerializeGLFormat(json, renderbufferState.getFormat());
789*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Samples", renderbufferState.getSamples());
790*8975f5c5SAndroid Build Coastguard Worker json->addCString("InitState", InitStateToString(renderbufferState.getInitState()));
791*8975f5c5SAndroid Build Coastguard Worker }
792*8975f5c5SAndroid Build Coastguard Worker
SerializeRenderbuffer(const gl::Context * context,JsonSerializer * json,ScratchBuffer * scratchBuffer,gl::Renderbuffer * renderbuffer)793*8975f5c5SAndroid Build Coastguard Worker Result SerializeRenderbuffer(const gl::Context *context,
794*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
795*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer,
796*8975f5c5SAndroid Build Coastguard Worker gl::Renderbuffer *renderbuffer)
797*8975f5c5SAndroid Build Coastguard Worker {
798*8975f5c5SAndroid Build Coastguard Worker GroupScope wg(json, "Renderbuffer", renderbuffer->id().value);
799*8975f5c5SAndroid Build Coastguard Worker SerializeRenderbufferState(json, renderbuffer->getState());
800*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", renderbuffer->getLabel());
801*8975f5c5SAndroid Build Coastguard Worker
802*8975f5c5SAndroid Build Coastguard Worker if (renderbuffer->initState(GL_NONE, gl::ImageIndex()) == gl::InitState::Initialized)
803*8975f5c5SAndroid Build Coastguard Worker {
804*8975f5c5SAndroid Build Coastguard Worker if (renderbuffer->getSamples() > 1 && renderbuffer->getFormat().info->depthBits > 0)
805*8975f5c5SAndroid Build Coastguard Worker {
806*8975f5c5SAndroid Build Coastguard Worker // Vulkan can't do resolve blits for multisampled depth attachemnts and
807*8975f5c5SAndroid Build Coastguard Worker // we don't implement an emulation, therefore we can't read back any useful
808*8975f5c5SAndroid Build Coastguard Worker // data here.
809*8975f5c5SAndroid Build Coastguard Worker json->addCString("Pixels", "multisampled depth buffer");
810*8975f5c5SAndroid Build Coastguard Worker }
811*8975f5c5SAndroid Build Coastguard Worker else if (renderbuffer->getWidth() * renderbuffer->getHeight() <= 0)
812*8975f5c5SAndroid Build Coastguard Worker {
813*8975f5c5SAndroid Build Coastguard Worker json->addCString("Pixels", "no pixels");
814*8975f5c5SAndroid Build Coastguard Worker }
815*8975f5c5SAndroid Build Coastguard Worker else
816*8975f5c5SAndroid Build Coastguard Worker {
817*8975f5c5SAndroid Build Coastguard Worker const gl::InternalFormat &format = *renderbuffer->getFormat().info;
818*8975f5c5SAndroid Build Coastguard Worker
819*8975f5c5SAndroid Build Coastguard Worker const gl::Extents size(renderbuffer->getWidth(), renderbuffer->getHeight(), 1);
820*8975f5c5SAndroid Build Coastguard Worker gl::PixelPackState packState;
821*8975f5c5SAndroid Build Coastguard Worker packState.alignment = 1;
822*8975f5c5SAndroid Build Coastguard Worker
823*8975f5c5SAndroid Build Coastguard Worker GLenum readFormat = renderbuffer->getImplementationColorReadFormat(context);
824*8975f5c5SAndroid Build Coastguard Worker GLenum readType = renderbuffer->getImplementationColorReadType(context);
825*8975f5c5SAndroid Build Coastguard Worker
826*8975f5c5SAndroid Build Coastguard Worker GLuint bytes = 0;
827*8975f5c5SAndroid Build Coastguard Worker bool computeOK =
828*8975f5c5SAndroid Build Coastguard Worker format.computePackUnpackEndByte(readType, size, packState, false, &bytes);
829*8975f5c5SAndroid Build Coastguard Worker ASSERT(computeOK);
830*8975f5c5SAndroid Build Coastguard Worker
831*8975f5c5SAndroid Build Coastguard Worker MemoryBuffer *pixelsPtr = nullptr;
832*8975f5c5SAndroid Build Coastguard Worker ANGLE_CHECK_GL_ALLOC(const_cast<gl::Context *>(context),
833*8975f5c5SAndroid Build Coastguard Worker scratchBuffer->getInitialized(bytes, &pixelsPtr, 0));
834*8975f5c5SAndroid Build Coastguard Worker
835*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(renderbuffer->getImplementation()->getRenderbufferImage(
836*8975f5c5SAndroid Build Coastguard Worker context, packState, nullptr, readFormat, readType, pixelsPtr->data()));
837*8975f5c5SAndroid Build Coastguard Worker json->addBlob("Pixels", pixelsPtr->data(), pixelsPtr->size());
838*8975f5c5SAndroid Build Coastguard Worker }
839*8975f5c5SAndroid Build Coastguard Worker }
840*8975f5c5SAndroid Build Coastguard Worker else
841*8975f5c5SAndroid Build Coastguard Worker {
842*8975f5c5SAndroid Build Coastguard Worker json->addCString("Pixels", "Not initialized");
843*8975f5c5SAndroid Build Coastguard Worker }
844*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
845*8975f5c5SAndroid Build Coastguard Worker }
846*8975f5c5SAndroid Build Coastguard Worker
SerializeWorkGroupSize(JsonSerializer * json,const sh::WorkGroupSize & workGroupSize)847*8975f5c5SAndroid Build Coastguard Worker void SerializeWorkGroupSize(JsonSerializer *json, const sh::WorkGroupSize &workGroupSize)
848*8975f5c5SAndroid Build Coastguard Worker {
849*8975f5c5SAndroid Build Coastguard Worker GroupScope wg(json, "workGroupSize");
850*8975f5c5SAndroid Build Coastguard Worker json->addScalar("x", workGroupSize[0]);
851*8975f5c5SAndroid Build Coastguard Worker json->addScalar("y", workGroupSize[1]);
852*8975f5c5SAndroid Build Coastguard Worker json->addScalar("z", workGroupSize[2]);
853*8975f5c5SAndroid Build Coastguard Worker }
854*8975f5c5SAndroid Build Coastguard Worker
SerializeUniformIndexToBufferBinding(JsonSerializer * json,const gl::ProgramUniformBlockArray<GLuint> & blockToBuffer)855*8975f5c5SAndroid Build Coastguard Worker void SerializeUniformIndexToBufferBinding(JsonSerializer *json,
856*8975f5c5SAndroid Build Coastguard Worker const gl::ProgramUniformBlockArray<GLuint> &blockToBuffer)
857*8975f5c5SAndroid Build Coastguard Worker {
858*8975f5c5SAndroid Build Coastguard Worker GroupScope wg(json, "uniformBlockIndexToBufferBinding");
859*8975f5c5SAndroid Build Coastguard Worker for (size_t blockIndex = 0; blockIndex < blockToBuffer.size(); ++blockIndex)
860*8975f5c5SAndroid Build Coastguard Worker {
861*8975f5c5SAndroid Build Coastguard Worker json->addScalar(ToString(blockIndex), blockToBuffer[blockIndex]);
862*8975f5c5SAndroid Build Coastguard Worker }
863*8975f5c5SAndroid Build Coastguard Worker }
864*8975f5c5SAndroid Build Coastguard Worker
SerializeShaderVariable(JsonSerializer * json,const sh::ShaderVariable & shaderVariable)865*8975f5c5SAndroid Build Coastguard Worker void SerializeShaderVariable(JsonSerializer *json, const sh::ShaderVariable &shaderVariable)
866*8975f5c5SAndroid Build Coastguard Worker {
867*8975f5c5SAndroid Build Coastguard Worker GroupScope wg(json, "ShaderVariable");
868*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Type", shaderVariable.type);
869*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Precision", shaderVariable.precision);
870*8975f5c5SAndroid Build Coastguard Worker json->addString("Name", shaderVariable.name);
871*8975f5c5SAndroid Build Coastguard Worker json->addString("MappedName", shaderVariable.mappedName);
872*8975f5c5SAndroid Build Coastguard Worker json->addVector("ArraySizes", shaderVariable.arraySizes);
873*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StaticUse", shaderVariable.staticUse);
874*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Active", shaderVariable.active);
875*8975f5c5SAndroid Build Coastguard Worker for (const sh::ShaderVariable &field : shaderVariable.fields)
876*8975f5c5SAndroid Build Coastguard Worker {
877*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariable(json, field);
878*8975f5c5SAndroid Build Coastguard Worker }
879*8975f5c5SAndroid Build Coastguard Worker json->addString("StructOrBlockName", shaderVariable.structOrBlockName);
880*8975f5c5SAndroid Build Coastguard Worker json->addString("MappedStructOrBlockName", shaderVariable.mappedStructOrBlockName);
881*8975f5c5SAndroid Build Coastguard Worker json->addScalar("RowMajorLayout", shaderVariable.isRowMajorLayout);
882*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Location", shaderVariable.location);
883*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Binding", shaderVariable.binding);
884*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ImageUnitFormat", shaderVariable.imageUnitFormat);
885*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Offset", shaderVariable.offset);
886*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Readonly", shaderVariable.readonly);
887*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Writeonly", shaderVariable.writeonly);
888*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Index", shaderVariable.index);
889*8975f5c5SAndroid Build Coastguard Worker json->addScalar("YUV", shaderVariable.yuv);
890*8975f5c5SAndroid Build Coastguard Worker json->addCString("Interpolation", InterpolationTypeToString(shaderVariable.interpolation));
891*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Invariant", shaderVariable.isInvariant);
892*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TexelFetchStaticUse", shaderVariable.texelFetchStaticUse);
893*8975f5c5SAndroid Build Coastguard Worker }
894*8975f5c5SAndroid Build Coastguard Worker
SerializeShaderVariablesVector(JsonSerializer * json,const std::vector<sh::ShaderVariable> & shaderVariables)895*8975f5c5SAndroid Build Coastguard Worker void SerializeShaderVariablesVector(JsonSerializer *json,
896*8975f5c5SAndroid Build Coastguard Worker const std::vector<sh::ShaderVariable> &shaderVariables)
897*8975f5c5SAndroid Build Coastguard Worker {
898*8975f5c5SAndroid Build Coastguard Worker for (const sh::ShaderVariable &shaderVariable : shaderVariables)
899*8975f5c5SAndroid Build Coastguard Worker {
900*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariable(json, shaderVariable);
901*8975f5c5SAndroid Build Coastguard Worker }
902*8975f5c5SAndroid Build Coastguard Worker }
903*8975f5c5SAndroid Build Coastguard Worker
SerializeInterfaceBlocksVector(JsonSerializer * json,const std::vector<sh::InterfaceBlock> & interfaceBlocks)904*8975f5c5SAndroid Build Coastguard Worker void SerializeInterfaceBlocksVector(JsonSerializer *json,
905*8975f5c5SAndroid Build Coastguard Worker const std::vector<sh::InterfaceBlock> &interfaceBlocks)
906*8975f5c5SAndroid Build Coastguard Worker {
907*8975f5c5SAndroid Build Coastguard Worker for (const sh::InterfaceBlock &interfaceBlock : interfaceBlocks)
908*8975f5c5SAndroid Build Coastguard Worker {
909*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Interface Block");
910*8975f5c5SAndroid Build Coastguard Worker json->addString("Name", interfaceBlock.name);
911*8975f5c5SAndroid Build Coastguard Worker json->addString("MappedName", interfaceBlock.mappedName);
912*8975f5c5SAndroid Build Coastguard Worker json->addString("InstanceName", interfaceBlock.instanceName);
913*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ArraySize", interfaceBlock.arraySize);
914*8975f5c5SAndroid Build Coastguard Worker json->addCString("Layout", BlockLayoutTypeToString(interfaceBlock.layout));
915*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Binding", interfaceBlock.binding);
916*8975f5c5SAndroid Build Coastguard Worker json->addScalar("StaticUse", interfaceBlock.staticUse);
917*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Active", interfaceBlock.active);
918*8975f5c5SAndroid Build Coastguard Worker json->addCString("BlockType", BlockTypeToString(interfaceBlock.blockType));
919*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariablesVector(json, interfaceBlock.fields);
920*8975f5c5SAndroid Build Coastguard Worker }
921*8975f5c5SAndroid Build Coastguard Worker }
922*8975f5c5SAndroid Build Coastguard Worker
SerializeCompiledShaderState(JsonSerializer * json,const gl::SharedCompiledShaderState & state)923*8975f5c5SAndroid Build Coastguard Worker void SerializeCompiledShaderState(JsonSerializer *json, const gl::SharedCompiledShaderState &state)
924*8975f5c5SAndroid Build Coastguard Worker {
925*8975f5c5SAndroid Build Coastguard Worker json->addCString("Type", gl::ShaderTypeToString(state->shaderType));
926*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Version", state->shaderVersion);
927*8975f5c5SAndroid Build Coastguard Worker json->addString("TranslatedSource", state->translatedSource);
928*8975f5c5SAndroid Build Coastguard Worker json->addVectorAsHash("CompiledBinary", state->compiledBinary);
929*8975f5c5SAndroid Build Coastguard Worker SerializeWorkGroupSize(json, state->localSize);
930*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariablesVector(json, state->inputVaryings);
931*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariablesVector(json, state->outputVaryings);
932*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariablesVector(json, state->uniforms);
933*8975f5c5SAndroid Build Coastguard Worker SerializeInterfaceBlocksVector(json, state->uniformBlocks);
934*8975f5c5SAndroid Build Coastguard Worker SerializeInterfaceBlocksVector(json, state->shaderStorageBlocks);
935*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariablesVector(json, state->allAttributes);
936*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariablesVector(json, state->activeAttributes);
937*8975f5c5SAndroid Build Coastguard Worker SerializeShaderVariablesVector(json, state->activeOutputVariables);
938*8975f5c5SAndroid Build Coastguard Worker json->addScalar("NumViews", state->numViews);
939*8975f5c5SAndroid Build Coastguard Worker json->addScalar("SpecConstUsageBits", state->specConstUsageBits.bits());
940*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MetadataFlags", state->metadataFlags.bits());
941*8975f5c5SAndroid Build Coastguard Worker json->addScalar("AdvancedBlendEquations", state->advancedBlendEquations.bits());
942*8975f5c5SAndroid Build Coastguard Worker json->addString("GeometryShaderInputPrimitiveType",
943*8975f5c5SAndroid Build Coastguard Worker ToString(state->geometryShaderInputPrimitiveType));
944*8975f5c5SAndroid Build Coastguard Worker json->addString("GeometryShaderOutputPrimitiveType",
945*8975f5c5SAndroid Build Coastguard Worker ToString(state->geometryShaderOutputPrimitiveType));
946*8975f5c5SAndroid Build Coastguard Worker json->addScalar("GeometryShaderMaxVertices", state->geometryShaderMaxVertices);
947*8975f5c5SAndroid Build Coastguard Worker json->addScalar("GeometryShaderInvocations", state->geometryShaderInvocations);
948*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TessControlShaderVertices", state->tessControlShaderVertices);
949*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TessGenMode", state->tessGenMode);
950*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TessGenSpacing", state->tessGenSpacing);
951*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TessGenVertexOrder", state->tessGenVertexOrder);
952*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TessGenPointMode", state->tessGenPointMode);
953*8975f5c5SAndroid Build Coastguard Worker }
954*8975f5c5SAndroid Build Coastguard Worker
SerializeShaderState(JsonSerializer * json,const gl::ShaderState & shaderState)955*8975f5c5SAndroid Build Coastguard Worker void SerializeShaderState(JsonSerializer *json, const gl::ShaderState &shaderState)
956*8975f5c5SAndroid Build Coastguard Worker {
957*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "ShaderState");
958*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", shaderState.getLabel());
959*8975f5c5SAndroid Build Coastguard Worker json->addString("Source", shaderState.getSource());
960*8975f5c5SAndroid Build Coastguard Worker json->addCString("CompileStatus", CompileStatusToString(shaderState.getCompileStatus()));
961*8975f5c5SAndroid Build Coastguard Worker }
962*8975f5c5SAndroid Build Coastguard Worker
SerializeShader(const gl::Context * context,JsonSerializer * json,GLuint id,gl::Shader * shader)963*8975f5c5SAndroid Build Coastguard Worker void SerializeShader(const gl::Context *context,
964*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
965*8975f5c5SAndroid Build Coastguard Worker GLuint id,
966*8975f5c5SAndroid Build Coastguard Worker gl::Shader *shader)
967*8975f5c5SAndroid Build Coastguard Worker {
968*8975f5c5SAndroid Build Coastguard Worker // Ensure deterministic compilation.
969*8975f5c5SAndroid Build Coastguard Worker shader->resolveCompile(context);
970*8975f5c5SAndroid Build Coastguard Worker
971*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Shader", id);
972*8975f5c5SAndroid Build Coastguard Worker SerializeShaderState(json, shader->getState());
973*8975f5c5SAndroid Build Coastguard Worker SerializeCompiledShaderState(json, shader->getCompiledState());
974*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Handle", shader->getHandle().value);
975*8975f5c5SAndroid Build Coastguard Worker // TODO: implement MEC context validation only after all contexts have been initialized
976*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42266488
977*8975f5c5SAndroid Build Coastguard Worker // json->addScalar("RefCount", shader->getRefCount());
978*8975f5c5SAndroid Build Coastguard Worker json->addScalar("FlaggedForDeletion", shader->isFlaggedForDeletion());
979*8975f5c5SAndroid Build Coastguard Worker // Do not serialize mType because it is already serialized in SerializeCompiledShaderState.
980*8975f5c5SAndroid Build Coastguard Worker json->addString("InfoLogString", shader->getInfoLogString());
981*8975f5c5SAndroid Build Coastguard Worker // Do not serialize compiler resources string because it can vary between test modes.
982*8975f5c5SAndroid Build Coastguard Worker }
983*8975f5c5SAndroid Build Coastguard Worker
SerializeVariableLocationsVector(JsonSerializer * json,const std::string & group_name,const std::vector<gl::VariableLocation> & variableLocations)984*8975f5c5SAndroid Build Coastguard Worker void SerializeVariableLocationsVector(JsonSerializer *json,
985*8975f5c5SAndroid Build Coastguard Worker const std::string &group_name,
986*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::VariableLocation> &variableLocations)
987*8975f5c5SAndroid Build Coastguard Worker {
988*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, group_name);
989*8975f5c5SAndroid Build Coastguard Worker for (size_t locIndex = 0; locIndex < variableLocations.size(); ++locIndex)
990*8975f5c5SAndroid Build Coastguard Worker {
991*8975f5c5SAndroid Build Coastguard Worker const gl::VariableLocation &variableLocation = variableLocations[locIndex];
992*8975f5c5SAndroid Build Coastguard Worker GroupScope vargroup(json, "Location", static_cast<int>(locIndex));
993*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ArrayIndex", variableLocation.arrayIndex);
994*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Index", variableLocation.index);
995*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Ignored", variableLocation.ignored);
996*8975f5c5SAndroid Build Coastguard Worker }
997*8975f5c5SAndroid Build Coastguard Worker }
998*8975f5c5SAndroid Build Coastguard Worker
SerializeBlockMemberInfo(JsonSerializer * json,const sh::BlockMemberInfo & blockMemberInfo)999*8975f5c5SAndroid Build Coastguard Worker void SerializeBlockMemberInfo(JsonSerializer *json, const sh::BlockMemberInfo &blockMemberInfo)
1000*8975f5c5SAndroid Build Coastguard Worker {
1001*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "BlockMemberInfo");
1002*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Offset", blockMemberInfo.offset);
1003*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Stride", blockMemberInfo.arrayStride);
1004*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MatrixStride", blockMemberInfo.matrixStride);
1005*8975f5c5SAndroid Build Coastguard Worker json->addScalar("IsRowMajorMatrix", blockMemberInfo.isRowMajorMatrix);
1006*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TopLevelArrayStride", blockMemberInfo.topLevelArrayStride);
1007*8975f5c5SAndroid Build Coastguard Worker }
1008*8975f5c5SAndroid Build Coastguard Worker
SerializeBufferVariablesVector(JsonSerializer * json,const std::vector<gl::BufferVariable> & bufferVariables)1009*8975f5c5SAndroid Build Coastguard Worker void SerializeBufferVariablesVector(JsonSerializer *json,
1010*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::BufferVariable> &bufferVariables)
1011*8975f5c5SAndroid Build Coastguard Worker {
1012*8975f5c5SAndroid Build Coastguard Worker for (const gl::BufferVariable &bufferVariable : bufferVariables)
1013*8975f5c5SAndroid Build Coastguard Worker {
1014*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "BufferVariable");
1015*8975f5c5SAndroid Build Coastguard Worker json->addString("Name", bufferVariable.name);
1016*8975f5c5SAndroid Build Coastguard Worker json->addString("MappedName", bufferVariable.mappedName);
1017*8975f5c5SAndroid Build Coastguard Worker
1018*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Type", bufferVariable.pod.type);
1019*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Precision", bufferVariable.pod.precision);
1020*8975f5c5SAndroid Build Coastguard Worker json->addScalar("activeUseBits", bufferVariable.activeShaders().to_ulong());
1021*8975f5c5SAndroid Build Coastguard Worker for (const gl::ShaderType shaderType : gl::AllShaderTypes())
1022*8975f5c5SAndroid Build Coastguard Worker {
1023*8975f5c5SAndroid Build Coastguard Worker json->addScalar(
1024*8975f5c5SAndroid Build Coastguard Worker gl::ShaderTypeToString(shaderType),
1025*8975f5c5SAndroid Build Coastguard Worker bufferVariable.isActive(shaderType) ? bufferVariable.getId(shaderType) : 0);
1026*8975f5c5SAndroid Build Coastguard Worker }
1027*8975f5c5SAndroid Build Coastguard Worker
1028*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BufferIndex", bufferVariable.pod.bufferIndex);
1029*8975f5c5SAndroid Build Coastguard Worker SerializeBlockMemberInfo(json, bufferVariable.pod.blockInfo);
1030*8975f5c5SAndroid Build Coastguard Worker
1031*8975f5c5SAndroid Build Coastguard Worker json->addScalar("TopLevelArraySize", bufferVariable.pod.topLevelArraySize);
1032*8975f5c5SAndroid Build Coastguard Worker json->addScalar("basicTypeElementCount", bufferVariable.pod.basicTypeElementCount);
1033*8975f5c5SAndroid Build Coastguard Worker json->addScalar("isArray", bufferVariable.pod.isArray);
1034*8975f5c5SAndroid Build Coastguard Worker }
1035*8975f5c5SAndroid Build Coastguard Worker }
1036*8975f5c5SAndroid Build Coastguard Worker
SerializeProgramAliasedBindings(JsonSerializer * json,const gl::ProgramAliasedBindings & programAliasedBindings)1037*8975f5c5SAndroid Build Coastguard Worker void SerializeProgramAliasedBindings(JsonSerializer *json,
1038*8975f5c5SAndroid Build Coastguard Worker const gl::ProgramAliasedBindings &programAliasedBindings)
1039*8975f5c5SAndroid Build Coastguard Worker {
1040*8975f5c5SAndroid Build Coastguard Worker for (const auto &programAliasedBinding : programAliasedBindings)
1041*8975f5c5SAndroid Build Coastguard Worker {
1042*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, programAliasedBinding.first);
1043*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Location", programAliasedBinding.second.location);
1044*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Aliased", programAliasedBinding.second.aliased);
1045*8975f5c5SAndroid Build Coastguard Worker }
1046*8975f5c5SAndroid Build Coastguard Worker }
1047*8975f5c5SAndroid Build Coastguard Worker
SerializeProgramState(JsonSerializer * json,const gl::ProgramState & programState)1048*8975f5c5SAndroid Build Coastguard Worker void SerializeProgramState(JsonSerializer *json, const gl::ProgramState &programState)
1049*8975f5c5SAndroid Build Coastguard Worker {
1050*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", programState.getLabel());
1051*8975f5c5SAndroid Build Coastguard Worker json->addVectorOfStrings("TransformFeedbackVaryingNames",
1052*8975f5c5SAndroid Build Coastguard Worker programState.getTransformFeedbackVaryingNames());
1053*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BinaryRetrieveableHint", programState.hasBinaryRetrieveableHint());
1054*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Separable", programState.isSeparable());
1055*8975f5c5SAndroid Build Coastguard Worker SerializeProgramAliasedBindings(json, programState.getUniformLocationBindings());
1056*8975f5c5SAndroid Build Coastguard Worker
1057*8975f5c5SAndroid Build Coastguard Worker const gl::ProgramExecutable &executable = programState.getExecutable();
1058*8975f5c5SAndroid Build Coastguard Worker
1059*8975f5c5SAndroid Build Coastguard Worker SerializeWorkGroupSize(json, executable.getComputeShaderLocalSize());
1060*8975f5c5SAndroid Build Coastguard Worker SerializeUniformIndexToBufferBinding(
1061*8975f5c5SAndroid Build Coastguard Worker json, executable.getUniformBlockIndexToBufferBindingForCapture());
1062*8975f5c5SAndroid Build Coastguard Worker SerializeVariableLocationsVector(json, "UniformLocations", executable.getUniformLocations());
1063*8975f5c5SAndroid Build Coastguard Worker SerializeBufferVariablesVector(json, executable.getBufferVariables());
1064*8975f5c5SAndroid Build Coastguard Worker SerializeRange(json, executable.getAtomicCounterUniformRange());
1065*8975f5c5SAndroid Build Coastguard Worker SerializeVariableLocationsVector(json, "SecondaryOutputLocations",
1066*8975f5c5SAndroid Build Coastguard Worker executable.getSecondaryOutputLocations());
1067*8975f5c5SAndroid Build Coastguard Worker json->addScalar("NumViews", executable.getNumViews());
1068*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DrawIDLocation", executable.getDrawIDLocation());
1069*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BaseVertexLocation", executable.getBaseVertexLocation());
1070*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BaseInstanceLocation", executable.getBaseInstanceLocation());
1071*8975f5c5SAndroid Build Coastguard Worker }
1072*8975f5c5SAndroid Build Coastguard Worker
SerializeProgramBindings(JsonSerializer * json,const gl::ProgramBindings & programBindings)1073*8975f5c5SAndroid Build Coastguard Worker void SerializeProgramBindings(JsonSerializer *json, const gl::ProgramBindings &programBindings)
1074*8975f5c5SAndroid Build Coastguard Worker {
1075*8975f5c5SAndroid Build Coastguard Worker for (const auto &programBinding : programBindings)
1076*8975f5c5SAndroid Build Coastguard Worker {
1077*8975f5c5SAndroid Build Coastguard Worker json->addScalar(programBinding.first, programBinding.second);
1078*8975f5c5SAndroid Build Coastguard Worker }
1079*8975f5c5SAndroid Build Coastguard Worker }
1080*8975f5c5SAndroid Build Coastguard Worker
1081*8975f5c5SAndroid Build Coastguard Worker template <typename T>
SerializeUniformData(JsonSerializer * json,const gl::Context * context,const gl::ProgramExecutable & executable,gl::UniformLocation loc,GLenum type,GLint size,void (gl::ProgramExecutable::* getFunc)(const gl::Context *,gl::UniformLocation,T *)const)1082*8975f5c5SAndroid Build Coastguard Worker void SerializeUniformData(JsonSerializer *json,
1083*8975f5c5SAndroid Build Coastguard Worker const gl::Context *context,
1084*8975f5c5SAndroid Build Coastguard Worker const gl::ProgramExecutable &executable,
1085*8975f5c5SAndroid Build Coastguard Worker gl::UniformLocation loc,
1086*8975f5c5SAndroid Build Coastguard Worker GLenum type,
1087*8975f5c5SAndroid Build Coastguard Worker GLint size,
1088*8975f5c5SAndroid Build Coastguard Worker void (gl::ProgramExecutable::*getFunc)(const gl::Context *,
1089*8975f5c5SAndroid Build Coastguard Worker gl::UniformLocation,
1090*8975f5c5SAndroid Build Coastguard Worker T *) const)
1091*8975f5c5SAndroid Build Coastguard Worker {
1092*8975f5c5SAndroid Build Coastguard Worker std::vector<T> uniformData(gl::VariableComponentCount(type) * size, 0);
1093*8975f5c5SAndroid Build Coastguard Worker (executable.*getFunc)(context, loc, uniformData.data());
1094*8975f5c5SAndroid Build Coastguard Worker json->addVector("Data", uniformData);
1095*8975f5c5SAndroid Build Coastguard Worker }
1096*8975f5c5SAndroid Build Coastguard Worker
SerializeProgram(JsonSerializer * json,const gl::Context * context,GLuint id,gl::Program * program)1097*8975f5c5SAndroid Build Coastguard Worker void SerializeProgram(JsonSerializer *json,
1098*8975f5c5SAndroid Build Coastguard Worker const gl::Context *context,
1099*8975f5c5SAndroid Build Coastguard Worker GLuint id,
1100*8975f5c5SAndroid Build Coastguard Worker gl::Program *program)
1101*8975f5c5SAndroid Build Coastguard Worker {
1102*8975f5c5SAndroid Build Coastguard Worker // Ensure deterministic link.
1103*8975f5c5SAndroid Build Coastguard Worker program->resolveLink(context);
1104*8975f5c5SAndroid Build Coastguard Worker
1105*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Program", id);
1106*8975f5c5SAndroid Build Coastguard Worker
1107*8975f5c5SAndroid Build Coastguard Worker std::vector<GLint> shaderHandles;
1108*8975f5c5SAndroid Build Coastguard Worker for (gl::ShaderType shaderType : gl::AllShaderTypes())
1109*8975f5c5SAndroid Build Coastguard Worker {
1110*8975f5c5SAndroid Build Coastguard Worker gl::Shader *shader = program->getAttachedShader(shaderType);
1111*8975f5c5SAndroid Build Coastguard Worker shaderHandles.push_back(shader ? shader->getHandle().value : 0);
1112*8975f5c5SAndroid Build Coastguard Worker }
1113*8975f5c5SAndroid Build Coastguard Worker json->addVector("Handle", shaderHandles);
1114*8975f5c5SAndroid Build Coastguard Worker
1115*8975f5c5SAndroid Build Coastguard Worker SerializeProgramState(json, program->getState());
1116*8975f5c5SAndroid Build Coastguard Worker json->addScalar("IsValidated", program->isValidated());
1117*8975f5c5SAndroid Build Coastguard Worker SerializeProgramBindings(json, program->getAttributeBindings());
1118*8975f5c5SAndroid Build Coastguard Worker SerializeProgramAliasedBindings(json, program->getFragmentOutputLocations());
1119*8975f5c5SAndroid Build Coastguard Worker SerializeProgramAliasedBindings(json, program->getFragmentOutputIndexes());
1120*8975f5c5SAndroid Build Coastguard Worker json->addScalar("IsLinked", program->isLinked());
1121*8975f5c5SAndroid Build Coastguard Worker json->addScalar("IsFlaggedForDeletion", program->isFlaggedForDeletion());
1122*8975f5c5SAndroid Build Coastguard Worker // TODO: implement MEC context validation only after all contexts have been initialized
1123*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42266488
1124*8975f5c5SAndroid Build Coastguard Worker // json->addScalar("RefCount", program->getRefCount());
1125*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ID", program->id().value);
1126*8975f5c5SAndroid Build Coastguard Worker
1127*8975f5c5SAndroid Build Coastguard Worker const gl::ProgramExecutable &executable = program->getExecutable();
1128*8975f5c5SAndroid Build Coastguard Worker
1129*8975f5c5SAndroid Build Coastguard Worker // Serialize uniforms.
1130*8975f5c5SAndroid Build Coastguard Worker {
1131*8975f5c5SAndroid Build Coastguard Worker GroupScope uniformsGroup(json, "Uniforms");
1132*8975f5c5SAndroid Build Coastguard Worker GLint uniformCount = static_cast<GLint>(executable.getUniforms().size());
1133*8975f5c5SAndroid Build Coastguard Worker for (int uniformIndex = 0; uniformIndex < uniformCount; ++uniformIndex)
1134*8975f5c5SAndroid Build Coastguard Worker {
1135*8975f5c5SAndroid Build Coastguard Worker GroupScope uniformGroup(json, "Uniform", uniformIndex);
1136*8975f5c5SAndroid Build Coastguard Worker
1137*8975f5c5SAndroid Build Coastguard Worker constexpr GLsizei kMaxUniformNameLen = 1024;
1138*8975f5c5SAndroid Build Coastguard Worker char uniformName[kMaxUniformNameLen] = {};
1139*8975f5c5SAndroid Build Coastguard Worker GLint size = 0;
1140*8975f5c5SAndroid Build Coastguard Worker GLenum type = GL_NONE;
1141*8975f5c5SAndroid Build Coastguard Worker executable.getActiveUniform(uniformIndex, kMaxUniformNameLen, nullptr, &size, &type,
1142*8975f5c5SAndroid Build Coastguard Worker uniformName);
1143*8975f5c5SAndroid Build Coastguard Worker
1144*8975f5c5SAndroid Build Coastguard Worker json->addCString("Name", uniformName);
1145*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Size", size);
1146*8975f5c5SAndroid Build Coastguard Worker json->addCString("Type", gl::GLenumToString(gl::GLESEnum::AttributeType, type));
1147*8975f5c5SAndroid Build Coastguard Worker
1148*8975f5c5SAndroid Build Coastguard Worker const gl::UniformLocation loc = executable.getUniformLocation(uniformName);
1149*8975f5c5SAndroid Build Coastguard Worker
1150*8975f5c5SAndroid Build Coastguard Worker if (loc.value == -1)
1151*8975f5c5SAndroid Build Coastguard Worker {
1152*8975f5c5SAndroid Build Coastguard Worker continue;
1153*8975f5c5SAndroid Build Coastguard Worker }
1154*8975f5c5SAndroid Build Coastguard Worker
1155*8975f5c5SAndroid Build Coastguard Worker switch (gl::VariableComponentType(type))
1156*8975f5c5SAndroid Build Coastguard Worker {
1157*8975f5c5SAndroid Build Coastguard Worker case GL_FLOAT:
1158*8975f5c5SAndroid Build Coastguard Worker {
1159*8975f5c5SAndroid Build Coastguard Worker SerializeUniformData<GLfloat>(json, context, executable, loc, type, size,
1160*8975f5c5SAndroid Build Coastguard Worker &gl::ProgramExecutable::getUniformfv);
1161*8975f5c5SAndroid Build Coastguard Worker break;
1162*8975f5c5SAndroid Build Coastguard Worker }
1163*8975f5c5SAndroid Build Coastguard Worker case GL_BOOL:
1164*8975f5c5SAndroid Build Coastguard Worker case GL_INT:
1165*8975f5c5SAndroid Build Coastguard Worker {
1166*8975f5c5SAndroid Build Coastguard Worker SerializeUniformData<GLint>(json, context, executable, loc, type, size,
1167*8975f5c5SAndroid Build Coastguard Worker &gl::ProgramExecutable::getUniformiv);
1168*8975f5c5SAndroid Build Coastguard Worker break;
1169*8975f5c5SAndroid Build Coastguard Worker }
1170*8975f5c5SAndroid Build Coastguard Worker case GL_UNSIGNED_INT:
1171*8975f5c5SAndroid Build Coastguard Worker {
1172*8975f5c5SAndroid Build Coastguard Worker SerializeUniformData<GLuint>(json, context, executable, loc, type, size,
1173*8975f5c5SAndroid Build Coastguard Worker &gl::ProgramExecutable::getUniformuiv);
1174*8975f5c5SAndroid Build Coastguard Worker break;
1175*8975f5c5SAndroid Build Coastguard Worker }
1176*8975f5c5SAndroid Build Coastguard Worker default:
1177*8975f5c5SAndroid Build Coastguard Worker UNREACHABLE();
1178*8975f5c5SAndroid Build Coastguard Worker break;
1179*8975f5c5SAndroid Build Coastguard Worker }
1180*8975f5c5SAndroid Build Coastguard Worker }
1181*8975f5c5SAndroid Build Coastguard Worker }
1182*8975f5c5SAndroid Build Coastguard Worker }
1183*8975f5c5SAndroid Build Coastguard Worker
SerializeImageDesc(JsonSerializer * json,size_t descIndex,const gl::ImageDesc & imageDesc)1184*8975f5c5SAndroid Build Coastguard Worker void SerializeImageDesc(JsonSerializer *json, size_t descIndex, const gl::ImageDesc &imageDesc)
1185*8975f5c5SAndroid Build Coastguard Worker {
1186*8975f5c5SAndroid Build Coastguard Worker // Skip serializing unspecified image levels.
1187*8975f5c5SAndroid Build Coastguard Worker if (imageDesc.size.empty())
1188*8975f5c5SAndroid Build Coastguard Worker {
1189*8975f5c5SAndroid Build Coastguard Worker return;
1190*8975f5c5SAndroid Build Coastguard Worker }
1191*8975f5c5SAndroid Build Coastguard Worker
1192*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "ImageDesc", static_cast<int>(descIndex));
1193*8975f5c5SAndroid Build Coastguard Worker SerializeExtents(json, imageDesc.size);
1194*8975f5c5SAndroid Build Coastguard Worker SerializeGLFormat(json, imageDesc.format);
1195*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Samples", imageDesc.samples);
1196*8975f5c5SAndroid Build Coastguard Worker json->addScalar("FixesSampleLocations", imageDesc.fixedSampleLocations);
1197*8975f5c5SAndroid Build Coastguard Worker json->addCString("InitState", InitStateToString(imageDesc.initState));
1198*8975f5c5SAndroid Build Coastguard Worker }
1199*8975f5c5SAndroid Build Coastguard Worker
SerializeTextureState(JsonSerializer * json,const gl::TextureState & textureState)1200*8975f5c5SAndroid Build Coastguard Worker void SerializeTextureState(JsonSerializer *json, const gl::TextureState &textureState)
1201*8975f5c5SAndroid Build Coastguard Worker {
1202*8975f5c5SAndroid Build Coastguard Worker json->addString("Type", ToString(textureState.getType()));
1203*8975f5c5SAndroid Build Coastguard Worker SerializeSwizzleState(json, textureState.getSwizzleState());
1204*8975f5c5SAndroid Build Coastguard Worker {
1205*8975f5c5SAndroid Build Coastguard Worker GroupScope samplerStateGroup(json, "SamplerState");
1206*8975f5c5SAndroid Build Coastguard Worker SerializeSamplerState(json, textureState.getSamplerState());
1207*8975f5c5SAndroid Build Coastguard Worker }
1208*8975f5c5SAndroid Build Coastguard Worker json->addCString("SRGB", SrgbOverrideToString(textureState.getSRGBOverride()));
1209*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BaseLevel", textureState.getBaseLevel());
1210*8975f5c5SAndroid Build Coastguard Worker json->addScalar("MaxLevel", textureState.getMaxLevel());
1211*8975f5c5SAndroid Build Coastguard Worker json->addScalar("DepthStencilTextureMode", textureState.getDepthStencilTextureMode());
1212*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BeenBoundAsImage", textureState.hasBeenBoundAsImage());
1213*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ImmutableFormat", textureState.getImmutableFormat());
1214*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ImmutableLevels", textureState.getImmutableLevels());
1215*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Usage", textureState.getUsage());
1216*8975f5c5SAndroid Build Coastguard Worker SerializeRectangle(json, "Crop", textureState.getCrop());
1217*8975f5c5SAndroid Build Coastguard Worker json->addScalar("GenerateMipmapHint", textureState.getGenerateMipmapHint());
1218*8975f5c5SAndroid Build Coastguard Worker json->addCString("InitState", InitStateToString(textureState.getInitState()));
1219*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BoundBufferID", textureState.getBuffer().id().value);
1220*8975f5c5SAndroid Build Coastguard Worker
1221*8975f5c5SAndroid Build Coastguard Worker {
1222*8975f5c5SAndroid Build Coastguard Worker GroupScope descGroup(json, "ImageDescs");
1223*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::ImageDesc> &imageDescs = textureState.getImageDescs();
1224*8975f5c5SAndroid Build Coastguard Worker for (size_t descIndex = 0; descIndex < imageDescs.size(); ++descIndex)
1225*8975f5c5SAndroid Build Coastguard Worker {
1226*8975f5c5SAndroid Build Coastguard Worker SerializeImageDesc(json, descIndex, imageDescs[descIndex]);
1227*8975f5c5SAndroid Build Coastguard Worker }
1228*8975f5c5SAndroid Build Coastguard Worker }
1229*8975f5c5SAndroid Build Coastguard Worker }
1230*8975f5c5SAndroid Build Coastguard Worker
SerializeTextureData(JsonSerializer * json,const gl::Context * context,gl::Texture * texture,ScratchBuffer * scratchBuffer)1231*8975f5c5SAndroid Build Coastguard Worker Result SerializeTextureData(JsonSerializer *json,
1232*8975f5c5SAndroid Build Coastguard Worker const gl::Context *context,
1233*8975f5c5SAndroid Build Coastguard Worker gl::Texture *texture,
1234*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer)
1235*8975f5c5SAndroid Build Coastguard Worker {
1236*8975f5c5SAndroid Build Coastguard Worker gl::ImageIndexIterator imageIter = gl::ImageIndexIterator::MakeGeneric(
1237*8975f5c5SAndroid Build Coastguard Worker texture->getType(), texture->getBaseLevel(), texture->getMipmapMaxLevel() + 1,
1238*8975f5c5SAndroid Build Coastguard Worker gl::ImageIndex::kEntireLevel, gl::ImageIndex::kEntireLevel);
1239*8975f5c5SAndroid Build Coastguard Worker while (imageIter.hasNext())
1240*8975f5c5SAndroid Build Coastguard Worker {
1241*8975f5c5SAndroid Build Coastguard Worker gl::ImageIndex index = imageIter.next();
1242*8975f5c5SAndroid Build Coastguard Worker
1243*8975f5c5SAndroid Build Coastguard Worker // Skip serializing level data if the level index is out of range
1244*8975f5c5SAndroid Build Coastguard Worker GLuint levelIndex = index.getLevelIndex();
1245*8975f5c5SAndroid Build Coastguard Worker if (levelIndex > texture->getMipmapMaxLevel() || levelIndex < texture->getBaseLevel())
1246*8975f5c5SAndroid Build Coastguard Worker continue;
1247*8975f5c5SAndroid Build Coastguard Worker
1248*8975f5c5SAndroid Build Coastguard Worker const gl::ImageDesc &desc = texture->getTextureState().getImageDesc(index);
1249*8975f5c5SAndroid Build Coastguard Worker
1250*8975f5c5SAndroid Build Coastguard Worker if (desc.size.empty())
1251*8975f5c5SAndroid Build Coastguard Worker continue;
1252*8975f5c5SAndroid Build Coastguard Worker
1253*8975f5c5SAndroid Build Coastguard Worker const gl::InternalFormat &format = *desc.format.info;
1254*8975f5c5SAndroid Build Coastguard Worker
1255*8975f5c5SAndroid Build Coastguard Worker // Check for supported textures
1256*8975f5c5SAndroid Build Coastguard Worker ASSERT(index.getType() == gl::TextureType::_2D || index.getType() == gl::TextureType::_3D ||
1257*8975f5c5SAndroid Build Coastguard Worker index.getType() == gl::TextureType::_2DArray ||
1258*8975f5c5SAndroid Build Coastguard Worker index.getType() == gl::TextureType::CubeMap ||
1259*8975f5c5SAndroid Build Coastguard Worker index.getType() == gl::TextureType::CubeMapArray ||
1260*8975f5c5SAndroid Build Coastguard Worker index.getType() == gl::TextureType::_2DMultisampleArray ||
1261*8975f5c5SAndroid Build Coastguard Worker index.getType() == gl::TextureType::_2DMultisample ||
1262*8975f5c5SAndroid Build Coastguard Worker index.getType() == gl::TextureType::External);
1263*8975f5c5SAndroid Build Coastguard Worker
1264*8975f5c5SAndroid Build Coastguard Worker GLenum glFormat = format.format;
1265*8975f5c5SAndroid Build Coastguard Worker GLenum glType = format.type;
1266*8975f5c5SAndroid Build Coastguard Worker
1267*8975f5c5SAndroid Build Coastguard Worker const gl::Extents size(desc.size.width, desc.size.height, desc.size.depth);
1268*8975f5c5SAndroid Build Coastguard Worker gl::PixelPackState packState;
1269*8975f5c5SAndroid Build Coastguard Worker packState.alignment = 1;
1270*8975f5c5SAndroid Build Coastguard Worker
1271*8975f5c5SAndroid Build Coastguard Worker GLuint endByte = 0;
1272*8975f5c5SAndroid Build Coastguard Worker bool unpackSize = format.computePackUnpackEndByte(glType, size, packState, true, &endByte);
1273*8975f5c5SAndroid Build Coastguard Worker ASSERT(unpackSize);
1274*8975f5c5SAndroid Build Coastguard Worker MemoryBuffer *texelsPtr = nullptr;
1275*8975f5c5SAndroid Build Coastguard Worker ANGLE_CHECK_GL_ALLOC(const_cast<gl::Context *>(context),
1276*8975f5c5SAndroid Build Coastguard Worker scratchBuffer->getInitialized(endByte, &texelsPtr, 0));
1277*8975f5c5SAndroid Build Coastguard Worker
1278*8975f5c5SAndroid Build Coastguard Worker std::stringstream label;
1279*8975f5c5SAndroid Build Coastguard Worker
1280*8975f5c5SAndroid Build Coastguard Worker label << "Texels-Level" << index.getLevelIndex();
1281*8975f5c5SAndroid Build Coastguard Worker if (imageIter.current().hasLayer())
1282*8975f5c5SAndroid Build Coastguard Worker {
1283*8975f5c5SAndroid Build Coastguard Worker label << "-Layer" << imageIter.current().getLayerIndex();
1284*8975f5c5SAndroid Build Coastguard Worker }
1285*8975f5c5SAndroid Build Coastguard Worker
1286*8975f5c5SAndroid Build Coastguard Worker if (texture->getState().getInitState() == gl::InitState::Initialized)
1287*8975f5c5SAndroid Build Coastguard Worker {
1288*8975f5c5SAndroid Build Coastguard Worker if (format.compressed)
1289*8975f5c5SAndroid Build Coastguard Worker {
1290*8975f5c5SAndroid Build Coastguard Worker // TODO: Read back compressed data. http://anglebug.com/42264702
1291*8975f5c5SAndroid Build Coastguard Worker json->addCString(label.str(), "compressed texel data");
1292*8975f5c5SAndroid Build Coastguard Worker }
1293*8975f5c5SAndroid Build Coastguard Worker else
1294*8975f5c5SAndroid Build Coastguard Worker {
1295*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(texture->getTexImage(context, packState, nullptr, index.getTarget(),
1296*8975f5c5SAndroid Build Coastguard Worker index.getLevelIndex(), glFormat, glType,
1297*8975f5c5SAndroid Build Coastguard Worker texelsPtr->data()));
1298*8975f5c5SAndroid Build Coastguard Worker json->addBlob(label.str(), texelsPtr->data(), texelsPtr->size());
1299*8975f5c5SAndroid Build Coastguard Worker }
1300*8975f5c5SAndroid Build Coastguard Worker }
1301*8975f5c5SAndroid Build Coastguard Worker else
1302*8975f5c5SAndroid Build Coastguard Worker {
1303*8975f5c5SAndroid Build Coastguard Worker json->addCString(label.str(), "not initialized");
1304*8975f5c5SAndroid Build Coastguard Worker }
1305*8975f5c5SAndroid Build Coastguard Worker }
1306*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
1307*8975f5c5SAndroid Build Coastguard Worker }
1308*8975f5c5SAndroid Build Coastguard Worker
SerializeTexture(const gl::Context * context,JsonSerializer * json,ScratchBuffer * scratchBuffer,gl::Texture * texture)1309*8975f5c5SAndroid Build Coastguard Worker Result SerializeTexture(const gl::Context *context,
1310*8975f5c5SAndroid Build Coastguard Worker JsonSerializer *json,
1311*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer *scratchBuffer,
1312*8975f5c5SAndroid Build Coastguard Worker gl::Texture *texture)
1313*8975f5c5SAndroid Build Coastguard Worker {
1314*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "Texture", texture->getId());
1315*8975f5c5SAndroid Build Coastguard Worker
1316*8975f5c5SAndroid Build Coastguard Worker // We serialize texture data first, to force the texture state to be initialized.
1317*8975f5c5SAndroid Build Coastguard Worker if (texture->getType() != gl::TextureType::Buffer)
1318*8975f5c5SAndroid Build Coastguard Worker {
1319*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeTextureData(json, context, texture, scratchBuffer));
1320*8975f5c5SAndroid Build Coastguard Worker }
1321*8975f5c5SAndroid Build Coastguard Worker
1322*8975f5c5SAndroid Build Coastguard Worker SerializeTextureState(json, texture->getState());
1323*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", texture->getLabel());
1324*8975f5c5SAndroid Build Coastguard Worker // FrameCapture can not serialize mBoundSurface and mBoundStream
1325*8975f5c5SAndroid Build Coastguard Worker // because they are likely to change with each run
1326*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
1327*8975f5c5SAndroid Build Coastguard Worker }
1328*8975f5c5SAndroid Build Coastguard Worker
SerializeVertexAttributeVector(JsonSerializer * json,const std::vector<gl::VertexAttribute> & vertexAttributes)1329*8975f5c5SAndroid Build Coastguard Worker void SerializeVertexAttributeVector(JsonSerializer *json,
1330*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::VertexAttribute> &vertexAttributes)
1331*8975f5c5SAndroid Build Coastguard Worker {
1332*8975f5c5SAndroid Build Coastguard Worker for (size_t attribIndex = 0; attribIndex < vertexAttributes.size(); ++attribIndex)
1333*8975f5c5SAndroid Build Coastguard Worker {
1334*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "VertexAttribute", static_cast<int>(attribIndex));
1335*8975f5c5SAndroid Build Coastguard Worker const gl::VertexAttribute &vertexAttribute = vertexAttributes[attribIndex];
1336*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BindingIndex", vertexAttribute.bindingIndex);
1337*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Enabled", vertexAttribute.enabled);
1338*8975f5c5SAndroid Build Coastguard Worker ASSERT(vertexAttribute.format);
1339*8975f5c5SAndroid Build Coastguard Worker SerializeANGLEFormat(json, vertexAttribute.format);
1340*8975f5c5SAndroid Build Coastguard Worker json->addScalar("RelativeOffset", vertexAttribute.relativeOffset);
1341*8975f5c5SAndroid Build Coastguard Worker json->addScalar("VertexAttribArrayStride", vertexAttribute.vertexAttribArrayStride);
1342*8975f5c5SAndroid Build Coastguard Worker }
1343*8975f5c5SAndroid Build Coastguard Worker }
1344*8975f5c5SAndroid Build Coastguard Worker
SerializeVertexBindingsVector(JsonSerializer * json,const std::vector<gl::VertexBinding> & vertexBindings)1345*8975f5c5SAndroid Build Coastguard Worker void SerializeVertexBindingsVector(JsonSerializer *json,
1346*8975f5c5SAndroid Build Coastguard Worker const std::vector<gl::VertexBinding> &vertexBindings)
1347*8975f5c5SAndroid Build Coastguard Worker {
1348*8975f5c5SAndroid Build Coastguard Worker for (size_t bindingIndex = 0; bindingIndex < vertexBindings.size(); ++bindingIndex)
1349*8975f5c5SAndroid Build Coastguard Worker {
1350*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "VertexBinding", static_cast<int>(bindingIndex));
1351*8975f5c5SAndroid Build Coastguard Worker const gl::VertexBinding &vertexBinding = vertexBindings[bindingIndex];
1352*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Stride", vertexBinding.getStride());
1353*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Divisor", vertexBinding.getDivisor());
1354*8975f5c5SAndroid Build Coastguard Worker json->addScalar("Offset", vertexBinding.getOffset());
1355*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BufferID", vertexBinding.getBuffer().id().value);
1356*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BoundAttributesMask", vertexBinding.getBoundAttributesMask().to_ulong());
1357*8975f5c5SAndroid Build Coastguard Worker }
1358*8975f5c5SAndroid Build Coastguard Worker }
1359*8975f5c5SAndroid Build Coastguard Worker
SerializeVertexArrayState(JsonSerializer * json,const gl::VertexArrayState & vertexArrayState)1360*8975f5c5SAndroid Build Coastguard Worker void SerializeVertexArrayState(JsonSerializer *json, const gl::VertexArrayState &vertexArrayState)
1361*8975f5c5SAndroid Build Coastguard Worker {
1362*8975f5c5SAndroid Build Coastguard Worker json->addString("Label", vertexArrayState.getLabel());
1363*8975f5c5SAndroid Build Coastguard Worker SerializeVertexAttributeVector(json, vertexArrayState.getVertexAttributes());
1364*8975f5c5SAndroid Build Coastguard Worker if (vertexArrayState.getElementArrayBuffer())
1365*8975f5c5SAndroid Build Coastguard Worker {
1366*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ElementArrayBufferID",
1367*8975f5c5SAndroid Build Coastguard Worker vertexArrayState.getElementArrayBuffer()->id().value);
1368*8975f5c5SAndroid Build Coastguard Worker }
1369*8975f5c5SAndroid Build Coastguard Worker else
1370*8975f5c5SAndroid Build Coastguard Worker {
1371*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ElementArrayBufferID", 0);
1372*8975f5c5SAndroid Build Coastguard Worker }
1373*8975f5c5SAndroid Build Coastguard Worker SerializeVertexBindingsVector(json, vertexArrayState.getVertexBindings());
1374*8975f5c5SAndroid Build Coastguard Worker json->addScalar("EnabledAttributesMask",
1375*8975f5c5SAndroid Build Coastguard Worker vertexArrayState.getEnabledAttributesMask().to_ulong());
1376*8975f5c5SAndroid Build Coastguard Worker json->addScalar("VertexAttributesTypeMask",
1377*8975f5c5SAndroid Build Coastguard Worker vertexArrayState.getVertexAttributesTypeMask().to_ulong());
1378*8975f5c5SAndroid Build Coastguard Worker json->addScalar("ClientMemoryAttribsMask",
1379*8975f5c5SAndroid Build Coastguard Worker vertexArrayState.getClientMemoryAttribsMask().to_ulong());
1380*8975f5c5SAndroid Build Coastguard Worker json->addScalar("NullPointerClientMemoryAttribsMask",
1381*8975f5c5SAndroid Build Coastguard Worker vertexArrayState.getNullPointerClientMemoryAttribsMask().to_ulong());
1382*8975f5c5SAndroid Build Coastguard Worker }
1383*8975f5c5SAndroid Build Coastguard Worker
SerializeVertexArray(JsonSerializer * json,gl::VertexArray * vertexArray)1384*8975f5c5SAndroid Build Coastguard Worker void SerializeVertexArray(JsonSerializer *json, gl::VertexArray *vertexArray)
1385*8975f5c5SAndroid Build Coastguard Worker {
1386*8975f5c5SAndroid Build Coastguard Worker GroupScope group(json, "VertexArray", vertexArray->id().value);
1387*8975f5c5SAndroid Build Coastguard Worker SerializeVertexArrayState(json, vertexArray->getState());
1388*8975f5c5SAndroid Build Coastguard Worker json->addScalar("BufferAccessValidationEnabled",
1389*8975f5c5SAndroid Build Coastguard Worker vertexArray->isBufferAccessValidationEnabled());
1390*8975f5c5SAndroid Build Coastguard Worker }
1391*8975f5c5SAndroid Build Coastguard Worker
1392*8975f5c5SAndroid Build Coastguard Worker } // namespace
1393*8975f5c5SAndroid Build Coastguard Worker
SerializeContextToString(const gl::Context * context,std::string * stringOut)1394*8975f5c5SAndroid Build Coastguard Worker Result SerializeContextToString(const gl::Context *context, std::string *stringOut)
1395*8975f5c5SAndroid Build Coastguard Worker {
1396*8975f5c5SAndroid Build Coastguard Worker JsonSerializer json;
1397*8975f5c5SAndroid Build Coastguard Worker json.startGroup("Context");
1398*8975f5c5SAndroid Build Coastguard Worker
1399*8975f5c5SAndroid Build Coastguard Worker SerializeContextState(&json, context->getState());
1400*8975f5c5SAndroid Build Coastguard Worker ScratchBuffer scratchBuffer(1);
1401*8975f5c5SAndroid Build Coastguard Worker {
1402*8975f5c5SAndroid Build Coastguard Worker const gl::FramebufferManager &framebufferManager =
1403*8975f5c5SAndroid Build Coastguard Worker context->getState().getFramebufferManagerForCapture();
1404*8975f5c5SAndroid Build Coastguard Worker GroupScope framebufferGroup(&json, "FramebufferManager");
1405*8975f5c5SAndroid Build Coastguard Worker for (const auto &framebuffer :
1406*8975f5c5SAndroid Build Coastguard Worker gl::UnsafeResourceMapIter(framebufferManager.getResourcesForCapture()))
1407*8975f5c5SAndroid Build Coastguard Worker {
1408*8975f5c5SAndroid Build Coastguard Worker gl::Framebuffer *framebufferPtr = framebuffer.second;
1409*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeFramebuffer(context, &json, &scratchBuffer, framebufferPtr));
1410*8975f5c5SAndroid Build Coastguard Worker }
1411*8975f5c5SAndroid Build Coastguard Worker }
1412*8975f5c5SAndroid Build Coastguard Worker {
1413*8975f5c5SAndroid Build Coastguard Worker const gl::BufferManager &bufferManager = context->getState().getBufferManagerForCapture();
1414*8975f5c5SAndroid Build Coastguard Worker GroupScope framebufferGroup(&json, "BufferManager");
1415*8975f5c5SAndroid Build Coastguard Worker for (const auto &buffer : gl::UnsafeResourceMapIter(bufferManager.getResourcesForCapture()))
1416*8975f5c5SAndroid Build Coastguard Worker {
1417*8975f5c5SAndroid Build Coastguard Worker gl::Buffer *bufferPtr = buffer.second;
1418*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeBuffer(context, &json, &scratchBuffer, bufferPtr));
1419*8975f5c5SAndroid Build Coastguard Worker }
1420*8975f5c5SAndroid Build Coastguard Worker }
1421*8975f5c5SAndroid Build Coastguard Worker {
1422*8975f5c5SAndroid Build Coastguard Worker const gl::SamplerManager &samplerManager =
1423*8975f5c5SAndroid Build Coastguard Worker context->getState().getSamplerManagerForCapture();
1424*8975f5c5SAndroid Build Coastguard Worker GroupScope samplerGroup(&json, "SamplerManager");
1425*8975f5c5SAndroid Build Coastguard Worker for (const auto &sampler :
1426*8975f5c5SAndroid Build Coastguard Worker gl::UnsafeResourceMapIter(samplerManager.getResourcesForCapture()))
1427*8975f5c5SAndroid Build Coastguard Worker {
1428*8975f5c5SAndroid Build Coastguard Worker gl::Sampler *samplerPtr = sampler.second;
1429*8975f5c5SAndroid Build Coastguard Worker SerializeSampler(&json, samplerPtr);
1430*8975f5c5SAndroid Build Coastguard Worker }
1431*8975f5c5SAndroid Build Coastguard Worker }
1432*8975f5c5SAndroid Build Coastguard Worker {
1433*8975f5c5SAndroid Build Coastguard Worker const gl::RenderbufferManager &renderbufferManager =
1434*8975f5c5SAndroid Build Coastguard Worker context->getState().getRenderbufferManagerForCapture();
1435*8975f5c5SAndroid Build Coastguard Worker GroupScope renderbufferGroup(&json, "RenderbufferManager");
1436*8975f5c5SAndroid Build Coastguard Worker for (const auto &renderbuffer :
1437*8975f5c5SAndroid Build Coastguard Worker gl::UnsafeResourceMapIter(renderbufferManager.getResourcesForCapture()))
1438*8975f5c5SAndroid Build Coastguard Worker {
1439*8975f5c5SAndroid Build Coastguard Worker gl::Renderbuffer *renderbufferPtr = renderbuffer.second;
1440*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeRenderbuffer(context, &json, &scratchBuffer, renderbufferPtr));
1441*8975f5c5SAndroid Build Coastguard Worker }
1442*8975f5c5SAndroid Build Coastguard Worker }
1443*8975f5c5SAndroid Build Coastguard Worker const gl::ShaderProgramManager &shaderProgramManager =
1444*8975f5c5SAndroid Build Coastguard Worker context->getState().getShaderProgramManagerForCapture();
1445*8975f5c5SAndroid Build Coastguard Worker {
1446*8975f5c5SAndroid Build Coastguard Worker const gl::ResourceMap<gl::Shader, gl::ShaderProgramID> &shaderManager =
1447*8975f5c5SAndroid Build Coastguard Worker shaderProgramManager.getShadersForCapture();
1448*8975f5c5SAndroid Build Coastguard Worker GroupScope shaderGroup(&json, "ShaderManager");
1449*8975f5c5SAndroid Build Coastguard Worker for (const auto &shader : gl::UnsafeResourceMapIter(shaderManager))
1450*8975f5c5SAndroid Build Coastguard Worker {
1451*8975f5c5SAndroid Build Coastguard Worker GLuint id = shader.first;
1452*8975f5c5SAndroid Build Coastguard Worker gl::Shader *shaderPtr = shader.second;
1453*8975f5c5SAndroid Build Coastguard Worker SerializeShader(context, &json, id, shaderPtr);
1454*8975f5c5SAndroid Build Coastguard Worker }
1455*8975f5c5SAndroid Build Coastguard Worker }
1456*8975f5c5SAndroid Build Coastguard Worker {
1457*8975f5c5SAndroid Build Coastguard Worker const gl::ResourceMap<gl::Program, gl::ShaderProgramID> &programManager =
1458*8975f5c5SAndroid Build Coastguard Worker shaderProgramManager.getProgramsForCaptureAndPerf();
1459*8975f5c5SAndroid Build Coastguard Worker GroupScope shaderGroup(&json, "ProgramManager");
1460*8975f5c5SAndroid Build Coastguard Worker for (const auto &program : gl::UnsafeResourceMapIter(programManager))
1461*8975f5c5SAndroid Build Coastguard Worker {
1462*8975f5c5SAndroid Build Coastguard Worker GLuint id = program.first;
1463*8975f5c5SAndroid Build Coastguard Worker gl::Program *programPtr = program.second;
1464*8975f5c5SAndroid Build Coastguard Worker SerializeProgram(&json, context, id, programPtr);
1465*8975f5c5SAndroid Build Coastguard Worker }
1466*8975f5c5SAndroid Build Coastguard Worker }
1467*8975f5c5SAndroid Build Coastguard Worker {
1468*8975f5c5SAndroid Build Coastguard Worker const gl::TextureManager &textureManager =
1469*8975f5c5SAndroid Build Coastguard Worker context->getState().getTextureManagerForCapture();
1470*8975f5c5SAndroid Build Coastguard Worker GroupScope shaderGroup(&json, "TextureManager");
1471*8975f5c5SAndroid Build Coastguard Worker for (const auto &texture :
1472*8975f5c5SAndroid Build Coastguard Worker gl::UnsafeResourceMapIter(textureManager.getResourcesForCapture()))
1473*8975f5c5SAndroid Build Coastguard Worker {
1474*8975f5c5SAndroid Build Coastguard Worker gl::Texture *texturePtr = texture.second;
1475*8975f5c5SAndroid Build Coastguard Worker ANGLE_TRY(SerializeTexture(context, &json, &scratchBuffer, texturePtr));
1476*8975f5c5SAndroid Build Coastguard Worker }
1477*8975f5c5SAndroid Build Coastguard Worker }
1478*8975f5c5SAndroid Build Coastguard Worker {
1479*8975f5c5SAndroid Build Coastguard Worker const gl::VertexArrayMap &vertexArrayMap = context->getVertexArraysForCapture();
1480*8975f5c5SAndroid Build Coastguard Worker GroupScope shaderGroup(&json, "VertexArrayMap");
1481*8975f5c5SAndroid Build Coastguard Worker for (const auto &vertexArray : gl::UnsafeResourceMapIter(vertexArrayMap))
1482*8975f5c5SAndroid Build Coastguard Worker {
1483*8975f5c5SAndroid Build Coastguard Worker gl::VertexArray *vertexArrayPtr = vertexArray.second;
1484*8975f5c5SAndroid Build Coastguard Worker SerializeVertexArray(&json, vertexArrayPtr);
1485*8975f5c5SAndroid Build Coastguard Worker }
1486*8975f5c5SAndroid Build Coastguard Worker }
1487*8975f5c5SAndroid Build Coastguard Worker json.endGroup();
1488*8975f5c5SAndroid Build Coastguard Worker
1489*8975f5c5SAndroid Build Coastguard Worker *stringOut = json.data();
1490*8975f5c5SAndroid Build Coastguard Worker
1491*8975f5c5SAndroid Build Coastguard Worker scratchBuffer.clear();
1492*8975f5c5SAndroid Build Coastguard Worker return Result::Continue;
1493*8975f5c5SAndroid Build Coastguard Worker }
1494*8975f5c5SAndroid Build Coastguard Worker
1495*8975f5c5SAndroid Build Coastguard Worker } // namespace angle
1496