1 /*
2 * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
3 * The term “Broadcom” refers to Broadcom Inc.
4 * and/or its subsidiaries.
5 * SPDX-License-Identifier: MIT
6 */
7
8 #ifndef SVGA_SURFACE_H
9 #define SVGA_SURFACE_H
10
11
12 #include "util/compiler.h"
13 #include "pipe/p_state.h"
14 #include "util/u_inlines.h"
15 #include "svga_screen_cache.h"
16
17 struct pipe_context;
18 struct pipe_screen;
19 struct svga_context;
20 struct svga_texture;
21 struct svga_winsys_surface;
22 enum SVGA3dSurfaceFormat;
23
24
25 struct svga_surface
26 {
27 struct pipe_surface base;
28
29 struct svga_host_surface_cache_key key;
30
31 /*
32 * Note that the handle may point at a secondary / backing resource
33 * created by svga_texture_view_surface() which is something other
34 * than svga_texture(base->texture)->handle.
35 */
36 struct svga_winsys_surface *handle;
37
38 unsigned real_layer;
39 unsigned real_level;
40 unsigned real_zslice;
41
42 bool dirty;
43
44 /* VGPU10 */
45 SVGA3dRenderTargetViewId view_id;
46
47 /*
48 * As with 'handle' above, this may point to a secondary / backing resource.
49 * We can't have one resource bound as both a render target and a shader
50 * resource at the same time. But we sometimes want to do that, such as
51 * for mipmap generation where we sample from one level and render into
52 * another.
53 * In this situation, the backed surface is the render target while the
54 * original surface is the shader resource.
55 */
56 struct svga_surface *backed;
57 unsigned age; /* timestamp when the backed resource is
58 * synced with the original resource.
59 */
60 };
61
62
63 void
64 svga_mark_surfaces_dirty(struct svga_context *svga);
65
66 extern void
67 svga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf,
68 bool reset);
69
70 void
71 svga_propagate_rendertargets(struct svga_context *svga);
72
73 extern bool
74 svga_surface_needs_propagation(const struct pipe_surface *surf);
75
76 struct svga_winsys_surface *
77 svga_texture_view_surface(struct svga_context *svga,
78 struct svga_texture *tex,
79 unsigned bind_flags,
80 SVGA3dSurfaceAllFlags flags,
81 SVGA3dSurfaceFormat format,
82 unsigned start_mip,
83 unsigned num_mip,
84 int layer_pick,
85 unsigned num_layers,
86 int zslice_pick,
87 bool cacheable,
88 struct svga_host_surface_cache_key *key); /* OUT */
89
90 void
91 svga_texture_copy_region(struct svga_context *svga,
92 struct svga_winsys_surface *src_handle,
93 unsigned srcSubResource,
94 unsigned src_x, unsigned src_y, unsigned src_z,
95 struct svga_winsys_surface *dst_handle,
96 unsigned dstSubResource,
97 unsigned dst_x, unsigned dst_y, unsigned dst_z,
98 unsigned width, unsigned height, unsigned depth);
99
100 void
101 svga_texture_copy_handle(struct svga_context *svga,
102 struct svga_winsys_surface *src_handle,
103 unsigned src_x, unsigned src_y, unsigned src_z,
104 unsigned src_level, unsigned src_face,
105 struct svga_winsys_surface *dst_handle,
106 unsigned dst_x, unsigned dst_y, unsigned dst_z,
107 unsigned dst_level, unsigned dst_face,
108 unsigned width, unsigned height, unsigned depth);
109
110
111 static inline struct svga_surface *
svga_surface(struct pipe_surface * surface)112 svga_surface(struct pipe_surface *surface)
113 {
114 return (struct svga_surface *)surface;
115 }
116
117
118 static inline const struct svga_surface *
svga_surface_const(const struct pipe_surface * surface)119 svga_surface_const(const struct pipe_surface *surface)
120 {
121 return (const struct svga_surface *)surface;
122 }
123
124 struct pipe_surface *
125 svga_validate_surface_view(struct svga_context *svga, struct svga_surface *s);
126
127 void
128 svga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf,
129 bool reset);
130
131 static inline SVGA3dResourceType
svga_resource_type(enum pipe_texture_target target)132 svga_resource_type(enum pipe_texture_target target)
133 {
134 switch (target) {
135 case PIPE_BUFFER:
136 return SVGA3D_RESOURCE_BUFFER;
137 case PIPE_TEXTURE_1D:
138 case PIPE_TEXTURE_1D_ARRAY:
139 return SVGA3D_RESOURCE_TEXTURE1D;
140 case PIPE_TEXTURE_RECT:
141 case PIPE_TEXTURE_2D:
142 case PIPE_TEXTURE_2D_ARRAY:
143 case PIPE_TEXTURE_CUBE:
144 case PIPE_TEXTURE_CUBE_ARRAY:
145 /* drawing to cube map is treated as drawing to 2D array */
146 return SVGA3D_RESOURCE_TEXTURE2D;
147 case PIPE_TEXTURE_3D:
148 return SVGA3D_RESOURCE_TEXTURE3D;
149 default:
150 assert(!"Unexpected texture target");
151 return SVGA3D_RESOURCE_TEXTURE2D;
152 }
153 }
154
155 #endif
156