1 /* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can 5 * be found in the LICENSE file. 6 * 7 */ 8 9 #ifndef SKC_ONCE_RASTER 10 #define SKC_ONCE_RASTER 11 12 // 13 // 14 // 15 16 #include "block.h" 17 18 // 19 // The raster "head" structure aliases a block. 20 // 21 // Blocks are guaranteed to be at least 16 words. 22 // 23 // Note that the end of the ttsk key sequence and beginning of the 24 // ttpk key sequence may share a node. 25 // 26 // Note that keys are 64-bits and the "next" id is only a 32-bit 27 // (27-bit tagged block id) so there is room for another next id or a 28 // key/node countdown. For now we'll leave the second to last word 29 // empty/unused. 30 // 31 32 typedef skc_uint2 skc_ttsk_t; 33 typedef skc_uint2 skc_ttpk_t; 34 typedef skc_uint2 skc_ttxk_t; 35 36 union skc_raster_node_next 37 { 38 skc_uint2 u32v2; 39 40 struct { 41 skc_block_id_t node; // low word 42 skc_uint na; 43 }; 44 }; 45 46 // 47 // 48 // 49 50 union skc_raster_node_elem 51 { 52 skc_uint2 u32v2; 53 skc_ttsk_t sk; 54 skc_ttpk_t pk; 55 skc_ttxk_t xk; 56 union skc_raster_node_next next; 57 }; 58 59 // 60 // FIXME -- we're eventually going to convert this layout to split the 61 // 64-bit key into lo and hi segments because it will simplify later 62 // reclamation. 63 // 64 // u32[0]: header.blocks | header.nodes | bounds.x0 | bounds.y0 | TTXK.lo[] ... 65 // u32[1]: header.na | header.keys | bounds.x1 | bounds.y1 | TTXK.hi[] ... 66 // u32[2]: TTXK.lo[] ... 67 // u32[3]: TTXK.hi[] ... 68 // 69 70 union skc_raster_header 71 { 72 skc_uint4 u32v4; 73 74 struct { 75 skc_uint blocks; // # of blocks -- head+node+skb+pkb -- uint2.lo 76 skc_uint na; // unused -- uint2.hi 77 skc_uint nodes; // # of nodes -- not including header -- uint2.lo 78 skc_uint keys; // # of sk+pk keys -- uint2.hi 79 }; 80 }; 81 82 // 83 // 84 // 85 86 struct skc_raster_head 87 { 88 union skc_raster_header header; // 3 counters and a spare 89 skc_int4 bounds; // sub-pixel resolution bounds 90 union skc_raster_node_elem elems[]; // 64-bit keys and index of next node 91 }; 92 93 // 94 // 95 // 96 97 #define SKC_RASTER_HEAD_WORDS 8 98 99 #define SKC_RASTER_HEAD_OFFSET_COUNTS_BLOCKS 0 100 #define SKC_RASTER_HEAD_OFFSET_COUNTS_NA 1 101 #define SKC_RASTER_HEAD_OFFSET_COUNTS_NODES 2 102 #define SKC_RASTER_HEAD_OFFSET_COUNTS_KEYS 3 103 104 #define SKC_RASTER_HEAD_OFFSET_BOUNDS 4 105 #define SKC_RASTER_HEAD_OFFSET_ELEMS 8 106 107 // 108 // 109 // 110 111 #define SKC_RASTER_HEAD_WORDS_CALC (sizeof(struct skc_raster_head) / sizeof(skc_uint)) 112 113 #define SKC_RASTER_HEAD_OFFSET_COUNTS_BLOCKS_CALC (SKC_OFFSET_OF(struct skc_raster_head,header.blocks) / sizeof(skc_uint)) 114 #define SKC_RASTER_HEAD_OFFSET_COUNTS_NODES_CALC (SKC_OFFSET_OF(struct skc_raster_head,header.nodes) / sizeof(skc_uint)) 115 #define SKC_RASTER_HEAD_OFFSET_COUNTS_KEYS_CALC (SKC_OFFSET_OF(struct skc_raster_head,header.keys) / sizeof(skc_uint)) 116 117 #define SKC_RASTER_HEAD_OFFSET_BOUNDS_CALC (SKC_OFFSET_OF(struct skc_raster_head,bounds) / sizeof(skc_uint)) 118 #define SKC_RASTER_HEAD_OFFSET_ELEMS_CALC (SKC_OFFSET_OF(struct skc_raster_head,elems) / sizeof(skc_uint)) 119 120 // 121 // NOT ALL OPENCL PREPROCESSORS ARE HAPPY WITH CALCULATING OFFSET_OF() 122 // 123 // - Intel ioc compiler failed in the past 124 // 125 126 #if !defined(__OPENCL_C_VERSION__) 127 SKC_STATIC_ASSERT(SKC_RASTER_HEAD_WORDS == SKC_RASTER_HEAD_WORDS_CALC); 128 SKC_STATIC_ASSERT(SKC_RASTER_HEAD_OFFSET_COUNTS_BLOCKS == SKC_RASTER_HEAD_OFFSET_COUNTS_BLOCKS_CALC); 129 SKC_STATIC_ASSERT(SKC_RASTER_HEAD_OFFSET_COUNTS_NODES == SKC_RASTER_HEAD_OFFSET_COUNTS_NODES_CALC); 130 SKC_STATIC_ASSERT(SKC_RASTER_HEAD_OFFSET_COUNTS_KEYS == SKC_RASTER_HEAD_OFFSET_COUNTS_KEYS_CALC); 131 SKC_STATIC_ASSERT(SKC_RASTER_HEAD_OFFSET_BOUNDS == SKC_RASTER_HEAD_OFFSET_BOUNDS_CALC); 132 SKC_STATIC_ASSERT(SKC_RASTER_HEAD_OFFSET_ELEMS == SKC_RASTER_HEAD_OFFSET_ELEMS_CALC); 133 #endif 134 135 // 136 // 137 // 138 139 #if 0 140 #if !defined(__OPENCL_C_VERSION__) 141 struct skc_raster_node 142 { 143 union skc_raster_node_elem elems[]; 144 }; 145 #endif 146 #endif 147 148 // 149 // 150 // 151 152 #define SKC_RASTER_HEAD_DWORDS (SKC_RASTER_HEAD_WORDS / 2) 153 #define SKC_RASTER_NODE_DWORDS SKC_DEVICE_BLOCK_DWORDS 154 155 // 156 // 157 158 #define SKC_RASTER_NODE_COUNT_KEYS (SKC_DEVICE_BLOCK_DWORDS - 1) 159 #define SKC_RASTER_HEAD_COUNT_KEYS (SKC_RASTER_NODE_COUNT_KEYS - SKC_RASTER_HEAD_DWORDS) 160 161 // 162 // these are the most possible keys that could be produced by a node 163 // 164 165 #define SKC_RASTER_HEAD_MAX_TTSK SKC_RASTER_HEAD_COUNT_KEYS 166 #define SKC_RASTER_HEAD_MAX_TTPK ((SKC_DEVICE_BLOCK_DWORDS - SKC_RASTER_HEAD_DWORDS) / 2) 167 168 #define SKC_RASTER_NODE_MAX_TTSK SKC_RASTER_NODE_COUNT_KEYS // a node could be all TTSK keys minus next pointer 169 #define SKC_RASTER_NODE_MAX_TTPK (SKC_RASTER_NODE_DWORDS / 2) // a node could be at most half TTPK keys and (half-1) TTSK keys 170 171 #define SKC_RASTER_HEAD_MIN_TTSK (SKC_RASTER_HEAD_MAX_TTSK - SKC_RASTER_NODE_MAX_TTPK) 172 #define SKC_RASTER_HEAD_MIN_TTPK 0 173 174 #define SKC_RASTER_NODE_MIN_TTSK (SKC_RASTER_NODE_MAX_TTSK - SKC_RASTER_NODE_MAX_TTPK) 175 #define SKC_RASTER_NODE_MIN_TTPK 0 176 177 // 178 // 179 // 180 181 #endif 182 183 // 184 // 185 // 186