rewrite videodrv

This commit is contained in:
Pavel 2022-06-08 17:12:07 +03:00
parent a699fbb69a
commit 2a4e7a3af7
5 changed files with 932 additions and 717 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1042,12 +1042,21 @@ function ps4_sceGnmSubmitCommandBuffers(
dcbSizesInBytes:PDWORD; //3
ccbGpuAddrs:PPointer; //4
ccbSizesInBytes:PDWORD):Integer; SysV_ABI_CDecl; //5
var
Submit:TvSubmitInfo;
begin
//exit(0);
if (count=0) then Exit(SCE_KERNEL_ERROR_EINVAL);
Submit:=Default(TvSubmitInfo);
Submit.count :=count ;
Submit.dcbGpuAddrs :=dcbGpuAddrs ;
Submit.dcbSizesInBytes:=dcbSizesInBytes;
Submit.ccbGpuAddrs :=ccbGpuAddrs ;
Submit.ccbSizesInBytes:=ccbSizesInBytes;
_sig_lock;
//Writeln(GetCurrentThreadId,'>Submit');
vSubmitCommandBuffers(count,dcbGpuAddrs,dcbSizesInBytes,ccbGpuAddrs,ccbSizesInBytes,nil);
Result:=vSubmitCommandBuffers(@Submit,nil);
//Writeln(GetCurrentThreadId,'<Submit');
_sig_unlock;
Result:=0;
@ -1064,9 +1073,19 @@ function ps4_sceGnmSubmitAndFlipCommandBuffers(
flipMode:Integer; //8
flipArg:QWORD):Integer; SysV_ABI_CDecl; //9
var
Submit:TvSubmitInfo;
Flip:TqcFlipInfo;
begin
//exit(0);
if (count=0) or
(dcbGpuAddrs=nil) or
(dcbSizesInBytes=nil) then Exit(SCE_KERNEL_ERROR_EINVAL);
Submit:=Default(TvSubmitInfo);
Submit.count :=count ;
Submit.dcbGpuAddrs :=dcbGpuAddrs ;
Submit.dcbSizesInBytes:=dcbSizesInBytes;
Submit.ccbGpuAddrs :=ccbGpuAddrs ;
Submit.ccbSizesInBytes:=ccbSizesInBytes;
Flip.hVideo :=videoOutHandle;
Flip.bufferIndex:=displayBufferIndex;
@ -1075,7 +1094,7 @@ begin
_sig_lock;
//Writeln(GetCurrentThreadId,'>SubmitAndFlip');
vSubmitCommandBuffers(count,dcbGpuAddrs,dcbSizesInBytes,ccbGpuAddrs,ccbSizesInBytes,@Flip);
Result:=vSubmitCommandBuffers(@Submit,@Flip);
//Writeln(GetCurrentThreadId,'<SubmitAndFlip');
_sig_unlock;
Result:=0;

View File

@ -121,6 +121,18 @@ type
Procedure BindSet(BindPoint:TVkPipelineBindPoint;fset:TVkUInt32;FHandle:TVkDescriptorSet);
Procedure PushConstant(BindPoint:TVkPipelineBindPoint;stageFlags:TVkShaderStageFlags;offset,size:TVkUInt32;const pValues:PVkVoid);
Procedure DispatchDirect(X,Y,Z:TVkUInt32);
Procedure BindVertexBuffer(Binding:TVkUInt32;
Buffer:TVkBuffer;
Offset:TVkDeviceSize);
Procedure ClearDepthStencilImage(
image:TVkImage;
imageLayout:TVkImageLayout;
const pDepthStencil:PVkClearDepthStencilValue;
rangeCount:TVkUInt32;
const pRanges:PVkImageSubresourceRange);
end;
TvCmdBuffer=class(TvCustomCmdBuffer)
@ -292,7 +304,6 @@ end;
Procedure TvCustomCmdBuffer.BindPipeline(BindPoint:TVkPipelineBindPoint;F:TVkPipeline);
begin
if (Self=nil) then Exit;
if (cmdbuf=VK_NULL_HANDLE) then Exit;
if (FCurrPipeline[ord(BindPoint)]=F) then Exit;
if (not BeginCmdBuffer) then Exit;
@ -310,7 +321,6 @@ begin
Result:=False;
if (Self=nil) then Exit;
if (cmdbuf=VK_NULL_HANDLE) then Exit;
if (RT=nil) then
begin
@ -427,7 +437,7 @@ begin
FFence:=Fence.FHandle;
end;
r:=FQueue.QueueSubmit(1,@info,FFence);
r:=FQueue.Submit(1,@info,FFence);
if (r<>VK_SUCCESS) then
begin
@ -528,7 +538,8 @@ var
p:PvImageBarrier;
begin
if (Self=nil) then Exit;
if (cmdbuf=VK_NULL_HANDLE) then Exit;
if (not BeginCmdBuffer) then Exit;
t:=Default(TvImageBarrier);
t.Init(image,range);
@ -579,9 +590,10 @@ Procedure TvCustomCmdBuffer.PushConstant(BindPoint:TVkPipelineBindPoint;stageFla
begin
if (Self=nil) then Exit;
if (pValues=nil) or (size=0) then Exit;
if (cmdbuf=VK_NULL_HANDLE) then Exit;
if (FCurrLayout[ord(BindPoint)]=VK_NULL_HANDLE) then Exit;
if (not BeginCmdBuffer) then Exit;
Inc(cmd_count);
vkCmdPushConstants(cmdbuf,
@ -595,14 +607,53 @@ end;
Procedure TvCustomCmdBuffer.DispatchDirect(X,Y,Z:TVkUInt32);
begin
if (Self=nil) then Exit;
if (cmdbuf=VK_NULL_HANDLE) then Exit;
if (FCurrPipeline[1]=VK_NULL_HANDLE) then Exit;
if (not BeginCmdBuffer) then Exit;
Inc(cmd_count);
vkCmdDispatch(cmdbuf,X,Y,Z);
end;
Procedure TvCustomCmdBuffer.BindVertexBuffer(Binding:TVkUInt32;
Buffer:TVkBuffer;
Offset:TVkDeviceSize);
begin
if (Self=nil) then Exit;
if (not BeginCmdBuffer) then Exit;
vkCmdBindVertexBuffer(cmdbuf,
binding,
Buffer,
Offset);
end;
Procedure TvCustomCmdBuffer.ClearDepthStencilImage(
image:TVkImage;
imageLayout:TVkImageLayout;
const pDepthStencil:PVkClearDepthStencilValue;
rangeCount:TVkUInt32;
const pRanges:PVkImageSubresourceRange);
begin
if (Self=nil) then Exit;
EndRenderPass;
if (not BeginCmdBuffer) then Exit;
Inc(cmd_count);
vkCmdClearDepthStencilImage(
cmdbuf,
image,
imageLayout,
pDepthStencil,
rangeCount,
pRanges);
end;
Procedure TvCmdBuffer.BindSets(BindPoint:TVkPipelineBindPoint;F:TvDescriptorGroup);
var
i:Integer;
@ -655,7 +706,7 @@ begin
if (Self=nil) then Exit;
EndRenderPass;
BeginCmdBuffer;
if (not BeginCmdBuffer) then Exit;
srcb:=FetchHostBuffer(Self,src,byteCount,ord(VK_BUFFER_USAGE_TRANSFER_SRC_BIT));
Assert(srcb<>nil);
@ -711,7 +762,7 @@ begin
if (Self=nil) then Exit;
EndRenderPass;
BeginCmdBuffer;
if (not BeginCmdBuffer) then Exit;
dstb:=FetchHostBuffer(Self,dst,byteCount,ord(VK_BUFFER_USAGE_TRANSFER_DST_BIT));
Assert(dstb<>nil);
@ -749,7 +800,7 @@ begin
if (Self=nil) then Exit;
EndRenderPass;
BeginCmdBuffer;
if (not BeginCmdBuffer) then Exit;
Case eventType of
CS_DONE:

View File

@ -84,16 +84,18 @@ type
TvDevice=class
FHandle:TVkDevice;
FLock:Pointer;
Constructor Create(Queues:TvDeviceQueues);
Destructor Destroy; override;
function WaitIdle:TVkResult;
end;
TvQueue=class
FHandle:TVkQueue;
FLock:Pointer;
function QueueSubmit(submitCount:TVkUInt32;const pSubmits:PVkSubmitInfo;fence:TVkFence):TVkResult;
function QueueWaitIdle:TVkResult;
function QueuePresentKHR(const pPresentInfo:PVkPresentInfoKHR):TVkResult;
function Submit(submitCount:TVkUInt32;const pSubmits:PVkSubmitInfo;fence:TVkFence):TVkResult;
function WaitIdle:TVkResult;
function PresentKHR(const pPresentInfo:PVkPresentInfoKHR):TVkResult;
end;
TvCmdPool=class
@ -173,6 +175,29 @@ procedure vkBarrier(
srcStageMask:TVkPipelineStageFlags;
dstStageMask:TVkPipelineStageFlags);
Procedure vkCmdBindVertexBuffer(commandBuffer:TVkCommandBuffer;
Binding:TVkUInt32;
Buffer:TVkBuffer;
Offset:TVkDeviceSize);
Procedure vkCmdBindDescriptorBuffer(commandBuffer:TVkCommandBuffer;
Binding:TVkUInt32;
Buffer:TVkBuffer;
Offset:TVkDeviceSize);
Procedure vkCmdBindSB(cmd:TVkCommandBuffer;
point:TVkPipelineBindPoint;
layout:TVkPipelineLayout;
aSet,aBind,aElem:TVkUInt32;
buffer:TVkBuffer;
offset,range:TVkDeviceSize);
procedure vkCmdWaitEvent(commandBuffer:TVkCommandBuffer;
event:TVkEvent;
srcStageMask:TVkPipelineStageFlags;
dstStageMask:TVkPipelineStageFlags);
var
VulkanApp:TVulkanApp;
DebugReport:TVDebugReport;
@ -1097,23 +1122,30 @@ begin
vkDestroyDevice(FHandle,nil);
end;
function TvDevice.WaitIdle:TVkResult;
begin
spin_lock(FLock);
Result:=vkDeviceWaitIdle(FHandle);
spin_unlock(FLock);
end;
//
function TvQueue.QueueSubmit(submitCount:TVkUInt32;const pSubmits:PVkSubmitInfo;fence:TVkFence):TVkResult;
function TvQueue.Submit(submitCount:TVkUInt32;const pSubmits:PVkSubmitInfo;fence:TVkFence):TVkResult;
begin
spin_lock(FLock);
Result:=vkQueueSubmit(FHandle,submitCount,pSubmits,fence);
spin_unlock(FLock);
end;
function TvQueue.QueueWaitIdle:TVkResult;
function TvQueue.WaitIdle:TVkResult;
begin
spin_lock(FLock);
Result:=vkQueueWaitIdle(FHandle);
spin_unlock(FLock);
end;
function TvQueue.QueuePresentKHR(const pPresentInfo:PVkPresentInfoKHR):TVkResult;
function TvQueue.PresentKHR(const pPresentInfo:PVkPresentInfoKHR):TVkResult;
begin
spin_lock(FLock);
Result:=vkQueuePresentKHR(FHandle,pPresentInfo);
@ -1362,6 +1394,77 @@ begin
nil);
end;
Procedure vkCmdBindVertexBuffer(commandBuffer:TVkCommandBuffer;
Binding:TVkUInt32;
Buffer:TVkBuffer;
Offset:TVkDeviceSize);
begin
vkCmdBindVertexBuffers(commandBuffer,Binding,1,@Buffer,@Offset);
end;
Procedure vkCmdBindDescriptorBuffer(commandBuffer:TVkCommandBuffer;
Binding:TVkUInt32;
Buffer:TVkBuffer;
Offset:TVkDeviceSize);
var
info:TVkWriteDescriptorSet;
begin
info:=Default(TVkWriteDescriptorSet);
info.sType:=VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
end;
Procedure vkCmdBindSB(cmd:TVkCommandBuffer;
point:TVkPipelineBindPoint;
layout:TVkPipelineLayout;
aSet,aBind,aElem:TVkUInt32;
buffer:TVkBuffer;
offset,range:TVkDeviceSize);
var
dwrite:TVkWriteDescriptorSet;
buf:TVkDescriptorBufferInfo;
begin
dwrite:=Default(TVkWriteDescriptorSet);
dwrite.sType :=VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
dwrite.dstBinding :=aBind;
dwrite.dstArrayElement:=aElem;
dwrite.descriptorType :=VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
dwrite.descriptorCount:=1;
dwrite.pBufferInfo :=@buf;
buf:=Default(TVkDescriptorBufferInfo);
buf.buffer:=buffer;
buf.offset:=offset;
buf.range :=range ;
if (vkCmdPushDescriptorSetKHR=nil) then
begin
TPFN_vkVoidFunction(vkCmdPushDescriptorSetKHR):=vkGetInstanceProcAddr(VulkanApp.FInstance,'vkCmdPushDescriptorSetKHR');
end;
Assert(vkCmdPushDescriptorSetKHR<>nil);
vkCmdPushDescriptorSetKHR(cmd,point,layout,aSet,1,@dwrite);
end;
procedure vkCmdWaitEvent(commandBuffer:TVkCommandBuffer;
event:TVkEvent;
srcStageMask:TVkPipelineStageFlags;
dstStageMask:TVkPipelineStageFlags);
begin
vkCmdWaitEvents(commandBuffer,
1,
@event,
srcStageMask,
dstStageMask,
0,
nil,
0,
nil,
0,
nil);
end;
var
_lazy_init:Integer=0;
_lazy_wait:Integer=0;

View File

@ -193,7 +193,7 @@ Destructor TvFlip.Destroy;
var
i:Byte;
begin
FlipQueue.QueueWaitIdle;
FlipQueue.WaitIdle;
FreeAndNil(Ffilp_shader);
For i:=0 to 15 do
@ -364,7 +364,7 @@ begin
begin
Fformat:=format;
Ftmode:=tmode;
FlipQueue.QueueWaitIdle;
FlipQueue.WaitIdle;
FreeAndNil(Ffilp_shader);
Ffilp_shader:=TvShaderCompute.Create;
@ -383,7 +383,7 @@ begin
begin
Fformat:=format;
Ftmode:=tmode;
FlipQueue.QueueWaitIdle;
FlipQueue.WaitIdle;
FreeAndNil(Ffilp_shader);
Ffilp_shader:=TvShaderCompute.Create;
@ -587,7 +587,7 @@ end;
procedure TvFlip.recreateSwapChain;
begin
vkDeviceWaitIdle(Device.FHandle);
Device.WaitIdle;
FreeAndNil(FSwapChain);
FSwapChain:=TSwapChain.Create(FSurface,0{1},ord(VK_IMAGE_USAGE_TRANSFER_DST_BIT));
end;
@ -697,9 +697,9 @@ begin
until false;
SwapImage:=FSwapChain.FImage[imageIndex];
Writeln('>Flip.Fence.Wait');
//Writeln('>Flip.Fence.Wait');
buf^.cmdbuf.Fence.Wait(High(uint64));
Writeln('<Flip.Fence.Wait');
//Writeln('<Flip.Fence.Wait');
buf^.cmdbuf.Fence.Reset;
buf^.cmdbuf.ReleaseResource;
@ -1047,7 +1047,7 @@ begin
prInfo.pImageIndices :=@imageIndex;
prInfo.pResults:=nil;
R:=FlipQueue.QueuePresentKHR(@prInfo);
R:=FlipQueue.PresentKHR(@prInfo);
Case R of
VK_SUCCESS:;
VK_ERROR_OUT_OF_DATE_KHR,