Rev 4359 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4304 | Serge | 1 | /* |
2 | * Copyright © 2011 Intel Corporation |
||
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 (including the next |
||
12 | * paragraph) shall be included in all copies or substantial portions of the |
||
13 | * Software. |
||
14 | * |
||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||
21 | * SOFTWARE. |
||
22 | * |
||
23 | * Authors: |
||
24 | * Chris Wilson |
||
25 | * |
||
26 | */ |
||
27 | |||
28 | #include "sna.h" |
||
29 | #include "sna_render.h" |
||
30 | #include "brw/brw.h" |
||
31 | #include |
||
32 | |||
33 | int sna_static_stream_init(struct sna_static_stream *stream) |
||
34 | { |
||
35 | stream->used = 0; |
||
36 | stream->size = 64*1024; |
||
37 | |||
38 | stream->data = malloc(stream->size); |
||
39 | return stream->data != NULL; |
||
40 | } |
||
41 | |||
42 | static uint32_t sna_static_stream_alloc(struct sna_static_stream *stream, |
||
43 | uint32_t len, uint32_t align) |
||
44 | { |
||
45 | uint32_t offset = ALIGN(stream->used, align); |
||
46 | uint32_t size = offset + len; |
||
47 | |||
48 | if (size > stream->size) { |
||
49 | do |
||
50 | stream->size *= 2; |
||
51 | while (stream->size < size); |
||
52 | |||
53 | stream->data = realloc(stream->data, stream->size); |
||
54 | } |
||
55 | |||
56 | stream->used = size; |
||
57 | return offset; |
||
58 | } |
||
59 | |||
60 | uint32_t sna_static_stream_add(struct sna_static_stream *stream, |
||
61 | const void *data, uint32_t len, uint32_t align) |
||
62 | { |
||
63 | uint32_t offset = sna_static_stream_alloc(stream, len, align); |
||
64 | memcpy(stream->data + offset, data, len); |
||
65 | return offset; |
||
66 | } |
||
67 | |||
68 | void *sna_static_stream_map(struct sna_static_stream *stream, |
||
69 | uint32_t len, uint32_t align) |
||
70 | { |
||
71 | uint32_t offset = sna_static_stream_alloc(stream, len, align); |
||
72 | return memset(stream->data + offset, 0, len); |
||
73 | } |
||
74 | |||
75 | uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream, void *ptr) |
||
76 | { |
||
77 | return (uint8_t *)ptr - stream->data; |
||
78 | } |
||
79 | |||
80 | struct kgem_bo *sna_static_stream_fini(struct sna *sna, |
||
81 | struct sna_static_stream *stream) |
||
82 | { |
||
83 | struct kgem_bo *bo; |
||
84 | |||
85 | DBG(("uploaded %d bytes of static state\n", stream->used)); |
||
86 | |||
87 | if (DEBUG_DUMP) |
||
88 | { |
||
89 | int fd = open("/tmp1/1/static.bin", O_CREAT|O_WRONLY|O_BINARY); |
||
90 | if (fd != -1) { |
||
91 | write(fd, stream->data, stream->used); |
||
92 | close(fd); |
||
93 | } |
||
94 | else |
||
95 | { |
||
96 | printf("SNA: failed to write static stream\n"); |
||
97 | asm volatile("int3"); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | |||
102 | bo = kgem_create_linear(&sna->kgem, stream->used, 0); |
||
103 | if (bo && !kgem_bo_write(&sna->kgem, bo, stream->data, stream->used)) { |
||
104 | kgem_bo_destroy(&sna->kgem, bo); |
||
105 | return NULL; |
||
106 | } |
||
107 | |||
108 | free(stream->data); |
||
109 | |||
110 | return bo; |
||
111 | } |
||
112 | |||
113 | unsigned |
||
114 | sna_static_stream_compile_sf(struct sna *sna, |
||
115 | struct sna_static_stream *stream, |
||
116 | bool (*compile)(struct brw_compile *)) |
||
117 | { |
||
118 | struct brw_compile p; |
||
119 | |||
120 | brw_compile_init(&p, sna->kgem.gen, |
||
121 | sna_static_stream_map(stream, |
||
122 | 64*sizeof(uint32_t), 64)); |
||
123 | |||
124 | if (!compile(&p)) { |
||
125 | stream->used -= 64*sizeof(uint32_t); |
||
126 | return 0; |
||
127 | } |
||
128 | |||
129 | assert(p.nr_insn*sizeof(struct brw_instruction) <= 64*sizeof(uint32_t)); |
||
130 | |||
131 | stream->used -= 64*sizeof(uint32_t) - p.nr_insn*sizeof(struct brw_instruction); |
||
132 | return sna_static_stream_offsetof(stream, p.store); |
||
133 | } |
||
134 | |||
135 | unsigned |
||
136 | sna_static_stream_compile_wm(struct sna *sna, |
||
137 | struct sna_static_stream *stream, |
||
138 | bool (*compile)(struct brw_compile *, int), |
||
139 | int dispatch_width) |
||
140 | { |
||
141 | struct brw_compile p; |
||
142 | |||
143 | brw_compile_init(&p, sna->kgem.gen, |
||
144 | sna_static_stream_map(stream, |
||
145 | 256*sizeof(uint32_t), 64)); |
||
146 | |||
147 | if (!compile(&p, dispatch_width)) { |
||
148 | stream->used -= 256*sizeof(uint32_t); |
||
149 | return 0; |
||
150 | } |
||
151 | |||
152 | assert(p.nr_insn*sizeof(struct brw_instruction) <= 256*sizeof(uint32_t)); |
||
153 | |||
154 | stream->used -= 256*sizeof(uint32_t) - p.nr_insn*sizeof(struct brw_instruction); |
||
155 | return sna_static_stream_offsetof(stream, p.store); |
||
156 | }=>=>> |