Skip to content

Commit

Permalink
GPU is now threaded instead of 1,1,1 with new ComputeShader Debug wid…
Browse files Browse the repository at this point in the history
…get (basic)
  • Loading branch information
EvoPulseGaming committed Jul 8, 2018
1 parent 016b7a7 commit a82b66c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
Binary file modified Content/BP_ShaderController.uasset
Binary file not shown.
Binary file added Content/ComputeDebugUI.uasset
Binary file not shown.
Binary file modified Content/ComputeShaderDev.umap
Binary file not shown.
Binary file added Content/ComputeStructValueWidget.uasset
Binary file not shown.
4 changes: 2 additions & 2 deletions Shaders/Private/ComputeShader.usf
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ RWTexture2D<float> OutputSurface_Parameter_GPU;
//equals (1024,1024,1)!
//Then you can just use ThreadId.xy for each pixel without fancy math (using a 1024x1024 texture)

[numthreads(1, 1, 1)]
[numthreads(256, 1, 1)]
//If using more than 1,1,1, threads:
//Be aware that parrellel thread are running, make sure that no thread can stomp on another threads calculations by
//writing to the same buffer/texture point
void VS_test(uint3 ThreadId : SV_DispatchThreadID)
{
//Be aware that it may be faster to copy buffer data to a local variable here, as local memory is faster than buffer memory
//So for huge datasets with massive random read/write, its better to do this locally, and just copy it back when done.
TArray_Struct_Parameter_GPU[0].runCount = TArray_Struct_Parameter_GPU[0].runCount + 1;
TArray_Struct_Parameter_GPU[ThreadId.x].runCount = TArray_Struct_Parameter_GPU[ThreadId.x].runCount + 1;
}


Expand Down
19 changes: 12 additions & 7 deletions Source/ComputeShaderDevPlugin/Private/ShaderController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ AShaderController::AShaderController()
void AShaderController::OnConstruction(const FTransform& Transform)
{

TArray_FStruct_Shader_CPU.Empty();
//Create our data struct
FStruct_Shader_CPU instanceData;
//Set our data struct values
instanceData.runCount = 0;
//Add our data struct to the array
TArray_FStruct_Shader_CPU.Add(instanceData);




}

void AShaderController::BeginPlay()
{
//Init our instance of compute ComputeShaderInstance controller
TArray_FStruct_Shader_CPU.Empty();
TArray_FStruct_Shader_CPU.Reserve(256);

//Add our default data struct to the array
for (int i = 0; i<256; i++)
{
TArray_FStruct_Shader_CPU.Add(FStruct_Shader_CPU());
}


Shader_Constant_Params.ArrayNum = TArray_FStruct_Shader_CPU.Num();
Shader_Variable_Params = FVariables_Class();
Expand Down
6 changes: 6 additions & 0 deletions Source/ComputeShaderDevPlugin/Public/ShaderController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ struct FStruct_Shader_CPU {

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ComputeShader")
int32 runCount = 1;

//Have to have this initializer or you will have "optimized out" issues when
//creating new structs
FStruct_Shader_CPU()
{
}
};

UCLASS(BlueprintType)
Expand Down

0 comments on commit a82b66c

Please sign in to comment.