blob: f0b5eb9cb53543195bff52e89f30e27e5cd40db5 [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++) {
Chia-I Wuf50ee212014-12-29 14:31:52 +0800177 XglImage *img = new XglImage(m_device);
178 img->init(m_width, m_height, m_render_target_fmt,
179 XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT |
180 XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
181 m_renderTargets[i] = img;
Chia-I Wuecebf752014-12-05 10:45:15 +0800182 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600183}
184
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600185void XglRenderFramework::GenerateBindRenderTargetCmd()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600186{
Chia-I Wuecebf752014-12-05 10:45:15 +0800187 XGL_UINT i;
188
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600189 // bind render target
Chia-I Wuecebf752014-12-05 10:45:15 +0800190 for (i = 0; i < m_renderTargetCount; i++) {
191 m_colorBindings[i].view = m_renderTargets[i]->targetView();
192 m_colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
193 }
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600194 if (m_depthStencilBinding.view) {
Chia-I Wuecebf752014-12-05 10:45:15 +0800195 xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, &m_depthStencilBinding );
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600196 } else {
Chia-I Wuecebf752014-12-05 10:45:15 +0800197 xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, XGL_NULL_HANDLE );
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600198 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600199}
200
Tony Barboure2c58df2014-11-25 13:18:32 -0700201void XglRenderFramework::GenerateBindStateAndPipelineCmds()
202{
203 // set all states
204 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster );
205 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport );
206 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
207 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil );
208 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa );
209}
210
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600211void XglRenderFramework::GenerateClearAndPrepareBufferCmds()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600212{
Chia-I Wuecebf752014-12-05 10:45:15 +0800213 XGL_UINT i;
214
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600215 // whatever we want to do, we do it to the whole buffer
216 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
217 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
218 srRange.baseMipLevel = 0;
219 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
220 srRange.baseArraySlice = 0;
221 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
222
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600223 // clear the back buffer to dark grey
224 XGL_UINT clearColor[4] = {64, 64, 64, 0};
Chia-I Wuecebf752014-12-05 10:45:15 +0800225 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
226 for (i = 0; i < m_renderTargetCount; i++) {
227 transitionToClear.image = m_renderTargets[i]->image();
228 transitionToClear.oldState = m_renderTargets[i]->state();
229 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
230 transitionToClear.subresourceRange = srRange;
231 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
232 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
233
234 xglCmdClearColorImageRaw( m_cmdBuffer, m_renderTargets[i]->image(), clearColor, 1, &srRange );
235 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600236
237 // prepare back buffer for rendering
238 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wuecebf752014-12-05 10:45:15 +0800239 for (i = 0; i < m_renderTargetCount; i++) {
240 transitionToRender.image = m_renderTargets[i]->image();
241 transitionToRender.oldState = m_renderTargets[i]->state();
242 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
243 transitionToRender.subresourceRange = srRange;
244 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
245 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
246 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600247}
Tony Barbour82c39522014-12-04 14:33:33 -0700248
Tony Barboure2c58df2014-11-25 13:18:32 -0700249XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device)
250{
251 m_device = device;
252 m_nextSlot = 0;
253
254}
255
256void XglDescriptorSetObj::AttachMemoryView(XglConstantBufferObj *constantBuffer)
257{
258 m_memoryViews.push_back(&constantBuffer->m_constantBufferView);
259 m_memorySlots.push_back(m_nextSlot);
260 m_nextSlot++;
261
262}
Tony Barbour82c39522014-12-04 14:33:33 -0700263
Tony Barboure2c58df2014-11-25 13:18:32 -0700264void XglDescriptorSetObj::AttachSampler(XglSamplerObj *sampler)
265{
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800266 m_samplers.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700267 m_samplerSlots.push_back(m_nextSlot);
268 m_nextSlot++;
269
270}
Tony Barbour82c39522014-12-04 14:33:33 -0700271
Tony Barboure2c58df2014-11-25 13:18:32 -0700272void XglDescriptorSetObj::AttachImageView(XglTextureObj *texture)
273{
274 m_imageViews.push_back(&texture->m_textureViewInfo);
275 m_imageSlots.push_back(m_nextSlot);
276 m_nextSlot++;
277
278}
Tony Barbour82c39522014-12-04 14:33:33 -0700279
Tony Barboure2c58df2014-11-25 13:18:32 -0700280XGL_DESCRIPTOR_SLOT_INFO* XglDescriptorSetObj::GetSlotInfo(vector<int>slots,
281 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types,
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800282 vector<void *>objs )
Tony Barboure2c58df2014-11-25 13:18:32 -0700283{
284 int nSlots = m_memorySlots.size() + m_imageSlots.size() + m_samplerSlots.size();
285 m_slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( nSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
286 memset(m_slotInfo,0,nSlots*sizeof(XGL_DESCRIPTOR_SLOT_INFO));
287
288 for (int i=0; i<nSlots; i++)
289 {
290 m_slotInfo[i].slotObjectType = XGL_SLOT_UNUSED;
291 }
292
293 for (int i=0; i<slots.size(); i++)
294 {
295 for (int j=0; j<m_memorySlots.size(); j++)
296 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800297 if ( m_memoryViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700298 {
299 m_slotInfo[m_memorySlots[j]].shaderEntityIndex = slots[i];
300 m_slotInfo[m_memorySlots[j]].slotObjectType = types[i];
301 }
302 }
303 for (int j=0; j<m_imageSlots.size(); j++)
304 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800305 if ( m_imageViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700306 {
307 m_slotInfo[m_imageSlots[j]].shaderEntityIndex = slots[i];
308 m_slotInfo[m_imageSlots[j]].slotObjectType = types[i];
309 }
310 }
311 for (int j=0; j<m_samplerSlots.size(); j++)
312 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800313 if ( m_samplers[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700314 {
315 m_slotInfo[m_samplerSlots[j]].shaderEntityIndex = slots[i];
316 m_slotInfo[m_samplerSlots[j]].slotObjectType = types[i];
317 }
318 }
319 }
320
321 // for (int i=0;i<nSlots;i++)
322 // {
323 // printf("SlotInfo[%d]: Index = %d, Type = %d\n",i,m_slotInfo[i].shaderEntityIndex, m_slotInfo[i].slotObjectType);
324 // fflush(stdout);
325 // }
326
327 return(m_slotInfo);
328
329}
Tony Barbourb5f4d082014-12-17 10:54:03 -0700330void XglDescriptorSetObj::CreateXGLDescriptorSet()
331{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800332 init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot));
Tony Barbourb5f4d082014-12-17 10:54:03 -0700333
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800334 begin();
335 clear();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700336
Tony Barbourb5f4d082014-12-17 10:54:03 -0700337 for (int i=0; i<m_memoryViews.size();i++)
338 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800339 attach(m_memorySlots[i], *m_memoryViews[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700340 }
341 for (int i=0; i<m_samplers.size();i++)
342 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800343 attach(m_samplerSlots[i], *m_samplers[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700344 }
345 for (int i=0; i<m_imageViews.size();i++)
346 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800347 attach(m_imageSlots[i], *m_imageViews[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700348 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800349
350 end();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700351}
352
353XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle()
354{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800355 return obj();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700356}
Tony Barboure2c58df2014-11-25 13:18:32 -0700357
Tony Barbour824b7712014-12-18 17:06:21 -0700358int XglDescriptorSetObj::GetTotalSlots()
359{
360 return m_nextSlot;
361}
362
Tony Barboure2c58df2014-11-25 13:18:32 -0700363void XglDescriptorSetObj::BindCommandBuffer(XGL_CMD_BUFFER commandBuffer)
364{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800365 init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot));
Tony Barboure2c58df2014-11-25 13:18:32 -0700366
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800367 begin();
368 clear();
Tony Barboure2c58df2014-11-25 13:18:32 -0700369
Tony Barboure2c58df2014-11-25 13:18:32 -0700370 for (int i=0; i<m_memoryViews.size();i++)
371 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800372 attach(m_memorySlots[i], *m_memoryViews[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700373 }
374 for (int i=0; i<m_samplers.size();i++)
375 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800376 attach(m_samplerSlots[i], *m_samplers[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700377 }
378 for (int i=0; i<m_imageViews.size();i++)
379 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800380 attach(m_imageSlots[i], *m_imageViews[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700381 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800382
383 end();
Tony Barboure2c58df2014-11-25 13:18:32 -0700384
385 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800386 xglCmdBindDescriptorSet(commandBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, obj(), 0 );
Tony Barbour25ef8a62014-12-03 13:59:18 -0700387}
Tony Barboure2c58df2014-11-25 13:18:32 -0700388
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800389XglImage::XglImage(XglDevice *dev)
390{
391 m_device = dev;
392 m_imageInfo.view = XGL_NULL_HANDLE;
393 m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET;
394}
395
396void XglImage::init(XGL_UINT32 w, XGL_UINT32 h,
397 XGL_FORMAT fmt, XGL_FLAGS usage,
398 XGL_IMAGE_TILING tiling)
399{
400 XGL_UINT mipCount;
401
402 mipCount = 0;
403
404 XGL_UINT _w = w;
405 XGL_UINT _h = h;
406 while( ( _w > 0 ) || ( _h > 0 ) )
407 {
408 _w >>= 1;
409 _h >>= 1;
410 mipCount++;
411 }
412
413 XGL_IMAGE_CREATE_INFO imageCreateInfo = xgl_testing::Image::create_info();
414 imageCreateInfo.imageType = XGL_IMAGE_2D;
415 imageCreateInfo.format = fmt;
416 imageCreateInfo.extent.width = w;
417 imageCreateInfo.extent.height = h;
418 imageCreateInfo.mipLevels = mipCount;
419 imageCreateInfo.tiling = tiling;
420
421 imageCreateInfo.usage = usage;
422
423 xgl_testing::Image::init(*m_device, imageCreateInfo);
424
425 m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET;
426
427 XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO createView = {
428 XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO,
429 XGL_NULL_HANDLE,
430 obj(),
431 {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM},
432 0,
433 0,
434 1
435 };
436
437 m_targetView.init(*m_device, createView);
438}
439
440XGL_RESULT XglImage::MapMemory(XGL_VOID** ptr)
441{
442 *ptr = map();
443 return (*ptr) ? XGL_SUCCESS : XGL_ERROR_UNKNOWN;
444}
445
446XGL_RESULT XglImage::UnmapMemory()
447{
448 unmap();
449 return XGL_SUCCESS;
450}
451
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800452XglTextureObj::XglTextureObj(XglDevice *device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700453{
454 m_device = device;
455 const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM };
Tony Barboure2c58df2014-11-25 13:18:32 -0700456 const uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 };
Tony Barboure2c58df2014-11-25 13:18:32 -0700457
458 memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo));
459
460 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
461
462 const XGL_IMAGE_CREATE_INFO image = {
463 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
464 .pNext = NULL,
465 .imageType = XGL_IMAGE_2D,
466 .format = tex_format,
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800467 .extent = { 16, 16, 1 },
Tony Barboure2c58df2014-11-25 13:18:32 -0700468 .mipLevels = 1,
469 .arraySize = 1,
470 .samples = 1,
471 .tiling = XGL_LINEAR_TILING,
472 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
473 .flags = 0,
474 };
475
Tony Barboure2c58df2014-11-25 13:18:32 -0700476 XGL_IMAGE_VIEW_CREATE_INFO view;
477 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
478 view.pNext = NULL;
479 view.image = XGL_NULL_HANDLE;
480 view.viewType = XGL_IMAGE_VIEW_2D;
481 view.format = image.format;
482 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
483 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
484 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
485 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
486 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
487 view.subresourceRange.baseMipLevel = 0;
488 view.subresourceRange.mipLevels = 1;
489 view.subresourceRange.baseArraySlice = 0;
490 view.subresourceRange.arraySize = 1;
491 view.minLod = 0.0f;
492
Tony Barboure2c58df2014-11-25 13:18:32 -0700493 /* create image */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800494 init(*m_device, image);
Tony Barboure2c58df2014-11-25 13:18:32 -0700495
496 /* create image view */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800497 view.image = obj();
498 m_textureView.init(*m_device, view);
Tony Barboure2c58df2014-11-25 13:18:32 -0700499
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800500 XGL_SUBRESOURCE_LAYOUT layout =
501 subresource_layout(subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0));
502 m_rowPitch = layout.rowPitch;
Tony Barboure2c58df2014-11-25 13:18:32 -0700503
Tony Barboure2c58df2014-11-25 13:18:32 -0700504 XGL_VOID *data;
505 XGL_INT x, y;
506
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800507 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700508
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800509 for (y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700510 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800511 for (x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700512 row[x] = tex_colors[(x & 1) ^ (y & 1)];
513 }
514
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800515 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700516
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800517 m_textureViewInfo.view = m_textureView.obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700518
519}
Tony Barbour82c39522014-12-04 14:33:33 -0700520
Tony Barboure2c58df2014-11-25 13:18:32 -0700521void XglTextureObj::ChangeColors(uint32_t color1, uint32_t color2)
522{
Tony Barboure2c58df2014-11-25 13:18:32 -0700523 const uint32_t tex_colors[2] = { color1, color2 };
524 XGL_VOID *data;
525
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800526 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700527
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800528 for (int y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700529 uint32_t *row = (uint32_t *) ((char *) data + m_rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800530 for (int x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700531 row[x] = tex_colors[(x & 1) ^ (y & 1)];
532 }
533
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800534 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700535}
536
537XglSamplerObj::XglSamplerObj(XglDevice *device)
538{
Tony Barboure2c58df2014-11-25 13:18:32 -0700539 m_device = device;
Tony Barboure2c58df2014-11-25 13:18:32 -0700540
Chia-I Wue9864b52014-12-28 16:32:24 +0800541 XGL_SAMPLER_CREATE_INFO samplerCreateInfo;
542 memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo));
543 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
544 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
545 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
546 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
547 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
548 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
549 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
550 samplerCreateInfo.mipLodBias = 0.0;
551 samplerCreateInfo.maxAnisotropy = 0.0;
552 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
553 samplerCreateInfo.minLod = 0.0;
554 samplerCreateInfo.maxLod = 0.0;
555 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
Tony Barboure2c58df2014-11-25 13:18:32 -0700556
Chia-I Wue9864b52014-12-28 16:32:24 +0800557 init(*m_device, samplerCreateInfo);
Tony Barbourf325bf12014-12-03 15:59:38 -0700558}
Tony Barboure2c58df2014-11-25 13:18:32 -0700559
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700560/*
561 * Basic ConstantBuffer constructor. Then use create methods to fill in the details.
562 */
563XglConstantBufferObj::XglConstantBufferObj(XglDevice *device)
564{
565 m_device = device;
Tony Barbour38422802014-12-10 14:36:31 -0700566 m_commandBuffer = 0;
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700567
568 memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700569}
570
Tony Barboure2c58df2014-11-25 13:18:32 -0700571XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data)
572{
Tony Barboure2c58df2014-11-25 13:18:32 -0700573 m_device = device;
Chia-I Wua07fee62014-12-28 15:26:08 +0800574 m_commandBuffer = 0;
575
576 memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
Tony Barboure2c58df2014-11-25 13:18:32 -0700577 m_numVertices = constantCount;
578 m_stride = constantSize;
579
Chia-I Wua07fee62014-12-28 15:26:08 +0800580 const size_t allocationSize = constantCount * constantSize;
581 init(*m_device, allocationSize);
Tony Barboure2c58df2014-11-25 13:18:32 -0700582
Chia-I Wua07fee62014-12-28 15:26:08 +0800583 void *pData = map();
584 memcpy(pData, data, allocationSize);
585 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700586
587 // set up the memory view for the constant buffer
588 this->m_constantBufferView.stride = 16;
Chia-I Wua07fee62014-12-28 15:26:08 +0800589 this->m_constantBufferView.range = allocationSize;
Tony Barboure2c58df2014-11-25 13:18:32 -0700590 this->m_constantBufferView.offset = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800591 this->m_constantBufferView.mem = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700592 this->m_constantBufferView.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
593 this->m_constantBufferView.format.numericFormat = XGL_NUM_FMT_FLOAT;
594 this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER;
595}
Tony Barbour82c39522014-12-04 14:33:33 -0700596
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700597void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding)
598{
Chia-I Wua07fee62014-12-28 15:26:08 +0800599 xglCmdBindVertexData(cmdBuffer, obj(), offset, binding);
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700600}
601
602
Tony Barbour099a9eb2014-12-10 17:40:15 -0700603void XglConstantBufferObj::SetMemoryState(XGL_MEMORY_STATE newState)
Tony Barboure2c58df2014-11-25 13:18:32 -0700604{
Tony Barbour38422802014-12-10 14:36:31 -0700605 XGL_RESULT err = XGL_SUCCESS;
Tony Barbour38422802014-12-10 14:36:31 -0700606
Tony Barboure2c58df2014-11-25 13:18:32 -0700607 if (this->m_constantBufferView.state == newState)
608 return;
609
Tony Barbour38422802014-12-10 14:36:31 -0700610 if (!m_commandBuffer)
611 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800612 m_fence.init(*m_device, xgl_testing::Fence::create_info(0));
Tony Barbour38422802014-12-10 14:36:31 -0700613
614 m_commandBuffer = new XglCommandBufferObj(m_device);
615
616 }
617 else
618 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800619 m_device->wait(m_fence);
Tony Barbour38422802014-12-10 14:36:31 -0700620 }
621
Tony Barboure2c58df2014-11-25 13:18:32 -0700622 // open the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700623 err = m_commandBuffer->BeginCommandBuffer(0);
Tony Barboure2c58df2014-11-25 13:18:32 -0700624 ASSERT_XGL_SUCCESS(err);
625
Chia-I Wua07fee62014-12-28 15:26:08 +0800626 XGL_MEMORY_STATE_TRANSITION transition =
627 state_transition(XGL_MEMORY_STATE_DATA_TRANSFER, newState, 0, m_numVertices * m_stride);
Tony Barboure2c58df2014-11-25 13:18:32 -0700628
629 // write transition to the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700630 m_commandBuffer->PrepareMemoryRegions(1, &transition);
Tony Barboure2c58df2014-11-25 13:18:32 -0700631 this->m_constantBufferView.state = newState;
632
633 // finish recording the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700634 err = m_commandBuffer->EndCommandBuffer();
Tony Barboure2c58df2014-11-25 13:18:32 -0700635 ASSERT_XGL_SUCCESS(err);
636
637 XGL_UINT32 numMemRefs=1;
638 XGL_MEMORY_REF memRefs;
639 // this command buffer only uses the vertex buffer memory
640 memRefs.flags = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800641 memRefs.mem = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700642
643 // submit the command buffer to the universal queue
Tony Barbour471338d2014-12-10 17:28:39 -0700644 XGL_CMD_BUFFER bufferArray[1];
645 bufferArray[0] = m_commandBuffer->GetBufferHandle();
Chia-I Wua07fee62014-12-28 15:26:08 +0800646 err = xglQueueSubmit( m_device->m_queue, 1, bufferArray, numMemRefs, &memRefs, m_fence.obj() );
Tony Barboure2c58df2014-11-25 13:18:32 -0700647 ASSERT_XGL_SUCCESS(err);
648}
649
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700650XglIndexBufferObj::XglIndexBufferObj(XglDevice *device)
651 : XglConstantBufferObj(device)
652{
653
654}
655
656void XglIndexBufferObj::CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE indexType, const void* data)
657{
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700658 XGL_FORMAT viewFormat;
659
660 m_numVertices = numIndexes;
661 m_indexType = indexType;
662 viewFormat.numericFormat = XGL_NUM_FMT_UINT;
663 switch (indexType) {
664 case XGL_INDEX_8:
665 m_stride = 1;
666 viewFormat.channelFormat = XGL_CH_FMT_R8;
667 break;
668 case XGL_INDEX_16:
669 m_stride = 2;
670 viewFormat.channelFormat = XGL_CH_FMT_R16;
671 break;
672 case XGL_INDEX_32:
673 m_stride = 4;
674 viewFormat.channelFormat = XGL_CH_FMT_R32;
675 break;
Chia-I Wub4c2aa42014-12-15 23:50:11 +0800676 default:
677 assert(!"unknown index type");
678 break;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700679 }
680
Chia-I Wua07fee62014-12-28 15:26:08 +0800681 const size_t allocationSize = numIndexes * m_stride;
682 init(*m_device, allocationSize);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700683
Chia-I Wua07fee62014-12-28 15:26:08 +0800684 void *pData = map();
685 memcpy(pData, data, allocationSize);
686 unmap();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700687
688 // set up the memory view for the constant buffer
689 this->m_constantBufferView.stride = m_stride;
Chia-I Wua07fee62014-12-28 15:26:08 +0800690 this->m_constantBufferView.range = allocationSize;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700691 this->m_constantBufferView.offset = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800692 this->m_constantBufferView.mem = obj();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700693 this->m_constantBufferView.format.channelFormat = viewFormat.channelFormat;
694 this->m_constantBufferView.format.numericFormat = viewFormat.numericFormat;
695 this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER;
696}
697
698void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset)
699{
Chia-I Wua07fee62014-12-28 15:26:08 +0800700 xglCmdBindIndexData(cmdBuffer, obj(), offset, m_indexType);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700701}
Tony Barboure2c58df2014-11-25 13:18:32 -0700702
Tony Barbouraf1f9192014-12-17 10:57:58 -0700703XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType()
704{
705 return m_indexType;
706}
707
Tony Barbour5420af02014-12-03 13:58:15 -0700708XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo(XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700709{
710 XGL_DESCRIPTOR_SLOT_INFO *slotInfo;
711 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) );
712 stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
713 stageInfo->shader.stage = m_stage;
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800714 stageInfo->shader.shader = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700715 stageInfo->shader.descriptorSetMapping[0].descriptorCount = 0;
716 stageInfo->shader.linkConstBufferCount = 0;
717 stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
718 stageInfo->shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
719 stageInfo->shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
720
Tony Barbour824b7712014-12-18 17:06:21 -0700721 stageInfo->shader.descriptorSetMapping[0].descriptorCount = descriptorSet->GetTotalSlots();
Tony Barboure2c58df2014-11-25 13:18:32 -0700722 if (stageInfo->shader.descriptorSetMapping[0].descriptorCount)
723 {
724 vector<int> allSlots;
725 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> allTypes;
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800726 vector<void *> allObjs;
Tony Barboure2c58df2014-11-25 13:18:32 -0700727
728 allSlots.reserve(m_memSlots.size() + m_imageSlots.size() + m_samplerSlots.size());
729 allTypes.reserve(m_memTypes.size() + m_imageTypes.size() + m_samplerTypes.size());
730 allObjs.reserve(m_memObjs.size() + m_imageObjs.size() + m_samplerObjs.size());
731
732 if (m_memSlots.size())
733 {
734 allSlots.insert(allSlots.end(), m_memSlots.begin(), m_memSlots.end());
735 allTypes.insert(allTypes.end(), m_memTypes.begin(), m_memTypes.end());
736 allObjs.insert(allObjs.end(), m_memObjs.begin(), m_memObjs.end());
737 }
738 if (m_imageSlots.size())
739 {
740 allSlots.insert(allSlots.end(), m_imageSlots.begin(), m_imageSlots.end());
741 allTypes.insert(allTypes.end(), m_imageTypes.begin(), m_imageTypes.end());
742 allObjs.insert(allObjs.end(), m_imageObjs.begin(), m_imageObjs.end());
743 }
744 if (m_samplerSlots.size())
745 {
746 allSlots.insert(allSlots.end(), m_samplerSlots.begin(), m_samplerSlots.end());
747 allTypes.insert(allTypes.end(), m_samplerTypes.begin(), m_samplerTypes.end());
748 allObjs.insert(allObjs.end(), m_samplerObjs.begin(), m_samplerObjs.end());
749 }
750
Tony Barbour5420af02014-12-03 13:58:15 -0700751 slotInfo = descriptorSet->GetSlotInfo(allSlots, allTypes, allObjs);
Tony Barboure2c58df2014-11-25 13:18:32 -0700752 stageInfo->shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
753 }
754 return stageInfo;
755}
756
757void XglShaderObj::BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer)
758{
759 m_memSlots.push_back(slot);
760 m_memTypes.push_back(type);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800761 m_memObjs.push_back(&constantBuffer->m_constantBufferView);
Tony Barboure2c58df2014-11-25 13:18:32 -0700762
763}
Tony Barbour82c39522014-12-04 14:33:33 -0700764
Tony Barboure2c58df2014-11-25 13:18:32 -0700765void XglShaderObj::BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture)
766{
767 m_imageSlots.push_back(slot);
768 m_imageTypes.push_back(type);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800769 m_imageObjs.push_back(&texture->m_textureViewInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700770
771}
Tony Barbour82c39522014-12-04 14:33:33 -0700772
Tony Barboure2c58df2014-11-25 13:18:32 -0700773void XglShaderObj::BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler)
774{
775 m_samplerSlots.push_back(slot);
776 m_samplerTypes.push_back(XGL_SLOT_SHADER_SAMPLER);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800777 m_samplerObjs.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700778
779}
Tony Barbour82c39522014-12-04 14:33:33 -0700780
Tony Barboure2c58df2014-11-25 13:18:32 -0700781XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework)
782{
783 XGL_RESULT err = XGL_SUCCESS;
784 std::vector<unsigned int> bil;
785 XGL_SHADER_CREATE_INFO createInfo;
786 size_t shader_len;
787
788 m_stage = stage;
789 m_device = device;
790
791 createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
792 createInfo.pNext = NULL;
793
794 if (!framework->m_use_bil) {
795
796 shader_len = strlen(shader_code);
797 createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
798 createInfo.pCode = malloc(createInfo.codeSize);
799 createInfo.flags = 0;
800
801 /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */
802 ((uint32_t *) createInfo.pCode)[0] = ICD_BIL_MAGIC;
803 ((uint32_t *) createInfo.pCode)[1] = 0;
804 ((uint32_t *) createInfo.pCode)[2] = stage;
805 memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1);
806
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800807 err = init_try(*m_device, createInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700808 }
809
810 if (framework->m_use_bil || err) {
811 std::vector<unsigned int> bil;
812 err = XGL_SUCCESS;
813
814 // Use Reference GLSL to BIL compiler
815 framework->GLSLtoBIL(stage, shader_code, bil);
816 createInfo.pCode = bil.data();
817 createInfo.codeSize = bil.size() * sizeof(unsigned int);
818 createInfo.flags = 0;
Tony Barbour82c39522014-12-04 14:33:33 -0700819
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800820 init(*m_device, createInfo);
821 }
Tony Barbourf325bf12014-12-03 15:59:38 -0700822}
Tony Barbour82c39522014-12-04 14:33:33 -0700823
Tony Barboure2c58df2014-11-25 13:18:32 -0700824XglPipelineObj::XglPipelineObj(XglDevice *device)
825{
Tony Barboure2c58df2014-11-25 13:18:32 -0700826 m_device = device;
827 m_vi_state.attributeCount = m_vi_state.bindingCount = 0;
828 m_vertexBufferCount = 0;
829
830 m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO;
831 m_ia_state.pNext = XGL_NULL_HANDLE;
832 m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST;
833 m_ia_state.disableVertexReuse = XGL_FALSE;
834 m_ia_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST;
835 m_ia_state.primitiveRestartEnable = XGL_FALSE;
836 m_ia_state.primitiveRestartIndex = 0;
837
838 m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO;
839 m_rs_state.pNext = &m_ia_state;
840 m_rs_state.depthClipEnable = XGL_FALSE;
841 m_rs_state.rasterizerDiscardEnable = XGL_FALSE;
842 m_rs_state.pointSize = 1.0;
843
Tony Barboure2c58df2014-11-25 13:18:32 -0700844 memset(&m_cb_state,0,sizeof(m_cb_state));
845 m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO;
846 m_cb_state.pNext = &m_rs_state;
847 m_cb_state.alphaToCoverageEnable = XGL_FALSE;
848 m_cb_state.dualSourceBlendEnable = XGL_FALSE;
849 m_cb_state.logicOp = XGL_LOGIC_OP_COPY;
850
Chia-I Wu62bf1dc2014-12-05 11:12:13 +0800851 m_cb_state.attachment[0].blendEnable = XGL_FALSE;
852 m_cb_state.attachment[0].format.channelFormat = XGL_CH_FMT_R8G8B8A8;
853 m_cb_state.attachment[0].format.numericFormat = XGL_NUM_FMT_UNORM;
854 m_cb_state.attachment[0].channelWriteMask = 0xF;
Tony Barboure2c58df2014-11-25 13:18:32 -0700855
856 m_db_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
857 m_db_state.pNext = &m_cb_state,
858 m_db_state.format.channelFormat = XGL_CH_FMT_R32;
859 m_db_state.format.numericFormat = XGL_NUM_FMT_DS;
860
861
862};
863
864void XglPipelineObj::AddShader(XglShaderObj* shader)
865{
866 m_shaderObjs.push_back(shader);
867}
868
869void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count)
870{
871 m_vi_state.pVertexAttributeDescriptions = vi_attrib;
872 m_vi_state.attributeCount = count;
873}
874
875void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count)
876{
877 m_vi_state.pVertexBindingDescriptions = vi_binding;
878 m_vi_state.bindingCount = count;
879}
880
881void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding)
882{
883 m_vertexBufferObjs.push_back(vertexDataBuffer);
884 m_vertexBufferBindings.push_back(binding);
885 m_vertexBufferCount++;
886}
887
Chia-I Wuecebf752014-12-05 10:45:15 +0800888void XglPipelineObj::SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att)
889{
890 m_cb_state.attachment[binding] = *att;
891}
892
Tony Barbour976e1cf2014-12-17 11:57:31 -0700893void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet)
894{
Tony Barbour976e1cf2014-12-17 11:57:31 -0700895 XGL_VOID* head_ptr = &m_db_state;
896 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
897
898 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
899
900 for (int i=0; i<m_shaderObjs.size(); i++)
901 {
902 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
903 shaderCreateInfo->pNext = head_ptr;
904 head_ptr = shaderCreateInfo;
905 }
906
907 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
908 {
909 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
910 m_vi_state.pNext = head_ptr;
911 head_ptr = &m_vi_state;
912 }
913
914 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
915 info.pNext = head_ptr;
916 info.flags = 0;
917
Chia-I Wu2648d092014-12-29 14:24:14 +0800918 init(*m_device, info);
Tony Barbour976e1cf2014-12-17 11:57:31 -0700919}
Chia-I Wu2648d092014-12-29 14:24:14 +0800920
Tony Barbour976e1cf2014-12-17 11:57:31 -0700921XGL_PIPELINE XglPipelineObj::GetPipelineHandle()
922{
Chia-I Wu2648d092014-12-29 14:24:14 +0800923 return obj();
Tony Barbour976e1cf2014-12-17 11:57:31 -0700924}
925
Tony Barbour5420af02014-12-03 13:58:15 -0700926void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700927{
Tony Barboure2c58df2014-11-25 13:18:32 -0700928 XGL_VOID* head_ptr = &m_db_state;
929 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
930
931 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
Tony Barboure2c58df2014-11-25 13:18:32 -0700932
933 for (int i=0; i<m_shaderObjs.size(); i++)
934 {
935 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
936 shaderCreateInfo->pNext = head_ptr;
937 head_ptr = shaderCreateInfo;
938 }
939
940 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
941 {
942 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
943 m_vi_state.pNext = head_ptr;
944 head_ptr = &m_vi_state;
945 }
946
947 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
948 info.pNext = head_ptr;
949 info.flags = 0;
950
Chia-I Wu2648d092014-12-29 14:24:14 +0800951 init(*m_device, info);
Tony Barboure2c58df2014-11-25 13:18:32 -0700952
Chia-I Wu2648d092014-12-29 14:24:14 +0800953 xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, obj() );
Tony Barboure2c58df2014-11-25 13:18:32 -0700954
955
956 for (int i=0; i < m_vertexBufferCount; i++)
957 {
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700958 m_vertexBufferObjs[i]->Bind(m_cmdBuffer, m_vertexBufferObjs[i]->m_constantBufferView.offset, m_vertexBufferBindings[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700959 }
Tony Barboure2c58df2014-11-25 13:18:32 -0700960}
Tony Barbour82c39522014-12-04 14:33:33 -0700961
Tony Barboure2c58df2014-11-25 13:18:32 -0700962XglMemoryRefManager::XglMemoryRefManager() {
963
964}
Tony Barbour82c39522014-12-04 14:33:33 -0700965
Tony Barboure2c58df2014-11-25 13:18:32 -0700966void XglMemoryRefManager::AddMemoryRef(XglConstantBufferObj *constantBuffer) {
Chia-I Wua07fee62014-12-28 15:26:08 +0800967 m_bufferObjs.push_back(constantBuffer->obj());
Tony Barboure2c58df2014-11-25 13:18:32 -0700968}
Tony Barbour82c39522014-12-04 14:33:33 -0700969
Tony Barboure2c58df2014-11-25 13:18:32 -0700970void XglMemoryRefManager::AddMemoryRef(XglTextureObj *texture) {
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800971 const std::vector<XGL_GPU_MEMORY> mems = texture->memories();
972 if (!mems.empty())
973 m_bufferObjs.push_back(mems[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700974}
Tony Barbour82c39522014-12-04 14:33:33 -0700975
Tony Barboure2c58df2014-11-25 13:18:32 -0700976XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() {
977
978 XGL_MEMORY_REF *localRefs;
979 XGL_UINT32 numRefs=m_bufferObjs.size();
980
981 if (numRefs <= 0)
982 return NULL;
983
984 localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) );
985 for (int i=0; i<numRefs; i++)
986 {
987 localRefs[i].flags = 0;
Chia-I Wu283d7a62014-12-28 15:43:42 +0800988 localRefs[i].mem = m_bufferObjs[i];
Tony Barboure2c58df2014-11-25 13:18:32 -0700989 }
990 return localRefs;
991}
992int XglMemoryRefManager::GetNumRefs() {
993 return m_bufferObjs.size();
994}
Tony Barbour6d047bf2014-12-10 14:34:45 -0700995
996XglCommandBufferObj::XglCommandBufferObj(XglDevice *device)
Chia-I Wud28343c2014-12-28 15:12:48 +0800997 : xgl_testing::CmdBuffer(*device, xgl_testing::CmdBuffer::create_info(XGL_QUEUE_TYPE_GRAPHICS))
Tony Barbour6d047bf2014-12-10 14:34:45 -0700998{
Tony Barbour6d047bf2014-12-10 14:34:45 -0700999 m_device = device;
Chia-I Wud28343c2014-12-28 15:12:48 +08001000 m_renderTargetCount = 0;
Tony Barbour6d047bf2014-12-10 14:34:45 -07001001}
Tony Barbour471338d2014-12-10 17:28:39 -07001002
Tony Barbour6d047bf2014-12-10 14:34:45 -07001003XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle()
1004{
Chia-I Wud28343c2014-12-28 15:12:48 +08001005 return obj();
Tony Barbour6d047bf2014-12-10 14:34:45 -07001006}
Tony Barbour471338d2014-12-10 17:28:39 -07001007
1008XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_FLAGS flags)
1009{
Chia-I Wud28343c2014-12-28 15:12:48 +08001010 begin(flags);
1011 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001012}
1013
1014XGL_RESULT XglCommandBufferObj::EndCommandBuffer()
1015{
Chia-I Wud28343c2014-12-28 15:12:48 +08001016 end();
1017 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001018}
1019
1020void XglCommandBufferObj::PrepareMemoryRegions(int transitionCount, XGL_MEMORY_STATE_TRANSITION *transitionPtr)
1021{
Chia-I Wud28343c2014-12-28 15:12:48 +08001022 xglCmdPrepareMemoryRegions(obj(), transitionCount, transitionPtr);
Tony Barbour471338d2014-12-10 17:28:39 -07001023}
1024
Tony Barbour30cc9e82014-12-17 11:53:55 -07001025void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage)
1026{
1027 XGL_UINT i;
1028
1029 // whatever we want to do, we do it to the whole buffer
1030 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1031 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1032 srRange.baseMipLevel = 0;
1033 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1034 srRange.baseArraySlice = 0;
1035 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1036
1037 // clear the back buffer to dark grey
1038 XGL_UINT clearColor[4] = {64, 64, 64, 0};
1039 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
1040 for (i = 0; i < m_renderTargetCount; i++) {
1041 transitionToClear.image = m_renderTargets[i]->image();
1042 transitionToClear.oldState = m_renderTargets[i]->state();
1043 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1044 transitionToClear.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001045 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001046 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
1047
Chia-I Wud28343c2014-12-28 15:12:48 +08001048 xglCmdClearColorImageRaw( obj(), m_renderTargets[i]->image(), clearColor, 1, &srRange );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001049 }
1050
1051 if (depthStencilImage)
1052 {
1053 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
1054 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
1055 dsRange.baseMipLevel = 0;
1056 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1057 dsRange.baseArraySlice = 0;
1058 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1059
1060 // prepare the depth buffer for clear
1061 memset(&transitionToClear,0,sizeof(transitionToClear));
1062 transitionToClear.image = depthStencilImage;
1063 transitionToClear.oldState = depthStencilBinding->depthState;
1064 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1065 transitionToClear.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001066 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001067 depthStencilBinding->depthState = transitionToClear.newState;
1068
Chia-I Wud28343c2014-12-28 15:12:48 +08001069 xglCmdClearDepthStencil(obj(), depthStencilImage, 1.0f, 0, 1, &dsRange);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001070
1071 // prepare depth buffer for rendering
1072 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1073 transitionToRender.image = depthStencilImage;
1074 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
1075 transitionToRender.newState = depthStencilBinding->depthState;
1076 transitionToRender.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001077 xglCmdPrepareImages( obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001078 depthStencilBinding->depthState = transitionToClear.newState;
1079 }
1080}
1081
1082void XglCommandBufferObj::BindAttachments(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding)
1083{
1084 XGL_UINT i;
1085 XGL_COLOR_ATTACHMENT_BIND_INFO colorBindings[XGL_MAX_COLOR_ATTACHMENTS];
1086 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1087 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1088 srRange.baseMipLevel = 0;
1089 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1090 srRange.baseArraySlice = 0;
1091 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1092
1093 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1094 for(i=0; i<m_renderTargetCount; i++)
1095 {
1096 transitionToRender.image = m_renderTargets[i]->image();
1097 transitionToRender.oldState = m_renderTargets[i]->state();
1098 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
1099 transitionToRender.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001100 xglCmdPrepareImages(obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001101 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToRender.newState);
1102 }
1103 for (i = 0; i < m_renderTargetCount; i++) {
1104 colorBindings[i].view = m_renderTargets[i]->targetView();
1105 colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
1106 }
1107 if (depthStencilBinding) {
Chia-I Wud28343c2014-12-28 15:12:48 +08001108 xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, depthStencilBinding );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001109 } else {
Chia-I Wud28343c2014-12-28 15:12:48 +08001110 xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, XGL_NULL_HANDLE );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001111 }
1112}
1113
1114void XglCommandBufferObj::BindState(XGL_RASTER_STATE_OBJECT stateRaster, XGL_VIEWPORT_STATE_OBJECT stateViewport,
1115 XGL_COLOR_BLEND_STATE_OBJECT colorBlend, XGL_DEPTH_STENCIL_STATE_OBJECT stateDepthStencil,
1116 XGL_MSAA_STATE_OBJECT stateMsaa)
1117{
1118 // set all states
Chia-I Wud28343c2014-12-28 15:12:48 +08001119 xglCmdBindStateObject( obj(), XGL_STATE_BIND_RASTER, stateRaster );
1120 xglCmdBindStateObject( obj(), XGL_STATE_BIND_VIEWPORT, stateViewport );
1121 xglCmdBindStateObject( obj(), XGL_STATE_BIND_COLOR_BLEND, colorBlend);
1122 xglCmdBindStateObject( obj(), XGL_STATE_BIND_DEPTH_STENCIL, stateDepthStencil );
1123 xglCmdBindStateObject( obj(), XGL_STATE_BIND_MSAA, stateMsaa );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001124}
1125
1126void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget)
1127{
1128 m_renderTargets.push_back(renderTarget);
1129 m_renderTargetCount++;
1130}
1131
1132void XglCommandBufferObj::DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount)
1133{
Chia-I Wud28343c2014-12-28 15:12:48 +08001134 xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001135}
1136
1137void XglCommandBufferObj::Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount)
1138{
Chia-I Wud28343c2014-12-28 15:12:48 +08001139 xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001140}
1141
1142void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
1143{
1144 XGL_RESULT err = XGL_SUCCESS;
1145
1146 // submit the command buffer to the universal queue
Chia-I Wud28343c2014-12-28 15:12:48 +08001147 err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001148 ASSERT_XGL_SUCCESS( err );
1149
1150 err = xglQueueWaitIdle( m_device->m_queue );
1151 ASSERT_XGL_SUCCESS( err );
1152
1153 // Wait for work to finish before cleaning up.
1154 xglDeviceWaitIdle(m_device->device());
1155
1156}
1157void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline)
1158{
Chia-I Wud28343c2014-12-28 15:12:48 +08001159 xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001160}
1161
1162void XglCommandBufferObj::BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet)
1163{
1164 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
Chia-I Wud28343c2014-12-28 15:12:48 +08001165 xglCmdBindDescriptorSet(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, descriptorSet, 0 );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001166}
1167void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset)
1168{
Chia-I Wua07fee62014-12-28 15:26:08 +08001169 xglCmdBindIndexData(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001170}
1171void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding)
1172{
Chia-I Wua07fee62014-12-28 15:26:08 +08001173 xglCmdBindVertexData(obj(), vertexBuffer->obj(), offset, binding);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001174}