summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/ilo/ilo_context.c
blob: 714a9bf72c26910b264addcb02cd3604b93a6cdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Mesa 3-D graphics library
 *
 * Copyright (C) 2012-2013 LunarG, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *    Chia-I Wu <olv@lunarg.com>
 */

#include "intel_chipset.h"

#include "ilo_3d.h"
#include "ilo_blit.h"
#include "ilo_cp.h"
#include "ilo_gpgpu.h"
#include "ilo_query.h"
#include "ilo_resource.h"
#include "ilo_screen.h"
#include "ilo_state.h"
#include "ilo_video.h"
#include "ilo_context.h"

static void
ilo_context_new_cp_batch(struct ilo_cp *cp, void *data)
{
}

static void
ilo_context_pre_cp_flush(struct ilo_cp *cp, void *data)
{
}

static void
ilo_context_post_cp_flush(struct ilo_cp *cp, void *data)
{
   struct ilo_context *ilo = ilo_context(data);

   if (ilo->last_cp_bo)
      ilo->last_cp_bo->unreference(ilo->last_cp_bo);

   /* remember the just flushed bo, on which fences could wait */
   ilo->last_cp_bo = cp->bo;
   ilo->last_cp_bo->reference(ilo->last_cp_bo);
}

static void
ilo_flush(struct pipe_context *pipe,
          struct pipe_fence_handle **f,
          enum pipe_flush_flags flags)
{
   struct ilo_context *ilo = ilo_context(pipe);

   if (f) {
      struct ilo_fence *fence;

      fence = CALLOC_STRUCT(ilo_fence);
      if (fence) {
         pipe_reference_init(&fence->reference, 1);

         /* reference the batch bo that we want to wait on */
         if (ilo_cp_empty(ilo->cp))
            fence->bo = ilo->last_cp_bo;
         else
            fence->bo = ilo->cp->bo;

         if (fence->bo)
            fence->bo->reference(fence->bo);
      }

      *f = (struct pipe_fence_handle *) fence;
   }

   ilo_cp_flush(ilo->cp);
}

static void
ilo_context_destroy(struct pipe_context *pipe)
{
   struct ilo_context *ilo = ilo_context(pipe);

   if (ilo->last_cp_bo)
      ilo->last_cp_bo->unreference(ilo->last_cp_bo);

   if (ilo->cp)
      ilo_cp_destroy(ilo->cp);

   FREE(ilo);
}

static struct pipe_context *
ilo_context_create(struct pipe_screen *screen, void *priv)
{
   struct ilo_screen *is = ilo_screen(screen);
   struct ilo_context *ilo;

   ilo = CALLOC_STRUCT(ilo_context);
   if (!ilo)
      return NULL;

   ilo->winsys = is->winsys;
   ilo->devid = is->devid;
   ilo->gen = is->gen;

   if (IS_SNB_GT1(ilo->devid) ||
       IS_IVB_GT1(ilo->devid) ||
       IS_HSW_GT1(ilo->devid) ||
       IS_BAYTRAIL(ilo->devid))
      ilo->gt = 1;
   else if (IS_SNB_GT2(ilo->devid) ||
            IS_IVB_GT2(ilo->devid) ||
            IS_HSW_GT2(ilo->devid))
      ilo->gt = 2;
   else
      ilo->gt = 0;

   /* stolen from classic i965 */
   /* WM maximum threads is number of EUs times number of threads per EU. */
   if (ilo->gen >= ILO_GEN(7)) {
      if (ilo->gt == 1) {
	 ilo->max_wm_threads = 48;
	 ilo->max_vs_threads = 36;
	 ilo->max_gs_threads = 36;
	 ilo->urb.size = 128;
	 ilo->urb.max_vs_entries = 512;
	 ilo->urb.max_gs_entries = 192;
      } else if (ilo->gt == 2) {
	 ilo->max_wm_threads = 172;
	 ilo->max_vs_threads = 128;
	 ilo->max_gs_threads = 128;
	 ilo->urb.size = 256;
	 ilo->urb.max_vs_entries = 704;
	 ilo->urb.max_gs_entries = 320;
      } else {
	 assert(!"Unknown gen7 device.");
      }
   } else if (ilo->gen == ILO_GEN(6)) {
      if (ilo->gt == 2) {
	 ilo->max_wm_threads = 80;
	 ilo->max_vs_threads = 60;
	 ilo->max_gs_threads = 60;
	 ilo->urb.size = 64;            /* volume 5c.5 section 5.1 */
	 ilo->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */
	 ilo->urb.max_gs_entries = 256;
      } else {
	 ilo->max_wm_threads = 40;
	 ilo->max_vs_threads = 24;
	 ilo->max_gs_threads = 21; /* conservative; 24 if rendering disabled */
	 ilo->urb.size = 32;            /* volume 5c.5 section 5.1 */
	 ilo->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */
	 ilo->urb.max_gs_entries = 256;
      }
   }

   ilo->cp = ilo_cp_create(ilo->winsys, is->has_llc);
   if (!ilo->cp) {
      ilo_context_destroy(&ilo->base);
      return NULL;
   }

   ilo_cp_set_hook(ilo->cp, ILO_CP_HOOK_NEW_BATCH,
         ilo_context_new_cp_batch, (void *) ilo);
   ilo_cp_set_hook(ilo->cp, ILO_CP_HOOK_PRE_FLUSH,
         ilo_context_pre_cp_flush, (void *) ilo);
   ilo_cp_set_hook(ilo->cp, ILO_CP_HOOK_POST_FLUSH,
         ilo_context_post_cp_flush, (void *) ilo);

   ilo->base.screen = screen;
   ilo->base.priv = priv;

   ilo->base.destroy = ilo_context_destroy;
   ilo->base.flush = ilo_flush;

   ilo_init_3d_functions(ilo);
   ilo_init_query_functions(ilo);
   ilo_init_state_functions(ilo);
   ilo_init_blit_functions(ilo);
   ilo_init_transfer_functions(ilo);
   ilo_init_video_functions(ilo);
   ilo_init_gpgpu_functions(ilo);

   return &ilo->base;
}

/**
 * Initialize context-related functions.
 */
void
ilo_init_context_functions(struct ilo_screen *is)
{
   is->base.context_create = ilo_context_create;
}