aboutsummaryrefslogtreecommitdiff
path: root/src/wld/intel/batch.h
blob: cc9d1d908be577d2843f302498b0e8a032cac788 (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
/* wld: intel/batch.h
 *
 * Copyright (c) 2013, 2014 Michael Forney
 *
 * 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.
 */

#ifndef WLD_INTEL_BATCH_H
#define WLD_INTEL_BATCH_H

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <intel_bufmgr.h>

#define INTEL_BATCH_MAX_COMMANDS (1 << 13)
#define INTEL_BATCH_RESERVED_COMMANDS 2
#define INTEL_BATCH_SIZE (INTEL_BATCH_MAX_COMMANDS << 2)

enum intel_batch_result
{
    INTEL_BATCH_SUCCESS,
    INTEL_BATCH_NO_SPACE
};

struct intel_device_info
{
    int gen;
};

#define GEN(b, m) ((b)->device_info->gen >= (m))

struct intel_batch
{
    const struct intel_device_info * device_info;
    drm_intel_bo * bo;
    uint32_t commands[INTEL_BATCH_MAX_COMMANDS];
    uint32_t command_count;
};

bool intel_batch_initialize(struct intel_batch * batch,
                            drm_intel_bufmgr * bufmgr);

void intel_batch_finalize(struct intel_batch * batch);

void intel_batch_flush(struct intel_batch * batch);

static inline uint32_t intel_batch_check_space(struct intel_batch * batch,
                                               uint32_t size)
{
    return (INTEL_BATCH_MAX_COMMANDS - INTEL_BATCH_RESERVED_COMMANDS
            - batch->command_count) >= size;
}

static inline void intel_batch_ensure_space(struct intel_batch * batch, uint32_t size)
{
    if (!intel_batch_check_space(batch, size))
        intel_batch_flush(batch);
}

static inline void intel_batch_add_dword(struct intel_batch * batch,
                                         uint32_t dword)
{
    batch->commands[batch->command_count++] = dword;
}

static inline void intel_batch_add_dwords_va(struct intel_batch * batch,
                                             uint32_t count, va_list dwords)
{
    while (count--)
        intel_batch_add_dword(batch, va_arg(dwords, uint32_t));
}

static inline void intel_batch_add_dwords(struct intel_batch * batch,
                                          uint32_t count, ...)
{
    va_list dwords;
    va_start(dwords, count);
    intel_batch_add_dwords_va(batch, count, dwords);
    va_end(dwords);
}

static inline uint32_t intel_batch_offset(struct intel_batch * batch,
                                         uint32_t command_index)
{
    return (batch->command_count + command_index) << 2;
}

#endif