1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "i915_surface.h"
29 #include "i915_resource.h"
30 #include "i915_blit.h"
32 #include "i915_screen.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_inlines.h"
35 #include "util/u_math.h"
36 #include "util/u_format.h"
37 #include "util/u_memory.h"
38 #include "util/u_pack_color.h"
41 /* Assumes all values are within bounds -- no checking at this level -
42 * do it higher up if required.
45 i915_surface_copy(struct pipe_context
*pipe
,
46 struct pipe_resource
*dst
, struct pipe_subresource subdst
,
47 unsigned dstx
, unsigned dsty
, unsigned dstz
,
48 struct pipe_resource
*src
, struct pipe_subresource subsrc
,
49 unsigned srcx
, unsigned srcy
, unsigned srcz
,
50 unsigned width
, unsigned height
)
52 struct i915_texture
*dst_tex
= i915_texture(dst
);
53 struct i915_texture
*src_tex
= i915_texture(src
);
54 struct pipe_resource
*dpt
= &dst_tex
->b
.b
;
55 struct pipe_resource
*spt
= &src_tex
->b
.b
;
56 unsigned dst_offset
, src_offset
; /* in bytes */
58 if (dst
->target
== PIPE_TEXTURE_CUBE
) {
59 dst_offset
= dst_tex
->image_offset
[subdst
.level
][subdst
.face
];
61 else if (dst
->target
== PIPE_TEXTURE_3D
) {
62 dst_offset
= dst_tex
->image_offset
[subdst
.level
][dstz
];
65 dst_offset
= dst_tex
->image_offset
[subdst
.level
][0];
66 assert(subdst
.face
== 0);
69 if (src
->target
== PIPE_TEXTURE_CUBE
) {
70 src_offset
= src_tex
->image_offset
[subsrc
.level
][subsrc
.face
];
72 else if (src
->target
== PIPE_TEXTURE_3D
) {
73 src_offset
= src_tex
->image_offset
[subsrc
.level
][srcz
];
76 src_offset
= src_tex
->image_offset
[subsrc
.level
][0];
77 assert(subsrc
.face
== 0);
83 assert( util_format_get_blocksize(dpt
->format
) == util_format_get_blocksize(spt
->format
) );
84 assert( util_format_get_blockwidth(dpt
->format
) == util_format_get_blockwidth(spt
->format
) );
85 assert( util_format_get_blockheight(dpt
->format
) == util_format_get_blockheight(spt
->format
) );
86 assert( util_format_get_blockwidth(dpt
->format
) == 1 );
87 assert( util_format_get_blockheight(dpt
->format
) == 1 );
89 i915_copy_blit( i915_context(pipe
),
90 util_format_get_blocksize(dpt
->format
),
91 (unsigned short) src_tex
->stride
, src_tex
->buffer
, src_offset
,
92 (unsigned short) dst_tex
->stride
, dst_tex
->buffer
, dst_offset
,
93 (short) srcx
, (short) srcy
, (short) dstx
, (short) dsty
, (short) width
, (short) height
);
98 i915_clear_render_target(struct pipe_context
*pipe
,
99 struct pipe_surface
*dst
,
101 unsigned dstx
, unsigned dsty
,
102 unsigned width
, unsigned height
)
104 struct i915_texture
*tex
= i915_texture(dst
->texture
);
105 struct pipe_resource
*pt
= &tex
->b
.b
;
108 assert(util_format_get_blockwidth(pt
->format
) == 1);
109 assert(util_format_get_blockheight(pt
->format
) == 1);
111 util_pack_color(rgba
, dst
->format
, &uc
);
112 i915_fill_blit( i915_context(pipe
),
113 util_format_get_blocksize(pt
->format
),
114 XY_COLOR_BLT_WRITE_ALPHA
| XY_COLOR_BLT_WRITE_RGB
,
115 (unsigned short) tex
->stride
,
116 tex
->buffer
, dst
->offset
,
117 (short) dstx
, (short) dsty
,
118 (short) width
, (short) height
,
123 i915_clear_depth_stencil(struct pipe_context
*pipe
,
124 struct pipe_surface
*dst
,
125 unsigned clear_flags
,
128 unsigned dstx
, unsigned dsty
,
129 unsigned width
, unsigned height
)
131 struct i915_texture
*tex
= i915_texture(dst
->texture
);
132 struct pipe_resource
*pt
= &tex
->b
.b
;
136 assert(util_format_get_blockwidth(pt
->format
) == 1);
137 assert(util_format_get_blockheight(pt
->format
) == 1);
139 packedds
= util_pack_z_stencil(dst
->format
, depth
, stencil
);
141 if (clear_flags
& PIPE_CLEAR_DEPTH
)
142 mask
|= XY_COLOR_BLT_WRITE_RGB
;
143 /* XXX presumably this does read-modify-write
144 (otherwise this won't work anyway). Hence will only want to
145 do it if really have stencil and it isn't cleared */
146 if (!((clear_flags
& PIPE_CLEAR_STENCIL
) ||
147 (dst
->format
!= PIPE_FORMAT_Z24_UNORM_S8_USCALED
)))
148 mask
|= XY_COLOR_BLT_WRITE_ALPHA
;
150 i915_fill_blit( i915_context(pipe
),
151 util_format_get_blocksize(pt
->format
),
153 (unsigned short) tex
->stride
,
154 tex
->buffer
, dst
->offset
,
155 (short) dstx
, (short) dsty
,
156 (short) width
, (short) height
,
161 * Screen surface functions
165 static struct pipe_surface
*
166 i915_get_tex_surface(struct pipe_screen
*screen
,
167 struct pipe_resource
*pt
,
168 unsigned face
, unsigned level
, unsigned zslice
,
171 struct i915_texture
*tex
= i915_texture(pt
);
172 struct pipe_surface
*ps
;
173 unsigned offset
; /* in bytes */
175 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
176 offset
= tex
->image_offset
[level
][face
];
178 else if (pt
->target
== PIPE_TEXTURE_3D
) {
179 offset
= tex
->image_offset
[level
][zslice
];
182 offset
= tex
->image_offset
[level
][0];
187 ps
= CALLOC_STRUCT(pipe_surface
);
189 pipe_reference_init(&ps
->reference
, 1);
190 pipe_resource_reference(&ps
->texture
, pt
);
191 ps
->format
= pt
->format
;
192 ps
->width
= u_minify(pt
->width0
, level
);
193 ps
->height
= u_minify(pt
->height0
, level
);
201 i915_tex_surface_destroy(struct pipe_surface
*surf
)
203 pipe_resource_reference(&surf
->texture
, NULL
);
209 i915_init_surface_functions(struct i915_context
*i915
)
211 i915
->base
.resource_copy_region
= i915_surface_copy
;
212 i915
->base
.clear_render_target
= i915_clear_render_target
;
213 i915
->base
.clear_depth_stencil
= i915_clear_depth_stencil
;
216 /* No good reason for these to be in the screen.
219 i915_init_screen_surface_functions(struct i915_screen
*is
)
221 is
->base
.get_tex_surface
= i915_get_tex_surface
;
222 is
->base
.tex_surface_destroy
= i915_tex_surface_destroy
;