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

Metal: new binding model and SPIRV support #1576

Merged
merged 9 commits into from Oct 17, 2017

Conversation

@kvark
Copy link
Member

commented Oct 16, 2017

This PR grew out of scope (basic SPIRV-support), but that was necessary.
Major changes:

  • Argument buffer support is turned into a run-time feature flag, disabled until SPIRV gets support for it (KhronosGroup/SPIRV-Cross#293)
  • Proper resource binding/state inheritance for command buffers
  • SPIRV-cross integration

Also fixes #1581

New binding model

Assignment from (descriptor_set, binding) to MSL buffer/texture/sampler index is figured out for the pipeline layout and stored inside it as a hashmap.

A shader is not really compiled at create_shader_module, but rather - at PSO creation time, since this is where we know about the pipeline layout. The resource binding overrides of that layout are fed directly into SPIRV-cross compile options.

A command buffer caches all bound resources at the MSL level (not descriptor set level, like it previously did). Binding descriptor sets would update the caches and potentially set the active encoder values. Both argument and regular vertex buffers just participate without extra semantics at this stage, simplifying the command buffer handling and solving the question of how to map those to not conflict.

@kvark kvark referenced this pull request Oct 16, 2017

Open

Immutable `Ast` usage #29

@msiglreith
Copy link
Member

left a comment

Seems to be sound.. good job!

@@ -233,13 +235,15 @@ fn main() {

//
let pipelines = {
#[cfg(any(feature = "vulkan", feature = "dx12", feature = "gl"))]
//TODO: remove the type annotations when we have support for
// inidirect argument buffers in SPIRV-Cross

This comment has been minimized.

Copy link
@msiglreith

msiglreith Oct 16, 2017

Member

nit: inidirect -> indirect

self.samplers.clear();
}

fn add_buffer(&mut self, slot: usize, buffer: MTLBuffer, offset: usize) {

This comment has been minimized.

Copy link
@msiglreith

msiglreith Oct 16, 2017

Member

Could be also extended for multiple buffers for the future.

This comment has been minimized.

Copy link
@kvark

kvark Oct 16, 2017

Author Member

yes, totally

});
};
inner.viewport = Some(vp);
if let EncoderState::Render(ref encoder) = inner.encoder_state {

This comment has been minimized.

Copy link
@msiglreith

msiglreith Oct 16, 2017

Member

General question: Caching still required if we are already inside an encoder? Will the states in MTL be reset at encoder boundaries?

This comment has been minimized.

Copy link
@kvark

kvark Oct 16, 2017

Author Member

Yes, they will be reset. That's why we still fill the cache, so that when we exit a render pass and then enter another one, we can re-bind everything that is active.

}

command_buffer.encoder_state = EncoderState::Render(render_encoder);
command_buffer.begin_renderpass(render_encoder);

This comment has been minimized.

Copy link
@msiglreith

@kvark kvark force-pushed the kvark:metal-spirv branch 3 times, most recently from 54e072f to be59a2d Oct 16, 2017

@grovesNL grovesNL referenced this pull request Oct 16, 2017

Closed

[WIP] Travis/OSX failure #1583

@kvark kvark force-pushed the kvark:metal-spirv branch from be59a2d to 6a048c0 Oct 17, 2017

@kvark kvark force-pushed the kvark:metal-spirv branch from 6a048c0 to 7132b64 Oct 17, 2017

@kvark

This comment has been minimized.

Copy link
Member Author

commented Oct 17, 2017

Huge thanks to @grovesNL for fixing the OSX Travis build issues with spirv_cross!
bors r=msiglreith

bors bot added a commit that referenced this pull request Oct 17, 2017

Merge #1576
1576: [metal] New binding model and SPIRV support r=msiglreith a=kvark

This PR grew out of scope (basic SPIRV-support), but that was necessary.
Major changes:
  - Argument buffer support is turned into a run-time feature flag, disabled until SPIRV gets support for it (KhronosGroup/SPIRV-Cross#293)
  - Proper resource binding/state inheritance for command buffers
  - SPIRV-cross integration

Also fixes #1581

## New binding model
Assignment from (descriptor_set, binding) to MSL buffer/texture/sampler index is figured out for the pipeline layout and stored inside it as a hashmap.

A shader is not really compiled at `create_shader_module`, but rather - at PSO creation time, since this is where we know about the pipeline layout. The resource binding overrides of that layout are fed directly into SPIRV-cross compile options.

A command buffer caches all bound resources at the MSL level (not descriptor set level, like it previously did). Binding descriptor sets would update the caches and potentially set the active encoder values. Both argument and regular vertex buffers just participate without extra semantics at this stage, simplifying the command buffer handling and solving the question of how to map those to not conflict.

@kvark kvark changed the title [metal] New binding model and SPIRV support Metal: new binding model and SPIRV support Oct 17, 2017

@bors

This comment has been minimized.

Copy link
Contributor

commented Oct 17, 2017

@bors bors bot merged commit 7132b64 into gfx-rs:master Oct 17, 2017

3 checks passed

bors Build succeeded
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kvark kvark deleted the kvark:metal-spirv branch Oct 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.