Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 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 | * Chia-I Wu <olv@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #include "dev.h" |
| 29 | #include "obj.h" |
| 30 | #include "buf.h" |
| 31 | |
| 32 | static void buf_destroy(struct intel_obj *obj) |
| 33 | { |
| 34 | struct intel_buf *buf = intel_buf_from_obj(obj); |
| 35 | |
| 36 | intel_buf_destroy(buf); |
| 37 | } |
| 38 | |
| 39 | static XGL_RESULT buf_get_info(struct intel_base *base, int type, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 40 | size_t *size, void *data) |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 41 | { |
| 42 | struct intel_buf *buf = intel_buf_from_base(base); |
| 43 | XGL_RESULT ret = XGL_SUCCESS; |
| 44 | |
| 45 | switch (type) { |
| 46 | case XGL_INFO_TYPE_MEMORY_REQUIREMENTS: |
| 47 | { |
| 48 | XGL_MEMORY_REQUIREMENTS *mem_req = data; |
| 49 | |
| 50 | *size = sizeof(XGL_MEMORY_REQUIREMENTS); |
| 51 | if (data == NULL) |
| 52 | return ret; |
| 53 | |
| 54 | /* |
| 55 | * From the Sandy Bridge PRM, volume 1 part 1, page 118: |
| 56 | * |
| 57 | * "For buffers, which have no inherent "height," padding |
| 58 | * requirements are different. A buffer must be padded to the |
| 59 | * next multiple of 256 array elements, with an additional 16 |
| 60 | * bytes added beyond that to account for the L1 cache line." |
| 61 | */ |
| 62 | mem_req->size = buf->size; |
| 63 | if (buf->usage & XGL_BUFFER_USAGE_SHADER_ACCESS_READ_BIT) |
| 64 | mem_req->size = u_align(mem_req->size, 256) + 16; |
| 65 | |
| 66 | mem_req->alignment = 4096; |
Jon Ashburn | d803133 | 2015-01-22 10:52:13 -0700 | [diff] [blame] | 67 | mem_req->memType = XGL_MEMORY_TYPE_BUFFER; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 68 | |
| 69 | } |
| 70 | break; |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 71 | case XGL_INFO_TYPE_BUFFER_MEMORY_REQUIREMENTS: |
| 72 | { |
| 73 | XGL_BUFFER_MEMORY_REQUIREMENTS *buf_req = data; |
| 74 | |
| 75 | *size = sizeof(XGL_BUFFER_MEMORY_REQUIREMENTS); |
| 76 | if (data == NULL) |
| 77 | return ret; |
| 78 | buf_req->usage = buf->usage; |
| 79 | } |
| 80 | break; |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 81 | default: |
| 82 | ret = intel_base_get_info(base, type, size, data); |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | XGL_RESULT intel_buf_create(struct intel_dev *dev, |
| 90 | const XGL_BUFFER_CREATE_INFO *info, |
| 91 | struct intel_buf **buf_ret) |
| 92 | { |
| 93 | struct intel_buf *buf; |
| 94 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 95 | buf = (struct intel_buf *) intel_base_create(&dev->base.handle, |
| 96 | sizeof(*buf), dev->base.dbg, XGL_DBG_OBJECT_BUFFER, info, 0); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 97 | if (!buf) |
| 98 | return XGL_ERROR_OUT_OF_MEMORY; |
| 99 | |
| 100 | buf->size = info->size; |
| 101 | buf->usage = info->usage; |
| 102 | |
| 103 | buf->obj.destroy = buf_destroy; |
| 104 | buf->obj.base.get_info = buf_get_info; |
| 105 | |
| 106 | *buf_ret = buf; |
| 107 | |
| 108 | return XGL_SUCCESS; |
| 109 | } |
| 110 | |
| 111 | void intel_buf_destroy(struct intel_buf *buf) |
| 112 | { |
| 113 | intel_base_destroy(&buf->obj.base); |
| 114 | } |
| 115 | |
| 116 | ICD_EXPORT XGL_RESULT XGLAPI xglCreateBuffer( |
| 117 | XGL_DEVICE device, |
| 118 | const XGL_BUFFER_CREATE_INFO* pCreateInfo, |
| 119 | XGL_BUFFER* pBuffer) |
| 120 | { |
| 121 | struct intel_dev *dev = intel_dev(device); |
| 122 | |
| 123 | return intel_buf_create(dev, pCreateInfo, (struct intel_buf **) pBuffer); |
| 124 | } |