Wednesday, February 1, 2017

Stingray Renderer Walkthrough #1: Overview

Stingray Renderer Walkthrough #1: Overview

Introduction

When we started writing Bitsquid back in mid 2009 all platforms we intended to run on were already multi-core architectures. This and the fact that we had some prior experience trying to get our last engine to run efficiently on the PS3 answered the question how not to architecture an efficient renderer that scales to many cores. We knew we needed more than functional parallelism, we wanted data-parallelism.

To solve that we divide the CPU view of a rendered frame into three stages:

  1. Culling - Filter out visible renderable objects with respect to a camera from a potentially huge set of different type of objects (meshes, particle systems, lights, etc).
  2. Render - Iterate over the filtered result from Culling and “record” an intermediate representation of draw calls/state switches to a command buffer.
  3. Dispatch - Take result from Render and translate that into actual render API calls (D3D, OGL, Metal, GNM, etc).

As you can see each stage pipes its result into the next. Rendering is typically very simple in that sense; we tend to have a one way flow of our data: [[user input or time affects state, state propagates into changes of the renderable objects (transforms, shader constants, etc), figure out what need to be rendered, iterate over that and finally generate render API calls. Rinse & Repeat :]]

If we ignore the problem of ordering the final API calls in the rendering backend it’s fairly easy to see how we can achieve data parallelism in this scenario. Just fork at each stage splitting the workload into a n-chunks (where n is however many worker threads you can throw at it). When all workers are done for a stage take the result and pipe into the next stage.

In essence this is how all rendering in Stingray works. Obviously I’ve glanced over some rather important and challenging details but as you will see they are not too hard to solve if you have good control over your data flows and are picky about when mutation of the data happens.

Design Philosophies & Concepts

The rendering code in Stingray tends to be heavily influenced by Data Oriented Programming principles. When designing new systems our biggest efforts usually goes into structuring our data efficiently and thinking about its flow through the systems, more so than writing the actual code that transforms the data from one form to another.

To achieve data-parallelism throughout the rendering code the first thing to realize is that we have to be very picky about when mutation of the renderable objects happens. Multiple worker threads will run over our objects and its not unlikely that more than one thread visits the same object at the same time, hence we must not mutate the state of our objects in its render function. Therefore all of our render() functions are const.

To further guard ourselves from the outer world (i.e gameplay, physics, etc) the renderer operates in complete isolation from the game logics. It has its own representation of the data it needs, and only the data relevant for rendering. While the gameplay logics usually wants to reason about high-level concepts such as game entities (which basically groups a number of meshes, particle systems, lights, etc together), we on the rendering side don’t really care about that. We are much more interested in just having an array of all renderable objects in a game world, in a memory layout that makes it efficient to access.

Another nice thing with decoupling the representation of the renderable objects from the game objects is that it allows us to run simulation in parallel with rendering (functional parallelism). So while simulation is updating frame n the renderer is processing frame n-1. Some of you might argue that overlaying rendering on top of simulation doesn’t give any performance improvements if the work in all systems is nicely parallelized. In reality though this isn’t really the case. We still have systems that don’t go wide, or have certain sections where they need to do synchronous processing (last generation graphics APIs: e.g DX11, OpenGL are good examples). This creates bubbles in the frame slowing us down.

By overlaying simulation and rendering we get a form of bubble filling among the worker threads which in most cases gives a big enough speed improvement to justify the added complexity that comes from this architecture. More specifically:

  1. Double buffering of state - since the simulation might mutate the state of an object for frame n at the same time as the renderer is processing frame n-1 any mutable state needs to be double buffered.
  2. Life scope tracking of immutable data - while immutable/read only state such as static vertex and index buffers are safe to read by both simulation and renderer we still need to be careful not pulling the rug under the renderers feet by freeing anything still being in use by the renderer.

Here’s a conceptual graph showing the benefits of overlaying simulation and rendering:

So basically what we got here is two “controller threads”: simulation and render both offloading work to the worker threads. In the case that a controller thread is blocked waiting for some work to finish it will assist the worker threads striving to never sit idle. One thing to note is that to prevent frames from stacking up, we never allow the simulation thread to run more than one frame ahead of the render thread.

As a comparison here’s the same workload with simulation and rendering running in sequence.

As you can see we get significantly more idle time (bubbles) on the worker threads due to certain parts of both the simulation and rendering not being able to go wide.

Next up

I think this pretty much covers the high level view of the core rendering architecture in Stingray. Now lets go into some more detail.

Since Andreas Asplund recently covered both how we handle propagation of state from simulation to the renderer (we call this “State reflection” in Stingray): http://bitsquid.blogspot.se/2016/09/state-reflection.html as well as how our view frustum culling system(s) works: http://bitsquid.blogspot.se/2016/10/the-implementation-of-frustum-culling.html I won’t be covering that in this series.

Instead I will jump straight into how creating and destroying GPU resources works, and from there go through all the building blocks needed to implement the second stage Render mentioned above.

65 comments:

  1. Good one you explain. all building and civil related work to must use for the pre engineering process is very well done to introduce. Majorly access material is boom lift rental for access and tools used for core work. Thanks for the opportunity. and Thanks for post and creadited to Sendhamarai Engineering.

    ReplyDelete
  2. Wow, Great information and this is very useful for us.

    Aluminium scaffolding hire

    ReplyDelete
  3. Our sap scm mentors are sap production network the board (sap scm) ensured specialists and experienced working experts with hands on ongoing numerous SAP SCM ventures information. We have planned our sap scm course substance and prospectus dependent on understudies necessity to accomplish everybody's profession objective. In our sap scm training program, you will learn request the board, Supply Network Planning Heuristic, SNP Run Using Capable, SNP Configuration, Master Data and Transaction Data in SNP, Demand Planning, Interactive Planning, Safety Stock Planning, sap scm continuous venture and sap store network the board (sap scm) placement training.

    For More Info:- SAP SCM Course in Gurgaon

    ReplyDelete
  4. Thanks for the info. Please keep sharing the good stuff. I'm a first time visitor of your website and I love the information people share here. I'll bookmark your site and keep visit regularly. I was looking for Best Hindi Shayari Collection and I found this..

    Best Hindi Shayari Collection Best Hindi Shayari Collection
    Love Shayari Love Shayari
    Sad Shayari Sad Shayari
    Romantic Shayari Romantic Shayari
    Urdu Shayari Urdu Shayari
    Friendship Shayari Friendship Shayari
    New Shayari New Shayari
    Motivational Shayari Motivational Shayari
    Best Shayari Best Shayari
    Shayari Images to download Shayari Images to download

    ReplyDelete
  5. Very nice blog post, it is informative and i subscribed for all its future post. there are some useful links, i think i must share here:
    www.mcafee.com/activate
    mcafee.com/activate

    ReplyDelete
  6. What a resourceful piece of information thanks you for sharing. When it becomes hard to manage your resources, you can check this. I am very happy to read your post. I'm also sharing my nice stuff to you guys please go through it and take a review.

    outsource digital marketing services
    outsource website development
    top digital marketing agencies in india
    virtual assistant websites
    web design and development india
    web design and development india

    ReplyDelete
  7. Detroit Metropolitan Wayne County Airport- Choose Detroit Metropolitan Wayne County Airport to start your journey. Enjoy discounts and deals, book with us.

    ReplyDelete
  8. You can get more offers through Lufthansa Airlines Phone Number , which mainly looks for any details that you usually really like your airline. Want to experience with Lufthansa Airlines Phone Number is your personal travel agent who books your plan.

    ReplyDelete
  9. Get easy and quick reservations for American Airlines Cancellation . So there is no need to wait in lines now when all your booking can be done on the call of our travel expert.

    ReplyDelete
  10. Book your flight tickets effortlessly and also check-in through the website by visiting our “ Qatar Airways Contact Number ” website. You can contact us anytime. Our experts are always ready to assist you anytime.

    ReplyDelete
  11. If you wish to cancel your ticket that was purchased from American Airlines, you can contact American Airlines Cancellation through an online refund request by communicating customer support.

    ReplyDelete
  12. You just have to call Southwest Airlines Customer Service for flight booking our services. Get ready to have a joyful and comfortable journey with us.

    ReplyDelete
  13. Etihad Airways helps you to get luxurious facilities in low-cost. You can avail of all amazing facilities by connecting with us. Just dial Etihad Airways Contact Number and resolve all your travel-related issues here.

    ReplyDelete
  14. Feel free to get in touch with us via British Airways Toll Free Number to get the great deals and offers on your flight tickets and get all your problems and questions resolved in no time. We have a team of experts who are well-trained and always ready with support of your queries.

    ReplyDelete
  15. Plan a journey and contact our travel specialists on United Airlines Phone Number. helpline. With us, nothing is unattainable for our esteemed customers. United Phone Number is our toll-free service which takes care of all your booking needs when you want to move across to your destination for business or leisure purposes.

    ReplyDelete
  16. Call Etihad Airways Phone Number for your cheapest airfares across destinations. With a journey in your mind, Etihad Phone Number helpdesk is your best help.

    ReplyDelete
  17. If you are looking for reliable and affordable services then visit Spirit Airlines Contact Number . Here you can get best deals and offers on your flight tickets. So, go now book your flight tickets at low-cost. Now you can fulfil your vacation dreams in your budget.

    ReplyDelete
  18. If you are paining your trip by flights and looking to Travel several beautiful places then just visit at Airlines Low Fare Calendar where you don’t need to search over dates now and you will find the lowest airfare options for both domestic as well as international flights.. Get comfortable services to reach relaxed to your destination.

    ReplyDelete
  19. Nice Blog everything is very open with a very clear explanation of the challenges.If you have made your mind to make your travel hassle free then visit at Air France Airlines Low Fare Calendar .It shows you the ticket prices to the cities near & far and all of those will pop-up promptly.They are accessible 24*7 and working enthusiastically.Add brilliant moments in your journey when booking with us.

    ReplyDelete
  20. This is really a nice and informative blog. Want to explore the world, but tight-budget kills those dream of traveling. Not anymore, jump over the hurdle name budget and touch the finish line where your traveling dream starts with our great discounts and deals on air-tickets at American Airlines Low Fare Calendar and If your travel dates rescheduled. You can check the full month fare and purchase the flight tickets on the most auspicious day.

    ReplyDelete
  21. If you want to make your dream comes true with your loved once and looking for great deals and amazing discounts on airfares then get ready to book your flight
    tickets from Etihad Airways Low Fare Calendar This allow you to buy your tickets with the several low fare options which are available for you. The options are flexible with your travel plans.

    ReplyDelete
  22. Awesome Blog, Thanks for providing important informations there.Need to book tickets at last minute but don’t have time to go through the traditional time-consuming ways, just visit at Air Canada Airlines Low Fare Calendar This way of planning will help you in saving a lot on your budget and thus, will make your worthwhile journey.

    ReplyDelete
  23. Very infromative blog thant you.If you are looking for special assistance for flight then just dial Air china Toll free Number . and get the resolution of every flight related queries at your finger tips.

    ReplyDelete

  24. We understand the need of guidance and information for the new and experienced travelers. It is time-consuming and baffling to deal with numerous issues. Therefore, our team of experts are available round the clock and will brief you smoothly on various flights at Turkish Contact Number and will also help with all the available routes.

    ReplyDelete
  25. Book Delta Airlines Flights Tickets, vacation packages, and other travel services with us at the best-discounted price. Call us or visit our website to know the latest deals & offers.

    ReplyDelete
  26. Modify your journey details according to your new itinerary with Hawaiian Airlines Manage Booking service. So change your details as per your requirements.

    ReplyDelete
  27. Comfortably manage your Delta Airlines bookings within no time with the help of Delta Airlines Manage Booking helpdesk. We are available 24/7. Call Now!!

    ReplyDelete
  28. If you want to make changes in your flight booking then contact us through Emirates Airlines Manage Booking helpdesk. Also, know about our exclusive offers!

    ReplyDelete
  29. Enjoy your trip with your loved once and looking for great deals and amazing discounts on airfares then get ready to book your flight tickets from Air china Toll free . and Get a chance to avail of great offers, services, deals, discounts, and amazing vacation packages.

    ReplyDelete

  30. Awesome Blog, Thanks for providing important informations there.When you plan a great trip or vacation with your friends or family, the first and foremost thing that you do is searching for a cost-effective mode of traveling and the airline is flying to several destinations, so you can choose your destination to fly according to cheapest dates by Qatar Customer Service .

    ReplyDelete
  31. Are you getting errors with you Dell Printer Setup? Just dial our toll-free number. Our helpdesk technicians are certified and capable to assist you. Call Now!!

    ReplyDelete
  32. Travelers always look for cheap flights, hotels, and vacation packages to lower down their costs to spend more on other stuff like shopping, and exploring other things. Southwest Airlines is one of the largest flight carriers that offer the lowest flight fares for domestic flights.

    Check out the link to know the latest flight fares and other deals.

    Southwest Reservations

    Southwest Airlines Reservations

    Southwest Flights

    ReplyDelete
  33. Air Canada is the banner transporter and the biggest carrier of Canada by armada size and travelers conveyed. The carrier, established in 1937, gives planned and contract air transport for travelers and loads to 207 destinations around the world. It is an establishing individual from the Star Alliance. Air Canada's corporate central command is in Montreal, Quebec, while its biggest center point is at Toronto Pearson International Airport. The aircraft's provincial help is Air Canada Express.

    Air Canada Reservations | Delta First Class

    ReplyDelete
  34. Air Canada is the banner transporter and the biggest carrier of Canada by armada size and travelers conveyed. The carrier, established in 1937, gives planned and contract air transport for travelers and loads to 207 destinations around the world. It is an establishing individual from the Star Alliance. Air Canada's corporate central command is in Montreal, Quebec, while its biggest center point is at Toronto Pearson International Airport. The aircraft's provincial help is Air Canada Express.

    Air Canada Reservations | Delta First Class

    ReplyDelete
  35. If you face any issue during software downloading and installation, contact our helpdesk for Samsung Printer Setup. We are available 24/7. Call now.

    ReplyDelete
  36. Looking for reliable and affordable service of Mobile Locksmith Near Me, we can help you, as we have a team of certified and trained locksmiths. Call now.

    ReplyDelete
  37. If you want to make changes in your ticket type and not able to access your British Airways Manage Booking then contact us. We are available 24/7.

    ReplyDelete
  38. If you face any issue during software downloading and installation, contact our helpdesk for Samsung Printer Setup. We are available 24/7. Call now.

    ReplyDelete
  39. If your printer showing errors with your printer setup. You can call us at our toll-free number to get the best HP Printer Setup help. Call us now.

    ReplyDelete
  40. We provide a detailed update regarding cricket matches on a daily basis. We offer you the best India fantasy information and cricket news and player. So that you Get Best today match prediction and increase your chances of a win.
    dream11 apk

    ReplyDelete
  41. To be honest I found very helpful information your blog thanks for providing us such blog yuzvendra chahal wife

    ReplyDelete
  42. We provide a detailed update regarding cricket matches on a daily basis. We offer you the best India fantasy information and cricket news and player. So that you Get Best today match prediction and increase your chances of a win.
    win the 2023 ODI World Cup

    ReplyDelete
  43. Airlines-gethuman.org is a platform where you can Find Contact Information for all the airlines, Assistance with booking your flights, and vacation packages easily. It helps you to save both, your money and your time. We also help you to book Delta Airlines Reservations to or from popular destinations. In case, you are not sure about your destination and want to explore something new. Explore our best flights & vacations deals to popular destinations worldwide. For More:
    Delta Airline Flights

    ReplyDelete
  44. Get your bug control from the best service provider in the industry. Contact Massey Pest Control to book your first time free consultation.

    ReplyDelete
  45. Take your pest infestation seriously once you notice a few pests in your property. Call us at Dewey Pest Control for ultimate bug control services.

    ReplyDelete
  46. We offer more opportunities for great feedback in travel time. So, what are you waiting for now? Dial Southwest Airlines Phone Number or grab the amazing plan.

    ReplyDelete
  47. Get more mileage, the above facilities combine with Southwest Customer Service specialists. Save your time or money with a toll-free number.

    ReplyDelete
  48. Saving and Travelling is my two favorite things, but find a cheap flight always gives me a headache. Finally, I got a great solution when I was flying with Lufthansa Airlines. Prompt and amazing Lufthansa Airlines Phone Number, I got amazing deals and discounts with the best facilities. I will recommend Lufthansa Airlines Phone Number to all travelers.

    ReplyDelete
  49. Southwest Airlines Customer Service is the best platform for those travelers who are looking for the best deals along with 24/7 quick assistance. Especially, first time travelers or someone flying alone for the first time will find Southwest Airlines Customer Service very helpful. We will tell you all vital important such as flight tickets fare, availability, check-in, and everything which comes under the process of handling the reservation desk.

    ReplyDelete
  50. I love traveling and flights are like my second home in clouds. I always search for comfortable and affordable flight experience. I came across American Phone Number- it’s a great team that helps travelers to book their tickets at a cheap rate. Plus, they also helped me with my baggage and check-in. I would love to travel with them again.

    ReplyDelete
  51. Hey! I’m a regular visitor to your amazing website. By the way, I work with Allegiant Airlines. Because of the current pandemic situation, traveling is like gambling of life. S, if anyone wants to cancel their flight tickets, I would love to help them. Visit Allegiant Airlines Cancellation Helpdesk, our team will help you.

    ReplyDelete
  52. In simple words this website is great, all information is very useful. Well, there is a reason that comes to this website. Traveling in Covid-19 is very risky and people facing difficulties with the cancellation of their flight ticket. So, if you want to cancel your Southwest Flight Tickets, visit Southwest Airlines Cancellation helpdesk for assistance.

    ReplyDelete
  53. Got connected with a travel expert by dialing American Airlines Phone Number and he helped me a lot in choosing the right flight as per my budget. The agent available was so humble, patient and professional. He solved all my issues and queries and helped me in booking the flight tickets. Will definitely fly in American Airlines again.

    ReplyDelete
  54. Manga stories are typically printed in black-and-white due to time constraints, artistic reasons (as colouring could lessen the impact of the artwork) and to keep printing costs low although some full-colour manga exist. In Japan, manga are usually serialized in large manga magazines, often containing many stories, each presented in a single episode to be continued in the next issue. the best manga reading site in Indonesia, the fastest update
    baca komik boruto,
    baca boruto,
    manga boruto indonesia,
    baca manga boruto,
    boruto manga indonesia,
    komik boruto sub indo,
    situs baca manga terbaik bahasa indonesia

    boruto chapter 14 bahasa indonesia
    komik boruto chapter 7
    komik boruto chapter 22
    komik boruto 18
    boruto manga 24
    cara menghilangkan background foto
    berita online masa kini
    berita gadget terbaru

    ReplyDelete