Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
 
3
/*
4
 * Copyright (C) 2012 Rob Clark 
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice (including the next
14
 * paragraph) shall be included in all copies or substantial portions of the
15
 * Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 *
25
 * Authors:
26
 *    Rob Clark 
27
 */
28
 
29
#ifndef FREEDRENO_RESOURCE_H_
30
#define FREEDRENO_RESOURCE_H_
31
 
32
#include "util/list.h"
33
#include "util/u_range.h"
34
#include "util/u_transfer.h"
35
 
36
#include "freedreno_util.h"
37
 
38
/* Texture Layout on a3xx:
39
 *
40
 * Each mipmap-level contains all of it's layers (ie. all cubmap
41
 * faces, all 1d/2d array elements, etc).  The texture sampler is
42
 * programmed with the start address of each mipmap level, and hw
43
 * derives the layer offset within the level.
44
 *
45
 * Texture Layout on a4xx:
46
 *
47
 * For cubemap and 2d array, each layer contains all of it's mipmap
48
 * levels (layer_first layout).
49
 *
50
 * 3d textures are layed out as on a3xx, but unknown about 3d-array
51
 * textures.
52
 *
53
 * In either case, the slice represents the per-miplevel information,
54
 * but in layer_first layout it only includes the first layer, and
55
 * an additional offset of (rsc->layer_size * layer) must be added.
56
 */
57
struct fd_resource_slice {
58
	uint32_t offset;         /* offset of first layer in slice */
59
	uint32_t pitch;
60
	uint32_t size0;          /* size of first layer in slice */
61
};
62
 
63
struct fd_resource {
64
	struct u_resource base;
65
	struct fd_bo *bo;
66
	uint32_t cpp;
67
	bool layer_first;        /* see above description */
68
	uint32_t layer_size;
69
	struct fd_resource_slice slices[MAX_MIP_LEVELS];
70
	uint32_t timestamp;
71
	bool dirty, reading;
72
	/* buffer range that has been initialized */
73
	struct util_range valid_buffer_range;
74
 
75
	/* reference to the resource holding stencil data for a z32_s8 texture */
76
	struct fd_resource *stencil;
77
 
78
	struct list_head list;
79
};
80
 
81
static INLINE struct fd_resource *
82
fd_resource(struct pipe_resource *ptex)
83
{
84
	return (struct fd_resource *)ptex;
85
}
86
 
87
struct fd_transfer {
88
	struct pipe_transfer base;
89
	void *staging;
90
};
91
 
92
static INLINE struct fd_transfer *
93
fd_transfer(struct pipe_transfer *ptrans)
94
{
95
	return (struct fd_transfer *)ptrans;
96
}
97
 
98
static INLINE struct fd_resource_slice *
99
fd_resource_slice(struct fd_resource *rsc, unsigned level)
100
{
101
	assert(level <= rsc->base.b.last_level);
102
	return &rsc->slices[level];
103
}
104
 
105
/* get offset for specified mipmap level and texture/array layer */
106
static INLINE uint32_t
107
fd_resource_offset(struct fd_resource *rsc, unsigned level, unsigned layer)
108
{
109
	struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
110
	unsigned offset;
111
	if (rsc->layer_first) {
112
		offset = slice->offset + (rsc->layer_size * layer);
113
	} else {
114
		offset = slice->offset + (slice->size0 * layer);
115
	}
116
	debug_assert(offset < fd_bo_size(rsc->bo));
117
	return offset;
118
}
119
 
120
void fd_resource_screen_init(struct pipe_screen *pscreen);
121
void fd_resource_context_init(struct pipe_context *pctx);
122
 
123
#endif /* FREEDRENO_RESOURCE_H_ */