radeon/llvm: Eliminate CFGStructurizer dependency on AMDIL instructions
[mesa.git] / src / gallium / drivers / galahad / glhd_objects.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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 VMWARE 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.
25 *
26 **************************************************************************/
27
28 #include "util/u_inlines.h"
29 #include "util/u_memory.h"
30
31 #include "glhd_screen.h"
32 #include "glhd_objects.h"
33 #include "glhd_context.h"
34
35
36
37 struct pipe_resource *
38 galahad_resource_create(struct galahad_screen *glhd_screen,
39 struct pipe_resource *resource)
40 {
41 struct galahad_resource *glhd_resource;
42
43 if(!resource)
44 goto error;
45
46 assert(resource->screen == glhd_screen->screen);
47
48 glhd_resource = CALLOC_STRUCT(galahad_resource);
49 if(!glhd_resource)
50 goto error;
51
52 memcpy(&glhd_resource->base, resource, sizeof(struct pipe_resource));
53
54 pipe_reference_init(&glhd_resource->base.reference, 1);
55 glhd_resource->base.screen = &glhd_screen->base;
56 glhd_resource->resource = resource;
57
58 return &glhd_resource->base;
59
60 error:
61 pipe_resource_reference(&resource, NULL);
62 return NULL;
63 }
64
65 void
66 galahad_resource_destroy(struct galahad_resource *glhd_resource)
67 {
68 pipe_resource_reference(&glhd_resource->resource, NULL);
69 FREE(glhd_resource);
70 }
71
72
73 struct pipe_surface *
74 galahad_surface_create(struct galahad_context *glhd_context,
75 struct galahad_resource *glhd_resource,
76 struct pipe_surface *surface)
77 {
78 struct galahad_surface *glhd_surface;
79
80 if(!surface)
81 goto error;
82
83 assert(surface->texture == glhd_resource->resource);
84
85 glhd_surface = CALLOC_STRUCT(galahad_surface);
86 if(!glhd_surface)
87 goto error;
88
89 memcpy(&glhd_surface->base, surface, sizeof(struct pipe_surface));
90
91 pipe_reference_init(&glhd_surface->base.reference, 1);
92 glhd_surface->base.texture = NULL;
93 pipe_resource_reference(&glhd_surface->base.texture, &glhd_resource->base);
94 glhd_surface->surface = surface;
95
96 return &glhd_surface->base;
97
98 error:
99 pipe_surface_reference(&surface, NULL);
100 return NULL;
101 }
102
103 void
104 galahad_surface_destroy(struct galahad_context *glhd_context,
105 struct galahad_surface *glhd_surface)
106 {
107 pipe_resource_reference(&glhd_surface->base.texture, NULL);
108 glhd_context->pipe->surface_destroy(glhd_context->pipe, glhd_surface->surface);
109 FREE(glhd_surface);
110 }
111
112
113 struct pipe_sampler_view *
114 galahad_sampler_view_create(struct galahad_context *glhd_context,
115 struct galahad_resource *glhd_resource,
116 struct pipe_sampler_view *view)
117 {
118 struct galahad_sampler_view *glhd_view;
119
120 if (!view)
121 goto error;
122
123 assert(view->texture == glhd_resource->resource);
124
125 glhd_view = CALLOC_STRUCT(galahad_sampler_view);
126
127 glhd_view->base = *view;
128 glhd_view->base.reference.count = 1;
129 glhd_view->base.texture = NULL;
130 pipe_resource_reference(&glhd_view->base.texture, glhd_resource->resource);
131 glhd_view->base.context = glhd_context->pipe;
132 glhd_view->sampler_view = view;
133
134 return &glhd_view->base;
135 error:
136 return NULL;
137 }
138
139 void
140 galahad_sampler_view_destroy(struct galahad_context *glhd_context,
141 struct galahad_sampler_view *glhd_view)
142 {
143 pipe_resource_reference(&glhd_view->base.texture, NULL);
144 glhd_context->pipe->sampler_view_destroy(glhd_context->pipe,
145 glhd_view->sampler_view);
146 FREE(glhd_view);
147 }
148
149
150 struct pipe_transfer *
151 galahad_transfer_create(struct galahad_context *glhd_context,
152 struct galahad_resource *glhd_resource,
153 struct pipe_transfer *transfer)
154 {
155 struct galahad_transfer *glhd_transfer;
156
157 if(!transfer)
158 goto error;
159
160 assert(transfer->resource == glhd_resource->resource);
161
162 glhd_transfer = CALLOC_STRUCT(galahad_transfer);
163 if(!glhd_transfer)
164 goto error;
165
166 memcpy(&glhd_transfer->base, transfer, sizeof(struct pipe_transfer));
167
168 glhd_transfer->base.resource = NULL;
169 glhd_transfer->transfer = transfer;
170
171 pipe_resource_reference(&glhd_transfer->base.resource, &glhd_resource->base);
172 assert(glhd_transfer->base.resource == &glhd_resource->base);
173
174 return &glhd_transfer->base;
175
176 error:
177 glhd_context->pipe->transfer_destroy(glhd_context->pipe, transfer);
178 return NULL;
179 }
180
181 void
182 galahad_transfer_destroy(struct galahad_context *glhd_context,
183 struct galahad_transfer *glhd_transfer)
184 {
185 pipe_resource_reference(&glhd_transfer->base.resource, NULL);
186 glhd_context->pipe->transfer_destroy(glhd_context->pipe,
187 glhd_transfer->transfer);
188 FREE(glhd_transfer);
189 }