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