revert between 56095 -> 55830 in arch
[AROS.git] / workbench / hidds / nouveau / nouveau_galliumclass.c
blob423af08c798500edf0ce1d84d9770c272347676b
1 /*
2 Copyright 2010-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "nouveau_intern.h"
8 #include <aros/debug.h>
10 #include <proto/oop.h>
11 #include <proto/utility.h>
13 #include "util/u_memory.h"
14 #include "util/u_inlines.h"
15 #include "nouveau/nouveau_winsys.h"
16 #include "nv50/nv50_resource.h"
17 #include "nvfx/nvfx_resource.h"
18 #include "nvc0/nvc0_resource.h"
20 #undef HiddGalliumAttrBase
21 #define HiddGalliumAttrBase (SD(cl)->galliumAttrBase)
23 struct HiddNouveauWinSys
25 struct HIDDT_WinSys base;
26 struct pipe_screen *pscreen;
29 static INLINE struct HiddNouveauWinSys *
30 HiddNouveauWinSys(struct pipe_winsys *ws)
32 return (struct HiddNouveauWinSys *)ws;
35 static VOID
36 HIDDNouveauFlushFrontBuffer( struct pipe_screen *screen,
37 struct pipe_resource *resource,
38 unsigned level, unsigned layer,
39 void *winsys_drawable_handle )
41 /* No Op */
44 static VOID
45 HIDDNouveauDestroyWinSys(struct pipe_winsys *ws)
47 struct HiddNouveauWinSys *nvws = HiddNouveauWinSys(ws);
49 FREE(nvws);
52 /* Wraps the nouveau_bo from resource into 2D bitmap class data */
53 static BOOL
54 HIDDNouveauWrapResource(struct CardData * carddata, struct pipe_resource * resource,
55 struct HIDDNouveauBitMapData * bmdata)
57 struct nouveau_bo * bo = NULL;
58 ULONG pitch = 0; ULONG depth = 0;
60 /* Get buffer object and pitch */
61 switch(carddata->architecture)
63 case NV_ARCH_30:
64 case NV_ARCH_40:
65 bo = nvfx_resource(resource)->bo;
66 pitch = ((struct nvfx_miptree *)resource)->linear_pitch;
67 break;
68 case NV_ARCH_50:
69 bo = nv50_miptree(resource)->base.bo;
70 pitch = nv50_miptree(resource)->level[0].pitch;
71 break;
72 case NV_ARCH_C0:
73 bo = nvc0_miptree(resource)->base.bo;
74 pitch = nvc0_miptree(resource)->level[0].pitch;
75 break;
78 if ((bo == NULL) || (pitch == 0))
79 return FALSE;
81 switch(resource->format)
83 case PIPE_FORMAT_B8G8R8A8_UNORM:
84 case PIPE_FORMAT_A8R8G8B8_UNORM:
85 /* For purpose of blitting render buffer to screen, 32-bit render
86 buffer is treated as 24-bit surface. This is needed so that checks
87 (src->depth == dst->depth) pass. */
88 case PIPE_FORMAT_B8G8R8X8_UNORM:
89 case PIPE_FORMAT_X8R8G8B8_UNORM:
90 depth = 24;
91 break;
92 case PIPE_FORMAT_B5G5R5A1_UNORM:
93 case PIPE_FORMAT_B4G4R4A4_UNORM:
94 case PIPE_FORMAT_B5G6R5_UNORM:
95 depth = 16;
96 break;
97 default:
98 depth = 0;
99 break;
102 if (depth == 0)
103 return FALSE;
105 /* Set all fields */
106 bmdata->bo = bo;
107 bmdata->width = resource->width0;
108 bmdata->height = resource->height0;
109 bmdata->depth = depth;
110 if (bmdata->depth == 16)
111 bmdata->bytesperpixel = 2;
112 else
113 bmdata->bytesperpixel = 4;
114 bmdata->pitch = pitch;
115 bmdata->fbid = 0; /* Default value */
116 InitSemaphore(&bmdata->semaphore);
118 return TRUE;
122 /* METHODS */
123 OOP_Object *METHOD(NouveauGallium, Root, New)
125 IPTR interfaceVers;
127 interfaceVers = GetTagData(aHidd_Gallium_InterfaceVersion, -1, msg->attrList);
128 if (interfaceVers != GALLIUM_INTERFACE_VERSION)
129 return NULL;
131 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
132 if(o)
134 /* Check if chipset support hardware 3D via gallium */
135 if ((SD(cl)->carddata.dev == NULL) || (SD(cl)->carddata.dev->chipset < 0x30))
137 OOP_MethodID dispose_mid;
138 dispose_mid = OOP_GetMethodID(IID_Root, moRoot_Dispose);
139 OOP_CoerceMethod(cl, o, (OOP_Msg) & dispose_mid);
140 o = NULL;
144 return o;
147 VOID METHOD(NouveauGallium, Root, Get)
149 ULONG idx;
151 if (IS_GALLIUM_ATTR(msg->attrID, idx))
153 switch (idx)
155 /* Overload the property */
156 case aoHidd_Gallium_InterfaceVersion:
157 *msg->storage = GALLIUM_INTERFACE_VERSION;
158 return;
162 /* Use parent class for all other properties */
163 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
166 APTR METHOD(NouveauGallium, Hidd_Gallium, CreatePipeScreen)
168 struct HiddNouveauWinSys *nvws;
169 struct pipe_winsys *ws;
170 struct nouveau_device *dev = SD(cl)->carddata.dev;
171 struct pipe_screen *(*init)(struct pipe_winsys *,
172 struct nouveau_device *);
174 switch (dev->chipset & 0xf0)
176 case 0x30:
177 case 0x40:
178 case 0x60:
179 init = nvfx_screen_create;
180 break;
181 case 0x50:
182 case 0x80:
183 case 0x90:
184 case 0xa0:
185 init = nv50_screen_create;
186 break;
187 case 0xc0:
188 init = nvc0_screen_create;
189 break;
190 default:
191 D(bug("%s: unknown chipset nv%02x\n", __func__,
192 dev->chipset));
193 return NULL;
196 LOCK_ENGINE
198 nvws = CALLOC_STRUCT(HiddNouveauWinSys);
199 if (!nvws) {
200 UNLOCK_ENGINE
201 return NULL;
203 ws = &nvws->base.base;
204 ws->destroy = HIDDNouveauDestroyWinSys;
206 nvws->pscreen = init(ws, dev);
207 if (!nvws->pscreen) {
208 ws->destroy(ws);
209 UNLOCK_ENGINE
210 return NULL;
213 nvws->pscreen->flush_frontbuffer = HIDDNouveauFlushFrontBuffer;
215 /* Preserve pointer to HIDD driver */
216 nvws->base.driver = o;
218 UNLOCK_ENGINE
220 return nvws->pscreen;
223 VOID METHOD(NouveauGallium, Hidd_Gallium, DisplayResource)
225 struct CardData * carddata = &(SD(cl)->carddata);
226 struct HIDDNouveauBitMapData srcdata;
227 OOP_Object * bm = HIDD_BM_OBJ(msg->bitmap);
228 struct HIDDNouveauBitMapData * dstdata;
230 if (!IS_NOUVEAU_BM_CLASS(OOP_OCLASS(bm))) /* Check if bitmap is really nouveau bitmap */
231 return;
233 dstdata = OOP_INST_DATA(OOP_OCLASS(bm), bm);
235 if (!HIDDNouveauWrapResource(carddata, msg->resource, &srcdata))
236 return;
238 LOCK_ENGINE
240 /* srcdata does not require a lock, because it's a local object that is
241 access only by one task at a time */
242 LOCK_BITMAP_BM(dstdata)
243 /* XXX HACK XXX */
244 /* HACK: there seems to something wrong with blitting method. Without this
245 mapping, the blitting is jittering with high frame frames. Probably some
246 flush is missing somewhere and doing a mapping executes this missing flush
248 MAP_BUFFER_BM(dstdata)
249 /* XXX HACK XXX */
250 UNMAP_BUFFER_BM(dstdata)
252 switch(carddata->architecture)
254 case NV_ARCH_30:
255 case NV_ARCH_40:
256 HIDDNouveauNV04CopySameFormat(carddata, &srcdata, dstdata,
257 msg->srcx, msg->srcy, msg->dstx, msg->dsty, msg->width, msg->height,
258 0x03 /* vHidd_GC_DrawMode_Copy */);
259 break;
260 case NV_ARCH_50:
261 HIDDNouveauNV50CopySameFormat(carddata, &srcdata, dstdata,
262 msg->srcx, msg->srcy, msg->dstx, msg->dsty, msg->width, msg->height,
263 0x03 /* vHidd_GC_DrawMode_Copy */);
264 break;
265 case NV_ARCH_C0:
266 HIDDNouveauNVC0CopySameFormat(carddata, &srcdata, dstdata,
267 msg->srcx, msg->srcy, msg->dstx, msg->dsty, msg->width, msg->height,
268 0x03 /* vHidd_GC_DrawMode_Copy */);
269 default:
270 /* TODO: Report error */
271 break;
275 UNLOCK_BITMAP_BM(dstdata)
277 UNLOCK_ENGINE