AskingQuestions / Shadeup

A language for WebGPU that makes writing shaders easier
https://shadeup.dev
137 stars 4 forks source link

UE5.3 compatibility - getting errors in compute shader base #11

Open SalvatoSC opened 1 year ago

SalvatoSC commented 1 year ago

Hi, I just started learning compute shaders in unreal and wanted to follow your Recipe "Making a custom Advanced Output material expression accessible from Compute Shaders in Unreal Engine 5"

When I generate AdvancedOutputComputeShader.cpp I end up with errors on lines 168 and 185 DrawRenderState.SetViewUniformBuffer(ViewUniformBuffer); RHICmdList.SetComputeShader(ComputeShaderRHI); Both of those funtions have been depracated after 5.1 and I don't know where to begin with updating those for 5.3. Can you please help?

AskingQuestions commented 1 year ago

Thanks for the report

I just pushed an update today that should bring Shadeup fully up-to-date with UE 5.3

The following should fix both your errors above:

In AdvancedOutputComputeShader.cpp add the following include:

#include "MeshPassUtils.h"

and replace the lines found around 140-180 with the following

            PassParameters->OutputColor = GraphBuilder.CreateUAV(FRDGBufferUAVDesc(OutputBuffer, PF_A32B32G32R32F));
            FViewUniformShaderParameters ViewUniformShaderParameters;

            ViewUniformShaderParameters.GameTime = Params.GameTime;
            ViewUniformShaderParameters.RealTime = Params.GameTime;
            ViewUniformShaderParameters.Random = Params.Random;

            auto ViewUniformBuffer = TUniformBufferRef<FViewUniformShaderParameters>::CreateUniformBufferImmediate(ViewUniformShaderParameters, UniformBuffer_SingleFrame);
            PassParameters->View = ViewUniformBuffer;

            auto GroupCount = FComputeShaderUtils::GetGroupCount(FIntVector(Params.X, Params.Y, Params.Z), FComputeShaderUtils::kGolden2DGroupSize);
            GraphBuilder.AddPass(
                RDG_EVENT_NAME("ExecuteMyMaterial3"),
                PassParameters,
                ERDGPassFlags::AsyncCompute,
                [&PassParameters, ComputeShader, MaterialRenderProxy, MaterialResource, LocalScene, GroupCount](FRHIComputeCommandList& RHICmdList)
            {

                FMeshPassProcessorRenderState DrawRenderState;

                MaterialRenderProxy->UpdateUniformExpressionCacheIfNeeded(LocalScene->GetFeatureLevel());

                FMeshMaterialShaderElementData ShaderElementData;

                FMeshProcessorShaders PassShaders;
                PassShaders.ComputeShader = ComputeShader;

                FMeshDrawShaderBindings ShaderBindings;
                ShaderBindings.Initialize(PassShaders);

                int32 DataOffset = 0;
                FMeshDrawSingleShaderBindings SingleShaderBindings = ShaderBindings.GetSingleShaderBindings(SF_Compute, DataOffset);
                ComputeShader->GetShaderBindings(LocalScene->GetRenderScene(), LocalScene->GetFeatureLevel(), nullptr, *MaterialRenderProxy, *MaterialResource, DrawRenderState, ShaderElementData, SingleShaderBindings);

                ShaderBindings.Finalize(&PassShaders);

                UE::MeshPassUtils::Dispatch(RHICmdList, ComputeShader, ShaderBindings, *PassParameters, GroupCount);
            });

If you're still getting errors with I'd try regenerating.

SalvatoSC commented 1 year ago

Hi, first of all thanks for replying this quickly! I cleaned the project plugin of my previous downloads from Shadeup and installed the new shadeup CLI version (shows 1.2, UE5.3 compatible) I once again tried to go through the "Making a custom Advanced Output material expression accessible from Compute Shaders in Unreal Engine 5" and downloaded the templates through console. There was a missing include for MD_Surface so I added

#include "MaterialDomain.h"

at the top and then got the project to compile. After that I am getting the error that something went wrong, so basically this part evaluates as false:

bool bIsShaderValid = ComputeShader.IsValid();

So that's how my little adventure ended on this tutorial.

Just to be sure, I also downloaded pure "Bare-bones material graph evaluation via Compute Shader in UE5" (also cleaned the plugins etc, basically clean install from console as well). That one was also missing MaterialDomain.h and throws the same error.

hoummel commented 11 months ago

Hi, first of all thanks for replying this quickly! I cleaned the project plugin of my previous downloads from Shadeup and installed the new shadeup CLI version (shows 1.2, UE5.3 compatible) I once again tried to go through the "Making a custom Advanced Output material expression accessible from Compute Shaders in Unreal Engine 5" and downloaded the templates through console. There was a missing include for MD_Surface so I added

#include "MaterialDomain.h"

at the top and then got the project to compile. After that I am getting the error that something went wrong, so basically this part evaluates as false:

bool bIsShaderValid = ComputeShader.IsValid();

So that's how my little adventure ended on this tutorial.

Just to be sure, I also downloaded pure "Bare-bones material graph evaluation via Compute Shader in UE5" (also cleaned the plugins etc, basically clean install from console as well). That one was also missing MaterialDomain.h and throws the same error.

replace the code in ExampleComputeShader.cpp

const bool bIsCompatible = Parameters.MaterialParameters.MaterialDomain == MD_Surface
            && Parameters.MaterialParameters.BlendMode == BLEND_Opaque
            && Parameters.MaterialParameters.ShadingModels == MSM_DefaultLit
            && !Parameters.MaterialParameters.bIsUsedWithVirtualHeightfieldMesh;

there was a "!" missing which prevents the shader to be compiled