2 Copyright © 2011-2013, The AROS Development Team. All rights reserved.
5 Desc: Cumulative graphics benchmarks
8 /*****************************************************************************
28 ******************************************************************************/
30 #include <cybergraphx/cybergraphics.h>
31 #include <proto/exec.h>
32 #include <devices/timer.h>
33 #include <proto/diskfont.h>
34 #include <proto/graphics.h>
35 #include <proto/intuition.h>
36 #include <proto/dos.h>
37 #include <resources/processor.h>
38 #include <proto/processor.h>
39 #include <proto/oop.h>
40 #include <proto/cybergraphics.h>
51 static void printresults(LONG timems
, LONG blits
)
55 bpp
= GetCyberMapAttr(win
->WScreen
->RastPort
.BitMap
, CYBRMATTR_BPPIX
);
56 q
= ((QUAD
)width
) * ((QUAD
)height
) * ((QUAD
)bpp
) * ((QUAD
)blits
) * ((QUAD
)1000000) / (QUAD
)timems
;
58 printf("%.2f|%d|\n", (blits
* 1000000.0 / timems
), (int)(q
/ 1048576));
61 static void cleanup(STRPTR msg
, ULONG retcode
)
64 fprintf(stderr
, "text: %s\n", msg
);
70 #define ONLY_BENCH_CODE
72 STRPTR consttext
= "The AROS Development Team. All rights reserved.";
74 BOOL antialias
= FALSE
;
77 LONG pixfmt
= RECTFMT_ARGB
;
80 #include "pixelarray.c"
82 /* PCI Vendor/Product name translaction. Taken from PCITool */
85 // it's supposed to become a shared library one day ...
87 // current implementation:
88 // on pciids_Open(), the file is read in memory, then
89 // an index is built (in computeVendorIndexes()), as an array
90 // of couples (vendor_id, offset)
91 // where offset is the offset where the vendor stuff begins
92 // in the memory file. This array is ascending sorted by vendor_id,
93 // so a binary search can be done to retrieve the vendor offset
94 // given its id. This search is done in getVendorIndex().
95 // All the stringification functions first call this search func,
96 // then parse the memory:
97 // 1234 VendorName (so: s[0] = hex digit, s[4] == ' ', s[6+] == name)
98 // <tab>1234 DeviceName (same with a tab on linestart)
99 // todo: subvendor/subdevice parsing
100 // todo: proper memory reallocation, currently the index is fixed
103 static STRPTR mem
= NULL
;
104 static ULONG memsize
= 0;
112 static struct vendor_cell
*vendor_index
= NULL
;
113 static ULONG vi_allocated
= 0;
114 static UWORD vi_number
= 0;
116 static LONG
skip_line(const char *buffer
, LONG size
, LONG pos
)
121 if (*buffer
++ == '\n')
131 static LONG
copy_until_eol(STRPTR m
, ULONG msize
, LONG pos
, STRPTR buf
,
137 while ((pos
< msize
) && (j
< bufsize
- 1) && (*m
!= '\n'))
145 static BOOL
computeVendorIndexes(const char *buffer
, LONG size
)
150 vendor_index
= AllocVec(vi_allocated
* sizeof(struct vendor_cell
), MEMF_ANY
);
151 if (NULL
== vendor_index
)
159 // don't use isxdigit, beware of uppercase letter
160 if ((isdigit(buffer
[i
]) || (buffer
[i
] >= 'a' && buffer
[i
] <= 'f'))
161 && (i
+ 4 < size
) && (buffer
[i
+ 4] == ' '))
163 if (sscanf(buffer
+ i
, "%hx", &(vendor_index
[j
].vendorID
)) != 1)
165 vendor_index
[j
].offset
= i
;
168 if (j
>= vi_allocated
)
170 FreeVec(vendor_index
);
175 i
= skip_line(buffer
, size
, i
);
181 static LONG
getVendorIndex(UWORD vendorID
)
184 LONG upper
= vi_number
;
186 if (!mem
|| !vendor_index
)
189 while (upper
!= lower
)
193 vid
= vendor_index
[(upper
+ lower
) / 2].vendorID
;
195 return vendor_index
[(upper
+ lower
) / 2].offset
;
197 lower
= (upper
+ lower
) / 2 + 1;
199 upper
= (upper
+ lower
) / 2;
204 static LONG
getDeviceIndex(LONG vendorIndex
, UWORD deviceID
)
206 LONG i
= vendorIndex
;
211 i
= skip_line(mem
, memsize
, i
); // skip vendor
212 while ((i
< memsize
) && ((mem
[i
] == '\t') || (mem
[i
] == '#')))
218 if ((i
+ 6 < memsize
) && (mem
[i
+ 5] == ' ')
219 && (sscanf(mem
+ i
+ 1, "%hx", &did
) == 1) && (did
== deviceID
))
224 i
= skip_line(mem
, memsize
, i
);
229 static void pciids_Open(void)
234 fh
= Open("DEVS:pci.ids", MODE_OLDFILE
);
238 Seek(fh
, 0, OFFSET_END
);
239 size
= Seek(fh
, 0, OFFSET_CURRENT
);
243 memsize
= (ULONG
)size
;
244 Seek(fh
, 0, OFFSET_BEGINNING
);
246 mem
= AllocVec(memsize
, MEMF_ANY
);
250 if (Read(fh
, mem
, memsize
) != size
)
253 if (!computeVendorIndexes(mem
, memsize
))
270 static void pciids_Close(void)
274 FreeVec(vendor_index
);
285 static STRPTR
pciids_GetVendorName(UWORD vendorID
, STRPTR buf
, ULONG bufsize
)
287 LONG i
= getVendorIndex(vendorID
);
293 copy_until_eol(mem
, memsize
, i
+ 6, buf
, bufsize
);
298 static STRPTR
pciids_GetDeviceName(UWORD vendorID
, UWORD deviceID
, STRPTR buf
, ULONG bufsize
)
300 LONG i
= getVendorIndex(vendorID
);
303 if (i
< 0) // unknown vendor
306 i
= getDeviceIndex(i
, deviceID
);
307 if (i
< 0) // unknown device
310 copy_until_eol(mem
, memsize
, i
+ 7, buf
, bufsize
);
314 /* PCI Vendor/Product name translaction. Taken from PCITool */
318 OOP_AttrBase HiddPCIDeviceAttrBase
= 0;
319 OOP_Object
* pciDriver
= NULL
;
320 OOP_Object
* pciBus
= NULL
;
321 struct Library
* OOPBase
= NULL
;
323 AROS_UFH3(void, Enumerator
,
324 AROS_UFHA(struct Hook
*, hook
, A0
),
325 AROS_UFHA(OOP_Object
*, pciDevice
, A2
),
326 AROS_UFHA(APTR
, message
, A1
))
334 TEXT vendor
[100] = {0};
335 TEXT product
[100] = {0};
337 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_ProductID
, &productid
);
338 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_VendorID
, &vendorid
);
339 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_CapabilityAGP
, (APTR
)&agpcap
);
340 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_CapabilityPCIE
, (APTR
)&pciecap
);
341 pciids_GetVendorName(vendorid
, vendor
, 100);
342 pciids_GetDeviceName(vendorid
, productid
, product
, 100);
344 printf("|Video card|0x%x:0x%x %s %s",
345 (unsigned)vendorid
, (unsigned)productid
, vendor
, product
);
346 if (agpcap
) printf(" AGP");
347 if (pciecap
) printf(" PCIe");
353 static void listvideocards()
355 OOPBase
= OpenLibrary("oop.library", 0L);
356 if (!OOPBase
) return;
358 HiddPCIDeviceAttrBase
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
362 pciBus
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
365 CloseLibrary(OOPBase
);
374 struct Hook FindHook
= {
375 h_Entry
: (IPTR (*)())Enumerator
,
379 struct TagItem Requirements
[] = {
380 { tHidd_PCI_Interface
, 0x00 },
381 { tHidd_PCI_Class
, 0x03 },
382 { tHidd_PCI_SubClass
, 0x00 },
386 struct pHidd_PCI_EnumDevices enummsg
= {
387 mID
: OOP_GetMethodID(IID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
389 requirements
: (struct TagItem
*)&Requirements
,
392 OOP_DoMethod(pciBus
, (OOP_Msg
)msg
);
395 OOP_DisposeObject(pciBus
);
396 CloseLibrary(OOPBase
);
400 static void detectsystem()
402 printf("*System information*\n");
404 /* Detect CPU + Memory */
405 APTR ProcessorBase
= OpenResource(PROCESSORNAME
);
409 ULONG processorcount
;
411 struct TagItem tags
[] =
413 { GCIT_NumberOfProcessors
, (IPTR
)&processorcount
},
419 printf("|Processor count|%d|\n", (int)processorcount
);
421 for (i
= 0; i
< processorcount
; i
++)
424 STRPTR modelstr
= NULL
;
426 struct TagItem tags
[] =
428 { GCIT_SelectedProcessor
, (IPTR
)i
},
429 { GCIT_ProcessorSpeed
, (IPTR
)&frequency
},
430 { GCIT_ModelString
, (IPTR
)&modelstr
},
431 { TAG_DONE
, TAG_DONE
}
436 frequency
/= 1000000;
438 printf("|Processor #%d|%s - %d Mhz|\n", (int)i
, modelstr
, (int)frequency
);
442 printf("|Available memory|%dkB|\n", (int)(AvailMem(MEMF_ANY
) / 1024));
444 /* Detect video card device */
447 /* Detect screen properties */
449 struct Screen
* screen
= IntuitionBase
->FirstScreen
;
450 LONG sdepth
= 0, swidth
= 0, sheight
= 0;
452 swidth
= GetCyberMapAttr(screen
->RastPort
.BitMap
, CYBRMATTR_WIDTH
);
453 sheight
= GetCyberMapAttr(screen
->RastPort
.BitMap
, CYBRMATTR_HEIGHT
);
454 sdepth
= GetCyberMapAttr(screen
->RastPort
.BitMap
, CYBRMATTR_DEPTH
);
456 if (width
> swidth
) width
= swidth
;
457 if (height
> sheight
) height
= sheight
;
459 printf("|Screen information| %dx%dx%d|\n", (int)swidth
, (int)sheight
, (int)sdepth
);
465 static void textbenchmark(LONG optmode
, BOOL optantialias
, LONG optlen
)
467 STRPTR modestr
= "UNKNOWN";
468 STRPTR aastr
= "UNKNOWN";
469 TEXT lenstr
[10] = {0};
473 case(JAM1
): modestr
= "JAM1"; break;
474 case(JAM2
): modestr
= "JAM2"; break;
475 case(COMPLEMENT
): modestr
= "COMPLEMENT"; break;
480 aastr
= "ANTIALIASED";
482 aastr
= "NON-ANTIALIASED";
483 antialias
= optantialias
;
485 sprintf(lenstr
, "LEN %d", (int)optlen
);
488 printf("|%s, %s, %s|", modestr
, aastr
, lenstr
);
493 static void textbenchmarkset()
495 printf("*Text benchmark %dx%d*\n", (int)width
, (int)height
);
496 printf("||Test||Blits/s||MB/s||\n");
497 textbenchmark(JAM1
, FALSE
, 100);
498 textbenchmark(JAM2
, FALSE
, 100);
499 textbenchmark(COMPLEMENT
, FALSE
, 100);
500 textbenchmark(JAM1
, TRUE
, 100);
501 textbenchmark(JAM2
, TRUE
, 100);
502 textbenchmark(COMPLEMENT
, TRUE
, 100);
503 textbenchmark(JAM1
, FALSE
, 5);
504 textbenchmark(JAM2
, FALSE
, 5);
505 textbenchmark(COMPLEMENT
, FALSE
, 5);
506 textbenchmark(JAM1
, TRUE
, 5);
507 textbenchmark(JAM2
, TRUE
, 5);
508 textbenchmark(COMPLEMENT
, TRUE
, 5);
512 static void pixelarraybenchmark(LONG optpixfmt
, LONG optfunction
)
514 STRPTR functionstr
= "UNKNOWN";
515 STRPTR pixfmtstr
= "UNKNOWN";
520 case(FUNCTION_WRITE
): functionstr
= "WritePixelArray"; break;
521 case(FUNCTION_READ
): functionstr
= "ReadPixelArray"; break;
522 case(FUNCTION_WRITE_ALPHA
): functionstr
= "WritePixelArrayAlpha"; break;
525 for(i
= 0; pixfmt_table
[i
].name
; i
++)
527 if (pixfmt_table
[i
].id
== optpixfmt
)
529 pixfmtstr
= pixfmt_table
[i
].name
;
535 function
= optfunction
;
537 printf("| %s %s|", functionstr
, pixfmtstr
);
542 static void pixelarraybenchmarkset()
544 printf("*PixelArray benchmark %dx%d*\n", (int)width
, (int)height
);
545 printf("||Test||Blits/s||MB/s||\n");
546 pixelarraybenchmark(RECTFMT_RGB
, FUNCTION_WRITE
);
547 pixelarraybenchmark(RECTFMT_ARGB32
, FUNCTION_WRITE
);
548 pixelarraybenchmark(RECTFMT_RGBA
, FUNCTION_WRITE
);
549 pixelarraybenchmark(RECTFMT_RGB16PC
,FUNCTION_WRITE
);
550 pixelarraybenchmark(RECTFMT_LUT8
, FUNCTION_WRITE
);
551 pixelarraybenchmark(RECTFMT_RGB
, FUNCTION_READ
);
552 pixelarraybenchmark(RECTFMT_ARGB32
, FUNCTION_READ
);
553 pixelarraybenchmark(RECTFMT_RGBA
, FUNCTION_READ
);
554 pixelarraybenchmark(RECTFMT_RGB16PC
,FUNCTION_READ
);
555 pixelarraybenchmark(RECTFMT_ARGB32
, FUNCTION_WRITE_ALPHA
);
563 pixelarraybenchmarkset();