blob: 6ee0d7d58cdf246fac7e2c2479b78ec726d0d226 [file] [log] [blame]
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -06001/*
2 * XGL Tests
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Courtney Goeltzenleuchter <courtney@lunarg.com>
26 */
27
28#include "xglrenderframework.h"
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060029
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060030XglRenderFramework::XglRenderFramework() :
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060031 m_cmdBuffer( XGL_NULL_HANDLE ),
Chia-I Wu837f9952014-12-15 23:29:34 +080032 m_stateRaster( XGL_NULL_HANDLE ),
33 m_colorBlend( XGL_NULL_HANDLE ),
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -060034 m_stateViewport( XGL_NULL_HANDLE ),
Chia-I Wu837f9952014-12-15 23:29:34 +080035 m_stateDepthStencil( XGL_NULL_HANDLE ),
36 m_stateMsaa( XGL_NULL_HANDLE ),
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -060037 m_width( 256.0 ), // default window width
38 m_height( 256.0 ) // default window height
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060039{
Chia-I Wuecebf752014-12-05 10:45:15 +080040 m_renderTargetCount = 1;
41
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060042 m_render_target_fmt.channelFormat = XGL_CH_FMT_R8G8B8A8;
43 m_render_target_fmt.numericFormat = XGL_NUM_FMT_UNORM;
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -060044
Chia-I Wuecebf752014-12-05 10:45:15 +080045 m_colorBindings[0].view = XGL_NULL_HANDLE;
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -060046 m_depthStencilBinding.view = XGL_NULL_HANDLE;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060047}
48
49XglRenderFramework::~XglRenderFramework()
50{
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060051
52}
53
54void XglRenderFramework::InitFramework()
55{
56 XGL_RESULT err;
57
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060058 err = xglInitAndEnumerateGpus(&app_info, NULL,
Chia-I Wuaf11d922014-12-28 14:37:25 +080059 XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, objs);
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060060 ASSERT_XGL_SUCCESS(err);
Jon Ashburnbf843b22014-11-26 11:06:49 -070061 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060062
63 m_device = new XglDevice(0, objs[0]);
64 m_device->get_device_queue();
65}
66
67void XglRenderFramework::ShutdownFramework()
68{
69 if (m_colorBlend) xglDestroyObject(m_colorBlend);
70 if (m_stateMsaa) xglDestroyObject(m_stateMsaa);
71 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
72 if (m_stateRaster) xglDestroyObject(m_stateRaster);
73 if (m_cmdBuffer) xglDestroyObject(m_cmdBuffer);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060074
75 if (m_stateViewport) {
76 xglDestroyObject(m_stateViewport);
77 }
78
Chia-I Wuecebf752014-12-05 10:45:15 +080079 for (XGL_UINT i = 0; i < m_renderTargetCount; i++) {
80 if (m_renderTargets[i]) {
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060081 // TODO: XglImage should be able to destroy itself
82// m_renderTarget->
83// xglDestroyObject(*m_renderTarget);
Chia-I Wuecebf752014-12-05 10:45:15 +080084 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060085 }
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060086
87 // reset the driver
Chia-I Wub76e0fa2014-12-28 14:27:28 +080088 delete m_device;
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060089 xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060090}
91
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060092void XglRenderFramework::InitState()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060093{
94 XGL_RESULT err;
95
96 m_render_target_fmt.channelFormat = XGL_CH_FMT_R8G8B8A8;
97 m_render_target_fmt.numericFormat = XGL_NUM_FMT_UNORM;
98
99 // create a raster state (solid, back-face culling)
100 XGL_RASTER_STATE_CREATE_INFO raster = {};
101 raster.sType = XGL_STRUCTURE_TYPE_RASTER_STATE_CREATE_INFO;
102 raster.fillMode = XGL_FILL_SOLID;
103 raster.cullMode = XGL_CULL_NONE;
104 raster.frontFace = XGL_FRONT_FACE_CCW;
105 err = xglCreateRasterState( device(), &raster, &m_stateRaster );
106 ASSERT_XGL_SUCCESS(err);
107
108 XGL_COLOR_BLEND_STATE_CREATE_INFO blend = {};
109 blend.sType = XGL_STRUCTURE_TYPE_COLOR_BLEND_STATE_CREATE_INFO;
110 err = xglCreateColorBlendState(device(), &blend, &m_colorBlend);
111 ASSERT_XGL_SUCCESS( err );
112
113 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
114 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
115 depthStencil.depthTestEnable = XGL_FALSE;
116 depthStencil.depthWriteEnable = XGL_FALSE;
117 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
118 depthStencil.depthBoundsEnable = XGL_FALSE;
119 depthStencil.minDepth = 0.f;
120 depthStencil.maxDepth = 1.f;
121 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
122 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
123 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
124 depthStencil.back.stencilRef = 0x00;
125 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
126 depthStencil.front = depthStencil.back;
127
128 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
129 ASSERT_XGL_SUCCESS( err );
130
131 XGL_MSAA_STATE_CREATE_INFO msaa = {};
132 msaa.sType = XGL_STRUCTURE_TYPE_MSAA_STATE_CREATE_INFO;
133 msaa.sampleMask = 1;
134 msaa.samples = 1;
135
136 err = xglCreateMsaaState( device(), &msaa, &m_stateMsaa );
137 ASSERT_XGL_SUCCESS( err );
138
139 XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {};
140
141 cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
142 cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS;
143 err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer);
144 ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed";
145}
146
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600147void XglRenderFramework::InitViewport(float width, float height)
148{
149 XGL_RESULT err;
150
151 XGL_VIEWPORT_STATE_CREATE_INFO viewport = {};
152 viewport.viewportCount = 1;
153 viewport.scissorEnable = XGL_FALSE;
154 viewport.viewports[0].originX = 0;
155 viewport.viewports[0].originY = 0;
156 viewport.viewports[0].width = 1.f * width;
157 viewport.viewports[0].height = 1.f * height;
158 viewport.viewports[0].minDepth = 0.f;
159 viewport.viewports[0].maxDepth = 1.f;
160
161 err = xglCreateViewportState( device(), &viewport, &m_stateViewport );
162 ASSERT_XGL_SUCCESS( err );
163 m_width = width;
164 m_height = height;
165}
166
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600167void XglRenderFramework::InitViewport()
168{
169 InitViewport(m_width, m_height);
170}
171
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600172void XglRenderFramework::InitRenderTarget()
173{
Chia-I Wuecebf752014-12-05 10:45:15 +0800174 XGL_UINT i;
175
176 for (i = 0; i < m_renderTargetCount; i++) {
177 m_device->CreateImage(m_width, m_height, m_render_target_fmt,
178 XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT |
179 XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
180 &m_renderTargets[i]);
181 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600182}
183
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600184void XglRenderFramework::GenerateBindRenderTargetCmd()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600185{
Chia-I Wuecebf752014-12-05 10:45:15 +0800186 XGL_UINT i;
187
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600188 // bind render target
Chia-I Wuecebf752014-12-05 10:45:15 +0800189 for (i = 0; i < m_renderTargetCount; i++) {
190 m_colorBindings[i].view = m_renderTargets[i]->targetView();
191 m_colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
192 }
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600193 if (m_depthStencilBinding.view) {
Chia-I Wuecebf752014-12-05 10:45:15 +0800194 xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, &m_depthStencilBinding );
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600195 } else {
Chia-I Wuecebf752014-12-05 10:45:15 +0800196 xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, XGL_NULL_HANDLE );
Courtney Goeltzenleuchter32e486c2014-10-22 14:12:38 -0600197 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600198}
199
Tony Barboure2c58df2014-11-25 13:18:32 -0700200void XglRenderFramework::GenerateBindStateAndPipelineCmds()
201{
202 // set all states
203 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster );
204 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport );
205 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
206 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil );
207 xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa );
208}
209
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600210void XglRenderFramework::GenerateClearAndPrepareBufferCmds()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600211{
Chia-I Wuecebf752014-12-05 10:45:15 +0800212 XGL_UINT i;
213
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600214 // whatever we want to do, we do it to the whole buffer
215 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
216 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
217 srRange.baseMipLevel = 0;
218 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
219 srRange.baseArraySlice = 0;
220 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
221
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600222 // clear the back buffer to dark grey
223 XGL_UINT clearColor[4] = {64, 64, 64, 0};
Chia-I Wuecebf752014-12-05 10:45:15 +0800224 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
225 for (i = 0; i < m_renderTargetCount; i++) {
226 transitionToClear.image = m_renderTargets[i]->image();
227 transitionToClear.oldState = m_renderTargets[i]->state();
228 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
229 transitionToClear.subresourceRange = srRange;
230 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
231 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
232
233 xglCmdClearColorImageRaw( m_cmdBuffer, m_renderTargets[i]->image(), clearColor, 1, &srRange );
234 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600235
236 // prepare back buffer for rendering
237 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wuecebf752014-12-05 10:45:15 +0800238 for (i = 0; i < m_renderTargetCount; i++) {
239 transitionToRender.image = m_renderTargets[i]->image();
240 transitionToRender.oldState = m_renderTargets[i]->state();
241 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
242 transitionToRender.subresourceRange = srRange;
243 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
244 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
245 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600246}
Tony Barbour82c39522014-12-04 14:33:33 -0700247
Tony Barboure2c58df2014-11-25 13:18:32 -0700248XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device)
249{
250 m_device = device;
251 m_nextSlot = 0;
252
253}
254
255void XglDescriptorSetObj::AttachMemoryView(XglConstantBufferObj *constantBuffer)
256{
257 m_memoryViews.push_back(&constantBuffer->m_constantBufferView);
258 m_memorySlots.push_back(m_nextSlot);
259 m_nextSlot++;
260
261}
Tony Barbour82c39522014-12-04 14:33:33 -0700262
Tony Barboure2c58df2014-11-25 13:18:32 -0700263void XglDescriptorSetObj::AttachSampler(XglSamplerObj *sampler)
264{
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800265 m_samplers.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700266 m_samplerSlots.push_back(m_nextSlot);
267 m_nextSlot++;
268
269}
Tony Barbour82c39522014-12-04 14:33:33 -0700270
Tony Barboure2c58df2014-11-25 13:18:32 -0700271void XglDescriptorSetObj::AttachImageView(XglTextureObj *texture)
272{
273 m_imageViews.push_back(&texture->m_textureViewInfo);
274 m_imageSlots.push_back(m_nextSlot);
275 m_nextSlot++;
276
277}
Tony Barbour82c39522014-12-04 14:33:33 -0700278
Tony Barboure2c58df2014-11-25 13:18:32 -0700279XGL_DESCRIPTOR_SLOT_INFO* XglDescriptorSetObj::GetSlotInfo(vector<int>slots,
280 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types,
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800281 vector<void *>objs )
Tony Barboure2c58df2014-11-25 13:18:32 -0700282{
283 int nSlots = m_memorySlots.size() + m_imageSlots.size() + m_samplerSlots.size();
284 m_slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( nSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
285 memset(m_slotInfo,0,nSlots*sizeof(XGL_DESCRIPTOR_SLOT_INFO));
286
287 for (int i=0; i<nSlots; i++)
288 {
289 m_slotInfo[i].slotObjectType = XGL_SLOT_UNUSED;
290 }
291
292 for (int i=0; i<slots.size(); i++)
293 {
294 for (int j=0; j<m_memorySlots.size(); j++)
295 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800296 if ( m_memoryViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700297 {
298 m_slotInfo[m_memorySlots[j]].shaderEntityIndex = slots[i];
299 m_slotInfo[m_memorySlots[j]].slotObjectType = types[i];
300 }
301 }
302 for (int j=0; j<m_imageSlots.size(); j++)
303 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800304 if ( m_imageViews[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700305 {
306 m_slotInfo[m_imageSlots[j]].shaderEntityIndex = slots[i];
307 m_slotInfo[m_imageSlots[j]].slotObjectType = types[i];
308 }
309 }
310 for (int j=0; j<m_samplerSlots.size(); j++)
311 {
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800312 if ( m_samplers[j] == objs[i])
Tony Barboure2c58df2014-11-25 13:18:32 -0700313 {
314 m_slotInfo[m_samplerSlots[j]].shaderEntityIndex = slots[i];
315 m_slotInfo[m_samplerSlots[j]].slotObjectType = types[i];
316 }
317 }
318 }
319
320 // for (int i=0;i<nSlots;i++)
321 // {
322 // printf("SlotInfo[%d]: Index = %d, Type = %d\n",i,m_slotInfo[i].shaderEntityIndex, m_slotInfo[i].slotObjectType);
323 // fflush(stdout);
324 // }
325
326 return(m_slotInfo);
327
328}
Tony Barbourb5f4d082014-12-17 10:54:03 -0700329void XglDescriptorSetObj::CreateXGLDescriptorSet()
330{
331 XGL_RESULT err;
332
333 // Create descriptor set for a uniform resource
334 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
335 m_descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
336 m_descriptorInfo.slots = m_nextSlot;
337
338 // Create a descriptor set with requested number of slots
339 err = xglCreateDescriptorSet( m_device->device(), &m_descriptorInfo, &m_rsrcDescSet );
340 ASSERT_XGL_SUCCESS(err);
341
342 // Bind memory to the descriptor set
343 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
344 ASSERT_XGL_SUCCESS(err);
345
346 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
347 xglClearDescriptorSetSlots(m_rsrcDescSet, 0, m_nextSlot);
348 for (int i=0; i<m_memoryViews.size();i++)
349 {
350 xglAttachMemoryViewDescriptors( m_rsrcDescSet, m_memorySlots[i], 1, m_memoryViews[i] );
351 }
352 for (int i=0; i<m_samplers.size();i++)
353 {
Chia-I Wue9864b52014-12-28 16:32:24 +0800354 xglAttachSamplerDescriptors( m_rsrcDescSet, m_samplerSlots[i], 1, &m_samplers[i]->obj() );
Tony Barbourb5f4d082014-12-17 10:54:03 -0700355 }
356 for (int i=0; i<m_imageViews.size();i++)
357 {
358 xglAttachImageViewDescriptors( m_rsrcDescSet, m_imageSlots[i], 1, m_imageViews[i] );
359 }
360 xglEndDescriptorSetUpdate( m_rsrcDescSet );
361}
362
363XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle()
364{
365 return m_rsrcDescSet;
366}
Tony Barboure2c58df2014-11-25 13:18:32 -0700367
Tony Barbour824b7712014-12-18 17:06:21 -0700368int XglDescriptorSetObj::GetTotalSlots()
369{
370 return m_nextSlot;
371}
372
Tony Barboure2c58df2014-11-25 13:18:32 -0700373void XglDescriptorSetObj::BindCommandBuffer(XGL_CMD_BUFFER commandBuffer)
374{
375 XGL_RESULT err;
376
377 // Create descriptor set for a uniform resource
378 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
379 m_descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
380 m_descriptorInfo.slots = m_nextSlot;
381
382 // Create a descriptor set with requested number of slots
383 err = xglCreateDescriptorSet( m_device->device(), &m_descriptorInfo, &m_rsrcDescSet );
Tony Barbourba2a1062014-12-03 09:24:05 -0700384 ASSERT_XGL_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -0700385
386 // Bind memory to the descriptor set
387 err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
Tony Barbourba2a1062014-12-03 09:24:05 -0700388 ASSERT_XGL_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -0700389
390 xglBeginDescriptorSetUpdate( m_rsrcDescSet );
391 xglClearDescriptorSetSlots(m_rsrcDescSet, 0, m_nextSlot);
392 for (int i=0; i<m_memoryViews.size();i++)
393 {
394 xglAttachMemoryViewDescriptors( m_rsrcDescSet, m_memorySlots[i], 1, m_memoryViews[i] );
395 }
396 for (int i=0; i<m_samplers.size();i++)
397 {
Chia-I Wue9864b52014-12-28 16:32:24 +0800398 xglAttachSamplerDescriptors( m_rsrcDescSet, m_samplerSlots[i], 1, &m_samplers[i]->obj() );
Tony Barboure2c58df2014-11-25 13:18:32 -0700399 }
400 for (int i=0; i<m_imageViews.size();i++)
401 {
402 xglAttachImageViewDescriptors( m_rsrcDescSet, m_imageSlots[i], 1, m_imageViews[i] );
403 }
404 xglEndDescriptorSetUpdate( m_rsrcDescSet );
405
406 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
407 xglCmdBindDescriptorSet(commandBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
408}
Tony Barbour82c39522014-12-04 14:33:33 -0700409
Tony Barbour25ef8a62014-12-03 13:59:18 -0700410XglDescriptorSetObj::~XglDescriptorSetObj()
411{
412 if (m_rsrcDescSet != XGL_NULL_HANDLE) xglDestroyObject(m_rsrcDescSet);
413}
Tony Barboure2c58df2014-11-25 13:18:32 -0700414
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800415XglTextureObj::XglTextureObj(XglDevice *device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700416{
417 m_device = device;
418 const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM };
Tony Barboure2c58df2014-11-25 13:18:32 -0700419 const uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 };
Tony Barboure2c58df2014-11-25 13:18:32 -0700420
421 memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo));
422
423 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
424
425 const XGL_IMAGE_CREATE_INFO image = {
426 .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
427 .pNext = NULL,
428 .imageType = XGL_IMAGE_2D,
429 .format = tex_format,
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800430 .extent = { 16, 16, 1 },
Tony Barboure2c58df2014-11-25 13:18:32 -0700431 .mipLevels = 1,
432 .arraySize = 1,
433 .samples = 1,
434 .tiling = XGL_LINEAR_TILING,
435 .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT,
436 .flags = 0,
437 };
438
Tony Barboure2c58df2014-11-25 13:18:32 -0700439 XGL_IMAGE_VIEW_CREATE_INFO view;
440 view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
441 view.pNext = NULL;
442 view.image = XGL_NULL_HANDLE;
443 view.viewType = XGL_IMAGE_VIEW_2D;
444 view.format = image.format;
445 view.channels.r = XGL_CHANNEL_SWIZZLE_R;
446 view.channels.g = XGL_CHANNEL_SWIZZLE_G;
447 view.channels.b = XGL_CHANNEL_SWIZZLE_B;
448 view.channels.a = XGL_CHANNEL_SWIZZLE_A;
449 view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR;
450 view.subresourceRange.baseMipLevel = 0;
451 view.subresourceRange.mipLevels = 1;
452 view.subresourceRange.baseArraySlice = 0;
453 view.subresourceRange.arraySize = 1;
454 view.minLod = 0.0f;
455
Tony Barboure2c58df2014-11-25 13:18:32 -0700456 /* create image */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800457 init(*m_device, image);
Tony Barboure2c58df2014-11-25 13:18:32 -0700458
459 /* create image view */
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800460 view.image = obj();
461 m_textureView.init(*m_device, view);
Tony Barboure2c58df2014-11-25 13:18:32 -0700462
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800463 XGL_SUBRESOURCE_LAYOUT layout =
464 subresource_layout(subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0));
465 m_rowPitch = layout.rowPitch;
Tony Barboure2c58df2014-11-25 13:18:32 -0700466
Tony Barboure2c58df2014-11-25 13:18:32 -0700467 XGL_VOID *data;
468 XGL_INT x, y;
469
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800470 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700471
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800472 for (y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700473 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800474 for (x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700475 row[x] = tex_colors[(x & 1) ^ (y & 1)];
476 }
477
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800478 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700479
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800480 m_textureViewInfo.view = m_textureView.obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700481
482}
Tony Barbour82c39522014-12-04 14:33:33 -0700483
Tony Barboure2c58df2014-11-25 13:18:32 -0700484void XglTextureObj::ChangeColors(uint32_t color1, uint32_t color2)
485{
Tony Barboure2c58df2014-11-25 13:18:32 -0700486 const uint32_t tex_colors[2] = { color1, color2 };
487 XGL_VOID *data;
488
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800489 data = map();
Tony Barboure2c58df2014-11-25 13:18:32 -0700490
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800491 for (int y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700492 uint32_t *row = (uint32_t *) ((char *) data + m_rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800493 for (int x = 0; x < extent().width; x++)
Tony Barboure2c58df2014-11-25 13:18:32 -0700494 row[x] = tex_colors[(x & 1) ^ (y & 1)];
495 }
496
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800497 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700498}
499
500XglSamplerObj::XglSamplerObj(XglDevice *device)
501{
Tony Barboure2c58df2014-11-25 13:18:32 -0700502 m_device = device;
Tony Barboure2c58df2014-11-25 13:18:32 -0700503
Chia-I Wue9864b52014-12-28 16:32:24 +0800504 XGL_SAMPLER_CREATE_INFO samplerCreateInfo;
505 memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo));
506 samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
507 samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST;
508 samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST;
509 samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE;
510 samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP;
511 samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP;
512 samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP;
513 samplerCreateInfo.mipLodBias = 0.0;
514 samplerCreateInfo.maxAnisotropy = 0.0;
515 samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER;
516 samplerCreateInfo.minLod = 0.0;
517 samplerCreateInfo.maxLod = 0.0;
518 samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE;
Tony Barboure2c58df2014-11-25 13:18:32 -0700519
Chia-I Wue9864b52014-12-28 16:32:24 +0800520 init(*m_device, samplerCreateInfo);
Tony Barbourf325bf12014-12-03 15:59:38 -0700521}
Tony Barboure2c58df2014-11-25 13:18:32 -0700522
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700523/*
524 * Basic ConstantBuffer constructor. Then use create methods to fill in the details.
525 */
526XglConstantBufferObj::XglConstantBufferObj(XglDevice *device)
527{
528 m_device = device;
Tony Barbour38422802014-12-10 14:36:31 -0700529 m_commandBuffer = 0;
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700530
531 memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700532}
533
Tony Barboure2c58df2014-11-25 13:18:32 -0700534XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data)
535{
Tony Barboure2c58df2014-11-25 13:18:32 -0700536 m_device = device;
Chia-I Wua07fee62014-12-28 15:26:08 +0800537 m_commandBuffer = 0;
538
539 memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
Tony Barboure2c58df2014-11-25 13:18:32 -0700540 m_numVertices = constantCount;
541 m_stride = constantSize;
542
Chia-I Wua07fee62014-12-28 15:26:08 +0800543 const size_t allocationSize = constantCount * constantSize;
544 init(*m_device, allocationSize);
Tony Barboure2c58df2014-11-25 13:18:32 -0700545
Chia-I Wua07fee62014-12-28 15:26:08 +0800546 void *pData = map();
547 memcpy(pData, data, allocationSize);
548 unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700549
550 // set up the memory view for the constant buffer
551 this->m_constantBufferView.stride = 16;
Chia-I Wua07fee62014-12-28 15:26:08 +0800552 this->m_constantBufferView.range = allocationSize;
Tony Barboure2c58df2014-11-25 13:18:32 -0700553 this->m_constantBufferView.offset = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800554 this->m_constantBufferView.mem = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700555 this->m_constantBufferView.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
556 this->m_constantBufferView.format.numericFormat = XGL_NUM_FMT_FLOAT;
557 this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER;
558}
Tony Barbour82c39522014-12-04 14:33:33 -0700559
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700560void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding)
561{
Chia-I Wua07fee62014-12-28 15:26:08 +0800562 xglCmdBindVertexData(cmdBuffer, obj(), offset, binding);
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700563}
564
565
Tony Barbour099a9eb2014-12-10 17:40:15 -0700566void XglConstantBufferObj::SetMemoryState(XGL_MEMORY_STATE newState)
Tony Barboure2c58df2014-11-25 13:18:32 -0700567{
Tony Barbour38422802014-12-10 14:36:31 -0700568 XGL_RESULT err = XGL_SUCCESS;
Tony Barbour38422802014-12-10 14:36:31 -0700569
Tony Barboure2c58df2014-11-25 13:18:32 -0700570 if (this->m_constantBufferView.state == newState)
571 return;
572
Tony Barbour38422802014-12-10 14:36:31 -0700573 if (!m_commandBuffer)
574 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800575 m_fence.init(*m_device, xgl_testing::Fence::create_info(0));
Tony Barbour38422802014-12-10 14:36:31 -0700576
577 m_commandBuffer = new XglCommandBufferObj(m_device);
578
579 }
580 else
581 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800582 m_device->wait(m_fence);
Tony Barbour38422802014-12-10 14:36:31 -0700583 }
584
Tony Barboure2c58df2014-11-25 13:18:32 -0700585 // open the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700586 err = m_commandBuffer->BeginCommandBuffer(0);
Tony Barboure2c58df2014-11-25 13:18:32 -0700587 ASSERT_XGL_SUCCESS(err);
588
Chia-I Wua07fee62014-12-28 15:26:08 +0800589 XGL_MEMORY_STATE_TRANSITION transition =
590 state_transition(XGL_MEMORY_STATE_DATA_TRANSFER, newState, 0, m_numVertices * m_stride);
Tony Barboure2c58df2014-11-25 13:18:32 -0700591
592 // write transition to the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700593 m_commandBuffer->PrepareMemoryRegions(1, &transition);
Tony Barboure2c58df2014-11-25 13:18:32 -0700594 this->m_constantBufferView.state = newState;
595
596 // finish recording the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -0700597 err = m_commandBuffer->EndCommandBuffer();
Tony Barboure2c58df2014-11-25 13:18:32 -0700598 ASSERT_XGL_SUCCESS(err);
599
600 XGL_UINT32 numMemRefs=1;
601 XGL_MEMORY_REF memRefs;
602 // this command buffer only uses the vertex buffer memory
603 memRefs.flags = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800604 memRefs.mem = obj();
Tony Barboure2c58df2014-11-25 13:18:32 -0700605
606 // submit the command buffer to the universal queue
Tony Barbour471338d2014-12-10 17:28:39 -0700607 XGL_CMD_BUFFER bufferArray[1];
608 bufferArray[0] = m_commandBuffer->GetBufferHandle();
Chia-I Wua07fee62014-12-28 15:26:08 +0800609 err = xglQueueSubmit( m_device->m_queue, 1, bufferArray, numMemRefs, &memRefs, m_fence.obj() );
Tony Barboure2c58df2014-11-25 13:18:32 -0700610 ASSERT_XGL_SUCCESS(err);
611}
612
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700613XglIndexBufferObj::XglIndexBufferObj(XglDevice *device)
614 : XglConstantBufferObj(device)
615{
616
617}
618
619void XglIndexBufferObj::CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE indexType, const void* data)
620{
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700621 XGL_FORMAT viewFormat;
622
623 m_numVertices = numIndexes;
624 m_indexType = indexType;
625 viewFormat.numericFormat = XGL_NUM_FMT_UINT;
626 switch (indexType) {
627 case XGL_INDEX_8:
628 m_stride = 1;
629 viewFormat.channelFormat = XGL_CH_FMT_R8;
630 break;
631 case XGL_INDEX_16:
632 m_stride = 2;
633 viewFormat.channelFormat = XGL_CH_FMT_R16;
634 break;
635 case XGL_INDEX_32:
636 m_stride = 4;
637 viewFormat.channelFormat = XGL_CH_FMT_R32;
638 break;
Chia-I Wub4c2aa42014-12-15 23:50:11 +0800639 default:
640 assert(!"unknown index type");
641 break;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700642 }
643
Chia-I Wua07fee62014-12-28 15:26:08 +0800644 const size_t allocationSize = numIndexes * m_stride;
645 init(*m_device, allocationSize);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700646
Chia-I Wua07fee62014-12-28 15:26:08 +0800647 void *pData = map();
648 memcpy(pData, data, allocationSize);
649 unmap();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700650
651 // set up the memory view for the constant buffer
652 this->m_constantBufferView.stride = m_stride;
Chia-I Wua07fee62014-12-28 15:26:08 +0800653 this->m_constantBufferView.range = allocationSize;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700654 this->m_constantBufferView.offset = 0;
Chia-I Wua07fee62014-12-28 15:26:08 +0800655 this->m_constantBufferView.mem = obj();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700656 this->m_constantBufferView.format.channelFormat = viewFormat.channelFormat;
657 this->m_constantBufferView.format.numericFormat = viewFormat.numericFormat;
658 this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER;
659}
660
661void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset)
662{
Chia-I Wua07fee62014-12-28 15:26:08 +0800663 xglCmdBindIndexData(cmdBuffer, obj(), offset, m_indexType);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700664}
Tony Barboure2c58df2014-11-25 13:18:32 -0700665
Tony Barbouraf1f9192014-12-17 10:57:58 -0700666XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType()
667{
668 return m_indexType;
669}
670
Tony Barbour5420af02014-12-03 13:58:15 -0700671XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo(XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700672{
673 XGL_DESCRIPTOR_SLOT_INFO *slotInfo;
674 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) );
675 stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
676 stageInfo->shader.stage = m_stage;
677 stageInfo->shader.shader = m_shader;
678 stageInfo->shader.descriptorSetMapping[0].descriptorCount = 0;
679 stageInfo->shader.linkConstBufferCount = 0;
680 stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
681 stageInfo->shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
682 stageInfo->shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
683
Tony Barbour824b7712014-12-18 17:06:21 -0700684 stageInfo->shader.descriptorSetMapping[0].descriptorCount = descriptorSet->GetTotalSlots();
Tony Barboure2c58df2014-11-25 13:18:32 -0700685 if (stageInfo->shader.descriptorSetMapping[0].descriptorCount)
686 {
687 vector<int> allSlots;
688 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> allTypes;
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800689 vector<void *> allObjs;
Tony Barboure2c58df2014-11-25 13:18:32 -0700690
691 allSlots.reserve(m_memSlots.size() + m_imageSlots.size() + m_samplerSlots.size());
692 allTypes.reserve(m_memTypes.size() + m_imageTypes.size() + m_samplerTypes.size());
693 allObjs.reserve(m_memObjs.size() + m_imageObjs.size() + m_samplerObjs.size());
694
695 if (m_memSlots.size())
696 {
697 allSlots.insert(allSlots.end(), m_memSlots.begin(), m_memSlots.end());
698 allTypes.insert(allTypes.end(), m_memTypes.begin(), m_memTypes.end());
699 allObjs.insert(allObjs.end(), m_memObjs.begin(), m_memObjs.end());
700 }
701 if (m_imageSlots.size())
702 {
703 allSlots.insert(allSlots.end(), m_imageSlots.begin(), m_imageSlots.end());
704 allTypes.insert(allTypes.end(), m_imageTypes.begin(), m_imageTypes.end());
705 allObjs.insert(allObjs.end(), m_imageObjs.begin(), m_imageObjs.end());
706 }
707 if (m_samplerSlots.size())
708 {
709 allSlots.insert(allSlots.end(), m_samplerSlots.begin(), m_samplerSlots.end());
710 allTypes.insert(allTypes.end(), m_samplerTypes.begin(), m_samplerTypes.end());
711 allObjs.insert(allObjs.end(), m_samplerObjs.begin(), m_samplerObjs.end());
712 }
713
Tony Barbour5420af02014-12-03 13:58:15 -0700714 slotInfo = descriptorSet->GetSlotInfo(allSlots, allTypes, allObjs);
Tony Barboure2c58df2014-11-25 13:18:32 -0700715 stageInfo->shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
716 }
717 return stageInfo;
718}
719
720void XglShaderObj::BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer)
721{
722 m_memSlots.push_back(slot);
723 m_memTypes.push_back(type);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800724 m_memObjs.push_back(&constantBuffer->m_constantBufferView);
Tony Barboure2c58df2014-11-25 13:18:32 -0700725
726}
Tony Barbour82c39522014-12-04 14:33:33 -0700727
Tony Barboure2c58df2014-11-25 13:18:32 -0700728void XglShaderObj::BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture)
729{
730 m_imageSlots.push_back(slot);
731 m_imageTypes.push_back(type);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800732 m_imageObjs.push_back(&texture->m_textureViewInfo);
Tony Barboure2c58df2014-11-25 13:18:32 -0700733
734}
Tony Barbour82c39522014-12-04 14:33:33 -0700735
Tony Barboure2c58df2014-11-25 13:18:32 -0700736void XglShaderObj::BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler)
737{
738 m_samplerSlots.push_back(slot);
739 m_samplerTypes.push_back(XGL_SLOT_SHADER_SAMPLER);
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800740 m_samplerObjs.push_back(sampler);
Tony Barboure2c58df2014-11-25 13:18:32 -0700741
742}
Tony Barbour82c39522014-12-04 14:33:33 -0700743
Tony Barboure2c58df2014-11-25 13:18:32 -0700744XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework)
745{
746 XGL_RESULT err = XGL_SUCCESS;
747 std::vector<unsigned int> bil;
748 XGL_SHADER_CREATE_INFO createInfo;
749 size_t shader_len;
750
751 m_stage = stage;
752 m_device = device;
753
754 createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
755 createInfo.pNext = NULL;
756
757 if (!framework->m_use_bil) {
758
759 shader_len = strlen(shader_code);
760 createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
761 createInfo.pCode = malloc(createInfo.codeSize);
762 createInfo.flags = 0;
763
764 /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */
765 ((uint32_t *) createInfo.pCode)[0] = ICD_BIL_MAGIC;
766 ((uint32_t *) createInfo.pCode)[1] = 0;
767 ((uint32_t *) createInfo.pCode)[2] = stage;
768 memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1);
769
770 err = xglCreateShader(m_device->device(), &createInfo, &m_shader);
771 if (err) {
772 free((void *) createInfo.pCode);
773 }
774 }
775
776 if (framework->m_use_bil || err) {
777 std::vector<unsigned int> bil;
778 err = XGL_SUCCESS;
779
780 // Use Reference GLSL to BIL compiler
781 framework->GLSLtoBIL(stage, shader_code, bil);
782 createInfo.pCode = bil.data();
783 createInfo.codeSize = bil.size() * sizeof(unsigned int);
784 createInfo.flags = 0;
785 err = xglCreateShader(m_device->device(), &createInfo, &m_shader);
Tony Barbourba2a1062014-12-03 09:24:05 -0700786 assert(!err);
Tony Barboure2c58df2014-11-25 13:18:32 -0700787 }
788}
Tony Barbour82c39522014-12-04 14:33:33 -0700789
Tony Barbourf325bf12014-12-03 15:59:38 -0700790XglShaderObj::~XglShaderObj()
791{
792 if (m_shader != XGL_NULL_HANDLE) xglDestroyObject(m_shader);
793}
Tony Barbour82c39522014-12-04 14:33:33 -0700794
Tony Barboure2c58df2014-11-25 13:18:32 -0700795XglPipelineObj::XglPipelineObj(XglDevice *device)
796{
Tony Barboure2c58df2014-11-25 13:18:32 -0700797 m_device = device;
798 m_vi_state.attributeCount = m_vi_state.bindingCount = 0;
799 m_vertexBufferCount = 0;
800
801 m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO;
802 m_ia_state.pNext = XGL_NULL_HANDLE;
803 m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST;
804 m_ia_state.disableVertexReuse = XGL_FALSE;
805 m_ia_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST;
806 m_ia_state.primitiveRestartEnable = XGL_FALSE;
807 m_ia_state.primitiveRestartIndex = 0;
808
809 m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO;
810 m_rs_state.pNext = &m_ia_state;
811 m_rs_state.depthClipEnable = XGL_FALSE;
812 m_rs_state.rasterizerDiscardEnable = XGL_FALSE;
813 m_rs_state.pointSize = 1.0;
814
Tony Barboure2c58df2014-11-25 13:18:32 -0700815 memset(&m_cb_state,0,sizeof(m_cb_state));
816 m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO;
817 m_cb_state.pNext = &m_rs_state;
818 m_cb_state.alphaToCoverageEnable = XGL_FALSE;
819 m_cb_state.dualSourceBlendEnable = XGL_FALSE;
820 m_cb_state.logicOp = XGL_LOGIC_OP_COPY;
821
Chia-I Wu62bf1dc2014-12-05 11:12:13 +0800822 m_cb_state.attachment[0].blendEnable = XGL_FALSE;
823 m_cb_state.attachment[0].format.channelFormat = XGL_CH_FMT_R8G8B8A8;
824 m_cb_state.attachment[0].format.numericFormat = XGL_NUM_FMT_UNORM;
825 m_cb_state.attachment[0].channelWriteMask = 0xF;
Tony Barboure2c58df2014-11-25 13:18:32 -0700826
827 m_db_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
828 m_db_state.pNext = &m_cb_state,
829 m_db_state.format.channelFormat = XGL_CH_FMT_R32;
830 m_db_state.format.numericFormat = XGL_NUM_FMT_DS;
831
832
833};
834
835void XglPipelineObj::AddShader(XglShaderObj* shader)
836{
837 m_shaderObjs.push_back(shader);
838}
839
840void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count)
841{
842 m_vi_state.pVertexAttributeDescriptions = vi_attrib;
843 m_vi_state.attributeCount = count;
844}
845
846void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count)
847{
848 m_vi_state.pVertexBindingDescriptions = vi_binding;
849 m_vi_state.bindingCount = count;
850}
851
852void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding)
853{
854 m_vertexBufferObjs.push_back(vertexDataBuffer);
855 m_vertexBufferBindings.push_back(binding);
856 m_vertexBufferCount++;
857}
858
Chia-I Wuecebf752014-12-05 10:45:15 +0800859void XglPipelineObj::SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att)
860{
861 m_cb_state.attachment[binding] = *att;
862}
863
Tony Barbour976e1cf2014-12-17 11:57:31 -0700864void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet)
865{
866 XGL_RESULT err;
867 XGL_VOID* head_ptr = &m_db_state;
868 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
869
870 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
871
872 for (int i=0; i<m_shaderObjs.size(); i++)
873 {
874 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
875 shaderCreateInfo->pNext = head_ptr;
876 head_ptr = shaderCreateInfo;
877 }
878
879 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
880 {
881 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
882 m_vi_state.pNext = head_ptr;
883 head_ptr = &m_vi_state;
884 }
885
886 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
887 info.pNext = head_ptr;
888 info.flags = 0;
889
890 err = xglCreateGraphicsPipeline(m_device->device(), &info, &m_pipeline);
891 assert(!err);
892
893 err = m_device->AllocAndBindGpuMemory(m_pipeline, "Pipeline", &m_pipe_mem);
894 assert(!err);
895}
896XGL_PIPELINE XglPipelineObj::GetPipelineHandle()
897{
898 return m_pipeline;
899}
900
Tony Barbour5420af02014-12-03 13:58:15 -0700901void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet)
Tony Barboure2c58df2014-11-25 13:18:32 -0700902{
903 XGL_RESULT err;
904 XGL_VOID* head_ptr = &m_db_state;
905 XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
906
907 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo;
Tony Barboure2c58df2014-11-25 13:18:32 -0700908
909 for (int i=0; i<m_shaderObjs.size(); i++)
910 {
911 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet);
912 shaderCreateInfo->pNext = head_ptr;
913 head_ptr = shaderCreateInfo;
914 }
915
916 if (m_vi_state.attributeCount && m_vi_state.bindingCount)
917 {
918 m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO;
919 m_vi_state.pNext = head_ptr;
920 head_ptr = &m_vi_state;
921 }
922
923 info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
924 info.pNext = head_ptr;
925 info.flags = 0;
926
927 err = xglCreateGraphicsPipeline(m_device->device(), &info, &m_pipeline);
Tony Barbourba2a1062014-12-03 09:24:05 -0700928 assert(!err);
Tony Barboure2c58df2014-11-25 13:18:32 -0700929
930 err = m_device->AllocAndBindGpuMemory(m_pipeline, "Pipeline", &m_pipe_mem);
Tony Barbourba2a1062014-12-03 09:24:05 -0700931 assert(!err);
Tony Barboure2c58df2014-11-25 13:18:32 -0700932
933 xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline );
934
935
936 for (int i=0; i < m_vertexBufferCount; i++)
937 {
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700938 m_vertexBufferObjs[i]->Bind(m_cmdBuffer, m_vertexBufferObjs[i]->m_constantBufferView.offset, m_vertexBufferBindings[i]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700939 }
Tony Barboure2c58df2014-11-25 13:18:32 -0700940}
Tony Barbour82c39522014-12-04 14:33:33 -0700941
Tony Barbourf325bf12014-12-03 15:59:38 -0700942XglPipelineObj::~XglPipelineObj()
943{
944 if (m_pipeline != XGL_NULL_HANDLE) xglDestroyObject(m_pipeline);
945}
Tony Barboure2c58df2014-11-25 13:18:32 -0700946
947XglMemoryRefManager::XglMemoryRefManager() {
948
949}
Tony Barbour82c39522014-12-04 14:33:33 -0700950
Tony Barboure2c58df2014-11-25 13:18:32 -0700951void XglMemoryRefManager::AddMemoryRef(XglConstantBufferObj *constantBuffer) {
Chia-I Wua07fee62014-12-28 15:26:08 +0800952 m_bufferObjs.push_back(constantBuffer->obj());
Tony Barboure2c58df2014-11-25 13:18:32 -0700953}
Tony Barbour82c39522014-12-04 14:33:33 -0700954
Tony Barboure2c58df2014-11-25 13:18:32 -0700955void XglMemoryRefManager::AddMemoryRef(XglTextureObj *texture) {
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800956 const std::vector<XGL_GPU_MEMORY> mems = texture->memories();
957 if (!mems.empty())
958 m_bufferObjs.push_back(mems[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700959}
Tony Barbour82c39522014-12-04 14:33:33 -0700960
Tony Barboure2c58df2014-11-25 13:18:32 -0700961XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() {
962
963 XGL_MEMORY_REF *localRefs;
964 XGL_UINT32 numRefs=m_bufferObjs.size();
965
966 if (numRefs <= 0)
967 return NULL;
968
969 localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) );
970 for (int i=0; i<numRefs; i++)
971 {
972 localRefs[i].flags = 0;
Chia-I Wu283d7a62014-12-28 15:43:42 +0800973 localRefs[i].mem = m_bufferObjs[i];
Tony Barboure2c58df2014-11-25 13:18:32 -0700974 }
975 return localRefs;
976}
977int XglMemoryRefManager::GetNumRefs() {
978 return m_bufferObjs.size();
979}
Tony Barbour6d047bf2014-12-10 14:34:45 -0700980
981XglCommandBufferObj::XglCommandBufferObj(XglDevice *device)
Chia-I Wud28343c2014-12-28 15:12:48 +0800982 : xgl_testing::CmdBuffer(*device, xgl_testing::CmdBuffer::create_info(XGL_QUEUE_TYPE_GRAPHICS))
Tony Barbour6d047bf2014-12-10 14:34:45 -0700983{
Tony Barbour6d047bf2014-12-10 14:34:45 -0700984 m_device = device;
Chia-I Wud28343c2014-12-28 15:12:48 +0800985 m_renderTargetCount = 0;
Tony Barbour6d047bf2014-12-10 14:34:45 -0700986}
Tony Barbour471338d2014-12-10 17:28:39 -0700987
Tony Barbour6d047bf2014-12-10 14:34:45 -0700988XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle()
989{
Chia-I Wud28343c2014-12-28 15:12:48 +0800990 return obj();
Tony Barbour6d047bf2014-12-10 14:34:45 -0700991}
Tony Barbour471338d2014-12-10 17:28:39 -0700992
993XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_FLAGS flags)
994{
Chia-I Wud28343c2014-12-28 15:12:48 +0800995 begin(flags);
996 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -0700997}
998
999XGL_RESULT XglCommandBufferObj::EndCommandBuffer()
1000{
Chia-I Wud28343c2014-12-28 15:12:48 +08001001 end();
1002 return XGL_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001003}
1004
1005void XglCommandBufferObj::PrepareMemoryRegions(int transitionCount, XGL_MEMORY_STATE_TRANSITION *transitionPtr)
1006{
Chia-I Wud28343c2014-12-28 15:12:48 +08001007 xglCmdPrepareMemoryRegions(obj(), transitionCount, transitionPtr);
Tony Barbour471338d2014-12-10 17:28:39 -07001008}
1009
Tony Barbour30cc9e82014-12-17 11:53:55 -07001010void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage)
1011{
1012 XGL_UINT i;
1013
1014 // whatever we want to do, we do it to the whole buffer
1015 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1016 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1017 srRange.baseMipLevel = 0;
1018 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1019 srRange.baseArraySlice = 0;
1020 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1021
1022 // clear the back buffer to dark grey
1023 XGL_UINT clearColor[4] = {64, 64, 64, 0};
1024 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
1025 for (i = 0; i < m_renderTargetCount; i++) {
1026 transitionToClear.image = m_renderTargets[i]->image();
1027 transitionToClear.oldState = m_renderTargets[i]->state();
1028 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1029 transitionToClear.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001030 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001031 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState);
1032
Chia-I Wud28343c2014-12-28 15:12:48 +08001033 xglCmdClearColorImageRaw( obj(), m_renderTargets[i]->image(), clearColor, 1, &srRange );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001034 }
1035
1036 if (depthStencilImage)
1037 {
1038 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
1039 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
1040 dsRange.baseMipLevel = 0;
1041 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1042 dsRange.baseArraySlice = 0;
1043 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1044
1045 // prepare the depth buffer for clear
1046 memset(&transitionToClear,0,sizeof(transitionToClear));
1047 transitionToClear.image = depthStencilImage;
1048 transitionToClear.oldState = depthStencilBinding->depthState;
1049 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
1050 transitionToClear.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001051 xglCmdPrepareImages( obj(), 1, &transitionToClear );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001052 depthStencilBinding->depthState = transitionToClear.newState;
1053
Chia-I Wud28343c2014-12-28 15:12:48 +08001054 xglCmdClearDepthStencil(obj(), depthStencilImage, 1.0f, 0, 1, &dsRange);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001055
1056 // prepare depth buffer for rendering
1057 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1058 transitionToRender.image = depthStencilImage;
1059 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
1060 transitionToRender.newState = depthStencilBinding->depthState;
1061 transitionToRender.subresourceRange = dsRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001062 xglCmdPrepareImages( obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001063 depthStencilBinding->depthState = transitionToClear.newState;
1064 }
1065}
1066
1067void XglCommandBufferObj::BindAttachments(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding)
1068{
1069 XGL_UINT i;
1070 XGL_COLOR_ATTACHMENT_BIND_INFO colorBindings[XGL_MAX_COLOR_ATTACHMENTS];
1071 XGL_IMAGE_SUBRESOURCE_RANGE srRange = {};
1072 srRange.aspect = XGL_IMAGE_ASPECT_COLOR;
1073 srRange.baseMipLevel = 0;
1074 srRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
1075 srRange.baseArraySlice = 0;
1076 srRange.arraySize = XGL_LAST_MIP_OR_SLICE;
1077
1078 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
1079 for(i=0; i<m_renderTargetCount; i++)
1080 {
1081 transitionToRender.image = m_renderTargets[i]->image();
1082 transitionToRender.oldState = m_renderTargets[i]->state();
1083 transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
1084 transitionToRender.subresourceRange = srRange;
Chia-I Wud28343c2014-12-28 15:12:48 +08001085 xglCmdPrepareImages(obj(), 1, &transitionToRender );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001086 m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToRender.newState);
1087 }
1088 for (i = 0; i < m_renderTargetCount; i++) {
1089 colorBindings[i].view = m_renderTargets[i]->targetView();
1090 colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
1091 }
1092 if (depthStencilBinding) {
Chia-I Wud28343c2014-12-28 15:12:48 +08001093 xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, depthStencilBinding );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001094 } else {
Chia-I Wud28343c2014-12-28 15:12:48 +08001095 xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, XGL_NULL_HANDLE );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001096 }
1097}
1098
1099void XglCommandBufferObj::BindState(XGL_RASTER_STATE_OBJECT stateRaster, XGL_VIEWPORT_STATE_OBJECT stateViewport,
1100 XGL_COLOR_BLEND_STATE_OBJECT colorBlend, XGL_DEPTH_STENCIL_STATE_OBJECT stateDepthStencil,
1101 XGL_MSAA_STATE_OBJECT stateMsaa)
1102{
1103 // set all states
Chia-I Wud28343c2014-12-28 15:12:48 +08001104 xglCmdBindStateObject( obj(), XGL_STATE_BIND_RASTER, stateRaster );
1105 xglCmdBindStateObject( obj(), XGL_STATE_BIND_VIEWPORT, stateViewport );
1106 xglCmdBindStateObject( obj(), XGL_STATE_BIND_COLOR_BLEND, colorBlend);
1107 xglCmdBindStateObject( obj(), XGL_STATE_BIND_DEPTH_STENCIL, stateDepthStencil );
1108 xglCmdBindStateObject( obj(), XGL_STATE_BIND_MSAA, stateMsaa );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001109}
1110
1111void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget)
1112{
1113 m_renderTargets.push_back(renderTarget);
1114 m_renderTargetCount++;
1115}
1116
1117void XglCommandBufferObj::DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount)
1118{
Chia-I Wud28343c2014-12-28 15:12:48 +08001119 xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001120}
1121
1122void XglCommandBufferObj::Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount)
1123{
Chia-I Wud28343c2014-12-28 15:12:48 +08001124 xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001125}
1126
1127void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
1128{
1129 XGL_RESULT err = XGL_SUCCESS;
1130
1131 // submit the command buffer to the universal queue
Chia-I Wud28343c2014-12-28 15:12:48 +08001132 err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001133 ASSERT_XGL_SUCCESS( err );
1134
1135 err = xglQueueWaitIdle( m_device->m_queue );
1136 ASSERT_XGL_SUCCESS( err );
1137
1138 // Wait for work to finish before cleaning up.
1139 xglDeviceWaitIdle(m_device->device());
1140
1141}
1142void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline)
1143{
Chia-I Wud28343c2014-12-28 15:12:48 +08001144 xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001145}
1146
1147void XglCommandBufferObj::BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet)
1148{
1149 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view)
Chia-I Wud28343c2014-12-28 15:12:48 +08001150 xglCmdBindDescriptorSet(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, descriptorSet, 0 );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001151}
1152void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset)
1153{
Chia-I Wua07fee62014-12-28 15:26:08 +08001154 xglCmdBindIndexData(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001155}
1156void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding)
1157{
Chia-I Wua07fee62014-12-28 15:26:08 +08001158 xglCmdBindVertexData(obj(), vertexBuffer->obj(), offset, binding);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001159}