Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 1 | /* |
| 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 Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 29 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 30 | XglRenderFramework::XglRenderFramework() : |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 31 | m_cmdBuffer( XGL_NULL_HANDLE ), |
Chia-I Wu | 837f995 | 2014-12-15 23:29:34 +0800 | [diff] [blame] | 32 | m_stateRaster( XGL_NULL_HANDLE ), |
| 33 | m_colorBlend( XGL_NULL_HANDLE ), |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 34 | m_stateViewport( XGL_NULL_HANDLE ), |
Chia-I Wu | 837f995 | 2014-12-15 23:29:34 +0800 | [diff] [blame] | 35 | m_stateDepthStencil( XGL_NULL_HANDLE ), |
| 36 | m_stateMsaa( XGL_NULL_HANDLE ), |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 37 | m_width( 256.0 ), // default window width |
| 38 | m_height( 256.0 ) // default window height |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 39 | { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 40 | m_renderTargetCount = 1; |
| 41 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 42 | m_render_target_fmt.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 43 | m_render_target_fmt.numericFormat = XGL_NUM_FMT_UNORM; |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 44 | |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 45 | m_colorBindings[0].view = XGL_NULL_HANDLE; |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 46 | m_depthStencilBinding.view = XGL_NULL_HANDLE; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | XglRenderFramework::~XglRenderFramework() |
| 50 | { |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 51 | |
| 52 | } |
| 53 | |
| 54 | void XglRenderFramework::InitFramework() |
| 55 | { |
| 56 | XGL_RESULT err; |
| 57 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 58 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
Chia-I Wu | af11d92 | 2014-12-28 14:37:25 +0800 | [diff] [blame] | 59 | XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, objs); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 60 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | bf843b2 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 61 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 62 | |
| 63 | m_device = new XglDevice(0, objs[0]); |
| 64 | m_device->get_device_queue(); |
| 65 | } |
| 66 | |
| 67 | void 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 Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 74 | |
| 75 | if (m_stateViewport) { |
| 76 | xglDestroyObject(m_stateViewport); |
| 77 | } |
| 78 | |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 79 | for (XGL_UINT i = 0; i < m_renderTargetCount; i++) { |
| 80 | if (m_renderTargets[i]) { |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 81 | // TODO: XglImage should be able to destroy itself |
| 82 | // m_renderTarget-> |
| 83 | // xglDestroyObject(*m_renderTarget); |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 84 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 85 | } |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 86 | |
| 87 | // reset the driver |
Chia-I Wu | b76e0fa | 2014-12-28 14:27:28 +0800 | [diff] [blame] | 88 | delete m_device; |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 89 | xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 90 | } |
| 91 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 92 | void XglRenderFramework::InitState() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 93 | { |
| 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 Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 147 | void 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 Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 167 | void XglRenderFramework::InitViewport() |
| 168 | { |
| 169 | InitViewport(m_width, m_height); |
| 170 | } |
| 171 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 172 | void XglRenderFramework::InitRenderTarget() |
| 173 | { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 174 | XGL_UINT i; |
| 175 | |
| 176 | for (i = 0; i < m_renderTargetCount; i++) { |
Chia-I Wu | f50ee21 | 2014-12-29 14:31:52 +0800 | [diff] [blame] | 177 | XglImage *img = new XglImage(m_device); |
| 178 | img->init(m_width, m_height, m_render_target_fmt, |
| 179 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 180 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 181 | m_renderTargets[i] = img; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 182 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 183 | } |
| 184 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 185 | void XglRenderFramework::GenerateBindRenderTargetCmd() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 186 | { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 187 | XGL_UINT i; |
| 188 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 189 | // bind render target |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 190 | for (i = 0; i < m_renderTargetCount; i++) { |
| 191 | m_colorBindings[i].view = m_renderTargets[i]->targetView(); |
| 192 | m_colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 193 | } |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 194 | if (m_depthStencilBinding.view) { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 195 | xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, &m_depthStencilBinding ); |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 196 | } else { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 197 | xglCmdBindAttachments(m_cmdBuffer, m_renderTargetCount, m_colorBindings, XGL_NULL_HANDLE ); |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 198 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 199 | } |
| 200 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 201 | void XglRenderFramework::GenerateBindStateAndPipelineCmds() |
| 202 | { |
| 203 | // set all states |
| 204 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster ); |
| 205 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport ); |
| 206 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend); |
| 207 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil ); |
| 208 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa ); |
| 209 | } |
| 210 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 211 | void XglRenderFramework::GenerateClearAndPrepareBufferCmds() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 212 | { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 213 | XGL_UINT i; |
| 214 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 215 | // whatever we want to do, we do it to the whole buffer |
| 216 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 217 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 218 | srRange.baseMipLevel = 0; |
| 219 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 220 | srRange.baseArraySlice = 0; |
| 221 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 222 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 223 | // clear the back buffer to dark grey |
| 224 | XGL_UINT clearColor[4] = {64, 64, 64, 0}; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 225 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
| 226 | for (i = 0; i < m_renderTargetCount; i++) { |
| 227 | transitionToClear.image = m_renderTargets[i]->image(); |
| 228 | transitionToClear.oldState = m_renderTargets[i]->state(); |
| 229 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 230 | transitionToClear.subresourceRange = srRange; |
| 231 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear ); |
| 232 | m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
| 233 | |
| 234 | xglCmdClearColorImageRaw( m_cmdBuffer, m_renderTargets[i]->image(), clearColor, 1, &srRange ); |
| 235 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 236 | |
| 237 | // prepare back buffer for rendering |
| 238 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 239 | for (i = 0; i < m_renderTargetCount; i++) { |
| 240 | transitionToRender.image = m_renderTargets[i]->image(); |
| 241 | transitionToRender.oldState = m_renderTargets[i]->state(); |
| 242 | transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 243 | transitionToRender.subresourceRange = srRange; |
| 244 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender ); |
| 245 | m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
| 246 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 247 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 248 | |
Chia-I Wu | fb1459b | 2014-12-29 15:23:20 +0800 | [diff] [blame^] | 249 | XglDevice::XglDevice(XGL_UINT id, XGL_PHYSICAL_GPU obj) : |
| 250 | xgl_testing::Device(obj), id(id) |
| 251 | { |
| 252 | init(); |
| 253 | |
| 254 | props = gpu().properties(); |
| 255 | queue_props = &gpu().queue_properties()[0]; |
| 256 | } |
| 257 | |
| 258 | void XglDevice::get_device_queue() |
| 259 | { |
| 260 | ASSERT_NE(true, graphics_queues().empty()); |
| 261 | m_queue = graphics_queues()[0]->obj(); |
| 262 | } |
| 263 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 264 | XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device) |
| 265 | { |
| 266 | m_device = device; |
| 267 | m_nextSlot = 0; |
| 268 | |
| 269 | } |
| 270 | |
| 271 | void XglDescriptorSetObj::AttachMemoryView(XglConstantBufferObj *constantBuffer) |
| 272 | { |
| 273 | m_memoryViews.push_back(&constantBuffer->m_constantBufferView); |
| 274 | m_memorySlots.push_back(m_nextSlot); |
| 275 | m_nextSlot++; |
| 276 | |
| 277 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 278 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 279 | void XglDescriptorSetObj::AttachSampler(XglSamplerObj *sampler) |
| 280 | { |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 281 | m_samplers.push_back(sampler); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 282 | m_samplerSlots.push_back(m_nextSlot); |
| 283 | m_nextSlot++; |
| 284 | |
| 285 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 286 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 287 | void XglDescriptorSetObj::AttachImageView(XglTextureObj *texture) |
| 288 | { |
| 289 | m_imageViews.push_back(&texture->m_textureViewInfo); |
| 290 | m_imageSlots.push_back(m_nextSlot); |
| 291 | m_nextSlot++; |
| 292 | |
| 293 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 294 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 295 | XGL_DESCRIPTOR_SLOT_INFO* XglDescriptorSetObj::GetSlotInfo(vector<int>slots, |
| 296 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types, |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 297 | vector<void *>objs ) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 298 | { |
| 299 | int nSlots = m_memorySlots.size() + m_imageSlots.size() + m_samplerSlots.size(); |
| 300 | m_slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( nSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 301 | memset(m_slotInfo,0,nSlots*sizeof(XGL_DESCRIPTOR_SLOT_INFO)); |
| 302 | |
| 303 | for (int i=0; i<nSlots; i++) |
| 304 | { |
| 305 | m_slotInfo[i].slotObjectType = XGL_SLOT_UNUSED; |
| 306 | } |
| 307 | |
| 308 | for (int i=0; i<slots.size(); i++) |
| 309 | { |
| 310 | for (int j=0; j<m_memorySlots.size(); j++) |
| 311 | { |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 312 | if ( m_memoryViews[j] == objs[i]) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 313 | { |
| 314 | m_slotInfo[m_memorySlots[j]].shaderEntityIndex = slots[i]; |
| 315 | m_slotInfo[m_memorySlots[j]].slotObjectType = types[i]; |
| 316 | } |
| 317 | } |
| 318 | for (int j=0; j<m_imageSlots.size(); j++) |
| 319 | { |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 320 | if ( m_imageViews[j] == objs[i]) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 321 | { |
| 322 | m_slotInfo[m_imageSlots[j]].shaderEntityIndex = slots[i]; |
| 323 | m_slotInfo[m_imageSlots[j]].slotObjectType = types[i]; |
| 324 | } |
| 325 | } |
| 326 | for (int j=0; j<m_samplerSlots.size(); j++) |
| 327 | { |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 328 | if ( m_samplers[j] == objs[i]) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 329 | { |
| 330 | m_slotInfo[m_samplerSlots[j]].shaderEntityIndex = slots[i]; |
| 331 | m_slotInfo[m_samplerSlots[j]].slotObjectType = types[i]; |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | // for (int i=0;i<nSlots;i++) |
| 337 | // { |
| 338 | // printf("SlotInfo[%d]: Index = %d, Type = %d\n",i,m_slotInfo[i].shaderEntityIndex, m_slotInfo[i].slotObjectType); |
| 339 | // fflush(stdout); |
| 340 | // } |
| 341 | |
| 342 | return(m_slotInfo); |
| 343 | |
| 344 | } |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 345 | void XglDescriptorSetObj::CreateXGLDescriptorSet() |
| 346 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 347 | init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot)); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 348 | |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 349 | begin(); |
| 350 | clear(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 351 | |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 352 | for (int i=0; i<m_memoryViews.size();i++) |
| 353 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 354 | attach(m_memorySlots[i], *m_memoryViews[i]); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 355 | } |
| 356 | for (int i=0; i<m_samplers.size();i++) |
| 357 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 358 | attach(m_samplerSlots[i], *m_samplers[i]); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 359 | } |
| 360 | for (int i=0; i<m_imageViews.size();i++) |
| 361 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 362 | attach(m_imageSlots[i], *m_imageViews[i]); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 363 | } |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 364 | |
| 365 | end(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle() |
| 369 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 370 | return obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 371 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 372 | |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 373 | int XglDescriptorSetObj::GetTotalSlots() |
| 374 | { |
| 375 | return m_nextSlot; |
| 376 | } |
| 377 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 378 | void XglDescriptorSetObj::BindCommandBuffer(XGL_CMD_BUFFER commandBuffer) |
| 379 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 380 | init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 381 | |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 382 | begin(); |
| 383 | clear(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 384 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 385 | for (int i=0; i<m_memoryViews.size();i++) |
| 386 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 387 | attach(m_memorySlots[i], *m_memoryViews[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 388 | } |
| 389 | for (int i=0; i<m_samplers.size();i++) |
| 390 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 391 | attach(m_samplerSlots[i], *m_samplers[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 392 | } |
| 393 | for (int i=0; i<m_imageViews.size();i++) |
| 394 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 395 | attach(m_imageSlots[i], *m_imageViews[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 396 | } |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 397 | |
| 398 | end(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 399 | |
| 400 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view) |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 401 | xglCmdBindDescriptorSet(commandBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, obj(), 0 ); |
Tony Barbour | 25ef8a6 | 2014-12-03 13:59:18 -0700 | [diff] [blame] | 402 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 403 | |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 404 | XglImage::XglImage(XglDevice *dev) |
| 405 | { |
| 406 | m_device = dev; |
| 407 | m_imageInfo.view = XGL_NULL_HANDLE; |
| 408 | m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET; |
| 409 | } |
| 410 | |
| 411 | void XglImage::init(XGL_UINT32 w, XGL_UINT32 h, |
| 412 | XGL_FORMAT fmt, XGL_FLAGS usage, |
| 413 | XGL_IMAGE_TILING tiling) |
| 414 | { |
| 415 | XGL_UINT mipCount; |
| 416 | |
| 417 | mipCount = 0; |
| 418 | |
| 419 | XGL_UINT _w = w; |
| 420 | XGL_UINT _h = h; |
| 421 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 422 | { |
| 423 | _w >>= 1; |
| 424 | _h >>= 1; |
| 425 | mipCount++; |
| 426 | } |
| 427 | |
| 428 | XGL_IMAGE_CREATE_INFO imageCreateInfo = xgl_testing::Image::create_info(); |
| 429 | imageCreateInfo.imageType = XGL_IMAGE_2D; |
| 430 | imageCreateInfo.format = fmt; |
| 431 | imageCreateInfo.extent.width = w; |
| 432 | imageCreateInfo.extent.height = h; |
| 433 | imageCreateInfo.mipLevels = mipCount; |
| 434 | imageCreateInfo.tiling = tiling; |
| 435 | |
| 436 | imageCreateInfo.usage = usage; |
| 437 | |
| 438 | xgl_testing::Image::init(*m_device, imageCreateInfo); |
| 439 | |
| 440 | m_imageInfo.state = XGL_IMAGE_STATE_UNINITIALIZED_TARGET; |
| 441 | |
| 442 | XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO createView = { |
| 443 | XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO, |
| 444 | XGL_NULL_HANDLE, |
| 445 | obj(), |
| 446 | {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, |
| 447 | 0, |
| 448 | 0, |
| 449 | 1 |
| 450 | }; |
| 451 | |
| 452 | m_targetView.init(*m_device, createView); |
| 453 | } |
| 454 | |
| 455 | XGL_RESULT XglImage::MapMemory(XGL_VOID** ptr) |
| 456 | { |
| 457 | *ptr = map(); |
| 458 | return (*ptr) ? XGL_SUCCESS : XGL_ERROR_UNKNOWN; |
| 459 | } |
| 460 | |
| 461 | XGL_RESULT XglImage::UnmapMemory() |
| 462 | { |
| 463 | unmap(); |
| 464 | return XGL_SUCCESS; |
| 465 | } |
| 466 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 467 | XglTextureObj::XglTextureObj(XglDevice *device) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 468 | { |
| 469 | m_device = device; |
| 470 | const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM }; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 471 | const uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 }; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 472 | |
| 473 | memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo)); |
| 474 | |
| 475 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 476 | |
| 477 | const XGL_IMAGE_CREATE_INFO image = { |
| 478 | .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 479 | .pNext = NULL, |
| 480 | .imageType = XGL_IMAGE_2D, |
| 481 | .format = tex_format, |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 482 | .extent = { 16, 16, 1 }, |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 483 | .mipLevels = 1, |
| 484 | .arraySize = 1, |
| 485 | .samples = 1, |
| 486 | .tiling = XGL_LINEAR_TILING, |
| 487 | .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT, |
| 488 | .flags = 0, |
| 489 | }; |
| 490 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 491 | XGL_IMAGE_VIEW_CREATE_INFO view; |
| 492 | view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 493 | view.pNext = NULL; |
| 494 | view.image = XGL_NULL_HANDLE; |
| 495 | view.viewType = XGL_IMAGE_VIEW_2D; |
| 496 | view.format = image.format; |
| 497 | view.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 498 | view.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 499 | view.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 500 | view.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 501 | view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 502 | view.subresourceRange.baseMipLevel = 0; |
| 503 | view.subresourceRange.mipLevels = 1; |
| 504 | view.subresourceRange.baseArraySlice = 0; |
| 505 | view.subresourceRange.arraySize = 1; |
| 506 | view.minLod = 0.0f; |
| 507 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 508 | /* create image */ |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 509 | init(*m_device, image); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 510 | |
| 511 | /* create image view */ |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 512 | view.image = obj(); |
| 513 | m_textureView.init(*m_device, view); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 514 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 515 | XGL_SUBRESOURCE_LAYOUT layout = |
| 516 | subresource_layout(subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0)); |
| 517 | m_rowPitch = layout.rowPitch; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 518 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 519 | XGL_VOID *data; |
| 520 | XGL_INT x, y; |
| 521 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 522 | data = map(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 523 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 524 | for (y = 0; y < extent().height; y++) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 525 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 526 | for (x = 0; x < extent().width; x++) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 527 | row[x] = tex_colors[(x & 1) ^ (y & 1)]; |
| 528 | } |
| 529 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 530 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 531 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 532 | m_textureViewInfo.view = m_textureView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 533 | |
| 534 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 535 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 536 | void XglTextureObj::ChangeColors(uint32_t color1, uint32_t color2) |
| 537 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 538 | const uint32_t tex_colors[2] = { color1, color2 }; |
| 539 | XGL_VOID *data; |
| 540 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 541 | data = map(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 542 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 543 | for (int y = 0; y < extent().height; y++) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 544 | uint32_t *row = (uint32_t *) ((char *) data + m_rowPitch * y); |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 545 | for (int x = 0; x < extent().width; x++) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 546 | row[x] = tex_colors[(x & 1) ^ (y & 1)]; |
| 547 | } |
| 548 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 549 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | XglSamplerObj::XglSamplerObj(XglDevice *device) |
| 553 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 554 | m_device = device; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 555 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 556 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo; |
| 557 | memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo)); |
| 558 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 559 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 560 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 561 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 562 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 563 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 564 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 565 | samplerCreateInfo.mipLodBias = 0.0; |
| 566 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 567 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 568 | samplerCreateInfo.minLod = 0.0; |
| 569 | samplerCreateInfo.maxLod = 0.0; |
| 570 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 571 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 572 | init(*m_device, samplerCreateInfo); |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 573 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 574 | |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 575 | /* |
| 576 | * Basic ConstantBuffer constructor. Then use create methods to fill in the details. |
| 577 | */ |
| 578 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device) |
| 579 | { |
| 580 | m_device = device; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 581 | m_commandBuffer = 0; |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 582 | |
| 583 | memset(&m_constantBufferView,0,sizeof(m_constantBufferView)); |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 586 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data) |
| 587 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 588 | m_device = device; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 589 | m_commandBuffer = 0; |
| 590 | |
| 591 | memset(&m_constantBufferView,0,sizeof(m_constantBufferView)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 592 | m_numVertices = constantCount; |
| 593 | m_stride = constantSize; |
| 594 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 595 | const size_t allocationSize = constantCount * constantSize; |
| 596 | init(*m_device, allocationSize); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 597 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 598 | void *pData = map(); |
| 599 | memcpy(pData, data, allocationSize); |
| 600 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 601 | |
| 602 | // set up the memory view for the constant buffer |
| 603 | this->m_constantBufferView.stride = 16; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 604 | this->m_constantBufferView.range = allocationSize; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 605 | this->m_constantBufferView.offset = 0; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 606 | this->m_constantBufferView.mem = obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 607 | this->m_constantBufferView.format.channelFormat = XGL_CH_FMT_R32G32B32A32; |
| 608 | this->m_constantBufferView.format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 609 | this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 610 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 611 | |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 612 | void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding) |
| 613 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 614 | xglCmdBindVertexData(cmdBuffer, obj(), offset, binding); |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 618 | void XglConstantBufferObj::SetMemoryState(XGL_MEMORY_STATE newState) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 619 | { |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 620 | XGL_RESULT err = XGL_SUCCESS; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 621 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 622 | if (this->m_constantBufferView.state == newState) |
| 623 | return; |
| 624 | |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 625 | if (!m_commandBuffer) |
| 626 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 627 | m_fence.init(*m_device, xgl_testing::Fence::create_info(0)); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 628 | |
| 629 | m_commandBuffer = new XglCommandBufferObj(m_device); |
| 630 | |
| 631 | } |
| 632 | else |
| 633 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 634 | m_device->wait(m_fence); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 637 | // open the command buffer |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 638 | err = m_commandBuffer->BeginCommandBuffer(0); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 639 | ASSERT_XGL_SUCCESS(err); |
| 640 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 641 | XGL_MEMORY_STATE_TRANSITION transition = |
| 642 | state_transition(XGL_MEMORY_STATE_DATA_TRANSFER, newState, 0, m_numVertices * m_stride); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 643 | |
| 644 | // write transition to the command buffer |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 645 | m_commandBuffer->PrepareMemoryRegions(1, &transition); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 646 | this->m_constantBufferView.state = newState; |
| 647 | |
| 648 | // finish recording the command buffer |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 649 | err = m_commandBuffer->EndCommandBuffer(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 650 | ASSERT_XGL_SUCCESS(err); |
| 651 | |
| 652 | XGL_UINT32 numMemRefs=1; |
| 653 | XGL_MEMORY_REF memRefs; |
| 654 | // this command buffer only uses the vertex buffer memory |
| 655 | memRefs.flags = 0; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 656 | memRefs.mem = obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 657 | |
| 658 | // submit the command buffer to the universal queue |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 659 | XGL_CMD_BUFFER bufferArray[1]; |
| 660 | bufferArray[0] = m_commandBuffer->GetBufferHandle(); |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 661 | err = xglQueueSubmit( m_device->m_queue, 1, bufferArray, numMemRefs, &memRefs, m_fence.obj() ); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 662 | ASSERT_XGL_SUCCESS(err); |
| 663 | } |
| 664 | |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 665 | XglIndexBufferObj::XglIndexBufferObj(XglDevice *device) |
| 666 | : XglConstantBufferObj(device) |
| 667 | { |
| 668 | |
| 669 | } |
| 670 | |
| 671 | void XglIndexBufferObj::CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE indexType, const void* data) |
| 672 | { |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 673 | XGL_FORMAT viewFormat; |
| 674 | |
| 675 | m_numVertices = numIndexes; |
| 676 | m_indexType = indexType; |
| 677 | viewFormat.numericFormat = XGL_NUM_FMT_UINT; |
| 678 | switch (indexType) { |
| 679 | case XGL_INDEX_8: |
| 680 | m_stride = 1; |
| 681 | viewFormat.channelFormat = XGL_CH_FMT_R8; |
| 682 | break; |
| 683 | case XGL_INDEX_16: |
| 684 | m_stride = 2; |
| 685 | viewFormat.channelFormat = XGL_CH_FMT_R16; |
| 686 | break; |
| 687 | case XGL_INDEX_32: |
| 688 | m_stride = 4; |
| 689 | viewFormat.channelFormat = XGL_CH_FMT_R32; |
| 690 | break; |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 691 | default: |
| 692 | assert(!"unknown index type"); |
| 693 | break; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 696 | const size_t allocationSize = numIndexes * m_stride; |
| 697 | init(*m_device, allocationSize); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 698 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 699 | void *pData = map(); |
| 700 | memcpy(pData, data, allocationSize); |
| 701 | unmap(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 702 | |
| 703 | // set up the memory view for the constant buffer |
| 704 | this->m_constantBufferView.stride = m_stride; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 705 | this->m_constantBufferView.range = allocationSize; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 706 | this->m_constantBufferView.offset = 0; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 707 | this->m_constantBufferView.mem = obj(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 708 | this->m_constantBufferView.format.channelFormat = viewFormat.channelFormat; |
| 709 | this->m_constantBufferView.format.numericFormat = viewFormat.numericFormat; |
| 710 | this->m_constantBufferView.state = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 711 | } |
| 712 | |
| 713 | void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset) |
| 714 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 715 | xglCmdBindIndexData(cmdBuffer, obj(), offset, m_indexType); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 716 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 717 | |
Tony Barbour | af1f919 | 2014-12-17 10:57:58 -0700 | [diff] [blame] | 718 | XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType() |
| 719 | { |
| 720 | return m_indexType; |
| 721 | } |
| 722 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 723 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo(XglDescriptorSetObj *descriptorSet) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 724 | { |
| 725 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo; |
| 726 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) ); |
| 727 | stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 728 | stageInfo->shader.stage = m_stage; |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 729 | stageInfo->shader.shader = obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 730 | stageInfo->shader.descriptorSetMapping[0].descriptorCount = 0; |
| 731 | stageInfo->shader.linkConstBufferCount = 0; |
| 732 | stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 733 | stageInfo->shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 734 | stageInfo->shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 735 | |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 736 | stageInfo->shader.descriptorSetMapping[0].descriptorCount = descriptorSet->GetTotalSlots(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 737 | if (stageInfo->shader.descriptorSetMapping[0].descriptorCount) |
| 738 | { |
| 739 | vector<int> allSlots; |
| 740 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> allTypes; |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 741 | vector<void *> allObjs; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 742 | |
| 743 | allSlots.reserve(m_memSlots.size() + m_imageSlots.size() + m_samplerSlots.size()); |
| 744 | allTypes.reserve(m_memTypes.size() + m_imageTypes.size() + m_samplerTypes.size()); |
| 745 | allObjs.reserve(m_memObjs.size() + m_imageObjs.size() + m_samplerObjs.size()); |
| 746 | |
| 747 | if (m_memSlots.size()) |
| 748 | { |
| 749 | allSlots.insert(allSlots.end(), m_memSlots.begin(), m_memSlots.end()); |
| 750 | allTypes.insert(allTypes.end(), m_memTypes.begin(), m_memTypes.end()); |
| 751 | allObjs.insert(allObjs.end(), m_memObjs.begin(), m_memObjs.end()); |
| 752 | } |
| 753 | if (m_imageSlots.size()) |
| 754 | { |
| 755 | allSlots.insert(allSlots.end(), m_imageSlots.begin(), m_imageSlots.end()); |
| 756 | allTypes.insert(allTypes.end(), m_imageTypes.begin(), m_imageTypes.end()); |
| 757 | allObjs.insert(allObjs.end(), m_imageObjs.begin(), m_imageObjs.end()); |
| 758 | } |
| 759 | if (m_samplerSlots.size()) |
| 760 | { |
| 761 | allSlots.insert(allSlots.end(), m_samplerSlots.begin(), m_samplerSlots.end()); |
| 762 | allTypes.insert(allTypes.end(), m_samplerTypes.begin(), m_samplerTypes.end()); |
| 763 | allObjs.insert(allObjs.end(), m_samplerObjs.begin(), m_samplerObjs.end()); |
| 764 | } |
| 765 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 766 | slotInfo = descriptorSet->GetSlotInfo(allSlots, allTypes, allObjs); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 767 | stageInfo->shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 768 | } |
| 769 | return stageInfo; |
| 770 | } |
| 771 | |
| 772 | void XglShaderObj::BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer) |
| 773 | { |
| 774 | m_memSlots.push_back(slot); |
| 775 | m_memTypes.push_back(type); |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 776 | m_memObjs.push_back(&constantBuffer->m_constantBufferView); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 777 | |
| 778 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 779 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 780 | void XglShaderObj::BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture) |
| 781 | { |
| 782 | m_imageSlots.push_back(slot); |
| 783 | m_imageTypes.push_back(type); |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 784 | m_imageObjs.push_back(&texture->m_textureViewInfo); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 785 | |
| 786 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 787 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 788 | void XglShaderObj::BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler) |
| 789 | { |
| 790 | m_samplerSlots.push_back(slot); |
| 791 | m_samplerTypes.push_back(XGL_SLOT_SHADER_SAMPLER); |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 792 | m_samplerObjs.push_back(sampler); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 793 | |
| 794 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 795 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 796 | XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework) |
| 797 | { |
| 798 | XGL_RESULT err = XGL_SUCCESS; |
| 799 | std::vector<unsigned int> bil; |
| 800 | XGL_SHADER_CREATE_INFO createInfo; |
| 801 | size_t shader_len; |
| 802 | |
| 803 | m_stage = stage; |
| 804 | m_device = device; |
| 805 | |
| 806 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 807 | createInfo.pNext = NULL; |
| 808 | |
| 809 | if (!framework->m_use_bil) { |
| 810 | |
| 811 | shader_len = strlen(shader_code); |
| 812 | createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 813 | createInfo.pCode = malloc(createInfo.codeSize); |
| 814 | createInfo.flags = 0; |
| 815 | |
| 816 | /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */ |
| 817 | ((uint32_t *) createInfo.pCode)[0] = ICD_BIL_MAGIC; |
| 818 | ((uint32_t *) createInfo.pCode)[1] = 0; |
| 819 | ((uint32_t *) createInfo.pCode)[2] = stage; |
| 820 | memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1); |
| 821 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 822 | err = init_try(*m_device, createInfo); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | if (framework->m_use_bil || err) { |
| 826 | std::vector<unsigned int> bil; |
| 827 | err = XGL_SUCCESS; |
| 828 | |
| 829 | // Use Reference GLSL to BIL compiler |
| 830 | framework->GLSLtoBIL(stage, shader_code, bil); |
| 831 | createInfo.pCode = bil.data(); |
| 832 | createInfo.codeSize = bil.size() * sizeof(unsigned int); |
| 833 | createInfo.flags = 0; |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 834 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 835 | init(*m_device, createInfo); |
| 836 | } |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 837 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 838 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 839 | XglPipelineObj::XglPipelineObj(XglDevice *device) |
| 840 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 841 | m_device = device; |
| 842 | m_vi_state.attributeCount = m_vi_state.bindingCount = 0; |
| 843 | m_vertexBufferCount = 0; |
| 844 | |
| 845 | m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO; |
| 846 | m_ia_state.pNext = XGL_NULL_HANDLE; |
| 847 | m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST; |
| 848 | m_ia_state.disableVertexReuse = XGL_FALSE; |
| 849 | m_ia_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST; |
| 850 | m_ia_state.primitiveRestartEnable = XGL_FALSE; |
| 851 | m_ia_state.primitiveRestartIndex = 0; |
| 852 | |
| 853 | m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO; |
| 854 | m_rs_state.pNext = &m_ia_state; |
| 855 | m_rs_state.depthClipEnable = XGL_FALSE; |
| 856 | m_rs_state.rasterizerDiscardEnable = XGL_FALSE; |
| 857 | m_rs_state.pointSize = 1.0; |
| 858 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 859 | memset(&m_cb_state,0,sizeof(m_cb_state)); |
| 860 | m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO; |
| 861 | m_cb_state.pNext = &m_rs_state; |
| 862 | m_cb_state.alphaToCoverageEnable = XGL_FALSE; |
| 863 | m_cb_state.dualSourceBlendEnable = XGL_FALSE; |
| 864 | m_cb_state.logicOp = XGL_LOGIC_OP_COPY; |
| 865 | |
Chia-I Wu | 62bf1dc | 2014-12-05 11:12:13 +0800 | [diff] [blame] | 866 | m_cb_state.attachment[0].blendEnable = XGL_FALSE; |
| 867 | m_cb_state.attachment[0].format.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 868 | m_cb_state.attachment[0].format.numericFormat = XGL_NUM_FMT_UNORM; |
| 869 | m_cb_state.attachment[0].channelWriteMask = 0xF; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 870 | |
| 871 | m_db_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 872 | m_db_state.pNext = &m_cb_state, |
| 873 | m_db_state.format.channelFormat = XGL_CH_FMT_R32; |
| 874 | m_db_state.format.numericFormat = XGL_NUM_FMT_DS; |
| 875 | |
| 876 | |
| 877 | }; |
| 878 | |
| 879 | void XglPipelineObj::AddShader(XglShaderObj* shader) |
| 880 | { |
| 881 | m_shaderObjs.push_back(shader); |
| 882 | } |
| 883 | |
| 884 | void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count) |
| 885 | { |
| 886 | m_vi_state.pVertexAttributeDescriptions = vi_attrib; |
| 887 | m_vi_state.attributeCount = count; |
| 888 | } |
| 889 | |
| 890 | void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count) |
| 891 | { |
| 892 | m_vi_state.pVertexBindingDescriptions = vi_binding; |
| 893 | m_vi_state.bindingCount = count; |
| 894 | } |
| 895 | |
| 896 | void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding) |
| 897 | { |
| 898 | m_vertexBufferObjs.push_back(vertexDataBuffer); |
| 899 | m_vertexBufferBindings.push_back(binding); |
| 900 | m_vertexBufferCount++; |
| 901 | } |
| 902 | |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 903 | void XglPipelineObj::SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att) |
| 904 | { |
| 905 | m_cb_state.attachment[binding] = *att; |
| 906 | } |
| 907 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 908 | void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet) |
| 909 | { |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 910 | XGL_VOID* head_ptr = &m_db_state; |
| 911 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 912 | |
| 913 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
| 914 | |
| 915 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 916 | { |
| 917 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet); |
| 918 | shaderCreateInfo->pNext = head_ptr; |
| 919 | head_ptr = shaderCreateInfo; |
| 920 | } |
| 921 | |
| 922 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 923 | { |
| 924 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 925 | m_vi_state.pNext = head_ptr; |
| 926 | head_ptr = &m_vi_state; |
| 927 | } |
| 928 | |
| 929 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 930 | info.pNext = head_ptr; |
| 931 | info.flags = 0; |
| 932 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 933 | init(*m_device, info); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 934 | } |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 935 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 936 | XGL_PIPELINE XglPipelineObj::GetPipelineHandle() |
| 937 | { |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 938 | return obj(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 941 | void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 942 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 943 | XGL_VOID* head_ptr = &m_db_state; |
| 944 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 945 | |
| 946 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 947 | |
| 948 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 949 | { |
| 950 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet); |
| 951 | shaderCreateInfo->pNext = head_ptr; |
| 952 | head_ptr = shaderCreateInfo; |
| 953 | } |
| 954 | |
| 955 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 956 | { |
| 957 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 958 | m_vi_state.pNext = head_ptr; |
| 959 | head_ptr = &m_vi_state; |
| 960 | } |
| 961 | |
| 962 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 963 | info.pNext = head_ptr; |
| 964 | info.flags = 0; |
| 965 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 966 | init(*m_device, info); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 967 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 968 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, obj() ); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 969 | |
| 970 | |
| 971 | for (int i=0; i < m_vertexBufferCount; i++) |
| 972 | { |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 973 | m_vertexBufferObjs[i]->Bind(m_cmdBuffer, m_vertexBufferObjs[i]->m_constantBufferView.offset, m_vertexBufferBindings[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 974 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 975 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 976 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 977 | XglMemoryRefManager::XglMemoryRefManager() { |
| 978 | |
| 979 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 980 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 981 | void XglMemoryRefManager::AddMemoryRef(XglConstantBufferObj *constantBuffer) { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 982 | m_bufferObjs.push_back(constantBuffer->obj()); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 983 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 984 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 985 | void XglMemoryRefManager::AddMemoryRef(XglTextureObj *texture) { |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 986 | const std::vector<XGL_GPU_MEMORY> mems = texture->memories(); |
| 987 | if (!mems.empty()) |
| 988 | m_bufferObjs.push_back(mems[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 989 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 990 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 991 | XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() { |
| 992 | |
| 993 | XGL_MEMORY_REF *localRefs; |
| 994 | XGL_UINT32 numRefs=m_bufferObjs.size(); |
| 995 | |
| 996 | if (numRefs <= 0) |
| 997 | return NULL; |
| 998 | |
| 999 | localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) ); |
| 1000 | for (int i=0; i<numRefs; i++) |
| 1001 | { |
| 1002 | localRefs[i].flags = 0; |
Chia-I Wu | 283d7a6 | 2014-12-28 15:43:42 +0800 | [diff] [blame] | 1003 | localRefs[i].mem = m_bufferObjs[i]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1004 | } |
| 1005 | return localRefs; |
| 1006 | } |
| 1007 | int XglMemoryRefManager::GetNumRefs() { |
| 1008 | return m_bufferObjs.size(); |
| 1009 | } |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1010 | |
| 1011 | XglCommandBufferObj::XglCommandBufferObj(XglDevice *device) |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1012 | : xgl_testing::CmdBuffer(*device, xgl_testing::CmdBuffer::create_info(XGL_QUEUE_TYPE_GRAPHICS)) |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1013 | { |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1014 | m_device = device; |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1015 | m_renderTargetCount = 0; |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1016 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1017 | |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1018 | XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle() |
| 1019 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1020 | return obj(); |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1021 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1022 | |
| 1023 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_FLAGS flags) |
| 1024 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1025 | begin(flags); |
| 1026 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | XGL_RESULT XglCommandBufferObj::EndCommandBuffer() |
| 1030 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1031 | end(); |
| 1032 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | void XglCommandBufferObj::PrepareMemoryRegions(int transitionCount, XGL_MEMORY_STATE_TRANSITION *transitionPtr) |
| 1036 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1037 | xglCmdPrepareMemoryRegions(obj(), transitionCount, transitionPtr); |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1040 | void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage) |
| 1041 | { |
| 1042 | XGL_UINT i; |
| 1043 | |
| 1044 | // whatever we want to do, we do it to the whole buffer |
| 1045 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1046 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1047 | srRange.baseMipLevel = 0; |
| 1048 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1049 | srRange.baseArraySlice = 0; |
| 1050 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1051 | |
| 1052 | // clear the back buffer to dark grey |
| 1053 | XGL_UINT clearColor[4] = {64, 64, 64, 0}; |
| 1054 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
| 1055 | for (i = 0; i < m_renderTargetCount; i++) { |
| 1056 | transitionToClear.image = m_renderTargets[i]->image(); |
| 1057 | transitionToClear.oldState = m_renderTargets[i]->state(); |
| 1058 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 1059 | transitionToClear.subresourceRange = srRange; |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1060 | xglCmdPrepareImages( obj(), 1, &transitionToClear ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1061 | m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
| 1062 | |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1063 | xglCmdClearColorImageRaw( obj(), m_renderTargets[i]->image(), clearColor, 1, &srRange ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | if (depthStencilImage) |
| 1067 | { |
| 1068 | XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {}; |
| 1069 | dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 1070 | dsRange.baseMipLevel = 0; |
| 1071 | dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1072 | dsRange.baseArraySlice = 0; |
| 1073 | dsRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1074 | |
| 1075 | // prepare the depth buffer for clear |
| 1076 | memset(&transitionToClear,0,sizeof(transitionToClear)); |
| 1077 | transitionToClear.image = depthStencilImage; |
| 1078 | transitionToClear.oldState = depthStencilBinding->depthState; |
| 1079 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 1080 | transitionToClear.subresourceRange = dsRange; |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1081 | xglCmdPrepareImages( obj(), 1, &transitionToClear ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1082 | depthStencilBinding->depthState = transitionToClear.newState; |
| 1083 | |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1084 | xglCmdClearDepthStencil(obj(), depthStencilImage, 1.0f, 0, 1, &dsRange); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1085 | |
| 1086 | // prepare depth buffer for rendering |
| 1087 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
| 1088 | transitionToRender.image = depthStencilImage; |
| 1089 | transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR; |
| 1090 | transitionToRender.newState = depthStencilBinding->depthState; |
| 1091 | transitionToRender.subresourceRange = dsRange; |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1092 | xglCmdPrepareImages( obj(), 1, &transitionToRender ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1093 | depthStencilBinding->depthState = transitionToClear.newState; |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | void XglCommandBufferObj::BindAttachments(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding) |
| 1098 | { |
| 1099 | XGL_UINT i; |
| 1100 | XGL_COLOR_ATTACHMENT_BIND_INFO colorBindings[XGL_MAX_COLOR_ATTACHMENTS]; |
| 1101 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1102 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1103 | srRange.baseMipLevel = 0; |
| 1104 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1105 | srRange.baseArraySlice = 0; |
| 1106 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1107 | |
| 1108 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
| 1109 | for(i=0; i<m_renderTargetCount; i++) |
| 1110 | { |
| 1111 | transitionToRender.image = m_renderTargets[i]->image(); |
| 1112 | transitionToRender.oldState = m_renderTargets[i]->state(); |
| 1113 | transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 1114 | transitionToRender.subresourceRange = srRange; |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1115 | xglCmdPrepareImages(obj(), 1, &transitionToRender ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1116 | m_renderTargets[i]->state(( XGL_IMAGE_STATE ) transitionToRender.newState); |
| 1117 | } |
| 1118 | for (i = 0; i < m_renderTargetCount; i++) { |
| 1119 | colorBindings[i].view = m_renderTargets[i]->targetView(); |
| 1120 | colorBindings[i].colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 1121 | } |
| 1122 | if (depthStencilBinding) { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1123 | xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, depthStencilBinding ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1124 | } else { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1125 | xglCmdBindAttachments(obj(), m_renderTargetCount, colorBindings, XGL_NULL_HANDLE ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | void XglCommandBufferObj::BindState(XGL_RASTER_STATE_OBJECT stateRaster, XGL_VIEWPORT_STATE_OBJECT stateViewport, |
| 1130 | XGL_COLOR_BLEND_STATE_OBJECT colorBlend, XGL_DEPTH_STENCIL_STATE_OBJECT stateDepthStencil, |
| 1131 | XGL_MSAA_STATE_OBJECT stateMsaa) |
| 1132 | { |
| 1133 | // set all states |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1134 | xglCmdBindStateObject( obj(), XGL_STATE_BIND_RASTER, stateRaster ); |
| 1135 | xglCmdBindStateObject( obj(), XGL_STATE_BIND_VIEWPORT, stateViewport ); |
| 1136 | xglCmdBindStateObject( obj(), XGL_STATE_BIND_COLOR_BLEND, colorBlend); |
| 1137 | xglCmdBindStateObject( obj(), XGL_STATE_BIND_DEPTH_STENCIL, stateDepthStencil ); |
| 1138 | xglCmdBindStateObject( obj(), XGL_STATE_BIND_MSAA, stateMsaa ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget) |
| 1142 | { |
| 1143 | m_renderTargets.push_back(renderTarget); |
| 1144 | m_renderTargetCount++; |
| 1145 | } |
| 1146 | |
| 1147 | void XglCommandBufferObj::DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount) |
| 1148 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1149 | xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | void XglCommandBufferObj::Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount) |
| 1153 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1154 | xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs) |
| 1158 | { |
| 1159 | XGL_RESULT err = XGL_SUCCESS; |
| 1160 | |
| 1161 | // submit the command buffer to the universal queue |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1162 | err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1163 | ASSERT_XGL_SUCCESS( err ); |
| 1164 | |
| 1165 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1166 | ASSERT_XGL_SUCCESS( err ); |
| 1167 | |
| 1168 | // Wait for work to finish before cleaning up. |
| 1169 | xglDeviceWaitIdle(m_device->device()); |
| 1170 | |
| 1171 | } |
| 1172 | void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline) |
| 1173 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1174 | xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | void XglCommandBufferObj::BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet) |
| 1178 | { |
| 1179 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view) |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1180 | xglCmdBindDescriptorSet(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, descriptorSet, 0 ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1181 | } |
| 1182 | void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset) |
| 1183 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 1184 | xglCmdBindIndexData(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType()); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1185 | } |
| 1186 | void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding) |
| 1187 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 1188 | xglCmdBindVertexData(obj(), vertexBuffer->obj(), offset, binding); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1189 | } |