void RadixCreatePlan(FRadixPlan512* Plan, uint32 Slices) { Plan->Slices = Slices; // Create 6 param sets for 512x512 transform const uint32 thread_count = Plan->Slices * (512 * 512) / 8; uint32 ostride = 512 * 512 / 8; uint32 istride = ostride; uint32 pstride = 512; double phase_base = -TWO_PI / (512.0 * 512.0); RadixSetPerFrameParams(Plan, 0, thread_count, ostride, istride, pstride, (float)phase_base); for (int i = 1; i < FFT_PARAM_SETS; i++) { istride /= 8; phase_base *= 8.0; if (i == 3) { ostride /= 512; pstride = 1; } RadixSetPerFrameParams(Plan, i, thread_count, ostride, istride, pstride, (float)phase_base); } // Temp buffers uint32 BytesPerElement = sizeof(float) * 2; uint32 NumElements = (512 * Plan->Slices) * 512; Plan->pBuffer_Tmp = RHICreateStructuredBuffer(BytesPerElement, BytesPerElement * NumElements, NULL, (BUF_UnorderedAccess | BUF_ShaderResource)); Plan->pUAV_Tmp = RHICreateUnorderedAccessView(Plan->pBuffer_Tmp, false, false); Plan->pSRV_Tmp = RHICreateShaderResourceView(Plan->pBuffer_Tmp); }
void UVaOceanSimulatorComponent::CreateBufferAndUAV(FResourceArrayInterface* Data, uint32 byte_width, uint32 byte_stride, FStructuredBufferRHIRef* ppBuffer, FUnorderedAccessViewRHIRef* ppUAV, FShaderResourceViewRHIRef* ppSRV) { *ppBuffer = RHICreateStructuredBuffer(byte_stride, Data->GetResourceDataSize(), Data, (BUF_UnorderedAccess | BUF_ShaderResource)); *ppUAV = RHICreateUnorderedAccessView(*ppBuffer, false, false); *ppSRV = RHICreateShaderResourceView(*ppBuffer); }
FComputeShaderUsageExample::FComputeShaderUsageExample(float SimulationSpeed, int32 SizeX, int32 SizeY, ERHIFeatureLevel::Type ShaderFeatureLevel) { FeatureLevel = ShaderFeatureLevel; ConstantParameters.SimulationSpeed = SimulationSpeed; VariableParameters = FComputeShaderVariableParameters(); bIsComputeShaderExecuting = false; bIsUnloading = false; bSave = false; //There are only a few different texture formats we can use if we want to use the output texture as input in a pixel shader later //I would have loved to go with the R8G8B8A8_UNORM approach, but unfortunately, it seems UE4 does not support this in an obvious way, which is why I chose the UINT format using packing instead :) //There is some excellent information on this topic in the following links: //http://www.gamedev.net/topic/605356-r8g8b8a8-texture-format-in-compute-shader/ //https://msdn.microsoft.com/en-us/library/ff728749(v=vs.85).aspx FRHIResourceCreateInfo CreateInfo; Texture = RHICreateTexture2D(SizeX, SizeY, PF_R32_UINT, 1, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); TextureUAV = RHICreateUnorderedAccessView(Texture); }
FFluidSimulationShaderInstance::FFluidSimulationShaderInstance(int32 SizeX, int32 SizeY, int32 SizeZ, ERHIFeatureLevel::Type ShaderFeatureLevel) { FeatureLevel = ShaderFeatureLevel; ConstantParameters = FFluidSimulationShaderConstantParameters(); VariableParameters = FFluidSimulationShaderVariableParameters(); bIsShaderExecuting = false; bIsUnloading = false; FRHIResourceCreateInfo CreateInfo; PressureIn = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_R32_UINT, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); PressureOut = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_R32_UINT, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); Divergence = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_R32_UINT, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); VelocityIn = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_A32B32G32R32F, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); VelocityOut = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_A32B32G32R32F, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); DensityIn = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_A32B32G32R32F, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); DensityOut = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_A32B32G32R32F, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); TemperatureIn = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_R32_UINT, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); TemperatureOut = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_R32_UINT, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); Obstacle = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_R32_UINT, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); VorticityIn = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_A32B32G32R32F, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); VorticityOut = RHICreateTexture3D(SizeX, SizeY, SizeZ, PF_A32B32G32R32F, 1, TexCreate_ShaderResource | TexCreate_UAV, CreateInfo); PressureInUAV = RHICreateUnorderedAccessView(PressureIn); PressureOutUAV = RHICreateUnorderedAccessView(PressureOut); DivergenceUAV = RHICreateUnorderedAccessView(Divergence); VelocityInUAV = RHICreateUnorderedAccessView(VelocityIn); VelocityOutUAV = RHICreateUnorderedAccessView(VelocityOut); DensityInUAV = RHICreateUnorderedAccessView(DensityIn); DensityOutUAV = RHICreateUnorderedAccessView(DensityOut); TemperatureInUAV = RHICreateUnorderedAccessView(TemperatureIn); TemperatureOutUAV = RHICreateUnorderedAccessView(TemperatureOut); ObstacleUAV = RHICreateUnorderedAccessView(Obstacle); VorticityInUAV = RHICreateUnorderedAccessView(VorticityIn); VorticityOutUAV = RHICreateUnorderedAccessView(VorticityOut); PressureInSRV = RHICreateShaderResourceView(PressureIn, 0); PressureOutSRV = RHICreateShaderResourceView(PressureOut, 0); DivergenceSRV = RHICreateShaderResourceView(Divergence, 0); VelocityInSRV = RHICreateShaderResourceView(VelocityIn, 0); VelocityOutSRV = RHICreateShaderResourceView(VelocityOut, 0); DensityInSRV = RHICreateShaderResourceView(DensityIn, 0); DensityOutSRV = RHICreateShaderResourceView(DensityOut, 0); TemperatureInSRV = RHICreateShaderResourceView(TemperatureIn, 0); TemperatureOutSRV = RHICreateShaderResourceView(TemperatureOut, 0); ObstacleSRV = RHICreateShaderResourceView(Obstacle, 0); VorticityInSRV = RHICreateShaderResourceView(VorticityIn, 0); VorticityOutSRV = RHICreateShaderResourceView(VorticityOut, 0); GEngine->FluidSimDensitySRV = RHICreateShaderResourceView(DensityIn, 0); // Set up walls of simulation ExecuteObstaclesShader(); }