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.

libdrm-nouveau-better-relocs.patch 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. diff --git a/libdrm/nouveau/nouveau_bo.c b/libdrm/nouveau/nouveau_bo.c
  2. index b7e6d86..85fc14f 100644
  3. --- a/libdrm/nouveau/nouveau_bo.c
  4. +++ b/libdrm/nouveau/nouveau_bo.c
  5. @@ -607,6 +607,7 @@ nouveau_bo_emit_buffer(struct nouveau_channel *chan, struct nouveau_bo *bo)
  6. pbbo = nvpb->buffers + nvpb->nr_buffers++;
  7. nvbo->pending = pbbo;
  8. nvbo->pending_channel = chan;
  9. + nvbo->pending_refcnt = 0;
  10. nouveau_bo_ref(bo, &ref);
  11. pbbo->user_priv = (uint64_t)(unsigned long)ref;
  12. diff --git a/libdrm/nouveau/nouveau_private.h b/libdrm/nouveau/nouveau_private.h
  13. index 9ce87fb..784afc9 100644
  14. --- a/libdrm/nouveau/nouveau_private.h
  15. +++ b/libdrm/nouveau/nouveau_private.h
  16. @@ -52,6 +52,9 @@ struct nouveau_pushbuf_priv {
  17. unsigned *pushbuf;
  18. unsigned size;
  19. + unsigned marker;
  20. + unsigned marker_relocs;
  21. +
  22. struct drm_nouveau_gem_pushbuf_bo *buffers;
  23. unsigned nr_buffers;
  24. struct drm_nouveau_gem_pushbuf_reloc *relocs;
  25. @@ -99,6 +102,7 @@ struct nouveau_bo_priv {
  26. /* Tracking */
  27. struct drm_nouveau_gem_pushbuf_bo *pending;
  28. struct nouveau_channel *pending_channel;
  29. + int pending_refcnt;
  30. int write_marker;
  31. /* Userspace object */
  32. diff --git a/libdrm/nouveau/nouveau_pushbuf.c b/libdrm/nouveau/nouveau_pushbuf.c
  33. index d434a5f..90250c0 100644
  34. --- a/libdrm/nouveau/nouveau_pushbuf.c
  35. +++ b/libdrm/nouveau/nouveau_pushbuf.c
  36. @@ -60,17 +60,17 @@ nouveau_pushbuf_emit_reloc(struct nouveau_channel *chan, void *ptr,
  37. uint32_t flags, uint32_t vor, uint32_t tor)
  38. {
  39. struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(chan->pushbuf);
  40. + struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
  41. struct drm_nouveau_gem_pushbuf_reloc *r;
  42. struct drm_nouveau_gem_pushbuf_bo *pbbo;
  43. uint32_t domains = 0;
  44. if (nvpb->nr_relocs >= NOUVEAU_GEM_MAX_RELOCS) {
  45. fprintf(stderr, "too many relocs!!\n");
  46. - assert(0);
  47. return -ENOMEM;
  48. }
  49. - if (nouveau_bo(bo)->user && (flags & NOUVEAU_BO_WR)) {
  50. + if (nvbo->user && (flags & NOUVEAU_BO_WR)) {
  51. fprintf(stderr, "write to user buffer!!\n");
  52. return -EINVAL;
  53. }
  54. @@ -78,16 +78,21 @@ nouveau_pushbuf_emit_reloc(struct nouveau_channel *chan, void *ptr,
  55. pbbo = nouveau_bo_emit_buffer(chan, bo);
  56. if (!pbbo) {
  57. fprintf(stderr, "buffer emit fail :(\n");
  58. - assert(0);
  59. return -ENOMEM;
  60. }
  61. + nvbo->pending_refcnt++;
  62. +
  63. if (flags & NOUVEAU_BO_VRAM)
  64. domains |= NOUVEAU_GEM_DOMAIN_VRAM;
  65. if (flags & NOUVEAU_BO_GART)
  66. domains |= NOUVEAU_GEM_DOMAIN_GART;
  67. +
  68. + if (!(pbbo->valid_domains & domains)) {
  69. + fprintf(stderr, "no valid domains remain!\n");
  70. + return -EINVAL;
  71. + }
  72. pbbo->valid_domains &= domains;
  73. - assert(pbbo->valid_domains);
  74. assert(flags & NOUVEAU_BO_RDWR);
  75. if (flags & NOUVEAU_BO_RD) {
  76. @@ -95,7 +100,7 @@ nouveau_pushbuf_emit_reloc(struct nouveau_channel *chan, void *ptr,
  77. }
  78. if (flags & NOUVEAU_BO_WR) {
  79. pbbo->write_domains |= domains;
  80. - nouveau_bo(bo)->write_marker = 1;
  81. + nvbo->write_marker = 1;
  82. }
  83. r = nvpb->relocs + nvpb->nr_relocs++;
  84. @@ -322,18 +327,25 @@ restart_push:
  85. /* Update presumed offset/domain for any buffers that moved.
  86. * Dereference all buffers on validate list
  87. */
  88. - for (i = 0; i < nvpb->nr_buffers; i++) {
  89. - struct drm_nouveau_gem_pushbuf_bo *pbbo = &nvpb->buffers[i];
  90. + for (i = 0; i < nvpb->nr_relocs; i++) {
  91. + struct drm_nouveau_gem_pushbuf_reloc *r = &nvpb->relocs[i];
  92. + struct drm_nouveau_gem_pushbuf_bo *pbbo =
  93. + &nvpb->buffers[r->bo_index];
  94. struct nouveau_bo *bo = (void *)(unsigned long)pbbo->user_priv;
  95. + struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
  96. +
  97. + if (--nvbo->pending_refcnt)
  98. + continue;
  99. if (pbbo->presumed_ok == 0) {
  100. - nouveau_bo(bo)->domain = pbbo->presumed_domain;
  101. - nouveau_bo(bo)->offset = pbbo->presumed_offset;
  102. + nvbo->domain = pbbo->presumed_domain;
  103. + nvbo->offset = pbbo->presumed_offset;
  104. }
  105. - nouveau_bo(bo)->pending = NULL;
  106. + nvbo->pending = NULL;
  107. nouveau_bo_ref(NULL, &bo);
  108. }
  109. +
  110. nvpb->nr_buffers = 0;
  111. nvpb->nr_relocs = 0;
  112. @@ -343,6 +355,57 @@ restart_push:
  113. if (chan->flush_notify)
  114. chan->flush_notify(chan);
  115. + nvpb->marker = 0;
  116. return ret;
  117. }
  118. +int
  119. +nouveau_pushbuf_marker_emit(struct nouveau_channel *chan,
  120. + unsigned wait_dwords, unsigned wait_relocs)
  121. +{
  122. + struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(chan->pushbuf);
  123. +
  124. + if (AVAIL_RING(chan) < wait_dwords)
  125. + return nouveau_pushbuf_flush(chan, wait_dwords);
  126. +
  127. + if (nvpb->nr_relocs + wait_relocs >= NOUVEAU_GEM_MAX_RELOCS)
  128. + return nouveau_pushbuf_flush(chan, wait_dwords);
  129. +
  130. + nvpb->marker = nvpb->base.cur - nvpb->pushbuf;
  131. + nvpb->marker_relocs = nvpb->nr_relocs;
  132. + return 0;
  133. +}
  134. +
  135. +void
  136. +nouveau_pushbuf_marker_undo(struct nouveau_channel *chan)
  137. +{
  138. + struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(chan->pushbuf);
  139. + unsigned i;
  140. +
  141. + if (!nvpb->marker)
  142. + return;
  143. +
  144. + /* undo any relocs/buffers added to the list since last marker */
  145. + for (i = nvpb->marker_relocs; i < nvpb->nr_relocs; i++) {
  146. + struct drm_nouveau_gem_pushbuf_reloc *r = &nvpb->relocs[i];
  147. + struct drm_nouveau_gem_pushbuf_bo *pbbo =
  148. + &nvpb->buffers[r->bo_index];
  149. + struct nouveau_bo *bo = (void *)(unsigned long)pbbo->user_priv;
  150. + struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
  151. +
  152. + if (--nvbo->pending_refcnt)
  153. + continue;
  154. +
  155. + nvbo->pending = NULL;
  156. + nouveau_bo_ref(NULL, &bo);
  157. + nvpb->nr_buffers--;
  158. + }
  159. + nvpb->nr_relocs = nvpb->marker_relocs;
  160. +
  161. + /* reset pushbuf back to last marker */
  162. + nvpb->base.cur = nvpb->pushbuf + nvpb->marker;
  163. + nvpb->base.remaining = nvpb->size - nvpb->marker;
  164. + nvpb->marker = 0;
  165. +}
  166. +
  167. +
  168. diff --git a/libdrm/nouveau/nouveau_pushbuf.h b/libdrm/nouveau/nouveau_pushbuf.h
  169. index 3c746ed..c7ac8c4 100644
  170. --- a/libdrm/nouveau/nouveau_pushbuf.h
  171. +++ b/libdrm/nouveau/nouveau_pushbuf.h
  172. @@ -40,11 +40,30 @@ int
  173. nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
  174. int
  175. +nouveau_pushbuf_marker_emit(struct nouveau_channel *chan,
  176. + unsigned wait_dwords, unsigned wait_relocs);
  177. +
  178. +void
  179. +nouveau_pushbuf_marker_undo(struct nouveau_channel *chan);
  180. +
  181. +int
  182. nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
  183. struct nouveau_bo *, uint32_t data, uint32_t data2,
  184. uint32_t flags, uint32_t vor, uint32_t tor);
  185. /* Push buffer access macros */
  186. +static __inline__ int
  187. +MARK_RING(struct nouveau_channel *chan, unsigned dwords, unsigned relocs)
  188. +{
  189. + return nouveau_pushbuf_marker_emit(chan, dwords, relocs);
  190. +}
  191. +
  192. +static __inline__ void
  193. +MARK_UNDO(struct nouveau_channel *chan)
  194. +{
  195. + nouveau_pushbuf_marker_undo(chan);
  196. +}
  197. +
  198. static __inline__ void
  199. OUT_RING(struct nouveau_channel *chan, unsigned data)
  200. {
  201. @@ -116,62 +135,62 @@ BIND_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr, unsigned sc)
  202. OUT_RING (chan, gr->handle);
  203. }
  204. -static __inline__ void
  205. +static __inline__ int
  206. OUT_RELOC(struct nouveau_channel *chan, struct nouveau_bo *bo,
  207. unsigned data, unsigned flags, unsigned vor, unsigned tor)
  208. {
  209. - nouveau_pushbuf_emit_reloc(chan, chan->pushbuf->cur++, bo,
  210. - data, 0, flags, vor, tor);
  211. + return nouveau_pushbuf_emit_reloc(chan, chan->pushbuf->cur++, bo,
  212. + data, 0, flags, vor, tor);
  213. }
  214. -static __inline__ void
  215. +static __inline__ int
  216. OUT_RELOC2(struct nouveau_channel *chan, struct nouveau_bo *bo,
  217. unsigned data, unsigned data2, unsigned flags,
  218. unsigned vor, unsigned tor)
  219. {
  220. - nouveau_pushbuf_emit_reloc(chan, chan->pushbuf->cur++, bo,
  221. - data, data2, flags, vor, tor);
  222. + return nouveau_pushbuf_emit_reloc(chan, chan->pushbuf->cur++, bo,
  223. + data, data2, flags, vor, tor);
  224. }
  225. /* Raw data + flags depending on FB/TT buffer */
  226. -static __inline__ void
  227. +static __inline__ int
  228. OUT_RELOCd(struct nouveau_channel *chan, struct nouveau_bo *bo,
  229. unsigned data, unsigned flags, unsigned vor, unsigned tor)
  230. {
  231. - OUT_RELOC(chan, bo, data, flags | NOUVEAU_BO_OR, vor, tor);
  232. + return OUT_RELOC(chan, bo, data, flags | NOUVEAU_BO_OR, vor, tor);
  233. }
  234. /* FB/TT object handle */
  235. -static __inline__ void
  236. +static __inline__ int
  237. OUT_RELOCo(struct nouveau_channel *chan, struct nouveau_bo *bo,
  238. unsigned flags)
  239. {
  240. - OUT_RELOC(chan, bo, 0, flags | NOUVEAU_BO_OR,
  241. - chan->vram->handle, chan->gart->handle);
  242. + return OUT_RELOC(chan, bo, 0, flags | NOUVEAU_BO_OR,
  243. + chan->vram->handle, chan->gart->handle);
  244. }
  245. /* Low 32-bits of offset */
  246. -static __inline__ void
  247. +static __inline__ int
  248. OUT_RELOCl(struct nouveau_channel *chan, struct nouveau_bo *bo,
  249. unsigned delta, unsigned flags)
  250. {
  251. - OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_LOW, 0, 0);
  252. + return OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_LOW, 0, 0);
  253. }
  254. /* Low 32-bits of offset + GPU linear access range info */
  255. -static __inline__ void
  256. +static __inline__ int
  257. OUT_RELOCr(struct nouveau_channel *chan, struct nouveau_bo *bo,
  258. unsigned delta, unsigned size, unsigned flags)
  259. {
  260. - OUT_RELOC2(chan, bo, delta, size, flags | NOUVEAU_BO_LOW, 0, 0);
  261. + return OUT_RELOC2(chan, bo, delta, size, flags | NOUVEAU_BO_LOW, 0, 0);
  262. }
  263. /* High 32-bits of offset */
  264. -static __inline__ void
  265. +static __inline__ int
  266. OUT_RELOCh(struct nouveau_channel *chan, struct nouveau_bo *bo,
  267. unsigned delta, unsigned flags)
  268. {
  269. - OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_HIGH, 0, 0);
  270. + return OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_HIGH, 0, 0);
  271. }
  272. #endif