diff --git a/content/Graphics/Resources/ComputePipeline.md b/content/Graphics/Resources/ComputePipeline.md index e2f5318..d563614 100644 --- a/content/Graphics/Resources/ComputePipeline.md +++ b/content/Graphics/Resources/ComputePipeline.md @@ -16,18 +16,18 @@ var myComputeShader = new ShaderModule( "ParticleCompute.spv" ); -var myComputeShaderState = new ShaderStageState +var myComputeShaderInfo = new ComputeShaderInfo { ShaderModule = myComputeShader, EntryPointName = "main", - UniformBufferSize = 0 + UniformBufferSize = 0, + BufferBindingCount = 1, + ImageBindingCount = 0, }; var myComputePipeline = new ComputePipeline( GraphicsDevice, - myComputeShaderState, - 1, - 0 + myComputeShaderInfo ); ``` diff --git a/content/Graphics/Resources/GraphicsPipeline/AttachmentInfo.md b/content/Graphics/Resources/GraphicsPipeline/AttachmentInfo.md index 119c101..613a636 100644 --- a/content/Graphics/Resources/GraphicsPipeline/AttachmentInfo.md +++ b/content/Graphics/Resources/GraphicsPipeline/AttachmentInfo.md @@ -1,7 +1,7 @@ --- title: "Attachment Info" date: 2021-01-28T12:55:51-08:00 -weight: 10 +weight: 0 --- GraphicsPipelineAttachmentInfo tells the graphics pipeline what kinds of render passes will be used with the pipeline. These are *compatible* render passes. It also describes how the pipeline should blend colors. Blending does not affect compatibility, but the other properties do. @@ -32,4 +32,11 @@ var myColorTargetBlendState = new ColorTargetBlendState DestinationColorBlendFactor = BlendFactor.One, DestinationAlphaBlendFactor = BlendFactor.One }; + +var myColorAttachmentDescription = new ColorAttachmentDescriptions +{ + Format = TextureFormat.R8G8B8A8, + SampleCount = SampleCount.One, + BlendState = myColorTargetBlendState, +}; ``` diff --git a/content/Graphics/Resources/GraphicsPipeline/BlendConstants.md b/content/Graphics/Resources/GraphicsPipeline/BlendConstants.md new file mode 100644 index 0000000..9785ee2 --- /dev/null +++ b/content/Graphics/Resources/GraphicsPipeline/BlendConstants.md @@ -0,0 +1,17 @@ +--- +title: "Blend Constants" +date: 2021-01-28T12:55:51-08:00 +weight: 11 +--- + +Blend constants are only used with `BlendFactor.ConstantColor` and `BlendFactor.OneMinusConstantColor` blend factors. If you aren't using these you don't have to bother. + +```cs +var myBlendConstants = new BlendConstants +{ + R = 1.0f, + G = 0.33f, + B = 0.66f, + A = 1.0f +}; +``` diff --git a/content/Graphics/Resources/GraphicsPipeline/ColorBlendState.md b/content/Graphics/Resources/GraphicsPipeline/ColorBlendState.md deleted file mode 100644 index d838013..0000000 --- a/content/Graphics/Resources/GraphicsPipeline/ColorBlendState.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: "Color Blend State" -date: 2021-01-27T14:11:42-08:00 -weight: 1 ---- - -Color blend state is comprised of three fields - a logical operation, whether that logical operation is enabled, and some blending constants. - -`LogicOp` lets you do a bitwise combination of the original and new color. You can read about that in more detail [over here](https://www.khronos.org/registry/vulkan/specs/1.2/html/chap28.html#framebuffer-logicop). - -`BlendConstants` are used by the blend factors to produce result colors. You can read about that [here](https://www.khronos.org/registry/vulkan/specs/1.2/html/chap28.html#framebuffer-blendconstants). - -Let's put it all together: - -```cs -var myBlendConstants = new BlendConstants -{ - R = 1f, - G = 1f, - B = 1f, - A = 1f -}; - -var myColorBlendState = new ColorBlendState -{ - LogicOpEnable = true, - LogicOp = LogicOp.And, - BlendConstants = myBlendConstants -}; -``` - -Further blending state control is provided in GraphicsPipelineAttachmentInfo, which will be discussed later. diff --git a/content/Graphics/Resources/GraphicsPipeline/GraphicsPipeline.md b/content/Graphics/Resources/GraphicsPipeline/GraphicsPipeline.md index d597053..675e2c4 100644 --- a/content/Graphics/Resources/GraphicsPipeline/GraphicsPipeline.md +++ b/content/Graphics/Resources/GraphicsPipeline/GraphicsPipeline.md @@ -9,17 +9,16 @@ Finally, we have everything we need to build the graphics pipeline. We just need ```cs var myGraphicsPipelineCreateInfo = new GraphicsPipelineCreateInfo { - ColorBlendState = myColorBlendState, + AttachmentInfo = myAttachmentInfo, DepthStencilState = myDepthStencilState, - VertexShaderState = myVertexShaderState, - FragmentShaderState = myFragmentShaderState, + VertexShaderInfo = myVertexShaderInfo, + FragmentShaderInfo = myFragmentShaderInfo, MultisampleState = myMultisampleState, - PipelineLayoutInfo = myPipelineLayoutInfo, RasterizerState = myRasterizerState, PrimitiveType = PrimitiveType.TriangleList, VertexInputState = myVertexInputState, ViewportState = myViewportState, - RenderPass = myRenderPass + BlendConstants = myBlendConstants }; var myGraphicsPipeline = new GraphicsPipeline( diff --git a/content/Graphics/Resources/GraphicsPipeline/GraphicsPipelineLayoutInfo.md b/content/Graphics/Resources/GraphicsPipeline/GraphicsPipelineLayoutInfo.md deleted file mode 100644 index f26d152..0000000 --- a/content/Graphics/Resources/GraphicsPipeline/GraphicsPipelineLayoutInfo.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "Graphics Pipeline Layout Info" -date: 2021-01-27T15:04:37-08:00 -weight: 4 ---- - -You finally get a bit of a break for now, because this one is easy. - -`GraphicsPipelineLayoutInfo` just tells the graphics pipeline how many samplers you will be using in each shader stage. - -```cs -var myPipelineLayoutInfo = new GraphicsPipelineLayoutInfo -{ - VertexSamplerBindingCount = 1, - FragmentSamplerBindingCount = 3 -}; -``` - -With this example, we are telling our graphics pipeline that our vertex shader will be sampling one texture and our fragment shader will be sampling three textures. diff --git a/content/Graphics/Resources/GraphicsPipeline/ShaderStageState.md b/content/Graphics/Resources/GraphicsPipeline/GraphicsShaderInfo.md similarity index 97% rename from content/Graphics/Resources/GraphicsPipeline/ShaderStageState.md rename to content/Graphics/Resources/GraphicsPipeline/GraphicsShaderInfo.md index 18857c2..dece76a 100644 --- a/content/Graphics/Resources/GraphicsPipeline/ShaderStageState.md +++ b/content/Graphics/Resources/GraphicsPipeline/GraphicsShaderInfo.md @@ -81,10 +81,11 @@ var myColorPhaseFragmentShaderModule = new ShaderModule( "ColorPhaseFrag.spv" ); -var myFragmentShaderState = new ShaderStageState +var myFragmentShaderState = new GraphicsShaderInfo { ShaderModule = myColorPhaseFragmentShaderModule, EntryPoint = "main", - UniformBufferSize = Marshal.SizeOf() + UniformBufferSize = Marshal.SizeOf(), + SamplerCount = 0 }; ``` diff --git a/content/Graphics/Resources/GraphicsPipeline/VertexInputState.md b/content/Graphics/Resources/GraphicsPipeline/VertexInputState.md index 41fa7c8..6ce9786 100644 --- a/content/Graphics/Resources/GraphicsPipeline/VertexInputState.md +++ b/content/Graphics/Resources/GraphicsPipeline/VertexInputState.md @@ -52,6 +52,15 @@ var myVertexBindings = new VertexBinding[] }; ``` +We also have a convenient shortcut function that attempts to generate a binding given a vertex struct. + +```cs +var myVertexBindings = new VertexBinding[] +{ + VertexBinding.Create() +}; +``` + We need one "vertex attribute" per input value we have defined in our vertex shader, so in this specific case we need two. A "vertex attribute" contains binding value, location, a format, and an offset. The binding index corresponds to the binding index we provided in the vertex binding. Next, notice the `location` values in our vertex shader. This tells the pipeline that first it will read in the position value, and then it will read in the texcoord value. Next we provide the format. Our position is a vec3 and our texcoord is a vec2, so our formats will be `VertexElementFormat.Vector3` and `VertexElementFormat.Vector2` respectively. Finally, the offset tells the pipeline the positions of these values relative to the vertex structure, so these values will be `0` and `sizeof(float) * 3`, respectively. (Note that we can call `sizeof` here instead of `Marshal.SizeOf` because `float` is a built-in C# value.) For our example shader, the vertex attributes look like this: @@ -76,6 +85,16 @@ var myVertexAttributes = new VertexAttributes[] }; ``` +Similar to above, we have a shortcut function for this initialization. + +```cs +var myVertexAttributes = new VertexAttributes[] +{ + VertexAttribute.Create("Position", 0), + VertexAttribute.Create("Texture", 1) +}; +``` + Now we can put these arrays in our vertex input state struct. ```cs diff --git a/content/Graphics/Resources/GraphicsPipeline/ViewportState.md b/content/Graphics/Resources/GraphicsPipeline/ViewportState.md index e2c9663..9313775 100644 --- a/content/Graphics/Resources/GraphicsPipeline/ViewportState.md +++ b/content/Graphics/Resources/GraphicsPipeline/ViewportState.md @@ -51,3 +51,9 @@ var myViewportState = new ViewportState Scissors = myScissors; } ``` + +In many cases just want to provide viewport dimensions and not worry about the scissor. We have a shortcut for that! + +```cs +var myViewportState = new ViewportState(1280, 720); +``` diff --git a/content/Graphics/Resources/GraphicsPipeline/_index.md b/content/Graphics/Resources/GraphicsPipeline/_index.md index 0747f77..90568d2 100644 --- a/content/Graphics/Resources/GraphicsPipeline/_index.md +++ b/content/Graphics/Resources/GraphicsPipeline/_index.md @@ -8,16 +8,15 @@ Graphics pipelines are where we put together every concept we have discussed so A graphics pipeline needs the following information in order to generate: -* Color Blend State +* Attachment Info * Depth Stencil State -* Vertex Shader -* Fragment Shader +* Vertex Shader Info +* Fragment Shader Info +* Vertex Input State * Multisample State -* Pipeline Layout Creation Info * Rasterizer State * Primitive Type -* Vertex Input State * Viewport State -* Attachment Info +* Blend Constants Whew, that's a lot! Let's break it down one thing at a time. diff --git a/content/Graphics/Resources/Texture.md b/content/Graphics/Resources/Texture.md index 1ef4198..cd3e6a6 100644 --- a/content/Graphics/Resources/Texture.md +++ b/content/Graphics/Resources/Texture.md @@ -58,7 +58,7 @@ One last concept we should discuss before moving on is texture slicing. Texture slices are a very commonly used concept in MoonWorks. You don't have to do texture operations on an entire texture - you can instead use a subsection of the texture for whatever your operation is. ```cs -var myTexture = Texture.LoadPNG(GraphicsDevice, "myTexture.png"); +var myTexture = Texture.LoadPNG(GraphicsDevice, myCommandBuffer, "myTexture.png"); var mySliceRect = new Rect(0, 0, 16, 16); var myTextureSlice = new TextureSlice(myTexture, mySliceRect); ```