From 6226cceb192a46f9ce2da1dd30d5219a001b0532 Mon Sep 17 00:00:00 2001 From: Pavel <68122101+red-prig@users.noreply.github.com> Date: Thu, 10 Nov 2022 14:44:52 +0300 Subject: [PATCH] + --- chip/ps4_videodrv.pas | 54 +++++++++++++++++--------- vulkan/vShaderExt.pas | 1 + vulkan/vShaderManager.pas | 81 +++++++++++++++++++++++++++++++++------ 3 files changed, 107 insertions(+), 29 deletions(-) diff --git a/chip/ps4_videodrv.pas b/chip/ps4_videodrv.pas index 4768f4e..5db1b46 100644 --- a/chip/ps4_videodrv.pas +++ b/chip/ps4_videodrv.pas @@ -1708,6 +1708,8 @@ var Event:TvEvent2; + pa:TPushConstAllocator; + begin Result:=True; @@ -2016,10 +2018,21 @@ begin FRenderCmd:=LastRenderCmd; end; + pa.Init; + // + + {$ifdef ww}Writeln('[FPSShader]');{$endif} + FPSShader:=FetchShader(vShaderStagePs,1,GPU_REGS,@pa); + //if (FPSShader=nil) then Exit; + + // + {$ifdef ww}Writeln('[FVSShader]');{$endif} - FVSShader:=FetchShader(vShaderStageVs,0,GPU_REGS); + FVSShader:=FetchShader(vShaderStageVs,0,GPU_REGS,@pa); if (FVSShader=nil) then Exit(False); + // + FAttrBuilder:=Default(TvAttrBuilder); FVSShader.EnumVertLayout(@FAttrBuilder.AddAttr,FVSShader.FDescSetId,@GPU_REGS.SPI.VS.USER_DATA); @@ -2034,9 +2047,7 @@ begin end; end; - {$ifdef ww}Writeln('[FPSShader]');{$endif} - FPSShader:=FetchShader(vShaderStagePs,1,GPU_REGS); - //if (FPSShader=nil) then Exit; + // FShadersKey:=Default(TvShadersKey); FShadersKey.SetVSShader(FVSShader); @@ -2045,6 +2056,8 @@ begin FShaderGroup:=FetchShaderGroup(@FShadersKey); Assert(FShaderGroup<>nil); + // + FRenderCmd.FPipeline.FShaderGroup:=FShaderGroup; FDescriptorGroup:=FetchDescriptorGroup(GFXRing.CmdBuffer,FShaderGroup.FLayout); @@ -2119,18 +2132,6 @@ begin // - if (FVSShader.FPushConst.size<>0) then - begin - pData:=FVSShader.GetPushConstData(@GPU_REGS.SPI.VS.USER_DATA); - - if (pData<>nil) then - GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, - ord(VK_SHADER_STAGE_VERTEX_BIT), - 0,FVSShader.FPushConst.size, - pData); - - end; - if (FPSShader<>nil) then if (FPSShader.FPushConst.size<>0) then begin @@ -2139,10 +2140,22 @@ begin if (pData<>nil) then GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, ord(VK_SHADER_STAGE_FRAGMENT_BIT), - 0,FPSShader.FPushConst.size, + FPSShader.FPushConst.offset,FPSShader.FPushConst.size, pData); end; + if (FVSShader.FPushConst.size<>0) then + begin + pData:=FVSShader.GetPushConstData(@GPU_REGS.SPI.VS.USER_DATA); + + if (pData<>nil) then + GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, + ord(VK_SHADER_STAGE_VERTEX_BIT), + FVSShader.FPushConst.offset,FVSShader.FPushConst.size, + pData); + + end; + if (Length(FAttrBuilder.FBindExt)<>0) then begin For i:=0 to High(FAttrBuilder.FBindExt) do @@ -2248,6 +2261,9 @@ var FShaderGroup:TvShaderGroup; FComputePipeline:TvComputePipeline2; + + pa:TPushConstAllocator; + begin Result:=False; @@ -2269,7 +2285,9 @@ begin GFXRing.AllocCmdBuffer; GFXRing.CmdBuffer.EndRenderPass; - FCSShader:=FetchShader(vShaderStageCs,0,GPU_REGS); + pa.Init; + + FCSShader:=FetchShader(vShaderStageCs,0,GPU_REGS,@pa); if (FCSShader=nil) then Exit; diff --git a/vulkan/vShaderExt.pas b/vulkan/vShaderExt.pas index 6f8ac00..5913f86 100644 --- a/vulkan/vShaderExt.pas +++ b/vulkan/vShaderExt.pas @@ -835,6 +835,7 @@ begin B[p]:=Default(TVkPushConstantRange); B[p].stageFlags:=ord(FShaders[i].FStage); + B[p].offset :=FShaders[i].FPushConst.offset; B[p].size :=FShaders[i].FPushConst.size; Inc(p); diff --git a/vulkan/vShaderManager.pas b/vulkan/vShaderManager.pas index 39024a1..dace8b6 100644 --- a/vulkan/vShaderManager.pas +++ b/vulkan/vShaderManager.pas @@ -47,7 +47,16 @@ type Destructor Destroy; override; end; -function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS):TvShaderExt; + PPushConstAllocator=^TPushConstAllocator; + TPushConstAllocator=object + size:DWORD; + offset:DWORD; + Procedure Init; + function GetAvailable:DWORD; + procedure Apply(i:DWORD); + end; + +function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt; function FetchShaderGroup(F:PvShadersKey):TvShaderGroup; implementation @@ -192,7 +201,27 @@ begin FileClose(F); end; -function ParseShader(FStage:TvShaderStage;pData:PDWORD;var GPU_REGS:TGPU_REGS):TMemoryStream; +procedure TPushConstAllocator.Init; +begin + Size:=limits.maxPushConstantsSize; + offset:=0; +end; + +function TPushConstAllocator.GetAvailable:DWORD; +begin + Result:=0; + if (offsetnil) then + begin + SprvEmit.Config.PushConstantsOffset :=pc^.offset; + SprvEmit.Config.maxPushConstantsSize:=pc^.GetAvailable; + end; + //SprvEmit.Config.UseVertexInput:=False; if (SprvEmit.ParseStage(pData)>1) then @@ -253,7 +286,7 @@ begin //DumpSpv(FStage,Result); end; -function _FetchShader(FStage:TvShaderStage;pData:PDWORD;FDescSetId:Integer;var GPU_REGS:TGPU_REGS):TvShaderExt; +function _FetchShader(FStage:TvShaderStage;pData:PDWORD;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt; var F:TShaderDataKey; @@ -296,7 +329,20 @@ begin FShader.EnumUnifLayout(@ch.AddAttr,FDescSetId,pUserData); if ch.FResult then begin - Break; + + if (FShader.FPushConst.size<>0) and (pc<>nil) then + begin + if (FShader.FPushConst.offset=pc^.offset) then + if (FShader.FPushConst.size<=pc^.GetAvailable) then + begin + pc^.Apply(FShader.FPushConst.size); + Break; + end; + end else + begin + Break; + end; + end else begin FShader:=nil; @@ -306,13 +352,20 @@ begin if (FShader=nil) then begin - M:=ParseShader(FStage,pData,GPU_REGS); + M:=ParseShader(FStage,pData,GPU_REGS,pc); Assert(M<>nil); FShader:=TvShaderExt.Create; FShader.FDescSetId:=FDescSetId; FShader.LoadFromStream(M); + if (FShader.FPushConst.size<>0) and (pc<>nil) then + begin + FShader.FPushConst.offset:=pc^.offset; + Dec(FShader.FPushConst.size,pc^.offset); + pc^.Apply(FShader.FPushConst.size); + end; + M.Free; i:=Length(t.FShaders); @@ -350,7 +403,7 @@ begin } - M:=ParseShader(FStage,pData,GPU_REGS); + M:=ParseShader(FStage,pData,GPU_REGS,pc); Assert(M<>nil); FShader:=TvShaderExt.Create; @@ -359,6 +412,12 @@ begin M.Free; + if (FShader.FPushConst.size<>0) and (pc<>nil) then + begin + FShader.FPushConst.offset:=pc^.offset; + Dec(FShader.FPushConst.size,pc^.offset); + pc^.Apply(FShader.FPushConst.size); + end; SetLength(t.FShaders,1); t.FShaders[0]:=FShader; @@ -369,7 +428,7 @@ begin Result:=FShader; end; -function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS):TvShaderExt; +function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt; var pData:PDWORD; begin @@ -387,7 +446,7 @@ begin FShaderCacheSet.Lock_wr; - Result:=_FetchShader(FStage,pData,FDescSetId,GPU_REGS); + Result:=_FetchShader(FStage,pData,FDescSetId,GPU_REGS,pc); FShaderCacheSet.Unlock; end;