Wednesday, February 22, 2017

Stingray Renderer Walkthrough #6: RenderInterface

Stingray Renderer Walkthrough #6: RenderInterface

Today we will be looking at the RenderInterface. I’ve struggled a bit with deciding if it is worth covering this piece of the code or not, as most of the stuff described will likely feel kind of obvious. In the end I still decided to keep it to give a more complete picture of how everything fits together. Feel free to skim through it or sit tight and wait for the coming two posts that will dive into the data-driven aspects of the Stingray renderer.

The glue layer

The RenderInterface is responsible for tying together a bunch of rendering sub-systems. Some of which we have covered in earlier posts (like e.g the RenderDevice) and a bunch of other, more high-level, systems that forms the foundation of our data-driven rendering architecture.

The RenderInterface has a bunch of various responsibilities, including:

  • Tracking of windows and swap chains.

    While windows are managed by the simulation thread, swap chains are managed by the render thread. The RenderInterface is responsible for creating the swap chains and keep track of the mapping between a window and a swap chain. It is also responsible for signaling resizing and other state information from the window to the renderer.

  • Managing of RenderWorlds.

    As mentioned in the Overview post, the renderer has its own representation of game Worlds called RenderWorlds. The RenderInterface is responsible for creating, updating and destroying the RenderWorlds.

  • Owner of the four main building blocks of our data-driven rendering architecture: LayerManager, ResourceGeneratorManager, RenderResourceSet, RenderSettings

    Will be covered in the next post (I’ve talked about them in various presentations before [1] [2]).

  • Owner of the shader manager.

    Centralized repository for all available/loaded shaders. Controls scheduling for loading, unload and hot-reloading of shaders.

  • Owner of the render resource streamer.

    While all resource loading is asynchronous in Stingray (See [3]), the resource streamer I’m referring to in this context is responsible for dynamically loading in/out mip-levels of textures based on their screen coverage. Since this streaming system piggybacks on the view frustum culling system, it is owned and updated by the RenderInterface.

The interface

In addition to being the glue layer, the RenderInterface is also the interface to communicate with the renderer from other threads (simulation, resource streaming, etc.). The renderer operates under its own “controller thread” (as covered in the Overview post), and exposes two different types of functions: blocking and non-blocking.

Blocking functions

Blocking functions will enforce a flush of all outstanding rendering work (i.e. synchronize the calling thread with the rendering thread), allowing the caller to operate directly on the state of the renderer. This is mainly a convenience path when doing bigger state changes / reconfiguring the entire renderer, and should typically not be used during game simulation as it might cause stuttering in the frame rate.

Typical operations that are blocking:

  • Opening and closing of the RenderDevice.

    Sets up / shuts down the graphics API by calling the appropriate functions on the RenderDevice.

  • Creation and destruction of the swap chains.

    Creating and destroying swap chains associated to a Window. Done by forwarding the calls to the RenderDevice.

  • Loading of the render_config / configuring the data-driven rendering pipe.

    The render_config is a configuration file describing how the renderer should work for a specific project. It describes the entire flow of a rendered frame and without it the renderer won’t know what to do. It is the RenderInterface responsibility to make sure that all the different sub-systems (LayerManager, ResourceGeneratorManager, RenderResourceSet, RenderSettings) are set up correctly from the loaded render_config. More on this topic in the next post.

  • Loading, unloading and reloading of shaders.

    The shader system doesn’t have a thread safe interface and is only meant to be accessed from the rendering thread. Therefor any loading, unloading and reloading of shaders needs to synchronize with the rendering thread.

  • Registering and unregistering of Worlds

    Creates or destroys a corresponding RenderWorld and sets up mapping information to go from World* to RenderWorld*.

Non-blocking functions

Non-blocking functions communicates by posting messages to a ring-buffer that the rendering thread consumes. Since the renderer has its own representation of a “World” there is not much communication over this ring-buffer, in a normal frame we usually don’t have more than 10-20 messages posted.

Typical operations that are non-blocking:

  • Rendering of a World.

    void render_world(World &world, const Camera &camera, const Viewport &viewport, 
        const ShadingEnvironment &shading_env, uint32_t swap_chain);
    

    Main interface for rendering of a world viewed from a certain Camera into a certain Viewport. The ShadingEnvironment is basically just a set of shader constants and resources defined in data (usually containing a description of the lighting environment, post effects and similar). swap_chain is a handle referencing which window that will present the final result.

    When the user calls this function a RenderWorldMsg will be created and posted to the ring buffer holding handles to the rendering representations for the world, camera, viewport and shading environment. When the message is consumed by rendering thread it will enter the first of the three stages described in the Overview post - Culling.

  • Reflection of state from a World to the RenderWorld.

    Reflects the “state delta” (from the last frame) for all objects on the simulation thread over to the render thread. For more details see [4].

  • Synchronization.

    uint32_t create_fence();
    void wait_for_fence(uint32_t fence);
    

    Synchronization methods for making sure the renderer is finished processing up to a certain point. Used to handle blocking calls and to make sure the simulation doesn’t run more than one frame ahead of the renderer.

  • Presenting a swap chain.

    void present_frame(uint32_t swap_chain = 0);
    

    When the user is done with all rendering for a frame (i.e has no more render_world calls to do), the application will present the result by looping over all swap chains touched (i.e referenced in a previous call to render_world) and posting one or many PresentFrameMsg messages to the renderer.

  • Providing statistics from the RenderDevice.

    As mentioned in the RenderContext post, we gather various statistics and (if possible) GPU timings in the RenderDevice. Exactly what is gathered depends on the implementation of the RenderDevice. The RenderInterface is responsible for providing a non blocking interface for retrieving the statistics. Note: the statistics returned will be 2 frames old as we update them after the rendering thread is done processing a frame (GPU timings are even older). This typically doesn’t matter though as usually they don’t fluctuate much from one frame to another.

  • Executing user callbacks.

    typedef void (*Callback)(void *user_data);
    void run_callback(Callback callback, void *user, uint32_t user_data_size);
    

    Generic callback mechanics to easily inject code to be executed by the rendering thread.

  • Creation, dispatching and releasing of RenderContexts and RenderResourceContexts.

    While most systems tends to create, dispatch and release RenderContexts and RenderResourceContexts from the rendering thread there can be use cases for doing it from another thread (e.g. the resource thread creates RenderResourceContexts). The RenderInterface provides the necessary functions for doing so in a thread-safe way without having to block the rendering thread.

Wrap up

The RenderInterface in itself doesn’t get more interesting than that. Something needs to be responsible for coupling of various rendering systems and manage the interface for communicating with the controlling thread of the renderer - the RenderInterface is that something.

In the next post we will walk through the various components building the foundation of the data-driven rendering architecture and go through some examples of how to configure them to do something fun from the render_config file.

Stay tuned.

71 comments:

  1. Excellent series of posts! Really learned a lot! But i've got one question. Can the engine have multiple Worlds active at once? for example, have the Level in one World and an Overlay GUI in another World?

    ReplyDelete
  2. Really appreciate the great and inspirational reading of the series,
    eagerly waiting for the next post!

    I have some questions about memory management though.
    After reading the older referenced post "State Reflection" I found myself wondering: who actually owns the RenderMeshObject? I can see that the
    WorldRenderInterface allocates RenderMeshObjects and in the end the pointer ends up in the RenderWorld.

    The real question is then: In which order are Worlds destroyed and how do you
    deallocate the memory if the WorldRenderInterface who allocated the resource does not have pointers to all its allocated RenderMeshObjects (the RenderWorld have all the pointers, but it does not know which allocator the memory belongs to)?

    Is the missing piece here that both WorldRenderInterface and RenderWorld
    are using the same allocator?

    Sorry if it was wrong to ask these questions here and not in the actual article about "State Reflection".

    ReplyDelete
  3. @Dihara Yes, you can have any number of worlds active at once. It's up to the user to decide how she wants to render them.

    @esse Yup, correct. The WorldRenderInterface has a reference to the RenderWorld allocator. Memory for all objects associated with a RenderWorld comes from the same allocator. Next post will be up in an hour or so. Stay tuned. :)

    ReplyDelete
    Replies
    1. Thanks for your reply, everything makes sense now :)
      Woho post #7 has arrived, this will be a great evening!

      Delete
  4. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...

    Android App Development Company

    ReplyDelete
  5. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    PHP training in chennai

    ReplyDelete
  6. I just want to say that all the information you have given here is awesome...great and nice blog thanks sharing..Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Web Design Development Company
    Web design Company in Chennai
    Web development Company in Chennai

    ReplyDelete
  7. it is really amazing...thanks for sharing....provide more useful information...
    Mobile app development company

    ReplyDelete
  8. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    iOS App Development Company

    ReplyDelete
  9. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text

    ReplyDelete
  10. MS Office setup is very easy to install, download and redeem. Use of MS Office is also simple and the user can learn the use of it easily. Online help option is also available in all application of the MS Office which provides an instant guideline.

    office.com setup
    www.office.com
    www office com setup

    ReplyDelete
  11. How you install or reinstall Office 365 or Office 2016 depends on whether your Office product is part of an Office for home or Office for business plan. If you're not sure what you have, see what office.com setup products are included in each plan and then follow the steps for your product. The steps below also apply if you're installing a single, stand-alone Office application such as Access 2016 or Visio 2016. Need Help with office.com/ setup Enter Product Key?

    office.com set up
    office com setup
    microsoft office product

    ReplyDelete
  12. McAfee provides security for all sorts of users. They supply services and products for home and office at home, enterprise businesses with over 250 workers, and small organizations with under 250 employees, and also venture opportunities.


    mcafee.com activate
    mcafee com activate
    mcafee activate

    ReplyDelete
  13. We are providing help and support for Microsoft office Setup and activation. Call us or email us the error or problem, our one of the expert contact you with the suitable perfect solution. Get the MS Office application suite and as per your need and see how it is easy to work with Microsoft Office.


    Office.com setup
    www office com setup
    Install Office

    ReplyDelete
  14. setup.office.com

    Before you plan to install the Office 2016 or Office 365 on your device be it a Computer, Laptop, Mobile Phone or a Tablet, you are required to take few important steps on of them is to remove any existing Office installations from your PC. Just like the previous Office products, Office 2016 & 365 will conflict with the previously installed versions. So, it becomes necessary to remove the previous office files properly.


    setup.office.com
    www.office.com/setup
    office.com

    ReplyDelete
  15. www.office.com/myaccount

    To Setup retail card please visit official website Www.Office.Com/Setup. Office Retail Cards allow you to download your security product from the internet instead of installing from a CD, ensuring recent versions.


    www.office.com/myaccount
    www.office.com/setup
    Microsoft Office product

    ReplyDelete
  16. Office.com/setup - Instructions for Office Setup Installation with the help of this Blog. Get the installation help for Microsoft Office Follow the bearing on the page. you can download and introduce Office, Help with the installation process of Windows 10, Installation process for Office 365 Home
    For Installation Help Please Visit...
    www.office.com/setup
    office setup

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. Yahoo Mail users have been seeing their accounts broken into for months. While Yahoo says it has plugged at least two separate security holes leading to accounts getting hijacked, it appears the problem persists. For get full solution yahoo helpline support

    ReplyDelete
  19. Thank you for sharing this great post, I am very impressed with your post, the information provided is meticulous and easy to understand. I will regularly follow your next post.

    Thanks
    Cpa offers

    ReplyDelete
  20. APTRON offers amazon web services training with decision of numerous training areas crosswise over Gurgaon. Our aws training focuses are outfitted with lab offices and amazing framework. We have the best Amazon Web Services (AWS) Training Institute in Gurgaon and furthermore give amazon cloud aws certification training way for our understudies in Gurgaon.

    For More Info:- AWS course in Gurgaon

    ReplyDelete
  21. very high quality and useful content .keep sharing such informative informationMovers And Packers In Delhi

    ReplyDelete
  22. Thanks for amazing information. The post is about Render Interface which is added value to my knowledge. There are few more information about Render Interface that can be covered here.


    Hire software developers
    Hire Full Stack Developers
    Hire OpenCart Developer
    hire opencart developers
    hire virtual assistants in india
    best digital marketing company in India
    Hire Magento Developer
    Hire FrontEnd Developer

    ReplyDelete
  23. Sky HD(DailyNewsScoop)

    Sky HD (not connected to UK TV channel) only works on Android and is essentially a copy of PlayBox HD. It doesn't have a lot of originality, but it works very well and seems to be reliable.

    CinemaBox

    CinemaBox is basically another Showbox clone. Add the ability to watch content offline, which is great if you don't always have WiFi access or are planning a long vacation in the woods but want to take some movies with you. CinemaBox is available on both Android and iOS.

    ReplyDelete
  24. Online religion research paper writing services are very difficult to complete and many students are always searching for Religion Research Paper Services companies to help them complete their custom religion essay writing services.

    ReplyDelete
  25. If you are the one looking for technical help in AOL mail then call us today at AOL Mail Support Number and get connected with our award-winning team of AOL Mail Services. They are capable of resolving the technical bugs and issues.

    AOL Mail Support Number
    Recover Hacked AOL Mail Account
    Forgot AOL Mail Password
    Change AOL Email Password
    Recover AOL Password
    Reset AOL Mail Password
    Install AOL Desktop Gold
    Download AOL Desktop Gold
    AOL Desktop Gold Update Error
    AOL Shield Pro Support

    ReplyDelete
  26. click on one of the sites below to get a variety of the best tips and tricks in life.

    result togel

    ReplyDelete
  27. I have been on your site quite often but have not gone through this stuff. I like the information and want to speak about the same over my social channels. Hope you don't mind sharing your piece on my social network.
    Offshore Software Development
    app development
    Front End Developer

    ReplyDelete
  28. I have just come across your post and I believe this is exactly what I am looking for. I want an economics assignment help from a tutor who can guarantee me a top grade. Do you charge per page or does it depend on the
    bulk of the economics homework help being completed? More to that if the work is not good enough do you offer free corrections.

    ReplyDelete
  29. Matlab Assignment Help helped me to complete my seventh Matlab assignment, which was also the best-performed! It scored 92/100, which I've never scored before on any other assignment/exam in my lifetime. Otherwise, their service was as quick as usual. The delivery was also on time. I'm now requesting to use this same programmer multiple times. He seems the best in Image Processing tasks. Meanwhile, I'll ask for more Matlab Homework Help soon.

    ReplyDelete
  30. I am looking for a Statistics Assignment Help expert for Statistics Homework Help. I have struggled enough with statistics and therefore I just can't do it anymore on my own. . I have come across your post and I think you are the right person to provide me with SPSS homework help. Let me know how much you charge per assignment so that I can hire you today.

    ReplyDelete
  31. Besides my C course, I have a job and family, both of which compete to get my time. I couldn't find sufficient time for the challenging C assignments, and these people came in and saved my skin. I must commend them for the genius Programming Assignment Help. Their C Homework Help tutors did the best job and got me shining grades.

    ReplyDelete
  32. Hi, other than economics assignment help are there other subjects that you cover? I am having several assignments one needs an economics homework help expert and the other one needs a financial expert. If you can guarantee quality work on both then I can hire you to complete them. All I am sure of is that I can hire you for the economics one but the finance one I am not sure.

    ReplyDelete
  33. Me and my classmates took too long to understand Matlab Assignment Help pricing criteria. we're always grateful for unique solutions on their Matlab assignments. Matlab Homework Help experts have the right experience and qualifications to work on any programming student's homework. They help us in our project.

    ReplyDelete
  34. Hey STATA homework help expert, I need to know if you can conduct the Kappa measurement of agreement. This is what is in my assignment. I can only hire someone for statistics assignment help if they are aware of the kappa measurement of agreement. If you can do it, then reply to me with a few lines of what the kappa measure of agreement is. Let me know also how much you charge for statistics homework help in SAS.

    ReplyDelete
  35. The ardent Programming Homework Help tutor that nailed down my project was very passionate. He answered my Python questions with long, self-explanatory solutions that make it easy for any average student to revise. Moreover, he didn't hesitate to answer other questions, too, even though they weren't part of the exam. If all Python Homework Help experts can be like this then they can trend as the best Programming school ever online.

    ReplyDelete
  36. Such a great Information. Thanks for sharing with us.
    Akshi Engineers Pvt. Ltd. is a major producer, exporter, and retailer of bar separating shears in India. The Bar Dividing Shear machine is easy to use and maintain. It is specially designed for shearing and cutting in steel rolling mills.

    ReplyDelete
  37. Thanks for the great content and sharing. Oflox is the best Digital Marketing Write For Us platform.

    ReplyDelete
  38. Hello. Please check the task I have just sent and reply as soon as possible. I want an adjustment assignment done within a period of one week. I have worked with an Accounting Homework Help tutor from your team and therefore I know it’s possible to complete it within that period. Let me know the cost so that I can settle it now as your Accounting Assignment Help experts work on it.

    ReplyDelete
  39. That is a huge number of students. Are they from the same country or different countries? I also want your math assignment help. I want to perform in my assignments and since this is what you have been doing for years, I believe you are the right person for me. Let me know how much you charge for your math homework help services.

    ReplyDelete
  40. I don’t have time to look for another expert and therefore I am going to hire you with the hope that I will get quality economics assignment help .Being aneconomics homework help professor I expect that your solutions are first class. All I want to tell you is that if the solutions are not up to the mark I am going to cancel the project.

    ReplyDelete
  41. Hey there, I need an Statistics Homework Help expert to help me understand the topic of piecewise regression. In our lectures, the concept seemed very hard, and I could not understand it completely. I need someone who can explain to me in a simpler way that I can understand the topic. he/she should explain to me which is the best model, the best data before the model and how to fit the model using SPSS. If you can deliver quality work then you would be my official Statistics Assignment Help partner.

    ReplyDelete
  42. Brilliant Information. I apprecaite your skills and your knowledge. Thanks for sharing this information.
    Are you looking for fine-tuned Rolling Mill Drives & Automation control solutions to increase process stability, reduce downtime, and ensure consistent product quality? Don't need to go anywhere. The Akshi automation team brings together a rare combination of long production process expertise and electrical device knowledge to ensure that our technology solutions boost mill efficiency, ensure reliable production, and deliver premium product quality.

    ReplyDelete

  43. I’m glad to find another amazing app development blogger.
    on demand service app development

    ReplyDelete
  44. Trade Stocks, Forex, And Bitcoin Anywhere In The World:tradeatf Is The Leading Provider Of Software That Allows You To Trade On Your Own Terms. Whether You Are Operating In The Forex, Stock, Or Cryptocurrency Markets, Use tradeatf Software And Anonymous Digital Wallet To Connect With The Financial World.: tradeatf Is A Currency Trading Company That Allows You To Trade Stocks, Forex, And Cryptocurrency.

    ReplyDelete
  45. We at Bajrangi Astro are an astrological firm providing astrological solutions to all the questions related to the various Life aspects. If you are stuck anywhere in Life and looking for a top astrologer near me, then come to us.

    ReplyDelete
  46. Mcafee has a configuration issue due to which it starts stopping chrome from functioning. But mcafee blocking chrome is easily fixable.

    ReplyDelete
  47. Everything is very open with a very clear explanation. It was definitely informative. Your site is very useful.
    Thank you for sharing!

    사설토토
    카지노
    파워볼사이트
    온라인카지노

    ReplyDelete
  48. Thank you for posting such a great article. Keep it up mate.

    UP URise Portal

    ReplyDelete
  49. Have you ever thought about creating an ebook or guest authoring on other websites? I have a blog centered on the same ideas you discuss and would love to have you share some stories/information. I know my audience would value your work. If you are even remotely interested, feel free to shoot me an e mail.my web blog;



    토토사이트
    토토
    메이저사이트 목록

    ReplyDelete
  50. This is my first time pay a visit at here and i am in fact pleassant to read all at single place.

    스포츠토토
    먹튀검증
    토토 대표 사이트

    ReplyDelete
  51. I love seeing blog that understand the value of providing a quality..


    카지노사이트
    카지노사이트홈
    홈카지노

    ReplyDelete