วันอาทิตย์ที่ 18 พฤษภาคม พ.ศ. 2551

ati ผิดหวังอย่างแรง

สืบเนื่องจากการทดลองลงเครื่อง pheonom + HD3870 ก็เลยซื้อมาทดลองใช้กับ project นี้ดูบ้าง ก็รากฏว่า ต้องผิดหวังอย่างแรง ตั้งแต่การลงที่ค่อนข้างยาก ผมลงไม่สำเร็จบน kubuntu 7.04 จึงต้องลงเครื่องใหม่เป็น 7.10 แล้วใช้ script จำพวก envy มาช่วยลงก็ถึงจะทำได้อย่างเรียบรอยดีไม่มีปัญหา

แต่ปัญหาหลักที่ทำให้ต้องยกเลิกความคิดที่จะใช้การ์ดนี้ก็คือ มันไม่สามารถเล่น tvtime ได้ เนื่องจาก fglrx ซึ่งเป็น driver ของการ์ด มันไม่ support pixel format YUY2 ซึ่ง tvtime ต้องการ

เซ็งเลย เพราะ performance เวลารัน glxgears เมื่อเทียบกับ 8600gt นั้น มันทำ frame rate ได้ดีกว่าถึง 2 เท่า เดี๋ยวจะไปซื้อ 9600 มาลองเปรียบเทียบกันอีกที

วันอังคารที่ 13 พฤษภาคม พ.ศ. 2551

OpenGL ตอนที่ 2

ในที่สุดก็ใช้งาน OpenGL เบื้องต้นได้ ที่บอกว่าเบื้องต้นก็เพราะ มันดูเหมือนไม่ได้ช่วยให้ CPU ทำงานน้อยลงเลย หรือมันถูก block ไว้ก็ไม่รู้ แต่มันก็ช่วยให้ frame rate ดีขึ้นแหละนะ หลักๆที่แก้ไป ไม่ใช่เรื่อง multi-thread เพราะออกแบบให้ copy ลง memory ก่อนแล้วค่อยให้ gui thread เรียก glTexSubImage2D อยู่แล้ว แต่เป็นเรื่องการทำงานร่วมกันระหว่าง wxGLCanvas กับ glut และ OpenGL มากกว่า โดยไปออกแบบใหม่ให้ลด layer ของ window ลง ลองไปอ่านใน wiki ดูนะคร้าบ อีกอันหนึ่งคือ การสร้าง texture object ดูเหมือนว่าเราจะสร้างใน constructor ของ wxGLCanvas ไม่ได้นะ ต้องให้มัน show ก่อน

อย่างไรก็ดี คงจะต้องปรับปรุงกันต่อไป เห็นมีการพูดถึง Pixel Buffer Object ไม่รู้ว่าจะช่วยได้ป่าว ต้องลองดูตามที่ไปหามา(อีกแล้ว)

1. Create PBO
2. map buffer
3. give pbo pointer to decoder thread (or put it in pool of free pbo's)
4. decoder copy frame in pbo memory and notify render thread about that, or decoder ask pool for free pbo pointer and copy image data and notify render thread about that.
5. render thread unmap pointer and call glTexSubImage2D
6. render thread mark that pbo to map its pointer again at next frame (or two frames later)
7. at next frame (or two frames later) map pbo pointer and give it to decoder thread (or pool)

Using pool you can handle multiple video stream transfers.

ก๊อปมาจาก ที่นี่ จ้า

ติตตามความคืบหน้ากันต่อไป

วันอาทิตย์ที่ 4 พฤษภาคม พ.ศ. 2551

OpenGL and Multithreading

หลังจากที่ต้องการวาดภาพที่ได้จากหลายๆตัวพร้อมๆกัน โดยใช้ multi-thread นั้นก็พบว่า ถ้าไม่ใช้ความสามารถของการ์ดจอเข้ามาช่วยละก็พอแต่ละ window มันใหญ่ขึ้น ก็จะกิน cpu แบบมหาศาล แล้วจะ crash ไปในที่สุด ไม่สามารถรันติดต่อกันเป็นเวลานานๆได้ นั่นเป็นเรื่องที่ยอมรับไม่ได้เลยทีเดียว (จากการทดสอบ ถา้เปิดแค่สองกล้อง จะรันได้ข้ามวัน แต่ถ้าเปิดสี่กล้อง สองชั่วโมงก็ตายแว้วว) อันนี้ไม่เกี่ยวกับเมมโมรี่ แต่สังเกตได้ว่าเกิดจากการที่ main thread ซึ่งทำหน้าที่วาดที่ทุกอย่างนั้นทำงานช้าเกินไป

จากที่เล่ามาข้างบนจึงมาคิดว่า คงต้องให้การ์ดจออันแสนแพง ทำงานคุ้มค่าหน่อย วิธีหนึ่งที่ทำได้ง่ายๆคือใช้ OpenGL ใช่มั้ยครับ แต่ แต่ช้าแต่ ช้าก่อนครับ มันไม่ง่ายอย่างนั้นน่ะสิ เพราะตอนนี้เราทำงานแบบ multihreading ซึ่งตัว OpenGL มันเหมือนจะไม่ได้ออกแบบมาเพื่อการนี้สักเท่าไร ถึงกระนัน้ก็ตาม ไม่ใช่ผมเป็นคนแรกที่คิดจะทำแบบนี้แน่่นอน ว่าแล้วก็ค้นดูจาก google จนได้ link ไปที่ forum ซึ่งมีการพูดคุยเรื่องนี้อยู่ และมีคนแนะนำไว้ว่าอย่างนี้

(I copied this below text from this link)
The basic problem with multithreading in OGL is the fact that OGL context, which contains entire state of the OGL, can be at one time bound to only one thread. Because of this you can not simultaneously modify it from two threads. You basically have three options.
  • You can create one context for each thread and enable sharing of display lists and textures between them. It is likely that this path is not too well supported by the drivers.
  • You can load and prepare the resources by the second thread and let the main thread do the creation call into OGL.
  • If the resource type supports it (e.g. VBO), you can map its memory by the main thread. Fill it in the second thread and unmap it by the main thread
ประเด็นมันอยู่ตรงนี้เอง นั่งทำอยู่สองวัน ได้แค่หน้าจอดำๆ ต้องกลับไปแก้ไขใหม่ ได้เรื่องอย่างไรแล้วจะเอามาให้ชมเป็นตอนต่อไป อ้อ การเขียน OpenGL บน wxWidgets นั้น เค้ามี class wxGLCanvas่ กับ wxGLContext มาให้ใช้ ช่วยให้สะดวกขึ้นมิใช่น้อย