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