Early support for HLSL static variables
このコミットが含まれているのは:
1 親
f87105b23c
コミット
c3365e5253
2ファイル変更
+12
-7
検索条件に一致するファイルはありません
@@ -28,16 +28,15 @@ namespace DirectX12ComputeShaderSample
|
||||
}
|
||||
|
||||
using Buffer<float> gpuBuffer = Buffer.UnorderedAccess.New(device, array.AsSpan());
|
||||
using Buffer<uint> widthBuffer = Buffer.Constant.New(device, (uint)width);
|
||||
|
||||
// Variables for closure
|
||||
uint Width = (uint)width;
|
||||
uint size = (uint)width;
|
||||
var data = gpuBuffer.GetGpuResource();
|
||||
|
||||
// Shader body
|
||||
Action<UInt3> action = id =>
|
||||
{
|
||||
data[id.X + id.Y * Width] *= 2;
|
||||
data[id.X + id.Y * size] *= 2;
|
||||
};
|
||||
|
||||
// Generate computer shader
|
||||
@@ -50,7 +49,6 @@ namespace DirectX12ComputeShaderSample
|
||||
|
||||
RootParameter[] rootParameters =
|
||||
{
|
||||
new RootParameter(ShaderVisibility.All, new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, 0)),
|
||||
new RootParameter(ShaderVisibility.All, new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, 0))
|
||||
};
|
||||
|
||||
@@ -67,8 +65,7 @@ namespace DirectX12ComputeShaderSample
|
||||
{
|
||||
commandList.SetPipelineState(pipelineState);
|
||||
|
||||
commandList.SetComputeRootDescriptorTable(0, widthBuffer);
|
||||
commandList.SetComputeRootDescriptorTable(1, gpuBuffer);
|
||||
commandList.SetComputeRootDescriptorTable(0, gpuBuffer);
|
||||
|
||||
commandList.Dispatch(2, 2, 1);
|
||||
commandList.Flush(true);
|
||||
|
||||
@@ -125,7 +125,8 @@ namespace DirectX12GameEngine.Shaders
|
||||
|
||||
if (memberType.IsGenericType && memberType.GetGenericTypeDefinition() == typeof(RWBufferResource<>))
|
||||
WriteUnorderedAccessView(fieldInfo, memberType, bindingTracker.UnorderedAccessView++);
|
||||
else WriteConstantBuffer(fieldInfo, memberType, bindingTracker.ConstantBuffer++);
|
||||
//else WriteConstantBuffer(fieldInfo, memberType, bindingTracker.ConstantBuffer++);
|
||||
else WriteStaticVariable(fieldInfo, memberType, fieldInfo.GetValue(shaderInstance));
|
||||
}
|
||||
|
||||
// Write the actual shader body
|
||||
@@ -333,6 +334,13 @@ namespace DirectX12GameEngine.Shaders
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteStaticVariable(MemberInfo memberInfo, Type memberType, object value)
|
||||
{
|
||||
writer.Write($"static {HlslKnownTypes.GetMappedName(memberType)} {memberInfo.Name}");
|
||||
writer.Write($" = {value};");
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
private void WriteConstantBuffer(MemberInfo memberInfo, Type memberType, int binding)
|
||||
{
|
||||
int arrayCount = memberType.IsArray ? 2 : 0;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする