blob: ef048e576c8686bc42382fdd561d5677aa83a95f [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
30#include "loader_platform.h"
31#include "xgl_dispatch_table_helper.h"
32#include "xgl_struct_string_helper_cpp.h"
33#pragma GCC diagnostic ignored "-Wwrite-strings"
34#include "xgl_struct_graphviz_helper.h"
35#pragma GCC diagnostic warning "-Wwrite-strings"
36#include "xgl_struct_size_helper.h"
37#include "draw_state.h"
38#include "layers_config.h"
39// The following is #included again to catch certain OS-specific functions
40// being used:
41#include "loader_platform.h"
42#include "layers_msg.h"
43
44unordered_map<XGL_SAMPLER, SAMPLER_NODE*> sampleMap;
45unordered_map<XGL_IMAGE_VIEW, IMAGE_NODE*> imageMap;
46unordered_map<XGL_BUFFER_VIEW, BUFFER_NODE*> bufferMap;
47unordered_map<XGL_DYNAMIC_STATE_OBJECT, DYNAMIC_STATE_NODE*> dynamicStateMap;
48unordered_map<XGL_PIPELINE, PIPELINE_NODE*> pipelineMap;
49unordered_map<XGL_DESCRIPTOR_REGION, REGION_NODE*> regionMap;
50unordered_map<XGL_DESCRIPTOR_SET, SET_NODE*> setMap;
51unordered_map<XGL_DESCRIPTOR_SET_LAYOUT, LAYOUT_NODE*> layoutMap;
52unordered_map<XGL_CMD_BUFFER, GLOBAL_CB_NODE*> cmdBufferMap;
Tobin Ehlis2464b882015-04-01 08:40:34 -060053unordered_map<XGL_RENDER_PASS, XGL_RENDER_PASS_CREATE_INFO*> renderPassMap;
54unordered_map<XGL_FRAMEBUFFER, XGL_FRAMEBUFFER_CREATE_INFO*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060055
56static XGL_LAYER_DISPATCH_TABLE nextTable;
57static XGL_BASE_LAYER_OBJECT *pCurObj;
58static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
59// TODO : This can be much smarter, using separate locks for separate global data
60static int globalLockInitialized = 0;
61static loader_platform_thread_mutex globalLock;
62#define ALLOC_DEBUG 0
63#if ALLOC_DEBUG
64static uint64_t g_alloc_count = 0;
65static uint64_t g_free_count = 0;
66#endif
67#define MAX_TID 513
68static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
69static uint32_t g_maxTID = 0;
70// Map actual TID to an index value and return that index
71// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
72static uint32_t getTIDIndex() {
73 loader_platform_thread_id tid = loader_platform_get_thread_id();
74 for (uint32_t i = 0; i < g_maxTID; i++) {
75 if (tid == g_tidMapping[i])
76 return i;
77 }
78 // Don't yet have mapping, set it and return newly set index
79 uint32_t retVal = (uint32_t) g_maxTID;
80 g_tidMapping[g_maxTID++] = tid;
81 assert(g_maxTID < MAX_TID);
82 return retVal;
83}
84// Return a string representation of CMD_TYPE enum
85static string cmdTypeToString(CMD_TYPE cmd)
86{
87 switch (cmd)
88 {
89 case CMD_BINDPIPELINE:
90 return "CMD_BINDPIPELINE";
91 case CMD_BINDPIPELINEDELTA:
92 return "CMD_BINDPIPELINEDELTA";
93 case CMD_BINDDYNAMICSTATEOBJECT:
94 return "CMD_BINDDYNAMICSTATEOBJECT";
95 case CMD_BINDDESCRIPTORSET:
96 return "CMD_BINDDESCRIPTORSET";
97 case CMD_BINDINDEXBUFFER:
98 return "CMD_BINDINDEXBUFFER";
99 case CMD_BINDVERTEXBUFFER:
100 return "CMD_BINDVERTEXBUFFER";
101 case CMD_DRAW:
102 return "CMD_DRAW";
103 case CMD_DRAWINDEXED:
104 return "CMD_DRAWINDEXED";
105 case CMD_DRAWINDIRECT:
106 return "CMD_DRAWINDIRECT";
107 case CMD_DRAWINDEXEDINDIRECT:
108 return "CMD_DRAWINDEXEDINDIRECT";
109 case CMD_DISPATCH:
110 return "CMD_DISPATCH";
111 case CMD_DISPATCHINDIRECT:
112 return "CMD_DISPATCHINDIRECT";
113 case CMD_COPYBUFFER:
114 return "CMD_COPYBUFFER";
115 case CMD_COPYIMAGE:
116 return "CMD_COPYIMAGE";
117 case CMD_COPYBUFFERTOIMAGE:
118 return "CMD_COPYBUFFERTOIMAGE";
119 case CMD_COPYIMAGETOBUFFER:
120 return "CMD_COPYIMAGETOBUFFER";
121 case CMD_CLONEIMAGEDATA:
122 return "CMD_CLONEIMAGEDATA";
123 case CMD_UPDATEBUFFER:
124 return "CMD_UPDATEBUFFER";
125 case CMD_FILLBUFFER:
126 return "CMD_FILLBUFFER";
127 case CMD_CLEARCOLORIMAGE:
128 return "CMD_CLEARCOLORIMAGE";
129 case CMD_CLEARCOLORIMAGERAW:
130 return "CMD_CLEARCOLORIMAGERAW";
131 case CMD_CLEARDEPTHSTENCIL:
132 return "CMD_CLEARDEPTHSTENCIL";
133 case CMD_RESOLVEIMAGE:
134 return "CMD_RESOLVEIMAGE";
135 case CMD_SETEVENT:
136 return "CMD_SETEVENT";
137 case CMD_RESETEVENT:
138 return "CMD_RESETEVENT";
139 case CMD_WAITEVENTS:
140 return "CMD_WAITEVENTS";
141 case CMD_PIPELINEBARRIER:
142 return "CMD_PIPELINEBARRIER";
143 case CMD_BEGINQUERY:
144 return "CMD_BEGINQUERY";
145 case CMD_ENDQUERY:
146 return "CMD_ENDQUERY";
147 case CMD_RESETQUERYPOOL:
148 return "CMD_RESETQUERYPOOL";
149 case CMD_WRITETIMESTAMP:
150 return "CMD_WRITETIMESTAMP";
151 case CMD_INITATOMICCOUNTERS:
152 return "CMD_INITATOMICCOUNTERS";
153 case CMD_LOADATOMICCOUNTERS:
154 return "CMD_LOADATOMICCOUNTERS";
155 case CMD_SAVEATOMICCOUNTERS:
156 return "CMD_SAVEATOMICCOUNTERS";
157 case CMD_BEGINRENDERPASS:
158 return "CMD_BEGINRENDERPASS";
159 case CMD_ENDRENDERPASS:
160 return "CMD_ENDRENDERPASS";
161 case CMD_DBGMARKERBEGIN:
162 return "CMD_DBGMARKERBEGIN";
163 case CMD_DBGMARKEREND:
164 return "CMD_DBGMARKEREND";
165 default:
166 return "UNKNOWN";
167 }
168}
169// Block of code at start here for managing/tracking Pipeline state that this layer cares about
170// Just track 2 shaders for now
171#define XGL_NUM_GRAPHICS_SHADERS XGL_SHADER_STAGE_COMPUTE
172#define MAX_SLOTS 2048
173#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
174
175static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
176
177// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
178// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
179// to that same cmd buffer by separate thread are not changing state from underneath us
180// Track the last cmd buffer touched by this thread
181static XGL_CMD_BUFFER g_lastCmdBuffer[MAX_TID] = {NULL};
182// Track the last group of CBs touched for displaying to dot file
183static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
184static uint32_t g_lastTouchedCBIndex = 0;
185// Track the last global DrawState of interest touched by any thread
186static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
187static PIPELINE_NODE* g_lastBoundPipeline = NULL;
188static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[XGL_NUM_STATE_BIND_POINT] = {NULL};
189static XGL_DESCRIPTOR_SET g_lastBoundDescriptorSet = NULL;
190#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
191
192//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[XGL_NUM_STATE_BIND_POINT] = {0};
193
194static void insertDynamicState(const XGL_DYNAMIC_STATE_OBJECT state, const GENERIC_HEADER* pCreateInfo, XGL_STATE_BIND_POINT bindPoint)
195{
196 XGL_DYNAMIC_VP_STATE_CREATE_INFO* pVPCI = NULL;
197 size_t scSize = 0;
198 size_t vpSize = 0;
199 loader_platform_thread_lock_mutex(&globalLock);
200 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
201 pStateNode->stateObj = state;
202 switch (pCreateInfo->sType) {
203 case XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
204 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(XGL_DYNAMIC_VP_STATE_CREATE_INFO));
205 pVPCI = (XGL_DYNAMIC_VP_STATE_CREATE_INFO*)pCreateInfo;
206 pStateNode->create_info.vpci.pScissors = new XGL_RECT[pStateNode->create_info.vpci.viewportAndScissorCount];
207 pStateNode->create_info.vpci.pViewports = new XGL_VIEWPORT[pStateNode->create_info.vpci.viewportAndScissorCount];
208 scSize = pVPCI->viewportAndScissorCount * sizeof(XGL_RECT);
209 vpSize = pVPCI->viewportAndScissorCount * sizeof(XGL_VIEWPORT);
210 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
211 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
212 break;
213 case XGL_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
214 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(XGL_DYNAMIC_RS_STATE_CREATE_INFO));
215 break;
216 case XGL_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
217 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(XGL_DYNAMIC_CB_STATE_CREATE_INFO));
218 break;
219 case XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
220 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(XGL_DYNAMIC_DS_STATE_CREATE_INFO));
221 break;
222 default:
223 assert(0);
224 break;
225 }
226 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
227 dynamicStateMap[state] = pStateNode;
228 loader_platform_thread_unlock_mutex(&globalLock);
229}
230// Free all allocated nodes for Dynamic State objs
231static void freeDynamicState()
232{
233 for (unordered_map<XGL_DYNAMIC_STATE_OBJECT, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
234 if (XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
235 delete[] (*ii).second->create_info.vpci.pScissors;
236 delete[] (*ii).second->create_info.vpci.pViewports;
237 }
238 delete (*ii).second;
239 }
240}
241// Free all sampler nodes
242static void freeSamplers()
243{
244 for (unordered_map<XGL_SAMPLER, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
245 delete (*ii).second;
246 }
247}
248static XGL_IMAGE_VIEW_CREATE_INFO* getImageViewCreateInfo(XGL_IMAGE_VIEW view)
249{
250 loader_platform_thread_lock_mutex(&globalLock);
251 if (imageMap.find(view) == imageMap.end()) {
252 loader_platform_thread_unlock_mutex(&globalLock);
253 return NULL;
254 }
255 else {
256 loader_platform_thread_unlock_mutex(&globalLock);
257 return &imageMap[view]->createInfo;
258 }
259}
260// Free all image nodes
261static void freeImages()
262{
263 for (unordered_map<XGL_IMAGE_VIEW, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
264 delete (*ii).second;
265 }
266}
267static XGL_BUFFER_VIEW_CREATE_INFO* getBufferViewCreateInfo(XGL_BUFFER_VIEW view)
268{
269 loader_platform_thread_lock_mutex(&globalLock);
270 if (bufferMap.find(view) == bufferMap.end()) {
271 loader_platform_thread_unlock_mutex(&globalLock);
272 return NULL;
273 }
274 else {
275 loader_platform_thread_unlock_mutex(&globalLock);
276 return &bufferMap[view]->createInfo;
277 }
278}
279// Free all buffer nodes
280static void freeBuffers()
281{
282 for (unordered_map<XGL_BUFFER_VIEW, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
283 delete (*ii).second;
284 }
285}
286static GLOBAL_CB_NODE* getCBNode(XGL_CMD_BUFFER cb);
287
288static void updateCBTracking(XGL_CMD_BUFFER cb)
289{
290 g_lastCmdBuffer[getTIDIndex()] = cb;
291 GLOBAL_CB_NODE* pCB = getCBNode(cb);
292 loader_platform_thread_lock_mutex(&globalLock);
293 g_lastGlobalCB = pCB;
294 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
295 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
296 if (g_pLastTouchedCB[i] == pCB) {
297 loader_platform_thread_unlock_mutex(&globalLock);
298 return;
299 }
300 }
301 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
302 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
303 loader_platform_thread_unlock_mutex(&globalLock);
304}
305
306// Print the last bound dynamic state
307static void printDynamicState(const XGL_CMD_BUFFER cb)
308{
309 GLOBAL_CB_NODE* pCB = getCBNode(cb);
310 if (pCB) {
311 loader_platform_thread_lock_mutex(&globalLock);
312 char str[4*1024];
313 for (uint32_t i = 0; i < XGL_NUM_STATE_BIND_POINT; i++) {
314 if (pCB->lastBoundDynamicState[i]) {
315 sprintf(str, "Reporting CreateInfo for currently bound %s object %p", string_XGL_STATE_BIND_POINT((XGL_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i]->stateObj);
316 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
317 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", dynamic_display(pCB->lastBoundDynamicState[i]->pCreateInfo, " ").c_str());
318 break;
319 }
320 else {
321 sprintf(str, "No dynamic state of type %s bound", string_XGL_STATE_BIND_POINT((XGL_STATE_BIND_POINT)i));
322 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
323 }
324 }
325 loader_platform_thread_unlock_mutex(&globalLock);
326 }
327 else {
328 char str[1024];
329 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
330 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
331 }
332}
333// Retrieve pipeline node ptr for given pipeline object
334static PIPELINE_NODE* getPipeline(XGL_PIPELINE pipeline)
335{
336 loader_platform_thread_lock_mutex(&globalLock);
337 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
338 loader_platform_thread_unlock_mutex(&globalLock);
339 return NULL;
340 }
341 loader_platform_thread_unlock_mutex(&globalLock);
342 return pipelineMap[pipeline];
343}
344
345// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
346static XGL_SAMPLER_CREATE_INFO* getSamplerCreateInfo(const XGL_SAMPLER sampler)
347{
348 loader_platform_thread_lock_mutex(&globalLock);
349 if (sampleMap.find(sampler) == sampleMap.end()) {
350 loader_platform_thread_unlock_mutex(&globalLock);
351 return NULL;
352 }
353 loader_platform_thread_unlock_mutex(&globalLock);
354 return &sampleMap[sampler]->createInfo;
355}
356
357// Init the pipeline mapping info based on pipeline create info LL tree
358// Threading note : Calls to this function should wrapped in mutex
359static void initPipeline(PIPELINE_NODE* pPipeline, const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo)
360{
361 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600362 // TODO : Validate that no create info is incorrectly replicated
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600363 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(XGL_GRAPHICS_PIPELINE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600364 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600365 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600366 size_t bufferSize = 0;
367 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO* pVICI = NULL;
368 XGL_PIPELINE_CB_STATE_CREATE_INFO* pCBCI = NULL;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600369 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600370 while (pTrav) {
371 switch (pTrav->sType) {
372 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600373 pTmpPSSCI = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pTrav;
374 switch (pTmpPSSCI->shader.stage) {
375 case XGL_SHADER_STAGE_VERTEX:
376 pPrev->pNext = &pPipeline->vsCI;
377 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
378 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO));
379 break;
380 case XGL_SHADER_STAGE_TESS_CONTROL:
381 pPrev->pNext = &pPipeline->tcsCI;
382 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
383 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO));
384 break;
385 case XGL_SHADER_STAGE_TESS_EVALUATION:
386 pPrev->pNext = &pPipeline->tesCI;
387 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
388 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO));
389 break;
390 case XGL_SHADER_STAGE_GEOMETRY:
391 pPrev->pNext = &pPipeline->gsCI;
392 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
393 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO));
394 break;
395 case XGL_SHADER_STAGE_FRAGMENT:
396 pPrev->pNext = &pPipeline->fsCI;
397 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
398 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO));
399 break;
400 case XGL_SHADER_STAGE_COMPUTE:
401 // TODO : Flag error, CS is specified through XGL_COMPUTE_PIPELINE_CREATE_INFO
402 break;
403 default:
404 // TODO : Flag error
405 break;
406 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600407 break;
408 case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600409 pPrev->pNext = &pPipeline->vertexInputCI;
410 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
411 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600412 // Copy embedded ptrs
413 pVICI = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO*)pTrav;
414 pPipeline->vtxBindingCount = pVICI->bindingCount;
415 if (pPipeline->vtxBindingCount) {
416 pPipeline->pVertexBindingDescriptions = new XGL_VERTEX_INPUT_BINDING_DESCRIPTION[pPipeline->vtxBindingCount];
417 bufferSize = pPipeline->vtxBindingCount * sizeof(XGL_VERTEX_INPUT_BINDING_DESCRIPTION);
418 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO*)pTrav)->pVertexAttributeDescriptions, bufferSize);
419 }
420 pPipeline->vtxAttributeCount = pVICI->attributeCount;
421 if (pPipeline->vtxAttributeCount) {
422 pPipeline->pVertexAttributeDescriptions = new XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION[pPipeline->vtxAttributeCount];
423 bufferSize = pPipeline->vtxAttributeCount * sizeof(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION);
424 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO*)pTrav)->pVertexAttributeDescriptions, bufferSize);
425 }
426 break;
427 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600428 pPrev->pNext = &pPipeline->iaStateCI;
429 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
430 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(XGL_PIPELINE_IA_STATE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600431 break;
432 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600433 pPrev->pNext = &pPipeline->tessStateCI;
434 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
435 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(XGL_PIPELINE_TESS_STATE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600436 break;
437 case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600438 pPrev->pNext = &pPipeline->vpStateCI;
439 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
440 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(XGL_PIPELINE_VP_STATE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600441 break;
442 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600443 pPrev->pNext = &pPipeline->rsStateCI;
444 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
445 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(XGL_PIPELINE_RS_STATE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600446 break;
447 case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600448 pPrev->pNext = &pPipeline->msStateCI;
449 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
450 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(XGL_PIPELINE_MS_STATE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600451 break;
452 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600453 pPrev->pNext = &pPipeline->cbStateCI;
454 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
455 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(XGL_PIPELINE_CB_STATE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600456 // Copy embedded ptrs
457 pCBCI = (XGL_PIPELINE_CB_STATE_CREATE_INFO*)pTrav;
458 pPipeline->attachmentCount = pCBCI->attachmentCount;
459 if (pPipeline->attachmentCount) {
460 pPipeline->pAttachments = new XGL_PIPELINE_CB_ATTACHMENT_STATE[pPipeline->attachmentCount];
461 bufferSize = pPipeline->attachmentCount * sizeof(XGL_PIPELINE_CB_ATTACHMENT_STATE);
462 memcpy((void*)pPipeline->pAttachments, ((XGL_PIPELINE_CB_STATE_CREATE_INFO*)pTrav)->pAttachments, bufferSize);
463 }
464 break;
465 case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600466 pPrev->pNext = &pPipeline->dsStateCI;
467 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
468 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(XGL_PIPELINE_DS_STATE_CREATE_INFO));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600469 break;
470 default:
471 assert(0);
472 break;
473 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600474 pTrav = (GENERIC_HEADER*)pTrav->pNext;
475 }
476 pipelineMap[pPipeline->pipeline] = pPipeline;
477}
478// Free the Pipeline nodes
479static void freePipelines()
480{
481 for (unordered_map<XGL_PIPELINE, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600482 if ((*ii).second->pVertexBindingDescriptions) {
483 delete[] (*ii).second->pVertexBindingDescriptions;
484 }
485 if ((*ii).second->pVertexAttributeDescriptions) {
486 delete[] (*ii).second->pVertexAttributeDescriptions;
487 }
488 if ((*ii).second->pAttachments) {
489 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600490 }
491 delete (*ii).second;
492 }
493}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600494// For given pipeline, return number of MSAA samples, or one if MSAA disabled
495static uint32_t getNumSamples(const XGL_PIPELINE pipeline)
496{
497 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600498 if (XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
499 if (pPipe->msStateCI.multisampleEnable)
500 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600501 }
502 return 1;
503}
504// Validate state related to the PSO
505static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const XGL_PIPELINE_BIND_POINT pipelineBindPoint, const XGL_PIPELINE pipeline)
506{
507 if (XGL_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
508 // Verify that any MSAA request in PSO matches sample# in bound FB
509 uint32_t psoNumSamples = getNumSamples(pipeline);
510 if (pCB->activeRenderPass) {
511 XGL_RENDER_PASS_CREATE_INFO* pRPCI = renderPassMap[pCB->activeRenderPass];
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600512 XGL_FRAMEBUFFER_CREATE_INFO* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis2464b882015-04-01 08:40:34 -0600513 if (psoNumSamples != pFBCI->sampleCount) {
514 char str[1024];
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600515 sprintf(str, "Num samples mismatche! Binding PSO (%p) with %u samples while current RenderPass (%p) uses FB (%p) with %u samples!", (void*)pipeline, psoNumSamples, (void*)pCB->activeRenderPass, (void*)pCB->framebuffer, pFBCI->sampleCount);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600516 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
517 }
518 } else {
519 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
520 // Verify and flag error as appropriate
521 }
522 // TODO : Add more checks here
523 } else {
524 // TODO : Validate non-gfx pipeline updates
525 }
526}
527
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600528// Block of code at start here specifically for managing/tracking DSs
529
530// Return Region node ptr for specified region or else NULL
531static REGION_NODE* getRegionNode(XGL_DESCRIPTOR_REGION region)
532{
533 loader_platform_thread_lock_mutex(&globalLock);
534 if (regionMap.find(region) == regionMap.end()) {
535 loader_platform_thread_unlock_mutex(&globalLock);
536 return NULL;
537 }
538 loader_platform_thread_unlock_mutex(&globalLock);
539 return regionMap[region];
540}
541// Return Set node ptr for specified set or else NULL
542static SET_NODE* getSetNode(XGL_DESCRIPTOR_SET set)
543{
544 loader_platform_thread_lock_mutex(&globalLock);
545 if (setMap.find(set) == setMap.end()) {
546 loader_platform_thread_unlock_mutex(&globalLock);
547 return NULL;
548 }
549 loader_platform_thread_unlock_mutex(&globalLock);
550 return setMap[set];
551}
552
553// Return XGL_TRUE if DS Exists and is within an xglBeginDescriptorRegionUpdate() call sequence, otherwise XGL_FALSE
554static bool32_t dsUpdateActive(XGL_DESCRIPTOR_SET ds)
555{
556 // Note, both "get" functions use global mutex so this guy does not
557 SET_NODE* pTrav = getSetNode(ds);
558 if (pTrav) {
559 REGION_NODE* pRegion = getRegionNode(pTrav->region);
560 if (pRegion) {
561 return pRegion->updateActive;
562 }
563 }
564 return XGL_FALSE;
565}
566
567static LAYOUT_NODE* getLayoutNode(XGL_DESCRIPTOR_SET_LAYOUT layout) {
568 loader_platform_thread_lock_mutex(&globalLock);
569 if (layoutMap.find(layout) == layoutMap.end()) {
570 loader_platform_thread_unlock_mutex(&globalLock);
571 return NULL;
572 }
573 loader_platform_thread_unlock_mutex(&globalLock);
574 return layoutMap[layout];
575}
576
577static uint32_t getUpdateIndex(GENERIC_HEADER* pUpdateStruct)
578{
579 switch (pUpdateStruct->sType)
580 {
581 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:
582 return ((XGL_UPDATE_SAMPLERS*)pUpdateStruct)->index;
583 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
584 return ((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdateStruct)->index;
585 case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:
586 return ((XGL_UPDATE_IMAGES*)pUpdateStruct)->index;
587 case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:
588 return ((XGL_UPDATE_BUFFERS*)pUpdateStruct)->index;
589 case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:
590 return ((XGL_UPDATE_AS_COPY*)pUpdateStruct)->descriptorIndex;
591 default:
592 // TODO : Flag specific error for this case
593 return 0;
594 }
595}
596
597static uint32_t getUpdateUpperBound(GENERIC_HEADER* pUpdateStruct)
598{
599 switch (pUpdateStruct->sType)
600 {
601 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:
602 return (((XGL_UPDATE_SAMPLERS*)pUpdateStruct)->count + ((XGL_UPDATE_SAMPLERS*)pUpdateStruct)->index);
603 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
604 return (((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdateStruct)->count + ((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdateStruct)->index);
605 case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:
606 return (((XGL_UPDATE_IMAGES*)pUpdateStruct)->count + ((XGL_UPDATE_IMAGES*)pUpdateStruct)->index);
607 case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:
608 return (((XGL_UPDATE_BUFFERS*)pUpdateStruct)->count + ((XGL_UPDATE_BUFFERS*)pUpdateStruct)->index);
609 case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:
610 // TODO : Need to understand this case better and make sure code is correct
611 return (((XGL_UPDATE_AS_COPY*)pUpdateStruct)->count + ((XGL_UPDATE_AS_COPY*)pUpdateStruct)->descriptorIndex);
612 default:
613 // TODO : Flag specific error for this case
614 return 0;
615 }
616}
617
618// Verify that the descriptor type in the update struct matches what's expected by the layout
619static bool32_t validateUpdateType(GENERIC_HEADER* pUpdateStruct, const LAYOUT_NODE* pLayout)//XGL_DESCRIPTOR_TYPE type)
620{
621 // First get actual type of update
622 XGL_DESCRIPTOR_TYPE actualType;
623 uint32_t i = 0;
624 uint32_t bound = getUpdateUpperBound(pUpdateStruct);
625 switch (pUpdateStruct->sType)
626 {
627 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:
628 actualType = XGL_DESCRIPTOR_TYPE_SAMPLER;
629 break;
630 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
631 actualType = XGL_DESCRIPTOR_TYPE_SAMPLER_TEXTURE;
632 break;
633 case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:
634 actualType = ((XGL_UPDATE_IMAGES*)pUpdateStruct)->descriptorType;
635 break;
636 case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:
637 actualType = ((XGL_UPDATE_BUFFERS*)pUpdateStruct)->descriptorType;
638 break;
639 case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:
640 actualType = ((XGL_UPDATE_AS_COPY*)pUpdateStruct)->descriptorType;
641 break;
642 default:
643 // TODO : Flag specific error for this case
644 return 0;
645 }
646 for (i = getUpdateIndex(pUpdateStruct); i < bound; i++) {
647 if (pLayout->pTypes[i] != actualType)
648 return 0;
649 }
650 return 1;
651}
652
653// Verify that update region for this update does not exceed max layout index for this type
654static bool32_t validateUpdateSize(GENERIC_HEADER* pUpdateStruct, uint32_t layoutIdx)
655{
656 if ((getUpdateUpperBound(pUpdateStruct)-1) > layoutIdx)
657 return 0;
658 return 1;
659}
660// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
661// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
662// NOTE : Calls to this function should be wrapped in mutex
663static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
664{
665 GENERIC_HEADER* pNewNode = NULL;
666 size_t array_size = 0;
667 size_t base_array_size = 0;
668 size_t total_array_size = 0;
669 size_t baseBuffAddr = 0;
670 XGL_UPDATE_BUFFERS* pUBCI;
671 XGL_UPDATE_IMAGES* pUICI;
672 XGL_IMAGE_VIEW_ATTACH_INFO*** pppLocalImageViews = NULL;
673 XGL_BUFFER_VIEW_ATTACH_INFO*** pppLocalBufferViews = NULL;
674 char str[1024];
675 switch (pUpdate->sType)
676 {
677 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:
678 pNewNode = (GENERIC_HEADER*)malloc(sizeof(XGL_UPDATE_SAMPLERS));
679#if ALLOC_DEBUG
680 printf("Alloc10 #%lu pNewNode addr(%p)\n", ++g_alloc_count, (void*)pNewNode);
681#endif
682 memcpy(pNewNode, pUpdate, sizeof(XGL_UPDATE_SAMPLERS));
683 array_size = sizeof(XGL_SAMPLER) * ((XGL_UPDATE_SAMPLERS*)pNewNode)->count;
684 ((XGL_UPDATE_SAMPLERS*)pNewNode)->pSamplers = (XGL_SAMPLER*)malloc(array_size);
685#if ALLOC_DEBUG
686 printf("Alloc11 #%lu pNewNode->pSamplers addr(%p)\n", ++g_alloc_count, (void*)((XGL_UPDATE_SAMPLERS*)pNewNode)->pSamplers);
687#endif
688 memcpy((XGL_SAMPLER*)((XGL_UPDATE_SAMPLERS*)pNewNode)->pSamplers, ((XGL_UPDATE_SAMPLERS*)pUpdate)->pSamplers, array_size);
689 break;
690 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
691 pNewNode = (GENERIC_HEADER*)malloc(sizeof(XGL_UPDATE_SAMPLER_TEXTURES));
692#if ALLOC_DEBUG
693 printf("Alloc12 #%lu pNewNode addr(%p)\n", ++g_alloc_count, (void*)pNewNode);
694#endif
695 memcpy(pNewNode, pUpdate, sizeof(XGL_UPDATE_SAMPLER_TEXTURES));
696 array_size = sizeof(XGL_SAMPLER_IMAGE_VIEW_INFO) * ((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->count;
697 ((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->pSamplerImageViews = (XGL_SAMPLER_IMAGE_VIEW_INFO*)malloc(array_size);
698#if ALLOC_DEBUG
699 printf("Alloc13 #%lu pNewNode->pSamplerImageViews addr(%p)\n", ++g_alloc_count, (void*)((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->pSamplerImageViews);
700#endif
701 for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->count; i++) {
702 memcpy((XGL_SAMPLER_IMAGE_VIEW_INFO*)&((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->pSamplerImageViews[i], &((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdate)->pSamplerImageViews[i], sizeof(XGL_SAMPLER_IMAGE_VIEW_INFO));
703 ((XGL_SAMPLER_IMAGE_VIEW_INFO*)((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->pSamplerImageViews)[i].pImageView = (XGL_IMAGE_VIEW_ATTACH_INFO*)malloc(sizeof(XGL_IMAGE_VIEW_ATTACH_INFO));
704#if ALLOC_DEBUG
705 printf("Alloc14 #%lu pSamplerImageViews)[%u].pImageView addr(%p)\n", ++g_alloc_count, i, (void*)((XGL_SAMPLER_IMAGE_VIEW_INFO*)((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->pSamplerImageViews)[i].pImageView);
706#endif
707 memcpy((XGL_IMAGE_VIEW_ATTACH_INFO*)((XGL_UPDATE_SAMPLER_TEXTURES*)pNewNode)->pSamplerImageViews[i].pImageView, ((XGL_UPDATE_SAMPLER_TEXTURES*)pUpdate)->pSamplerImageViews[i].pImageView, sizeof(XGL_IMAGE_VIEW_ATTACH_INFO));
708 }
709 break;
710 case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:
711 pUICI = (XGL_UPDATE_IMAGES*)pUpdate;
712 pNewNode = (GENERIC_HEADER*)malloc(sizeof(XGL_UPDATE_IMAGES));
713#if ALLOC_DEBUG
714 printf("Alloc15 #%lu pNewNode addr(%p)\n", ++g_alloc_count, (void*)pNewNode);
715#endif
716 memcpy(pNewNode, pUpdate, sizeof(XGL_UPDATE_IMAGES));
717 base_array_size = sizeof(XGL_IMAGE_VIEW_ATTACH_INFO*) * ((XGL_UPDATE_IMAGES*)pNewNode)->count;
718 total_array_size = (sizeof(XGL_IMAGE_VIEW_ATTACH_INFO) * ((XGL_UPDATE_IMAGES*)pNewNode)->count) + base_array_size;
719 pppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO***)&((XGL_UPDATE_IMAGES*)pNewNode)->pImageViews;
720 *pppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO**)malloc(total_array_size);
721#if ALLOC_DEBUG
722 printf("Alloc16 #%lu *pppLocalImageViews addr(%p)\n", ++g_alloc_count, (void*)*pppLocalImageViews);
723#endif
724 baseBuffAddr = (size_t)(*pppLocalImageViews) + base_array_size;
725 for (uint32_t i = 0; i < pUICI->count; i++) {
726 (*pppLocalImageViews)[i] = (XGL_IMAGE_VIEW_ATTACH_INFO*)(baseBuffAddr + (i * sizeof(XGL_IMAGE_VIEW_ATTACH_INFO)));
727 memcpy((*pppLocalImageViews)[i], pUICI->pImageViews[i], sizeof(XGL_IMAGE_VIEW_ATTACH_INFO));
728 }
729 break;
730 case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:
731 pUBCI = (XGL_UPDATE_BUFFERS*)pUpdate;
732 pNewNode = (GENERIC_HEADER*)malloc(sizeof(XGL_UPDATE_BUFFERS));
733#if ALLOC_DEBUG
734 printf("Alloc17 #%lu pNewNode addr(%p)\n", ++g_alloc_count, (void*)pNewNode);
735#endif
736 memcpy(pNewNode, pUpdate, sizeof(XGL_UPDATE_BUFFERS));
737 base_array_size = sizeof(XGL_BUFFER_VIEW_ATTACH_INFO*) * pUBCI->count;
738 total_array_size = (sizeof(XGL_BUFFER_VIEW_ATTACH_INFO) * pUBCI->count) + base_array_size;
739 pppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO***)&((XGL_UPDATE_BUFFERS*)pNewNode)->pBufferViews;
740 *pppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO**)malloc(total_array_size);
741#if ALLOC_DEBUG
742 printf("Alloc18 #%lu *pppLocalBufferViews addr(%p)\n", ++g_alloc_count, (void*)*pppLocalBufferViews);
743#endif
744 baseBuffAddr = (size_t)(*pppLocalBufferViews) + base_array_size;
745 for (uint32_t i = 0; i < pUBCI->count; i++) {
746 // Set ptr and then copy data into that ptr
747 (*pppLocalBufferViews)[i] = (XGL_BUFFER_VIEW_ATTACH_INFO*)(baseBuffAddr + (i * sizeof(XGL_BUFFER_VIEW_ATTACH_INFO)));
748 memcpy((*pppLocalBufferViews)[i], pUBCI->pBufferViews[i], sizeof(XGL_BUFFER_VIEW_ATTACH_INFO));
749 }
750 break;
751 case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:
752 pNewNode = (GENERIC_HEADER*)malloc(sizeof(XGL_UPDATE_AS_COPY));
753#if ALLOC_DEBUG
754 printf("Alloc19 #%lu pNewNode addr(%p)\n", ++g_alloc_count, (void*)pNewNode);
755#endif
756 memcpy(pNewNode, pUpdate, sizeof(XGL_UPDATE_AS_COPY));
757 break;
758 default:
759 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in xglUpdateDescriptors() struct tree", string_XGL_STRUCTURE_TYPE(pUpdate->sType), pUpdate->sType);
760 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
761 return NULL;
762 }
763 // Make sure that pNext for the end of shadow copy is NULL
764 pNewNode->pNext = NULL;
765 return pNewNode;
766}
767// For given ds, update its mapping based on pUpdateChain linked-list
768static void dsUpdate(XGL_DESCRIPTOR_SET ds, GENERIC_HEADER* pUpdateChain)
769{
770 SET_NODE* pSet = getSetNode(ds);
771 loader_platform_thread_lock_mutex(&globalLock);
772 g_lastBoundDescriptorSet = pSet->set;
773 LAYOUT_NODE* pLayout = NULL;
774 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pLayoutCI = NULL;
775 // TODO : If pCIList is NULL, flag error
776 GENERIC_HEADER* pUpdates = pUpdateChain;
777 // Perform all updates
778 while (pUpdates) {
779 pLayout = pSet->pLayouts;
780 // For each update first find the layout section that it overlaps
781 while (pLayout && (pLayout->startIndex > getUpdateIndex(pUpdates))) {
782 pLayout = pLayout->pPriorSetLayout;
783 }
784 if (!pLayout) {
785 char str[1024];
786 sprintf(str, "Descriptor Set %p does not have index to match update index %u for update type %s!", ds, getUpdateIndex(pUpdates), string_XGL_STRUCTURE_TYPE(pUpdates->sType));
787 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
788 }
789 else {
790 // Next verify that update is correct size
791 if (!validateUpdateSize(pUpdates, pLayout->endIndex)) {
792 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
793 pLayoutCI = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pLayout->pCreateInfoList;
794 string DSstr = xgl_print_xgl_descriptor_set_layout_create_info(pLayoutCI, "{DS} ").c_str();
795 sprintf(str, "Descriptor update type of %s is out of bounds for matching layout w/ CI:\n%s!", string_XGL_STRUCTURE_TYPE(pUpdates->sType), DSstr.c_str());
796 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS", str);
797 }
798 else { // TODO : should we skip update on a type mismatch or force it?
799 // We have the right layout section, now verify that update is of the right type
800 if (!validateUpdateType(pUpdates, pLayout)) {
801 char str[1024];
802 sprintf(str, "Descriptor update type of %s does not match overlapping layout type!", string_XGL_STRUCTURE_TYPE(pUpdates->sType));
803 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
804 }
805 else {
806 // Save the update info
807 // TODO : Info message that update successful
808 // Create new update struct for this set's shadow copy
809 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdates);
810 if (NULL == pNewNode) {
811 char str[1024];
812 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in xglUpdateDescriptors()");
813 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
814 }
815 else {
816 // Insert shadow node into LL of updates for this set
817 pNewNode->pNext = pSet->pUpdateStructs;
818 pSet->pUpdateStructs = pNewNode;
819 // Now update appropriate descriptor(s) to point to new Update node
820 for (uint32_t i = getUpdateIndex(pUpdates); i < getUpdateUpperBound(pUpdates); i++) {
821 assert(i<pSet->descriptorCount);
822 pSet->ppDescriptors[i] = pNewNode;
823 }
824 }
825 }
826 }
827 }
828 pUpdates = (GENERIC_HEADER*)pUpdates->pNext;
829 }
830 loader_platform_thread_unlock_mutex(&globalLock);
831}
832// Free the shadowed update node for this Set
833// NOTE : Calls to this function should be wrapped in mutex
834static void freeShadowUpdateTree(SET_NODE* pSet)
835{
836 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
837 pSet->pUpdateStructs = NULL;
838 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
839 // Clear the descriptor mappings as they will now be invalid
840 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
841 while(pShadowUpdate) {
842 pFreeUpdate = pShadowUpdate;
843 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
844 uint32_t index = 0;
845 XGL_UPDATE_SAMPLERS* pUS = NULL;
846 XGL_UPDATE_SAMPLER_TEXTURES* pUST = NULL;
847 XGL_UPDATE_IMAGES* pUI = NULL;
848 XGL_UPDATE_BUFFERS* pUB = NULL;
849 void** ppToFree = NULL;
850 switch (pFreeUpdate->sType)
851 {
852 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:
853 pUS = (XGL_UPDATE_SAMPLERS*)pFreeUpdate;
854 if (pUS->pSamplers) {
855 ppToFree = (void**)&pUS->pSamplers;
856#if ALLOC_DEBUG
857 printf("Free11 #%lu pSamplers addr(%p)\n", ++g_free_count, (void*)*ppToFree);
858#endif
859 free(*ppToFree);
860 }
861 break;
862 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
863 pUST = (XGL_UPDATE_SAMPLER_TEXTURES*)pFreeUpdate;
864 for (index = 0; index < pUST->count; index++) {
865 if (pUST->pSamplerImageViews[index].pImageView) {
866 ppToFree = (void**)&pUST->pSamplerImageViews[index].pImageView;
867#if ALLOC_DEBUG
868 printf("Free14 #%lu pImageView addr(%p)\n", ++g_free_count, (void*)*ppToFree);
869#endif
870 free(*ppToFree);
871 }
872 }
873 ppToFree = (void**)&pUST->pSamplerImageViews;
874#if ALLOC_DEBUG
875 printf("Free13 #%lu pSamplerImageViews addr(%p)\n", ++g_free_count, (void*)*ppToFree);
876#endif
877 free(*ppToFree);
878 break;
879 case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:
880 pUI = (XGL_UPDATE_IMAGES*)pFreeUpdate;
881 if (pUI->pImageViews) {
882 ppToFree = (void**)&pUI->pImageViews;
883#if ALLOC_DEBUG
884 printf("Free16 #%lu pImageViews addr(%p)\n", ++g_free_count, (void*)*ppToFree);
885#endif
886 free(*ppToFree);
887 }
888 break;
889 case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:
890 pUB = (XGL_UPDATE_BUFFERS*)pFreeUpdate;
891 if (pUB->pBufferViews) {
892 ppToFree = (void**)&pUB->pBufferViews;
893#if ALLOC_DEBUG
894 printf("Free18 #%lu pBufferViews addr(%p)\n", ++g_free_count, (void*)*ppToFree);
895#endif
896 free(*ppToFree);
897 }
898 break;
899 case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:
900 break;
901 default:
902 assert(0);
903 break;
904 }
905#if ALLOC_DEBUG
906 printf("Free10, Free12, Free15, Free17, Free19 #%lu pUpdateNode addr(%p)\n", ++g_free_count, (void*)pFreeUpdate);
907#endif
908 free(pFreeUpdate);
909 }
910}
911// Free all DS Regions including their Sets & related sub-structs
912// NOTE : Calls to this function should be wrapped in mutex
913static void freeRegions()
914{
915 for (unordered_map<XGL_DESCRIPTOR_REGION, REGION_NODE*>::iterator ii=regionMap.begin(); ii!=regionMap.end(); ++ii) {
916 SET_NODE* pSet = (*ii).second->pSets;
917 SET_NODE* pFreeSet = pSet;
918 while (pSet) {
919 pFreeSet = pSet;
920 pSet = pSet->pNext;
921 // Freeing layouts handled in freeLayouts() function
922 // Free Update shadow struct tree
923 freeShadowUpdateTree(pFreeSet);
924 if (pFreeSet->ppDescriptors) {
925 delete pFreeSet->ppDescriptors;
926 }
927 delete pFreeSet;
928 }
929 if ((*ii).second->createInfo.pTypeCount) {
930 delete (*ii).second->createInfo.pTypeCount;
931 }
932 delete (*ii).second;
933 }
934}
935// WARN : Once freeLayouts() called, any layout ptrs in Region/Set data structure will be invalid
936// NOTE : Calls to this function should be wrapped in mutex
937static void freeLayouts()
938{
939 for (unordered_map<XGL_DESCRIPTOR_SET_LAYOUT, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
940 LAYOUT_NODE* pLayout = (*ii).second;
941 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pLayout->pCreateInfoList;
942 while (pTrav) {
943 GENERIC_HEADER* pToFree = pTrav;
944 pTrav = (GENERIC_HEADER*)pTrav->pNext;
945 delete pToFree;
946 }
947 if (pLayout->pTypes) {
948 delete pLayout->pTypes;
949 }
950 delete pLayout;
951 }
952}
953// Currently clearing a set is removing all previous updates to that set
954// TODO : Validate if this is correct clearing behavior
955static void clearDescriptorSet(XGL_DESCRIPTOR_SET set)
956{
957 SET_NODE* pSet = getSetNode(set);
958 if (!pSet) {
959 // TODO : Return error
960 }
961 else {
962 loader_platform_thread_lock_mutex(&globalLock);
963 freeShadowUpdateTree(pSet);
964 loader_platform_thread_unlock_mutex(&globalLock);
965 }
966}
967
968static void clearDescriptorRegion(XGL_DESCRIPTOR_REGION region)
969{
970 REGION_NODE* pRegion = getRegionNode(region);
971 if (!pRegion) {
972 char str[1024];
973 sprintf(str, "Unable to find region node for region %p specified in xglClearDescriptorRegion() call", (void*)region);
974 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, region, 0, DRAWSTATE_INVALID_REGION, "DS", str);
975 }
976 else
977 {
978 // For every set off of this region, clear it
979 SET_NODE* pSet = pRegion->pSets;
980 while (pSet) {
981 clearDescriptorSet(pSet->set);
982 }
983 }
984}
985
986// Code here to manage the Cmd buffer LL
987static GLOBAL_CB_NODE* getCBNode(XGL_CMD_BUFFER cb)
988{
989 loader_platform_thread_lock_mutex(&globalLock);
990 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
991 loader_platform_thread_unlock_mutex(&globalLock);
992 return NULL;
993 }
994 loader_platform_thread_unlock_mutex(&globalLock);
995 return cmdBufferMap[cb];
996}
997// Free all CB Nodes
998// NOTE : Calls to this function should be wrapped in mutex
999static void freeCmdBuffers()
1000{
1001 for (unordered_map<XGL_CMD_BUFFER, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
1002 while (!(*ii).second->pCmds.empty()) {
1003 delete (*ii).second->pCmds.back();
1004 (*ii).second->pCmds.pop_back();
1005 }
1006 delete (*ii).second;
1007 }
1008}
1009static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1010{
1011 CMD_NODE* pCmd = new CMD_NODE;
1012 if (pCmd) {
1013 // init cmd node and append to end of cmd LL
1014 memset(pCmd, 0, sizeof(CMD_NODE));
1015 pCmd->cmdNumber = ++pCB->numCmds;
1016 pCmd->type = cmd;
1017 pCB->pCmds.push_back(pCmd);
1018 }
1019 else {
1020 char str[1024];
1021 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
1022 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
1023 }
1024}
1025static void resetCB(const XGL_CMD_BUFFER cb)
1026{
1027 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1028 if (pCB) {
1029 while (!pCB->pCmds.empty()) {
1030 delete pCB->pCmds.back();
1031 pCB->pCmds.pop_back();
1032 }
1033 // Reset CB state
1034 XGL_FLAGS saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001035 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001036 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1037 pCB->cmdBuffer = cb;
1038 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001039 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001040 pCB->lastVtxBinding = MAX_BINDING;
1041 }
1042}
1043// Set the last bound dynamic state of given type
1044// TODO : Need to track this per cmdBuffer and correlate cmdBuffer for Draw w/ last bound for that cmdBuffer?
1045static void setLastBoundDynamicState(const XGL_CMD_BUFFER cmdBuffer, const XGL_DYNAMIC_STATE_OBJECT state, const XGL_STATE_BIND_POINT sType)
1046{
1047 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1048 if (pCB) {
1049 updateCBTracking(cmdBuffer);
1050 loader_platform_thread_lock_mutex(&globalLock);
1051 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1052 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1053 char str[1024];
1054 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
1055 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
1056 }
1057 else {
1058 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1059 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1060 }
1061 loader_platform_thread_unlock_mutex(&globalLock);
1062 }
1063 else {
1064 char str[1024];
1065 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
1066 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
1067 }
1068}
1069// Print the last bound Gfx Pipeline
1070static void printPipeline(const XGL_CMD_BUFFER cb)
1071{
1072 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1073 if (pCB) {
1074 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1075 if (!pPipeTrav) {
1076 // nothing to print
1077 }
1078 else {
Tobin Ehliscd3109e2015-04-01 11:59:08 -06001079 string pipeStr = xgl_print_xgl_graphics_pipeline_create_info(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001080 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
1081 }
1082 }
1083}
1084// Common Dot dumping code
1085static void dsCoreDumpDot(const XGL_DESCRIPTOR_SET ds, FILE* pOutFile)
1086{
1087 SET_NODE* pSet = getSetNode(ds);
1088 if (pSet) {
1089 REGION_NODE* pRegion = getRegionNode(pSet->region);
1090 char tmp_str[4*1024];
1091 fprintf(pOutFile, "subgraph cluster_DescriptorRegion\n{\nlabel=\"Descriptor Region\"\n");
1092 sprintf(tmp_str, "Region (%p)", pRegion->region);
1093 char* pGVstr = xgl_gv_print_xgl_descriptor_region_create_info(&pRegion->createInfo, tmp_str);
1094 fprintf(pOutFile, "%s", pGVstr);
1095 free(pGVstr);
1096 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1097 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
1098 LAYOUT_NODE* pLayout = pSet->pLayouts;
1099 uint32_t layout_index = 0;
1100 while (pLayout) {
1101 ++layout_index;
1102 sprintf(tmp_str, "LAYOUT%u", layout_index);
1103 pGVstr = xgl_gv_print_xgl_descriptor_set_layout_create_info(pLayout->pCreateInfoList, tmp_str);
1104 fprintf(pOutFile, "%s", pGVstr);
1105 free(pGVstr);
1106 pLayout = pLayout->pPriorSetLayout;
1107 if (pLayout) {
1108 fprintf(pOutFile, "\"%s\" -> \"LAYOUT%u\" [];\n", tmp_str, layout_index+1);
1109 }
1110 }
1111 if (pSet->pUpdateStructs) {
1112 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1113 fprintf(pOutFile, "%s", pGVstr);
1114 free(pGVstr);
1115 }
1116 if (pSet->ppDescriptors) {
1117 //void* pDesc = NULL;
1118 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1119 uint32_t i = 0;
1120 for (i=0; i < pSet->descriptorCount; i++) {
1121 if (pSet->ppDescriptors[i]) {
1122 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_XGL_STRUCTURE_TYPE(pSet->ppDescriptors[i]->sType));
1123 }
1124 }
1125#define NUM_COLORS 7
1126 vector<string> edgeColors;
1127 edgeColors.push_back("0000ff");
1128 edgeColors.push_back("ff00ff");
1129 edgeColors.push_back("ffff00");
1130 edgeColors.push_back("00ff00");
1131 edgeColors.push_back("000000");
1132 edgeColors.push_back("00ffff");
1133 edgeColors.push_back("ff0000");
1134 uint32_t colorIdx = 0;
1135 fprintf(pOutFile, "</TABLE>>\n];\n");
1136 // Now add the views that are mapped to active descriptors
1137 XGL_UPDATE_SAMPLERS* pUS = NULL;
1138 XGL_UPDATE_SAMPLER_TEXTURES* pUST = NULL;
1139 XGL_UPDATE_IMAGES* pUI = NULL;
1140 XGL_UPDATE_BUFFERS* pUB = NULL;
1141 XGL_UPDATE_AS_COPY* pUAC = NULL;
1142 XGL_SAMPLER_CREATE_INFO* pSCI = NULL;
1143 XGL_IMAGE_VIEW_CREATE_INFO* pIVCI = NULL;
1144 XGL_BUFFER_VIEW_CREATE_INFO* pBVCI = NULL;
1145 void** ppNextPtr = NULL;
1146 void* pSaveNext = NULL;
1147 for (i=0; i < pSet->descriptorCount; i++) {
1148 if (pSet->ppDescriptors[i]) {
1149 switch (pSet->ppDescriptors[i]->sType)
1150 {
1151 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:
1152 pUS = (XGL_UPDATE_SAMPLERS*)pSet->ppDescriptors[i];
1153 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->index]);
1154 if (pSCI) {
1155 sprintf(tmp_str, "SAMPLER%u", i);
1156 fprintf(pOutFile, "%s", xgl_gv_print_xgl_sampler_create_info(pSCI, tmp_str));
1157 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1158 }
1159 break;
1160 case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
1161 pUST = (XGL_UPDATE_SAMPLER_TEXTURES*)pSet->ppDescriptors[i];
1162 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->index].pSampler);
1163 if (pSCI) {
1164 sprintf(tmp_str, "SAMPLER%u", i);
1165 fprintf(pOutFile, "%s", xgl_gv_print_xgl_sampler_create_info(pSCI, tmp_str));
1166 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1167 }
1168 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->index].pImageView->view);
1169 if (pIVCI) {
1170 sprintf(tmp_str, "IMAGE_VIEW%u", i);
1171 fprintf(pOutFile, "%s", xgl_gv_print_xgl_image_view_create_info(pIVCI, tmp_str));
1172 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1173 }
1174 break;
1175 case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:
1176 pUI = (XGL_UPDATE_IMAGES*)pSet->ppDescriptors[i];
1177 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->index]->view);
1178 if (pIVCI) {
1179 sprintf(tmp_str, "IMAGE_VIEW%u", i);
1180 fprintf(pOutFile, "%s", xgl_gv_print_xgl_image_view_create_info(pIVCI, tmp_str));
1181 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1182 }
1183 break;
1184 case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:
1185 pUB = (XGL_UPDATE_BUFFERS*)pSet->ppDescriptors[i];
1186 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->index]->view);
1187 if (pBVCI) {
1188 sprintf(tmp_str, "BUFFER_VIEW%u", i);
1189 fprintf(pOutFile, "%s", xgl_gv_print_xgl_buffer_view_create_info(pBVCI, tmp_str));
1190 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1191 }
1192 break;
1193 case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:
1194 pUAC = (XGL_UPDATE_AS_COPY*)pSet->ppDescriptors[i];
1195 // TODO : Need to validate this code
1196 // Save off pNext and set to NULL while printing this struct, then restore it
1197 ppNextPtr = (void**)&pUAC->pNext;
1198 pSaveNext = *ppNextPtr;
1199 *ppNextPtr = NULL;
1200 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
1201 fprintf(pOutFile, "%s", xgl_gv_print_xgl_update_as_copy(pUAC, tmp_str));
1202 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1203 // Restore next ptr
1204 *ppNextPtr = pSaveNext;
1205 break;
1206 default:
1207 break;
1208 }
1209 colorIdx = (colorIdx+1) % NUM_COLORS;
1210 }
1211 }
1212 }
1213 fprintf(pOutFile, "}\n");
1214 fprintf(pOutFile, "}\n");
1215 }
1216}
1217// Dump subgraph w/ DS info
1218static void dsDumpDot(const XGL_CMD_BUFFER cb, FILE* pOutFile)
1219{
1220 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1221 if (pCB && pCB->lastBoundDescriptorSet) {
1222 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1223 }
1224}
1225// Dump a GraphViz dot file showing the Cmd Buffers
1226static void cbDumpDotFile(string outFileName)
1227{
1228 // Print CB Chain for each CB
1229 FILE* pOutFile;
1230 pOutFile = fopen(outFileName.c_str(), "w");
1231 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1232 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1233 GLOBAL_CB_NODE* pCB = NULL;
1234 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1235 pCB = g_pLastTouchedCB[i];
1236 if (pCB) {
1237 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1238 uint32_t instNum = 0;
1239 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1240 if (instNum) {
1241 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1242 }
1243 if (pCB == g_lastGlobalCB) {
1244 fprintf(pOutFile, "\"CB%pCMD%u\" [\nlabel=<<TABLE BGCOLOR=\"#00FF00\" BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD>CMD#</TD><TD>%u</TD></TR><TR><TD>CMD Type</TD><TD>%s</TD></TR></TABLE>>\n];\n", (void*)pCB->cmdBuffer, instNum, instNum, cmdTypeToString((*ii)->type).c_str());
1245 }
1246 else {
1247 fprintf(pOutFile, "\"CB%pCMD%u\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD>CMD#</TD><TD>%u</TD></TR><TR><TD>CMD Type</TD><TD>%s</TD></TR></TABLE>>\n];\n", (void*)pCB->cmdBuffer, instNum, instNum, cmdTypeToString((*ii)->type).c_str());
1248 }
1249 ++instNum;
1250 }
1251 fprintf(pOutFile, "}\n");
1252 }
1253 }
1254 fprintf(pOutFile, "}\n");
1255 fprintf(pOutFile, "}\n"); // close main graph "g"
1256 fclose(pOutFile);
1257}
1258// Dump a GraphViz dot file showing the pipeline for last bound global state
1259static void dumpGlobalDotFile(char *outFileName)
1260{
1261 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1262 if (pPipeTrav) {
1263 FILE* pOutFile;
1264 pOutFile = fopen(outFileName, "w");
1265 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1266 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1267 char* pGVstr = NULL;
1268 for (uint32_t i = 0; i < XGL_NUM_STATE_BIND_POINT; i++) {
1269 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
1270 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_XGL_STATE_BIND_POINT((XGL_STATE_BIND_POINT)i));
1271 fprintf(pOutFile, "%s", pGVstr);
1272 free(pGVstr);
1273 }
1274 }
1275 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1276 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Tobin Ehliscd3109e2015-04-01 11:59:08 -06001277 pGVstr = xgl_gv_print_xgl_graphics_pipeline_create_info(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001278 fprintf(pOutFile, "%s", pGVstr);
1279 free(pGVstr);
1280 fprintf(pOutFile, "}\n");
1281 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1282 fprintf(pOutFile, "}\n"); // close main graph "g"
1283 fclose(pOutFile);
1284 }
1285}
1286// Dump a GraphViz dot file showing the pipeline for a given CB
1287static void dumpDotFile(const XGL_CMD_BUFFER cb, string outFileName)
1288{
1289 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1290 if (pCB) {
1291 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1292 if (pPipeTrav) {
1293 FILE* pOutFile;
1294 pOutFile = fopen(outFileName.c_str(), "w");
1295 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1296 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1297 char* pGVstr = NULL;
1298 for (uint32_t i = 0; i < XGL_NUM_STATE_BIND_POINT; i++) {
1299 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
1300 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_XGL_STATE_BIND_POINT((XGL_STATE_BIND_POINT)i));
1301 fprintf(pOutFile, "%s", pGVstr);
1302 free(pGVstr);
1303 }
1304 }
1305 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1306 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Tobin Ehliscd3109e2015-04-01 11:59:08 -06001307 pGVstr = xgl_gv_print_xgl_graphics_pipeline_create_info(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001308 fprintf(pOutFile, "%s", pGVstr);
1309 free(pGVstr);
1310 fprintf(pOutFile, "}\n");
1311 dsDumpDot(cb, pOutFile);
1312 fprintf(pOutFile, "}\n"); // close main graph "g"
1313 fclose(pOutFile);
1314 }
1315 }
1316}
1317// Verify VB Buffer binding
1318static void validateVBBinding(const XGL_CMD_BUFFER cb)
1319{
1320 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1321 if (pCB && pCB->lastBoundPipeline) {
1322 // First verify that we have a Node for bound pipeline
1323 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1324 char str[1024];
1325 if (!pPipeTrav) {
1326 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
1327 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
1328 }
1329 else {
1330 // Verify Vtx binding
1331 if (MAX_BINDING != pCB->lastVtxBinding) {
1332 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1333 if (0 == pPipeTrav->vtxBindingCount) {
1334 sprintf(str, "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
1335 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
1336 }
1337 else {
1338 sprintf(str, "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
1339 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
1340 }
1341 }
1342 else {
1343 string tmpStr = xgl_print_xgl_vertex_input_binding_description(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
1344 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
1345 }
1346 }
1347 }
1348 }
1349}
1350// Print details of DS config to stdout
1351static void printDSConfig(const XGL_CMD_BUFFER cb)
1352{
1353 char tmp_str[1024];
1354 char ds_config_str[1024*256] = {0}; // TODO : Currently making this buffer HUGE w/o overrun protection. Need to be smarter, start smaller, and grow as needed.
1355 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1356 if (pCB) {
1357 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
1358 REGION_NODE* pRegion = getRegionNode(pSet->region);
1359 // Print out region details
1360 sprintf(tmp_str, "Details for region %p.", (void*)pRegion->region);
1361 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
1362 string regionStr = xgl_print_xgl_descriptor_region_create_info(&pRegion->createInfo, " ");
1363 sprintf(ds_config_str, "%s", regionStr.c_str());
1364 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
1365 // Print out set details
1366 char prefix[10];
1367 uint32_t index = 0;
1368 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
1369 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
1370 LAYOUT_NODE* pLayout = pSet->pLayouts;
1371 while (pLayout) {
1372 // Print layout details
1373 sprintf(tmp_str, "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
1374 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
1375 sprintf(prefix, " [L%u] ", index);
1376 string DSLstr = xgl_print_xgl_descriptor_set_layout_create_info(&pLayout->pCreateInfoList[0], prefix).c_str();
1377 sprintf(ds_config_str, "%s", DSLstr.c_str());
1378 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
1379 pLayout = pLayout->pPriorSetLayout;
1380 index++;
1381 }
1382 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1383 if (pUpdate) {
1384 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
1385 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
1386 sprintf(prefix, " [UC] ");
1387 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
1388 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
1389 // TODO : If there is a "view" associated with this update, print CI for that view
1390 }
1391 else {
1392 sprintf(tmp_str, "No Update Chain for descriptor set %p (xglUpdateDescriptors has not been called)", (void*)pSet->set);
1393 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
1394 }
1395 }
1396}
1397
1398static void printCB(const XGL_CMD_BUFFER cb)
1399{
1400 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1401 if (pCB) {
1402 char str[1024];
1403 sprintf(str, "Cmds in CB %p", (void*)cb);
1404 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
1405 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1406 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
1407 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
1408 }
1409 }
1410 else {
1411 // Nothing to print
1412 }
1413}
1414
1415
1416static void synchAndPrintDSConfig(const XGL_CMD_BUFFER cb)
1417{
1418 printDSConfig(cb);
1419 printPipeline(cb);
1420 printDynamicState(cb);
1421 static int autoDumpOnce = 0;
1422 if (autoDumpOnce) {
1423 autoDumpOnce = 0;
1424 dumpDotFile(cb, "pipeline_dump.dot");
1425 cbDumpDotFile("cb_dump.dot");
1426#if defined(_WIN32)
1427// FIXME: NEED WINDOWS EQUIVALENT
1428#else // WIN32
1429 // Convert dot to svg if dot available
1430 if(access( "/usr/bin/dot", X_OK) != -1) {
1431 system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1432 }
1433#endif // WIN32
1434 }
1435}
1436
1437static void initDrawState(void)
1438{
1439 const char *strOpt;
1440 // initialize DrawState options
1441 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1442 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1443
1444 if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)
1445 {
1446 strOpt = getLayerOption("DrawStateLogFilename");
1447 if (strOpt)
1448 {
1449 g_logFile = fopen(strOpt, "w");
1450 }
1451 if (g_logFile == NULL)
1452 g_logFile = stdout;
1453 }
1454 // initialize Layer dispatch table
1455 // TODO handle multiple GPUs
1456 xglGetProcAddrType fpNextGPA;
1457 fpNextGPA = pCurObj->pGPA;
1458 assert(fpNextGPA);
1459
1460 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);
1461
1462 xglGetProcAddrType fpGetProcAddr = (xglGetProcAddrType)fpNextGPA((XGL_PHYSICAL_GPU) pCurObj->nextObject, (char *) "xglGetProcAddr");
1463 nextTable.GetProcAddr = fpGetProcAddr;
1464
1465 if (!globalLockInitialized)
1466 {
1467 // TODO/TBD: Need to delete this mutex sometime. How??? One
1468 // suggestion is to call this during xglCreateInstance(), and then we
1469 // can clean it up during xglDestroyInstance(). However, that requires
1470 // that the layer have per-instance locks. We need to come back and
1471 // address this soon.
1472 loader_platform_thread_create_mutex(&globalLock);
1473 globalLockInitialized = 1;
1474 }
1475}
1476
1477XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDevice(XGL_PHYSICAL_GPU gpu, const XGL_DEVICE_CREATE_INFO* pCreateInfo, XGL_DEVICE* pDevice)
1478{
1479 XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
1480 pCurObj = gpuw;
1481 loader_platform_thread_once(&g_initOnce, initDrawState);
1482 XGL_RESULT result = nextTable.CreateDevice((XGL_PHYSICAL_GPU)gpuw->nextObject, pCreateInfo, pDevice);
1483 return result;
1484}
1485
1486XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDestroyDevice(XGL_DEVICE device)
1487{
1488 // Free all the memory
1489 loader_platform_thread_lock_mutex(&globalLock);
1490 freePipelines();
1491 freeSamplers();
1492 freeImages();
1493 freeBuffers();
1494 freeCmdBuffers();
1495 freeDynamicState();
1496 freeRegions();
1497 freeLayouts();
1498 loader_platform_thread_unlock_mutex(&globalLock);
1499 XGL_RESULT result = nextTable.DestroyDevice(device);
1500 return result;
1501}
1502
1503XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t maxLayerCount, size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
1504{
1505 if (gpu != NULL)
1506 {
1507 XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
1508 pCurObj = gpuw;
1509 loader_platform_thread_once(&g_initOnce, initDrawState);
1510 XGL_RESULT result = nextTable.EnumerateLayers((XGL_PHYSICAL_GPU)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
1511 return result;
1512 } else
1513 {
1514 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
1515 return XGL_ERROR_INVALID_POINTER;
1516 // This layer compatible with all GPUs
1517 *pOutLayerCount = 1;
1518 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
1519 return XGL_SUCCESS;
1520 }
1521}
1522
1523XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglQueueSubmit(XGL_QUEUE queue, uint32_t cmdBufferCount, const XGL_CMD_BUFFER* pCmdBuffers, uint32_t memRefCount, const XGL_MEMORY_REF* pMemRefs, XGL_FENCE fence)
1524{
1525 for (uint32_t i=0; i < cmdBufferCount; i++) {
1526 // Validate that cmd buffers have been updated
1527 }
1528 XGL_RESULT result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, memRefCount, pMemRefs, fence);
1529 return result;
1530}
1531
1532XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDestroyObject(XGL_OBJECT object)
1533{
1534 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
1535 XGL_RESULT result = nextTable.DestroyObject(object);
1536 return result;
1537}
1538
1539XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateBufferView(XGL_DEVICE device, const XGL_BUFFER_VIEW_CREATE_INFO* pCreateInfo, XGL_BUFFER_VIEW* pView)
1540{
1541 XGL_RESULT result = nextTable.CreateBufferView(device, pCreateInfo, pView);
1542 if (XGL_SUCCESS == result) {
1543 loader_platform_thread_lock_mutex(&globalLock);
1544 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1545 pNewNode->buffer = *pView;
1546 pNewNode->createInfo = *pCreateInfo;
1547 bufferMap[*pView] = pNewNode;
1548 loader_platform_thread_unlock_mutex(&globalLock);
1549 }
1550 return result;
1551}
1552
1553XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateImageView(XGL_DEVICE device, const XGL_IMAGE_VIEW_CREATE_INFO* pCreateInfo, XGL_IMAGE_VIEW* pView)
1554{
1555 XGL_RESULT result = nextTable.CreateImageView(device, pCreateInfo, pView);
1556 if (XGL_SUCCESS == result) {
1557 loader_platform_thread_lock_mutex(&globalLock);
1558 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1559 pNewNode->image = *pView;
1560 pNewNode->createInfo = *pCreateInfo;
1561 imageMap[*pView] = pNewNode;
1562 loader_platform_thread_unlock_mutex(&globalLock);
1563 }
1564 return result;
1565}
1566
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001567static void track_pipeline(const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo, XGL_PIPELINE* pPipeline)
1568{
1569 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1570 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1571 pPipeNode->pipeline = *pPipeline;
1572 initPipeline(pPipeNode, pCreateInfo);
1573}
1574
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001575XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipeline(XGL_DEVICE device, const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo, XGL_PIPELINE* pPipeline)
1576{
1577 XGL_RESULT result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
1578 // Create LL HEAD for this Pipeline
1579 char str[1024];
1580 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
1581 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, (XGL_BASE_OBJECT)pPipeline, 0, DRAWSTATE_NONE, "DS", str);
1582 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001583
1584 track_pipeline(pCreateInfo, pPipeline);
1585
1586 loader_platform_thread_unlock_mutex(&globalLock);
1587 return result;
1588}
1589
1590XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipelineDerivative(
1591 XGL_DEVICE device,
1592 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1593 XGL_PIPELINE basePipeline,
1594 XGL_PIPELINE* pPipeline)
1595{
1596 XGL_RESULT result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
1597 // Create LL HEAD for this Pipeline
1598 char str[1024];
1599 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
1600 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, (XGL_BASE_OBJECT)pPipeline, 0, DRAWSTATE_NONE, "DS", str);
1601 loader_platform_thread_lock_mutex(&globalLock);
1602
1603 track_pipeline(pCreateInfo, pPipeline);
1604
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001605 loader_platform_thread_unlock_mutex(&globalLock);
1606 return result;
1607}
1608
1609XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateSampler(XGL_DEVICE device, const XGL_SAMPLER_CREATE_INFO* pCreateInfo, XGL_SAMPLER* pSampler)
1610{
1611 XGL_RESULT result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
1612 if (XGL_SUCCESS == result) {
1613 loader_platform_thread_lock_mutex(&globalLock);
1614 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1615 pNewNode->sampler = *pSampler;
1616 pNewNode->createInfo = *pCreateInfo;
1617 sampleMap[*pSampler] = pNewNode;
1618 loader_platform_thread_unlock_mutex(&globalLock);
1619 }
1620 return result;
1621}
1622
1623XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDescriptorSetLayout(XGL_DEVICE device, XGL_FLAGS stageFlags, const uint32_t* pSetBindPoints, XGL_DESCRIPTOR_SET_LAYOUT priorSetLayout, const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pSetLayoutInfoList, XGL_DESCRIPTOR_SET_LAYOUT* pSetLayout)
1624{
1625 XGL_RESULT result = nextTable.CreateDescriptorSetLayout(device, stageFlags, pSetBindPoints, priorSetLayout, pSetLayoutInfoList, pSetLayout);
1626 if (XGL_SUCCESS == result) {
1627 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1628 if (NULL == pNewNode) {
1629 char str[1024];
1630 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in xglCreateDescriptorSetLayout()");
1631 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
1632 }
1633 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
1634 // TODO : API Currently missing a count here that we should multiply by struct size
1635 pNewNode->pCreateInfoList = new XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1636 memset((void*)pNewNode->pCreateInfoList, 0, sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO));
1637 void* pCITrav = NULL;
1638 uint32_t totalCount = 0;
1639 if (pSetLayoutInfoList) {
1640 memcpy((void*)pNewNode->pCreateInfoList, pSetLayoutInfoList, sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO));
1641 pCITrav = (void*)pSetLayoutInfoList->pNext;
1642 totalCount = pSetLayoutInfoList->count;
1643 }
1644 void** ppNext = (void**)&pNewNode->pCreateInfoList->pNext;
1645 while (pCITrav) {
1646 totalCount += ((XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pCITrav)->count;
1647 *ppNext = new XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1648 memcpy((void*)*ppNext, pCITrav, sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO));
1649 pCITrav = (void*)((XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pCITrav)->pNext;
1650 ppNext = (void**)&((XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)*ppNext)->pNext;
1651 }
1652 if (totalCount > 0) {
1653 pNewNode->pTypes = new XGL_DESCRIPTOR_TYPE[totalCount];
1654 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pLCI = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pSetLayoutInfoList;
1655 uint32_t offset = 0;
1656 uint32_t i = 0;
1657 while (pLCI) {
1658 for (i = 0; i < pLCI->count; i++) {
1659 pNewNode->pTypes[offset + i] = pLCI->descriptorType;
1660 }
1661 offset += i;
1662 pLCI = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pLCI->pNext;
1663 }
1664 }
1665 pNewNode->layout = *pSetLayout;
1666 pNewNode->stageFlags = stageFlags;
1667 uint32_t i = (XGL_SHADER_STAGE_FLAGS_ALL == stageFlags) ? 0 : XGL_SHADER_STAGE_COMPUTE;
1668 for (uint32_t stage = XGL_SHADER_STAGE_FLAGS_COMPUTE_BIT; stage > 0; stage >>= 1) {
1669 assert(i < XGL_NUM_SHADER_STAGE);
1670 if (stage & stageFlags)
1671 pNewNode->shaderStageBindPoints[i] = pSetBindPoints[i];
1672 i = (i == 0) ? 0 : (i-1);
1673 }
1674 pNewNode->startIndex = 0;
1675 LAYOUT_NODE* pPriorNode = getLayoutNode(priorSetLayout);
1676 // Point to prior node or NULL if no prior node
1677 if (NULL != priorSetLayout && pPriorNode == NULL) {
1678 char str[1024];
1679 sprintf(str, "Invalid priorSetLayout of %p passed to xglCreateDescriptorSetLayout()", (void*)priorSetLayout);
1680 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, priorSetLayout, 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
1681 }
1682 else if (pPriorNode != NULL) { // We have a node for a valid prior layout
1683 // Get count for prior layout
1684 pNewNode->startIndex = pPriorNode->endIndex + 1;
1685 }
1686 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1687 assert(pNewNode->endIndex >= pNewNode->startIndex);
1688 pNewNode->pPriorSetLayout = pPriorNode;
1689 // Put new node at Head of global Layer list
1690 loader_platform_thread_lock_mutex(&globalLock);
1691 layoutMap[*pSetLayout] = pNewNode;
1692 loader_platform_thread_unlock_mutex(&globalLock);
1693 }
1694 return result;
1695}
1696
1697XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglBeginDescriptorRegionUpdate(XGL_DEVICE device, XGL_DESCRIPTOR_UPDATE_MODE updateMode)
1698{
1699 XGL_RESULT result = nextTable.BeginDescriptorRegionUpdate(device, updateMode);
1700 if (XGL_SUCCESS == result) {
1701 loader_platform_thread_lock_mutex(&globalLock);
1702 REGION_NODE* pRegionNode = regionMap.begin()->second;
1703 if (!pRegionNode) {
1704 char str[1024];
1705 sprintf(str, "Unable to find region node");
1706 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
1707 }
1708 else {
1709 pRegionNode->updateActive = 1;
1710 }
1711 loader_platform_thread_unlock_mutex(&globalLock);
1712 }
1713 return result;
1714}
1715
1716XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEndDescriptorRegionUpdate(XGL_DEVICE device, XGL_CMD_BUFFER cmd)
1717{
1718 XGL_RESULT result = nextTable.EndDescriptorRegionUpdate(device, cmd);
1719 if (XGL_SUCCESS == result) {
1720 loader_platform_thread_lock_mutex(&globalLock);
1721 REGION_NODE* pRegionNode = regionMap.begin()->second;
1722 if (!pRegionNode) {
1723 char str[1024];
1724 sprintf(str, "Unable to find region node");
1725 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
1726 }
1727 else {
1728 if (!pRegionNode->updateActive) {
1729 char str[1024];
1730 sprintf(str, "You must call xglBeginDescriptorRegionUpdate() before this call to xglEndDescriptorRegionUpdate()!");
1731 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_DS_END_WITHOUT_BEGIN, "DS", str);
1732 }
1733 else {
1734 pRegionNode->updateActive = 0;
1735 }
1736 pRegionNode->updateActive = 0;
1737 }
1738 loader_platform_thread_unlock_mutex(&globalLock);
1739 }
1740 return result;
1741}
1742
1743XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDescriptorRegion(XGL_DEVICE device, XGL_DESCRIPTOR_REGION_USAGE regionUsage, uint32_t maxSets, const XGL_DESCRIPTOR_REGION_CREATE_INFO* pCreateInfo, XGL_DESCRIPTOR_REGION* pDescriptorRegion)
1744{
1745 XGL_RESULT result = nextTable.CreateDescriptorRegion(device, regionUsage, maxSets, pCreateInfo, pDescriptorRegion);
1746 if (XGL_SUCCESS == result) {
1747 // Insert this region into Global Region LL at head
1748 char str[1024];
1749 sprintf(str, "Created Descriptor Region %p", (void*)*pDescriptorRegion);
1750 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, (XGL_BASE_OBJECT)pDescriptorRegion, 0, DRAWSTATE_NONE, "DS", str);
1751 loader_platform_thread_lock_mutex(&globalLock);
1752 REGION_NODE* pNewNode = new REGION_NODE;
1753 if (NULL == pNewNode) {
1754 char str[1024];
1755 sprintf(str, "Out of memory while attempting to allocate REGION_NODE in xglCreateDescriptorRegion()");
1756 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, (XGL_BASE_OBJECT)*pDescriptorRegion, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
1757 }
1758 else {
1759 memset(pNewNode, 0, sizeof(REGION_NODE));
1760 XGL_DESCRIPTOR_REGION_CREATE_INFO* pCI = (XGL_DESCRIPTOR_REGION_CREATE_INFO*)&pNewNode->createInfo;
1761 memcpy((void*)pCI, pCreateInfo, sizeof(XGL_DESCRIPTOR_REGION_CREATE_INFO));
1762 if (pNewNode->createInfo.count) {
1763 size_t typeCountSize = pNewNode->createInfo.count * sizeof(XGL_DESCRIPTOR_TYPE_COUNT);
1764 pNewNode->createInfo.pTypeCount = new XGL_DESCRIPTOR_TYPE_COUNT[typeCountSize];
1765 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1766 }
1767 pNewNode->regionUsage = regionUsage;
1768 pNewNode->updateActive = 0;
1769 pNewNode->maxSets = maxSets;
1770 pNewNode->region = *pDescriptorRegion;
1771 regionMap[*pDescriptorRegion] = pNewNode;
1772 }
1773 loader_platform_thread_unlock_mutex(&globalLock);
1774 }
1775 else {
1776 // Need to do anything if region create fails?
1777 }
1778 return result;
1779}
1780
1781XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglClearDescriptorRegion(XGL_DESCRIPTOR_REGION descriptorRegion)
1782{
1783 XGL_RESULT result = nextTable.ClearDescriptorRegion(descriptorRegion);
1784 if (XGL_SUCCESS == result) {
1785 clearDescriptorRegion(descriptorRegion);
1786 }
1787 return result;
1788}
1789
1790XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglAllocDescriptorSets(XGL_DESCRIPTOR_REGION descriptorRegion, XGL_DESCRIPTOR_SET_USAGE setUsage, uint32_t count, const XGL_DESCRIPTOR_SET_LAYOUT* pSetLayouts, XGL_DESCRIPTOR_SET* pDescriptorSets, uint32_t* pCount)
1791{
1792 XGL_RESULT result = nextTable.AllocDescriptorSets(descriptorRegion, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
1793 if ((XGL_SUCCESS == result) || (*pCount > 0)) {
1794 REGION_NODE *pRegionNode = getRegionNode(descriptorRegion);
1795 if (!pRegionNode) {
1796 char str[1024];
1797 sprintf(str, "Unable to find region node for region %p specified in xglAllocDescriptorSets() call", (void*)descriptorRegion);
1798 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, descriptorRegion, 0, DRAWSTATE_INVALID_REGION, "DS", str);
1799 }
1800 else {
1801 for (uint32_t i = 0; i < *pCount; i++) {
1802 char str[1024];
1803 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
1804 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
1805 // Create new set node and add to head of region nodes
1806 SET_NODE* pNewNode = new SET_NODE;
1807 if (NULL == pNewNode) {
1808 char str[1024];
1809 sprintf(str, "Out of memory while attempting to allocate SET_NODE in xglAllocDescriptorSets()");
1810 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
1811 }
1812 else {
1813 memset(pNewNode, 0, sizeof(SET_NODE));
1814 // Insert set at head of Set LL for this region
1815 pNewNode->pNext = pRegionNode->pSets;
1816 pRegionNode->pSets = pNewNode;
1817 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1818 if (NULL == pLayout) {
1819 char str[1024];
1820 sprintf(str, "Unable to find set layout node for layout %p specified in xglAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1821 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
1822 }
1823 pNewNode->pLayouts = pLayout;
1824 pNewNode->region = descriptorRegion;
1825 pNewNode->set = pDescriptorSets[i];
1826 pNewNode->setUsage = setUsage;
1827 pNewNode->descriptorCount = pLayout->endIndex + 1;
1828 if (pNewNode->descriptorCount) {
1829 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1830 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1831 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1832 }
1833 setMap[pDescriptorSets[i]] = pNewNode;
1834 }
1835 }
1836 }
1837 }
1838 return result;
1839}
1840
1841XGL_LAYER_EXPORT void XGLAPI xglClearDescriptorSets(XGL_DESCRIPTOR_REGION descriptorRegion, uint32_t count, const XGL_DESCRIPTOR_SET* pDescriptorSets)
1842{
1843 for (uint32_t i = 0; i < count; i++) {
1844 clearDescriptorSet(pDescriptorSets[i]);
1845 }
1846 nextTable.ClearDescriptorSets(descriptorRegion, count, pDescriptorSets);
1847}
1848
1849XGL_LAYER_EXPORT void XGLAPI xglUpdateDescriptors(XGL_DESCRIPTOR_SET descriptorSet, const void* pUpdateChain)
1850{
1851 SET_NODE* pSet = getSetNode(descriptorSet);
1852 if (!dsUpdateActive(descriptorSet)) {
1853 char str[1024];
1854 sprintf(str, "You must call xglBeginDescriptorRegionUpdate() before this call to xglUpdateDescriptors()!");
1855 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pSet->region, 0, DRAWSTATE_UPDATE_WITHOUT_BEGIN, "DS", str);
1856 }
1857 else {
1858 // pUpdateChain is a Linked-list of XGL_UPDATE_* structures defining the mappings for the descriptors
1859 dsUpdate(descriptorSet, (GENERIC_HEADER*)pUpdateChain);
1860 }
1861
1862 nextTable.UpdateDescriptors(descriptorSet, pUpdateChain);
1863}
1864
1865XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicViewportState(XGL_DEVICE device, const XGL_DYNAMIC_VP_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_VP_STATE_OBJECT* pState)
1866{
1867 XGL_RESULT result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
1868 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_VIEWPORT);
1869 return result;
1870}
1871
1872XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicRasterState(XGL_DEVICE device, const XGL_DYNAMIC_RS_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_RS_STATE_OBJECT* pState)
1873{
1874 XGL_RESULT result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
1875 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_RASTER);
1876 return result;
1877}
1878
1879XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicColorBlendState(XGL_DEVICE device, const XGL_DYNAMIC_CB_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_CB_STATE_OBJECT* pState)
1880{
1881 XGL_RESULT result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
1882 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_COLOR_BLEND);
1883 return result;
1884}
1885
1886XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicDepthStencilState(XGL_DEVICE device, const XGL_DYNAMIC_DS_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_DS_STATE_OBJECT* pState)
1887{
1888 XGL_RESULT result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
1889 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_DEPTH_STENCIL);
1890 return result;
1891}
1892
1893XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateCommandBuffer(XGL_DEVICE device, const XGL_CMD_BUFFER_CREATE_INFO* pCreateInfo, XGL_CMD_BUFFER* pCmdBuffer)
1894{
1895 XGL_RESULT result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
1896 if (XGL_SUCCESS == result) {
1897 loader_platform_thread_lock_mutex(&globalLock);
1898 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1899 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1900 pCB->cmdBuffer = *pCmdBuffer;
1901 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001902 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 pCB->lastVtxBinding = MAX_BINDING;
1904 cmdBufferMap[*pCmdBuffer] = pCB;
1905 loader_platform_thread_unlock_mutex(&globalLock);
1906 updateCBTracking(*pCmdBuffer);
1907 }
1908 return result;
1909}
1910
1911XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglBeginCommandBuffer(XGL_CMD_BUFFER cmdBuffer, const XGL_CMD_BUFFER_BEGIN_INFO* pBeginInfo)
1912{
1913 XGL_RESULT result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
1914 if (XGL_SUCCESS == result) {
1915 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1916 if (pCB) {
1917 if (CB_NEW != pCB->state)
1918 resetCB(cmdBuffer);
1919 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001920 if (pBeginInfo->pNext) {
1921 XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO* pCbGfxBI = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)pBeginInfo->pNext;
1922 if (XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001923 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001924 }
1925 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001926 }
1927 else {
1928 char str[1024];
1929 sprintf(str, "In xglBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1930 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
1931 }
1932 updateCBTracking(cmdBuffer);
1933 }
1934 return result;
1935}
1936
1937XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEndCommandBuffer(XGL_CMD_BUFFER cmdBuffer)
1938{
1939 XGL_RESULT result = nextTable.EndCommandBuffer(cmdBuffer);
1940 if (XGL_SUCCESS == result) {
1941 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1942 if (pCB) {
1943 pCB->state = CB_UPDATE_COMPLETE;
1944 printCB(cmdBuffer);
1945 }
1946 else {
1947 char str[1024];
1948 sprintf(str, "In xglEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1949 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
1950 }
1951 updateCBTracking(cmdBuffer);
1952 //cbDumpDotFile("cb_dump.dot");
1953 }
1954 return result;
1955}
1956
1957XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglResetCommandBuffer(XGL_CMD_BUFFER cmdBuffer)
1958{
1959 XGL_RESULT result = nextTable.ResetCommandBuffer(cmdBuffer);
1960 if (XGL_SUCCESS == result) {
1961 resetCB(cmdBuffer);
1962 updateCBTracking(cmdBuffer);
1963 }
1964 return result;
1965}
1966
1967XGL_LAYER_EXPORT void XGLAPI xglCmdBindPipeline(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, XGL_PIPELINE pipeline)
1968{
1969 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1970 if (pCB) {
1971 updateCBTracking(cmdBuffer);
1972 addCmd(pCB, CMD_BINDPIPELINE);
1973 PIPELINE_NODE* pPN = getPipeline(pipeline);
1974 if (pPN) {
1975 pCB->lastBoundPipeline = pipeline;
1976 loader_platform_thread_lock_mutex(&globalLock);
1977 g_lastBoundPipeline = pPN;
1978 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001979 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001980 }
1981 else {
1982 char str[1024];
1983 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
1984 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
1985 }
1986 }
1987 else {
1988 char str[1024];
1989 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
1990 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
1991 }
1992 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1993}
1994
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001995XGL_LAYER_EXPORT void XGLAPI xglCmdBindDynamicStateObject(XGL_CMD_BUFFER cmdBuffer, XGL_STATE_BIND_POINT stateBindPoint, XGL_DYNAMIC_STATE_OBJECT state)
1996{
1997 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
1998 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
1999}
2000
2001XGL_LAYER_EXPORT void XGLAPI xglCmdBindDescriptorSet(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, XGL_DESCRIPTOR_SET descriptorSet, const uint32_t* pUserData)
2002{
2003 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2004 if (pCB) {
2005 updateCBTracking(cmdBuffer);
2006 addCmd(pCB, CMD_BINDDESCRIPTORSET);
2007 if (getSetNode(descriptorSet)) {
2008 if (dsUpdateActive(descriptorSet)) {
2009 // TODO : This check here needs to be made at QueueSubmit time
2010/*
2011 char str[1024];
2012 sprintf(str, "You must call xglEndDescriptorRegionUpdate(%p) before this call to xglCmdBindDescriptorSet()!", (void*)descriptorSet);
2013 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_BINDING_DS_NO_END_UPDATE, "DS", str);
2014*/
2015 }
2016 loader_platform_thread_lock_mutex(&globalLock);
2017 pCB->lastBoundDescriptorSet = descriptorSet;
2018 g_lastBoundDescriptorSet = descriptorSet;
2019 loader_platform_thread_unlock_mutex(&globalLock);
2020 char str[1024];
2021 sprintf(str, "DS %p bound on pipeline %s", (void*)descriptorSet, string_XGL_PIPELINE_BIND_POINT(pipelineBindPoint));
2022 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_NONE, "DS", str);
2023 synchAndPrintDSConfig(cmdBuffer);
2024 }
2025 else {
2026 char str[1024];
2027 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)descriptorSet);
2028 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_INVALID_SET, "DS", str);
2029 }
2030 }
2031 else {
2032 char str[1024];
2033 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2034 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2035 }
2036 nextTable.CmdBindDescriptorSet(cmdBuffer, pipelineBindPoint, descriptorSet, pUserData);
2037}
2038
2039XGL_LAYER_EXPORT void XGLAPI xglCmdBindIndexBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, XGL_INDEX_TYPE indexType)
2040{
2041 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2042 if (pCB) {
2043 updateCBTracking(cmdBuffer);
2044 addCmd(pCB, CMD_BINDINDEXBUFFER);
2045 // TODO : Track idxBuffer binding
2046 }
2047 else {
2048 char str[1024];
2049 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2050 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2051 }
2052 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2053}
2054
2055XGL_LAYER_EXPORT void XGLAPI xglCmdBindVertexBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, uint32_t binding)
2056{
2057 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2058 if (pCB) {
2059 updateCBTracking(cmdBuffer);
2060 addCmd(pCB, CMD_BINDVERTEXBUFFER);
2061 pCB->lastVtxBinding = binding;
2062 validateVBBinding(cmdBuffer);
2063 }
2064 else {
2065 char str[1024];
2066 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2067 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2068 }
2069 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
2070}
2071
2072XGL_LAYER_EXPORT void XGLAPI xglCmdDraw(XGL_CMD_BUFFER cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
2073{
2074 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2075 if (pCB) {
2076 updateCBTracking(cmdBuffer);
2077 addCmd(pCB, CMD_DRAW);
2078 pCB->drawCount[DRAW]++;
2079 char str[1024];
2080 sprintf(str, "xglCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2081 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2082 synchAndPrintDSConfig(cmdBuffer);
2083 }
2084 else {
2085 char str[1024];
2086 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2087 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2088 }
2089 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2090}
2091
2092XGL_LAYER_EXPORT void XGLAPI xglCmdDrawIndexed(XGL_CMD_BUFFER cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
2093{
2094 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2095 if (pCB) {
2096 updateCBTracking(cmdBuffer);
2097 addCmd(pCB, CMD_DRAWINDEXED);
2098 pCB->drawCount[DRAW_INDEXED]++;
2099 char str[1024];
2100 sprintf(str, "xglCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2101 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2102 synchAndPrintDSConfig(cmdBuffer);
2103 }
2104 else {
2105 char str[1024];
2106 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2107 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2108 }
2109 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2110}
2111
2112XGL_LAYER_EXPORT void XGLAPI xglCmdDrawIndirect(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, uint32_t count, uint32_t stride)
2113{
2114 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2115 if (pCB) {
2116 updateCBTracking(cmdBuffer);
2117 addCmd(pCB, CMD_DRAWINDIRECT);
2118 pCB->drawCount[DRAW_INDIRECT]++;
2119 char str[1024];
2120 sprintf(str, "xglCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2121 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2122 synchAndPrintDSConfig(cmdBuffer);
2123 }
2124 else {
2125 char str[1024];
2126 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2127 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2128 }
2129 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2130}
2131
2132XGL_LAYER_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, uint32_t count, uint32_t stride)
2133{
2134 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2135 if (pCB) {
2136 updateCBTracking(cmdBuffer);
2137 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2138 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2139 char str[1024];
2140 sprintf(str, "xglCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2141 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2142 synchAndPrintDSConfig(cmdBuffer);
2143 }
2144 else {
2145 char str[1024];
2146 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2147 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2148 }
2149 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2150}
2151
2152XGL_LAYER_EXPORT void XGLAPI xglCmdDispatch(XGL_CMD_BUFFER cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
2153{
2154 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2155 if (pCB) {
2156 updateCBTracking(cmdBuffer);
2157 addCmd(pCB, CMD_DISPATCH);
2158 }
2159 else {
2160 char str[1024];
2161 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2162 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2163 }
2164 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2165}
2166
2167XGL_LAYER_EXPORT void XGLAPI xglCmdDispatchIndirect(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset)
2168{
2169 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2170 if (pCB) {
2171 updateCBTracking(cmdBuffer);
2172 addCmd(pCB, CMD_DISPATCHINDIRECT);
2173 }
2174 else {
2175 char str[1024];
2176 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2177 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2178 }
2179 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2180}
2181
2182XGL_LAYER_EXPORT void XGLAPI xglCmdCopyBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER srcBuffer, XGL_BUFFER destBuffer, uint32_t regionCount, const XGL_BUFFER_COPY* pRegions)
2183{
2184 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2185 if (pCB) {
2186 updateCBTracking(cmdBuffer);
2187 addCmd(pCB, CMD_COPYBUFFER);
2188 }
2189 else {
2190 char str[1024];
2191 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2192 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2193 }
2194 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2195}
2196
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002197XGL_LAYER_EXPORT void XGLAPI xglCmdCopyImage(
2198 XGL_CMD_BUFFER cmdBuffer,
2199 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2200 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2201 uint32_t regionCount, const XGL_IMAGE_COPY* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002202{
2203 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2204 if (pCB) {
2205 updateCBTracking(cmdBuffer);
2206 addCmd(pCB, CMD_COPYIMAGE);
2207 }
2208 else {
2209 char str[1024];
2210 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2211 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2212 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002213 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002214}
2215
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002216XGL_LAYER_EXPORT void XGLAPI xglCmdBlitImage(XGL_CMD_BUFFER cmdBuffer,
2217 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2218 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2219 uint32_t regionCount, const XGL_IMAGE_BLIT* pRegions)
2220{
2221 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2222 if (pCB) {
2223 updateCBTracking(cmdBuffer);
2224 addCmd(pCB, CMD_COPYIMAGE);
2225 }
2226 else {
2227 char str[1024];
2228 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2229 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2230 }
2231 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2232}
2233
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002234XGL_LAYER_EXPORT void XGLAPI xglCmdCopyBufferToImage(
2235 XGL_CMD_BUFFER cmdBuffer,
2236 XGL_BUFFER srcBuffer,
2237 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2238 uint32_t regionCount, const XGL_BUFFER_IMAGE_COPY* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002239{
2240 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2241 if (pCB) {
2242 updateCBTracking(cmdBuffer);
2243 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2244 }
2245 else {
2246 char str[1024];
2247 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2248 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2249 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002250 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002251}
2252
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002253XGL_LAYER_EXPORT void XGLAPI xglCmdCopyImageToBuffer(
2254 XGL_CMD_BUFFER cmdBuffer,
2255 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2256 XGL_BUFFER destBuffer,
2257 uint32_t regionCount, const XGL_BUFFER_IMAGE_COPY* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002258{
2259 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2260 if (pCB) {
2261 updateCBTracking(cmdBuffer);
2262 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2263 }
2264 else {
2265 char str[1024];
2266 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2267 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2268 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002269 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002270}
2271
2272XGL_LAYER_EXPORT void XGLAPI xglCmdCloneImageData(XGL_CMD_BUFFER cmdBuffer, XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout, XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout)
2273{
2274 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2275 if (pCB) {
2276 updateCBTracking(cmdBuffer);
2277 addCmd(pCB, CMD_CLONEIMAGEDATA);
2278 }
2279 else {
2280 char str[1024];
2281 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2282 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2283 }
2284 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2285}
2286
2287XGL_LAYER_EXPORT void XGLAPI xglCmdUpdateBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER destBuffer, XGL_GPU_SIZE destOffset, XGL_GPU_SIZE dataSize, const uint32_t* pData)
2288{
2289 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2290 if (pCB) {
2291 updateCBTracking(cmdBuffer);
2292 addCmd(pCB, CMD_UPDATEBUFFER);
2293 }
2294 else {
2295 char str[1024];
2296 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2297 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2298 }
2299 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2300}
2301
2302XGL_LAYER_EXPORT void XGLAPI xglCmdFillBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER destBuffer, XGL_GPU_SIZE destOffset, XGL_GPU_SIZE fillSize, uint32_t data)
2303{
2304 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2305 if (pCB) {
2306 updateCBTracking(cmdBuffer);
2307 addCmd(pCB, CMD_FILLBUFFER);
2308 }
2309 else {
2310 char str[1024];
2311 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2312 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2313 }
2314 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2315}
2316
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002317XGL_LAYER_EXPORT void XGLAPI xglCmdClearColorImage(
2318 XGL_CMD_BUFFER cmdBuffer,
2319 XGL_IMAGE image, XGL_IMAGE_LAYOUT imageLayout,
2320 XGL_CLEAR_COLOR color,
2321 uint32_t rangeCount, const XGL_IMAGE_SUBRESOURCE_RANGE* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002322{
2323 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2324 if (pCB) {
2325 updateCBTracking(cmdBuffer);
2326 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2327 }
2328 else {
2329 char str[1024];
2330 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2331 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2332 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002333 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002334}
2335
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002336XGL_LAYER_EXPORT void XGLAPI xglCmdClearDepthStencil(
2337 XGL_CMD_BUFFER cmdBuffer,
2338 XGL_IMAGE image, XGL_IMAGE_LAYOUT imageLayout,
2339 float depth, uint32_t stencil,
2340 uint32_t rangeCount, const XGL_IMAGE_SUBRESOURCE_RANGE* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002341{
2342 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2343 if (pCB) {
2344 updateCBTracking(cmdBuffer);
2345 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2346 }
2347 else {
2348 char str[1024];
2349 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2350 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2351 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002352 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002353}
2354
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002355XGL_LAYER_EXPORT void XGLAPI xglCmdResolveImage(
2356 XGL_CMD_BUFFER cmdBuffer,
2357 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2358 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2359 uint32_t rectCount, const XGL_IMAGE_RESOLVE* pRects)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002360{
2361 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2362 if (pCB) {
2363 updateCBTracking(cmdBuffer);
2364 addCmd(pCB, CMD_RESOLVEIMAGE);
2365 }
2366 else {
2367 char str[1024];
2368 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2369 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2370 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002371 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, rectCount, pRects);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002372}
2373
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002374XGL_LAYER_EXPORT void XGLAPI xglCmdSetEvent(XGL_CMD_BUFFER cmdBuffer, XGL_EVENT event, XGL_PIPE_EVENT pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002375{
2376 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2377 if (pCB) {
2378 updateCBTracking(cmdBuffer);
2379 addCmd(pCB, CMD_SETEVENT);
2380 }
2381 else {
2382 char str[1024];
2383 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2384 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2385 }
2386 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2387}
2388
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002389XGL_LAYER_EXPORT void XGLAPI xglCmdResetEvent(XGL_CMD_BUFFER cmdBuffer, XGL_EVENT event, XGL_PIPE_EVENT pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002390{
2391 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2392 if (pCB) {
2393 updateCBTracking(cmdBuffer);
2394 addCmd(pCB, CMD_RESETEVENT);
2395 }
2396 else {
2397 char str[1024];
2398 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2399 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2400 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002401 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002402}
2403
2404XGL_LAYER_EXPORT void XGLAPI xglCmdWaitEvents(XGL_CMD_BUFFER cmdBuffer, const XGL_EVENT_WAIT_INFO* pWaitInfo)
2405{
2406 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2407 if (pCB) {
2408 updateCBTracking(cmdBuffer);
2409 addCmd(pCB, CMD_WAITEVENTS);
2410 }
2411 else {
2412 char str[1024];
2413 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2414 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2415 }
2416 nextTable.CmdWaitEvents(cmdBuffer, pWaitInfo);
2417}
2418
2419XGL_LAYER_EXPORT void XGLAPI xglCmdPipelineBarrier(XGL_CMD_BUFFER cmdBuffer, const XGL_PIPELINE_BARRIER* pBarrier)
2420{
2421 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2422 if (pCB) {
2423 updateCBTracking(cmdBuffer);
2424 addCmd(pCB, CMD_PIPELINEBARRIER);
2425 }
2426 else {
2427 char str[1024];
2428 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2429 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2430 }
2431 nextTable.CmdPipelineBarrier(cmdBuffer, pBarrier);
2432}
2433
2434XGL_LAYER_EXPORT void XGLAPI xglCmdBeginQuery(XGL_CMD_BUFFER cmdBuffer, XGL_QUERY_POOL queryPool, uint32_t slot, XGL_FLAGS flags)
2435{
2436 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2437 if (pCB) {
2438 updateCBTracking(cmdBuffer);
2439 addCmd(pCB, CMD_BEGINQUERY);
2440 }
2441 else {
2442 char str[1024];
2443 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2444 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2445 }
2446 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2447}
2448
2449XGL_LAYER_EXPORT void XGLAPI xglCmdEndQuery(XGL_CMD_BUFFER cmdBuffer, XGL_QUERY_POOL queryPool, uint32_t slot)
2450{
2451 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2452 if (pCB) {
2453 updateCBTracking(cmdBuffer);
2454 addCmd(pCB, CMD_ENDQUERY);
2455 }
2456 else {
2457 char str[1024];
2458 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2459 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2460 }
2461 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2462}
2463
2464XGL_LAYER_EXPORT void XGLAPI xglCmdResetQueryPool(XGL_CMD_BUFFER cmdBuffer, XGL_QUERY_POOL queryPool, uint32_t startQuery, uint32_t queryCount)
2465{
2466 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2467 if (pCB) {
2468 updateCBTracking(cmdBuffer);
2469 addCmd(pCB, CMD_RESETQUERYPOOL);
2470 }
2471 else {
2472 char str[1024];
2473 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2474 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2475 }
2476 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2477}
2478
2479XGL_LAYER_EXPORT void XGLAPI xglCmdWriteTimestamp(XGL_CMD_BUFFER cmdBuffer, XGL_TIMESTAMP_TYPE timestampType, XGL_BUFFER destBuffer, XGL_GPU_SIZE destOffset)
2480{
2481 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2482 if (pCB) {
2483 updateCBTracking(cmdBuffer);
2484 addCmd(pCB, CMD_WRITETIMESTAMP);
2485 }
2486 else {
2487 char str[1024];
2488 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2489 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2490 }
2491 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2492}
2493
2494XGL_LAYER_EXPORT void XGLAPI xglCmdInitAtomicCounters(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
2495{
2496 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2497 if (pCB) {
2498 updateCBTracking(cmdBuffer);
2499 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2500 }
2501 else {
2502 char str[1024];
2503 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2504 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2505 }
2506 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2507}
2508
2509XGL_LAYER_EXPORT void XGLAPI xglCmdLoadAtomicCounters(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, XGL_BUFFER srcBuffer, XGL_GPU_SIZE srcOffset)
2510{
2511 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2512 if (pCB) {
2513 updateCBTracking(cmdBuffer);
2514 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2515 }
2516 else {
2517 char str[1024];
2518 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2519 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2520 }
2521 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2522}
2523
2524XGL_LAYER_EXPORT void XGLAPI xglCmdSaveAtomicCounters(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, XGL_BUFFER destBuffer, XGL_GPU_SIZE destOffset)
2525{
2526 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2527 if (pCB) {
2528 updateCBTracking(cmdBuffer);
2529 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2530 }
2531 else {
2532 char str[1024];
2533 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2534 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2535 }
2536 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2537}
2538
Tobin Ehlis2464b882015-04-01 08:40:34 -06002539XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateFramebuffer(XGL_DEVICE device, const XGL_FRAMEBUFFER_CREATE_INFO* pCreateInfo, XGL_FRAMEBUFFER* pFramebuffer)
2540{
2541 XGL_RESULT result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
2542 if (XGL_SUCCESS == result) {
2543 // Shadow create info and store in map
2544 XGL_FRAMEBUFFER_CREATE_INFO* localFBCI = new XGL_FRAMEBUFFER_CREATE_INFO(*pCreateInfo);
2545 if (pCreateInfo->pColorAttachments) {
2546 localFBCI->pColorAttachments = new XGL_COLOR_ATTACHMENT_BIND_INFO[localFBCI->colorAttachmentCount];
2547 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(XGL_COLOR_ATTACHMENT_BIND_INFO));
2548 }
2549 if (pCreateInfo->pDepthStencilAttachment) {
2550 localFBCI->pDepthStencilAttachment = new XGL_DEPTH_STENCIL_BIND_INFO[localFBCI->colorAttachmentCount];
2551 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(XGL_DEPTH_STENCIL_BIND_INFO));
2552 }
2553 frameBufferMap[*pFramebuffer] = localFBCI;
2554 }
2555 return result;
2556}
2557
2558XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateRenderPass(XGL_DEVICE device, const XGL_RENDER_PASS_CREATE_INFO* pCreateInfo, XGL_RENDER_PASS* pRenderPass)
2559{
2560 XGL_RESULT result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
2561 if (XGL_SUCCESS == result) {
2562 // Shadow create info and store in map
2563 XGL_RENDER_PASS_CREATE_INFO* localRPCI = new XGL_RENDER_PASS_CREATE_INFO(*pCreateInfo);
2564 if (pCreateInfo->pColorLoadOps) {
2565 localRPCI->pColorLoadOps = new XGL_ATTACHMENT_LOAD_OP[localRPCI->colorAttachmentCount];
2566 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(XGL_ATTACHMENT_LOAD_OP));
2567 }
2568 if (pCreateInfo->pColorStoreOps) {
2569 localRPCI->pColorStoreOps = new XGL_ATTACHMENT_STORE_OP[localRPCI->colorAttachmentCount];
2570 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(XGL_ATTACHMENT_STORE_OP));
2571 }
2572 if (pCreateInfo->pColorLoadClearValues) {
2573 localRPCI->pColorLoadClearValues = new XGL_CLEAR_COLOR[localRPCI->colorAttachmentCount];
2574 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(XGL_CLEAR_COLOR));
2575 }
2576 renderPassMap[*pRenderPass] = localRPCI;
2577 }
2578 return result;
2579}
2580
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002581XGL_LAYER_EXPORT void XGLAPI xglCmdBeginRenderPass(XGL_CMD_BUFFER cmdBuffer, const XGL_RENDER_PASS_BEGIN *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002582{
2583 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2584 if (pCB) {
2585 updateCBTracking(cmdBuffer);
2586 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002587 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2588 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002589 validatePipelineState(pCB, XGL_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002590 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002591 char str[1024];
2592 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2593 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2594 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002595 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002596}
2597
2598XGL_LAYER_EXPORT void XGLAPI xglCmdEndRenderPass(XGL_CMD_BUFFER cmdBuffer, XGL_RENDER_PASS renderPass)
2599{
2600 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2601 if (pCB) {
2602 updateCBTracking(cmdBuffer);
2603 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002604 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002605 }
2606 else {
2607 char str[1024];
2608 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2609 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2610 }
2611 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2612}
2613
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002614XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002615{
2616 // This layer intercepts callbacks
2617 XGL_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));
2618#if ALLOC_DEBUG
2619 printf("Alloc34 #%lu pNewDbgFuncNode addr(%p)\n", ++g_alloc_count, (void*)pNewDbgFuncNode);
2620#endif
2621 if (!pNewDbgFuncNode)
2622 return XGL_ERROR_OUT_OF_MEMORY;
2623 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2624 pNewDbgFuncNode->pUserData = pUserData;
2625 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2626 g_pDbgFunctionHead = pNewDbgFuncNode;
2627 // force callbacks if DebugAction hasn't been set already other than initial value
2628 if (g_actionIsDefault) {
2629 g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;
2630 }
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002631 XGL_RESULT result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002632 return result;
2633}
2634
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002635XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002636{
2637 XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2638 XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
2639 while (pTrav) {
2640 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2641 pPrev->pNext = pTrav->pNext;
2642 if (g_pDbgFunctionHead == pTrav)
2643 g_pDbgFunctionHead = pTrav->pNext;
2644#if ALLOC_DEBUG
2645 printf("Free34 #%lu pNewDbgFuncNode addr(%p)\n", ++g_alloc_count, (void*)pTrav);
2646#endif
2647 free(pTrav);
2648 break;
2649 }
2650 pPrev = pTrav;
2651 pTrav = pTrav->pNext;
2652 }
2653 if (g_pDbgFunctionHead == NULL)
2654 {
2655 if (g_actionIsDefault)
2656 g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;
2657 else
2658 g_debugAction = (XGL_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)XGL_DBG_LAYER_ACTION_CALLBACK));
2659 }
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002660 XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002661 return result;
2662}
2663
2664XGL_LAYER_EXPORT void XGLAPI xglCmdDbgMarkerBegin(XGL_CMD_BUFFER cmdBuffer, const char* pMarker)
2665{
2666 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2667 if (pCB) {
2668 updateCBTracking(cmdBuffer);
2669 addCmd(pCB, CMD_DBGMARKERBEGIN);
2670 }
2671 else {
2672 char str[1024];
2673 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2674 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2675 }
2676 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2677}
2678
2679XGL_LAYER_EXPORT void XGLAPI xglCmdDbgMarkerEnd(XGL_CMD_BUFFER cmdBuffer)
2680{
2681 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2682 if (pCB) {
2683 updateCBTracking(cmdBuffer);
2684 addCmd(pCB, CMD_DBGMARKEREND);
2685 }
2686 else {
2687 char str[1024];
2688 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2689 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2690 }
2691 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2692}
2693
2694// TODO : Want to pass in a cmdBuffer here based on which state to display
2695void drawStateDumpDotFile(char* outFileName)
2696{
2697 // TODO : Currently just setting cmdBuffer based on global var
2698 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2699 dumpGlobalDotFile(outFileName);
2700}
2701
2702void drawStateDumpCommandBufferDotFile(char* outFileName)
2703{
2704 cbDumpDotFile(outFileName);
2705}
2706
2707void drawStateDumpPngFile(char* outFileName)
2708{
2709#if defined(_WIN32)
2710// FIXME: NEED WINDOWS EQUIVALENT
2711 char str[1024];
2712 sprintf(str, "Cannot execute dot program yet on Windows.");
2713 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
2714#else // WIN32
2715 char dotExe[32] = "/usr/bin/dot";
2716 if( access(dotExe, X_OK) != -1) {
2717 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2718 char dotCmd[1024];
2719 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
2720 system(dotCmd);
2721 remove("/tmp/tmp.dot");
2722 }
2723 else {
2724 char str[1024];
2725 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
2726 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
2727 }
2728#endif // WIN32
2729}
2730
2731XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)
2732{
2733 XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
2734
2735 if (gpu == NULL)
2736 return NULL;
2737 pCurObj = gpuw;
2738 loader_platform_thread_once(&g_initOnce, initDrawState);
2739
2740 if (!strcmp(funcName, "xglGetProcAddr"))
2741 return (void *) xglGetProcAddr;
2742 if (!strcmp(funcName, "xglCreateDevice"))
2743 return (void*) xglCreateDevice;
2744 if (!strcmp(funcName, "xglDestroyDevice"))
2745 return (void*) xglDestroyDevice;
2746 if (!strcmp(funcName, "xglEnumerateLayers"))
2747 return (void*) xglEnumerateLayers;
2748 if (!strcmp(funcName, "xglQueueSubmit"))
2749 return (void*) xglQueueSubmit;
2750 if (!strcmp(funcName, "xglDestroyObject"))
2751 return (void*) xglDestroyObject;
2752 if (!strcmp(funcName, "xglCreateBufferView"))
2753 return (void*) xglCreateBufferView;
2754 if (!strcmp(funcName, "xglCreateImageView"))
2755 return (void*) xglCreateImageView;
2756 if (!strcmp(funcName, "xglCreateGraphicsPipeline"))
2757 return (void*) xglCreateGraphicsPipeline;
2758 if (!strcmp(funcName, "xglCreateSampler"))
2759 return (void*) xglCreateSampler;
2760 if (!strcmp(funcName, "xglCreateDescriptorSetLayout"))
2761 return (void*) xglCreateDescriptorSetLayout;
2762 if (!strcmp(funcName, "xglBeginDescriptorRegionUpdate"))
2763 return (void*) xglBeginDescriptorRegionUpdate;
2764 if (!strcmp(funcName, "xglEndDescriptorRegionUpdate"))
2765 return (void*) xglEndDescriptorRegionUpdate;
2766 if (!strcmp(funcName, "xglCreateDescriptorRegion"))
2767 return (void*) xglCreateDescriptorRegion;
2768 if (!strcmp(funcName, "xglClearDescriptorRegion"))
2769 return (void*) xglClearDescriptorRegion;
2770 if (!strcmp(funcName, "xglAllocDescriptorSets"))
2771 return (void*) xglAllocDescriptorSets;
2772 if (!strcmp(funcName, "xglClearDescriptorSets"))
2773 return (void*) xglClearDescriptorSets;
2774 if (!strcmp(funcName, "xglUpdateDescriptors"))
2775 return (void*) xglUpdateDescriptors;
2776 if (!strcmp(funcName, "xglCreateDynamicViewportState"))
2777 return (void*) xglCreateDynamicViewportState;
2778 if (!strcmp(funcName, "xglCreateDynamicRasterState"))
2779 return (void*) xglCreateDynamicRasterState;
2780 if (!strcmp(funcName, "xglCreateDynamicColorBlendState"))
2781 return (void*) xglCreateDynamicColorBlendState;
2782 if (!strcmp(funcName, "xglCreateDynamicDepthStencilState"))
2783 return (void*) xglCreateDynamicDepthStencilState;
2784 if (!strcmp(funcName, "xglCreateCommandBuffer"))
2785 return (void*) xglCreateCommandBuffer;
2786 if (!strcmp(funcName, "xglBeginCommandBuffer"))
2787 return (void*) xglBeginCommandBuffer;
2788 if (!strcmp(funcName, "xglEndCommandBuffer"))
2789 return (void*) xglEndCommandBuffer;
2790 if (!strcmp(funcName, "xglResetCommandBuffer"))
2791 return (void*) xglResetCommandBuffer;
2792 if (!strcmp(funcName, "xglCmdBindPipeline"))
2793 return (void*) xglCmdBindPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002794 if (!strcmp(funcName, "xglCmdBindDynamicStateObject"))
2795 return (void*) xglCmdBindDynamicStateObject;
2796 if (!strcmp(funcName, "xglCmdBindDescriptorSet"))
2797 return (void*) xglCmdBindDescriptorSet;
2798 if (!strcmp(funcName, "xglCmdBindVertexBuffer"))
2799 return (void*) xglCmdBindVertexBuffer;
2800 if (!strcmp(funcName, "xglCmdBindIndexBuffer"))
2801 return (void*) xglCmdBindIndexBuffer;
2802 if (!strcmp(funcName, "xglCmdDraw"))
2803 return (void*) xglCmdDraw;
2804 if (!strcmp(funcName, "xglCmdDrawIndexed"))
2805 return (void*) xglCmdDrawIndexed;
2806 if (!strcmp(funcName, "xglCmdDrawIndirect"))
2807 return (void*) xglCmdDrawIndirect;
2808 if (!strcmp(funcName, "xglCmdDrawIndexedIndirect"))
2809 return (void*) xglCmdDrawIndexedIndirect;
2810 if (!strcmp(funcName, "xglCmdDispatch"))
2811 return (void*) xglCmdDispatch;
2812 if (!strcmp(funcName, "xglCmdDispatchIndirect"))
2813 return (void*) xglCmdDispatchIndirect;
2814 if (!strcmp(funcName, "xglCmdCopyBuffer"))
2815 return (void*) xglCmdCopyBuffer;
2816 if (!strcmp(funcName, "xglCmdCopyImage"))
2817 return (void*) xglCmdCopyImage;
2818 if (!strcmp(funcName, "xglCmdCopyBufferToImage"))
2819 return (void*) xglCmdCopyBufferToImage;
2820 if (!strcmp(funcName, "xglCmdCopyImageToBuffer"))
2821 return (void*) xglCmdCopyImageToBuffer;
2822 if (!strcmp(funcName, "xglCmdCloneImageData"))
2823 return (void*) xglCmdCloneImageData;
2824 if (!strcmp(funcName, "xglCmdUpdateBuffer"))
2825 return (void*) xglCmdUpdateBuffer;
2826 if (!strcmp(funcName, "xglCmdFillBuffer"))
2827 return (void*) xglCmdFillBuffer;
2828 if (!strcmp(funcName, "xglCmdClearColorImage"))
2829 return (void*) xglCmdClearColorImage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002830 if (!strcmp(funcName, "xglCmdClearDepthStencil"))
2831 return (void*) xglCmdClearDepthStencil;
2832 if (!strcmp(funcName, "xglCmdResolveImage"))
2833 return (void*) xglCmdResolveImage;
2834 if (!strcmp(funcName, "xglCmdSetEvent"))
2835 return (void*) xglCmdSetEvent;
2836 if (!strcmp(funcName, "xglCmdResetEvent"))
2837 return (void*) xglCmdResetEvent;
2838 if (!strcmp(funcName, "xglCmdWaitEvents"))
2839 return (void*) xglCmdWaitEvents;
2840 if (!strcmp(funcName, "xglCmdPipelineBarrier"))
2841 return (void*) xglCmdPipelineBarrier;
2842 if (!strcmp(funcName, "xglCmdBeginQuery"))
2843 return (void*) xglCmdBeginQuery;
2844 if (!strcmp(funcName, "xglCmdEndQuery"))
2845 return (void*) xglCmdEndQuery;
2846 if (!strcmp(funcName, "xglCmdResetQueryPool"))
2847 return (void*) xglCmdResetQueryPool;
2848 if (!strcmp(funcName, "xglCmdWriteTimestamp"))
2849 return (void*) xglCmdWriteTimestamp;
2850 if (!strcmp(funcName, "xglCmdInitAtomicCounters"))
2851 return (void*) xglCmdInitAtomicCounters;
2852 if (!strcmp(funcName, "xglCmdLoadAtomicCounters"))
2853 return (void*) xglCmdLoadAtomicCounters;
2854 if (!strcmp(funcName, "xglCmdSaveAtomicCounters"))
2855 return (void*) xglCmdSaveAtomicCounters;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002856 if (!strcmp(funcName, "xglCreateFramebuffer"))
2857 return (void*) xglCreateFramebuffer;
2858 if (!strcmp(funcName, "xglCreateRenderPass"))
2859 return (void*) xglCreateRenderPass;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002860 if (!strcmp(funcName, "xglCmdBeginRenderPass"))
2861 return (void*) xglCmdBeginRenderPass;
2862 if (!strcmp(funcName, "xglCmdEndRenderPass"))
2863 return (void*) xglCmdEndRenderPass;
2864 if (!strcmp(funcName, "xglDbgRegisterMsgCallback"))
2865 return (void*) xglDbgRegisterMsgCallback;
2866 if (!strcmp(funcName, "xglDbgUnregisterMsgCallback"))
2867 return (void*) xglDbgUnregisterMsgCallback;
2868 if (!strcmp(funcName, "xglCmdDbgMarkerBegin"))
2869 return (void*) xglCmdDbgMarkerBegin;
2870 if (!strcmp(funcName, "xglCmdDbgMarkerEnd"))
2871 return (void*) xglCmdDbgMarkerEnd;
2872 if (!strcmp("drawStateDumpDotFile", funcName))
2873 return (void*) drawStateDumpDotFile;
2874 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2875 return (void*) drawStateDumpCommandBufferDotFile;
2876 if (!strcmp("drawStateDumpPngFile", funcName))
2877 return (void*) drawStateDumpPngFile;
2878 else {
2879 if (gpuw->pGPA == NULL)
2880 return NULL;
2881 return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);
2882 }
2883}