Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nv50_screen.c 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. /*
  2. * Copyright 2010 Christoph Bumiller
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include <errno.h>
  23. #include <xf86drm.h>
  24. #include <nouveau_drm.h>
  25. #include "util/u_format.h"
  26. #include "util/u_format_s3tc.h"
  27. #include "pipe/p_screen.h"
  28. #include "nv50/nv50_context.h"
  29. #include "nv50/nv50_screen.h"
  30. #include "nouveau_vp3_video.h"
  31. #include "nv_object.xml.h"
  32. /* affected by LOCAL_WARPS_LOG_ALLOC / LOCAL_WARPS_NO_CLAMP */
  33. #define LOCAL_WARPS_ALLOC 32
  34. /* affected by STACK_WARPS_LOG_ALLOC / STACK_WARPS_NO_CLAMP */
  35. #define STACK_WARPS_ALLOC 32
  36. #define THREADS_IN_WARP 32
  37. #define ONE_TEMP_SIZE (4/*vector*/ * sizeof(float))
  38. static boolean
  39. nv50_screen_is_format_supported(struct pipe_screen *pscreen,
  40. enum pipe_format format,
  41. enum pipe_texture_target target,
  42. unsigned sample_count,
  43. unsigned bindings)
  44. {
  45. if (sample_count > 8)
  46. return FALSE;
  47. if (!(0x117 & (1 << sample_count))) /* 0, 1, 2, 4 or 8 */
  48. return FALSE;
  49. if (sample_count == 8 && util_format_get_blocksizebits(format) >= 128)
  50. return FALSE;
  51. if (!util_format_is_supported(format, bindings))
  52. return FALSE;
  53. switch (format) {
  54. case PIPE_FORMAT_Z16_UNORM:
  55. if (nv50_screen(pscreen)->tesla->oclass < NVA0_3D_CLASS)
  56. return FALSE;
  57. break;
  58. default:
  59. break;
  60. }
  61. /* transfers & shared are always supported */
  62. bindings &= ~(PIPE_BIND_TRANSFER_READ |
  63. PIPE_BIND_TRANSFER_WRITE |
  64. PIPE_BIND_SHARED);
  65. return (nv50_format_table[format].usage & bindings) == bindings;
  66. }
  67. static int
  68. nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
  69. {
  70. const uint16_t class_3d = nouveau_screen(pscreen)->class_3d;
  71. struct nouveau_device *dev = nouveau_screen(pscreen)->device;
  72. switch (param) {
  73. /* non-boolean caps */
  74. case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
  75. return 14;
  76. case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
  77. return 12;
  78. case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
  79. return 14;
  80. case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
  81. return 512;
  82. case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
  83. case PIPE_CAP_MIN_TEXEL_OFFSET:
  84. return -8;
  85. case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
  86. case PIPE_CAP_MAX_TEXEL_OFFSET:
  87. return 7;
  88. case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
  89. return 65536;
  90. case PIPE_CAP_GLSL_FEATURE_LEVEL:
  91. return 330;
  92. case PIPE_CAP_MAX_RENDER_TARGETS:
  93. return 8;
  94. case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
  95. return 1;
  96. case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
  97. return 4;
  98. case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
  99. case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
  100. return 64;
  101. case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
  102. case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
  103. return 1024;
  104. case PIPE_CAP_MAX_VERTEX_STREAMS:
  105. return 1;
  106. case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
  107. return 2048;
  108. case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
  109. return 256;
  110. case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
  111. return 1; /* 256 for binding as RT, but that's not possible in GL */
  112. case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
  113. return NOUVEAU_MIN_BUFFER_MAP_ALIGN;
  114. case PIPE_CAP_MAX_VIEWPORTS:
  115. return NV50_MAX_VIEWPORTS;
  116. case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
  117. return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50;
  118. case PIPE_CAP_ENDIANNESS:
  119. return PIPE_ENDIAN_LITTLE;
  120. case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
  121. return (class_3d >= NVA3_3D_CLASS) ? 4 : 0;
  122. /* supported caps */
  123. case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
  124. case PIPE_CAP_TEXTURE_SWIZZLE:
  125. case PIPE_CAP_TEXTURE_SHADOW_MAP:
  126. case PIPE_CAP_NPOT_TEXTURES:
  127. case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
  128. case PIPE_CAP_ANISOTROPIC_FILTER:
  129. case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
  130. case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
  131. case PIPE_CAP_TWO_SIDED_STENCIL:
  132. case PIPE_CAP_DEPTH_CLIP_DISABLE:
  133. case PIPE_CAP_POINT_SPRITE:
  134. case PIPE_CAP_SM3:
  135. case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
  136. case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
  137. case PIPE_CAP_VERTEX_COLOR_CLAMPED:
  138. case PIPE_CAP_QUERY_TIMESTAMP:
  139. case PIPE_CAP_QUERY_TIME_ELAPSED:
  140. case PIPE_CAP_OCCLUSION_QUERY:
  141. case PIPE_CAP_BLEND_EQUATION_SEPARATE:
  142. case PIPE_CAP_INDEP_BLEND_ENABLE:
  143. case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
  144. case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
  145. case PIPE_CAP_PRIMITIVE_RESTART:
  146. case PIPE_CAP_TGSI_INSTANCEID:
  147. case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
  148. case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
  149. case PIPE_CAP_CONDITIONAL_RENDER:
  150. case PIPE_CAP_TEXTURE_BARRIER:
  151. case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
  152. case PIPE_CAP_START_INSTANCE:
  153. case PIPE_CAP_USER_CONSTANT_BUFFERS:
  154. case PIPE_CAP_USER_INDEX_BUFFERS:
  155. case PIPE_CAP_USER_VERTEX_BUFFERS:
  156. case PIPE_CAP_TEXTURE_MULTISAMPLE:
  157. case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
  158. case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
  159. case PIPE_CAP_SAMPLER_VIEW_TARGET:
  160. case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
  161. case PIPE_CAP_CLIP_HALFZ:
  162. return 1;
  163. case PIPE_CAP_SEAMLESS_CUBE_MAP:
  164. return 1; /* class_3d >= NVA0_3D_CLASS; */
  165. /* supported on nva0+ */
  166. case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
  167. return class_3d >= NVA0_3D_CLASS;
  168. /* supported on nva3+ */
  169. case PIPE_CAP_CUBE_MAP_ARRAY:
  170. case PIPE_CAP_INDEP_BLEND_FUNC:
  171. case PIPE_CAP_TEXTURE_QUERY_LOD:
  172. case PIPE_CAP_SAMPLE_SHADING:
  173. return class_3d >= NVA3_3D_CLASS;
  174. /* unsupported caps */
  175. case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
  176. case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
  177. case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
  178. case PIPE_CAP_SHADER_STENCIL_EXPORT:
  179. case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
  180. case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
  181. case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
  182. case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
  183. case PIPE_CAP_TGSI_TEXCOORD:
  184. case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
  185. case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
  186. case PIPE_CAP_TEXTURE_GATHER_SM5:
  187. case PIPE_CAP_FAKE_SW_MSAA:
  188. case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
  189. case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
  190. case PIPE_CAP_COMPUTE:
  191. case PIPE_CAP_DRAW_INDIRECT:
  192. return 0;
  193. case PIPE_CAP_VENDOR_ID:
  194. return 0x10de;
  195. case PIPE_CAP_DEVICE_ID: {
  196. uint64_t device_id;
  197. if (nouveau_getparam(dev, NOUVEAU_GETPARAM_PCI_DEVICE, &device_id)) {
  198. NOUVEAU_ERR("NOUVEAU_GETPARAM_PCI_DEVICE failed.\n");
  199. return -1;
  200. }
  201. return device_id;
  202. }
  203. case PIPE_CAP_ACCELERATED:
  204. return 1;
  205. case PIPE_CAP_VIDEO_MEMORY:
  206. return dev->vram_size >> 20;
  207. case PIPE_CAP_UMA:
  208. return 0;
  209. }
  210. NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
  211. return 0;
  212. }
  213. static int
  214. nv50_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
  215. enum pipe_shader_cap param)
  216. {
  217. switch (shader) {
  218. case PIPE_SHADER_VERTEX:
  219. case PIPE_SHADER_GEOMETRY:
  220. case PIPE_SHADER_FRAGMENT:
  221. break;
  222. default:
  223. return 0;
  224. }
  225. switch (param) {
  226. case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
  227. case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
  228. case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
  229. case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
  230. return 16384;
  231. case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
  232. return 4;
  233. case PIPE_SHADER_CAP_MAX_INPUTS:
  234. if (shader == PIPE_SHADER_VERTEX)
  235. return 32;
  236. return 15;
  237. case PIPE_SHADER_CAP_MAX_OUTPUTS:
  238. return 16;
  239. case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
  240. return 65536;
  241. case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
  242. return NV50_MAX_PIPE_CONSTBUFS;
  243. case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
  244. case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
  245. return shader != PIPE_SHADER_FRAGMENT;
  246. case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
  247. case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
  248. return 1;
  249. case PIPE_SHADER_CAP_MAX_PREDS:
  250. return 0;
  251. case PIPE_SHADER_CAP_MAX_TEMPS:
  252. return nv50_screen(pscreen)->max_tls_space / ONE_TEMP_SIZE;
  253. case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
  254. return 1;
  255. case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
  256. return 0;
  257. case PIPE_SHADER_CAP_SUBROUTINES:
  258. return 0; /* please inline, or provide function declarations */
  259. case PIPE_SHADER_CAP_INTEGERS:
  260. return 1;
  261. case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
  262. /* The chip could handle more sampler views than samplers */
  263. case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
  264. return MIN2(32, PIPE_MAX_SAMPLERS);
  265. default:
  266. NOUVEAU_ERR("unknown PIPE_SHADER_CAP %d\n", param);
  267. return 0;
  268. }
  269. }
  270. static float
  271. nv50_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
  272. {
  273. switch (param) {
  274. case PIPE_CAPF_MAX_LINE_WIDTH:
  275. case PIPE_CAPF_MAX_LINE_WIDTH_AA:
  276. return 10.0f;
  277. case PIPE_CAPF_MAX_POINT_WIDTH:
  278. case PIPE_CAPF_MAX_POINT_WIDTH_AA:
  279. return 64.0f;
  280. case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
  281. return 16.0f;
  282. case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
  283. return 4.0f;
  284. case PIPE_CAPF_GUARD_BAND_LEFT:
  285. case PIPE_CAPF_GUARD_BAND_TOP:
  286. return 0.0f;
  287. case PIPE_CAPF_GUARD_BAND_RIGHT:
  288. case PIPE_CAPF_GUARD_BAND_BOTTOM:
  289. return 0.0f; /* that or infinity */
  290. }
  291. NOUVEAU_ERR("unknown PIPE_CAPF %d\n", param);
  292. return 0.0f;
  293. }
  294. static void
  295. nv50_screen_destroy(struct pipe_screen *pscreen)
  296. {
  297. struct nv50_screen *screen = nv50_screen(pscreen);
  298. if (!nouveau_drm_screen_unref(&screen->base))
  299. return;
  300. if (screen->base.fence.current) {
  301. struct nouveau_fence *current = NULL;
  302. /* nouveau_fence_wait will create a new current fence, so wait on the
  303. * _current_ one, and remove both.
  304. */
  305. nouveau_fence_ref(screen->base.fence.current, &current);
  306. nouveau_fence_wait(current);
  307. nouveau_fence_ref(NULL, &current);
  308. nouveau_fence_ref(NULL, &screen->base.fence.current);
  309. }
  310. if (screen->base.pushbuf)
  311. screen->base.pushbuf->user_priv = NULL;
  312. if (screen->blitter)
  313. nv50_blitter_destroy(screen);
  314. nouveau_bo_ref(NULL, &screen->code);
  315. nouveau_bo_ref(NULL, &screen->tls_bo);
  316. nouveau_bo_ref(NULL, &screen->stack_bo);
  317. nouveau_bo_ref(NULL, &screen->txc);
  318. nouveau_bo_ref(NULL, &screen->uniforms);
  319. nouveau_bo_ref(NULL, &screen->fence.bo);
  320. nouveau_heap_destroy(&screen->vp_code_heap);
  321. nouveau_heap_destroy(&screen->gp_code_heap);
  322. nouveau_heap_destroy(&screen->fp_code_heap);
  323. FREE(screen->tic.entries);
  324. nouveau_object_del(&screen->tesla);
  325. nouveau_object_del(&screen->eng2d);
  326. nouveau_object_del(&screen->m2mf);
  327. nouveau_object_del(&screen->sync);
  328. nouveau_screen_fini(&screen->base);
  329. FREE(screen);
  330. }
  331. static void
  332. nv50_screen_fence_emit(struct pipe_screen *pscreen, u32 *sequence)
  333. {
  334. struct nv50_screen *screen = nv50_screen(pscreen);
  335. struct nouveau_pushbuf *push = screen->base.pushbuf;
  336. /* we need to do it after possible flush in MARK_RING */
  337. *sequence = ++screen->base.fence.sequence;
  338. PUSH_DATA (push, NV50_FIFO_PKHDR(NV50_3D(QUERY_ADDRESS_HIGH), 4));
  339. PUSH_DATAh(push, screen->fence.bo->offset);
  340. PUSH_DATA (push, screen->fence.bo->offset);
  341. PUSH_DATA (push, *sequence);
  342. PUSH_DATA (push, NV50_3D_QUERY_GET_MODE_WRITE_UNK0 |
  343. NV50_3D_QUERY_GET_UNK4 |
  344. NV50_3D_QUERY_GET_UNIT_CROP |
  345. NV50_3D_QUERY_GET_TYPE_QUERY |
  346. NV50_3D_QUERY_GET_QUERY_SELECT_ZERO |
  347. NV50_3D_QUERY_GET_SHORT);
  348. }
  349. static u32
  350. nv50_screen_fence_update(struct pipe_screen *pscreen)
  351. {
  352. return nv50_screen(pscreen)->fence.map[0];
  353. }
  354. static void
  355. nv50_screen_init_hwctx(struct nv50_screen *screen)
  356. {
  357. struct nouveau_pushbuf *push = screen->base.pushbuf;
  358. struct nv04_fifo *fifo;
  359. unsigned i;
  360. fifo = (struct nv04_fifo *)screen->base.channel->data;
  361. BEGIN_NV04(push, SUBC_M2MF(NV01_SUBCHAN_OBJECT), 1);
  362. PUSH_DATA (push, screen->m2mf->handle);
  363. BEGIN_NV04(push, SUBC_M2MF(NV03_M2MF_DMA_NOTIFY), 3);
  364. PUSH_DATA (push, screen->sync->handle);
  365. PUSH_DATA (push, fifo->vram);
  366. PUSH_DATA (push, fifo->vram);
  367. BEGIN_NV04(push, SUBC_2D(NV01_SUBCHAN_OBJECT), 1);
  368. PUSH_DATA (push, screen->eng2d->handle);
  369. BEGIN_NV04(push, NV50_2D(DMA_NOTIFY), 4);
  370. PUSH_DATA (push, screen->sync->handle);
  371. PUSH_DATA (push, fifo->vram);
  372. PUSH_DATA (push, fifo->vram);
  373. PUSH_DATA (push, fifo->vram);
  374. BEGIN_NV04(push, NV50_2D(OPERATION), 1);
  375. PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY);
  376. BEGIN_NV04(push, NV50_2D(CLIP_ENABLE), 1);
  377. PUSH_DATA (push, 0);
  378. BEGIN_NV04(push, NV50_2D(COLOR_KEY_ENABLE), 1);
  379. PUSH_DATA (push, 0);
  380. BEGIN_NV04(push, SUBC_2D(0x0888), 1);
  381. PUSH_DATA (push, 1);
  382. BEGIN_NV04(push, NV50_2D(COND_MODE), 1);
  383. PUSH_DATA (push, NV50_2D_COND_MODE_ALWAYS);
  384. BEGIN_NV04(push, SUBC_3D(NV01_SUBCHAN_OBJECT), 1);
  385. PUSH_DATA (push, screen->tesla->handle);
  386. BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
  387. PUSH_DATA (push, NV50_3D_COND_MODE_ALWAYS);
  388. BEGIN_NV04(push, NV50_3D(DMA_NOTIFY), 1);
  389. PUSH_DATA (push, screen->sync->handle);
  390. BEGIN_NV04(push, NV50_3D(DMA_ZETA), 11);
  391. for (i = 0; i < 11; ++i)
  392. PUSH_DATA(push, fifo->vram);
  393. BEGIN_NV04(push, NV50_3D(DMA_COLOR(0)), NV50_3D_DMA_COLOR__LEN);
  394. for (i = 0; i < NV50_3D_DMA_COLOR__LEN; ++i)
  395. PUSH_DATA(push, fifo->vram);
  396. BEGIN_NV04(push, NV50_3D(REG_MODE), 1);
  397. PUSH_DATA (push, NV50_3D_REG_MODE_STRIPED);
  398. BEGIN_NV04(push, NV50_3D(UNK1400_LANES), 1);
  399. PUSH_DATA (push, 0xf);
  400. if (debug_get_bool_option("NOUVEAU_SHADER_WATCHDOG", TRUE)) {
  401. BEGIN_NV04(push, NV50_3D(WATCHDOG_TIMER), 1);
  402. PUSH_DATA (push, 0x18);
  403. }
  404. BEGIN_NV04(push, NV50_3D(RT_CONTROL), 1);
  405. PUSH_DATA (push, 1);
  406. BEGIN_NV04(push, NV50_3D(CSAA_ENABLE), 1);
  407. PUSH_DATA (push, 0);
  408. BEGIN_NV04(push, NV50_3D(MULTISAMPLE_ENABLE), 1);
  409. PUSH_DATA (push, 0);
  410. BEGIN_NV04(push, NV50_3D(MULTISAMPLE_MODE), 1);
  411. PUSH_DATA (push, NV50_3D_MULTISAMPLE_MODE_MS1);
  412. BEGIN_NV04(push, NV50_3D(MULTISAMPLE_CTRL), 1);
  413. PUSH_DATA (push, 0);
  414. BEGIN_NV04(push, NV50_3D(PRIM_RESTART_WITH_DRAW_ARRAYS), 1);
  415. PUSH_DATA (push, 1);
  416. BEGIN_NV04(push, NV50_3D(LINE_LAST_PIXEL), 1);
  417. PUSH_DATA (push, 0);
  418. BEGIN_NV04(push, NV50_3D(BLEND_SEPARATE_ALPHA), 1);
  419. PUSH_DATA (push, 1);
  420. if (screen->tesla->oclass >= NVA0_3D_CLASS) {
  421. BEGIN_NV04(push, SUBC_3D(NVA0_3D_TEX_MISC), 1);
  422. PUSH_DATA (push, NVA0_3D_TEX_MISC_SEAMLESS_CUBE_MAP);
  423. }
  424. BEGIN_NV04(push, NV50_3D(SCREEN_Y_CONTROL), 1);
  425. PUSH_DATA (push, 0);
  426. BEGIN_NV04(push, NV50_3D(WINDOW_OFFSET_X), 2);
  427. PUSH_DATA (push, 0);
  428. PUSH_DATA (push, 0);
  429. BEGIN_NV04(push, NV50_3D(ZCULL_REGION), 1);
  430. PUSH_DATA (push, 0x3f);
  431. BEGIN_NV04(push, NV50_3D(VP_ADDRESS_HIGH), 2);
  432. PUSH_DATAh(push, screen->code->offset + (0 << NV50_CODE_BO_SIZE_LOG2));
  433. PUSH_DATA (push, screen->code->offset + (0 << NV50_CODE_BO_SIZE_LOG2));
  434. BEGIN_NV04(push, NV50_3D(FP_ADDRESS_HIGH), 2);
  435. PUSH_DATAh(push, screen->code->offset + (1 << NV50_CODE_BO_SIZE_LOG2));
  436. PUSH_DATA (push, screen->code->offset + (1 << NV50_CODE_BO_SIZE_LOG2));
  437. BEGIN_NV04(push, NV50_3D(GP_ADDRESS_HIGH), 2);
  438. PUSH_DATAh(push, screen->code->offset + (2 << NV50_CODE_BO_SIZE_LOG2));
  439. PUSH_DATA (push, screen->code->offset + (2 << NV50_CODE_BO_SIZE_LOG2));
  440. BEGIN_NV04(push, NV50_3D(LOCAL_ADDRESS_HIGH), 3);
  441. PUSH_DATAh(push, screen->tls_bo->offset);
  442. PUSH_DATA (push, screen->tls_bo->offset);
  443. PUSH_DATA (push, util_logbase2(screen->cur_tls_space / 8));
  444. BEGIN_NV04(push, NV50_3D(STACK_ADDRESS_HIGH), 3);
  445. PUSH_DATAh(push, screen->stack_bo->offset);
  446. PUSH_DATA (push, screen->stack_bo->offset);
  447. PUSH_DATA (push, 4);
  448. BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
  449. PUSH_DATAh(push, screen->uniforms->offset + (0 << 16));
  450. PUSH_DATA (push, screen->uniforms->offset + (0 << 16));
  451. PUSH_DATA (push, (NV50_CB_PVP << 16) | 0x0000);
  452. BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
  453. PUSH_DATAh(push, screen->uniforms->offset + (1 << 16));
  454. PUSH_DATA (push, screen->uniforms->offset + (1 << 16));
  455. PUSH_DATA (push, (NV50_CB_PGP << 16) | 0x0000);
  456. BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
  457. PUSH_DATAh(push, screen->uniforms->offset + (2 << 16));
  458. PUSH_DATA (push, screen->uniforms->offset + (2 << 16));
  459. PUSH_DATA (push, (NV50_CB_PFP << 16) | 0x0000);
  460. BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
  461. PUSH_DATAh(push, screen->uniforms->offset + (3 << 16));
  462. PUSH_DATA (push, screen->uniforms->offset + (3 << 16));
  463. PUSH_DATA (push, (NV50_CB_AUX << 16) | (NV50_CB_AUX_SIZE & 0xffff));
  464. BEGIN_NI04(push, NV50_3D(SET_PROGRAM_CB), 3);
  465. PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf01);
  466. PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf21);
  467. PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf31);
  468. /* return { 0.0, 0.0, 0.0, 0.0 } on out-of-bounds vtxbuf access */
  469. BEGIN_NV04(push, NV50_3D(CB_ADDR), 1);
  470. PUSH_DATA (push, (NV50_CB_AUX_RUNOUT_OFFSET << (8 - 2)) | NV50_CB_AUX);
  471. BEGIN_NI04(push, NV50_3D(CB_DATA(0)), 4);
  472. PUSH_DATAf(push, 0.0f);
  473. PUSH_DATAf(push, 0.0f);
  474. PUSH_DATAf(push, 0.0f);
  475. PUSH_DATAf(push, 0.0f);
  476. BEGIN_NV04(push, NV50_3D(VERTEX_RUNOUT_ADDRESS_HIGH), 2);
  477. PUSH_DATAh(push, screen->uniforms->offset + (3 << 16) + NV50_CB_AUX_RUNOUT_OFFSET);
  478. PUSH_DATA (push, screen->uniforms->offset + (3 << 16) + NV50_CB_AUX_RUNOUT_OFFSET);
  479. nv50_upload_ms_info(push);
  480. /* max TIC (bits 4:8) & TSC bindings, per program type */
  481. for (i = 0; i < 3; ++i) {
  482. BEGIN_NV04(push, NV50_3D(TEX_LIMITS(i)), 1);
  483. PUSH_DATA (push, 0x54);
  484. }
  485. BEGIN_NV04(push, NV50_3D(TIC_ADDRESS_HIGH), 3);
  486. PUSH_DATAh(push, screen->txc->offset);
  487. PUSH_DATA (push, screen->txc->offset);
  488. PUSH_DATA (push, NV50_TIC_MAX_ENTRIES - 1);
  489. BEGIN_NV04(push, NV50_3D(TSC_ADDRESS_HIGH), 3);
  490. PUSH_DATAh(push, screen->txc->offset + 65536);
  491. PUSH_DATA (push, screen->txc->offset + 65536);
  492. PUSH_DATA (push, NV50_TSC_MAX_ENTRIES - 1);
  493. BEGIN_NV04(push, NV50_3D(LINKED_TSC), 1);
  494. PUSH_DATA (push, 0);
  495. BEGIN_NV04(push, NV50_3D(CLIP_RECTS_EN), 1);
  496. PUSH_DATA (push, 0);
  497. BEGIN_NV04(push, NV50_3D(CLIP_RECTS_MODE), 1);
  498. PUSH_DATA (push, NV50_3D_CLIP_RECTS_MODE_INSIDE_ANY);
  499. BEGIN_NV04(push, NV50_3D(CLIP_RECT_HORIZ(0)), 8 * 2);
  500. for (i = 0; i < 8 * 2; ++i)
  501. PUSH_DATA(push, 0);
  502. BEGIN_NV04(push, NV50_3D(CLIPID_ENABLE), 1);
  503. PUSH_DATA (push, 0);
  504. BEGIN_NV04(push, NV50_3D(VIEWPORT_TRANSFORM_EN), 1);
  505. PUSH_DATA (push, 1);
  506. for (i = 0; i < NV50_MAX_VIEWPORTS; i++) {
  507. BEGIN_NV04(push, NV50_3D(DEPTH_RANGE_NEAR(i)), 2);
  508. PUSH_DATAf(push, 0.0f);
  509. PUSH_DATAf(push, 1.0f);
  510. BEGIN_NV04(push, NV50_3D(VIEWPORT_HORIZ(i)), 2);
  511. PUSH_DATA (push, 8192 << 16);
  512. PUSH_DATA (push, 8192 << 16);
  513. }
  514. BEGIN_NV04(push, NV50_3D(VIEW_VOLUME_CLIP_CTRL), 1);
  515. #ifdef NV50_SCISSORS_CLIPPING
  516. PUSH_DATA (push, 0x0000);
  517. #else
  518. PUSH_DATA (push, 0x1080);
  519. #endif
  520. BEGIN_NV04(push, NV50_3D(CLEAR_FLAGS), 1);
  521. PUSH_DATA (push, NV50_3D_CLEAR_FLAGS_CLEAR_RECT_VIEWPORT);
  522. /* We use scissors instead of exact view volume clipping,
  523. * so they're always enabled.
  524. */
  525. for (i = 0; i < NV50_MAX_VIEWPORTS; i++) {
  526. BEGIN_NV04(push, NV50_3D(SCISSOR_ENABLE(i)), 3);
  527. PUSH_DATA (push, 1);
  528. PUSH_DATA (push, 8192 << 16);
  529. PUSH_DATA (push, 8192 << 16);
  530. }
  531. BEGIN_NV04(push, NV50_3D(RASTERIZE_ENABLE), 1);
  532. PUSH_DATA (push, 1);
  533. BEGIN_NV04(push, NV50_3D(POINT_RASTER_RULES), 1);
  534. PUSH_DATA (push, NV50_3D_POINT_RASTER_RULES_OGL);
  535. BEGIN_NV04(push, NV50_3D(FRAG_COLOR_CLAMP_EN), 1);
  536. PUSH_DATA (push, 0x11111111);
  537. BEGIN_NV04(push, NV50_3D(EDGEFLAG), 1);
  538. PUSH_DATA (push, 1);
  539. PUSH_KICK (push);
  540. }
  541. static int nv50_tls_alloc(struct nv50_screen *screen, unsigned tls_space,
  542. uint64_t *tls_size)
  543. {
  544. struct nouveau_device *dev = screen->base.device;
  545. int ret;
  546. screen->cur_tls_space = util_next_power_of_two(tls_space / ONE_TEMP_SIZE) *
  547. ONE_TEMP_SIZE;
  548. if (nouveau_mesa_debug)
  549. debug_printf("allocating space for %u temps\n",
  550. util_next_power_of_two(tls_space / ONE_TEMP_SIZE));
  551. *tls_size = screen->cur_tls_space * util_next_power_of_two(screen->TPs) *
  552. screen->MPsInTP * LOCAL_WARPS_ALLOC * THREADS_IN_WARP;
  553. ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16,
  554. *tls_size, NULL, &screen->tls_bo);
  555. if (ret) {
  556. NOUVEAU_ERR("Failed to allocate local bo: %d\n", ret);
  557. return ret;
  558. }
  559. return 0;
  560. }
  561. int nv50_tls_realloc(struct nv50_screen *screen, unsigned tls_space)
  562. {
  563. struct nouveau_pushbuf *push = screen->base.pushbuf;
  564. int ret;
  565. uint64_t tls_size;
  566. if (tls_space < screen->cur_tls_space)
  567. return 0;
  568. if (tls_space > screen->max_tls_space) {
  569. /* fixable by limiting number of warps (LOCAL_WARPS_LOG_ALLOC /
  570. * LOCAL_WARPS_NO_CLAMP) */
  571. NOUVEAU_ERR("Unsupported number of temporaries (%u > %u). Fixable if someone cares.\n",
  572. (unsigned)(tls_space / ONE_TEMP_SIZE),
  573. (unsigned)(screen->max_tls_space / ONE_TEMP_SIZE));
  574. return -ENOMEM;
  575. }
  576. nouveau_bo_ref(NULL, &screen->tls_bo);
  577. ret = nv50_tls_alloc(screen, tls_space, &tls_size);
  578. if (ret)
  579. return ret;
  580. BEGIN_NV04(push, NV50_3D(LOCAL_ADDRESS_HIGH), 3);
  581. PUSH_DATAh(push, screen->tls_bo->offset);
  582. PUSH_DATA (push, screen->tls_bo->offset);
  583. PUSH_DATA (push, util_logbase2(screen->cur_tls_space / 8));
  584. return 1;
  585. }
  586. struct pipe_screen *
  587. nv50_screen_create(struct nouveau_device *dev)
  588. {
  589. struct nv50_screen *screen;
  590. struct pipe_screen *pscreen;
  591. struct nouveau_object *chan;
  592. uint64_t value;
  593. uint32_t tesla_class;
  594. unsigned stack_size;
  595. int ret;
  596. screen = CALLOC_STRUCT(nv50_screen);
  597. if (!screen)
  598. return NULL;
  599. pscreen = &screen->base.base;
  600. ret = nouveau_screen_init(&screen->base, dev);
  601. if (ret) {
  602. NOUVEAU_ERR("nouveau_screen_init failed: %d\n", ret);
  603. goto fail;
  604. }
  605. /* TODO: Prevent FIFO prefetch before transfer of index buffers and
  606. * admit them to VRAM.
  607. */
  608. screen->base.vidmem_bindings |= PIPE_BIND_CONSTANT_BUFFER |
  609. PIPE_BIND_VERTEX_BUFFER;
  610. screen->base.sysmem_bindings |=
  611. PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER;
  612. screen->base.pushbuf->user_priv = screen;
  613. screen->base.pushbuf->rsvd_kick = 5;
  614. chan = screen->base.channel;
  615. pscreen->destroy = nv50_screen_destroy;
  616. pscreen->context_create = nv50_create;
  617. pscreen->is_format_supported = nv50_screen_is_format_supported;
  618. pscreen->get_param = nv50_screen_get_param;
  619. pscreen->get_shader_param = nv50_screen_get_shader_param;
  620. pscreen->get_paramf = nv50_screen_get_paramf;
  621. nv50_screen_init_resource_functions(pscreen);
  622. if (screen->base.device->chipset < 0x84 ||
  623. debug_get_bool_option("NOUVEAU_PMPEG", FALSE)) {
  624. /* PMPEG */
  625. nouveau_screen_init_vdec(&screen->base);
  626. } else if (screen->base.device->chipset < 0x98 ||
  627. screen->base.device->chipset == 0xa0) {
  628. /* VP2 */
  629. screen->base.base.get_video_param = nv84_screen_get_video_param;
  630. screen->base.base.is_video_format_supported = nv84_screen_video_supported;
  631. } else {
  632. /* VP3/4 */
  633. screen->base.base.get_video_param = nouveau_vp3_screen_get_video_param;
  634. screen->base.base.is_video_format_supported = nouveau_vp3_screen_video_supported;
  635. }
  636. ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, 4096,
  637. NULL, &screen->fence.bo);
  638. if (ret) {
  639. NOUVEAU_ERR("Failed to allocate fence bo: %d\n", ret);
  640. goto fail;
  641. }
  642. nouveau_bo_map(screen->fence.bo, 0, NULL);
  643. screen->fence.map = screen->fence.bo->map;
  644. screen->base.fence.emit = nv50_screen_fence_emit;
  645. screen->base.fence.update = nv50_screen_fence_update;
  646. ret = nouveau_object_new(chan, 0xbeef0301, NOUVEAU_NOTIFIER_CLASS,
  647. &(struct nv04_notify){ .length = 32 },
  648. sizeof(struct nv04_notify), &screen->sync);
  649. if (ret) {
  650. NOUVEAU_ERR("Failed to allocate notifier: %d\n", ret);
  651. goto fail;
  652. }
  653. ret = nouveau_object_new(chan, 0xbeef5039, NV50_M2MF_CLASS,
  654. NULL, 0, &screen->m2mf);
  655. if (ret) {
  656. NOUVEAU_ERR("Failed to allocate PGRAPH context for M2MF: %d\n", ret);
  657. goto fail;
  658. }
  659. ret = nouveau_object_new(chan, 0xbeef502d, NV50_2D_CLASS,
  660. NULL, 0, &screen->eng2d);
  661. if (ret) {
  662. NOUVEAU_ERR("Failed to allocate PGRAPH context for 2D: %d\n", ret);
  663. goto fail;
  664. }
  665. switch (dev->chipset & 0xf0) {
  666. case 0x50:
  667. tesla_class = NV50_3D_CLASS;
  668. break;
  669. case 0x80:
  670. case 0x90:
  671. tesla_class = NV84_3D_CLASS;
  672. break;
  673. case 0xa0:
  674. switch (dev->chipset) {
  675. case 0xa0:
  676. case 0xaa:
  677. case 0xac:
  678. tesla_class = NVA0_3D_CLASS;
  679. break;
  680. case 0xaf:
  681. tesla_class = NVAF_3D_CLASS;
  682. break;
  683. default:
  684. tesla_class = NVA3_3D_CLASS;
  685. break;
  686. }
  687. break;
  688. default:
  689. NOUVEAU_ERR("Not a known NV50 chipset: NV%02x\n", dev->chipset);
  690. goto fail;
  691. }
  692. screen->base.class_3d = tesla_class;
  693. ret = nouveau_object_new(chan, 0xbeef5097, tesla_class,
  694. NULL, 0, &screen->tesla);
  695. if (ret) {
  696. NOUVEAU_ERR("Failed to allocate PGRAPH context for 3D: %d\n", ret);
  697. goto fail;
  698. }
  699. /* This over-allocates by a page. The GP, which would execute at the end of
  700. * the last page, would trigger faults. The going theory is that it
  701. * prefetches up to a certain amount.
  702. */
  703. ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16,
  704. (3 << NV50_CODE_BO_SIZE_LOG2) + 0x1000,
  705. NULL, &screen->code);
  706. if (ret) {
  707. NOUVEAU_ERR("Failed to allocate code bo: %d\n", ret);
  708. goto fail;
  709. }
  710. nouveau_heap_init(&screen->vp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
  711. nouveau_heap_init(&screen->gp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
  712. nouveau_heap_init(&screen->fp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
  713. nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value);
  714. screen->TPs = util_bitcount(value & 0xffff);
  715. screen->MPsInTP = util_bitcount((value >> 24) & 0xf);
  716. stack_size = util_next_power_of_two(screen->TPs) * screen->MPsInTP *
  717. STACK_WARPS_ALLOC * 64 * 8;
  718. ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, stack_size, NULL,
  719. &screen->stack_bo);
  720. if (ret) {
  721. NOUVEAU_ERR("Failed to allocate stack bo: %d\n", ret);
  722. goto fail;
  723. }
  724. uint64_t size_of_one_temp = util_next_power_of_two(screen->TPs) *
  725. screen->MPsInTP * LOCAL_WARPS_ALLOC * THREADS_IN_WARP *
  726. ONE_TEMP_SIZE;
  727. screen->max_tls_space = dev->vram_size / size_of_one_temp * ONE_TEMP_SIZE;
  728. screen->max_tls_space /= 2; /* half of vram */
  729. /* hw can address max 64 KiB */
  730. screen->max_tls_space = MIN2(screen->max_tls_space, 64 << 10);
  731. uint64_t tls_size;
  732. unsigned tls_space = 4/*temps*/ * ONE_TEMP_SIZE;
  733. ret = nv50_tls_alloc(screen, tls_space, &tls_size);
  734. if (ret)
  735. goto fail;
  736. if (nouveau_mesa_debug)
  737. debug_printf("TPs = %u, MPsInTP = %u, VRAM = %"PRIu64" MiB, tls_size = %"PRIu64" KiB\n",
  738. screen->TPs, screen->MPsInTP, dev->vram_size >> 20, tls_size >> 10);
  739. ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 4 << 16, NULL,
  740. &screen->uniforms);
  741. if (ret) {
  742. NOUVEAU_ERR("Failed to allocate uniforms bo: %d\n", ret);
  743. goto fail;
  744. }
  745. ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 3 << 16, NULL,
  746. &screen->txc);
  747. if (ret) {
  748. NOUVEAU_ERR("Failed to allocate TIC/TSC bo: %d\n", ret);
  749. goto fail;
  750. }
  751. screen->tic.entries = CALLOC(4096, sizeof(void *));
  752. screen->tsc.entries = screen->tic.entries + 2048;
  753. if (!nv50_blitter_create(screen))
  754. goto fail;
  755. nv50_screen_init_hwctx(screen);
  756. nouveau_fence_new(&screen->base, &screen->base.fence.current, FALSE);
  757. return pscreen;
  758. fail:
  759. nv50_screen_destroy(pscreen);
  760. return NULL;
  761. }
  762. int
  763. nv50_screen_tic_alloc(struct nv50_screen *screen, void *entry)
  764. {
  765. int i = screen->tic.next;
  766. while (screen->tic.lock[i / 32] & (1 << (i % 32)))
  767. i = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1);
  768. screen->tic.next = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1);
  769. if (screen->tic.entries[i])
  770. nv50_tic_entry(screen->tic.entries[i])->id = -1;
  771. screen->tic.entries[i] = entry;
  772. return i;
  773. }
  774. int
  775. nv50_screen_tsc_alloc(struct nv50_screen *screen, void *entry)
  776. {
  777. int i = screen->tsc.next;
  778. while (screen->tsc.lock[i / 32] & (1 << (i % 32)))
  779. i = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1);
  780. screen->tsc.next = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1);
  781. if (screen->tsc.entries[i])
  782. nv50_tsc_entry(screen->tsc.entries[i])->id = -1;
  783. screen->tsc.entries[i] = entry;
  784. return i;
  785. }