Subversion Repositories Kolibri OS

Rev

Rev 3254 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3254 Rev 3255
1
/*
1
/*
2
 * Copyright © 2011 Intel Corporation
2
 * Copyright © 2011 Intel Corporation
3
 *
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the "Software"),
5
 * copy of this software and associated documentation files (the "Software"),
6
 * to deal in the Software without restriction, including without limitation
6
 * to deal in the Software without restriction, including without limitation
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
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
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:
9
 * Software is furnished to do so, subject to the following conditions:
10
 *
10
 *
11
 * The above copyright notice and this permission notice (including the next
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
12
 * paragraph) shall be included in all copies or substantial portions of the
13
 * Software.
13
 * Software.
14
 *
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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,
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
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
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,
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
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
 * SOFTWARE.
21
 * SOFTWARE.
22
 *
22
 *
23
 * Authors:
23
 * Authors:
24
 *    Chris Wilson 
24
 *    Chris Wilson 
25
 *
25
 *
26
 */
26
 */
27
 
27
 
28
#include "sna.h"
28
#include "sna.h"
29
#include "sna_render.h"
29
#include "sna_render.h"
30
#include "brw/brw.h"
30
#include "brw/brw.h"
31
 
31
 
32
int sna_static_stream_init(struct sna_static_stream *stream)
32
int sna_static_stream_init(struct sna_static_stream *stream)
33
{
33
{
34
	stream->used = 0;
34
	stream->used = 0;
35
	stream->size = 64*1024;
35
	stream->size = 64*1024;
36
 
36
 
37
	stream->data = malloc(stream->size);
37
	stream->data = malloc(stream->size);
38
	return stream->data != NULL;
38
	return stream->data != NULL;
39
}
39
}
40
 
40
 
41
static uint32_t sna_static_stream_alloc(struct sna_static_stream *stream,
41
static uint32_t sna_static_stream_alloc(struct sna_static_stream *stream,
42
					uint32_t len, uint32_t align)
42
					uint32_t len, uint32_t align)
43
{
43
{
44
	uint32_t offset = ALIGN(stream->used, align);
44
	uint32_t offset = ALIGN(stream->used, align);
45
	uint32_t size = offset + len;
45
	uint32_t size = offset + len;
46
 
46
 
47
	if (size > stream->size) {
47
	if (size > stream->size) {
48
		do
48
		do
49
			stream->size *= 2;
49
			stream->size *= 2;
50
		while (stream->size < size);
50
		while (stream->size < size);
51
 
51
 
52
		stream->data = realloc(stream->data, stream->size);
52
		stream->data = realloc(stream->data, stream->size);
53
	}
53
	}
54
 
54
 
55
	stream->used = size;
55
	stream->used = size;
56
	return offset;
56
	return offset;
57
}
57
}
58
 
58
 
59
uint32_t sna_static_stream_add(struct sna_static_stream *stream,
59
uint32_t sna_static_stream_add(struct sna_static_stream *stream,
60
			       const void *data, uint32_t len, uint32_t align)
60
			       const void *data, uint32_t len, uint32_t align)
61
{
61
{
62
	uint32_t offset = sna_static_stream_alloc(stream, len, align);
62
	uint32_t offset = sna_static_stream_alloc(stream, len, align);
63
	memcpy(stream->data + offset, data, len);
63
	memcpy(stream->data + offset, data, len);
64
	return offset;
64
	return offset;
65
}
65
}
66
 
66
 
67
void *sna_static_stream_map(struct sna_static_stream *stream,
67
void *sna_static_stream_map(struct sna_static_stream *stream,
68
			    uint32_t len, uint32_t align)
68
			    uint32_t len, uint32_t align)
69
{
69
{
70
	uint32_t offset = sna_static_stream_alloc(stream, len, align);
70
	uint32_t offset = sna_static_stream_alloc(stream, len, align);
71
	return memset(stream->data + offset, 0, len);
71
	return memset(stream->data + offset, 0, len);
72
}
72
}
73
 
73
 
74
uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream, void *ptr)
74
uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream, void *ptr)
75
{
75
{
76
	return (uint8_t *)ptr - stream->data;
76
	return (uint8_t *)ptr - stream->data;
77
}
77
}
78
 
78
 
79
struct kgem_bo *sna_static_stream_fini(struct sna *sna,
79
struct kgem_bo *sna_static_stream_fini(struct sna *sna,
80
				       struct sna_static_stream *stream)
80
				       struct sna_static_stream *stream)
81
{
81
{
82
	struct kgem_bo *bo;
82
	struct kgem_bo *bo;
83
 
83
 
84
	DBG(("uploaded %d bytes of static state\n", stream->used));
84
	DBG(("uploaded %d bytes of static state\n", stream->used));
85
 
85
 
86
	bo = kgem_create_linear(&sna->kgem, stream->used, 0);
86
	bo = kgem_create_linear(&sna->kgem, stream->used, 0);
87
	if (bo && !kgem_bo_write(&sna->kgem, bo, stream->data, stream->used)) {
87
	if (bo && !kgem_bo_write(&sna->kgem, bo, stream->data, stream->used)) {
88
//       kgem_bo_destroy(&sna->kgem, bo);
88
        kgem_bo_destroy(&sna->kgem, bo);
89
		return NULL;
89
		return NULL;
90
	}
90
	}
91
 
91
 
92
	free(stream->data);
92
	free(stream->data);
93
 
93
 
94
	return bo;
94
	return bo;
95
}
95
}
96
unsigned
96
unsigned
97
sna_static_stream_compile_wm(struct sna *sna,
97
sna_static_stream_compile_wm(struct sna *sna,
98
			     struct sna_static_stream *stream,
98
			     struct sna_static_stream *stream,
99
			     bool (*compile)(struct brw_compile *, int),
99
			     bool (*compile)(struct brw_compile *, int),
100
			     int dispatch_width)
100
			     int dispatch_width)
101
{
101
{
102
	struct brw_compile p;
102
	struct brw_compile p;
103
 
103
 
104
	brw_compile_init(&p, sna->kgem.gen,
104
	brw_compile_init(&p, sna->kgem.gen,
105
			 sna_static_stream_map(stream,
105
			 sna_static_stream_map(stream,
106
					       256*sizeof(uint32_t), 64));
106
					       256*sizeof(uint32_t), 64));
107
 
107
 
108
	if (!compile(&p, dispatch_width)) {
108
	if (!compile(&p, dispatch_width)) {
109
		stream->used -= 256*sizeof(uint32_t);
109
		stream->used -= 256*sizeof(uint32_t);
110
		return 0;
110
		return 0;
111
	}
111
	}
112
 
112
 
113
	assert(p.nr_insn*sizeof(struct brw_instruction) <= 256*sizeof(uint32_t));
113
	assert(p.nr_insn*sizeof(struct brw_instruction) <= 256*sizeof(uint32_t));
114
 
114
 
115
	stream->used -= 256*sizeof(uint32_t) - p.nr_insn*sizeof(struct brw_instruction);
115
	stream->used -= 256*sizeof(uint32_t) - p.nr_insn*sizeof(struct brw_instruction);
116
	return sna_static_stream_offsetof(stream, p.store);
116
	return sna_static_stream_offsetof(stream, p.store);
117
}
117
}