Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX11 Graphics Backend #50

Open
wants to merge 53 commits into
base: master
Choose a base branch
from

Conversation

matthewgeorgy
Copy link
Contributor

@matthewgeorgy matthewgeorgy commented Dec 11, 2021

Figured I'd put it in a separate branch to make tracking its progress easier.

Currently, only a few things have been implemented thus far, but the plumbing is laid out for many more things to be added in the future. To get an idea of how much is implemented, I can compile and run the 02_simple_triangle, 04_simple_texture, 07_instancing (with and without index buffers), and 19_uniform_buffer.

Implemented so far

Resource creation:

  • gs_graphics_vertex_buffer_create(...)
  • gs_graphics_index_buffer_create(...)
  • gs_graphics_shader_create(...)
  • gs_graphics_pipeline_create(...)
  • gs_graphics_uniform_buffer_create(...)
  • gs_graphics_uniform_create(...)
  • gs_graphics_texture_create(...) (+ internal())

Resource Updates:

  • __gs_graphics_update_buffer_internal(...)
  • gs_graphics_uniform_buffer_update_request(...)

Command Buffer Ops:

  • OP_BEGIN_RENDER_PASS
  • OP_END_RENDER_PASS
  • OP_SET_VIEWPORT
  • OP_CLEAR
  • OP_BIND_PIPELINE
  • OP_APPLY_BINDINGS
  • OP_DRAW
    Scrapped the command buffer + op code system in favour for ID3D11CommandLists.

Supported features:

  • Vertex buffers
  • Index buffers
  • Uniform buffers
  • Uniforms (DX11 SRV's)
  • Textures
  • Shaders
  • Pipelines
  • Instanced rendering

Command Buffer Funcs:

  • gs_graphics_begin_render_pass(...)
  • gs_graphics_end_render_pass(...)
  • gs_graphics_clear(...)
  • gs_graphics_set_viewport(...)
  • gs_graphics_apply_bindings(...)
  • gs_graphics_bind_pipeline(...)
  • gs_graphics_draw(...)
  • gs_graphics_submit_command_buffer(...)

The command buffer system works by first receiving the gs_graphics_pipeline object with the call to gs_graphics_bind_pipeline, binding shaders, and then caching it for later use. Then, using this cached pipeline, vertex buffer layouts are filled in under the OP_APPLY_BINDINGS instruction. Here, any appropriate vertex buffers are bound, and the ID3D11InputLayout is created here and also bound. The only purpose of the OP_DRAW instruction is to make the API draw call, using all of the data that was bound to the pipeline by the previous two instructions.
This is different from the OpenGL implementation, where the OP_DRAW instruction is also responsible for binding some necessary data. This is the design choice for now but, of course, it may change in the future.

NOTE: I have completely revamped the command buffer system by getting rid of it and using ID3D11CommandList and deferred contexts in order to support proper multithreaded rendering safety. I've also made use of CRITICAL_SECTION
objects to allow for safe multithreaded object creation.

Next Steps

  • Proper thread safety with ID3D11CommandList + deferred context
  • Support multiple uniforms (currently can only bind 1 uniform at a time)
  • Changes to platform layer with GLFW so that the D3D11 backend can actually initialize properly (ie, getting an HWND, NO_CLIENT_API, etc)
  • Framebuffers
  • Compute shaders
  • gunslinger immediate draw
  • Support more uniform types(Buffers, etc)

My main testing philosophy is to get as many of the example apps running with this backend as possible. This also doubles as a simple way of tracking progress and figuring out what needs to be implemented next.

Still lots of things to add, even to the simple things so far.
See comments for more details.
- Refacted to use D3D11's C interface
…ill break the GS handle system (it won't, talked about it with John and it turns out I was just confused + misreading)
…ts to DX11 formats.

- Added few comments documenting future ideas
…set.

- Added function for creating index buffers (index_buffer_create)
- Resolved compiler errors.
- Added main.c; successfully drawing red triangle! (many steps skipped..., too many d3d11 calls)
- Now creating shaders through impl instead of directly through dx11!
…command buffer system

- Tested and verified clearing these buffers through a command buffer
- Tested and verified changing viewport size this way (commented out in main.c)
…urces (VS + PS)

- Verified with main.c
- Need this change for implementing pipeline bindings because the raster_state_desc only supports binding a single shader at a time. Thus, we need to group all of our shaders into a single handle + struct so that they can be sent to the pipeline, and then from that point we can bind them each individually with {}SSetShader.
- Now able to find vertex buffers to the pipeline
- Tested/verified in main.c
…INGS op. This is perfectly legal we require the pipeline to be bound before we can bind any additional data. This is not stated explicitly (AFAIK), but it makes sense, especially if you look at the GL impl, which does the same thing.

- Left original comments for OP_DRAW since some comments need be addressed in the future (such as strides, offsets, etc.)
- Also removed the commented-out IASetVertexBuffers() call in main.c for cleanliness
- Tested in main.c; removed input layout stuff in main.c
- Currently, the create function is working, and binding the buffer is handled as a case
in apply_bindings.
- Now, this case must be dealt with in the APPLY_BINDINGS op
- Removed assertion for uniform buffer desc having a name
- Made changes in main.c/data.c for this to use the DX11 backend
- Need to test and debug (currently getting a white screen, but no crashes?)
…e buffer

- Used some mho_math mat4 funcs instead of gs' in main.c
- Successfully rotating the red cube! Although, for some reason it's shifted to the right instead of the left, need to figure out why.
- Next is to implement multiple render passes so that we can draw all 4 colored cubes at once
- Added error handling in shader_create(... ) in case of failed compilation
…r now

- Next to implement are uniforms, as these will act as resource views for textures (and maybe buffers in the future if GS starts supporting it)
- Still needs to be tested and verified
…ng for Texture2D's

- Added functionality for reading multiple subbuffers from the pipeline layout in OP_APPLY_BINDINGS
- Added main.c test program for uniform/texture creation + binding
- Tested and verified!
…using previous buffer data to be invalidated
…riptors (see big comment).

- Need to also handle INDEXED instanced rendering (shouldn't be hard).
- Removed the 'instanced' field in the cache since it's redundant
…n build simple_triangle and index_buffer examples with the scheme I've developed currently.

- Next step is to port the remaining command buffer parts to use the command list and test to make sure that more of the example apps work.
- Updated vertex buffer binding logic to support instanced (+ indexed) rendering in the command list scheme
- Handling uniform buffer update requests with command lists
- Cleaned up (aka removed) most of the legacy command buffer stuff, might have some more left to remove
- Implemented object creation thread-safety with CRITICAL_SECTION objects
- Cleaned up some stuff + comment about testing the thread-safety mechanisms
This reverts commit 2bfe44c.

fixing state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant