• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ic0de

Is OpenCL what I need?

11 posts in this topic

I wrote a terrain raycaster that runs entirely on the CPU but not nearly as fast as i want it to considering Comanche did it back in 1992. A large bottleneck in my code is the fact that bilinear filtering is done on the CPU. One reason I thought I should move my raycaster to OpenCL is because the algorithm is extremely parallelizable beyond the cabilities of multicore cpus. The renderer shoots off a ray for every column of pixels and then checks the hieght of every fragment it hits rendering heights as so. So I have two main questions:

1. Can I use OpenCL to access the dedicated filtering hardware?
2. Is it feasible to use OpenCL for my raycaster?

attached is a screenshot of my raycaster.
0

Share this post


Link to post
Share on other sites

OpenCL is certainly an option, but why not just use graphics shaders? OpenCL most likely won't give you access to hardware filtering, whereas a graphics shader will. OpenCL is more general purpose and can run on any kind of parallel hardware (multiple cores on a CPU, or CUDA cores on an nvidia card for example), but since you're working with a graphics algorithm anyway, you might as well use something like GLSL or HLSL.

0

Share this post


Link to post
Share on other sites
OpenCL is certainly an option, but why not just use graphics shaders? OpenCL most likely won't give you access to hardware filtering, whereas a graphics shader will. OpenCL is more general purpose and can run on any kind of parallel hardware (multiple cores on a CPU, or CUDA cores on an nvidia card for example), but since you're working with a graphics algorithm anyway, you might as well use something like GLSL or HLSL.

The problem with GLSL/HLSL is that they are deeply integrated into the OpenGL/D3D pipeline. A shader operates on a single pixel but my algorithm draws columns at a time. Ideally I would be using a shader that instead of outputting a one pixel can write pixels wherever it chooses. In short if I were to use shaders to get the same effect I would need exponentially more rays. This is a 2d raycaster like wolfenstein 3d or doom and almost exactly like comanche its not a good fit for the shading pipeline.
1

Share this post


Link to post
Share on other sites
OpenCL is certainly an option, but why not just use graphics shaders? OpenCL most likely won't give you access to hardware filtering, whereas a graphics shader will. OpenCL is more general purpose and can run on any kind of parallel hardware (multiple cores on a CPU, or CUDA cores on an nvidia card for example), but since you're working with a graphics algorithm anyway, you might as well use something like GLSL or HLSL.

The problem with GLSL/HLSL is that they are deeply integrated into the OpenGL/D3D pipeline. A shader operates on a single pixel but my algorithm draws columns at a time. Ideally I would be using a shader that instead of outputting a one pixel can write pixels wherever it chooses. In short if I were to use shaders to get the same effect I would need exponentially more rays. This is a 2d raycaster like wolfenstein 3d or doom and almost exactly like comanche its not a good fit for the shading pipeline.

 

In that case why not draw a series of 1-pixel wide quads on the screen and do your ray casting in the vertex shader? That way your vertex shader is your "column" drawer, and the pixel shader just uses whatever value was given it by the vertex shader to calculate the final color. 

 

Another idea is to have your pixel shader figure out what column its pixel falls in and use that information for the color. The pixel shader will always get executed for each pixel that falls on a rasterized primitive, so why not take advantage of that parallelism?

0

Share this post


Link to post
Share on other sites

Just a question you should ask yourself. Sadly I don't know the answer myself.

 

Is OpenCL really delivering what it is promising?

 

Or more detailed:

Can you really run it on all platforms you're targeting?

Is an additional driver installation required? If not when can you safely assume that OpenCL is there?

Do you still need a non-OpenCL version for platforms where OpenCL is unavailable or can you just tell the user to screw himself?

 

I would love some of the answers myself, but I guess that would need more research.

 

Maybe the Graphics card vendors are shipping the OpenCL runtime with their GPU drivers, that would be great because asking the user to install another driver is often asked too much.

However what about graphic cards that don't ship with OpenCL, is OpenCL automatically able to run on the CPU or are CPU drivers required?

 

Good luck

-Christoph

0

Share this post


Link to post
Share on other sites

You could use either OpenCL or HLSL/GLSL -- Those fancy Parallax Shaders are a form of ray-casting for example.

 

However, more to the point, as you said yourself, Games like Delta Force: Land Warrior did this stuff on CPUs way back in the day -- I recall running Delta Force at relatively low settings on a Pentium 2 @ 233Mhz -- and Commanche did it even earlier. I'm pretty sure I've seen a similar, though limited, voxel terrain running on either the Gameboy advance or some microcontroller as a tech demo.

 

It sounds to me that you simply need to dive into optimizing your code -- A single modern CPU core ought to be able to push modern, full-screen resolutions if you can achieve similar efficency to those old games (and I bet a really optimized one could do perhaps twice the frame-rate at the same time). Modern CPUs have 2, 4, even 6  cores (Discounting AMD's "8-core" Bulldozer, but are slower) so there's absolutely no reason you shouldn't be able to get satisfactory results.

 

I imagine you'd learn more by making your CPU algorithm fast, than by porting your slow CPU algorithm to OpenCL or shaders.

Edited by Ravyne
2

Share this post


Link to post
Share on other sites
I imagine you'd learn more by making your CPU algorithm fast, than by porting your slow CPU algorithm to OpenCL or shaders.

I guess i'll do that then, there are parts of my code that are screaming for more sse stuff
0

Share this post


Link to post
Share on other sites

One benefit of moving it to the GPU would be that then you dont need to stream 60 FPS picture to the GPU, which could be important if you want to lets say draw regular rasterized polygon meshes on top of the terrain, or simply use the CPU for something else.

1

Share this post


Link to post
Share on other sites
I imagine you'd learn more by making your CPU algorithm fast, than by porting your slow CPU algorithm to OpenCL or shaders.

I guess i'll do that then, there are parts of my code that are screaming for more sse stuff

 

SSE is good, but that's more of a micro-optimization, your fundamental problem is more-likely algorithmic -- in other words, you need to do less work, not the same amount of work more quickly.

 

For example:

 

Are you using Level-of-Detail for far-away landscapes?

Are you calculating/drawing slices that will just get covered by nearer and taller slices?

 

Are you paying attention to how data is moving through the memory hierarchy?

 

Have you read anything about the techniques that were used to achieve Commanche/Delta Force/Outcast? I know I've read whitepapers or blog posts about them at one point.

1

Share this post


Link to post
Share on other sites
For example:

Are you using Level-of-Detail for far-away landscapes?
Are you calculating/drawing slices that will just get covered by nearer and taller slices?

Are you paying attention to how data is moving through the memory hierarchy?

Have you read anything about the techniques that were used to achieve Commanche/Delta Force/Outcast? I know I've read whitepapers or blog posts about them at one point.


All slices are sampled but are discarded before being drawn if they are hidden by a taller slice, I tried doing a fast single channel sample just for the height lookup but my sse version was just as fast and i was just making it slower. LOD is probably a good idea Ill look into that. I know Comanche had a shorter render distance and didn't use any filtering but then again I ran it on a 25mhz 386sx just as fast.

Edited by ic0de
0

Share this post


Link to post
Share on other sites

[quote name='ic0de' timestamp='1356794744' post='5015438']
ran it on a 25mhz 386sx just as fast
[/quote]

 

You can't really compare it directly. For example CPU speeds increased much more than memory speed did.

And thats where graphic cards have the advantage, while the gpu is glocked much lower than a cpu it has faster memory with more bandwidth. Of course having hundreds of processing units also helps.

 

But the memory is really where it gets difficult, because if you double your vertical and horizontal resolution you've already quadrupled the screen buffer size. Which means you need four times the bandwidth. Delta Force, Commance, Outcast used maybe 640x480 (307200 pixels), maybe more, maybe less, nowadays I run games in 1920x1200 (2304000 pixels). That's 7 times the number of pixels, not counting anti-aliasing. And almost all the time the work done per pixel has also increased.

 

Just an example, there is this demo called heaven seven which used realtime-raytracing (cpu). It's from mid 2000. Now more than 12 years later there is still nobody that is using realtime-raytracing in a broader scale.

 

 

[quote name='ic0de' timestamp='1356675956' post='5014999']
The problem with GLSL/HLSL is that they are deeply integrated into the OpenGL/D3D pipeline.
[/quote]

While it's true, using some tricks or hacks you can do alot of things in the shader, that where never to be done on it.

If you need an example, take a look at my (still work in progress) website. Or look around the web for more examples of creative shader usage. (The examples you can find on the web are probably less hackish...)

0

Share this post


Link to post
Share on other sites
OpenCL is likely not the right solution. You will end up spending a lot of time with setup, and use of OpenCL. Furthermore, is the CL buffer mapping to GL buffer slow. So the bottleneck on the CPU implementation, may also be the bottleneck when using OpenCL for rendering.
I have to admit that OpenCL is more stylish, and in many ways easier for others to understand. However it takes time to become familiar with it, so why not use GLSL?

While it's true, using some tricks or hacks you can do alot of things in the shader, that where never to be done on it.If you need an example, take a look at my (still work in progress) website. Or look around the web for more examples of creative shader usage. (The examples you can find on the web are probably less hackish...)
To support shadowomf, i claim that you can do the same things in a shader as in OpenCL. You only need to think innovative, in other words use framebuffers, textures and transform feedbacks, then you can do pretty much whatever you want.

Good luck Edited by Tapped
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0