blob: c4d1ee3b50277eedf7811a62653de30af5f4efac [file] [log] [blame]
Chia-I Wu4ea339e2014-08-08 21:56:26 +08001/*
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.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wu4ea339e2014-08-08 21:56:26 +080026 */
27
Chia-I Wue46da3e2014-08-08 21:52:48 +080028#include "kmd/winsys.h"
29#include "dev.h"
30#include "gpu.h"
31#include "img.h"
Chia-I Wu4ea339e2014-08-08 21:56:26 +080032
Chia-I Wu4ea339e2014-08-08 21:56:26 +080033/*
34 * From the Ivy Bridge PRM, volume 1 part 1, page 105:
35 *
36 * "In addition to restrictions on maximum height, width, and depth,
37 * surfaces are also restricted to a maximum size in bytes. This
38 * maximum is 2 GB for all products and all surface types."
39 */
Chia-I Wue46da3e2014-08-08 21:52:48 +080040static const size_t intel_max_resource_size = 1u << 31;
Chia-I Wu4ea339e2014-08-08 21:56:26 +080041
Chia-I Wufeb441f2014-08-08 21:27:38 +080042static void img_destroy(struct intel_obj *obj)
43{
44 struct intel_img *img = intel_img_from_obj(obj);
45
46 intel_img_destroy(img);
47}
48
49static XGL_RESULT img_get_info(struct intel_base *base, int type,
50 XGL_SIZE *size, XGL_VOID *data)
51{
52 struct intel_img *img = intel_img_from_base(base);
53 XGL_RESULT ret = XGL_SUCCESS;
54
55 switch (type) {
56 case XGL_INFO_TYPE_MEMORY_REQUIREMENTS:
57 {
58 XGL_MEMORY_REQUIREMENTS *mem_req = data;
59
Chia-I Wu9b752e12014-08-15 16:21:44 +080060 mem_req->size = img->total_size;
Chia-I Wufeb441f2014-08-08 21:27:38 +080061 mem_req->alignment = 4096;
62 mem_req->heapCount = 1;
63 mem_req->heaps[0] = 0;
64
65 *size = sizeof(*mem_req);
66 }
67 break;
68 default:
69 ret = intel_base_get_info(base, type, size, data);
70 break;
71 }
72
73 return ret;
74}
75
76XGL_RESULT intel_img_create(struct intel_dev *dev,
77 const XGL_IMAGE_CREATE_INFO *info,
78 struct intel_img **img_ret)
79{
Chia-I Wufeb441f2014-08-08 21:27:38 +080080 struct intel_img *img;
Chia-I Wu37cba152014-08-15 16:03:10 +080081 struct intel_layout *layout;
Chia-I Wufeb441f2014-08-08 21:27:38 +080082
Courtney Goeltzenleuchterfb4fb532014-08-14 09:35:21 -060083 img = (struct intel_img *) intel_base_create(dev, sizeof(*img),
Chia-I Wufeb441f2014-08-08 21:27:38 +080084 dev->base.dbg, XGL_DBG_OBJECT_IMAGE, info, 0);
85 if (!img)
86 return XGL_ERROR_OUT_OF_MEMORY;
87
Chia-I Wu37cba152014-08-15 16:03:10 +080088 layout = &img->layout;
89
Chia-I Wueb2da592014-08-16 14:19:39 +080090 img->type = info->imageType;
Chia-I Wu73e326f2014-08-21 11:07:57 +080091 img->depth = info->extent.depth;
Chia-I Wueb2da592014-08-16 14:19:39 +080092 img->array_size = info->arraySize;
93 img->samples = info->samples;
Chia-I Wu37cba152014-08-15 16:03:10 +080094 intel_layout_init(layout, dev, info);
95
96 if (layout->bo_stride > intel_max_resource_size / layout->bo_height) {
97 intel_dev_log(dev, XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0,
98 XGL_NULL_HANDLE, 0, 0, "image too big");
99 intel_img_destroy(img);
100 return XGL_ERROR_INVALID_MEMORY_SIZE;
101 }
Chia-I Wufeb441f2014-08-08 21:27:38 +0800102
Chia-I Wu9b752e12014-08-15 16:21:44 +0800103 img->total_size = img->layout.bo_stride * img->layout.bo_height;
104
Chia-I Wu457d0a62014-08-18 13:02:26 +0800105 if (layout->aux != INTEL_LAYOUT_AUX_NONE) {
Chia-I Wu9b752e12014-08-15 16:21:44 +0800106 img->aux_offset = u_align(img->total_size, 4096);
107 img->total_size = img->aux_offset +
108 layout->aux_stride * layout->aux_height;
109 }
110
111 if (layout->separate_stencil) {
112 XGL_IMAGE_CREATE_INFO s8_info;
113
114 img->s8_layout = icd_alloc(sizeof(*img->s8_layout), 0,
115 XGL_SYSTEM_ALLOC_INTERNAL);
116 if (!img->s8_layout) {
117 intel_img_destroy(img);
118 return XGL_ERROR_OUT_OF_MEMORY;
119 }
120
121 s8_info = *info;
122 s8_info.format.channelFormat = XGL_CH_FMT_R8;
123 assert(info->format.numericFormat == XGL_NUM_FMT_DS);
124
125 intel_layout_init(img->s8_layout, dev, &s8_info);
126
127 img->s8_offset = u_align(img->total_size, 4096);
128 img->total_size = img->s8_offset +
129 img->s8_layout->bo_stride * img->s8_layout->bo_height;
Chia-I Wufeb441f2014-08-08 21:27:38 +0800130 }
131
Chia-I Wufeb441f2014-08-08 21:27:38 +0800132 img->obj.destroy = img_destroy;
133 img->obj.base.get_info = img_get_info;
134
135 *img_ret = img;
136
137 return XGL_SUCCESS;
138}
139
140void intel_img_destroy(struct intel_img *img)
141{
Chia-I Wu9b752e12014-08-15 16:21:44 +0800142 if (img->s8_layout)
143 icd_free(img->s8_layout);
144
Chia-I Wufeb441f2014-08-08 21:27:38 +0800145 intel_base_destroy(&img->obj.base);
146}
147
Chia-I Wu251e7d92014-08-19 13:35:42 +0800148XGL_RESULT XGLAPI intelOpenPeerImage(
149 XGL_DEVICE device,
150 const XGL_PEER_IMAGE_OPEN_INFO* pOpenInfo,
151 XGL_IMAGE* pImage,
152 XGL_GPU_MEMORY* pMem)
153{
154 return XGL_ERROR_UNAVAILABLE;
155}
156
Chia-I Wufeb441f2014-08-08 21:27:38 +0800157XGL_RESULT XGLAPI intelCreateImage(
158 XGL_DEVICE device,
159 const XGL_IMAGE_CREATE_INFO* pCreateInfo,
160 XGL_IMAGE* pImage)
161{
162 struct intel_dev *dev = intel_dev(device);
163
164 return intel_img_create(dev, pCreateInfo, (struct intel_img **) pImage);
165}
166
167XGL_RESULT XGLAPI intelGetImageSubresourceInfo(
168 XGL_IMAGE image,
169 const XGL_IMAGE_SUBRESOURCE* pSubresource,
170 XGL_SUBRESOURCE_INFO_TYPE infoType,
171 XGL_SIZE* pDataSize,
172 XGL_VOID* pData)
173{
174 const struct intel_img *img = intel_img(image);
175 XGL_RESULT ret = XGL_SUCCESS;
176
177 switch (infoType) {
178 case XGL_INFO_TYPE_SUBRESOURCE_LAYOUT:
179 {
180 XGL_SUBRESOURCE_LAYOUT *layout = (XGL_SUBRESOURCE_LAYOUT *) pData;
Chia-I Wu2b685d72014-08-14 13:45:37 +0800181 unsigned x, y;
182
183 intel_layout_get_slice_pos(&img->layout, pSubresource->mipLevel,
184 pSubresource->arraySlice, &x, &y);
185 intel_layout_pos_to_mem(&img->layout, x, y, &x, &y);
Chia-I Wufeb441f2014-08-08 21:27:38 +0800186
187 *pDataSize = sizeof(XGL_SUBRESOURCE_LAYOUT);
188
Chia-I Wu457d0a62014-08-18 13:02:26 +0800189 layout->offset = intel_layout_mem_to_linear(&img->layout, x, y);
Chia-I Wu2b685d72014-08-14 13:45:37 +0800190 layout->size = intel_layout_get_slice_size(&img->layout,
191 pSubresource->mipLevel);
192 layout->rowPitch = img->layout.bo_stride;
193 layout->depthPitch = intel_layout_get_slice_stride(&img->layout,
194 pSubresource->mipLevel);
Chia-I Wufeb441f2014-08-08 21:27:38 +0800195 }
196 break;
197 default:
198 ret = XGL_ERROR_INVALID_VALUE;
199 break;
200 }
201
202 return ret;
203}