Notes.txt 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ----------------------------------------------------------------------------------------------
  2. General longterm systems:
  3. - Camera controls + world grid
  4. - Frustum culling and octree (or some other) acceleration structure
  5. - Render queue and sorting
  6. ----------------------------------------------------------------------------------------------
  7. Reminders:
  8. - Assets manifest
  9. - I need to be able to create a list of assets used in the game. Assets referenced from the editor
  10. should be easy to account for. But assets loaded from code are special. Maybe be like Unity and allow
  11. special Resources folder?
  12. - When displaying inspector data for a component, take into consideration that it will need to be able
  13. to display that data for user created C# classes as well. AND I will most certainly have C# versions of all my
  14. components. Therefore is there any purpose of having C++ only inspector parsing code?
  15. - When I'll be doing SRGB write make sure GUI textures are handled properly. Right now they are read in gamma space, and displayed
  16. as normal, but if I switch to SRGB write then gamma would be applied twice to those textures.
  17. - Make editor background have a tileable pattern (see Mini paper app on my cell). Since tileable images wouldn't work with scale9grid, it should be an overlay over the solid background.
  18. - Maybe use the background type I used for website in WebDIP?
  19. - Use black with yellow-orange highlights (highlight = selected button, selected frame border, selected entry box, etc.)
  20. Potential optimizations:
  21. - bulkPixelConversion is EXTREMELY poorly unoptimized. Each pixel it calls a separate method that does redudant operations every pixel.
  22. - UI buffer updates
  23. - https://developer.nvidia.com/sites/default/files/akamai/gamedev/files/gdc12/Efficient_Buffer_Management_McDonald.pdf
  24. - See here how to avoid locks and stalls when updating just parts of a GUI buffer. In need to modify my mesh update code because it currently always updates 100% of the buffer.
  25. - Maybe get rid of CPU UI buffers completely.
  26. - UI shader resolution params for gui should be in a separate constant buffer
  27. ----------------------------------------------------------------------------------------------
  28. More detailed thought out system descriptions:
  29. <<<<DirectDraw>>>>
  30. - Used for quickly drawing something, usually for debug and editor purposes.
  31. - It consists of methods like: DrawLine, DrawPolygon, DrawCube, DrawSphere, etc.
  32. - It may also contain other fancier methods like DrawWireframeMesh, DrawWorldGrid etc.
  33. - Commands get queued from various Component::update methods and get executed at the end of frame. After they're executed they are cleared and need to be re-queued next frame.
  34. - Internally DirectDraw manages dynamic meshes so it can merge multiple DrawLine class into one and such. This can help performance, but generally performance of this class should not be a major concern.
  35. - Example uses for it:
  36. - Drawing GUI element bounds when debugging GUI
  37. - Drawing a wireframe selection effect when a mesh is selected in the scene
  38. <<<<Multithreaded memory allocator>>>>
  39. - Singlethreaded implementation from Game Engine Gems 2 book
  40. - Small and medium allocators separate for each thread. Memory overhead should be minimal considering how small the pages are. But performance benefits are great.
  41. - Large allocator just uses some simple form of page allocation and reuse, using atomics?
  42. - Must ensure that memory allocated on one thread can only be freed from that thread
  43. - How do I easily tell which allocator to call based on current thread? Require a thread ID with each alloc/dealloc?
  44. - Need to think this through more
  45. <<<<More on memory allocator>>>>
  46. - Regarding potentially often allocating large amounts of memory:
  47. - Ignore this for now. Allocating large amounts (16K+ of memory often probably won't be the case). This will only happen when modifying textures or meshes and I can assume there won't be many of such updates.
  48. - (But there will be multiple such updates per frame when it comes to GUI meshes for example)
  49. - However I should implement allocation counter in my allocator so I can know if I have a bottleneck.
  50. - For those allocations that do hit this limit I should implement a FrameAllocator. Memory is allocated during simulation step and the entire block is cleared when the frame ends.
  51. - Allocations like copying MeshData, PixelData, PassParams, etc. when queing commands for render thread should all be using this.
  52. - Problem with such allocator is safety
  53. - Allocations that are created and deleted in a single function should use a Stack allocator
  54. <<<<Resource changes and reimport>>>>
  55. Use case example:
  56. - User reimports a .gpuproginc file
  57. - Dependencies are held by CoreGpuObjectManager. Objects are required to register/unregister
  58. their dependencies in their methods manually.
  59. - Editor calls SomeClass::reimport(handle) after it detects a change
  60. - this will load a new resource, release the old one and assign the new one to Handle without changing the GUID
  61. - In order to make it thread safe force all threads to finish what they're doing and pause them until the switch is done
  62. - Should be okay considering this should only happen in edit-mode so performance isn't imperative
  63. - reimport is recursively called on all dependant objects as well.
  64. <<<<Handle multithreaded object management>>>:
  65. - Make everything that is possible immutable. Once created it cant be changed.
  66. - Example are shaders, state objects and similar
  67. - Things like Textures, Vertex, Index buffers, GpuParams may be changed
  68. - Make Vertex/Index buffers and similar only accesible from render thread. Higher level classes like meshes can have deferred methods
  69. - TODO - How to handle the remaining actually deferred methods? Like Textures?
  70. DirectX11 supports concurrent drawing and resource creation so all my resource updates should be direct calls to DX methods (I'll need a deferred context?)
  71. - DX9 doesn't so creating/updating resources should wait for render thread?
  72. - Although these are sync points which kill the whole concept of separate render thread
  73. - Updating via copy then? (DX11 driver does it internally if resource is used anyway)
  74. - OpenGL? No idea, need to study GL contexts
  75. - Although it seems DX11 also copies data when mapping/unmapping or updating on a non-immediate context. So maybe copy is the solution?
  76. So final solution:
  77. - Copy all data that will be updated on a deferred context
  78. - Make deferred context have a scratch buffer it can use for storing temporary copied data
  79. - Immediate context will execute all commands right away
  80. - This applies when rendering thread calls resource create/update internally
  81. - Or when other thread blocks and waits for rendering thread
  82. - Create a simple distinction so user knows when is something executed deferred and when immediate?
  83. - Move resource update/create methods to DeferredContext?
  84. - Not ALL methods need to be moved, only those that are resource heavy
  85. - Smaller methods may remain and always stay async, but keep internal state?
  86. - Resource creation on DX11 should be direct though, without a queue (especially if we manage to populate a resource in the same step)
  87. - Remove & replace internal data copying in GpuParamBlock (or just use a allocator instead of new())
  88. A POSSIBLY BETTER SOLUTION THAN COPYING ALL THE DATA?
  89. Classes derive from ISharedMemoryBuffer
  90. - For example PixelData, used when setting texture pixels
  91. - They have lock, unlock & clone methods
  92. - Users can choose whether they want to lock themselves out from modifying the class, or clone it, before passing it to a threaded method
  93. - Downside is that I need to do this for every class that will be used in threaded methods
  94. - Upside is that I think that is how DX handles its buffers at the moment
  95. <<<<RenderSystem needed modifications>>>>
  96. - Texture resource views (Specifying just a subresource of a texture as a shader parameter)
  97. - UAV for textures
  98. - Stream out (write vertex buffers) (DX11 and GL)
  99. - Texture buffers
  100. - Just add a special texture type? OpenGL doesn't support getting offset from within a texture buffer anyway
  101. - Tesselation (hull/domain) shader
  102. - Detachable and readable depthstencil buffer (Window buffers not required as they behave a bit differently in OpenGL)
  103. - OpenGL provides image load/store which seems to be GL UAV equivalent (http://www.opengl.org/wiki/Image_Load_Store)
  104. - Resolving MSAA textures (i.e. copying them to non-MSAA so they can be displayed on-screen). DX has ResolveSubresource, and OpenGL might have something similar.
  105. - Single and dual channel textures (especially render textures, which are very important for effects like SSAO)
  106. - Compute pipeline
  107. - Instancing (DrawInstanced) (DX11 and GL)
  108. - OpenGL append/consume buffers
  109. - Indirect drawing via indirect argument buffers
  110. - Texture arrays
  111. - Rendertargets that aren't just 2D (Volumetric (3D) render targets in particular)
  112. - Shader support for doubles
  113. - Dynamic shader linkage (Interfaces and similar)
  114. - Multisampled texture resources
  115. - Multiple adapters (multi gpu)
  116. - Passing initial data when creating a resource (DX11, but possibly GL too)
  117. - Sample mask when setting blend state (DX11, check if equivalent exists in GL)
  118. - RGBA blend factor when setting blend state(DX11, check if equivalent exists in GL)
  119. - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes
  120. - One camera -> one task (thread) approach for multithreading
  121. - Also make sure to run off a thread pool (WorkQueue class already exists that provides needed interface)
  122. - The way I handle rendering currently is to discard simulation results if gpu thread isn't finished.
  123. - This reduces input lag but at worst case scenario the effect of multithreading might be completely eliminated as
  124. GPU ends up waiting for GPU, just because it was few milliseconds late. Maybe better to wait for GPU?