Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

r300_texture_desc.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
  3. * Copyright 2010 Marek Olšák <maraeo@gmail.com>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * 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 NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE. */
  23. #include "r300_texture_desc.h"
  24. #include "r300_context.h"
  25. #include "util/u_format.h"
  26. /* Returns the number of pixels that the texture should be aligned to
  27. * in the given dimension. */
  28. unsigned r300_get_pixel_alignment(enum pipe_format format,
  29. unsigned num_samples,
  30. enum radeon_bo_layout microtile,
  31. enum radeon_bo_layout macrotile,
  32. enum r300_dim dim, boolean is_rs690)
  33. {
  34. static const unsigned table[2][5][3][2] =
  35. {
  36. {
  37. /* Macro: linear linear linear
  38. Micro: linear tiled square-tiled */
  39. {{ 32, 1}, { 8, 4}, { 0, 0}}, /* 8 bits per pixel */
  40. {{ 16, 1}, { 8, 2}, { 4, 4}}, /* 16 bits per pixel */
  41. {{ 8, 1}, { 4, 2}, { 0, 0}}, /* 32 bits per pixel */
  42. {{ 4, 1}, { 2, 2}, { 0, 0}}, /* 64 bits per pixel */
  43. {{ 2, 1}, { 0, 0}, { 0, 0}} /* 128 bits per pixel */
  44. },
  45. {
  46. /* Macro: tiled tiled tiled
  47. Micro: linear tiled square-tiled */
  48. {{256, 8}, {64, 32}, { 0, 0}}, /* 8 bits per pixel */
  49. {{128, 8}, {64, 16}, {32, 32}}, /* 16 bits per pixel */
  50. {{ 64, 8}, {32, 16}, { 0, 0}}, /* 32 bits per pixel */
  51. {{ 32, 8}, {16, 16}, { 0, 0}}, /* 64 bits per pixel */
  52. {{ 16, 8}, { 0, 0}, { 0, 0}} /* 128 bits per pixel */
  53. }
  54. };
  55. static const unsigned aa_block[2] = {4, 8};
  56. unsigned tile = 0;
  57. unsigned pixsize = util_format_get_blocksize(format);
  58. assert(macrotile <= RADEON_LAYOUT_TILED);
  59. assert(microtile <= RADEON_LAYOUT_SQUARETILED);
  60. assert(pixsize <= 16);
  61. assert(dim <= DIM_HEIGHT);
  62. if (num_samples > 1) {
  63. /* Multisampled textures have their own alignment scheme. */
  64. if (pixsize == 4)
  65. tile = aa_block[dim];
  66. /* XXX FP16 AA. */
  67. } else {
  68. /* Standard alignment. */
  69. tile = table[macrotile][util_logbase2(pixsize)][microtile][dim];
  70. if (macrotile == 0 && is_rs690 && dim == DIM_WIDTH) {
  71. int align;
  72. int h_tile;
  73. h_tile = table[macrotile][util_logbase2(pixsize)][microtile][DIM_HEIGHT];
  74. align = 64 / (pixsize * h_tile);
  75. if (tile < align)
  76. tile = align;
  77. }
  78. }
  79. assert(tile);
  80. return tile;
  81. }
  82. /* Return true if macrotiling should be enabled on the miplevel. */
  83. static boolean r300_texture_macro_switch(struct r300_resource *tex,
  84. unsigned level,
  85. boolean rv350_mode,
  86. enum r300_dim dim)
  87. {
  88. unsigned tile, texdim;
  89. tile = r300_get_pixel_alignment(tex->b.b.format, tex->b.b.nr_samples,
  90. tex->tex.microtile, RADEON_LAYOUT_TILED, dim, 0);
  91. if (dim == DIM_WIDTH) {
  92. texdim = u_minify(tex->tex.width0, level);
  93. } else {
  94. texdim = u_minify(tex->tex.height0, level);
  95. }
  96. /* See TX_FILTER1_n.MACRO_SWITCH. */
  97. if (rv350_mode) {
  98. return texdim >= tile;
  99. } else {
  100. return texdim > tile;
  101. }
  102. }
  103. /**
  104. * Return the stride, in bytes, of the texture image of the given texture
  105. * at the given level.
  106. */
  107. static unsigned r300_texture_get_stride(struct r300_screen *screen,
  108. struct r300_resource *tex,
  109. unsigned level)
  110. {
  111. unsigned tile_width, width, stride;
  112. boolean is_rs690 = (screen->caps.family == CHIP_FAMILY_RS600 ||
  113. screen->caps.family == CHIP_FAMILY_RS690 ||
  114. screen->caps.family == CHIP_FAMILY_RS740);
  115. if (tex->tex.stride_in_bytes_override)
  116. return tex->tex.stride_in_bytes_override;
  117. /* Check the level. */
  118. if (level > tex->b.b.last_level) {
  119. SCREEN_DBG(screen, DBG_TEX, "%s: level (%u) > last_level (%u)\n",
  120. __FUNCTION__, level, tex->b.b.last_level);
  121. return 0;
  122. }
  123. width = u_minify(tex->tex.width0, level);
  124. if (util_format_is_plain(tex->b.b.format)) {
  125. tile_width = r300_get_pixel_alignment(tex->b.b.format,
  126. tex->b.b.nr_samples,
  127. tex->tex.microtile,
  128. tex->tex.macrotile[level],
  129. DIM_WIDTH, is_rs690);
  130. width = align(width, tile_width);
  131. stride = util_format_get_stride(tex->b.b.format, width);
  132. /* The alignment to 32 bytes is sort of implied by the layout... */
  133. return stride;
  134. } else {
  135. return align(util_format_get_stride(tex->b.b.format, width), is_rs690 ? 64 : 32);
  136. }
  137. }
  138. static unsigned r300_texture_get_nblocksy(struct r300_resource *tex,
  139. unsigned level,
  140. boolean *out_aligned_for_cbzb)
  141. {
  142. unsigned height, tile_height;
  143. height = u_minify(tex->tex.height0, level);
  144. /* Mipmapped and 3D textures must have their height aligned to POT. */
  145. if ((tex->b.b.target != PIPE_TEXTURE_1D &&
  146. tex->b.b.target != PIPE_TEXTURE_2D &&
  147. tex->b.b.target != PIPE_TEXTURE_RECT) ||
  148. tex->b.b.last_level != 0) {
  149. height = util_next_power_of_two(height);
  150. }
  151. if (util_format_is_plain(tex->b.b.format)) {
  152. tile_height = r300_get_pixel_alignment(tex->b.b.format,
  153. tex->b.b.nr_samples,
  154. tex->tex.microtile,
  155. tex->tex.macrotile[level],
  156. DIM_HEIGHT, 0);
  157. height = align(height, tile_height);
  158. /* See if the CBZB clear can be used on the buffer,
  159. * taking the texture size into account. */
  160. if (out_aligned_for_cbzb) {
  161. if (tex->tex.macrotile[level]) {
  162. /* When clearing, the layer (width*height) is horizontally split
  163. * into two, and the upper and lower halves are cleared by the CB
  164. * and ZB units, respectively. Therefore, the number of macrotiles
  165. * in the Y direction must be even. */
  166. /* Align the height so that there is an even number of macrotiles.
  167. * Do so for 3 or more macrotiles in the Y direction. */
  168. if (level == 0 && tex->b.b.last_level == 0 &&
  169. (tex->b.b.target == PIPE_TEXTURE_1D ||
  170. tex->b.b.target == PIPE_TEXTURE_2D ||
  171. tex->b.b.target == PIPE_TEXTURE_RECT) &&
  172. height >= tile_height * 3) {
  173. height = align(height, tile_height * 2);
  174. }
  175. *out_aligned_for_cbzb = height % (tile_height * 2) == 0;
  176. } else {
  177. *out_aligned_for_cbzb = FALSE;
  178. }
  179. }
  180. }
  181. return util_format_get_nblocksy(tex->b.b.format, height);
  182. }
  183. /* Get a width in pixels from a stride in bytes. */
  184. unsigned r300_stride_to_width(enum pipe_format format,
  185. unsigned stride_in_bytes)
  186. {
  187. return (stride_in_bytes / util_format_get_blocksize(format)) *
  188. util_format_get_blockwidth(format);
  189. }
  190. static void r300_setup_miptree(struct r300_screen *screen,
  191. struct r300_resource *tex,
  192. boolean align_for_cbzb)
  193. {
  194. struct pipe_resource *base = &tex->b.b;
  195. unsigned stride, size, layer_size, nblocksy, i;
  196. boolean rv350_mode = screen->caps.family >= CHIP_FAMILY_R350;
  197. boolean aligned_for_cbzb;
  198. tex->tex.size_in_bytes = 0;
  199. SCREEN_DBG(screen, DBG_TEXALLOC,
  200. "r300: Making miptree for texture, format %s\n",
  201. util_format_short_name(base->format));
  202. for (i = 0; i <= base->last_level; i++) {
  203. /* Let's see if this miplevel can be macrotiled. */
  204. tex->tex.macrotile[i] =
  205. (tex->tex.macrotile[0] == RADEON_LAYOUT_TILED &&
  206. r300_texture_macro_switch(tex, i, rv350_mode, DIM_WIDTH) &&
  207. r300_texture_macro_switch(tex, i, rv350_mode, DIM_HEIGHT)) ?
  208. RADEON_LAYOUT_TILED : RADEON_LAYOUT_LINEAR;
  209. stride = r300_texture_get_stride(screen, tex, i);
  210. /* Compute the number of blocks in Y, see if the CBZB clear can be
  211. * used on the texture. */
  212. aligned_for_cbzb = FALSE;
  213. if (align_for_cbzb && tex->tex.cbzb_allowed[i])
  214. nblocksy = r300_texture_get_nblocksy(tex, i, &aligned_for_cbzb);
  215. else
  216. nblocksy = r300_texture_get_nblocksy(tex, i, NULL);
  217. layer_size = stride * nblocksy;
  218. if (base->nr_samples) {
  219. layer_size *= base->nr_samples;
  220. }
  221. if (base->target == PIPE_TEXTURE_CUBE)
  222. size = layer_size * 6;
  223. else
  224. size = layer_size * u_minify(tex->tex.depth0, i);
  225. tex->tex.offset_in_bytes[i] = tex->tex.size_in_bytes;
  226. tex->tex.size_in_bytes = tex->tex.offset_in_bytes[i] + size;
  227. tex->tex.layer_size_in_bytes[i] = layer_size;
  228. tex->tex.stride_in_bytes[i] = stride;
  229. tex->tex.cbzb_allowed[i] = tex->tex.cbzb_allowed[i] && aligned_for_cbzb;
  230. SCREEN_DBG(screen, DBG_TEXALLOC, "r300: Texture miptree: Level %d "
  231. "(%dx%dx%d px, pitch %d bytes) %d bytes total, macrotiled %s\n",
  232. i, u_minify(tex->tex.width0, i), u_minify(tex->tex.height0, i),
  233. u_minify(tex->tex.depth0, i), stride, tex->tex.size_in_bytes,
  234. tex->tex.macrotile[i] ? "TRUE" : "FALSE");
  235. }
  236. }
  237. static void r300_setup_flags(struct r300_resource *tex)
  238. {
  239. tex->tex.uses_stride_addressing =
  240. !util_is_power_of_two(tex->b.b.width0) ||
  241. (tex->tex.stride_in_bytes_override &&
  242. r300_stride_to_width(tex->b.b.format,
  243. tex->tex.stride_in_bytes_override) != tex->b.b.width0);
  244. tex->tex.is_npot =
  245. tex->tex.uses_stride_addressing ||
  246. !util_is_power_of_two(tex->b.b.height0) ||
  247. !util_is_power_of_two(tex->b.b.depth0);
  248. }
  249. static void r300_setup_cbzb_flags(struct r300_screen *rscreen,
  250. struct r300_resource *tex)
  251. {
  252. unsigned i, bpp;
  253. boolean first_level_valid;
  254. bpp = util_format_get_blocksizebits(tex->b.b.format);
  255. /* 1) The texture must be point-sampled,
  256. * 2) The depth must be 16 or 32 bits.
  257. * 3) If the midpoint ZB offset is not aligned to 2048, it returns garbage
  258. * with certain texture sizes. Macrotiling ensures the alignment. */
  259. first_level_valid = tex->b.b.nr_samples <= 1 &&
  260. (bpp == 16 || bpp == 32) &&
  261. tex->tex.macrotile[0];
  262. if (SCREEN_DBG_ON(rscreen, DBG_NO_CBZB))
  263. first_level_valid = FALSE;
  264. for (i = 0; i <= tex->b.b.last_level; i++)
  265. tex->tex.cbzb_allowed[i] = first_level_valid && tex->tex.macrotile[i];
  266. }
  267. static unsigned r300_pixels_to_dwords(unsigned stride,
  268. unsigned height,
  269. unsigned xblock, unsigned yblock)
  270. {
  271. return (util_align_npot(stride, xblock) * align(height, yblock)) / (xblock * yblock);
  272. }
  273. static void r300_setup_hyperz_properties(struct r300_screen *screen,
  274. struct r300_resource *tex)
  275. {
  276. /* The tile size of 1 DWORD in ZMASK RAM is:
  277. *
  278. * GPU Pipes 4x4 mode 8x8 mode
  279. * ------------------------------------------
  280. * R580 4P/1Z 32x32 64x64
  281. * RV570 3P/1Z 48x16 96x32
  282. * RV530 1P/2Z 32x16 64x32
  283. * 1P/1Z 16x16 32x32
  284. */
  285. static unsigned zmask_blocks_x_per_dw[4] = {4, 8, 12, 8};
  286. static unsigned zmask_blocks_y_per_dw[4] = {4, 4, 4, 8};
  287. /* In HIZ RAM, one dword is always 8x8 pixels (each byte is 4x4 pixels),
  288. * but the blocks have very weird ordering.
  289. *
  290. * With 2 pipes and an image of size 8xY, where Y >= 1,
  291. * clearing 4 dwords clears blocks like this:
  292. *
  293. * 01012323
  294. *
  295. * where numbers correspond to dword indices. The blocks are interleaved
  296. * in the X direction, so the alignment must be 4x1 blocks (32x8 pixels).
  297. *
  298. * With 4 pipes and an image of size 8xY, where Y >= 4,
  299. * clearing 8 dwords clears blocks like this:
  300. * 01012323
  301. * 45456767
  302. * 01012323
  303. * 45456767
  304. * where numbers correspond to dword indices. The blocks are interleaved
  305. * in both directions, so the alignment must be 4x4 blocks (32x32 pixels)
  306. */
  307. static unsigned hiz_align_x[4] = {8, 32, 48, 32};
  308. static unsigned hiz_align_y[4] = {8, 8, 8, 32};
  309. if (util_format_is_depth_or_stencil(tex->b.b.format) &&
  310. util_format_get_blocksizebits(tex->b.b.format) == 32 &&
  311. tex->tex.microtile) {
  312. unsigned i, pipes;
  313. if (screen->caps.family == CHIP_FAMILY_RV530) {
  314. pipes = screen->info.r300_num_z_pipes;
  315. } else {
  316. pipes = screen->info.r300_num_gb_pipes;
  317. }
  318. for (i = 0; i <= tex->b.b.last_level; i++) {
  319. unsigned zcomp_numdw, zcompsize, hiz_numdw, stride, height;
  320. stride = r300_stride_to_width(tex->b.b.format,
  321. tex->tex.stride_in_bytes[i]);
  322. stride = align(stride, 16);
  323. height = u_minify(tex->b.b.height0, i);
  324. /* The 8x8 compression mode needs macrotiling. */
  325. zcompsize = screen->caps.z_compress == R300_ZCOMP_8X8 &&
  326. tex->tex.macrotile[i] &&
  327. tex->b.b.nr_samples <= 1 ? 8 : 4;
  328. /* Get the ZMASK buffer size in dwords. */
  329. zcomp_numdw = r300_pixels_to_dwords(stride, height,
  330. zmask_blocks_x_per_dw[pipes-1] * zcompsize,
  331. zmask_blocks_y_per_dw[pipes-1] * zcompsize);
  332. /* Check whether we have enough ZMASK memory. */
  333. if (util_format_get_blocksizebits(tex->b.b.format) == 32 &&
  334. zcomp_numdw <= screen->caps.zmask_ram * pipes) {
  335. tex->tex.zmask_dwords[i] = zcomp_numdw;
  336. tex->tex.zcomp8x8[i] = zcompsize == 8;
  337. tex->tex.zmask_stride_in_pixels[i] =
  338. util_align_npot(stride, zmask_blocks_x_per_dw[pipes-1] * zcompsize);
  339. } else {
  340. tex->tex.zmask_dwords[i] = 0;
  341. tex->tex.zcomp8x8[i] = FALSE;
  342. tex->tex.zmask_stride_in_pixels[i] = 0;
  343. }
  344. /* Now setup HIZ. */
  345. stride = util_align_npot(stride, hiz_align_x[pipes-1]);
  346. height = align(height, hiz_align_y[pipes-1]);
  347. /* Get the HIZ buffer size in dwords. */
  348. hiz_numdw = (stride * height) / (8*8 * pipes);
  349. /* Check whether we have enough HIZ memory. */
  350. if (hiz_numdw <= screen->caps.hiz_ram * pipes) {
  351. tex->tex.hiz_dwords[i] = hiz_numdw;
  352. tex->tex.hiz_stride_in_pixels[i] = stride;
  353. } else {
  354. tex->tex.hiz_dwords[i] = 0;
  355. tex->tex.hiz_stride_in_pixels[i] = 0;
  356. }
  357. }
  358. }
  359. }
  360. static void r300_setup_tiling(struct r300_screen *screen,
  361. struct r300_resource *tex)
  362. {
  363. enum pipe_format format = tex->b.b.format;
  364. boolean rv350_mode = screen->caps.family >= CHIP_FAMILY_R350;
  365. boolean is_zb = util_format_is_depth_or_stencil(format);
  366. boolean dbg_no_tiling = SCREEN_DBG_ON(screen, DBG_NO_TILING);
  367. tex->tex.microtile = RADEON_LAYOUT_LINEAR;
  368. tex->tex.macrotile[0] = RADEON_LAYOUT_LINEAR;
  369. if (!util_format_is_plain(format)) {
  370. return;
  371. }
  372. /* If height == 1, disable microtiling except for zbuffer. */
  373. if (!is_zb && (tex->b.b.height0 == 1 || dbg_no_tiling)) {
  374. return;
  375. }
  376. /* Set microtiling. */
  377. switch (util_format_get_blocksize(format)) {
  378. case 1:
  379. case 4:
  380. case 8:
  381. tex->tex.microtile = RADEON_LAYOUT_TILED;
  382. break;
  383. case 2:
  384. tex->tex.microtile = RADEON_LAYOUT_SQUARETILED;
  385. break;
  386. }
  387. if (dbg_no_tiling) {
  388. return;
  389. }
  390. /* Set macrotiling. */
  391. if (r300_texture_macro_switch(tex, 0, rv350_mode, DIM_WIDTH) &&
  392. r300_texture_macro_switch(tex, 0, rv350_mode, DIM_HEIGHT)) {
  393. tex->tex.macrotile[0] = RADEON_LAYOUT_TILED;
  394. }
  395. }
  396. static void r300_tex_print_info(struct r300_resource *tex,
  397. const char *func)
  398. {
  399. fprintf(stderr,
  400. "r300: %s: Macro: %s, Micro: %s, Pitch: %i, Dim: %ix%ix%i, "
  401. "LastLevel: %i, Size: %i, Format: %s\n",
  402. func,
  403. tex->tex.macrotile[0] ? "YES" : " NO",
  404. tex->tex.microtile ? "YES" : " NO",
  405. r300_stride_to_width(tex->b.b.format, tex->tex.stride_in_bytes[0]),
  406. tex->b.b.width0, tex->b.b.height0, tex->b.b.depth0,
  407. tex->b.b.last_level, tex->tex.size_in_bytes,
  408. util_format_short_name(tex->b.b.format));
  409. }
  410. void r300_texture_desc_init(struct r300_screen *rscreen,
  411. struct r300_resource *tex,
  412. const struct pipe_resource *base)
  413. {
  414. tex->b.b.target = base->target;
  415. tex->b.b.format = base->format;
  416. tex->b.b.width0 = base->width0;
  417. tex->b.b.height0 = base->height0;
  418. tex->b.b.depth0 = base->depth0;
  419. tex->b.b.array_size = base->array_size;
  420. tex->b.b.last_level = base->last_level;
  421. tex->b.b.nr_samples = base->nr_samples;
  422. tex->tex.width0 = base->width0;
  423. tex->tex.height0 = base->height0;
  424. tex->tex.depth0 = base->depth0;
  425. r300_setup_flags(tex);
  426. /* Align a 3D NPOT texture to POT. */
  427. if (base->target == PIPE_TEXTURE_3D && tex->tex.is_npot) {
  428. tex->tex.width0 = util_next_power_of_two(tex->tex.width0);
  429. tex->tex.height0 = util_next_power_of_two(tex->tex.height0);
  430. tex->tex.depth0 = util_next_power_of_two(tex->tex.depth0);
  431. }
  432. /* Setup tiling. */
  433. if (tex->tex.microtile == RADEON_LAYOUT_UNKNOWN) {
  434. r300_setup_tiling(rscreen, tex);
  435. }
  436. r300_setup_cbzb_flags(rscreen, tex);
  437. /* Setup the miptree description. */
  438. r300_setup_miptree(rscreen, tex, TRUE);
  439. /* If the required buffer size is larger than the given max size,
  440. * try again without the alignment for the CBZB clear. */
  441. if (tex->buf && tex->tex.size_in_bytes > tex->buf->size) {
  442. r300_setup_miptree(rscreen, tex, FALSE);
  443. /* Make sure the buffer we got is large enough. */
  444. if (tex->tex.size_in_bytes > tex->buf->size) {
  445. fprintf(stderr,
  446. "r300: I got a pre-allocated buffer to use it as a texture "
  447. "storage, but the buffer is too small. I'll use the buffer "
  448. "anyway, because I can't crash here, but it's dangerous. "
  449. "This can be a DDX bug. Got: %iB, Need: %iB, Info:\n",
  450. tex->buf->size, tex->tex.size_in_bytes);
  451. r300_tex_print_info(tex, "texture_desc_init");
  452. /* Ooops, what now. Apps will break if we fail this,
  453. * so just pretend everything's okay. */
  454. }
  455. }
  456. r300_setup_hyperz_properties(rscreen, tex);
  457. if (SCREEN_DBG_ON(rscreen, DBG_TEX))
  458. r300_tex_print_info(tex, "texture_desc_init");
  459. }
  460. unsigned r300_texture_get_offset(struct r300_resource *tex,
  461. unsigned level, unsigned layer)
  462. {
  463. unsigned offset = tex->tex.offset_in_bytes[level];
  464. switch (tex->b.b.target) {
  465. case PIPE_TEXTURE_3D:
  466. case PIPE_TEXTURE_CUBE:
  467. return offset + layer * tex->tex.layer_size_in_bytes[level];
  468. default:
  469. assert(layer == 0);
  470. return offset;
  471. }
  472. }