ace439239e2909b99382fd584183aceaf657d782
[platform/upstream/intel-gpu-tools.git] / lib / rendercopy.h
1 #ifndef RENDERCOPY_H
2 #define RENDERCOPY_H
3
4 #include <stdlib.h>
5 #include <sys/ioctl.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <assert.h>
9 #include <fcntl.h>
10 #include <inttypes.h>
11 #include <errno.h>
12 #include <sys/stat.h>
13 #include <sys/time.h>
14 #include <getopt.h>
15 #include "drm.h"
16 #include "i915_drm.h"
17 #include "drmtest.h"
18 #include "intel_bufmgr.h"
19 #include "intel_batchbuffer.h"
20 #include "intel_gpu_tools.h"
21
22 struct scratch_buf {
23     drm_intel_bo *bo;
24     uint32_t stride;
25     uint32_t tiling;
26     uint32_t *data;
27     uint32_t *cpu_mapping;
28     uint32_t size;
29     unsigned num_tiles;
30 };
31
32 static inline void emit_vertex_2s(struct intel_batchbuffer *batch,
33                                   int16_t x, int16_t y)
34 {
35         OUT_BATCH((uint16_t)y << 16 | (uint16_t)x);
36 }
37
38 static inline void emit_vertex(struct intel_batchbuffer *batch,
39                                float f)
40 {
41         union { float f; uint32_t ui; } u;
42         u.f = f;
43         OUT_BATCH(u.ui);
44 }
45
46 static inline void emit_vertex_normalized(struct intel_batchbuffer *batch,
47                                           float f, float total)
48 {
49         union { float f; uint32_t ui; } u;
50         u.f = f / total;
51         OUT_BATCH(u.ui);
52 }
53
54 static inline unsigned buf_width(struct scratch_buf *buf)
55 {
56         return buf->stride/sizeof(uint32_t);
57 }
58
59 static inline unsigned buf_height(struct scratch_buf *buf)
60 {
61         return buf->size/buf->stride;
62 }
63
64 typedef void (*render_copyfunc_t)(struct intel_batchbuffer *batch,
65                                   struct scratch_buf *src, unsigned src_x, unsigned src_y,
66                                   unsigned width, unsigned height,
67                                   struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
68
69 render_copyfunc_t get_render_copyfunc(int devid);
70
71 void gen7_render_copyfunc(struct intel_batchbuffer *batch,
72                           struct scratch_buf *src, unsigned src_x, unsigned src_y,
73                           unsigned width, unsigned height,
74                           struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
75 void gen6_render_copyfunc(struct intel_batchbuffer *batch,
76                           struct scratch_buf *src, unsigned src_x, unsigned src_y,
77                           unsigned width, unsigned height,
78                           struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
79 void gen3_render_copyfunc(struct intel_batchbuffer *batch,
80                           struct scratch_buf *src, unsigned src_x, unsigned src_y,
81                           unsigned width, unsigned height,
82                           struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
83 void gen2_render_copyfunc(struct intel_batchbuffer *batch,
84                           struct scratch_buf *src, unsigned src_x, unsigned src_y,
85                           unsigned width, unsigned height,
86                           struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
87
88 void scratch_buf_write_to_png(struct scratch_buf *buf, const char *filename);
89
90 #endif /* RENDERCOPY_H */