1b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák/*
2b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * Copyright 2010 Marek Olšák <maraeo@gmail.com
3b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák *
4b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * Permission is hereby granted, free of charge, to any person obtaining a
5b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * copy of this software and associated documentation files (the "Software"),
6b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * to deal in the Software without restriction, including without limitation
7b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * on the rights to use, copy, modify, merge, publish, distribute, sub
8b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * license, and/or sell copies of the Software, and to permit persons to whom
9b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * the Software is furnished to do so, subject to the following conditions:
10b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák *
11b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * The above copyright notice and this permission notice (including the next
12b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * paragraph) shall be included in all copies or substantial portions of the
13b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * Software.
14b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák *
15b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák * USE OR OTHER DEALINGS IN THE SOFTWARE.
22b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák */
23b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák#ifndef R600_RESOURCE_H
24b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák#define R600_RESOURCE_H
25b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák
26330b6c85c961b32f704ce8ec7dbf8cb7fc0b80a8Marek Olšák#include "r600.h"
27742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse
2892ed84d11560e226c87bf2758b1503e3075b3f82Dave Airlie/* flag to indicate a resource is to be used as a transfer so should not be tiled */
29018e3f75d69490598d61059ece56d379867f3995Marek Olšák#define R600_RESOURCE_FLAG_TRANSFER		PIPE_RESOURCE_FLAG_DRV_PRIV
30018e3f75d69490598d61059ece56d379867f3995Marek Olšák#define R600_RESOURCE_FLAG_FLUSHED_DEPTH	(PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
310ac90296a092f846647812318913b0e492775f31Marek Olšák#define R600_RESOURCE_FLAG_FORCE_TILING		(PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
3292ed84d11560e226c87bf2758b1503e3075b3f82Dave Airlie
339c284b5cae916a083d17d1039d2f2da128b47882Jerome Glissestruct r600_transfer {
349c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse	struct pipe_transfer		transfer;
35897af1d499ed91ed3629432424eb1ac62bff2c5fMarek Olšák	struct r600_resource		*staging;
369c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse	unsigned			offset;
379c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse};
38b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák
396a829a1b724ca0d960decee217d260b4de8a5463Adam Rakstruct compute_memory_item;
406a829a1b724ca0d960decee217d260b4de8a5463Adam Rak
416a829a1b724ca0d960decee217d260b4de8a5463Adam Rakstruct r600_resource_global {
426a829a1b724ca0d960decee217d260b4de8a5463Adam Rak	struct r600_resource base;
436a829a1b724ca0d960decee217d260b4de8a5463Adam Rak	struct compute_memory_item *chunk;
446a829a1b724ca0d960decee217d260b4de8a5463Adam Rak};
456a829a1b724ca0d960decee217d260b4de8a5463Adam Rak
46951ac46a6a0a901b53a518c8dcde734578cbf228Marek Olšákstruct r600_texture {
47742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse	struct r600_resource		resource;
4868c54abb2cfd12a031829e78d721b2480d0c8cc4Marek Olšák
49ea5aab85fd195074189832c2d6870dd78f0f8966Dave Airlie	unsigned			array_mode[PIPE_MAX_TEXTURE_LEVELS];
50f8778eeb40daf355f8dbcfeb1a9b492c57ce6a35Dave Airlie	unsigned			pitch_override;
51f8778eeb40daf355f8dbcfeb1a9b492c57ce6a35Dave Airlie	unsigned			size;
5236efb86c0570d86d8dfce87fd2416125e0e91b40Jerome Glisse	unsigned			tile_type;
53d334d591a71c41d6a1eb4f2ea6cdabedc425e42fMarek Olšák	bool				is_depth;
549d3644137427893b1deb629410ebc68c89f26d74Tom Stellard	bool				is_rat;
5548edfe0505ee79d35f770f53b9c9b7ca3c69fd2bMarek Olšák	unsigned			dirty_level_mask; /* each bit says if that mipmap is compressed */
56951ac46a6a0a901b53a518c8dcde734578cbf228Marek Olšák	struct r600_texture		*flushed_depth_texture;
57b13b7b86b2e1165b24a2df20cb67f9f3baa17b13Dave Airlie	boolean				is_flushing_texture;
58c0c979eebc076b95cc8d18a013ce2968fe6311adJerome Glisse	struct radeon_surface		surface;
59a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák
60a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	/* FMASK and CMASK can only be used with MSAA textures for now.
61a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	 * MSAA textures cannot have mipmaps. */
62a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	unsigned			fmask_offset, fmask_size, fmask_bank_height;
63a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	unsigned			cmask_offset, cmask_size, cmask_slice_tile_max;
64121079bd679ea0729834cca79ab3c424e006feedJerome Glisse};
65121079bd679ea0729834cca79ab3c424e006feedJerome Glisse
66ea7a548d07ddc69c226a425af0f88f818203d6eeDave Airlie#define R600_TEX_IS_TILED(tex, level) ((tex)->array_mode[level] != V_038000_ARRAY_LINEAR_GENERAL && (tex)->array_mode[level] != V_038000_ARRAY_LINEAR_ALIGNED)
67ea7a548d07ddc69c226a425af0f88f818203d6eeDave Airlie
6878354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšákstruct r600_fmask_info {
6978354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	unsigned size;
7078354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	unsigned alignment;
7178354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	unsigned bank_height;
7278354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák};
7378354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák
7478354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšákstruct r600_cmask_info {
7578354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	unsigned size;
7678354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	unsigned alignment;
7778354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	unsigned slice_tile_max;
7878354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák};
7978354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák
80121079bd679ea0729834cca79ab3c424e006feedJerome Glissestruct r600_surface {
81121079bd679ea0729834cca79ab3c424e006feedJerome Glisse	struct pipe_surface		base;
82cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák
83cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	bool color_initialized;
84cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	bool depth_initialized;
85cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák
86cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	/* Misc. color flags. */
87cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	bool alphatest_bypass;
88cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	bool export_16bpc;
89cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák
90cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	/* Color registers. */
91cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_info;
92cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_base;
93cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_view;
94cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_size;		/* R600 only */
95cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_dim;		/* EG only */
96cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_pitch;	/* EG only */
97cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_slice;	/* EG only */
98cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák	unsigned cb_color_attrib;	/* EG only */
99a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	unsigned cb_color_fmask;	/* CB_COLORn_FMASK (EG) or CB_COLORn_FRAG (r600) */
100a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	unsigned cb_color_fmask_slice;	/* EG only */
101a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	unsigned cb_color_cmask;	/* CB_COLORn_CMASK (EG) or CB_COLORn_TILE (r600) */
102a3d9d7ec79d6f7205fab2324e47d8ea185431de0Marek Olšák	unsigned cb_color_cmask_slice;	/* EG only */
1038698a3b85dd89c5d2fa473e7942b7dc8d25f3c8fMarek Olšák	unsigned cb_color_mask;		/* R600 only */
10478354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	struct r600_resource *cb_buffer_fmask; /* Used for FMASK relocations. R600 only */
10578354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák	struct r600_resource *cb_buffer_cmask; /* Used for CMASK relocations. R600 only */
106cb922b63eba1d75706354614bc5de4d39dbe9ad3Marek Olšák
107cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	/* DB registers. */
108cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_depth_info;		/* DB_Z_INFO (EG) or DB_DEPTH_INFO (r600) */
109cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_depth_base;		/* DB_Z_READ/WRITE_BASE (EG) or DB_DEPTH_BASE (r600) */
110cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_depth_view;
111cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_depth_size;
112cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_depth_slice;	/* EG only */
113cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_stencil_base;	/* EG only */
114cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_stencil_info;	/* EG only */
115cdc681c3ad746fe8adab4ea71358bcc54e024ff9Marek Olšák	unsigned db_prefetch_limit;	/* R600 only */
116742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse};
117742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse
1186a829a1b724ca0d960decee217d260b4de8a5463Adam Rakvoid r600_resource_destroy(struct pipe_screen *screen, struct pipe_resource *res);
119fd266ec62ca772a8551d2d7922d718d9d84bdf07Jerome Glissevoid r600_init_screen_resource_functions(struct pipe_screen *screen);
120b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák
121742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse/* r600_texture */
12278354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšákvoid r600_texture_get_fmask_info(struct r600_screen *rscreen,
12378354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák				 struct r600_texture *rtex,
12478354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák				 unsigned nr_samples,
12578354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák				 struct r600_fmask_info *out);
12678354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšákvoid r600_texture_get_cmask_info(struct r600_screen *rscreen,
12778354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák				 struct r600_texture *rtex,
12878354011f99c4103345f8f32e10b0b4b884ebdafMarek Olšák				 struct r600_cmask_info *out);
129742ee7935da60dda974795243d2e0fcf31accb59Jerome Glissestruct pipe_resource *r600_texture_create(struct pipe_screen *screen,
130742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse					const struct pipe_resource *templ);
131742ee7935da60dda974795243d2e0fcf31accb59Jerome Glissestruct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
132742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse						const struct pipe_resource *base,
133742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse						struct winsys_handle *whandle);
134742ee7935da60dda974795243d2e0fcf31accb59Jerome Glisse
1359f0dc855b274cb2591fc6896149f9a9cabcbcab5Marek Olšákstatic INLINE struct r600_resource *r600_resource(struct pipe_resource *r)
1360d76bb5d4c5c867155f7fb381c46018e1560b790Dave Airlie{
1379f0dc855b274cb2591fc6896149f9a9cabcbcab5Marek Olšák	return (struct r600_resource*)r;
1380d76bb5d4c5c867155f7fb381c46018e1560b790Dave Airlie}
1390d76bb5d4c5c867155f7fb381c46018e1560b790Dave Airlie
140611dd529425281d73f1f0ad2000362d4a5525a25Marek Olšákbool r600_init_flushed_depth_texture(struct pipe_context *ctx,
14137708479608af877986b76302a9c92611d1e23d0Vadim Girlin				     struct pipe_resource *texture,
142951ac46a6a0a901b53a518c8dcde734578cbf228Marek Olšák				     struct r600_texture **staging);
1439c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse
1449c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse/* r600_texture.c texture transfer functions. */
1459c284b5cae916a083d17d1039d2f2da128b47882Jerome Glissestruct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
1469c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse						struct pipe_resource *texture,
1474c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger						unsigned level,
1489c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse						unsigned usage,
1499c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse						const struct pipe_box *box);
1509c284b5cae916a083d17d1039d2f2da128b47882Jerome Glissevoid r600_texture_transfer_destroy(struct pipe_context *ctx,
1519c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse				   struct pipe_transfer *trans);
1529c284b5cae916a083d17d1039d2f2da128b47882Jerome Glissevoid* r600_texture_transfer_map(struct pipe_context *ctx,
1539c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse				struct pipe_transfer* transfer);
1549c284b5cae916a083d17d1039d2f2da128b47882Jerome Glissevoid r600_texture_transfer_unmap(struct pipe_context *ctx,
1559c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse				 struct pipe_transfer* transfer);
1569c284b5cae916a083d17d1039d2f2da128b47882Jerome Glisse
157b8fb1d75ce95fe5d404b301ab31ca0c323967d14Marek Olšák#endif
158