• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 2012-2013 LunarG, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the 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 NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Chia-I Wu <olv@lunarg.com>
26  */
27 
28 #ifndef ILO_CP_H
29 #define ILO_CP_H
30 
31 #include "core/ilo_builder.h"
32 #include "core/intel_winsys.h"
33 
34 #include "ilo_common.h"
35 
36 struct ilo_cp;
37 struct ilo_shader_cache;
38 
39 typedef void (*ilo_cp_callback)(struct ilo_cp *cp, void *data);
40 
41 /**
42  * Parser owners are notified when they gain or lose the ownership of the
43  * parser.  This gives owners a chance to emit prolog or epilog.
44  */
45 struct ilo_cp_owner {
46    ilo_cp_callback own;
47    ilo_cp_callback release;
48    void *data;
49 
50    /*
51     * Space reserved for release().  This can be modified at any time, as long
52     * as it is never increased by more than ilo_cp_space().
53     */
54    int reserve;
55 };
56 
57 /**
58  * Command parser.
59  */
60 struct ilo_cp {
61    struct intel_winsys *winsys;
62    struct ilo_shader_cache *shader_cache;
63    struct intel_context *render_ctx;
64 
65    ilo_cp_callback submit_callback;
66    void *submit_callback_data;
67 
68    enum intel_ring_type ring;
69    const struct ilo_cp_owner *owner;
70 
71    unsigned one_off_flags;
72 
73    struct ilo_builder builder;
74    struct intel_bo *last_submitted_bo;
75 
76    uint32_t active_lost;
77    uint32_t pending_lost;
78 };
79 
80 struct ilo_cp *
81 ilo_cp_create(const struct ilo_dev *dev,
82               struct intel_winsys *winsys,
83               struct ilo_shader_cache *shc);
84 
85 void
86 ilo_cp_destroy(struct ilo_cp *cp);
87 
88 void
89 ilo_cp_submit_internal(struct ilo_cp *cp);
90 
91 static inline void
ilo_cp_submit(struct ilo_cp * cp,const char * reason)92 ilo_cp_submit(struct ilo_cp *cp, const char *reason)
93 {
94    if (ilo_debug & ILO_DEBUG_SUBMIT) {
95       ilo_printf("submit batch buffer to %s ring because of %s: ",
96             (cp->ring == INTEL_RING_RENDER) ? "render" : "unknown", reason);
97       ilo_builder_batch_print_stats(&cp->builder);
98    }
99 
100    ilo_cp_submit_internal(cp);
101 }
102 
103 void
104 ilo_cp_set_owner(struct ilo_cp *cp, enum intel_ring_type ring,
105                  const struct ilo_cp_owner *owner);
106 
107 /**
108  * Return the remaining space (in dwords) in the parser buffer.
109  */
110 static inline int
ilo_cp_space(struct ilo_cp * cp)111 ilo_cp_space(struct ilo_cp *cp)
112 {
113    const int space = ilo_builder_batch_space(&cp->builder);
114    const int mi_batch_buffer_end_space = 2;
115 
116    assert(space >= cp->owner->reserve + mi_batch_buffer_end_space);
117 
118    return space - cp->owner->reserve - mi_batch_buffer_end_space;
119 }
120 
121 /**
122  * Set one-off flags.  They will be cleared after submission.
123  */
124 static inline void
ilo_cp_set_one_off_flags(struct ilo_cp * cp,unsigned flags)125 ilo_cp_set_one_off_flags(struct ilo_cp *cp, unsigned flags)
126 {
127    cp->one_off_flags |= flags;
128 }
129 
130 /**
131  * Set submit callback.  The callback is invoked after the bo has been
132  * successfully submitted, and before the bo is reallocated.
133  */
134 static inline void
ilo_cp_set_submit_callback(struct ilo_cp * cp,ilo_cp_callback callback,void * data)135 ilo_cp_set_submit_callback(struct ilo_cp *cp, ilo_cp_callback callback,
136                           void *data)
137 {
138    cp->submit_callback = callback;
139    cp->submit_callback_data = data;
140 }
141 
142 #endif /* ILO_CP_H */
143