edited: to make use of class ComputeEffectShader
edited: works now, updated code to working one
hi,
im trying to get a Compute shader to work, but i still fail.
it compiles and run, it executes this (cpu)sources
the shader gets compiled (tested via wrong shader source)
also tried without the structured buffer (only the texture)
im using dx11, win10
but it seems to not beeing executed.
currently i use 2 parameters
shader code only writes something to sBuffer[0] and texture[0],
just to see if it works.
the code is executed by my game system class
plxxxxx help! :)
what i did:
cpu:
init:
struct VoxelData
{
public float Material;
public float Color;
}
dbgTexture = Texture.New2D(Game.GraphicsDevice, Size.X, Size.Y, PixelFormat.R32G32B32A32_Float,
TextureFlags.ShaderResource | TextureFlags.UnorderedAccess, 1,
GraphicsResourceUsage.Default );
VoxelDataArray = new VoxelData[Size.X * Size.Y * Size.Z];
for (int i = 0; i < VoxelDataArray.Length; i++)
VoxelDataArray[i] = new VoxelData { Material = i, Color = -i };
var groupCounts = new Int3(32, 32, 1);
drawEffectContext = RenderContext.GetShared(Game.Services);
VolumeShader = new ComputeEffectShader(drawEffectContext) { ShaderSourceName = "VolumeComputeShaderEffect", ThreadGroupCounts = groupCounts };
VoxelBuffer = Buffer.Structured.New<VoxelData>(Game.GraphicsDevice, VoxelDataArray, true);
VolumeShader.Parameters.Set(VolumeComputeShaderKeys.DbgTexture, dbgTexture);
VolumeShader.Parameters.Set(VolumeComputeShaderKeys.VoxelBuffer, VoxelBuffer);
cpu: draw
RenderDocHost.RenderDocManager.StartCapture(Game.GraphicsDevice,IntPtr.Zero);
var renderDrawContext = new RenderDrawContext(Game.Services, drawEffectContext, Game.GraphicsContext);
VolumeShader.Draw(renderDrawContext);
VoxelData[] resultDataArray;
resultDataArray = VoxelBuffer.GetData<VoxelData>(Game.GraphicsContext.CommandList);
RenderDocHost.RenderDocManager.EndFrameCapture(Game.GraphicsDevice, IntPtr.Zero);
shader
shader VolumeComputeShader : ComputeShaderBase
{
struct VoxelData
{
float Material;
float Color;
};
stage RWTexture2D<float4> DbgTexture;
stage RWStructuredBuffer<VoxelData> VoxelBuffer;
override void Compute()
{
DbgTexture[0] = float4(1,1,1,1);
VoxelBuffer[0].Color = 123;
}
};
effect VolumeComputeShaderEffect
{
mixin VolumeComputeShader;
};
just one hint, instead of EffectInstance, use the ComputeEffectShader. the tests are always a nice learning source:
https://github.com/stride3d/xenko/blob/master/sources/engine/Xenko.Graphics.Tests.11_0/TestComputeShader.cs
tnx for the info,
rewrote to make use of 'ComputeEffectShader' and updated question.
unluckyly the result is the same :(
it works! cant believe it works!, tnx @tebjan !
updated the code above in case someone wanna do the same.
Most helpful comment
just one hint, instead of
EffectInstance, use theComputeEffectShader. the tests are always a nice learning source:https://github.com/stride3d/xenko/blob/master/sources/engine/Xenko.Graphics.Tests.11_0/TestComputeShader.cs