r300g: only check for an empty shader if there are no compile errors
[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_resource *glhd_resource,
75 struct pipe_surface *surface)
76 {
77 struct galahad_surface *glhd_surface;
78
79 if(!surface)
80 goto error;
81
82 assert(surface->texture == glhd_resource->resource);
83
84 glhd_surface = CALLOC_STRUCT(galahad_surface);
85 if(!glhd_surface)
86 goto error;
87
88 memcpy(&glhd_surface->base, surface, sizeof(struct pipe_surface));
89
90 pipe_reference_init(&glhd_surface->base.reference, 1);
91 glhd_surface->base.texture = NULL;
92 pipe_resource_reference(&glhd_surface->base.texture, &glhd_resource->base);
93 glhd_surface->surface = surface;
94
95 return &glhd_surface->base;
96
97 error:
98 pipe_surface_reference(&surface, NULL);
99 return NULL;
100 }
101
102 void
103 galahad_surface_destroy(struct galahad_surface *glhd_surface)
104 {
105 pipe_resource_reference(&glhd_surface->base.texture, NULL);
106 pipe_surface_reference(&glhd_surface->surface, NULL);
107 FREE(glhd_surface);
108 }
109
110
111 struct pipe_sampler_view *
112 galahad_sampler_view_create(struct galahad_context *glhd_context,
113 struct galahad_resource *glhd_resource,
114 struct pipe_sampler_view *view)
115 {
116 struct galahad_sampler_view *glhd_view;
117
118 if (!view)
119 goto error;
120
121 assert(view->texture == glhd_resource->resource);
122
123 glhd_view = CALLOC_STRUCT(galahad_sampler_view);
124
125 glhd_view->base = *view;
126 glhd_view->base.reference.count = 1;
127 glhd_view->base.texture = NULL;
128 pipe_resource_reference(&glhd_view->base.texture, glhd_resource->resource);
129 glhd_view->base.context = glhd_context->pipe;
130 glhd_view->sampler_view = view;
131
132 return &glhd_view->base;
133 error:
134 return NULL;
135 }
136
137 void
138 galahad_sampler_view_destroy(struct galahad_context *glhd_context,
139 struct galahad_sampler_view *glhd_view)
140 {
141 pipe_resource_reference(&glhd_view->base.texture, NULL);
142 glhd_context->pipe->sampler_view_destroy(glhd_context->pipe,
143 glhd_view->sampler_view);
144 FREE(glhd_view);
145 }
146
147
148 struct pipe_transfer *
149 galahad_transfer_create(struct galahad_context *glhd_context,
150 struct galahad_resource *glhd_resource,
151 struct pipe_transfer *transfer)
152 {
153 struct galahad_transfer *glhd_transfer;
154
155 if(!transfer)
156 goto error;
157
158 assert(transfer->resource == glhd_resource->resource);
159
160 glhd_transfer = CALLOC_STRUCT(galahad_transfer);
161 if(!glhd_transfer)
162 goto error;
163
164 memcpy(&glhd_transfer->base, transfer, sizeof(struct pipe_transfer));
165
166 glhd_transfer->base.resource = NULL;
167 glhd_transfer->transfer = transfer;
168
169 pipe_resource_reference(&glhd_transfer->base.resource, &glhd_resource->base);
170 assert(glhd_transfer->base.resource == &glhd_resource->base);
171
172 return &glhd_transfer->base;
173
174 error:
175 glhd_context->pipe->transfer_destroy(glhd_context->pipe, transfer);
176 return NULL;
177 }
178
179 void
180 galahad_transfer_destroy(struct galahad_context *glhd_context,
181 struct galahad_transfer *glhd_transfer)
182 {
183 pipe_resource_reference(&glhd_transfer->base.resource, NULL);
184 glhd_context->pipe->transfer_destroy(glhd_context->pipe,
185 glhd_transfer->transfer);
186 FREE(glhd_transfer);
187 }