2 * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
3 * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
4 * Copyright © 2010 Intel Corporation
5 * Copyright © 2011 Bryan Cain
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 #include "st_glsl_types.h"
30 * Returns the number of places to offset the uniform index, given the type of
31 * a struct member. We use this because samplers and images have backing
32 * storeage only when they are bindless.
35 st_glsl_storage_type_size(const struct glsl_type
*type
, bool is_bindless
)
40 switch (type
->base_type
) {
45 if (type
->is_matrix()) {
46 return type
->matrix_columns
;
48 /* Regardless of size of vector, it gets a vec4. This is bad
49 * packing for things like floats, but otherwise arrays become a
50 * mess. Hopefully a later pass over the code can pack scalars
51 * down if appropriate.
56 case GLSL_TYPE_DOUBLE
:
57 if (type
->is_matrix()) {
58 if (type
->vector_elements
<= 2)
59 return type
->matrix_columns
;
61 return type
->matrix_columns
* 2;
63 /* For doubles if we have a double or dvec2 they fit in one
64 * vec4, else they need 2 vec4s.
66 if (type
->vector_elements
<= 2)
72 case GLSL_TYPE_UINT64
:
74 if (type
->vector_elements
<= 2)
79 assert(type
->length
> 0);
80 return st_glsl_storage_type_size(type
->fields
.array
, is_bindless
) *
82 case GLSL_TYPE_STRUCT
:
84 for (i
= 0; i
< type
->length
; i
++) {
85 size
+= st_glsl_storage_type_size(type
->fields
.structure
[i
].type
,
89 case GLSL_TYPE_SAMPLER
:
94 case GLSL_TYPE_SUBROUTINE
:
96 case GLSL_TYPE_ATOMIC_UINT
:
97 case GLSL_TYPE_INTERFACE
:
100 case GLSL_TYPE_FUNCTION
:
101 case GLSL_TYPE_FLOAT16
:
102 case GLSL_TYPE_UINT16
:
103 case GLSL_TYPE_INT16
:
104 case GLSL_TYPE_UINT8
:
106 assert(!"Invalid type in type_size");
113 st_glsl_type_dword_size(const struct glsl_type
*type
, bool bindless
)
115 unsigned int size
, i
;
117 switch (type
->base_type
) {
120 case GLSL_TYPE_FLOAT
:
122 return type
->components();
123 case GLSL_TYPE_UINT16
:
124 case GLSL_TYPE_INT16
:
125 case GLSL_TYPE_FLOAT16
:
126 return DIV_ROUND_UP(type
->components(), 2);
127 case GLSL_TYPE_UINT8
:
129 return DIV_ROUND_UP(type
->components(), 4);
130 case GLSL_TYPE_IMAGE
:
131 case GLSL_TYPE_SAMPLER
:
134 case GLSL_TYPE_DOUBLE
:
135 case GLSL_TYPE_UINT64
:
136 case GLSL_TYPE_INT64
:
137 return type
->components() * 2;
138 case GLSL_TYPE_ARRAY
:
139 return st_glsl_type_dword_size(type
->fields
.array
, bindless
) *
141 case GLSL_TYPE_STRUCT
:
143 for (i
= 0; i
< type
->length
; i
++) {
144 size
+= st_glsl_type_dword_size(type
->fields
.structure
[i
].type
,
148 case GLSL_TYPE_ATOMIC_UINT
:
150 case GLSL_TYPE_SUBROUTINE
:
153 case GLSL_TYPE_ERROR
:
154 case GLSL_TYPE_INTERFACE
:
155 case GLSL_TYPE_FUNCTION
:
157 unreachable("invalid type in st_glsl_type_dword_size()");
164 * Returns the type size of uniforms when !PIPE_CAP_PACKED_UNIFORMS -- each
165 * value or array element is aligned to a vec4 offset and expanded out to a
169 st_glsl_uniforms_type_size(const struct glsl_type
*type
, bool bindless
)
171 return st_glsl_storage_type_size(type
, bindless
);