update ComputeUniforms
parent
165af544de
commit
b9337fdbe6
|
@ -9,7 +9,7 @@ namespace MoonWorks.Test
|
||||||
private GraphicsPipeline drawPipeline;
|
private GraphicsPipeline drawPipeline;
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
private Sampler sampler;
|
private Sampler sampler;
|
||||||
private Buffer vertexBuffer;
|
private GpuBuffer vertexBuffer;
|
||||||
|
|
||||||
struct GradientTextureComputeUniforms
|
struct GradientTextureComputeUniforms
|
||||||
{
|
{
|
||||||
|
@ -60,13 +60,6 @@ namespace MoonWorks.Test
|
||||||
drawPipelineCreateInfo
|
drawPipelineCreateInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create buffers and textures
|
|
||||||
vertexBuffer = Buffer.Create<PositionTextureVertex>(
|
|
||||||
GraphicsDevice,
|
|
||||||
BufferUsageFlags.Vertex,
|
|
||||||
6
|
|
||||||
);
|
|
||||||
|
|
||||||
texture = Texture.CreateTexture2D(
|
texture = Texture.CreateTexture2D(
|
||||||
GraphicsDevice,
|
GraphicsDevice,
|
||||||
MainWindow.Width,
|
MainWindow.Width,
|
||||||
|
@ -78,26 +71,36 @@ namespace MoonWorks.Test
|
||||||
sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
|
sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
|
||||||
|
|
||||||
// Upload GPU resources and dispatch compute work
|
// Upload GPU resources and dispatch compute work
|
||||||
|
|
||||||
|
var resourceInitializer = new ResourceInitializer(GraphicsDevice);
|
||||||
|
|
||||||
|
vertexBuffer = resourceInitializer.CreateBuffer(
|
||||||
|
[
|
||||||
|
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
||||||
|
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)),
|
||||||
|
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
||||||
|
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
||||||
|
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
||||||
|
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
|
||||||
|
],
|
||||||
|
BufferUsageFlags.Vertex
|
||||||
|
);
|
||||||
|
|
||||||
|
resourceInitializer.Upload();
|
||||||
|
resourceInitializer.Dispose();
|
||||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
cmdbuf.SetBufferData(vertexBuffer, new PositionTextureVertex[]
|
|
||||||
{
|
|
||||||
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
|
||||||
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
|
|
||||||
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
|
|
||||||
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
|
|
||||||
});
|
|
||||||
|
|
||||||
GradientTextureComputeUniforms gradientUniforms = new GradientTextureComputeUniforms(
|
GradientTextureComputeUniforms gradientUniforms = new GradientTextureComputeUniforms(
|
||||||
texture.Width / 8,
|
texture.Width / 8,
|
||||||
texture.Height / 8
|
texture.Height / 8
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cmdbuf.BeginComputePass();
|
||||||
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
|
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
|
||||||
cmdbuf.BindComputeTextures(texture);
|
cmdbuf.BindComputeTextures(new TextureLevelBinding(texture, 0));
|
||||||
uint offset = cmdbuf.PushComputeShaderUniforms(gradientUniforms);
|
cmdbuf.PushComputeShaderUniforms(gradientUniforms);
|
||||||
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1, offset);
|
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1);
|
||||||
|
cmdbuf.EndComputePass();
|
||||||
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
}
|
}
|
||||||
|
@ -114,7 +117,7 @@ namespace MoonWorks.Test
|
||||||
cmdbuf.BindGraphicsPipeline(drawPipeline);
|
cmdbuf.BindGraphicsPipeline(drawPipeline);
|
||||||
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
|
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
|
||||||
cmdbuf.BindVertexBuffers(vertexBuffer);
|
cmdbuf.BindVertexBuffers(vertexBuffer);
|
||||||
cmdbuf.DrawPrimitives(0, 2, 0, 0);
|
cmdbuf.DrawPrimitives(0, 2);
|
||||||
cmdbuf.EndRenderPass();
|
cmdbuf.EndRenderPass();
|
||||||
}
|
}
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
|
Loading…
Reference in New Issue