aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/drm/intel/gem/intel_be_context.c
blob: 95e761d78d0f8050010992909c43ef5d4656e007 (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

#include "intel_be_device.h"
#include "intel_be_context.h"
#include "intel_be_batchbuffer.h"

#include "i915_drm.h"

static struct i915_batchbuffer *
intel_be_batch_get(struct i915_winsys *sws)
{
	struct intel_be_context *intel = intel_be_context(sws);
	return &intel->batch->base;
}

static void
intel_be_batch_reloc(struct i915_winsys *sws,
		     struct pipe_buffer *buf,
		     unsigned access_flags,
		     unsigned delta)
{
	struct intel_be_context *intel = intel_be_context(sws);
	drm_intel_bo *bo = intel_bo(buf);
	int ret;
	uint32_t read = 0;
	uint32_t write = 0;

	if (access_flags & I915_BUFFER_ACCESS_WRITE) {
		write = I915_GEM_DOMAIN_RENDER;
		read = I915_GEM_DOMAIN_RENDER;
	}

	if (access_flags & I915_BUFFER_ACCESS_READ) {
		read |= I915_GEM_DOMAIN_VERTEX;
	}

	ret = intel_be_offset_relocation(intel->batch,
	                                 delta,
	                                 bo,
	                                 read,
	                                 write);
    assert(ret == 0);

	/* TODO change return type */
	/* return ret; */
}

static void
intel_be_batch_flush(struct i915_winsys *sws,
		     struct pipe_fence_handle **fence)
{
	struct intel_be_context *intel = intel_be_context(sws);
	struct intel_be_fence **f = (struct intel_be_fence **)fence;

	if (fence && *fence)
		assert(0);

	intel_be_batchbuffer_flush(intel->batch, f);
}

boolean
intel_be_init_context(struct intel_be_context *intel, struct intel_be_device *device)
{
	assert(intel);
	assert(device);
	intel->device = device;

	intel->base.batch_get = intel_be_batch_get;
	intel->base.batch_reloc = intel_be_batch_reloc;
	intel->base.batch_flush = intel_be_batch_flush;

	intel->batch = intel_be_batchbuffer_alloc(intel);

	return true;
}

void
intel_be_destroy_context(struct intel_be_context *intel)
{
	intel_be_batchbuffer_free(intel->batch);
}