blob: 520b6a3a440e32db10fb61a86a4b4b9e09ef1d02 [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);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001606}
1607
1608XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateSampler(XGL_DEVICE device, const XGL_SAMPLER_CREATE_INFO* pCreateInfo, XGL_SAMPLER* pSampler)
1609{
1610 XGL_RESULT result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
1611 if (XGL_SUCCESS == result) {
1612 loader_platform_thread_lock_mutex(&globalLock);
1613 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1614 pNewNode->sampler = *pSampler;
1615 pNewNode->createInfo = *pCreateInfo;
1616 sampleMap[*pSampler] = pNewNode;
1617 loader_platform_thread_unlock_mutex(&globalLock);
1618 }
1619 return result;
1620}
1621
1622XGL_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)
1623{
1624 XGL_RESULT result = nextTable.CreateDescriptorSetLayout(device, stageFlags, pSetBindPoints, priorSetLayout, pSetLayoutInfoList, pSetLayout);
1625 if (XGL_SUCCESS == result) {
1626 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1627 if (NULL == pNewNode) {
1628 char str[1024];
1629 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in xglCreateDescriptorSetLayout()");
1630 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
1631 }
1632 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
1633 // TODO : API Currently missing a count here that we should multiply by struct size
1634 pNewNode->pCreateInfoList = new XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1635 memset((void*)pNewNode->pCreateInfoList, 0, sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO));
1636 void* pCITrav = NULL;
1637 uint32_t totalCount = 0;
1638 if (pSetLayoutInfoList) {
1639 memcpy((void*)pNewNode->pCreateInfoList, pSetLayoutInfoList, sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO));
1640 pCITrav = (void*)pSetLayoutInfoList->pNext;
1641 totalCount = pSetLayoutInfoList->count;
1642 }
1643 void** ppNext = (void**)&pNewNode->pCreateInfoList->pNext;
1644 while (pCITrav) {
1645 totalCount += ((XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pCITrav)->count;
1646 *ppNext = new XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1647 memcpy((void*)*ppNext, pCITrav, sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO));
1648 pCITrav = (void*)((XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pCITrav)->pNext;
1649 ppNext = (void**)&((XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)*ppNext)->pNext;
1650 }
1651 if (totalCount > 0) {
1652 pNewNode->pTypes = new XGL_DESCRIPTOR_TYPE[totalCount];
1653 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pLCI = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pSetLayoutInfoList;
1654 uint32_t offset = 0;
1655 uint32_t i = 0;
1656 while (pLCI) {
1657 for (i = 0; i < pLCI->count; i++) {
1658 pNewNode->pTypes[offset + i] = pLCI->descriptorType;
1659 }
1660 offset += i;
1661 pLCI = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pLCI->pNext;
1662 }
1663 }
1664 pNewNode->layout = *pSetLayout;
1665 pNewNode->stageFlags = stageFlags;
1666 uint32_t i = (XGL_SHADER_STAGE_FLAGS_ALL == stageFlags) ? 0 : XGL_SHADER_STAGE_COMPUTE;
1667 for (uint32_t stage = XGL_SHADER_STAGE_FLAGS_COMPUTE_BIT; stage > 0; stage >>= 1) {
1668 assert(i < XGL_NUM_SHADER_STAGE);
1669 if (stage & stageFlags)
1670 pNewNode->shaderStageBindPoints[i] = pSetBindPoints[i];
1671 i = (i == 0) ? 0 : (i-1);
1672 }
1673 pNewNode->startIndex = 0;
1674 LAYOUT_NODE* pPriorNode = getLayoutNode(priorSetLayout);
1675 // Point to prior node or NULL if no prior node
1676 if (NULL != priorSetLayout && pPriorNode == NULL) {
1677 char str[1024];
1678 sprintf(str, "Invalid priorSetLayout of %p passed to xglCreateDescriptorSetLayout()", (void*)priorSetLayout);
1679 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, priorSetLayout, 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
1680 }
1681 else if (pPriorNode != NULL) { // We have a node for a valid prior layout
1682 // Get count for prior layout
1683 pNewNode->startIndex = pPriorNode->endIndex + 1;
1684 }
1685 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1686 assert(pNewNode->endIndex >= pNewNode->startIndex);
1687 pNewNode->pPriorSetLayout = pPriorNode;
1688 // Put new node at Head of global Layer list
1689 loader_platform_thread_lock_mutex(&globalLock);
1690 layoutMap[*pSetLayout] = pNewNode;
1691 loader_platform_thread_unlock_mutex(&globalLock);
1692 }
1693 return result;
1694}
1695
1696XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglBeginDescriptorRegionUpdate(XGL_DEVICE device, XGL_DESCRIPTOR_UPDATE_MODE updateMode)
1697{
1698 XGL_RESULT result = nextTable.BeginDescriptorRegionUpdate(device, updateMode);
1699 if (XGL_SUCCESS == result) {
1700 loader_platform_thread_lock_mutex(&globalLock);
1701 REGION_NODE* pRegionNode = regionMap.begin()->second;
1702 if (!pRegionNode) {
1703 char str[1024];
1704 sprintf(str, "Unable to find region node");
1705 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
1706 }
1707 else {
1708 pRegionNode->updateActive = 1;
1709 }
1710 loader_platform_thread_unlock_mutex(&globalLock);
1711 }
1712 return result;
1713}
1714
1715XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEndDescriptorRegionUpdate(XGL_DEVICE device, XGL_CMD_BUFFER cmd)
1716{
1717 XGL_RESULT result = nextTable.EndDescriptorRegionUpdate(device, cmd);
1718 if (XGL_SUCCESS == result) {
1719 loader_platform_thread_lock_mutex(&globalLock);
1720 REGION_NODE* pRegionNode = regionMap.begin()->second;
1721 if (!pRegionNode) {
1722 char str[1024];
1723 sprintf(str, "Unable to find region node");
1724 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
1725 }
1726 else {
1727 if (!pRegionNode->updateActive) {
1728 char str[1024];
1729 sprintf(str, "You must call xglBeginDescriptorRegionUpdate() before this call to xglEndDescriptorRegionUpdate()!");
1730 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_DS_END_WITHOUT_BEGIN, "DS", str);
1731 }
1732 else {
1733 pRegionNode->updateActive = 0;
1734 }
1735 pRegionNode->updateActive = 0;
1736 }
1737 loader_platform_thread_unlock_mutex(&globalLock);
1738 }
1739 return result;
1740}
1741
1742XGL_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)
1743{
1744 XGL_RESULT result = nextTable.CreateDescriptorRegion(device, regionUsage, maxSets, pCreateInfo, pDescriptorRegion);
1745 if (XGL_SUCCESS == result) {
1746 // Insert this region into Global Region LL at head
1747 char str[1024];
1748 sprintf(str, "Created Descriptor Region %p", (void*)*pDescriptorRegion);
1749 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, (XGL_BASE_OBJECT)pDescriptorRegion, 0, DRAWSTATE_NONE, "DS", str);
1750 loader_platform_thread_lock_mutex(&globalLock);
1751 REGION_NODE* pNewNode = new REGION_NODE;
1752 if (NULL == pNewNode) {
1753 char str[1024];
1754 sprintf(str, "Out of memory while attempting to allocate REGION_NODE in xglCreateDescriptorRegion()");
1755 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, (XGL_BASE_OBJECT)*pDescriptorRegion, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
1756 }
1757 else {
1758 memset(pNewNode, 0, sizeof(REGION_NODE));
1759 XGL_DESCRIPTOR_REGION_CREATE_INFO* pCI = (XGL_DESCRIPTOR_REGION_CREATE_INFO*)&pNewNode->createInfo;
1760 memcpy((void*)pCI, pCreateInfo, sizeof(XGL_DESCRIPTOR_REGION_CREATE_INFO));
1761 if (pNewNode->createInfo.count) {
1762 size_t typeCountSize = pNewNode->createInfo.count * sizeof(XGL_DESCRIPTOR_TYPE_COUNT);
1763 pNewNode->createInfo.pTypeCount = new XGL_DESCRIPTOR_TYPE_COUNT[typeCountSize];
1764 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1765 }
1766 pNewNode->regionUsage = regionUsage;
1767 pNewNode->updateActive = 0;
1768 pNewNode->maxSets = maxSets;
1769 pNewNode->region = *pDescriptorRegion;
1770 regionMap[*pDescriptorRegion] = pNewNode;
1771 }
1772 loader_platform_thread_unlock_mutex(&globalLock);
1773 }
1774 else {
1775 // Need to do anything if region create fails?
1776 }
1777 return result;
1778}
1779
1780XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglClearDescriptorRegion(XGL_DESCRIPTOR_REGION descriptorRegion)
1781{
1782 XGL_RESULT result = nextTable.ClearDescriptorRegion(descriptorRegion);
1783 if (XGL_SUCCESS == result) {
1784 clearDescriptorRegion(descriptorRegion);
1785 }
1786 return result;
1787}
1788
1789XGL_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)
1790{
1791 XGL_RESULT result = nextTable.AllocDescriptorSets(descriptorRegion, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
1792 if ((XGL_SUCCESS == result) || (*pCount > 0)) {
1793 REGION_NODE *pRegionNode = getRegionNode(descriptorRegion);
1794 if (!pRegionNode) {
1795 char str[1024];
1796 sprintf(str, "Unable to find region node for region %p specified in xglAllocDescriptorSets() call", (void*)descriptorRegion);
1797 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, descriptorRegion, 0, DRAWSTATE_INVALID_REGION, "DS", str);
1798 }
1799 else {
1800 for (uint32_t i = 0; i < *pCount; i++) {
1801 char str[1024];
1802 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
1803 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
1804 // Create new set node and add to head of region nodes
1805 SET_NODE* pNewNode = new SET_NODE;
1806 if (NULL == pNewNode) {
1807 char str[1024];
1808 sprintf(str, "Out of memory while attempting to allocate SET_NODE in xglAllocDescriptorSets()");
1809 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
1810 }
1811 else {
1812 memset(pNewNode, 0, sizeof(SET_NODE));
1813 // Insert set at head of Set LL for this region
1814 pNewNode->pNext = pRegionNode->pSets;
1815 pRegionNode->pSets = pNewNode;
1816 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1817 if (NULL == pLayout) {
1818 char str[1024];
1819 sprintf(str, "Unable to find set layout node for layout %p specified in xglAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1820 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
1821 }
1822 pNewNode->pLayouts = pLayout;
1823 pNewNode->region = descriptorRegion;
1824 pNewNode->set = pDescriptorSets[i];
1825 pNewNode->setUsage = setUsage;
1826 pNewNode->descriptorCount = pLayout->endIndex + 1;
1827 if (pNewNode->descriptorCount) {
1828 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1829 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1830 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1831 }
1832 setMap[pDescriptorSets[i]] = pNewNode;
1833 }
1834 }
1835 }
1836 }
1837 return result;
1838}
1839
1840XGL_LAYER_EXPORT void XGLAPI xglClearDescriptorSets(XGL_DESCRIPTOR_REGION descriptorRegion, uint32_t count, const XGL_DESCRIPTOR_SET* pDescriptorSets)
1841{
1842 for (uint32_t i = 0; i < count; i++) {
1843 clearDescriptorSet(pDescriptorSets[i]);
1844 }
1845 nextTable.ClearDescriptorSets(descriptorRegion, count, pDescriptorSets);
1846}
1847
1848XGL_LAYER_EXPORT void XGLAPI xglUpdateDescriptors(XGL_DESCRIPTOR_SET descriptorSet, const void* pUpdateChain)
1849{
1850 SET_NODE* pSet = getSetNode(descriptorSet);
1851 if (!dsUpdateActive(descriptorSet)) {
1852 char str[1024];
1853 sprintf(str, "You must call xglBeginDescriptorRegionUpdate() before this call to xglUpdateDescriptors()!");
1854 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pSet->region, 0, DRAWSTATE_UPDATE_WITHOUT_BEGIN, "DS", str);
1855 }
1856 else {
1857 // pUpdateChain is a Linked-list of XGL_UPDATE_* structures defining the mappings for the descriptors
1858 dsUpdate(descriptorSet, (GENERIC_HEADER*)pUpdateChain);
1859 }
1860
1861 nextTable.UpdateDescriptors(descriptorSet, pUpdateChain);
1862}
1863
1864XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicViewportState(XGL_DEVICE device, const XGL_DYNAMIC_VP_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_VP_STATE_OBJECT* pState)
1865{
1866 XGL_RESULT result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
1867 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_VIEWPORT);
1868 return result;
1869}
1870
1871XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicRasterState(XGL_DEVICE device, const XGL_DYNAMIC_RS_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_RS_STATE_OBJECT* pState)
1872{
1873 XGL_RESULT result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
1874 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_RASTER);
1875 return result;
1876}
1877
1878XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicColorBlendState(XGL_DEVICE device, const XGL_DYNAMIC_CB_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_CB_STATE_OBJECT* pState)
1879{
1880 XGL_RESULT result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
1881 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_COLOR_BLEND);
1882 return result;
1883}
1884
1885XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDynamicDepthStencilState(XGL_DEVICE device, const XGL_DYNAMIC_DS_STATE_CREATE_INFO* pCreateInfo, XGL_DYNAMIC_DS_STATE_OBJECT* pState)
1886{
1887 XGL_RESULT result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
1888 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, XGL_STATE_BIND_DEPTH_STENCIL);
1889 return result;
1890}
1891
1892XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateCommandBuffer(XGL_DEVICE device, const XGL_CMD_BUFFER_CREATE_INFO* pCreateInfo, XGL_CMD_BUFFER* pCmdBuffer)
1893{
1894 XGL_RESULT result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
1895 if (XGL_SUCCESS == result) {
1896 loader_platform_thread_lock_mutex(&globalLock);
1897 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1898 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1899 pCB->cmdBuffer = *pCmdBuffer;
1900 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001901 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001902 pCB->lastVtxBinding = MAX_BINDING;
1903 cmdBufferMap[*pCmdBuffer] = pCB;
1904 loader_platform_thread_unlock_mutex(&globalLock);
1905 updateCBTracking(*pCmdBuffer);
1906 }
1907 return result;
1908}
1909
1910XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglBeginCommandBuffer(XGL_CMD_BUFFER cmdBuffer, const XGL_CMD_BUFFER_BEGIN_INFO* pBeginInfo)
1911{
1912 XGL_RESULT result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
1913 if (XGL_SUCCESS == result) {
1914 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1915 if (pCB) {
1916 if (CB_NEW != pCB->state)
1917 resetCB(cmdBuffer);
1918 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001919 if (pBeginInfo->pNext) {
1920 XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO* pCbGfxBI = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)pBeginInfo->pNext;
1921 if (XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001922 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001923 }
1924 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001925 }
1926 else {
1927 char str[1024];
1928 sprintf(str, "In xglBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1929 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
1930 }
1931 updateCBTracking(cmdBuffer);
1932 }
1933 return result;
1934}
1935
1936XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEndCommandBuffer(XGL_CMD_BUFFER cmdBuffer)
1937{
1938 XGL_RESULT result = nextTable.EndCommandBuffer(cmdBuffer);
1939 if (XGL_SUCCESS == result) {
1940 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1941 if (pCB) {
1942 pCB->state = CB_UPDATE_COMPLETE;
1943 printCB(cmdBuffer);
1944 }
1945 else {
1946 char str[1024];
1947 sprintf(str, "In xglEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1948 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
1949 }
1950 updateCBTracking(cmdBuffer);
1951 //cbDumpDotFile("cb_dump.dot");
1952 }
1953 return result;
1954}
1955
1956XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglResetCommandBuffer(XGL_CMD_BUFFER cmdBuffer)
1957{
1958 XGL_RESULT result = nextTable.ResetCommandBuffer(cmdBuffer);
1959 if (XGL_SUCCESS == result) {
1960 resetCB(cmdBuffer);
1961 updateCBTracking(cmdBuffer);
1962 }
1963 return result;
1964}
1965
1966XGL_LAYER_EXPORT void XGLAPI xglCmdBindPipeline(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, XGL_PIPELINE pipeline)
1967{
1968 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1969 if (pCB) {
1970 updateCBTracking(cmdBuffer);
1971 addCmd(pCB, CMD_BINDPIPELINE);
1972 PIPELINE_NODE* pPN = getPipeline(pipeline);
1973 if (pPN) {
1974 pCB->lastBoundPipeline = pipeline;
1975 loader_platform_thread_lock_mutex(&globalLock);
1976 g_lastBoundPipeline = pPN;
1977 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001978 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001979 }
1980 else {
1981 char str[1024];
1982 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
1983 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
1984 }
1985 }
1986 else {
1987 char str[1024];
1988 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
1989 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
1990 }
1991 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1992}
1993
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001994XGL_LAYER_EXPORT void XGLAPI xglCmdBindDynamicStateObject(XGL_CMD_BUFFER cmdBuffer, XGL_STATE_BIND_POINT stateBindPoint, XGL_DYNAMIC_STATE_OBJECT state)
1995{
1996 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
1997 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
1998}
1999
2000XGL_LAYER_EXPORT void XGLAPI xglCmdBindDescriptorSet(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, XGL_DESCRIPTOR_SET descriptorSet, const uint32_t* pUserData)
2001{
2002 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2003 if (pCB) {
2004 updateCBTracking(cmdBuffer);
2005 addCmd(pCB, CMD_BINDDESCRIPTORSET);
2006 if (getSetNode(descriptorSet)) {
2007 if (dsUpdateActive(descriptorSet)) {
2008 // TODO : This check here needs to be made at QueueSubmit time
2009/*
2010 char str[1024];
2011 sprintf(str, "You must call xglEndDescriptorRegionUpdate(%p) before this call to xglCmdBindDescriptorSet()!", (void*)descriptorSet);
2012 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_BINDING_DS_NO_END_UPDATE, "DS", str);
2013*/
2014 }
2015 loader_platform_thread_lock_mutex(&globalLock);
2016 pCB->lastBoundDescriptorSet = descriptorSet;
2017 g_lastBoundDescriptorSet = descriptorSet;
2018 loader_platform_thread_unlock_mutex(&globalLock);
2019 char str[1024];
2020 sprintf(str, "DS %p bound on pipeline %s", (void*)descriptorSet, string_XGL_PIPELINE_BIND_POINT(pipelineBindPoint));
2021 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_NONE, "DS", str);
2022 synchAndPrintDSConfig(cmdBuffer);
2023 }
2024 else {
2025 char str[1024];
2026 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)descriptorSet);
2027 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_INVALID_SET, "DS", str);
2028 }
2029 }
2030 else {
2031 char str[1024];
2032 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2033 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2034 }
2035 nextTable.CmdBindDescriptorSet(cmdBuffer, pipelineBindPoint, descriptorSet, pUserData);
2036}
2037
2038XGL_LAYER_EXPORT void XGLAPI xglCmdBindIndexBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, XGL_INDEX_TYPE indexType)
2039{
2040 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2041 if (pCB) {
2042 updateCBTracking(cmdBuffer);
2043 addCmd(pCB, CMD_BINDINDEXBUFFER);
2044 // TODO : Track idxBuffer binding
2045 }
2046 else {
2047 char str[1024];
2048 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2049 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2050 }
2051 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2052}
2053
2054XGL_LAYER_EXPORT void XGLAPI xglCmdBindVertexBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, uint32_t binding)
2055{
2056 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2057 if (pCB) {
2058 updateCBTracking(cmdBuffer);
2059 addCmd(pCB, CMD_BINDVERTEXBUFFER);
2060 pCB->lastVtxBinding = binding;
2061 validateVBBinding(cmdBuffer);
2062 }
2063 else {
2064 char str[1024];
2065 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2066 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2067 }
2068 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
2069}
2070
2071XGL_LAYER_EXPORT void XGLAPI xglCmdDraw(XGL_CMD_BUFFER cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
2072{
2073 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2074 if (pCB) {
2075 updateCBTracking(cmdBuffer);
2076 addCmd(pCB, CMD_DRAW);
2077 pCB->drawCount[DRAW]++;
2078 char str[1024];
2079 sprintf(str, "xglCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2080 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2081 synchAndPrintDSConfig(cmdBuffer);
2082 }
2083 else {
2084 char str[1024];
2085 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2086 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2087 }
2088 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2089}
2090
2091XGL_LAYER_EXPORT void XGLAPI xglCmdDrawIndexed(XGL_CMD_BUFFER cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
2092{
2093 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2094 if (pCB) {
2095 updateCBTracking(cmdBuffer);
2096 addCmd(pCB, CMD_DRAWINDEXED);
2097 pCB->drawCount[DRAW_INDEXED]++;
2098 char str[1024];
2099 sprintf(str, "xglCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2100 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2101 synchAndPrintDSConfig(cmdBuffer);
2102 }
2103 else {
2104 char str[1024];
2105 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2106 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2107 }
2108 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2109}
2110
2111XGL_LAYER_EXPORT void XGLAPI xglCmdDrawIndirect(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, uint32_t count, uint32_t stride)
2112{
2113 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2114 if (pCB) {
2115 updateCBTracking(cmdBuffer);
2116 addCmd(pCB, CMD_DRAWINDIRECT);
2117 pCB->drawCount[DRAW_INDIRECT]++;
2118 char str[1024];
2119 sprintf(str, "xglCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2120 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2121 synchAndPrintDSConfig(cmdBuffer);
2122 }
2123 else {
2124 char str[1024];
2125 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2126 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2127 }
2128 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2129}
2130
2131XGL_LAYER_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset, uint32_t count, uint32_t stride)
2132{
2133 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2134 if (pCB) {
2135 updateCBTracking(cmdBuffer);
2136 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2137 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2138 char str[1024];
2139 sprintf(str, "xglCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2140 layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
2141 synchAndPrintDSConfig(cmdBuffer);
2142 }
2143 else {
2144 char str[1024];
2145 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2146 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2147 }
2148 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2149}
2150
2151XGL_LAYER_EXPORT void XGLAPI xglCmdDispatch(XGL_CMD_BUFFER cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
2152{
2153 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2154 if (pCB) {
2155 updateCBTracking(cmdBuffer);
2156 addCmd(pCB, CMD_DISPATCH);
2157 }
2158 else {
2159 char str[1024];
2160 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2161 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2162 }
2163 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2164}
2165
2166XGL_LAYER_EXPORT void XGLAPI xglCmdDispatchIndirect(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER buffer, XGL_GPU_SIZE offset)
2167{
2168 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2169 if (pCB) {
2170 updateCBTracking(cmdBuffer);
2171 addCmd(pCB, CMD_DISPATCHINDIRECT);
2172 }
2173 else {
2174 char str[1024];
2175 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2176 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2177 }
2178 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2179}
2180
2181XGL_LAYER_EXPORT void XGLAPI xglCmdCopyBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER srcBuffer, XGL_BUFFER destBuffer, uint32_t regionCount, const XGL_BUFFER_COPY* pRegions)
2182{
2183 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2184 if (pCB) {
2185 updateCBTracking(cmdBuffer);
2186 addCmd(pCB, CMD_COPYBUFFER);
2187 }
2188 else {
2189 char str[1024];
2190 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2191 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2192 }
2193 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2194}
2195
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002196XGL_LAYER_EXPORT void XGLAPI xglCmdCopyImage(
2197 XGL_CMD_BUFFER cmdBuffer,
2198 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2199 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2200 uint32_t regionCount, const XGL_IMAGE_COPY* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002201{
2202 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2203 if (pCB) {
2204 updateCBTracking(cmdBuffer);
2205 addCmd(pCB, CMD_COPYIMAGE);
2206 }
2207 else {
2208 char str[1024];
2209 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2210 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2211 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002212 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002213}
2214
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002215XGL_LAYER_EXPORT void XGLAPI xglCmdBlitImage(XGL_CMD_BUFFER cmdBuffer,
2216 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2217 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2218 uint32_t regionCount, const XGL_IMAGE_BLIT* pRegions)
2219{
2220 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2221 if (pCB) {
2222 updateCBTracking(cmdBuffer);
2223 addCmd(pCB, CMD_COPYIMAGE);
2224 }
2225 else {
2226 char str[1024];
2227 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2228 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2229 }
2230 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2231}
2232
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002233XGL_LAYER_EXPORT void XGLAPI xglCmdCopyBufferToImage(
2234 XGL_CMD_BUFFER cmdBuffer,
2235 XGL_BUFFER srcBuffer,
2236 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2237 uint32_t regionCount, const XGL_BUFFER_IMAGE_COPY* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002238{
2239 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2240 if (pCB) {
2241 updateCBTracking(cmdBuffer);
2242 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2243 }
2244 else {
2245 char str[1024];
2246 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2247 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2248 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002249 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002250}
2251
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002252XGL_LAYER_EXPORT void XGLAPI xglCmdCopyImageToBuffer(
2253 XGL_CMD_BUFFER cmdBuffer,
2254 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2255 XGL_BUFFER destBuffer,
2256 uint32_t regionCount, const XGL_BUFFER_IMAGE_COPY* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002257{
2258 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2259 if (pCB) {
2260 updateCBTracking(cmdBuffer);
2261 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2262 }
2263 else {
2264 char str[1024];
2265 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2266 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2267 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002268 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002269}
2270
2271XGL_LAYER_EXPORT void XGLAPI xglCmdCloneImageData(XGL_CMD_BUFFER cmdBuffer, XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout, XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout)
2272{
2273 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2274 if (pCB) {
2275 updateCBTracking(cmdBuffer);
2276 addCmd(pCB, CMD_CLONEIMAGEDATA);
2277 }
2278 else {
2279 char str[1024];
2280 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2281 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2282 }
2283 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2284}
2285
2286XGL_LAYER_EXPORT void XGLAPI xglCmdUpdateBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER destBuffer, XGL_GPU_SIZE destOffset, XGL_GPU_SIZE dataSize, const uint32_t* pData)
2287{
2288 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2289 if (pCB) {
2290 updateCBTracking(cmdBuffer);
2291 addCmd(pCB, CMD_UPDATEBUFFER);
2292 }
2293 else {
2294 char str[1024];
2295 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2296 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2297 }
2298 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2299}
2300
2301XGL_LAYER_EXPORT void XGLAPI xglCmdFillBuffer(XGL_CMD_BUFFER cmdBuffer, XGL_BUFFER destBuffer, XGL_GPU_SIZE destOffset, XGL_GPU_SIZE fillSize, uint32_t data)
2302{
2303 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2304 if (pCB) {
2305 updateCBTracking(cmdBuffer);
2306 addCmd(pCB, CMD_FILLBUFFER);
2307 }
2308 else {
2309 char str[1024];
2310 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2311 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2312 }
2313 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2314}
2315
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002316XGL_LAYER_EXPORT void XGLAPI xglCmdClearColorImage(
2317 XGL_CMD_BUFFER cmdBuffer,
2318 XGL_IMAGE image, XGL_IMAGE_LAYOUT imageLayout,
2319 XGL_CLEAR_COLOR color,
2320 uint32_t rangeCount, const XGL_IMAGE_SUBRESOURCE_RANGE* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002321{
2322 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2323 if (pCB) {
2324 updateCBTracking(cmdBuffer);
2325 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2326 }
2327 else {
2328 char str[1024];
2329 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2330 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2331 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002332 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002333}
2334
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002335XGL_LAYER_EXPORT void XGLAPI xglCmdClearDepthStencil(
2336 XGL_CMD_BUFFER cmdBuffer,
2337 XGL_IMAGE image, XGL_IMAGE_LAYOUT imageLayout,
2338 float depth, uint32_t stencil,
2339 uint32_t rangeCount, const XGL_IMAGE_SUBRESOURCE_RANGE* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002340{
2341 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2342 if (pCB) {
2343 updateCBTracking(cmdBuffer);
2344 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2345 }
2346 else {
2347 char str[1024];
2348 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2349 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2350 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002351 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002352}
2353
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002354XGL_LAYER_EXPORT void XGLAPI xglCmdResolveImage(
2355 XGL_CMD_BUFFER cmdBuffer,
2356 XGL_IMAGE srcImage, XGL_IMAGE_LAYOUT srcImageLayout,
2357 XGL_IMAGE destImage, XGL_IMAGE_LAYOUT destImageLayout,
2358 uint32_t rectCount, const XGL_IMAGE_RESOLVE* pRects)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359{
2360 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2361 if (pCB) {
2362 updateCBTracking(cmdBuffer);
2363 addCmd(pCB, CMD_RESOLVEIMAGE);
2364 }
2365 else {
2366 char str[1024];
2367 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2368 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2369 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002370 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, rectCount, pRects);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002371}
2372
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002373XGL_LAYER_EXPORT void XGLAPI xglCmdSetEvent(XGL_CMD_BUFFER cmdBuffer, XGL_EVENT event, XGL_PIPE_EVENT pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002374{
2375 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2376 if (pCB) {
2377 updateCBTracking(cmdBuffer);
2378 addCmd(pCB, CMD_SETEVENT);
2379 }
2380 else {
2381 char str[1024];
2382 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2383 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2384 }
2385 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2386}
2387
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002388XGL_LAYER_EXPORT void XGLAPI xglCmdResetEvent(XGL_CMD_BUFFER cmdBuffer, XGL_EVENT event, XGL_PIPE_EVENT pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002389{
2390 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2391 if (pCB) {
2392 updateCBTracking(cmdBuffer);
2393 addCmd(pCB, CMD_RESETEVENT);
2394 }
2395 else {
2396 char str[1024];
2397 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2398 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2399 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002400 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002401}
2402
2403XGL_LAYER_EXPORT void XGLAPI xglCmdWaitEvents(XGL_CMD_BUFFER cmdBuffer, const XGL_EVENT_WAIT_INFO* pWaitInfo)
2404{
2405 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2406 if (pCB) {
2407 updateCBTracking(cmdBuffer);
2408 addCmd(pCB, CMD_WAITEVENTS);
2409 }
2410 else {
2411 char str[1024];
2412 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2413 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2414 }
2415 nextTable.CmdWaitEvents(cmdBuffer, pWaitInfo);
2416}
2417
2418XGL_LAYER_EXPORT void XGLAPI xglCmdPipelineBarrier(XGL_CMD_BUFFER cmdBuffer, const XGL_PIPELINE_BARRIER* pBarrier)
2419{
2420 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2421 if (pCB) {
2422 updateCBTracking(cmdBuffer);
2423 addCmd(pCB, CMD_PIPELINEBARRIER);
2424 }
2425 else {
2426 char str[1024];
2427 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2428 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2429 }
2430 nextTable.CmdPipelineBarrier(cmdBuffer, pBarrier);
2431}
2432
2433XGL_LAYER_EXPORT void XGLAPI xglCmdBeginQuery(XGL_CMD_BUFFER cmdBuffer, XGL_QUERY_POOL queryPool, uint32_t slot, XGL_FLAGS flags)
2434{
2435 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2436 if (pCB) {
2437 updateCBTracking(cmdBuffer);
2438 addCmd(pCB, CMD_BEGINQUERY);
2439 }
2440 else {
2441 char str[1024];
2442 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2443 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2444 }
2445 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2446}
2447
2448XGL_LAYER_EXPORT void XGLAPI xglCmdEndQuery(XGL_CMD_BUFFER cmdBuffer, XGL_QUERY_POOL queryPool, uint32_t slot)
2449{
2450 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2451 if (pCB) {
2452 updateCBTracking(cmdBuffer);
2453 addCmd(pCB, CMD_ENDQUERY);
2454 }
2455 else {
2456 char str[1024];
2457 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2458 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2459 }
2460 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2461}
2462
2463XGL_LAYER_EXPORT void XGLAPI xglCmdResetQueryPool(XGL_CMD_BUFFER cmdBuffer, XGL_QUERY_POOL queryPool, uint32_t startQuery, uint32_t queryCount)
2464{
2465 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2466 if (pCB) {
2467 updateCBTracking(cmdBuffer);
2468 addCmd(pCB, CMD_RESETQUERYPOOL);
2469 }
2470 else {
2471 char str[1024];
2472 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2473 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2474 }
2475 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2476}
2477
2478XGL_LAYER_EXPORT void XGLAPI xglCmdWriteTimestamp(XGL_CMD_BUFFER cmdBuffer, XGL_TIMESTAMP_TYPE timestampType, XGL_BUFFER destBuffer, XGL_GPU_SIZE destOffset)
2479{
2480 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2481 if (pCB) {
2482 updateCBTracking(cmdBuffer);
2483 addCmd(pCB, CMD_WRITETIMESTAMP);
2484 }
2485 else {
2486 char str[1024];
2487 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2488 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2489 }
2490 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2491}
2492
2493XGL_LAYER_EXPORT void XGLAPI xglCmdInitAtomicCounters(XGL_CMD_BUFFER cmdBuffer, XGL_PIPELINE_BIND_POINT pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
2494{
2495 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2496 if (pCB) {
2497 updateCBTracking(cmdBuffer);
2498 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2499 }
2500 else {
2501 char str[1024];
2502 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2503 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2504 }
2505 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2506}
2507
2508XGL_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)
2509{
2510 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2511 if (pCB) {
2512 updateCBTracking(cmdBuffer);
2513 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2514 }
2515 else {
2516 char str[1024];
2517 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2518 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2519 }
2520 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2521}
2522
2523XGL_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)
2524{
2525 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2526 if (pCB) {
2527 updateCBTracking(cmdBuffer);
2528 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2529 }
2530 else {
2531 char str[1024];
2532 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2533 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2534 }
2535 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2536}
2537
Tobin Ehlis2464b882015-04-01 08:40:34 -06002538XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateFramebuffer(XGL_DEVICE device, const XGL_FRAMEBUFFER_CREATE_INFO* pCreateInfo, XGL_FRAMEBUFFER* pFramebuffer)
2539{
2540 XGL_RESULT result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
2541 if (XGL_SUCCESS == result) {
2542 // Shadow create info and store in map
2543 XGL_FRAMEBUFFER_CREATE_INFO* localFBCI = new XGL_FRAMEBUFFER_CREATE_INFO(*pCreateInfo);
2544 if (pCreateInfo->pColorAttachments) {
2545 localFBCI->pColorAttachments = new XGL_COLOR_ATTACHMENT_BIND_INFO[localFBCI->colorAttachmentCount];
2546 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(XGL_COLOR_ATTACHMENT_BIND_INFO));
2547 }
2548 if (pCreateInfo->pDepthStencilAttachment) {
2549 localFBCI->pDepthStencilAttachment = new XGL_DEPTH_STENCIL_BIND_INFO[localFBCI->colorAttachmentCount];
2550 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(XGL_DEPTH_STENCIL_BIND_INFO));
2551 }
2552 frameBufferMap[*pFramebuffer] = localFBCI;
2553 }
2554 return result;
2555}
2556
2557XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateRenderPass(XGL_DEVICE device, const XGL_RENDER_PASS_CREATE_INFO* pCreateInfo, XGL_RENDER_PASS* pRenderPass)
2558{
2559 XGL_RESULT result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
2560 if (XGL_SUCCESS == result) {
2561 // Shadow create info and store in map
2562 XGL_RENDER_PASS_CREATE_INFO* localRPCI = new XGL_RENDER_PASS_CREATE_INFO(*pCreateInfo);
2563 if (pCreateInfo->pColorLoadOps) {
2564 localRPCI->pColorLoadOps = new XGL_ATTACHMENT_LOAD_OP[localRPCI->colorAttachmentCount];
2565 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(XGL_ATTACHMENT_LOAD_OP));
2566 }
2567 if (pCreateInfo->pColorStoreOps) {
2568 localRPCI->pColorStoreOps = new XGL_ATTACHMENT_STORE_OP[localRPCI->colorAttachmentCount];
2569 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(XGL_ATTACHMENT_STORE_OP));
2570 }
2571 if (pCreateInfo->pColorLoadClearValues) {
2572 localRPCI->pColorLoadClearValues = new XGL_CLEAR_COLOR[localRPCI->colorAttachmentCount];
2573 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(XGL_CLEAR_COLOR));
2574 }
2575 renderPassMap[*pRenderPass] = localRPCI;
2576 }
2577 return result;
2578}
2579
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002580XGL_LAYER_EXPORT void XGLAPI xglCmdBeginRenderPass(XGL_CMD_BUFFER cmdBuffer, const XGL_RENDER_PASS_BEGIN *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002581{
2582 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2583 if (pCB) {
2584 updateCBTracking(cmdBuffer);
2585 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002586 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2587 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002588 validatePipelineState(pCB, XGL_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002589 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002590 char str[1024];
2591 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2592 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2593 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002594 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002595}
2596
2597XGL_LAYER_EXPORT void XGLAPI xglCmdEndRenderPass(XGL_CMD_BUFFER cmdBuffer, XGL_RENDER_PASS renderPass)
2598{
2599 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2600 if (pCB) {
2601 updateCBTracking(cmdBuffer);
2602 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002603 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604 }
2605 else {
2606 char str[1024];
2607 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2608 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2609 }
2610 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2611}
2612
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002613XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002614{
2615 // This layer intercepts callbacks
2616 XGL_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));
2617#if ALLOC_DEBUG
2618 printf("Alloc34 #%lu pNewDbgFuncNode addr(%p)\n", ++g_alloc_count, (void*)pNewDbgFuncNode);
2619#endif
2620 if (!pNewDbgFuncNode)
2621 return XGL_ERROR_OUT_OF_MEMORY;
2622 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2623 pNewDbgFuncNode->pUserData = pUserData;
2624 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2625 g_pDbgFunctionHead = pNewDbgFuncNode;
2626 // force callbacks if DebugAction hasn't been set already other than initial value
2627 if (g_actionIsDefault) {
2628 g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;
2629 }
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002630 XGL_RESULT result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002631 return result;
2632}
2633
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002634XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002635{
2636 XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2637 XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
2638 while (pTrav) {
2639 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2640 pPrev->pNext = pTrav->pNext;
2641 if (g_pDbgFunctionHead == pTrav)
2642 g_pDbgFunctionHead = pTrav->pNext;
2643#if ALLOC_DEBUG
2644 printf("Free34 #%lu pNewDbgFuncNode addr(%p)\n", ++g_alloc_count, (void*)pTrav);
2645#endif
2646 free(pTrav);
2647 break;
2648 }
2649 pPrev = pTrav;
2650 pTrav = pTrav->pNext;
2651 }
2652 if (g_pDbgFunctionHead == NULL)
2653 {
2654 if (g_actionIsDefault)
2655 g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;
2656 else
2657 g_debugAction = (XGL_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)XGL_DBG_LAYER_ACTION_CALLBACK));
2658 }
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -06002659 XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002660 return result;
2661}
2662
2663XGL_LAYER_EXPORT void XGLAPI xglCmdDbgMarkerBegin(XGL_CMD_BUFFER cmdBuffer, const char* pMarker)
2664{
2665 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2666 if (pCB) {
2667 updateCBTracking(cmdBuffer);
2668 addCmd(pCB, CMD_DBGMARKERBEGIN);
2669 }
2670 else {
2671 char str[1024];
2672 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2673 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2674 }
2675 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2676}
2677
2678XGL_LAYER_EXPORT void XGLAPI xglCmdDbgMarkerEnd(XGL_CMD_BUFFER cmdBuffer)
2679{
2680 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2681 if (pCB) {
2682 updateCBTracking(cmdBuffer);
2683 addCmd(pCB, CMD_DBGMARKEREND);
2684 }
2685 else {
2686 char str[1024];
2687 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
2688 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
2689 }
2690 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2691}
2692
2693// TODO : Want to pass in a cmdBuffer here based on which state to display
2694void drawStateDumpDotFile(char* outFileName)
2695{
2696 // TODO : Currently just setting cmdBuffer based on global var
2697 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2698 dumpGlobalDotFile(outFileName);
2699}
2700
2701void drawStateDumpCommandBufferDotFile(char* outFileName)
2702{
2703 cbDumpDotFile(outFileName);
2704}
2705
2706void drawStateDumpPngFile(char* outFileName)
2707{
2708#if defined(_WIN32)
2709// FIXME: NEED WINDOWS EQUIVALENT
2710 char str[1024];
2711 sprintf(str, "Cannot execute dot program yet on Windows.");
2712 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
2713#else // WIN32
2714 char dotExe[32] = "/usr/bin/dot";
2715 if( access(dotExe, X_OK) != -1) {
2716 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2717 char dotCmd[1024];
2718 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
2719 system(dotCmd);
2720 remove("/tmp/tmp.dot");
2721 }
2722 else {
2723 char str[1024];
2724 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
2725 layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
2726 }
2727#endif // WIN32
2728}
2729
2730XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)
2731{
2732 XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
2733
2734 if (gpu == NULL)
2735 return NULL;
2736 pCurObj = gpuw;
2737 loader_platform_thread_once(&g_initOnce, initDrawState);
2738
2739 if (!strcmp(funcName, "xglGetProcAddr"))
2740 return (void *) xglGetProcAddr;
2741 if (!strcmp(funcName, "xglCreateDevice"))
2742 return (void*) xglCreateDevice;
2743 if (!strcmp(funcName, "xglDestroyDevice"))
2744 return (void*) xglDestroyDevice;
2745 if (!strcmp(funcName, "xglEnumerateLayers"))
2746 return (void*) xglEnumerateLayers;
2747 if (!strcmp(funcName, "xglQueueSubmit"))
2748 return (void*) xglQueueSubmit;
2749 if (!strcmp(funcName, "xglDestroyObject"))
2750 return (void*) xglDestroyObject;
2751 if (!strcmp(funcName, "xglCreateBufferView"))
2752 return (void*) xglCreateBufferView;
2753 if (!strcmp(funcName, "xglCreateImageView"))
2754 return (void*) xglCreateImageView;
2755 if (!strcmp(funcName, "xglCreateGraphicsPipeline"))
2756 return (void*) xglCreateGraphicsPipeline;
Tobin Ehlise19e7ed2015-03-17 16:24:32 -06002757 if (!strcmp(funcName, "xglCreateGraphicsPipelineDerivative"))
2758 return (void*) xglCreateGraphicsPipelineDerivative;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002759 if (!strcmp(funcName, "xglCreateSampler"))
2760 return (void*) xglCreateSampler;
2761 if (!strcmp(funcName, "xglCreateDescriptorSetLayout"))
2762 return (void*) xglCreateDescriptorSetLayout;
2763 if (!strcmp(funcName, "xglBeginDescriptorRegionUpdate"))
2764 return (void*) xglBeginDescriptorRegionUpdate;
2765 if (!strcmp(funcName, "xglEndDescriptorRegionUpdate"))
2766 return (void*) xglEndDescriptorRegionUpdate;
2767 if (!strcmp(funcName, "xglCreateDescriptorRegion"))
2768 return (void*) xglCreateDescriptorRegion;
2769 if (!strcmp(funcName, "xglClearDescriptorRegion"))
2770 return (void*) xglClearDescriptorRegion;
2771 if (!strcmp(funcName, "xglAllocDescriptorSets"))
2772 return (void*) xglAllocDescriptorSets;
2773 if (!strcmp(funcName, "xglClearDescriptorSets"))
2774 return (void*) xglClearDescriptorSets;
2775 if (!strcmp(funcName, "xglUpdateDescriptors"))
2776 return (void*) xglUpdateDescriptors;
2777 if (!strcmp(funcName, "xglCreateDynamicViewportState"))
2778 return (void*) xglCreateDynamicViewportState;
2779 if (!strcmp(funcName, "xglCreateDynamicRasterState"))
2780 return (void*) xglCreateDynamicRasterState;
2781 if (!strcmp(funcName, "xglCreateDynamicColorBlendState"))
2782 return (void*) xglCreateDynamicColorBlendState;
2783 if (!strcmp(funcName, "xglCreateDynamicDepthStencilState"))
2784 return (void*) xglCreateDynamicDepthStencilState;
2785 if (!strcmp(funcName, "xglCreateCommandBuffer"))
2786 return (void*) xglCreateCommandBuffer;
2787 if (!strcmp(funcName, "xglBeginCommandBuffer"))
2788 return (void*) xglBeginCommandBuffer;
2789 if (!strcmp(funcName, "xglEndCommandBuffer"))
2790 return (void*) xglEndCommandBuffer;
2791 if (!strcmp(funcName, "xglResetCommandBuffer"))
2792 return (void*) xglResetCommandBuffer;
2793 if (!strcmp(funcName, "xglCmdBindPipeline"))
2794 return (void*) xglCmdBindPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002795 if (!strcmp(funcName, "xglCmdBindDynamicStateObject"))
2796 return (void*) xglCmdBindDynamicStateObject;
2797 if (!strcmp(funcName, "xglCmdBindDescriptorSet"))
2798 return (void*) xglCmdBindDescriptorSet;
2799 if (!strcmp(funcName, "xglCmdBindVertexBuffer"))
2800 return (void*) xglCmdBindVertexBuffer;
2801 if (!strcmp(funcName, "xglCmdBindIndexBuffer"))
2802 return (void*) xglCmdBindIndexBuffer;
2803 if (!strcmp(funcName, "xglCmdDraw"))
2804 return (void*) xglCmdDraw;
2805 if (!strcmp(funcName, "xglCmdDrawIndexed"))
2806 return (void*) xglCmdDrawIndexed;
2807 if (!strcmp(funcName, "xglCmdDrawIndirect"))
2808 return (void*) xglCmdDrawIndirect;
2809 if (!strcmp(funcName, "xglCmdDrawIndexedIndirect"))
2810 return (void*) xglCmdDrawIndexedIndirect;
2811 if (!strcmp(funcName, "xglCmdDispatch"))
2812 return (void*) xglCmdDispatch;
2813 if (!strcmp(funcName, "xglCmdDispatchIndirect"))
2814 return (void*) xglCmdDispatchIndirect;
2815 if (!strcmp(funcName, "xglCmdCopyBuffer"))
2816 return (void*) xglCmdCopyBuffer;
2817 if (!strcmp(funcName, "xglCmdCopyImage"))
2818 return (void*) xglCmdCopyImage;
2819 if (!strcmp(funcName, "xglCmdCopyBufferToImage"))
2820 return (void*) xglCmdCopyBufferToImage;
2821 if (!strcmp(funcName, "xglCmdCopyImageToBuffer"))
2822 return (void*) xglCmdCopyImageToBuffer;
2823 if (!strcmp(funcName, "xglCmdCloneImageData"))
2824 return (void*) xglCmdCloneImageData;
2825 if (!strcmp(funcName, "xglCmdUpdateBuffer"))
2826 return (void*) xglCmdUpdateBuffer;
2827 if (!strcmp(funcName, "xglCmdFillBuffer"))
2828 return (void*) xglCmdFillBuffer;
2829 if (!strcmp(funcName, "xglCmdClearColorImage"))
2830 return (void*) xglCmdClearColorImage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002831 if (!strcmp(funcName, "xglCmdClearDepthStencil"))
2832 return (void*) xglCmdClearDepthStencil;
2833 if (!strcmp(funcName, "xglCmdResolveImage"))
2834 return (void*) xglCmdResolveImage;
2835 if (!strcmp(funcName, "xglCmdSetEvent"))
2836 return (void*) xglCmdSetEvent;
2837 if (!strcmp(funcName, "xglCmdResetEvent"))
2838 return (void*) xglCmdResetEvent;
2839 if (!strcmp(funcName, "xglCmdWaitEvents"))
2840 return (void*) xglCmdWaitEvents;
2841 if (!strcmp(funcName, "xglCmdPipelineBarrier"))
2842 return (void*) xglCmdPipelineBarrier;
2843 if (!strcmp(funcName, "xglCmdBeginQuery"))
2844 return (void*) xglCmdBeginQuery;
2845 if (!strcmp(funcName, "xglCmdEndQuery"))
2846 return (void*) xglCmdEndQuery;
2847 if (!strcmp(funcName, "xglCmdResetQueryPool"))
2848 return (void*) xglCmdResetQueryPool;
2849 if (!strcmp(funcName, "xglCmdWriteTimestamp"))
2850 return (void*) xglCmdWriteTimestamp;
2851 if (!strcmp(funcName, "xglCmdInitAtomicCounters"))
2852 return (void*) xglCmdInitAtomicCounters;
2853 if (!strcmp(funcName, "xglCmdLoadAtomicCounters"))
2854 return (void*) xglCmdLoadAtomicCounters;
2855 if (!strcmp(funcName, "xglCmdSaveAtomicCounters"))
2856 return (void*) xglCmdSaveAtomicCounters;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002857 if (!strcmp(funcName, "xglCreateFramebuffer"))
2858 return (void*) xglCreateFramebuffer;
2859 if (!strcmp(funcName, "xglCreateRenderPass"))
2860 return (void*) xglCreateRenderPass;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002861 if (!strcmp(funcName, "xglCmdBeginRenderPass"))
2862 return (void*) xglCmdBeginRenderPass;
2863 if (!strcmp(funcName, "xglCmdEndRenderPass"))
2864 return (void*) xglCmdEndRenderPass;
2865 if (!strcmp(funcName, "xglDbgRegisterMsgCallback"))
2866 return (void*) xglDbgRegisterMsgCallback;
2867 if (!strcmp(funcName, "xglDbgUnregisterMsgCallback"))
2868 return (void*) xglDbgUnregisterMsgCallback;
2869 if (!strcmp(funcName, "xglCmdDbgMarkerBegin"))
2870 return (void*) xglCmdDbgMarkerBegin;
2871 if (!strcmp(funcName, "xglCmdDbgMarkerEnd"))
2872 return (void*) xglCmdDbgMarkerEnd;
2873 if (!strcmp("drawStateDumpDotFile", funcName))
2874 return (void*) drawStateDumpDotFile;
2875 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2876 return (void*) drawStateDumpCommandBufferDotFile;
2877 if (!strcmp("drawStateDumpPngFile", funcName))
2878 return (void*) drawStateDumpPngFile;
2879 else {
2880 if (gpuw->pGPA == NULL)
2881 return NULL;
2882 return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);
2883 }
2884}