update docs with new MoonWorks changes
continuous-integration/drone/push Build is passing Details

main
cosmonaut 2022-03-04 10:34:23 -08:00
parent 344eac22c3
commit db898a40d3
11 changed files with 68 additions and 71 deletions

View File

@ -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
);
```

View File

@ -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,
};
```

View File

@ -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
};
```

View File

@ -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.

View File

@ -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(

View File

@ -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.

View File

@ -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<ColorPhaseUniforms>()
UniformBufferSize = Marshal.SizeOf<ColorPhaseUniforms>(),
SamplerCount = 0
};
```

View File

@ -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<PositionTextureVertex>()
};
```
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<PositionTextureVertex>("Position", 0),
VertexAttribute.Create<PositionTextureVertex>("Texture", 1)
};
```
Now we can put these arrays in our vertex input state struct.
```cs

View File

@ -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);
```

View File

@ -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.

View File

@ -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);
```