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 ), |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 36 | m_width( 256.0 ), // default window width |
| 37 | m_height( 256.0 ) // default window height |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 38 | { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 39 | m_renderTargetCount = 1; |
| 40 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 41 | m_render_target_fmt.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 42 | m_render_target_fmt.numericFormat = XGL_NUM_FMT_UNORM; |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 43 | |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 44 | m_depthStencilBinding.view = XGL_NULL_HANDLE; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | XglRenderFramework::~XglRenderFramework() |
| 48 | { |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 49 | |
| 50 | } |
| 51 | |
| 52 | void XglRenderFramework::InitFramework() |
| 53 | { |
| 54 | XGL_RESULT err; |
| 55 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 56 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
Chia-I Wu | af11d92 | 2014-12-28 14:37:25 +0800 | [diff] [blame] | 57 | XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, objs); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 58 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | bf843b2 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 59 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 60 | |
| 61 | m_device = new XglDevice(0, objs[0]); |
| 62 | m_device->get_device_queue(); |
| 63 | } |
| 64 | |
| 65 | void XglRenderFramework::ShutdownFramework() |
| 66 | { |
| 67 | if (m_colorBlend) xglDestroyObject(m_colorBlend); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 68 | if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil); |
| 69 | if (m_stateRaster) xglDestroyObject(m_stateRaster); |
| 70 | if (m_cmdBuffer) xglDestroyObject(m_cmdBuffer); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 71 | |
| 72 | if (m_stateViewport) { |
| 73 | xglDestroyObject(m_stateViewport); |
| 74 | } |
| 75 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 76 | // reset the driver |
Chia-I Wu | b76e0fa | 2014-12-28 14:27:28 +0800 | [diff] [blame] | 77 | delete m_device; |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 78 | 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] | 79 | } |
| 80 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 81 | void XglRenderFramework::InitState() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 82 | { |
| 83 | XGL_RESULT err; |
| 84 | |
| 85 | m_render_target_fmt.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 86 | m_render_target_fmt.numericFormat = XGL_NUM_FMT_UNORM; |
| 87 | |
| 88 | // create a raster state (solid, back-face culling) |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 89 | XGL_DYNAMIC_RS_STATE_CREATE_INFO raster = {}; |
| 90 | raster.sType = XGL_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO; |
| 91 | raster.pointSize = 1.0; |
| 92 | |
| 93 | err = xglCreateDynamicRasterState( device(), &raster, &m_stateRaster ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 94 | ASSERT_XGL_SUCCESS(err); |
| 95 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 96 | XGL_DYNAMIC_CB_STATE_CREATE_INFO blend = {}; |
| 97 | blend.sType = XGL_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO; |
| 98 | err = xglCreateDynamicColorBlendState(device(), &blend, &m_colorBlend); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 99 | ASSERT_XGL_SUCCESS( err ); |
| 100 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 101 | XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {}; |
| 102 | depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 103 | depthStencil.minDepth = 0.f; |
| 104 | depthStencil.maxDepth = 1.f; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 105 | depthStencil.stencilFrontRef = 0; |
| 106 | depthStencil.stencilBackRef = 0; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 107 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 108 | err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 109 | ASSERT_XGL_SUCCESS( err ); |
| 110 | |
| 111 | XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {}; |
| 112 | |
| 113 | cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 114 | cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS; |
| 115 | err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer); |
| 116 | ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed"; |
| 117 | } |
| 118 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 119 | void XglRenderFramework::InitViewport(float width, float height) |
| 120 | { |
| 121 | XGL_RESULT err; |
| 122 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 123 | XGL_VIEWPORT viewport; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 124 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 125 | XGL_DYNAMIC_VP_STATE_CREATE_INFO viewportCreate = {}; |
| 126 | viewportCreate.sType = XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO; |
| 127 | viewportCreate.viewportCount = 1; |
| 128 | viewportCreate.scissorCount = 0; |
| 129 | viewport.originX = 0; |
| 130 | viewport.originY = 0; |
| 131 | viewport.width = 1.f * width; |
| 132 | viewport.height = 1.f * height; |
| 133 | viewport.minDepth = 0.f; |
| 134 | viewport.maxDepth = 1.f; |
| 135 | viewportCreate.pViewports = &viewport; |
| 136 | |
| 137 | err = xglCreateDynamicViewportState( device(), &viewportCreate, &m_stateViewport ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 138 | ASSERT_XGL_SUCCESS( err ); |
| 139 | m_width = width; |
| 140 | m_height = height; |
| 141 | } |
| 142 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 143 | void XglRenderFramework::InitViewport() |
| 144 | { |
| 145 | InitViewport(m_width, m_height); |
| 146 | } |
| 147 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 148 | void XglRenderFramework::InitRenderTarget() |
| 149 | { |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 150 | XGL_UINT i; |
| 151 | |
| 152 | for (i = 0; i < m_renderTargetCount; i++) { |
Chia-I Wu | f50ee21 | 2014-12-29 14:31:52 +0800 | [diff] [blame] | 153 | XglImage *img = new XglImage(m_device); |
| 154 | img->init(m_width, m_height, m_render_target_fmt, |
| 155 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 156 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 157 | m_colorBindings[i].view = img->targetView(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 158 | m_colorBindings[i].layout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 159 | m_renderTargets.push_back(img); |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 160 | } |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 161 | // Create Framebuffer and RenderPass with color attachments and any depth/stencil attachment |
| 162 | XGL_ATTACHMENT_LOAD_OP load_op = XGL_ATTACHMENT_LOAD_OP_LOAD; |
| 163 | XGL_ATTACHMENT_STORE_OP store_op = XGL_ATTACHMENT_STORE_OP_STORE; |
| 164 | XGL_DEPTH_STENCIL_BIND_INFO *dsBinding; |
| 165 | if (m_depthStencilBinding.view) |
| 166 | dsBinding = &m_depthStencilBinding; |
| 167 | else |
| 168 | dsBinding = NULL; |
| 169 | const XGL_FRAMEBUFFER_CREATE_INFO fb_info = { |
| 170 | .sType = XGL_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, |
| 171 | .pNext = NULL, |
| 172 | .colorAttachmentCount = m_renderTargetCount, |
| 173 | .pColorAttachments = m_colorBindings, |
| 174 | .pDepthStencilAttachment = dsBinding, |
| 175 | .sampleCount = 1, |
| 176 | }; |
| 177 | XGL_RENDER_PASS_CREATE_INFO rp_info; |
| 178 | memset(&rp_info, 0 , sizeof(rp_info)); |
| 179 | xglCreateFramebuffer(device(), &fb_info, &(rp_info.framebuffer)); |
| 180 | rp_info.sType = XGL_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 181 | rp_info.renderArea.extent.width = m_width; |
| 182 | rp_info.renderArea.extent.height = m_height; |
| 183 | rp_info.pColorLoadOps = &load_op; |
| 184 | rp_info.pColorStoreOps = &store_op; |
| 185 | rp_info.depthLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD; |
| 186 | rp_info.depthStoreOp = XGL_ATTACHMENT_STORE_OP_STORE; |
| 187 | rp_info.stencilLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD; |
| 188 | rp_info.stencilStoreOp = XGL_ATTACHMENT_STORE_OP_STORE; |
| 189 | xglCreateRenderPass(device(), &rp_info, &m_renderPass); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 190 | } |
| 191 | |
Chia-I Wu | fb1459b | 2014-12-29 15:23:20 +0800 | [diff] [blame] | 192 | XglDevice::XglDevice(XGL_UINT id, XGL_PHYSICAL_GPU obj) : |
| 193 | xgl_testing::Device(obj), id(id) |
| 194 | { |
| 195 | init(); |
| 196 | |
| 197 | props = gpu().properties(); |
| 198 | queue_props = &gpu().queue_properties()[0]; |
| 199 | } |
| 200 | |
| 201 | void XglDevice::get_device_queue() |
| 202 | { |
| 203 | ASSERT_NE(true, graphics_queues().empty()); |
| 204 | m_queue = graphics_queues()[0]->obj(); |
| 205 | } |
| 206 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 207 | XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device) |
| 208 | { |
| 209 | m_device = device; |
| 210 | m_nextSlot = 0; |
| 211 | |
| 212 | } |
| 213 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 214 | void XglDescriptorSetObj::AttachBufferView(XglConstantBufferObj *constantBuffer) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 215 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 216 | m_bufferViews.push_back(&constantBuffer->m_bufferViewInfo); |
| 217 | m_bufferSlots.push_back(m_nextSlot); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 218 | m_nextSlot++; |
| 219 | |
| 220 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 221 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 222 | void XglDescriptorSetObj::AttachSampler(XglSamplerObj *sampler) |
| 223 | { |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 224 | m_samplers.push_back(sampler); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 225 | m_samplerSlots.push_back(m_nextSlot); |
| 226 | m_nextSlot++; |
| 227 | |
| 228 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 229 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 230 | void XglDescriptorSetObj::AttachImageView(XglTextureObj *texture) |
| 231 | { |
| 232 | m_imageViews.push_back(&texture->m_textureViewInfo); |
| 233 | m_imageSlots.push_back(m_nextSlot); |
| 234 | m_nextSlot++; |
| 235 | |
| 236 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 237 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 238 | XGL_DESCRIPTOR_SLOT_INFO* XglDescriptorSetObj::GetSlotInfo(vector<int>slots, |
| 239 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types, |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 240 | vector<void *>objs ) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 241 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 242 | int nSlots = m_bufferSlots.size() + m_imageSlots.size() + m_samplerSlots.size(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 243 | m_slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( nSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 244 | memset(m_slotInfo,0,nSlots*sizeof(XGL_DESCRIPTOR_SLOT_INFO)); |
| 245 | |
| 246 | for (int i=0; i<nSlots; i++) |
| 247 | { |
| 248 | m_slotInfo[i].slotObjectType = XGL_SLOT_UNUSED; |
| 249 | } |
| 250 | |
| 251 | for (int i=0; i<slots.size(); i++) |
| 252 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 253 | for (int j=0; j<m_bufferSlots.size(); j++) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 254 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 255 | if ( m_bufferViews[j] == objs[i]) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 256 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 257 | m_slotInfo[m_bufferSlots[j]].shaderEntityIndex = slots[i]; |
| 258 | m_slotInfo[m_bufferSlots[j]].slotObjectType = types[i]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | for (int j=0; j<m_imageSlots.size(); j++) |
| 262 | { |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 263 | if ( m_imageViews[j] == objs[i]) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 264 | { |
| 265 | m_slotInfo[m_imageSlots[j]].shaderEntityIndex = slots[i]; |
| 266 | m_slotInfo[m_imageSlots[j]].slotObjectType = types[i]; |
| 267 | } |
| 268 | } |
| 269 | for (int j=0; j<m_samplerSlots.size(); j++) |
| 270 | { |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 271 | if ( m_samplers[j] == objs[i]) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 272 | { |
| 273 | m_slotInfo[m_samplerSlots[j]].shaderEntityIndex = slots[i]; |
| 274 | m_slotInfo[m_samplerSlots[j]].slotObjectType = types[i]; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // for (int i=0;i<nSlots;i++) |
| 280 | // { |
| 281 | // printf("SlotInfo[%d]: Index = %d, Type = %d\n",i,m_slotInfo[i].shaderEntityIndex, m_slotInfo[i].slotObjectType); |
| 282 | // fflush(stdout); |
| 283 | // } |
| 284 | |
| 285 | return(m_slotInfo); |
| 286 | |
| 287 | } |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 288 | void XglDescriptorSetObj::CreateXGLDescriptorSet() |
| 289 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 290 | init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot)); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 291 | |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 292 | begin(); |
| 293 | clear(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 294 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 295 | for (int i=0; i<m_bufferViews.size();i++) |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 296 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 297 | attach(m_bufferSlots[i], *m_bufferViews[i]); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 298 | } |
| 299 | for (int i=0; i<m_samplers.size();i++) |
| 300 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 301 | attach(m_samplerSlots[i], *m_samplers[i]); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 302 | } |
| 303 | for (int i=0; i<m_imageViews.size();i++) |
| 304 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 305 | attach(m_imageSlots[i], *m_imageViews[i]); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 306 | } |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 307 | |
| 308 | end(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle() |
| 312 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 313 | return obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 314 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 315 | |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 316 | int XglDescriptorSetObj::GetTotalSlots() |
| 317 | { |
| 318 | return m_nextSlot; |
| 319 | } |
| 320 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 321 | void XglDescriptorSetObj::BindCommandBuffer(XGL_CMD_BUFFER commandBuffer) |
| 322 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 323 | init(*m_device, xgl_testing::DescriptorSet::create_info(m_nextSlot)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 324 | |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 325 | begin(); |
| 326 | clear(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 327 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 328 | for (int i=0; i<m_bufferViews.size();i++) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 329 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 330 | attach(m_bufferSlots[i], *m_bufferViews[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 331 | } |
| 332 | for (int i=0; i<m_samplers.size();i++) |
| 333 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 334 | attach(m_samplerSlots[i], *m_samplers[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 335 | } |
| 336 | for (int i=0; i<m_imageViews.size();i++) |
| 337 | { |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 338 | attach(m_imageSlots[i], *m_imageViews[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 339 | } |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 340 | |
| 341 | end(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 342 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 343 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view) |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 344 | xglCmdBindDescriptorSet(commandBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, obj(), 0 ); |
Tony Barbour | 25ef8a6 | 2014-12-03 13:59:18 -0700 | [diff] [blame] | 345 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 346 | |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 347 | XglImage::XglImage(XglDevice *dev) |
| 348 | { |
| 349 | m_device = dev; |
| 350 | m_imageInfo.view = XGL_NULL_HANDLE; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 351 | m_imageInfo.layout = XGL_IMAGE_LAYOUT_GENERAL; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void XglImage::init(XGL_UINT32 w, XGL_UINT32 h, |
| 355 | XGL_FORMAT fmt, XGL_FLAGS usage, |
| 356 | XGL_IMAGE_TILING tiling) |
| 357 | { |
| 358 | XGL_UINT mipCount; |
| 359 | |
| 360 | mipCount = 0; |
| 361 | |
| 362 | XGL_UINT _w = w; |
| 363 | XGL_UINT _h = h; |
| 364 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 365 | { |
| 366 | _w >>= 1; |
| 367 | _h >>= 1; |
| 368 | mipCount++; |
| 369 | } |
| 370 | |
| 371 | XGL_IMAGE_CREATE_INFO imageCreateInfo = xgl_testing::Image::create_info(); |
| 372 | imageCreateInfo.imageType = XGL_IMAGE_2D; |
| 373 | imageCreateInfo.format = fmt; |
| 374 | imageCreateInfo.extent.width = w; |
| 375 | imageCreateInfo.extent.height = h; |
| 376 | imageCreateInfo.mipLevels = mipCount; |
| 377 | imageCreateInfo.tiling = tiling; |
| 378 | |
| 379 | imageCreateInfo.usage = usage; |
| 380 | |
| 381 | xgl_testing::Image::init(*m_device, imageCreateInfo); |
| 382 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 383 | m_imageInfo.layout = XGL_IMAGE_LAYOUT_GENERAL; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 384 | |
| 385 | XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO createView = { |
| 386 | XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO, |
| 387 | XGL_NULL_HANDLE, |
| 388 | obj(), |
| 389 | {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, |
| 390 | 0, |
| 391 | 0, |
| 392 | 1 |
| 393 | }; |
| 394 | |
| 395 | m_targetView.init(*m_device, createView); |
| 396 | } |
| 397 | |
| 398 | XGL_RESULT XglImage::MapMemory(XGL_VOID** ptr) |
| 399 | { |
| 400 | *ptr = map(); |
| 401 | return (*ptr) ? XGL_SUCCESS : XGL_ERROR_UNKNOWN; |
| 402 | } |
| 403 | |
| 404 | XGL_RESULT XglImage::UnmapMemory() |
| 405 | { |
| 406 | unmap(); |
| 407 | return XGL_SUCCESS; |
| 408 | } |
| 409 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 410 | XglTextureObj::XglTextureObj(XglDevice *device) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 411 | { |
| 412 | m_device = device; |
| 413 | 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] | 414 | const uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 }; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 415 | |
| 416 | memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo)); |
| 417 | |
| 418 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 419 | |
| 420 | const XGL_IMAGE_CREATE_INFO image = { |
| 421 | .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 422 | .pNext = NULL, |
| 423 | .imageType = XGL_IMAGE_2D, |
| 424 | .format = tex_format, |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 425 | .extent = { 16, 16, 1 }, |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 426 | .mipLevels = 1, |
| 427 | .arraySize = 1, |
| 428 | .samples = 1, |
| 429 | .tiling = XGL_LINEAR_TILING, |
| 430 | .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT, |
| 431 | .flags = 0, |
| 432 | }; |
| 433 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 434 | XGL_IMAGE_VIEW_CREATE_INFO view; |
| 435 | view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 436 | view.pNext = NULL; |
| 437 | view.image = XGL_NULL_HANDLE; |
| 438 | view.viewType = XGL_IMAGE_VIEW_2D; |
| 439 | view.format = image.format; |
| 440 | view.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 441 | view.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 442 | view.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 443 | view.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 444 | view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 445 | view.subresourceRange.baseMipLevel = 0; |
| 446 | view.subresourceRange.mipLevels = 1; |
| 447 | view.subresourceRange.baseArraySlice = 0; |
| 448 | view.subresourceRange.arraySize = 1; |
| 449 | view.minLod = 0.0f; |
| 450 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 451 | /* create image */ |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 452 | init(*m_device, image); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 453 | |
| 454 | /* create image view */ |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 455 | view.image = obj(); |
| 456 | m_textureView.init(*m_device, view); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 457 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 458 | XGL_SUBRESOURCE_LAYOUT layout = |
| 459 | subresource_layout(subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0)); |
| 460 | m_rowPitch = layout.rowPitch; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 461 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 462 | XGL_VOID *data; |
| 463 | XGL_INT x, y; |
| 464 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 465 | data = map(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 466 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 467 | for (y = 0; y < extent().height; y++) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 468 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 469 | for (x = 0; x < extent().width; x++) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 470 | row[x] = tex_colors[(x & 1) ^ (y & 1)]; |
| 471 | } |
| 472 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 473 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 474 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 475 | m_textureViewInfo.view = m_textureView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 476 | |
| 477 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 478 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 479 | void XglTextureObj::ChangeColors(uint32_t color1, uint32_t color2) |
| 480 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 481 | const uint32_t tex_colors[2] = { color1, color2 }; |
| 482 | XGL_VOID *data; |
| 483 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 484 | data = map(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 485 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 486 | for (int y = 0; y < extent().height; y++) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 487 | uint32_t *row = (uint32_t *) ((char *) data + m_rowPitch * y); |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 488 | for (int x = 0; x < extent().width; x++) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 489 | row[x] = tex_colors[(x & 1) ^ (y & 1)]; |
| 490 | } |
| 491 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 492 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | XglSamplerObj::XglSamplerObj(XglDevice *device) |
| 496 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 497 | m_device = device; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 498 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 499 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo; |
| 500 | memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo)); |
| 501 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 502 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 503 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 504 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 505 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 506 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 507 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 508 | samplerCreateInfo.mipLodBias = 0.0; |
| 509 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 510 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 511 | samplerCreateInfo.minLod = 0.0; |
| 512 | samplerCreateInfo.maxLod = 0.0; |
| 513 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 514 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 515 | init(*m_device, samplerCreateInfo); |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 516 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 517 | |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 518 | /* |
| 519 | * Basic ConstantBuffer constructor. Then use create methods to fill in the details. |
| 520 | */ |
| 521 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device) |
| 522 | { |
| 523 | m_device = device; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 524 | m_commandBuffer = 0; |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 525 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 526 | memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo)); |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 529 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data) |
| 530 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 531 | m_device = device; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 532 | m_commandBuffer = 0; |
| 533 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 534 | memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 535 | m_numVertices = constantCount; |
| 536 | m_stride = constantSize; |
| 537 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 538 | const size_t allocationSize = constantCount * constantSize; |
| 539 | init(*m_device, allocationSize); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 540 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 541 | void *pData = map(); |
| 542 | memcpy(pData, data, allocationSize); |
| 543 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 544 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 545 | // set up the buffer view for the constant buffer |
| 546 | XGL_BUFFER_VIEW_CREATE_INFO view_info = {}; |
| 547 | view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 548 | view_info.buffer = obj(); |
Chia-I Wu | bb0c8d2 | 2015-01-16 22:31:25 +0800 | [diff] [blame^] | 549 | view_info.viewType = XGL_BUFFER_VIEW_RAW; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 550 | view_info.offset = 0; |
| 551 | view_info.range = allocationSize; |
| 552 | m_bufferView.init(*m_device, view_info); |
| 553 | |
| 554 | this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 555 | this->m_bufferViewInfo.view = m_bufferView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 556 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 557 | |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 558 | void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding) |
| 559 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 560 | xglCmdBindVertexBuffer(cmdBuffer, obj(), offset, binding); |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 564 | void XglConstantBufferObj::BufferMemoryBarrier( |
| 565 | XGL_FLAGS outputMask /*= |
| 566 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 567 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 568 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 569 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 570 | XGL_MEMORY_OUTPUT_COPY_BIT*/, |
| 571 | XGL_FLAGS inputMask /*= |
| 572 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 573 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 574 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 575 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 576 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 577 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 578 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 579 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 580 | XGL_MEMORY_INPUT_COPY_BIT*/) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 581 | { |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 582 | XGL_RESULT err = XGL_SUCCESS; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 583 | |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 584 | if (!m_commandBuffer) |
| 585 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 586 | m_fence.init(*m_device, xgl_testing::Fence::create_info(0)); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 587 | |
| 588 | m_commandBuffer = new XglCommandBufferObj(m_device); |
| 589 | |
| 590 | } |
| 591 | else |
| 592 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 593 | m_device->wait(m_fence); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 596 | // open the command buffer |
Jon Ashburn | c4164b1 | 2014-12-31 17:10:47 -0700 | [diff] [blame] | 597 | XGL_CMD_BUFFER_BEGIN_INFO cmd_buf_info = { |
| 598 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO, |
| 599 | .pNext = NULL, |
| 600 | .flags = 0, |
| 601 | }; |
| 602 | err = m_commandBuffer->BeginCommandBuffer(&cmd_buf_info); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 603 | ASSERT_XGL_SUCCESS(err); |
| 604 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 605 | XGL_BUFFER_MEMORY_BARRIER memory_barrier = |
| 606 | buffer_memory_barrier(outputMask, inputMask, 0, m_numVertices * m_stride); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 607 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 608 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 609 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 610 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 611 | pipeline_barrier.eventCount = 1; |
| 612 | pipeline_barrier.pEvents = set_events; |
| 613 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 614 | pipeline_barrier.memBarrierCount = 1; |
| 615 | pipeline_barrier.pMemBarriers = &memory_barrier; |
| 616 | |
| 617 | // write barrier to the command buffer |
| 618 | m_commandBuffer->PipelineBarrier(&pipeline_barrier); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 619 | |
| 620 | // finish recording the command buffer |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 621 | err = m_commandBuffer->EndCommandBuffer(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 622 | ASSERT_XGL_SUCCESS(err); |
| 623 | |
| 624 | XGL_UINT32 numMemRefs=1; |
| 625 | XGL_MEMORY_REF memRefs; |
| 626 | // this command buffer only uses the vertex buffer memory |
| 627 | memRefs.flags = 0; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 628 | memRefs.mem = memories()[0]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 629 | |
| 630 | // submit the command buffer to the universal queue |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 631 | XGL_CMD_BUFFER bufferArray[1]; |
| 632 | bufferArray[0] = m_commandBuffer->GetBufferHandle(); |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 633 | 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] | 634 | ASSERT_XGL_SUCCESS(err); |
| 635 | } |
| 636 | |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 637 | XglIndexBufferObj::XglIndexBufferObj(XglDevice *device) |
| 638 | : XglConstantBufferObj(device) |
| 639 | { |
| 640 | |
| 641 | } |
| 642 | |
| 643 | void XglIndexBufferObj::CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE indexType, const void* data) |
| 644 | { |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 645 | XGL_FORMAT viewFormat; |
| 646 | |
| 647 | m_numVertices = numIndexes; |
| 648 | m_indexType = indexType; |
| 649 | viewFormat.numericFormat = XGL_NUM_FMT_UINT; |
| 650 | switch (indexType) { |
| 651 | case XGL_INDEX_8: |
| 652 | m_stride = 1; |
| 653 | viewFormat.channelFormat = XGL_CH_FMT_R8; |
| 654 | break; |
| 655 | case XGL_INDEX_16: |
| 656 | m_stride = 2; |
| 657 | viewFormat.channelFormat = XGL_CH_FMT_R16; |
| 658 | break; |
| 659 | case XGL_INDEX_32: |
| 660 | m_stride = 4; |
| 661 | viewFormat.channelFormat = XGL_CH_FMT_R32; |
| 662 | break; |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 663 | default: |
| 664 | assert(!"unknown index type"); |
| 665 | break; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 668 | const size_t allocationSize = numIndexes * m_stride; |
| 669 | init(*m_device, allocationSize); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 670 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 671 | void *pData = map(); |
| 672 | memcpy(pData, data, allocationSize); |
| 673 | unmap(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 674 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 675 | // set up the buffer view for the constant buffer |
| 676 | XGL_BUFFER_VIEW_CREATE_INFO view_info = {}; |
| 677 | view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 678 | view_info.buffer = obj(); |
| 679 | view_info.viewType = XGL_BUFFER_VIEW_TYPED; |
| 680 | view_info.stride = m_stride; |
| 681 | view_info.format.channelFormat = viewFormat.channelFormat; |
| 682 | view_info.format.numericFormat = viewFormat.numericFormat; |
| 683 | view_info.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 684 | view_info.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 685 | view_info.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 686 | view_info.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 687 | view_info.offset = 0; |
| 688 | view_info.range = allocationSize; |
| 689 | m_bufferView.init(*m_device, view_info); |
| 690 | |
| 691 | this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 692 | this->m_bufferViewInfo.view = m_bufferView.obj(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset) |
| 696 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 697 | xglCmdBindIndexBuffer(cmdBuffer, obj(), offset, m_indexType); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 698 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 699 | |
Tony Barbour | af1f919 | 2014-12-17 10:57:58 -0700 | [diff] [blame] | 700 | XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType() |
| 701 | { |
| 702 | return m_indexType; |
| 703 | } |
| 704 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 705 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo(XglDescriptorSetObj *descriptorSet) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 706 | { |
| 707 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo; |
| 708 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) ); |
| 709 | stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 710 | stageInfo->shader.stage = m_stage; |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 711 | stageInfo->shader.shader = obj(); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 712 | stageInfo->shader.descriptorSetMappingCount = 1; |
| 713 | stageInfo->shader.pDescriptorSetMapping = (XGL_DESCRIPTOR_SET_MAPPING *)malloc(sizeof(XGL_DESCRIPTOR_SET_MAPPING)); |
| 714 | stageInfo->shader.pDescriptorSetMapping->descriptorCount = 0; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 715 | stageInfo->shader.linkConstBufferCount = 0; |
| 716 | stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 717 | stageInfo->shader.dynamicBufferViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 718 | stageInfo->shader.dynamicBufferViewMapping.shaderEntityIndex = 0; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 719 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 720 | stageInfo->shader.pDescriptorSetMapping->descriptorCount = descriptorSet->GetTotalSlots(); |
| 721 | if (stageInfo->shader.pDescriptorSetMapping->descriptorCount) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 722 | { |
| 723 | vector<int> allSlots; |
| 724 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> allTypes; |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 725 | vector<void *> allObjs; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 726 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 727 | allSlots.reserve(m_bufferSlots.size() + m_imageSlots.size() + m_samplerSlots.size()); |
| 728 | allTypes.reserve(m_bufferTypes.size() + m_imageTypes.size() + m_samplerTypes.size()); |
| 729 | allObjs.reserve(m_bufferObjs.size() + m_imageObjs.size() + m_samplerObjs.size()); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 730 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 731 | if (m_bufferSlots.size()) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 732 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 733 | allSlots.insert(allSlots.end(), m_bufferSlots.begin(), m_bufferSlots.end()); |
| 734 | allTypes.insert(allTypes.end(), m_bufferTypes.begin(), m_bufferTypes.end()); |
| 735 | allObjs.insert(allObjs.end(), m_bufferObjs.begin(), m_bufferObjs.end()); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 736 | } |
| 737 | if (m_imageSlots.size()) |
| 738 | { |
| 739 | allSlots.insert(allSlots.end(), m_imageSlots.begin(), m_imageSlots.end()); |
| 740 | allTypes.insert(allTypes.end(), m_imageTypes.begin(), m_imageTypes.end()); |
| 741 | allObjs.insert(allObjs.end(), m_imageObjs.begin(), m_imageObjs.end()); |
| 742 | } |
| 743 | if (m_samplerSlots.size()) |
| 744 | { |
| 745 | allSlots.insert(allSlots.end(), m_samplerSlots.begin(), m_samplerSlots.end()); |
| 746 | allTypes.insert(allTypes.end(), m_samplerTypes.begin(), m_samplerTypes.end()); |
| 747 | allObjs.insert(allObjs.end(), m_samplerObjs.begin(), m_samplerObjs.end()); |
| 748 | } |
| 749 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 750 | slotInfo = descriptorSet->GetSlotInfo(allSlots, allTypes, allObjs); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 751 | stageInfo->shader.pDescriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 752 | } |
| 753 | return stageInfo; |
| 754 | } |
| 755 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 756 | void XglShaderObj::BindShaderEntitySlotToBuffer(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 757 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 758 | m_bufferSlots.push_back(slot); |
| 759 | m_bufferTypes.push_back(type); |
| 760 | m_bufferObjs.push_back(&constantBuffer->m_bufferViewInfo); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 761 | |
| 762 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 763 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 764 | void XglShaderObj::BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture) |
| 765 | { |
| 766 | m_imageSlots.push_back(slot); |
| 767 | m_imageTypes.push_back(type); |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 768 | m_imageObjs.push_back(&texture->m_textureViewInfo); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 769 | |
| 770 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 771 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 772 | void XglShaderObj::BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler) |
| 773 | { |
| 774 | m_samplerSlots.push_back(slot); |
| 775 | m_samplerTypes.push_back(XGL_SLOT_SHADER_SAMPLER); |
Chia-I Wu | c86b54c | 2014-12-28 16:07:01 +0800 | [diff] [blame] | 776 | m_samplerObjs.push_back(sampler); |
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 | XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework) |
| 781 | { |
| 782 | XGL_RESULT err = XGL_SUCCESS; |
| 783 | std::vector<unsigned int> bil; |
| 784 | XGL_SHADER_CREATE_INFO createInfo; |
| 785 | size_t shader_len; |
| 786 | |
| 787 | m_stage = stage; |
| 788 | m_device = device; |
| 789 | |
| 790 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 791 | createInfo.pNext = NULL; |
| 792 | |
| 793 | if (!framework->m_use_bil) { |
| 794 | |
| 795 | shader_len = strlen(shader_code); |
| 796 | createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 797 | createInfo.pCode = malloc(createInfo.codeSize); |
| 798 | createInfo.flags = 0; |
| 799 | |
| 800 | /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */ |
| 801 | ((uint32_t *) createInfo.pCode)[0] = ICD_BIL_MAGIC; |
| 802 | ((uint32_t *) createInfo.pCode)[1] = 0; |
| 803 | ((uint32_t *) createInfo.pCode)[2] = stage; |
| 804 | memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1); |
| 805 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 806 | err = init_try(*m_device, createInfo); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | if (framework->m_use_bil || err) { |
| 810 | std::vector<unsigned int> bil; |
| 811 | err = XGL_SUCCESS; |
| 812 | |
| 813 | // Use Reference GLSL to BIL compiler |
| 814 | framework->GLSLtoBIL(stage, shader_code, bil); |
| 815 | createInfo.pCode = bil.data(); |
| 816 | createInfo.codeSize = bil.size() * sizeof(unsigned int); |
| 817 | createInfo.flags = 0; |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 818 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 819 | init(*m_device, createInfo); |
| 820 | } |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 821 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 822 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 823 | XglPipelineObj::XglPipelineObj(XglDevice *device) |
| 824 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 825 | m_device = device; |
| 826 | m_vi_state.attributeCount = m_vi_state.bindingCount = 0; |
| 827 | m_vertexBufferCount = 0; |
| 828 | |
| 829 | m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO; |
| 830 | m_ia_state.pNext = XGL_NULL_HANDLE; |
| 831 | m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST; |
| 832 | m_ia_state.disableVertexReuse = XGL_FALSE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 833 | m_ia_state.primitiveRestartEnable = XGL_FALSE; |
| 834 | m_ia_state.primitiveRestartIndex = 0; |
| 835 | |
| 836 | m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO; |
| 837 | m_rs_state.pNext = &m_ia_state; |
| 838 | m_rs_state.depthClipEnable = XGL_FALSE; |
| 839 | m_rs_state.rasterizerDiscardEnable = XGL_FALSE; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 840 | m_rs_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST; |
| 841 | m_rs_state.fillMode = XGL_FILL_SOLID; |
| 842 | m_rs_state.cullMode = XGL_CULL_NONE; |
| 843 | m_rs_state.frontFace = XGL_FRONT_FACE_CCW; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 844 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 845 | memset(&m_cb_state,0,sizeof(m_cb_state)); |
| 846 | m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO; |
| 847 | m_cb_state.pNext = &m_rs_state; |
| 848 | m_cb_state.alphaToCoverageEnable = XGL_FALSE; |
| 849 | m_cb_state.dualSourceBlendEnable = XGL_FALSE; |
| 850 | m_cb_state.logicOp = XGL_LOGIC_OP_COPY; |
| 851 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 852 | m_ms_state.pNext = &m_cb_state; |
| 853 | m_ms_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO; |
| 854 | m_ms_state.multisampleEnable = XGL_FALSE; |
| 855 | m_ms_state.sampleMask = 1; // Do we have to specify MSAA even just to disable it? |
| 856 | m_ms_state.samples = 1; |
| 857 | m_ms_state.minSampleShading = 0; |
| 858 | m_ms_state.sampleShadingEnable = 0; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 859 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 860 | m_ds_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO; |
| 861 | m_ds_state.pNext = &m_ms_state, |
| 862 | m_ds_state.format.channelFormat = XGL_CH_FMT_R32; |
| 863 | m_ds_state.format.numericFormat = XGL_NUM_FMT_DS; |
| 864 | m_ds_state.depthTestEnable = XGL_FALSE; |
| 865 | m_ds_state.depthWriteEnable = XGL_FALSE; |
| 866 | m_ds_state.depthBoundsEnable = XGL_FALSE; |
| 867 | m_ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 868 | m_ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 869 | m_ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 870 | m_ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 871 | m_ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 872 | m_ds_state.stencilTestEnable = XGL_FALSE; |
| 873 | m_ds_state.front = m_ds_state.back; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 874 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 875 | XGL_PIPELINE_CB_ATTACHMENT_STATE att = {}; |
| 876 | att.blendEnable = XGL_FALSE; |
| 877 | att.format.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 878 | att.format.numericFormat = XGL_NUM_FMT_UNORM; |
| 879 | att.channelWriteMask = 0xf; |
| 880 | AddColorAttachment(0, &att); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 881 | |
| 882 | }; |
| 883 | |
| 884 | void XglPipelineObj::AddShader(XglShaderObj* shader) |
| 885 | { |
| 886 | m_shaderObjs.push_back(shader); |
| 887 | } |
| 888 | |
| 889 | void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count) |
| 890 | { |
| 891 | m_vi_state.pVertexAttributeDescriptions = vi_attrib; |
| 892 | m_vi_state.attributeCount = count; |
| 893 | } |
| 894 | |
| 895 | void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count) |
| 896 | { |
| 897 | m_vi_state.pVertexBindingDescriptions = vi_binding; |
| 898 | m_vi_state.bindingCount = count; |
| 899 | } |
| 900 | |
| 901 | void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding) |
| 902 | { |
| 903 | m_vertexBufferObjs.push_back(vertexDataBuffer); |
| 904 | m_vertexBufferBindings.push_back(binding); |
| 905 | m_vertexBufferCount++; |
| 906 | } |
| 907 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 908 | void XglPipelineObj::AddColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att) |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 909 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 910 | if (binding+1 > m_colorAttachments.size()) |
| 911 | { |
| 912 | m_colorAttachments.resize(binding+1); |
| 913 | } |
| 914 | m_colorAttachments[binding] = *att; |
| 915 | } |
| 916 | |
| 917 | void XglPipelineObj::SetDepthStencil(XGL_PIPELINE_DS_STATE_CREATE_INFO *ds_state) |
| 918 | { |
| 919 | m_ds_state.format = ds_state->format; |
| 920 | m_ds_state.depthTestEnable = ds_state->depthTestEnable; |
| 921 | m_ds_state.depthWriteEnable = ds_state->depthWriteEnable; |
| 922 | m_ds_state.depthBoundsEnable = ds_state->depthBoundsEnable; |
| 923 | m_ds_state.depthFunc = ds_state->depthFunc; |
| 924 | m_ds_state.stencilTestEnable = ds_state->stencilTestEnable; |
| 925 | m_ds_state.back = ds_state->back; |
| 926 | m_ds_state.front = ds_state->front; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 927 | } |
| 928 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 929 | void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet) |
| 930 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 931 | XGL_VOID* head_ptr = &m_ds_state; |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 932 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 933 | |
| 934 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
| 935 | |
| 936 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 937 | { |
| 938 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet); |
| 939 | shaderCreateInfo->pNext = head_ptr; |
| 940 | head_ptr = shaderCreateInfo; |
| 941 | } |
| 942 | |
| 943 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 944 | { |
| 945 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 946 | m_vi_state.pNext = head_ptr; |
| 947 | head_ptr = &m_vi_state; |
| 948 | } |
| 949 | |
| 950 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 951 | info.pNext = head_ptr; |
| 952 | info.flags = 0; |
| 953 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 954 | m_cb_state.attachmentCount = m_colorAttachments.size(); |
| 955 | m_cb_state.pAttachments = &m_colorAttachments[0]; |
| 956 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 957 | init(*m_device, info); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 958 | } |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 959 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 960 | XGL_PIPELINE XglPipelineObj::GetPipelineHandle() |
| 961 | { |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 962 | return obj(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 965 | void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 966 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 967 | XGL_VOID* head_ptr = &m_ds_state; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 968 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 969 | |
| 970 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 971 | |
| 972 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 973 | { |
| 974 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(descriptorSet); |
| 975 | shaderCreateInfo->pNext = head_ptr; |
| 976 | head_ptr = shaderCreateInfo; |
| 977 | } |
| 978 | |
| 979 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 980 | { |
| 981 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 982 | m_vi_state.pNext = head_ptr; |
| 983 | head_ptr = &m_vi_state; |
| 984 | } |
| 985 | |
| 986 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 987 | info.pNext = head_ptr; |
| 988 | info.flags = 0; |
| 989 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 990 | init(*m_device, info); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 991 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 992 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, obj() ); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 993 | |
| 994 | |
| 995 | for (int i=0; i < m_vertexBufferCount; i++) |
| 996 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 997 | m_vertexBufferObjs[i]->Bind(m_cmdBuffer, 0, m_vertexBufferBindings[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 998 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 999 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1000 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1001 | XglMemoryRefManager::XglMemoryRefManager() { |
| 1002 | |
| 1003 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1004 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1005 | void XglMemoryRefManager::AddMemoryRef(XglConstantBufferObj *constantBuffer) { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1006 | const std::vector<XGL_GPU_MEMORY> mems = constantBuffer->memories(); |
| 1007 | if (!mems.empty()) |
| 1008 | m_bufferObjs.push_back(mems[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1009 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1010 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1011 | void XglMemoryRefManager::AddMemoryRef(XglTextureObj *texture) { |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 1012 | const std::vector<XGL_GPU_MEMORY> mems = texture->memories(); |
| 1013 | if (!mems.empty()) |
| 1014 | m_bufferObjs.push_back(mems[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1015 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1016 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1017 | XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() { |
| 1018 | |
| 1019 | XGL_MEMORY_REF *localRefs; |
| 1020 | XGL_UINT32 numRefs=m_bufferObjs.size(); |
| 1021 | |
| 1022 | if (numRefs <= 0) |
| 1023 | return NULL; |
| 1024 | |
| 1025 | localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) ); |
| 1026 | for (int i=0; i<numRefs; i++) |
| 1027 | { |
| 1028 | localRefs[i].flags = 0; |
Chia-I Wu | 283d7a6 | 2014-12-28 15:43:42 +0800 | [diff] [blame] | 1029 | localRefs[i].mem = m_bufferObjs[i]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1030 | } |
| 1031 | return localRefs; |
| 1032 | } |
| 1033 | int XglMemoryRefManager::GetNumRefs() { |
| 1034 | return m_bufferObjs.size(); |
| 1035 | } |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1036 | |
| 1037 | XglCommandBufferObj::XglCommandBufferObj(XglDevice *device) |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1038 | : 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] | 1039 | { |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1040 | m_device = device; |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1041 | m_renderTargetCount = 0; |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1042 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1043 | |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1044 | XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle() |
| 1045 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1046 | return obj(); |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1047 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1048 | |
Jon Ashburn | c4164b1 | 2014-12-31 17:10:47 -0700 | [diff] [blame] | 1049 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_CMD_BUFFER_BEGIN_INFO *pInfo) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1050 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1051 | begin(pInfo); |
| 1052 | return XGL_SUCCESS; |
| 1053 | } |
| 1054 | |
| 1055 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_RENDER_PASS renderpass_obj) |
| 1056 | { |
| 1057 | begin(renderpass_obj); |
| 1058 | return XGL_SUCCESS; |
| 1059 | } |
| 1060 | |
| 1061 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer() |
| 1062 | { |
| 1063 | begin(); |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1064 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | XGL_RESULT XglCommandBufferObj::EndCommandBuffer() |
| 1068 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1069 | end(); |
| 1070 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1073 | void XglCommandBufferObj::PipelineBarrier(XGL_PIPELINE_BARRIER *barrierPtr) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1074 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1075 | xglCmdPipelineBarrier(obj(), barrierPtr); |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1078 | void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage) |
| 1079 | { |
| 1080 | XGL_UINT i; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1081 | const XGL_FLAGS output_mask = |
| 1082 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1083 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1084 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1085 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1086 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1087 | const XGL_FLAGS input_mask = 0; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1088 | |
| 1089 | // whatever we want to do, we do it to the whole buffer |
| 1090 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1091 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1092 | srRange.baseMipLevel = 0; |
| 1093 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1094 | srRange.baseArraySlice = 0; |
| 1095 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1096 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1097 | XGL_IMAGE_MEMORY_BARRIER memory_barrier = {}; |
| 1098 | memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 1099 | memory_barrier.outputMask = output_mask; |
| 1100 | memory_barrier.inputMask = input_mask; |
| 1101 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1102 | memory_barrier.subresourceRange = srRange; |
| 1103 | |
| 1104 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1105 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1106 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1107 | pipeline_barrier.eventCount = 1; |
| 1108 | pipeline_barrier.pEvents = set_events; |
| 1109 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1110 | pipeline_barrier.memBarrierCount = 1; |
| 1111 | pipeline_barrier.pMemBarriers = &memory_barrier; |
| 1112 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1113 | // clear the back buffer to dark grey |
| 1114 | XGL_UINT clearColor[4] = {64, 64, 64, 0}; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1115 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1116 | for (i = 0; i < m_renderTargetCount; i++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1117 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1118 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
| 1119 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1120 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1121 | |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1122 | xglCmdClearColorImageRaw( obj(), m_renderTargets[i]->image(), clearColor, 1, &srRange ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | if (depthStencilImage) |
| 1126 | { |
| 1127 | XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {}; |
| 1128 | dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 1129 | dsRange.baseMipLevel = 0; |
| 1130 | dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1131 | dsRange.baseArraySlice = 0; |
| 1132 | dsRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1133 | |
| 1134 | // prepare the depth buffer for clear |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1135 | |
| 1136 | memory_barrier.oldLayout = depthStencilBinding->layout; |
| 1137 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1138 | memory_barrier.image = depthStencilImage; |
| 1139 | memory_barrier.subresourceRange = dsRange; |
| 1140 | |
| 1141 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1142 | depthStencilBinding->layout = memory_barrier.newLayout; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1143 | |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1144 | xglCmdClearDepthStencil(obj(), depthStencilImage, 1.0f, 0, 1, &dsRange); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1145 | |
| 1146 | // prepare depth buffer for rendering |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1147 | memory_barrier.image = depthStencilImage; |
| 1148 | memory_barrier.oldLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1149 | memory_barrier.newLayout = depthStencilBinding->layout; |
| 1150 | memory_barrier.subresourceRange = dsRange; |
| 1151 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1152 | depthStencilBinding->layout = memory_barrier.newLayout; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | |
Jon Ashburn | cdc40be | 2015-01-02 18:27:14 -0700 | [diff] [blame] | 1156 | void XglCommandBufferObj::PrepareAttachments() |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1157 | { |
| 1158 | XGL_UINT i; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1159 | const XGL_FLAGS output_mask = |
| 1160 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1161 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1162 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1163 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1164 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1165 | const XGL_FLAGS input_mask = |
| 1166 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 1167 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1168 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1169 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1170 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1171 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 1172 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1173 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1174 | XGL_MEMORY_INPUT_COPY_BIT; |
| 1175 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1176 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1177 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1178 | srRange.baseMipLevel = 0; |
| 1179 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1180 | srRange.baseArraySlice = 0; |
| 1181 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1182 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1183 | XGL_IMAGE_MEMORY_BARRIER memory_barrier = {}; |
| 1184 | memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 1185 | memory_barrier.outputMask = output_mask; |
| 1186 | memory_barrier.inputMask = input_mask; |
| 1187 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 1188 | memory_barrier.subresourceRange = srRange; |
| 1189 | |
| 1190 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1191 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1192 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1193 | pipeline_barrier.eventCount = 1; |
| 1194 | pipeline_barrier.pEvents = set_events; |
| 1195 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1196 | pipeline_barrier.memBarrierCount = 1; |
| 1197 | pipeline_barrier.pMemBarriers = &memory_barrier; |
| 1198 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1199 | for(i=0; i<m_renderTargetCount; i++) |
| 1200 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1201 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1202 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
| 1203 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1204 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1205 | } |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1208 | void XglCommandBufferObj::BindStateObject(XGL_STATE_BIND_POINT stateBindPoint, XGL_DYNAMIC_STATE_OBJECT stateObject) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1209 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1210 | xglCmdBindDynamicStateObject( obj(), stateBindPoint, stateObject); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget) |
| 1214 | { |
| 1215 | m_renderTargets.push_back(renderTarget); |
| 1216 | m_renderTargetCount++; |
| 1217 | } |
| 1218 | |
| 1219 | void XglCommandBufferObj::DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount) |
| 1220 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1221 | xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | void XglCommandBufferObj::Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount) |
| 1225 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1226 | xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs) |
| 1230 | { |
| 1231 | XGL_RESULT err = XGL_SUCCESS; |
| 1232 | |
| 1233 | // submit the command buffer to the universal queue |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1234 | err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1235 | ASSERT_XGL_SUCCESS( err ); |
| 1236 | |
| 1237 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1238 | ASSERT_XGL_SUCCESS( err ); |
| 1239 | |
| 1240 | // Wait for work to finish before cleaning up. |
| 1241 | xglDeviceWaitIdle(m_device->device()); |
| 1242 | |
| 1243 | } |
| 1244 | void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline) |
| 1245 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1246 | xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | void XglCommandBufferObj::BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet) |
| 1250 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1251 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view) |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1252 | xglCmdBindDescriptorSet(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, descriptorSet, 0 ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1253 | } |
| 1254 | void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset) |
| 1255 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1256 | xglCmdBindIndexBuffer(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType()); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1257 | } |
| 1258 | void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding) |
| 1259 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1260 | xglCmdBindVertexBuffer(obj(), vertexBuffer->obj(), offset, binding); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1261 | } |