blob: c144ac4fbec542e9a4400ff4d0eb721582443de9 [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;
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700182 m_colorBindings[i].view = m_renderTargets[i]->targetView();
183 m_colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
Chia-I Wuecebf752014-12-05 10:45:15 +0800184 }
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700185 // Create Framebuffer and RenderPass with color attachments and any depth/stencil attachment
186 XGL_ATTACHMENT_LOAD_OP load_op = XGL_ATTACHMENT_LOAD_OP_LOAD;
187 XGL_ATTACHMENT_STORE_OP store_op = XGL_ATTACHMENT_STORE_OP_STORE;
188 XGL_DEPTH_STENCIL_BIND_INFO *dsBinding;
189 if (m_depthStencilBinding.view)
190 dsBinding = &m_depthStencilBinding;
191 else
192 dsBinding = NULL;
193 const XGL_FRAMEBUFFER_CREATE_INFO fb_info = {
194 .sType = XGL_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
195 .pNext = NULL,
196 .colorAttachmentCount = m_renderTargetCount,
197 .pColorAttachments = m_colorBindings,
198 .pDepthStencilAttachment = dsBinding,
199 .sampleCount = 1,
200 };
201 XGL_RENDER_PASS_CREATE_INFO rp_info;
202 memset(&rp_info, 0 , sizeof(rp_info));
203 xglCreateFramebuffer(device(), &fb_info, &(rp_info.framebuffer));
204 rp_info.sType = XGL_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
205 rp_info.renderArea.extent.width = m_width;
206 rp_info.renderArea.extent.height = m_height;
207 rp_info.pColorLoadOps = &load_op;
208 rp_info.pColorStoreOps = &store_op;
209 rp_info.depthLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD;
210 rp_info.depthStoreOp = XGL_ATTACHMENT_STORE_OP_STORE;
211 rp_info.stencilLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD;
212 rp_info.stencilStoreOp = XGL_ATTACHMENT_STORE_OP_STORE;
213 xglCreateRenderPass(device(), &rp_info, &m_renderPass);
214
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600215}
216
Chia-I Wufb1459b2014-12-29 15:23:20 +0800217XglDevice::XglDevice(XGL_UINT id, XGL_PHYSICAL_GPU obj) :
218 xgl_testing::Device(obj), id(id)
219{
220 init();
221
222 props = gpu().properties();
223 queue_props = &gpu().queue_properties()[0];
224}
225
226void XglDevice::get_device_queue()
227{
228 ASSERT_NE(true, graphics_queues().empty());
229 m_queue = graphics_queues()[0]->obj();
230}
231
Tony Barboure2c58df2014-11-25 13:18:32 -0700232XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device)
233{
234 m_device = device;
235 m_nextSlot = 0;
236
237}
238
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800239void XglDescriptorSetObj::AttachBufferView(XglConstantBufferObj *constantBuffer)
Tony Barboure2c58df2014-11-25 13:18:32 -0700240{
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800241 m_bufferViews.push_back(&constantBuffer->m_bufferViewInfo);
242 m_bufferSlots.push_back(m_nextSlot);
Tony Barboure2c58df2014-11-25 13:18:32 -0700243 m_nextSlot++;
244
245}
Tony Barbour82c39522014-12-04 14:33:33 -0700246
Tony Barboure2c58df2014-11-25 13:18:32 -0700247void XglDescriptorSetObj::AttachSampler(XglSamplerObj *sampler)
248{
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800249 m_samplers.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700250 m_samplerSlots.push_back(m_nextSlot);
251 m_nextSlot++;
252
253}
Tony Barbour82c39522014-12-04 14:33:33 -0700254
Tony Barboure2c58df2014-11-25 13:18:32 -0700255void XglDescriptorSetObj::AttachImageView(XglTextureObj *texture)
256{
257 m_imageViews.push_back(&texture->m_textureViewInfo);
258 m_imageSlots.push_back(m_nextSlot);
259 m_nextSlot++;
260
261}
Tony Barbour82c39522014-12-04 14:33:33 -0700262
Tony Barboure2c58df2014-11-25 13:18:32 -0700263XGL_DESCRIPTOR_SLOT_INFO* XglDescriptorSetObj::GetSlotInfo(vector<int>slots,
264 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types,
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800265 vector<void *>objs )
Tony Barboure2c58df2014-11-25 13:18:32 -0700266{
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800267 int nSlots = m_bufferSlots.size() + m_imageSlots.size() + m_samplerSlots.size();
Tony Barboure2c58df2014-11-25 13:18:32 -0700268 m_slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( nSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
269 memset(m_slotInfo,0,nSlots*sizeof(XGL_DESCRIPTOR_SLOT_INFO));
270
271 for (int i=0; i<nSlots; i++)
272 {
273 m_slotInfo[i].slotObjectType = XGL_SLOT_UNUSED;
274 }
275
276 for (int i=0; i<slots.size(); i++)
277 {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800278 for (int j=0; j<m_bufferSlots.size(); j++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700279 {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800280 if ( m_bufferViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700281 {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800282 m_slotInfo[m_bufferSlots[j]].shaderEntityIndex = slots[i];
283 m_slotInfo[m_bufferSlots[j]].slotObjectType = types[i];
Tony Barboure2c58df2014-11-25 13:18:32 -0700284 }
285 }
286 for (int j=0; j<m_imageSlots.size(); j++)
287 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800288 if ( m_imageViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700289 {
290 m_slotInfo[m_imageSlots[j]].shaderEntityIndex = slots[i];
291 m_slotInfo[m_imageSlots[j]].slotObjectType = types[i];
292 }
293 }
294 for (int j=0; j<m_samplerSlots.size(); j++)
295 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800296 if ( m_samplers[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700297 {
298 m_slotInfo[m_samplerSlots[j]].shaderEntityIndex = slots[i];
299 m_slotInfo[m_samplerSlots[j]].slotObjectType = types[i];
300 }
301 }
302 }
303
304 // for (int i=0;i<nSlots;i++)
305 // {
306 // printf("SlotInfo[%d]: Index = %d, Type = %d\n",i,m_slotInfo[i].shaderEntityIndex, m_slotInfo[i].slotObjectType);
307 // fflush(stdout);
308 // }
309
310 return(m_slotInfo);
311
312}
Tony Barbourb5f4d082014-12-17 10:54:03 -0700313void XglDescriptorSetObj::CreateXGLDescriptorSet()
314{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800315 init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot));
Tony Barbourb5f4d082014-12-17 10:54:03 -0700316
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800317 begin();
318 clear();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700319
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800320 for (int i=0; i<m_bufferViews.size();i++)
Tony Barbourb5f4d082014-12-17 10:54:03 -0700321 {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800322 attach(m_bufferSlots[i], *m_bufferViews[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700323 }
324 for (int i=0; i<m_samplers.size();i++)
325 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800326 attach(m_samplerSlots[i], *m_samplers[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700327 }
328 for (int i=0; i<m_imageViews.size();i++)
329 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800330 attach(m_imageSlots[i], *m_imageViews[i]);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700331 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800332
333 end();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700334}
335
336XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle()
337{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800338 return obj();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700339}
Tony Barboure2c58df2014-11-25 13:18:32 -0700340
Tony Barbour824b7712014-12-18 17:06:21 -0700341int XglDescriptorSetObj::GetTotalSlots()
342{
343 return m_nextSlot;
344}
345
Tony Barboure2c58df2014-11-25 13:18:32 -0700346void XglDescriptorSetObj::BindCommandBuffer(XGL_CMD_BUFFER commandBuffer)
347{
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800348 init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot));
Tony Barboure2c58df2014-11-25 13:18:32 -0700349
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800350 begin();
351 clear();
Tony Barboure2c58df2014-11-25 13:18:32 -0700352
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800353 for (int i=0; i<m_bufferViews.size();i++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700354 {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800355 attach(m_bufferSlots[i], *m_bufferViews[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700356 }
357 for (int i=0; i<m_samplers.size();i++)
358 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800359 attach(m_samplerSlots[i], *m_samplers[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700360 }
361 for (int i=0; i<m_imageViews.size();i++)
362 {
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800363 attach(m_imageSlots[i], *m_imageViews[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700364 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800365
366 end();
Tony Barboure2c58df2014-11-25 13:18:32 -0700367
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800368 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view)
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800369 xglCmdBindDescriptorSet(commandBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, obj(), 0 );
Tony Barbour25ef8a62014-12-03 13:59:18 -0700370}
Tony Barboure2c58df2014-11-25 13:18:32 -0700371
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800372XglImage::XglImage(XglDevice *dev)
373{
374 m_device = dev;
375 m_imageInfo.view = XGL_NULL_HANDLE;
376 m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET;
377}
378
379void XglImage::init(XGL_UINT32 w, XGL_UINT32 h,
380 XGL_FORMAT fmt, XGL_FLAGS usage,
381 XGL_IMAGE_TILING tiling)
382{
383 XGL_UINT mipCount;
384
385 mipCount = 0;
386
387 XGL_UINT _w = w;
388 XGL_UINT _h = h;
389 while( ( _w > 0 ) || ( _h > 0 ) )
390 {
391 _w >>= 1;
392 _h >>= 1;
393 mipCount++;
394 }
395
396 XGL_IMAGE_CREATE_INFO imageCreateInfo = xgl_testing::Image::create_info();
397 imageCreateInfo.imageType = XGL_IMAGE_2D;
398 imageCreateInfo.format = fmt;
399 imageCreateInfo.extent.width = w;
400 imageCreateInfo.extent.height = h;
401 imageCreateInfo.mipLevels = mipCount;
402 imageCreateInfo.tiling = tiling;
403
404 imageCreateInfo.usage = usage;
405
406 xgl_testing::Image::init(*m_device, imageCreateInfo);
407
408 m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET;
409
410 XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO createView = {
411 XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO,
412 XGL_NULL_HANDLE,
413 obj(),
414 {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM},
415 0,
416 0,
417 1
418 };
419
420 m_targetView.init(*m_device, createView);
421}
422
423XGL_RESULT XglImage::MapMemory(XGL_VOID** ptr)
424{
425 *ptr = map();
426 return (*ptr) ? XGL_SUCCESS : XGL_ERROR_UNKNOWN;
427}
428
429XGL_RESULT XglImage::UnmapMemory()
430{
431 unmap();
432 return XGL_SUCCESS;
433}
434
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800435XglTextureObj::XglTextureObj(XglDevice *device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700436{
437 m_device = device;
438 const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM };
Tony Barboure2c58df2014-11-25 13:18:32 -0700439 const uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 };
Tony Barboure2c58df2014-11-25 13:18:32 -0700440
441 memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo));
442
443 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
444
445 const XGL_IMAGE_CREATE_INFO image = {
446 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
447 .pNext = NULL,
448 .imageType = XGL_IMAGE_2D,
449 .format = tex_format,
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800450 .extent = { 16, 16, 1 },
Tony Barboure2c58df2014-11-25 13:18:32 -0700451 .mipLevels = 1,
452 .arraySize = 1,
453 .samples = 1,
454 .tiling = XGL_LINEAR_TILING,
455 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
456 .flags = 0,
457 };
458
Tony Barboure2c58df2014-11-25 13:18:32 -0700459 XGL_IMAGE_VIEW_CREATE_INFO view;
460 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
461 view.pNext = NULL;
462 view.image = XGL_NULL_HANDLE;
463 view.viewType = XGL_IMAGE_VIEW_2D;
464 view.format = image.format;
465 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
466 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
467 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
468 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
469 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
470 view.subresourceRange.baseMipLevel = 0;
471 view.subresourceRange.mipLevels = 1;
472 view.subresourceRange.baseArraySlice = 0;
473 view.subresourceRange.arraySize = 1;
474 view.minLod = 0.0f;
475
Tony Barboure2c58df2014-11-25 13:18:32 -0700476 /* create image */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800477 init(*m_device, image);
Tony Barboure2c58df2014-11-25 13:18:32 -0700478
479 /* create image view */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800480 view.image = obj();
481 m_textureView.init(*m_device, view);
Tony Barboure2c58df2014-11-25 13:18:32 -0700482
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800483 XGL_SUBRESOURCE_LAYOUT layout =
484 subresource_layout(subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0));
485 m_rowPitch = layout.rowPitch;
Tony Barboure2c58df2014-11-25 13:18:32 -0700486
Tony Barboure2c58df2014-11-25 13:18:32 -0700487 XGL_VOID *data;
488 XGL_INT x, y;
489
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800490 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700491
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800492 for (y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700493 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800494 for (x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700495 row[x] = tex_colors[(x & 1) ^ (y & 1)];
496 }
497
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800498 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700499
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800500 m_textureViewInfo.view = m_textureView.obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700501
502}
Tony Barbour82c39522014-12-04 14:33:33 -0700503
Tony Barboure2c58df2014-11-25 13:18:32 -0700504void XglTextureObj::ChangeColors(uint32_t color1, uint32_t color2)
505{
Tony Barboure2c58df2014-11-25 13:18:32 -0700506 const uint32_t tex_colors[2] = { color1, color2 };
507 XGL_VOID *data;
508
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800509 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700510
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800511 for (int y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700512 uint32_t *row = (uint32_t *) ((char *) data + m_rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800513 for (int x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700514 row[x] = tex_colors[(x & 1) ^ (y & 1)];
515 }
516
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800517 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700518}
519
520XglSamplerObj::XglSamplerObj(XglDevice *device)
521{
Tony Barboure2c58df2014-11-25 13:18:32 -0700522 m_device = device;
Tony Barboure2c58df2014-11-25 13:18:32 -0700523
Chia-I Wue9864b52014-12-28 16:32:24 +0800524 XGL_SAMPLER_CREATE_INFO samplerCreateInfo;
525 memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo));
526 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
527 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
528 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
529 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
530 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
531 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
532 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
533 samplerCreateInfo.mipLodBias = 0.0;
534 samplerCreateInfo.maxAnisotropy = 0.0;
535 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
536 samplerCreateInfo.minLod = 0.0;
537 samplerCreateInfo.maxLod = 0.0;
538 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
Tony Barboure2c58df2014-11-25 13:18:32 -0700539
Chia-I Wue9864b52014-12-28 16:32:24 +0800540 init(*m_device, samplerCreateInfo);
Tony Barbourf325bf12014-12-03 15:59:38 -0700541}
Tony Barboure2c58df2014-11-25 13:18:32 -0700542
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700543/*
544 * Basic ConstantBuffer constructor. Then use create methods to fill in the details.
545 */
546XglConstantBufferObj::XglConstantBufferObj(XglDevice *device)
547{
548 m_device = device;
Tony Barbour38422802014-12-10 14:36:31 -0700549 m_commandBuffer = 0;
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700550
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800551 memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo));
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700552}
553
Tony Barboure2c58df2014-11-25 13:18:32 -0700554XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data)
555{
Tony Barboure2c58df2014-11-25 13:18:32 -0700556 m_device = device;
Chia-I Wua07fee62014-12-28 15:26:08 +0800557 m_commandBuffer = 0;
558
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800559 memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700560 m_numVertices = constantCount;
561 m_stride = constantSize;
562
Chia-I Wua07fee62014-12-28 15:26:08 +0800563 const size_t allocationSize = constantCount * constantSize;
564 init(*m_device, allocationSize);
Tony Barboure2c58df2014-11-25 13:18:32 -0700565
Chia-I Wua07fee62014-12-28 15:26:08 +0800566 void *pData = map();
567 memcpy(pData, data, allocationSize);
568 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700569
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800570 // set up the buffer view for the constant buffer
571 XGL_BUFFER_VIEW_CREATE_INFO view_info = {};
572 view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
573 view_info.buffer = obj();
574 view_info.viewType = XGL_BUFFER_VIEW_TYPED;
575 view_info.stride = 16;
576 view_info.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
577 view_info.format.numericFormat = XGL_NUM_FMT_FLOAT;
578 view_info.channels.r = XGL_CHANNEL_SWIZZLE_R;
579 view_info.channels.g = XGL_CHANNEL_SWIZZLE_G;
580 view_info.channels.b = XGL_CHANNEL_SWIZZLE_B;
581 view_info.channels.a = XGL_CHANNEL_SWIZZLE_A;
582 view_info.offset = 0;
583 view_info.range = allocationSize;
584 m_bufferView.init(*m_device, view_info);
585
586 this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO;
587 this->m_bufferViewInfo.view = m_bufferView.obj();
588 this->m_bufferViewInfo.state = XGL_BUFFER_STATE_DATA_TRANSFER;
Tony Barboure2c58df2014-11-25 13:18:32 -0700589}
Tony Barbour82c39522014-12-04 14:33:33 -0700590
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700591void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding)
592{
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800593 xglCmdBindVertexBuffer(cmdBuffer, obj(), offset, binding);
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700594}
595
596
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800597void XglConstantBufferObj::SetBufferState(XGL_BUFFER_STATE newState)
Tony Barboure2c58df2014-11-25 13:18:32 -0700598{
Tony Barbour38422802014-12-10 14:36:31 -0700599 XGL_RESULT err = XGL_SUCCESS;
Tony Barbour38422802014-12-10 14:36:31 -0700600
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800601 if (this->m_bufferViewInfo.state == newState)
Tony Barboure2c58df2014-11-25 13:18:32 -0700602 return;
603
Tony Barbour38422802014-12-10 14:36:31 -0700604 if (!m_commandBuffer)
605 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800606 m_fence.init(*m_device, xgl_testing::Fence::create_info(0));
Tony Barbour38422802014-12-10 14:36:31 -0700607
608 m_commandBuffer = new XglCommandBufferObj(m_device);
609
610 }
611 else
612 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800613 m_device->wait(m_fence);
Tony Barbour38422802014-12-10 14:36:31 -0700614 }
615
Tony Barboure2c58df2014-11-25 13:18:32 -0700616 // open the command buffer
Jon Ashburnc4164b12014-12-31 17:10:47 -0700617 XGL_CMD_BUFFER_BEGIN_INFO cmd_buf_info = {
618 .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO,
619 .pNext = NULL,
620 .flags = 0,
621 };
622 err = m_commandBuffer->BeginCommandBuffer(&cmd_buf_info);
Tony Barboure2c58df2014-11-25 13:18:32 -0700623 ASSERT_XGL_SUCCESS(err);
624
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800625 XGL_BUFFER_STATE_TRANSITION transition =
626 state_transition(XGL_BUFFER_STATE_DATA_TRANSFER, newState, 0, m_numVertices * m_stride);
Tony Barboure2c58df2014-11-25 13:18:32 -0700627
628 // write transition to the command buffer
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800629 m_commandBuffer->PrepareBufferRegions(1, &transition);
630 this->m_bufferViewInfo.state = newState;
Tony Barboure2c58df2014-11-25 13:18:32 -0700631
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 Wu1a28fe02015-01-01 07:55:04 +0800640 memRefs.mem = memories()[0];
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
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800687 // set up the buffer view for the constant buffer
688 XGL_BUFFER_VIEW_CREATE_INFO view_info = {};
689 view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
690 view_info.buffer = obj();
691 view_info.viewType = XGL_BUFFER_VIEW_TYPED;
692 view_info.stride = m_stride;
693 view_info.format.channelFormat = viewFormat.channelFormat;
694 view_info.format.numericFormat = viewFormat.numericFormat;
695 view_info.channels.r = XGL_CHANNEL_SWIZZLE_R;
696 view_info.channels.g = XGL_CHANNEL_SWIZZLE_G;
697 view_info.channels.b = XGL_CHANNEL_SWIZZLE_B;
698 view_info.channels.a = XGL_CHANNEL_SWIZZLE_A;
699 view_info.offset = 0;
700 view_info.range = allocationSize;
701 m_bufferView.init(*m_device, view_info);
702
703 this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO;
704 this->m_bufferViewInfo.view = m_bufferView.obj();
705 this->m_bufferViewInfo.state = XGL_BUFFER_STATE_DATA_TRANSFER;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700706}
707
708void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset)
709{
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800710 xglCmdBindIndexBuffer(cmdBuffer, obj(), offset, m_indexType);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700711}
Tony Barboure2c58df2014-11-25 13:18:32 -0700712
Tony Barbouraf1f9192014-12-17 10:57:58 -0700713XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType()
714{
715 return m_indexType;
716}
717
Tony Barbour5420af02014-12-03 13:58:15 -0700718XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo(XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700719{
720 XGL_DESCRIPTOR_SLOT_INFO *slotInfo;
721 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) );
722 stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
723 stageInfo->shader.stage = m_stage;
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800724 stageInfo->shader.shader = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700725 stageInfo->shader.descriptorSetMapping[0].descriptorCount = 0;
726 stageInfo->shader.linkConstBufferCount = 0;
727 stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800728 stageInfo->shader.dynamicBufferViewMapping.slotObjectType = XGL_SLOT_UNUSED;
729 stageInfo->shader.dynamicBufferViewMapping.shaderEntityIndex = 0;
Tony Barboure2c58df2014-11-25 13:18:32 -0700730
Tony Barbour824b7712014-12-18 17:06:21 -0700731 stageInfo->shader.descriptorSetMapping[0].descriptorCount = descriptorSet->GetTotalSlots();
Tony Barboure2c58df2014-11-25 13:18:32 -0700732 if (stageInfo->shader.descriptorSetMapping[0].descriptorCount)
733 {
734 vector<int> allSlots;
735 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> allTypes;
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800736 vector<void *> allObjs;
Tony Barboure2c58df2014-11-25 13:18:32 -0700737
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800738 allSlots.reserve(m_bufferSlots.size() + m_imageSlots.size() + m_samplerSlots.size());
739 allTypes.reserve(m_bufferTypes.size() + m_imageTypes.size() + m_samplerTypes.size());
740 allObjs.reserve(m_bufferObjs.size() + m_imageObjs.size() + m_samplerObjs.size());
Tony Barboure2c58df2014-11-25 13:18:32 -0700741
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800742 if (m_bufferSlots.size())
Tony Barboure2c58df2014-11-25 13:18:32 -0700743 {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800744 allSlots.insert(allSlots.end(), m_bufferSlots.begin(), m_bufferSlots.end());
745 allTypes.insert(allTypes.end(), m_bufferTypes.begin(), m_bufferTypes.end());
746 allObjs.insert(allObjs.end(), m_bufferObjs.begin(), m_bufferObjs.end());
Tony Barboure2c58df2014-11-25 13:18:32 -0700747 }
748 if (m_imageSlots.size())
749 {
750 allSlots.insert(allSlots.end(), m_imageSlots.begin(), m_imageSlots.end());
751 allTypes.insert(allTypes.end(), m_imageTypes.begin(), m_imageTypes.end());
752 allObjs.insert(allObjs.end(), m_imageObjs.begin(), m_imageObjs.end());
753 }
754 if (m_samplerSlots.size())
755 {
756 allSlots.insert(allSlots.end(), m_samplerSlots.begin(), m_samplerSlots.end());
757 allTypes.insert(allTypes.end(), m_samplerTypes.begin(), m_samplerTypes.end());
758 allObjs.insert(allObjs.end(), m_samplerObjs.begin(), m_samplerObjs.end());
759 }
760
Tony Barbour5420af02014-12-03 13:58:15 -0700761 slotInfo = descriptorSet->GetSlotInfo(allSlots, allTypes, allObjs);
Tony Barboure2c58df2014-11-25 13:18:32 -0700762 stageInfo->shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
763 }
764 return stageInfo;
765}
766
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800767void XglShaderObj::BindShaderEntitySlotToBuffer(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer)
Tony Barboure2c58df2014-11-25 13:18:32 -0700768{
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800769 m_bufferSlots.push_back(slot);
770 m_bufferTypes.push_back(type);
771 m_bufferObjs.push_back(&constantBuffer->m_bufferViewInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700772
773}
Tony Barbour82c39522014-12-04 14:33:33 -0700774
Tony Barboure2c58df2014-11-25 13:18:32 -0700775void XglShaderObj::BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture)
776{
777 m_imageSlots.push_back(slot);
778 m_imageTypes.push_back(type);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800779 m_imageObjs.push_back(&texture->m_textureViewInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700780
781}
Tony Barbour82c39522014-12-04 14:33:33 -0700782
Tony Barboure2c58df2014-11-25 13:18:32 -0700783void XglShaderObj::BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler)
784{
785 m_samplerSlots.push_back(slot);
786 m_samplerTypes.push_back(XGL_SLOT_SHADER_SAMPLER);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800787 m_samplerObjs.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700788
789}
Tony Barbour82c39522014-12-04 14:33:33 -0700790
Tony Barboure2c58df2014-11-25 13:18:32 -0700791XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework)
792{
793 XGL_RESULT err = XGL_SUCCESS;
794 std::vector<unsigned int> bil;
795 XGL_SHADER_CREATE_INFO createInfo;
796 size_t shader_len;
797
798 m_stage = stage;
799 m_device = device;
800
801 createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
802 createInfo.pNext = NULL;
803
804 if (!framework->m_use_bil) {
805
806 shader_len = strlen(shader_code);
807 createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
808 createInfo.pCode = malloc(createInfo.codeSize);
809 createInfo.flags = 0;
810
811 /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */
812 ((uint32_t *) createInfo.pCode)[0] = ICD_BIL_MAGIC;
813 ((uint32_t *) createInfo.pCode)[1] = 0;
814 ((uint32_t *) createInfo.pCode)[2] = stage;
815 memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1);
816
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800817 err = init_try(*m_device, createInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700818 }
819
820 if (framework->m_use_bil || err) {
821 std::vector<unsigned int> bil;
822 err = XGL_SUCCESS;
823
824 // Use Reference GLSL to BIL compiler
825 framework->GLSLtoBIL(stage, shader_code, bil);
826 createInfo.pCode = bil.data();
827 createInfo.codeSize = bil.size() * sizeof(unsigned int);
828 createInfo.flags = 0;
Tony Barbour82c39522014-12-04 14:33:33 -0700829
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800830 init(*m_device, createInfo);
831 }
Tony Barbourf325bf12014-12-03 15:59:38 -0700832}
Tony Barbour82c39522014-12-04 14:33:33 -0700833
Tony Barboure2c58df2014-11-25 13:18:32 -0700834XglPipelineObj::XglPipelineObj(XglDevice *device)
835{
Tony Barboure2c58df2014-11-25 13:18:32 -0700836 m_device = device;
837 m_vi_state.attributeCount = m_vi_state.bindingCount = 0;
838 m_vertexBufferCount = 0;
839
840 m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO;
841 m_ia_state.pNext = XGL_NULL_HANDLE;
842 m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST;
843 m_ia_state.disableVertexReuse = XGL_FALSE;
844 m_ia_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST;
845 m_ia_state.primitiveRestartEnable = XGL_FALSE;
846 m_ia_state.primitiveRestartIndex = 0;
847
848 m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO;
849 m_rs_state.pNext = &m_ia_state;
850 m_rs_state.depthClipEnable = XGL_FALSE;
851 m_rs_state.rasterizerDiscardEnable = XGL_FALSE;
852 m_rs_state.pointSize = 1.0;
853
Tony Barboure2c58df2014-11-25 13:18:32 -0700854 memset(&m_cb_state,0,sizeof(m_cb_state));
855 m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO;
856 m_cb_state.pNext = &m_rs_state;
857 m_cb_state.alphaToCoverageEnable = XGL_FALSE;
858 m_cb_state.dualSourceBlendEnable = XGL_FALSE;
859 m_cb_state.logicOp = XGL_LOGIC_OP_COPY;
860
Chia-I Wu62bf1dc2014-12-05 11:12:13 +0800861 m_cb_state.attachment[0].blendEnable = XGL_FALSE;
862 m_cb_state.attachment[0].format.channelFormat = XGL_CH_FMT_R8G8B8A8;
863 m_cb_state.attachment[0].format.numericFormat = XGL_NUM_FMT_UNORM;
864 m_cb_state.attachment[0].channelWriteMask = 0xF;
Tony Barboure2c58df2014-11-25 13:18:32 -0700865
866 m_db_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
867 m_db_state.pNext = &m_cb_state,
868 m_db_state.format.channelFormat = XGL_CH_FMT_R32;
869 m_db_state.format.numericFormat = XGL_NUM_FMT_DS;
870
871
872};
873
874void XglPipelineObj::AddShader(XglShaderObj* shader)
875{
876 m_shaderObjs.push_back(shader);
877}
878
879void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count)
880{
881 m_vi_state.pVertexAttributeDescriptions = vi_attrib;
882 m_vi_state.attributeCount = count;
883}
884
885void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count)
886{
887 m_vi_state.pVertexBindingDescriptions = vi_binding;
888 m_vi_state.bindingCount = count;
889}
890
891void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding)
892{
893 m_vertexBufferObjs.push_back(vertexDataBuffer);
894 m_vertexBufferBindings.push_back(binding);
895 m_vertexBufferCount++;
896}
897
Chia-I Wuecebf752014-12-05 10:45:15 +0800898void XglPipelineObj::SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att)
899{
900 m_cb_state.attachment[binding] = *att;
901}
902
Tony Barbour976e1cf2014-12-17 11:57:31 -0700903void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet)
904{
Tony Barbour976e1cf2014-12-17 11:57:31 -0700905 XGL_VOID* head_ptr = &m_db_state;
906 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
907
908 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
909
910 for (int i=0; i<m_shaderObjs.size(); i++)
911 {
912 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
913 shaderCreateInfo->pNext = head_ptr;
914 head_ptr = shaderCreateInfo;
915 }
916
917 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
918 {
919 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
920 m_vi_state.pNext = head_ptr;
921 head_ptr = &m_vi_state;
922 }
923
924 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
925 info.pNext = head_ptr;
926 info.flags = 0;
927
Chia-I Wu2648d092014-12-29 14:24:14 +0800928 init(*m_device, info);
Tony Barbour976e1cf2014-12-17 11:57:31 -0700929}
Chia-I Wu2648d092014-12-29 14:24:14 +0800930
Tony Barbour976e1cf2014-12-17 11:57:31 -0700931XGL_PIPELINE XglPipelineObj::GetPipelineHandle()
932{
Chia-I Wu2648d092014-12-29 14:24:14 +0800933 return obj();
Tony Barbour976e1cf2014-12-17 11:57:31 -0700934}
935
Tony Barbour5420af02014-12-03 13:58:15 -0700936void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700937{
Tony Barboure2c58df2014-11-25 13:18:32 -0700938 XGL_VOID* head_ptr = &m_db_state;
939 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
940
941 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
Tony Barboure2c58df2014-11-25 13:18:32 -0700942
943 for (int i=0; i<m_shaderObjs.size(); i++)
944 {
945 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
946 shaderCreateInfo->pNext = head_ptr;
947 head_ptr = shaderCreateInfo;
948 }
949
950 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
951 {
952 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
953 m_vi_state.pNext = head_ptr;
954 head_ptr = &m_vi_state;
955 }
956
957 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
958 info.pNext = head_ptr;
959 info.flags = 0;
960
Chia-I Wu2648d092014-12-29 14:24:14 +0800961 init(*m_device, info);
Tony Barboure2c58df2014-11-25 13:18:32 -0700962
Chia-I Wu2648d092014-12-29 14:24:14 +0800963 xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, obj() );
Tony Barboure2c58df2014-11-25 13:18:32 -0700964
965
966 for (int i=0; i < m_vertexBufferCount; i++)
967 {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800968 m_vertexBufferObjs[i]->Bind(m_cmdBuffer, 0, m_vertexBufferBindings[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700969 }
Tony Barboure2c58df2014-11-25 13:18:32 -0700970}
Tony Barbour82c39522014-12-04 14:33:33 -0700971
Tony Barboure2c58df2014-11-25 13:18:32 -0700972XglMemoryRefManager::XglMemoryRefManager() {
973
974}
Tony Barbour82c39522014-12-04 14:33:33 -0700975
Tony Barboure2c58df2014-11-25 13:18:32 -0700976void XglMemoryRefManager::AddMemoryRef(XglConstantBufferObj *constantBuffer) {
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800977 const std::vector<XGL_GPU_MEMORY> mems = constantBuffer->memories();
978 if (!mems.empty())
979 m_bufferObjs.push_back(mems[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700980}
Tony Barbour82c39522014-12-04 14:33:33 -0700981
Tony Barboure2c58df2014-11-25 13:18:32 -0700982void XglMemoryRefManager::AddMemoryRef(XglTextureObj *texture) {
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800983 const std::vector<XGL_GPU_MEMORY> mems = texture->memories();
984 if (!mems.empty())
985 m_bufferObjs.push_back(mems[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700986}
Tony Barbour82c39522014-12-04 14:33:33 -0700987
Tony Barboure2c58df2014-11-25 13:18:32 -0700988XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() {
989
990 XGL_MEMORY_REF *localRefs;
991 XGL_UINT32 numRefs=m_bufferObjs.size();
992
993 if (numRefs <= 0)
994 return NULL;
995
996 localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) );
997 for (int i=0; i<numRefs; i++)
998 {
999 localRefs[i].flags = 0;
Chia-I Wu283d7a62014-12-28 15:43:42 +08001000 localRefs[i].mem = m_bufferObjs[i];
Tony Barboure2c58df2014-11-25 13:18:32 -07001001 }
1002 return localRefs;
1003}
1004int XglMemoryRefManager::GetNumRefs() {
1005 return m_bufferObjs.size();
1006}
Tony Barbour6d047bf2014-12-10 14:34:45 -07001007
1008XglCommandBufferObj::XglCommandBufferObj(XglDevice *device)
Chia-I Wud28343c2014-12-28 15:12:48 +08001009 : xgl_testing::CmdBuffer(*device, xgl_testing::CmdBuffer::create_info(XGL_QUEUE_TYPE_GRAPHICS))
Tony Barbour6d047bf2014-12-10 14:34:45 -07001010{
Tony Barbour6d047bf2014-12-10 14:34:45 -07001011 m_device = device;
Chia-I Wud28343c2014-12-28 15:12:48 +08001012 m_renderTargetCount = 0;
Tony Barbour6d047bf2014-12-10 14:34:45 -07001013}
Tony Barbour471338d2014-12-10 17:28:39 -07001014
Tony Barbour6d047bf2014-12-10 14:34:45 -07001015XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle()
1016{
Chia-I Wud28343c2014-12-28 15:12:48 +08001017 return obj();
Tony Barbour6d047bf2014-12-10 14:34:45 -07001018}
Tony Barbour471338d2014-12-10 17:28:39 -07001019
Jon Ashburnc4164b12014-12-31 17:10:47 -07001020XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_CMD_BUFFER_BEGIN_INFO *pInfo)
Tony Barbour471338d2014-12-10 17:28:39 -07001021{
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001022 begin(pInfo);
1023 return XGL_SUCCESS;
1024}
1025
1026XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_RENDER_PASS renderpass_obj)
1027{
1028 begin(renderpass_obj);
1029 return XGL_SUCCESS;
1030}
1031
1032XGL_RESULT XglCommandBufferObj::BeginCommandBuffer()
1033{
1034 begin();
Chia-I Wud28343c2014-12-28 15:12:48 +08001035 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001036}
1037
1038XGL_RESULT XglCommandBufferObj::EndCommandBuffer()
1039{
Chia-I Wud28343c2014-12-28 15:12:48 +08001040 end();
1041 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001042}
1043
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001044void XglCommandBufferObj::PrepareBufferRegions(int transitionCount, XGL_BUFFER_STATE_TRANSITION *transitionPtr)
Tony Barbour471338d2014-12-10 17:28:39 -07001045{
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001046 xglCmdPrepareBufferRegions(obj(), transitionCount, transitionPtr);
Tony Barbour471338d2014-12-10 17:28:39 -07001047}
1048
Tony Barbour30cc9e82014-12-17 11:53:55 -07001049void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage)
1050{
1051 XGL_UINT i;
1052
1053 // whatever we want to do, we do it to the whole buffer
1054 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1055 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1056 srRange.baseMipLevel = 0;
1057 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1058 srRange.baseArraySlice = 0;
1059 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1060
1061 // clear the back buffer to dark grey
1062 XGL_UINT clearColor[4] = {64, 64, 64, 0};
1063 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
1064 for (i = 0; i < m_renderTargetCount; i++) {
1065 transitionToClear.image = m_renderTargets[i]->image();
1066 transitionToClear.oldState = m_renderTargets[i]->state();
1067 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1068 transitionToClear.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001069 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001070 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
1071
Chia-I Wud28343c2014-12-28 15:12:48 +08001072 xglCmdClearColorImageRaw( obj(), m_renderTargets[i]->image(), clearColor, 1, &srRange );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001073 }
1074
1075 if (depthStencilImage)
1076 {
1077 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
1078 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
1079 dsRange.baseMipLevel = 0;
1080 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1081 dsRange.baseArraySlice = 0;
1082 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1083
1084 // prepare the depth buffer for clear
1085 memset(&transitionToClear,0,sizeof(transitionToClear));
1086 transitionToClear.image = depthStencilImage;
1087 transitionToClear.oldState = depthStencilBinding->depthState;
1088 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1089 transitionToClear.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001090 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001091 depthStencilBinding->depthState = transitionToClear.newState;
1092
Chia-I Wud28343c2014-12-28 15:12:48 +08001093 xglCmdClearDepthStencil(obj(), depthStencilImage, 1.0f, 0, 1, &dsRange);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001094
1095 // prepare depth buffer for rendering
1096 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1097 transitionToRender.image = depthStencilImage;
1098 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
1099 transitionToRender.newState = depthStencilBinding->depthState;
1100 transitionToRender.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001101 xglCmdPrepareImages( obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001102 depthStencilBinding->depthState = transitionToClear.newState;
1103 }
1104}
1105
Jon Ashburncdc40be2015-01-02 18:27:14 -07001106void XglCommandBufferObj::PrepareAttachments()
Tony Barbour30cc9e82014-12-17 11:53:55 -07001107{
1108 XGL_UINT i;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001109 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1110 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1111 srRange.baseMipLevel = 0;
1112 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1113 srRange.baseArraySlice = 0;
1114 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1115
1116 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1117 for(i=0; i<m_renderTargetCount; i++)
1118 {
1119 transitionToRender.image = m_renderTargets[i]->image();
1120 transitionToRender.oldState = m_renderTargets[i]->state();
1121 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
1122 transitionToRender.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001123 xglCmdPrepareImages(obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001124 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToRender.newState);
1125 }
Tony Barbour30cc9e82014-12-17 11:53:55 -07001126}
1127
Tony Barbour22e32a12015-01-08 17:08:28 -07001128void XglCommandBufferObj::BindStateObject(XGL_STATE_BIND_POINT stateBindPoint, XGL_STATE_OBJECT stateObject)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001129{
Tony Barbour22e32a12015-01-08 17:08:28 -07001130 xglCmdBindStateObject( obj(), stateBindPoint, stateObject);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001131}
1132
1133void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget)
1134{
1135 m_renderTargets.push_back(renderTarget);
1136 m_renderTargetCount++;
1137}
1138
1139void XglCommandBufferObj::DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount)
1140{
Chia-I Wud28343c2014-12-28 15:12:48 +08001141 xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001142}
1143
1144void XglCommandBufferObj::Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount)
1145{
Chia-I Wud28343c2014-12-28 15:12:48 +08001146 xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001147}
1148
1149void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
1150{
1151 XGL_RESULT err = XGL_SUCCESS;
1152
1153 // submit the command buffer to the universal queue
Chia-I Wud28343c2014-12-28 15:12:48 +08001154 err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001155 ASSERT_XGL_SUCCESS( err );
1156
1157 err = xglQueueWaitIdle( m_device->m_queue );
1158 ASSERT_XGL_SUCCESS( err );
1159
1160 // Wait for work to finish before cleaning up.
1161 xglDeviceWaitIdle(m_device->device());
1162
1163}
1164void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline)
1165{
Chia-I Wud28343c2014-12-28 15:12:48 +08001166 xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001167}
1168
1169void XglCommandBufferObj::BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet)
1170{
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001171 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view)
Chia-I Wud28343c2014-12-28 15:12:48 +08001172 xglCmdBindDescriptorSet(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, descriptorSet, 0 );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001173}
1174void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset)
1175{
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001176 xglCmdBindIndexBuffer(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001177}
1178void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding)
1179{
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001180 xglCmdBindVertexBuffer(obj(), vertexBuffer->obj(), offset, binding);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001181}