blob: ab1fd0fcd597e9b2c6a753f38e4eaad3b013c717 [file] [log] [blame]
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -06001/*
2 * XGL Tests
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 * Authors:
25 * Courtney Goeltzenleuchter <courtney@lunarg.com>
26 */
27
28#include "xglrenderframework.h"
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060029
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060030XglRenderFramework::XglRenderFramework() :
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060031 m_cmdBuffer( XGL_NULL_HANDLE ),
Chia-I Wu837f9952014-12-15 23:29:34 +080032 m_stateRaster( XGL_NULL_HANDLE ),
33 m_colorBlend( XGL_NULL_HANDLE ),
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -060034 m_stateViewport( XGL_NULL_HANDLE ),
Chia-I Wu837f9952014-12-15 23:29:34 +080035 m_stateDepthStencil( XGL_NULL_HANDLE ),
36 m_stateMsaa( XGL_NULL_HANDLE ),
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -060037 m_width( 256.0 ), // default window width
38 m_height( 256.0 ) // default window height
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060039{
Chia-I Wuecebf752014-12-05 10:45:15 +080040 m_renderTargetCount = 1;
41
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060042 m_render_target_fmt.channelFormat = XGL_CH_FMT_R8G8B8A8;
43 m_render_target_fmt.numericFormat = XGL_NUM_FMT_UNORM;
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -060044
Chia-I Wuecebf752014-12-05 10:45:15 +080045 m_colorBindings[0].view = XGL_NULL_HANDLE;
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -060046 m_depthStencilBinding.view = XGL_NULL_HANDLE;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060047}
48
49XglRenderFramework::~XglRenderFramework()
50{
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060051
52}
53
54void XglRenderFramework::InitFramework()
55{
56 XGL_RESULT err;
57
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060058 err = xglInitAndEnumerateGpus(&app_info, NULL,
Chia-I Wuaf11d922014-12-28 14:37:25 +080059 XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, objs);
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060060 ASSERT_XGL_SUCCESS(err);
Jon Ashburnbf843b22014-11-26 11:06:49 -070061 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060062
63 m_device = new XglDevice(0, objs[0]);
64 m_device->get_device_queue();
65}
66
67void XglRenderFramework::ShutdownFramework()
68{
69 if (m_colorBlend) xglDestroyObject(m_colorBlend);
70 if (m_stateMsaa) xglDestroyObject(m_stateMsaa);
71 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
72 if (m_stateRaster) xglDestroyObject(m_stateRaster);
73 if (m_cmdBuffer) xglDestroyObject(m_cmdBuffer);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060074
75 if (m_stateViewport) {
76 xglDestroyObject(m_stateViewport);
77 }
78
Chia-I Wuecebf752014-12-05 10:45:15 +080079 for (XGL_UINT i = 0; i < m_renderTargetCount; i++) {
80 if (m_renderTargets[i]) {
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060081 // TODO: XglImage should be able to destroy itself
82// m_renderTarget->
83// xglDestroyObject(*m_renderTarget);
Chia-I Wuecebf752014-12-05 10:45:15 +080084 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060085 }
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060086
87 // reset the driver
Chia-I Wub76e0fa2014-12-28 14:27:28 +080088 delete m_device;
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060089 xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060090}
91
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060092void XglRenderFramework::InitState()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060093{
94 XGL_RESULT err;
95
96 m_render_target_fmt.channelFormat = XGL_CH_FMT_R8G8B8A8;
97 m_render_target_fmt.numericFormat = XGL_NUM_FMT_UNORM;
98
99 // create a raster state (solid, back-face culling)
100 XGL_RASTER_STATE_CREATE_INFO raster = {};
101 raster.sType = XGL_STRUCTURE_TYPE_RASTER_STATE_CREATE_INFO;
102 raster.fillMode = XGL_FILL_SOLID;
103 raster.cullMode = XGL_CULL_NONE;
104 raster.frontFace = XGL_FRONT_FACE_CCW;
105 err = xglCreateRasterState( device(), &raster, &m_stateRaster );
106 ASSERT_XGL_SUCCESS(err);
107
108 XGL_COLOR_BLEND_STATE_CREATE_INFO blend = {};
109 blend.sType = XGL_STRUCTURE_TYPE_COLOR_BLEND_STATE_CREATE_INFO;
110 err = xglCreateColorBlendState(device(), &blend, &m_colorBlend);
111 ASSERT_XGL_SUCCESS( err );
112
113 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
114 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
115 depthStencil.depthTestEnable = XGL_FALSE;
116 depthStencil.depthWriteEnable = XGL_FALSE;
117 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
118 depthStencil.depthBoundsEnable = XGL_FALSE;
119 depthStencil.minDepth = 0.f;
120 depthStencil.maxDepth = 1.f;
121 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
122 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
123 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
124 depthStencil.back.stencilRef = 0x00;
125 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
126 depthStencil.front = depthStencil.back;
127
128 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
129 ASSERT_XGL_SUCCESS( err );
130
131 XGL_MSAA_STATE_CREATE_INFO msaa = {};
132 msaa.sType = XGL_STRUCTURE_TYPE_MSAA_STATE_CREATE_INFO;
133 msaa.sampleMask = 1;
134 msaa.samples = 1;
135
136 err = xglCreateMsaaState( device(), &msaa, &m_stateMsaa );
137 ASSERT_XGL_SUCCESS( err );
138
139 XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {};
140
141 cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
142 cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS;
143 err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer);
144 ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed";
145}
146
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600147void XglRenderFramework::InitViewport(float width, float height)
148{
149 XGL_RESULT err;
150
151 XGL_VIEWPORT_STATE_CREATE_INFO viewport = {};
152 viewport.viewportCount = 1;
153 viewport.scissorEnable = XGL_FALSE;
154 viewport.viewports[0].originX = 0;
155 viewport.viewports[0].originY = 0;
156 viewport.viewports[0].width = 1.f * width;
157 viewport.viewports[0].height = 1.f * height;
158 viewport.viewports[0].minDepth = 0.f;
159 viewport.viewports[0].maxDepth = 1.f;
160
161 err = xglCreateViewportState( device(), &viewport, &m_stateViewport );
162 ASSERT_XGL_SUCCESS( err );
163 m_width = width;
164 m_height = height;
165}
166
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600167void XglRenderFramework::InitViewport()
168{
169 InitViewport(m_width, m_height);
170}
171
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600172void XglRenderFramework::InitRenderTarget()
173{
Chia-I Wuecebf752014-12-05 10:45:15 +0800174 XGL_UINT i;
175
176 for (i = 0; i < m_renderTargetCount; i++) {
177 m_device->CreateImage(m_width, m_height, m_render_target_fmt,
178 XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT |
179 XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
180 &m_renderTargets[i]);
181 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600182}
183
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600184void XglRenderFramework::GenerateBindRenderTargetCmd()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600185{
Chia-I Wuecebf752014-12-05 10:45:15 +0800186 XGL_UINT i;
187
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600188 // bind render target
Chia-I Wuecebf752014-12-05 10:45:15 +0800189 for (i = 0; i < m_renderTargetCount; i++) {
190 m_colorBindings[i].view = m_renderTargets[i]->targetView();
191 m_colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
192 }
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600193 if (m_depthStencilBinding.view) {
Chia-I Wuecebf752014-12-05 10:45:15 +0800194 xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, &m_depthStencilBinding );
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600195 } else {
Chia-I Wuecebf752014-12-05 10:45:15 +0800196 xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, XGL_NULL_HANDLE );
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600197 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600198}
199
Tony Barboure2c58df2014-11-25 13:18:32 -0700200void XglRenderFramework::GenerateBindStateAndPipelineCmds()
201{
202 // set all states
203 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster );
204 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport );
205 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
206 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil );
207 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa );
208}
209
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600210void XglRenderFramework::GenerateClearAndPrepareBufferCmds()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600211{
Chia-I Wuecebf752014-12-05 10:45:15 +0800212 XGL_UINT i;
213
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600214 // whatever we want to do, we do it to the whole buffer
215 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
216 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
217 srRange.baseMipLevel = 0;
218 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
219 srRange.baseArraySlice = 0;
220 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
221
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600222 // clear the back buffer to dark grey
223 XGL_UINT clearColor[4] = {64, 64, 64, 0};
Chia-I Wuecebf752014-12-05 10:45:15 +0800224 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
225 for (i = 0; i < m_renderTargetCount; i++) {
226 transitionToClear.image = m_renderTargets[i]->image();
227 transitionToClear.oldState = m_renderTargets[i]->state();
228 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
229 transitionToClear.subresourceRange = srRange;
230 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
231 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
232
233 xglCmdClearColorImageRaw( m_cmdBuffer, m_renderTargets[i]->image(), clearColor, 1, &srRange );
234 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600235
236 // prepare back buffer for rendering
237 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wuecebf752014-12-05 10:45:15 +0800238 for (i = 0; i < m_renderTargetCount; i++) {
239 transitionToRender.image = m_renderTargets[i]->image();
240 transitionToRender.oldState = m_renderTargets[i]->state();
241 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
242 transitionToRender.subresourceRange = srRange;
243 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
244 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
245 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600246}
Tony Barbour82c39522014-12-04 14:33:33 -0700247
Tony Barboure2c58df2014-11-25 13:18:32 -0700248XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device)
249{
250 m_device = device;
251 m_nextSlot = 0;
252
253}
254
255void XglDescriptorSetObj::AttachMemoryView(XglConstantBufferObj *constantBuffer)
256{
257 m_memoryViews.push_back(&constantBuffer->m_constantBufferView);
258 m_memorySlots.push_back(m_nextSlot);
259 m_nextSlot++;
260
261}
Tony Barbour82c39522014-12-04 14:33:33 -0700262
Tony Barboure2c58df2014-11-25 13:18:32 -0700263void XglDescriptorSetObj::AttachSampler(XglSamplerObj *sampler)
264{
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800265 m_samplers.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700266 m_samplerSlots.push_back(m_nextSlot);
267 m_nextSlot++;
268
269}
Tony Barbour82c39522014-12-04 14:33:33 -0700270
Tony Barboure2c58df2014-11-25 13:18:32 -0700271void XglDescriptorSetObj::AttachImageView(XglTextureObj *texture)
272{
273 m_imageViews.push_back(&texture->m_textureViewInfo);
274 m_imageSlots.push_back(m_nextSlot);
275 m_nextSlot++;
276
277}
Tony Barbour82c39522014-12-04 14:33:33 -0700278
Tony Barboure2c58df2014-11-25 13:18:32 -0700279XGL_DESCRIPTOR_SLOT_INFO* XglDescriptorSetObj::GetSlotInfo(vector<int>slots,
280 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types,
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800281 vector<void *>objs )
Tony Barboure2c58df2014-11-25 13:18:32 -0700282{
283 int nSlots = m_memorySlots.size() + m_imageSlots.size() + m_samplerSlots.size();
284 m_slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( nSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
285 memset(m_slotInfo,0,nSlots*sizeof(XGL_DESCRIPTOR_SLOT_INFO));
286
287 for (int i=0; i<nSlots; i++)
288 {
289 m_slotInfo[i].slotObjectType = XGL_SLOT_UNUSED;
290 }
291
292 for (int i=0; i<slots.size(); i++)
293 {
294 for (int j=0; j<m_memorySlots.size(); j++)
295 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800296 if ( m_memoryViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700297 {
298 m_slotInfo[m_memorySlots[j]].shaderEntityIndex = slots[i];
299 m_slotInfo[m_memorySlots[j]].slotObjectType = types[i];
300 }
301 }
302 for (int j=0; j<m_imageSlots.size(); j++)
303 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800304 if ( m_imageViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700305 {
306 m_slotInfo[m_imageSlots[j]].shaderEntityIndex = slots[i];
307 m_slotInfo[m_imageSlots[j]].slotObjectType = types[i];
308 }
309 }
310 for (int j=0; j<m_samplerSlots.size(); j++)
311 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800312 if ( m_samplers[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700313 {
314 m_slotInfo[m_samplerSlots[j]].shaderEntityIndex = slots[i];
315 m_slotInfo[m_samplerSlots[j]].slotObjectType = types[i];
316 }
317 }
318 }
319
320 // for (int i=0;i<nSlots;i++)
321 // {
322 // printf("SlotInfo[%d]: Index = %d, Type = %d\n",i,m_slotInfo[i].shaderEntityIndex, m_slotInfo[i].slotObjectType);
323 // fflush(stdout);
324 // }
325
326 return(m_slotInfo);
327
328}
Tony Barbourb5f4d082014-12-17 10:54:03 -0700329void XglDescriptorSetObj::CreateXGLDescriptorSet()
330{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800331 init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot));
Tony Barbourb5f4d082014-12-17 10:54:03 -0700332
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800333 begin();
334 clear();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700335
Tony Barbourb5f4d082014-12-17 10:54:03 -0700336 for (int i=0; i<m_memoryViews.size();i++)
337 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800338 attach(m_memorySlots[i], *m_memoryViews[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700339 }
340 for (int i=0; i<m_samplers.size();i++)
341 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800342 attach(m_samplerSlots[i], *m_samplers[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700343 }
344 for (int i=0; i<m_imageViews.size();i++)
345 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800346 attach(m_imageSlots[i], *m_imageViews[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700347 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800348
349 end();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700350}
351
352XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle()
353{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800354 return obj();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700355}
Tony Barboure2c58df2014-11-25 13:18:32 -0700356
Tony Barbour824b7712014-12-18 17:06:21 -0700357int XglDescriptorSetObj::GetTotalSlots()
358{
359 return m_nextSlot;
360}
361
Tony Barboure2c58df2014-11-25 13:18:32 -0700362void XglDescriptorSetObj::BindCommandBuffer(XGL_CMD_BUFFER commandBuffer)
363{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800364 init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot));
Tony Barboure2c58df2014-11-25 13:18:32 -0700365
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800366 begin();
367 clear();
Tony Barboure2c58df2014-11-25 13:18:32 -0700368
Tony Barboure2c58df2014-11-25 13:18:32 -0700369 for (int i=0; i<m_memoryViews.size();i++)
370 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800371 attach(m_memorySlots[i], *m_memoryViews[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700372 }
373 for (int i=0; i<m_samplers.size();i++)
374 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800375 attach(m_samplerSlots[i], *m_samplers[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700376 }
377 for (int i=0; i<m_imageViews.size();i++)
378 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800379 attach(m_imageSlots[i], *m_imageViews[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700380 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800381
382 end();
Tony Barboure2c58df2014-11-25 13:18:32 -0700383
384 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800385 xglCmdBindDescriptorSet(commandBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, obj(), 0 );
Tony Barbour25ef8a62014-12-03 13:59:18 -0700386}
Tony Barboure2c58df2014-11-25 13:18:32 -0700387
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800388XglImage::XglImage(XglDevice *dev)
389{
390 m_device = dev;
391 m_imageInfo.view = XGL_NULL_HANDLE;
392 m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET;
393}
394
395void XglImage::init(XGL_UINT32 w, XGL_UINT32 h,
396 XGL_FORMAT fmt, XGL_FLAGS usage,
397 XGL_IMAGE_TILING tiling)
398{
399 XGL_UINT mipCount;
400
401 mipCount = 0;
402
403 XGL_UINT _w = w;
404 XGL_UINT _h = h;
405 while( ( _w > 0 ) || ( _h > 0 ) )
406 {
407 _w >>= 1;
408 _h >>= 1;
409 mipCount++;
410 }
411
412 XGL_IMAGE_CREATE_INFO imageCreateInfo = xgl_testing::Image::create_info();
413 imageCreateInfo.imageType = XGL_IMAGE_2D;
414 imageCreateInfo.format = fmt;
415 imageCreateInfo.extent.width = w;
416 imageCreateInfo.extent.height = h;
417 imageCreateInfo.mipLevels = mipCount;
418 imageCreateInfo.tiling = tiling;
419
420 imageCreateInfo.usage = usage;
421
422 xgl_testing::Image::init(*m_device, imageCreateInfo);
423
424 m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET;
425
426 XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO createView = {
427 XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO,
428 XGL_NULL_HANDLE,
429 obj(),
430 {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM},
431 0,
432 0,
433 1
434 };
435
436 m_targetView.init(*m_device, createView);
437}
438
439XGL_RESULT XglImage::MapMemory(XGL_VOID** ptr)
440{
441 *ptr = map();
442 return (*ptr) ? XGL_SUCCESS : XGL_ERROR_UNKNOWN;
443}
444
445XGL_RESULT XglImage::UnmapMemory()
446{
447 unmap();
448 return XGL_SUCCESS;
449}
450
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800451XglTextureObj::XglTextureObj(XglDevice *device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700452{
453 m_device = device;
454 const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM };
Tony Barboure2c58df2014-11-25 13:18:32 -0700455 const uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 };
Tony Barboure2c58df2014-11-25 13:18:32 -0700456
457 memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo));
458
459 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
460
461 const XGL_IMAGE_CREATE_INFO image = {
462 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
463 .pNext = NULL,
464 .imageType = XGL_IMAGE_2D,
465 .format = tex_format,
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800466 .extent = { 16, 16, 1 },
Tony Barboure2c58df2014-11-25 13:18:32 -0700467 .mipLevels = 1,
468 .arraySize = 1,
469 .samples = 1,
470 .tiling = XGL_LINEAR_TILING,
471 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
472 .flags = 0,
473 };
474
Tony Barboure2c58df2014-11-25 13:18:32 -0700475 XGL_IMAGE_VIEW_CREATE_INFO view;
476 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
477 view.pNext = NULL;
478 view.image = XGL_NULL_HANDLE;
479 view.viewType = XGL_IMAGE_VIEW_2D;
480 view.format = image.format;
481 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
482 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
483 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
484 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
485 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
486 view.subresourceRange.baseMipLevel = 0;
487 view.subresourceRange.mipLevels = 1;
488 view.subresourceRange.baseArraySlice = 0;
489 view.subresourceRange.arraySize = 1;
490 view.minLod = 0.0f;
491
Tony Barboure2c58df2014-11-25 13:18:32 -0700492 /* create image */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800493 init(*m_device, image);
Tony Barboure2c58df2014-11-25 13:18:32 -0700494
495 /* create image view */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800496 view.image = obj();
497 m_textureView.init(*m_device, view);
Tony Barboure2c58df2014-11-25 13:18:32 -0700498
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800499 XGL_SUBRESOURCE_LAYOUT layout =
500 subresource_layout(subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0));
501 m_rowPitch = layout.rowPitch;
Tony Barboure2c58df2014-11-25 13:18:32 -0700502
Tony Barboure2c58df2014-11-25 13:18:32 -0700503 XGL_VOID *data;
504 XGL_INT x, y;
505
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800506 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700507
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800508 for (y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700509 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800510 for (x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700511 row[x] = tex_colors[(x & 1) ^ (y & 1)];
512 }
513
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800514 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700515
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800516 m_textureViewInfo.view = m_textureView.obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700517
518}
Tony Barbour82c39522014-12-04 14:33:33 -0700519
Tony Barboure2c58df2014-11-25 13:18:32 -0700520void XglTextureObj::ChangeColors(uint32_t color1, uint32_t color2)
521{
Tony Barboure2c58df2014-11-25 13:18:32 -0700522 const uint32_t tex_colors[2] = { color1, color2 };
523 XGL_VOID *data;
524
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800525 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700526
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800527 for (int y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700528 uint32_t *row = (uint32_t *) ((char *) data + m_rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800529 for (int x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700530 row[x] = tex_colors[(x & 1) ^ (y & 1)];
531 }
532
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800533 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700534}
535
536XglSamplerObj::XglSamplerObj(XglDevice *device)
537{
Tony Barboure2c58df2014-11-25 13:18:32 -0700538 m_device = device;
Tony Barboure2c58df2014-11-25 13:18:32 -0700539
Chia-I Wue9864b52014-12-28 16:32:24 +0800540 XGL_SAMPLER_CREATE_INFO samplerCreateInfo;
541 memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo));
542 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
543 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
544 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
545 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
546 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
547 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
548 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
549 samplerCreateInfo.mipLodBias = 0.0;
550 samplerCreateInfo.maxAnisotropy = 0.0;
551 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
552 samplerCreateInfo.minLod = 0.0;
553 samplerCreateInfo.maxLod = 0.0;
554 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
Tony Barboure2c58df2014-11-25 13:18:32 -0700555
Chia-I Wue9864b52014-12-28 16:32:24 +0800556 init(*m_device, samplerCreateInfo);
Tony Barbourf325bf12014-12-03 15:59:38 -0700557}
Tony Barboure2c58df2014-11-25 13:18:32 -0700558
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700559/*
560 * Basic ConstantBuffer constructor. Then use create methods to fill in the details.
561 */
562XglConstantBufferObj::XglConstantBufferObj(XglDevice *device)
563{
564 m_device = device;
Tony Barbour38422802014-12-10 14:36:31 -0700565 m_commandBuffer = 0;
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700566
567 memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700568}
569
Tony Barboure2c58df2014-11-25 13:18:32 -0700570XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data)
571{
Tony Barboure2c58df2014-11-25 13:18:32 -0700572 m_device = device;
Chia-I Wua07fee62014-12-28 15:26:08 +0800573 m_commandBuffer = 0;
574
575 memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
Tony Barboure2c58df2014-11-25 13:18:32 -0700576 m_numVertices = constantCount;
577 m_stride = constantSize;
578
Chia-I Wua07fee62014-12-28 15:26:08 +0800579 const size_t allocationSize = constantCount * constantSize;
580 init(*m_device, allocationSize);
Tony Barboure2c58df2014-11-25 13:18:32 -0700581
Chia-I Wua07fee62014-12-28 15:26:08 +0800582 void *pData = map();
583 memcpy(pData, data, allocationSize);
584 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700585
586 // set up the memory view for the constant buffer
587 this->m_constantBufferView.stride = 16;
Chia-I Wua07fee62014-12-28 15:26:08 +0800588 this->m_constantBufferView.range = allocationSize;
Tony Barboure2c58df2014-11-25 13:18:32 -0700589 this->m_constantBufferView.offset = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800590 this->m_constantBufferView.mem = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700591 this->m_constantBufferView.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
592 this->m_constantBufferView.format.numericFormat = XGL_NUM_FMT_FLOAT;
593 this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER;
594}
Tony Barbour82c39522014-12-04 14:33:33 -0700595
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700596void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding)
597{
Chia-I Wua07fee62014-12-28 15:26:08 +0800598 xglCmdBindVertexData(cmdBuffer, obj(), offset, binding);
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700599}
600
601
Tony Barbour099a9eb2014-12-10 17:40:15 -0700602void XglConstantBufferObj::SetMemoryState(XGL_MEMORY_STATE newState)
Tony Barboure2c58df2014-11-25 13:18:32 -0700603{
Tony Barbour38422802014-12-10 14:36:31 -0700604 XGL_RESULT err = XGL_SUCCESS;
Tony Barbour38422802014-12-10 14:36:31 -0700605
Tony Barboure2c58df2014-11-25 13:18:32 -0700606 if (this->m_constantBufferView.state == newState)
607 return;
608
Tony Barbour38422802014-12-10 14:36:31 -0700609 if (!m_commandBuffer)
610 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800611 m_fence.init(*m_device, xgl_testing::Fence::create_info(0));
Tony Barbour38422802014-12-10 14:36:31 -0700612
613 m_commandBuffer = new XglCommandBufferObj(m_device);
614
615 }
616 else
617 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800618 m_device->wait(m_fence);
Tony Barbour38422802014-12-10 14:36:31 -0700619 }
620
Tony Barboure2c58df2014-11-25 13:18:32 -0700621 // open the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700622 err = m_commandBuffer->BeginCommandBuffer(0);
Tony Barboure2c58df2014-11-25 13:18:32 -0700623 ASSERT_XGL_SUCCESS(err);
624
Chia-I Wua07fee62014-12-28 15:26:08 +0800625 XGL_MEMORY_STATE_TRANSITION transition =
626 state_transition(XGL_MEMORY_STATE_DATA_TRANSFER, newState, 0, m_numVertices * m_stride);
Tony Barboure2c58df2014-11-25 13:18:32 -0700627
628 // write transition to the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700629 m_commandBuffer->PrepareMemoryRegions(1, &transition);
Tony Barboure2c58df2014-11-25 13:18:32 -0700630 this->m_constantBufferView.state = newState;
631
632 // finish recording the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700633 err = m_commandBuffer->EndCommandBuffer();
Tony Barboure2c58df2014-11-25 13:18:32 -0700634 ASSERT_XGL_SUCCESS(err);
635
636 XGL_UINT32 numMemRefs=1;
637 XGL_MEMORY_REF memRefs;
638 // this command buffer only uses the vertex buffer memory
639 memRefs.flags = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800640 memRefs.mem = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700641
642 // submit the command buffer to the universal queue
Tony Barbour471338d2014-12-10 17:28:39 -0700643 XGL_CMD_BUFFER bufferArray[1];
644 bufferArray[0] = m_commandBuffer->GetBufferHandle();
Chia-I Wua07fee62014-12-28 15:26:08 +0800645 err = xglQueueSubmit( m_device->m_queue, 1, bufferArray, numMemRefs, &memRefs, m_fence.obj() );
Tony Barboure2c58df2014-11-25 13:18:32 -0700646 ASSERT_XGL_SUCCESS(err);
647}
648
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700649XglIndexBufferObj::XglIndexBufferObj(XglDevice *device)
650 : XglConstantBufferObj(device)
651{
652
653}
654
655void XglIndexBufferObj::CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE indexType, const void* data)
656{
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700657 XGL_FORMAT viewFormat;
658
659 m_numVertices = numIndexes;
660 m_indexType = indexType;
661 viewFormat.numericFormat = XGL_NUM_FMT_UINT;
662 switch (indexType) {
663 case XGL_INDEX_8:
664 m_stride = 1;
665 viewFormat.channelFormat = XGL_CH_FMT_R8;
666 break;
667 case XGL_INDEX_16:
668 m_stride = 2;
669 viewFormat.channelFormat = XGL_CH_FMT_R16;
670 break;
671 case XGL_INDEX_32:
672 m_stride = 4;
673 viewFormat.channelFormat = XGL_CH_FMT_R32;
674 break;
Chia-I Wub4c2aa42014-12-15 23:50:11 +0800675 default:
676 assert(!"unknown index type");
677 break;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700678 }
679
Chia-I Wua07fee62014-12-28 15:26:08 +0800680 const size_t allocationSize = numIndexes * m_stride;
681 init(*m_device, allocationSize);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700682
Chia-I Wua07fee62014-12-28 15:26:08 +0800683 void *pData = map();
684 memcpy(pData, data, allocationSize);
685 unmap();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700686
687 // set up the memory view for the constant buffer
688 this->m_constantBufferView.stride = m_stride;
Chia-I Wua07fee62014-12-28 15:26:08 +0800689 this->m_constantBufferView.range = allocationSize;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700690 this->m_constantBufferView.offset = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800691 this->m_constantBufferView.mem = obj();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700692 this->m_constantBufferView.format.channelFormat = viewFormat.channelFormat;
693 this->m_constantBufferView.format.numericFormat = viewFormat.numericFormat;
694 this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER;
695}
696
697void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset)
698{
Chia-I Wua07fee62014-12-28 15:26:08 +0800699 xglCmdBindIndexData(cmdBuffer, obj(), offset, m_indexType);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700700}
Tony Barboure2c58df2014-11-25 13:18:32 -0700701
Tony Barbouraf1f9192014-12-17 10:57:58 -0700702XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType()
703{
704 return m_indexType;
705}
706
Tony Barbour5420af02014-12-03 13:58:15 -0700707XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo(XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700708{
709 XGL_DESCRIPTOR_SLOT_INFO *slotInfo;
710 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) );
711 stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
712 stageInfo->shader.stage = m_stage;
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800713 stageInfo->shader.shader = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700714 stageInfo->shader.descriptorSetMapping[0].descriptorCount = 0;
715 stageInfo->shader.linkConstBufferCount = 0;
716 stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
717 stageInfo->shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
718 stageInfo->shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
719
Tony Barbour824b7712014-12-18 17:06:21 -0700720 stageInfo->shader.descriptorSetMapping[0].descriptorCount = descriptorSet->GetTotalSlots();
Tony Barboure2c58df2014-11-25 13:18:32 -0700721 if (stageInfo->shader.descriptorSetMapping[0].descriptorCount)
722 {
723 vector<int> allSlots;
724 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> allTypes;
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800725 vector<void *> allObjs;
Tony Barboure2c58df2014-11-25 13:18:32 -0700726
727 allSlots.reserve(m_memSlots.size() + m_imageSlots.size() + m_samplerSlots.size());
728 allTypes.reserve(m_memTypes.size() + m_imageTypes.size() + m_samplerTypes.size());
729 allObjs.reserve(m_memObjs.size() + m_imageObjs.size() + m_samplerObjs.size());
730
731 if (m_memSlots.size())
732 {
733 allSlots.insert(allSlots.end(), m_memSlots.begin(), m_memSlots.end());
734 allTypes.insert(allTypes.end(), m_memTypes.begin(), m_memTypes.end());
735 allObjs.insert(allObjs.end(), m_memObjs.begin(), m_memObjs.end());
736 }
737 if (m_imageSlots.size())
738 {
739 allSlots.insert(allSlots.end(), m_imageSlots.begin(), m_imageSlots.end());
740 allTypes.insert(allTypes.end(), m_imageTypes.begin(), m_imageTypes.end());
741 allObjs.insert(allObjs.end(), m_imageObjs.begin(), m_imageObjs.end());
742 }
743 if (m_samplerSlots.size())
744 {
745 allSlots.insert(allSlots.end(), m_samplerSlots.begin(), m_samplerSlots.end());
746 allTypes.insert(allTypes.end(), m_samplerTypes.begin(), m_samplerTypes.end());
747 allObjs.insert(allObjs.end(), m_samplerObjs.begin(), m_samplerObjs.end());
748 }
749
Tony Barbour5420af02014-12-03 13:58:15 -0700750 slotInfo = descriptorSet->GetSlotInfo(allSlots, allTypes, allObjs);
Tony Barboure2c58df2014-11-25 13:18:32 -0700751 stageInfo->shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
752 }
753 return stageInfo;
754}
755
756void XglShaderObj::BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer)
757{
758 m_memSlots.push_back(slot);
759 m_memTypes.push_back(type);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800760 m_memObjs.push_back(&constantBuffer->m_constantBufferView);
Tony Barboure2c58df2014-11-25 13:18:32 -0700761
762}
Tony Barbour82c39522014-12-04 14:33:33 -0700763
Tony Barboure2c58df2014-11-25 13:18:32 -0700764void XglShaderObj::BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture)
765{
766 m_imageSlots.push_back(slot);
767 m_imageTypes.push_back(type);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800768 m_imageObjs.push_back(&texture->m_textureViewInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700769
770}
Tony Barbour82c39522014-12-04 14:33:33 -0700771
Tony Barboure2c58df2014-11-25 13:18:32 -0700772void XglShaderObj::BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler)
773{
774 m_samplerSlots.push_back(slot);
775 m_samplerTypes.push_back(XGL_SLOT_SHADER_SAMPLER);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800776 m_samplerObjs.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700777
778}
Tony Barbour82c39522014-12-04 14:33:33 -0700779
Tony Barboure2c58df2014-11-25 13:18:32 -0700780XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework)
781{
782 XGL_RESULT err = XGL_SUCCESS;
783 std::vector<unsigned int> bil;
784 XGL_SHADER_CREATE_INFO createInfo;
785 size_t shader_len;
786
787 m_stage = stage;
788 m_device = device;
789
790 createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
791 createInfo.pNext = NULL;
792
793 if (!framework->m_use_bil) {
794
795 shader_len = strlen(shader_code);
796 createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
797 createInfo.pCode = malloc(createInfo.codeSize);
798 createInfo.flags = 0;
799
800 /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */
801 ((uint32_t *) createInfo.pCode)[0] = ICD_BIL_MAGIC;
802 ((uint32_t *) createInfo.pCode)[1] = 0;
803 ((uint32_t *) createInfo.pCode)[2] = stage;
804 memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1);
805
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800806 err = init_try(*m_device, createInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700807 }
808
809 if (framework->m_use_bil || err) {
810 std::vector<unsigned int> bil;
811 err = XGL_SUCCESS;
812
813 // Use Reference GLSL to BIL compiler
814 framework->GLSLtoBIL(stage, shader_code, bil);
815 createInfo.pCode = bil.data();
816 createInfo.codeSize = bil.size() * sizeof(unsigned int);
817 createInfo.flags = 0;
Tony Barbour82c39522014-12-04 14:33:33 -0700818
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800819 init(*m_device, createInfo);
820 }
Tony Barbourf325bf12014-12-03 15:59:38 -0700821}
Tony Barbour82c39522014-12-04 14:33:33 -0700822
Tony Barboure2c58df2014-11-25 13:18:32 -0700823XglPipelineObj::XglPipelineObj(XglDevice *device)
824{
Tony Barboure2c58df2014-11-25 13:18:32 -0700825 m_device = device;
826 m_vi_state.attributeCount = m_vi_state.bindingCount = 0;
827 m_vertexBufferCount = 0;
828
829 m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO;
830 m_ia_state.pNext = XGL_NULL_HANDLE;
831 m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST;
832 m_ia_state.disableVertexReuse = XGL_FALSE;
833 m_ia_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST;
834 m_ia_state.primitiveRestartEnable = XGL_FALSE;
835 m_ia_state.primitiveRestartIndex = 0;
836
837 m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO;
838 m_rs_state.pNext = &m_ia_state;
839 m_rs_state.depthClipEnable = XGL_FALSE;
840 m_rs_state.rasterizerDiscardEnable = XGL_FALSE;
841 m_rs_state.pointSize = 1.0;
842
Tony Barboure2c58df2014-11-25 13:18:32 -0700843 memset(&m_cb_state,0,sizeof(m_cb_state));
844 m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO;
845 m_cb_state.pNext = &m_rs_state;
846 m_cb_state.alphaToCoverageEnable = XGL_FALSE;
847 m_cb_state.dualSourceBlendEnable = XGL_FALSE;
848 m_cb_state.logicOp = XGL_LOGIC_OP_COPY;
849
Chia-I Wu62bf1dc2014-12-05 11:12:13 +0800850 m_cb_state.attachment[0].blendEnable = XGL_FALSE;
851 m_cb_state.attachment[0].format.channelFormat = XGL_CH_FMT_R8G8B8A8;
852 m_cb_state.attachment[0].format.numericFormat = XGL_NUM_FMT_UNORM;
853 m_cb_state.attachment[0].channelWriteMask = 0xF;
Tony Barboure2c58df2014-11-25 13:18:32 -0700854
855 m_db_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
856 m_db_state.pNext = &m_cb_state,
857 m_db_state.format.channelFormat = XGL_CH_FMT_R32;
858 m_db_state.format.numericFormat = XGL_NUM_FMT_DS;
859
860
861};
862
863void XglPipelineObj::AddShader(XglShaderObj* shader)
864{
865 m_shaderObjs.push_back(shader);
866}
867
868void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count)
869{
870 m_vi_state.pVertexAttributeDescriptions = vi_attrib;
871 m_vi_state.attributeCount = count;
872}
873
874void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count)
875{
876 m_vi_state.pVertexBindingDescriptions = vi_binding;
877 m_vi_state.bindingCount = count;
878}
879
880void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding)
881{
882 m_vertexBufferObjs.push_back(vertexDataBuffer);
883 m_vertexBufferBindings.push_back(binding);
884 m_vertexBufferCount++;
885}
886
Chia-I Wuecebf752014-12-05 10:45:15 +0800887void XglPipelineObj::SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att)
888{
889 m_cb_state.attachment[binding] = *att;
890}
891
Tony Barbour976e1cf2014-12-17 11:57:31 -0700892void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet)
893{
Tony Barbour976e1cf2014-12-17 11:57:31 -0700894 XGL_VOID* head_ptr = &m_db_state;
895 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
896
897 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
898
899 for (int i=0; i<m_shaderObjs.size(); i++)
900 {
901 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
902 shaderCreateInfo->pNext = head_ptr;
903 head_ptr = shaderCreateInfo;
904 }
905
906 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
907 {
908 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
909 m_vi_state.pNext = head_ptr;
910 head_ptr = &m_vi_state;
911 }
912
913 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
914 info.pNext = head_ptr;
915 info.flags = 0;
916
Chia-I Wu2648d092014-12-29 14:24:14 +0800917 init(*m_device, info);
Tony Barbour976e1cf2014-12-17 11:57:31 -0700918}
Chia-I Wu2648d092014-12-29 14:24:14 +0800919
Tony Barbour976e1cf2014-12-17 11:57:31 -0700920XGL_PIPELINE XglPipelineObj::GetPipelineHandle()
921{
Chia-I Wu2648d092014-12-29 14:24:14 +0800922 return obj();
Tony Barbour976e1cf2014-12-17 11:57:31 -0700923}
924
Tony Barbour5420af02014-12-03 13:58:15 -0700925void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700926{
Tony Barboure2c58df2014-11-25 13:18:32 -0700927 XGL_VOID* head_ptr = &m_db_state;
928 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
929
930 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
Tony Barboure2c58df2014-11-25 13:18:32 -0700931
932 for (int i=0; i<m_shaderObjs.size(); i++)
933 {
934 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
935 shaderCreateInfo->pNext = head_ptr;
936 head_ptr = shaderCreateInfo;
937 }
938
939 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
940 {
941 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
942 m_vi_state.pNext = head_ptr;
943 head_ptr = &m_vi_state;
944 }
945
946 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
947 info.pNext = head_ptr;
948 info.flags = 0;
949
Chia-I Wu2648d092014-12-29 14:24:14 +0800950 init(*m_device, info);
Tony Barboure2c58df2014-11-25 13:18:32 -0700951
Chia-I Wu2648d092014-12-29 14:24:14 +0800952 xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, obj() );
Tony Barboure2c58df2014-11-25 13:18:32 -0700953
954
955 for (int i=0; i < m_vertexBufferCount; i++)
956 {
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700957 m_vertexBufferObjs[i]->Bind(m_cmdBuffer, m_vertexBufferObjs[i]->m_constantBufferView.offset, m_vertexBufferBindings[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700958 }
Tony Barboure2c58df2014-11-25 13:18:32 -0700959}
Tony Barbour82c39522014-12-04 14:33:33 -0700960
Tony Barboure2c58df2014-11-25 13:18:32 -0700961XglMemoryRefManager::XglMemoryRefManager() {
962
963}
Tony Barbour82c39522014-12-04 14:33:33 -0700964
Tony Barboure2c58df2014-11-25 13:18:32 -0700965void XglMemoryRefManager::AddMemoryRef(XglConstantBufferObj *constantBuffer) {
Chia-I Wua07fee62014-12-28 15:26:08 +0800966 m_bufferObjs.push_back(constantBuffer->obj());
Tony Barboure2c58df2014-11-25 13:18:32 -0700967}
Tony Barbour82c39522014-12-04 14:33:33 -0700968
Tony Barboure2c58df2014-11-25 13:18:32 -0700969void XglMemoryRefManager::AddMemoryRef(XglTextureObj *texture) {
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800970 const std::vector<XGL_GPU_MEMORY> mems = texture->memories();
971 if (!mems.empty())
972 m_bufferObjs.push_back(mems[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700973}
Tony Barbour82c39522014-12-04 14:33:33 -0700974
Tony Barboure2c58df2014-11-25 13:18:32 -0700975XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() {
976
977 XGL_MEMORY_REF *localRefs;
978 XGL_UINT32 numRefs=m_bufferObjs.size();
979
980 if (numRefs <= 0)
981 return NULL;
982
983 localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) );
984 for (int i=0; i<numRefs; i++)
985 {
986 localRefs[i].flags = 0;
Chia-I Wu283d7a62014-12-28 15:43:42 +0800987 localRefs[i].mem = m_bufferObjs[i];
Tony Barboure2c58df2014-11-25 13:18:32 -0700988 }
989 return localRefs;
990}
991int XglMemoryRefManager::GetNumRefs() {
992 return m_bufferObjs.size();
993}
Tony Barbour6d047bf2014-12-10 14:34:45 -0700994
995XglCommandBufferObj::XglCommandBufferObj(XglDevice *device)
Chia-I Wud28343c2014-12-28 15:12:48 +0800996 : xgl_testing::CmdBuffer(*device, xgl_testing::CmdBuffer::create_info(XGL_QUEUE_TYPE_GRAPHICS))
Tony Barbour6d047bf2014-12-10 14:34:45 -0700997{
Tony Barbour6d047bf2014-12-10 14:34:45 -0700998 m_device = device;
Chia-I Wud28343c2014-12-28 15:12:48 +0800999 m_renderTargetCount = 0;
Tony Barbour6d047bf2014-12-10 14:34:45 -07001000}
Tony Barbour471338d2014-12-10 17:28:39 -07001001
Tony Barbour6d047bf2014-12-10 14:34:45 -07001002XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle()
1003{
Chia-I Wud28343c2014-12-28 15:12:48 +08001004 return obj();
Tony Barbour6d047bf2014-12-10 14:34:45 -07001005}
Tony Barbour471338d2014-12-10 17:28:39 -07001006
1007XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_FLAGS flags)
1008{
Chia-I Wud28343c2014-12-28 15:12:48 +08001009 begin(flags);
1010 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001011}
1012
1013XGL_RESULT XglCommandBufferObj::EndCommandBuffer()
1014{
Chia-I Wud28343c2014-12-28 15:12:48 +08001015 end();
1016 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001017}
1018
1019void XglCommandBufferObj::PrepareMemoryRegions(int transitionCount, XGL_MEMORY_STATE_TRANSITION *transitionPtr)
1020{
Chia-I Wud28343c2014-12-28 15:12:48 +08001021 xglCmdPrepareMemoryRegions(obj(), transitionCount, transitionPtr);
Tony Barbour471338d2014-12-10 17:28:39 -07001022}
1023
Tony Barbour30cc9e82014-12-17 11:53:55 -07001024void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage)
1025{
1026 XGL_UINT i;
1027
1028 // whatever we want to do, we do it to the whole buffer
1029 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1030 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1031 srRange.baseMipLevel = 0;
1032 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1033 srRange.baseArraySlice = 0;
1034 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1035
1036 // clear the back buffer to dark grey
1037 XGL_UINT clearColor[4] = {64, 64, 64, 0};
1038 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
1039 for (i = 0; i < m_renderTargetCount; i++) {
1040 transitionToClear.image = m_renderTargets[i]->image();
1041 transitionToClear.oldState = m_renderTargets[i]->state();
1042 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1043 transitionToClear.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001044 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001045 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
1046
Chia-I Wud28343c2014-12-28 15:12:48 +08001047 xglCmdClearColorImageRaw( obj(), m_renderTargets[i]->image(), clearColor, 1, &srRange );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001048 }
1049
1050 if (depthStencilImage)
1051 {
1052 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
1053 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
1054 dsRange.baseMipLevel = 0;
1055 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1056 dsRange.baseArraySlice = 0;
1057 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1058
1059 // prepare the depth buffer for clear
1060 memset(&transitionToClear,0,sizeof(transitionToClear));
1061 transitionToClear.image = depthStencilImage;
1062 transitionToClear.oldState = depthStencilBinding->depthState;
1063 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1064 transitionToClear.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001065 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001066 depthStencilBinding->depthState = transitionToClear.newState;
1067
Chia-I Wud28343c2014-12-28 15:12:48 +08001068 xglCmdClearDepthStencil(obj(), depthStencilImage, 1.0f, 0, 1, &dsRange);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001069
1070 // prepare depth buffer for rendering
1071 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1072 transitionToRender.image = depthStencilImage;
1073 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
1074 transitionToRender.newState = depthStencilBinding->depthState;
1075 transitionToRender.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001076 xglCmdPrepareImages( obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001077 depthStencilBinding->depthState = transitionToClear.newState;
1078 }
1079}
1080
1081void XglCommandBufferObj::BindAttachments(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding)
1082{
1083 XGL_UINT i;
1084 XGL_COLOR_ATTACHMENT_BIND_INFO colorBindings[XGL_MAX_COLOR_ATTACHMENTS];
1085 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1086 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1087 srRange.baseMipLevel = 0;
1088 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1089 srRange.baseArraySlice = 0;
1090 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1091
1092 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1093 for(i=0; i<m_renderTargetCount; i++)
1094 {
1095 transitionToRender.image = m_renderTargets[i]->image();
1096 transitionToRender.oldState = m_renderTargets[i]->state();
1097 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
1098 transitionToRender.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001099 xglCmdPrepareImages(obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001100 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToRender.newState);
1101 }
1102 for (i = 0; i < m_renderTargetCount; i++) {
1103 colorBindings[i].view = m_renderTargets[i]->targetView();
1104 colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
1105 }
1106 if (depthStencilBinding) {
Chia-I Wud28343c2014-12-28 15:12:48 +08001107 xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, depthStencilBinding );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001108 } else {
Chia-I Wud28343c2014-12-28 15:12:48 +08001109 xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, XGL_NULL_HANDLE );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001110 }
1111}
1112
1113void XglCommandBufferObj::BindState(XGL_RASTER_STATE_OBJECT stateRaster, XGL_VIEWPORT_STATE_OBJECT stateViewport,
1114 XGL_COLOR_BLEND_STATE_OBJECT colorBlend, XGL_DEPTH_STENCIL_STATE_OBJECT stateDepthStencil,
1115 XGL_MSAA_STATE_OBJECT stateMsaa)
1116{
1117 // set all states
Chia-I Wud28343c2014-12-28 15:12:48 +08001118 xglCmdBindStateObject( obj(), XGL_STATE_BIND_RASTER, stateRaster );
1119 xglCmdBindStateObject( obj(), XGL_STATE_BIND_VIEWPORT, stateViewport );
1120 xglCmdBindStateObject( obj(), XGL_STATE_BIND_COLOR_BLEND, colorBlend);
1121 xglCmdBindStateObject( obj(), XGL_STATE_BIND_DEPTH_STENCIL, stateDepthStencil );
1122 xglCmdBindStateObject( obj(), XGL_STATE_BIND_MSAA, stateMsaa );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001123}
1124
1125void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget)
1126{
1127 m_renderTargets.push_back(renderTarget);
1128 m_renderTargetCount++;
1129}
1130
1131void XglCommandBufferObj::DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount)
1132{
Chia-I Wud28343c2014-12-28 15:12:48 +08001133 xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001134}
1135
1136void XglCommandBufferObj::Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount)
1137{
Chia-I Wud28343c2014-12-28 15:12:48 +08001138 xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001139}
1140
1141void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
1142{
1143 XGL_RESULT err = XGL_SUCCESS;
1144
1145 // submit the command buffer to the universal queue
Chia-I Wud28343c2014-12-28 15:12:48 +08001146 err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001147 ASSERT_XGL_SUCCESS( err );
1148
1149 err = xglQueueWaitIdle( m_device->m_queue );
1150 ASSERT_XGL_SUCCESS( err );
1151
1152 // Wait for work to finish before cleaning up.
1153 xglDeviceWaitIdle(m_device->device());
1154
1155}
1156void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline)
1157{
Chia-I Wud28343c2014-12-28 15:12:48 +08001158 xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001159}
1160
1161void XglCommandBufferObj::BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet)
1162{
1163 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
Chia-I Wud28343c2014-12-28 15:12:48 +08001164 xglCmdBindDescriptorSet(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, descriptorSet, 0 );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001165}
1166void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset)
1167{
Chia-I Wua07fee62014-12-28 15:26:08 +08001168 xglCmdBindIndexData(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001169}
1170void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding)
1171{
Chia-I Wua07fee62014-12-28 15:26:08 +08001172 xglCmdBindVertexData(obj(), vertexBuffer->obj(), offset, binding);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001173}