Notes.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ----------------------------------------------------------------------------------------------
  16. More detailed thought out system descriptions:
  17. <<<<DirectDraw>>>>
  18. - Used for quickly drawing something, usually for debug and editor purposes.
  19. - It consists of methods like: DrawLine, DrawPolygon, DrawCube, DrawSphere, etc.
  20. - It may also contain other fancier methods like DrawWireframeMesh, DrawWorldGrid etc.
  21. - 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.
  22. - 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.
  23. - Example uses for it:
  24. - Drawing GUI element bounds when debugging GUI
  25. - Drawing a wireframe selection effect when a mesh is selected in the scene
  26. <<<<Multithreaded memory allocator>>>>
  27. - Singlethreaded implementation from Game Engine Gems 2 book
  28. - Small and medium allocators separate for each thread. Memory overhead should be minimal considering how small the pages are. But performance benefits are great.
  29. - Large allocator just uses some simple form of page allocation and reuse, using atomics?
  30. - Must ensure that memory allocated on one thread can only be freed from that thread
  31. - How do I easily tell which allocator to call based on current thread? Require a thread ID with each alloc/dealloc?
  32. - Need to think this through more
  33. <<<<More on memory allocator>>>>
  34. - Regarding potentially often allocating large amounts of memory:
  35. - 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.
  36. - (But there will be multiple such updates per frame when it comes to GUI meshes for example)
  37. - However I should implement allocation counter in my allocator so I can know if I have a bottleneck.
  38. - 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.
  39. - Allocations like copying MeshData, PixelData, PassParams, etc. when queing commands for render thread should all be using this.
  40. - Problem with such allocator is safety
  41. - Allocations that are created and deleted in a single function should use a Stack allocator
  42. <<<<Resource changes and reimport>>>>
  43. Use case example:
  44. - User reimports a .gpuproginc file
  45. - Dependencies are held by CoreGpuObjectManager. Objects are required to register/unregister
  46. their dependencies in their methods manually.
  47. - Editor calls SomeClass::reimport(handle) after it detects a change
  48. - this will load a new resource, release the old one and assign the new one to Handle without changing the GUID
  49. - In order to make it thread safe force all threads to finish what they're doing and pause them until the switch is done
  50. - Should be okay considering this should only happen in edit-mode so performance isn't imperative
  51. - reimport is recursively called on all dependant objects as well.
  52. <<<<Handle multithreaded object management>>>:
  53. - Make everything that is possible immutable. Once created it cant be changed.
  54. - Example are shaders, state objects and similar
  55. - Things like Textures, Vertex, Index buffers, GpuParams may be changed
  56. - Make Vertex/Index buffers and similar only accesible from render thread. Higher level classes like meshes can have deferred methods
  57. - TODO - How to handle the remaining actually deferred methods? Like Textures?
  58. 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?)
  59. - DX9 doesn't so creating/updating resources should wait for render thread?
  60. - Although these are sync points which kill the whole concept of separate render thread
  61. - Updating via copy then? (DX11 driver does it internally if resource is used anyway)
  62. - OpenGL? No idea, need to study GL contexts
  63. - Although it seems DX11 also copies data when mapping/unmapping or updating on a non-immediate context. So maybe copy is the solution?
  64. So final solution:
  65. - Copy all data that will be updated on a deferred context
  66. - Make deferred context have a scratch buffer it can use for storing temporary copied data
  67. - Immediate context will execute all commands right away
  68. - This applies when rendering thread calls resource create/update internally
  69. - Or when other thread blocks and waits for rendering thread
  70. - Create a simple distinction so user knows when is something executed deferred and when immediate?
  71. - Move resource update/create methods to DeferredContext?
  72. - Not ALL methods need to be moved, only those that are resource heavy
  73. - Smaller methods may remain and always stay async, but keep internal state?
  74. - Resource creation on DX11 should be direct though, without a queue (especially if we manage to populate a resource in the same step)
  75. - Remove & replace internal data copying in GpuParamBlock (or just use a allocator instead of new())
  76. A POSSIBLY BETTER SOLUTION THAN COPYING ALL THE DATA?
  77. Classes derive from ISharedMemoryBuffer
  78. - For example PixelData, used when setting texture pixels
  79. - They have lock, unlock & clone methods
  80. - Users can choose whether they want to lock themselves out from modifying the class, or clone it, before passing it to a threaded method
  81. - Downside is that I need to do this for every class that will be used in threaded methods
  82. - Upside is that I think that is how DX handles its buffers at the moment
  83. <<<<RenderSystem needed modifications>>>>
  84. - Texture resource views (Specifying just a subresource of a texture as a shader parameter)
  85. - UAV for textures
  86. - Stream out (write vertex buffers) (DX11 and GL)
  87. - Texture buffers
  88. - Just add a special texture type? OpenGL doesn't support getting offset from within a texture buffer anyway
  89. - Tesselation (hull/domain) shader
  90. - Detachable and readable depthstencil buffer (Window buffers not required as they behave a bit differently in OpenGL)
  91. - OpenGL provides image load/store which seems to be GL UAV equivalent (http://www.opengl.org/wiki/Image_Load_Store)
  92. - 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.
  93. - Single and dual channel textures (especially render textures, which are very important for effects like SSAO)
  94. - Compute pipeline
  95. - Instancing (DrawInstanced) (DX11 and GL)
  96. - OpenGL append/consume buffers
  97. - Indirect drawing via indirect argument buffers
  98. - Texture arrays
  99. - Rendertargets that aren't just 2D (Volumetric (3D) render targets in particular)
  100. - Shader support for doubles
  101. - Dynamic shader linkage (Interfaces and similar)
  102. - Multisampled texture resources
  103. - Multiple adapters (multi gpu)
  104. - Passing initial data when creating a resource (DX11, but possibly GL too)
  105. - Sample mask when setting blend state (DX11, check if equivalent exists in GL)
  106. - RGBA blend factor when setting blend state(DX11, check if equivalent exists in GL)
  107. - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes
  108. - One camera -> one task (thread) approach for multithreading
  109. - Also make sure to run off a thread pool (WorkQueue class already exists that provides needed interface)
  110. - The way I handle rendering currently is to discard simulation results if gpu thread isn't finished.
  111. - This reduces input lag but at worst case scenario the effect of multithreading might be completely eliminated as
  112. GPU ends up waiting for GPU, just because it was few milliseconds late. Maybe better to wait for GPU?