From 5567c19bfb480e6b3a49e5919b95ec46e01a77d2 Mon Sep 17 00:00:00 2001 From: Pavel <68122101+red-prig@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:31:24 +0300 Subject: [PATCH] + --- chip/pm4_me.pas | 220 ++++++++++++++++++++++++++++++++-- chip/pm4_pfp.pas | 16 +++ sys/dev/dev_gc.pas | 4 +- sys/dev/display_soft.pas | 22 +++- vulkan/vCmdBuffer.pas | 64 ++++++++-- vulkan/vDevice.pas | 31 +++-- vulkan/vHostBufferManager.pas | 2 +- vulkan/vImage.pas | 8 +- vulkan/vMemory.pas | 19 ++- vulkan/vPipelineManager.pas | 24 +++- vulkan/vRegs2Vulkan.pas | 2 +- vulkan/vRender.pas | 31 ++++- vulkan/vShaderExt.pas | 62 +++++++++- 13 files changed, 445 insertions(+), 60 deletions(-) diff --git a/chip/pm4_me.pas b/chip/pm4_me.pas index 0bb855c5..2ba26542 100644 --- a/chip/pm4_me.pas +++ b/chip/pm4_me.pas @@ -10,6 +10,7 @@ uses LFQueue, Vulkan, + vDevice, vBuffer, vHostBufferManager, vImage, @@ -21,6 +22,7 @@ uses vShaderExt, vShaderManager, vRegs2Vulkan, + vCmdBuffer, shader_dump, @@ -51,6 +53,9 @@ type implementation +uses + kern_dmem; + procedure t_pm4_me.Init; begin queue.Create; @@ -93,6 +98,46 @@ end; // +Function GetAlignWidth(format:TVkFormat;width:DWORD):DWORD; +var + bpp,size,align_m:Ptruint; +begin + size:=width; + bpp:=getFormatSize(format); + align_m:=(128 div bpp)-1; + size:=(size+align_m) and (not align_m); + Result:=size; +end; + +Function GetLinearSize(image:TvImage2;align:Boolean):Ptruint; +var + extend:TvExtent3D; +begin + extend.width :=image.key.params.width; + extend.height:=image.key.params.height; + extend.depth :=image.key.params.depth; + + if align then + begin + extend.width:=GetAlignWidth(image.key.cformat,extend.width); + end; + + if IsTexelFormat(image.key.cformat) then + begin + extend.width :=(extend.width +3) div 4; + extend.height :=(extend.height +3) div 4; + end; + + Result:=extend.width* + extend.height* + extend.depth* + image.key.params.arrayLayers* + getFormatSize(image.key.cformat); +end; + +var + FCmdPool:TvCmdPool; + procedure pm4_DrawIndex2(node:p_pm4_node_DrawIndex2); var i:Integer; @@ -125,6 +170,14 @@ var ri:TvImage2; iv:TvImageView2; + + CmdBuffer:TvCmdBuffer; + r:TVkResult; + + buf:TvHostBuffer; + addr,size,offset:Ptruint; + + BufferImageCopy:TVkBufferImageCopy; begin GPU_REGS:=Default(TGPU_REGS); GPU_REGS.SH_REG:=@node^.SH_REG; @@ -154,6 +207,10 @@ begin begin RT_INFO[RT_COUNT]:=GPU_REGS.GET_RT_INFO(i); + //hack + //RT_INFO[RT_COUNT].IMAGE_USAGE:=TM_CLEAR or TM_WRITE; + // + RP_KEY.AddColorAt(RT_COUNT, RT_INFO[RT_COUNT].FImageInfo.cformat, RT_INFO[RT_COUNT].IMAGE_USAGE, @@ -175,7 +232,19 @@ begin end; - RP:=FetchRenderPass(nil,@RP_KEY); + // + if (FCmdPool=nil) then + begin + FCmdPool:=TvCmdPool.Create(VulkanApp.FGFamily); + end; + + CmdBuffer:=TvCmdBuffer.Create(FCmdPool,RenderQueue); + //CmdBuffer.submit_id:=submit_id; + + // + + + RP:=FetchRenderPass(CmdBuffer,@RP_KEY); BI:=GPU_REGS.GET_BLEND_INFO; @@ -208,7 +277,10 @@ begin FVSShader.EnumVertLayout(@FAttrBuilder.AddAttr,FVSShader.FDescSetId,GPU_REGS.get_user_data(vShaderStageVs)); end; - GP_KEY.SetVertexInput(FAttrBuilder); + if not limits.VK_EXT_vertex_input_dynamic_state then + begin + GP_KEY.SetVertexInput(FAttrBuilder); + end; GP_KEY.rasterizer :=GPU_REGS.GET_RASTERIZATION; GP_KEY.multisampling:=GPU_REGS.GET_MULTISAMPLE; @@ -220,7 +292,7 @@ begin GP_KEY.DepthStencil:=DB_INFO.ds_state; end; - GP:=FetchGraphicsPipeline(nil,@GP_KEY); + GP:=FetchGraphicsPipeline(CmdBuffer,@GP_KEY); FFramebuffer:=TvFramebufferIL.Create; FFramebuffer.Key.FRenderPass :=RP; @@ -251,19 +323,152 @@ begin if (RT_COUNT<>0) then For i:=0 to RT_COUNT-1 do begin - FRenderCmd.AddClearColor(TVkClearValue(RT_INFO[i].CLEAR_COLOR)); + //RT_INFO[i].CLEAR_COLOR.float32[2]:=1; - ri:=FetchImage(nil, + FRenderCmd.AddClearColor(RT_INFO[i].CLEAR_COLOR); + + ri:=FetchImage(CmdBuffer, RT_INFO[i].FImageInfo, iu_attachment, RT_INFO[i].IMAGE_USAGE ); - iv:=ri.FetchView(nil,RT_INFO[i].FImageView,iu_attachment); + iv:=ri.FetchView(CmdBuffer,RT_INFO[i].FImageView,iu_attachment); + + FRenderCmd.AddImageView(iv); + + ri.PushBarrier(CmdBuffer, + ord(VK_ACCESS_TRANSFER_READ_BIT), + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + ord(VK_PIPELINE_STAGE_TRANSFER_BIT)); + + ri.PushBarrier(CmdBuffer, + GetColorAccessMask(RT_INFO[i].IMAGE_USAGE), + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL {VK_IMAGE_LAYOUT_GENERAL}, + ord(VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) or + ord(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT) ); end; + if GPU_REGS.DB_ENABLE then + begin + FRenderCmd.AddClearColor(DB_INFO.CLEAR_VALUE); + end; + if not CmdBuffer.BeginRenderPass(FRenderCmd) then + begin + Assert(false,'BeginRenderPass(FRenderCmd)'); + end; + + CmdBuffer.SetVertexInput(FAttrBuilder); + + ///////// + CmdBuffer.instanceCount:=GPU_REGS.UC_REG^.VGT_NUM_INSTANCES; + CmdBuffer.DrawIndex2(node^.addr, + GPU_REGS.UC_REG^.VGT_NUM_INDICES, + GPU_REGS.GET_INDEX_TYPE); + ///////// + + CmdBuffer.EndRenderPass; + + //write back + + if (RT_COUNT<>0) then + For i:=0 to RT_COUNT-1 do + begin + + ri:=FetchImage(CmdBuffer, + RT_INFO[i].FImageInfo, + iu_attachment, + RT_INFO[i].IMAGE_USAGE + ); + + ri.PushBarrier(CmdBuffer, + ord(VK_ACCESS_TRANSFER_READ_BIT), + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + ord(VK_PIPELINE_STAGE_TRANSFER_BIT)); + + if not get_dmem_ptr(ri.key.Addr,@addr,nil) then + begin + Assert(false,'addr:0x'+HexStr(ri.key.Addr)+' not in dmem!'); + end; + + //Writeln('0x',HexStr(ri.key.Addr),'->0x',HexStr(addr,16)); + + size:=GetLinearSize(ri,true); + + buf:=FetchHostBuffer(CmdBuffer, + addr, + size, + ord(VK_BUFFER_USAGE_TRANSFER_DST_BIT)); + + offset:=buf.FAddr-addr; + + vkBufferMemoryBarrier(CmdBuffer.FCmdbuf, + buf.FHandle, + ord(VK_ACCESS_MEMORY_READ_BIT), + ord(VK_ACCESS_TRANSFER_WRITE_BIT), + offset, + size, + ord(VK_PIPELINE_STAGE_HOST_BIT), + ord(VK_PIPELINE_STAGE_TRANSFER_BIT) + ); + + BufferImageCopy:=Default(TVkBufferImageCopy); + + BufferImageCopy.bufferOffset :=offset; + BufferImageCopy.bufferRowLength :=0; + BufferImageCopy.bufferImageHeight:=0; + BufferImageCopy.imageSubresource :=ri.GetSubresLayer; + BufferImageCopy.imageExtent.Create(ri.key.params.width, + ri.key.params.height, + ri.key.params.depth); + + if true {align} then + begin + BufferImageCopy.bufferRowLength:=GetAlignWidth(ri.key.cformat,ri.key.params.width); + end; + + vkCmdCopyImageToBuffer(CmdBuffer.FCmdbuf, + ri.FHandle, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + buf.FHandle, + 1, + @BufferImageCopy); + + end; + + //write back + + if (CmdBuffer.QueueSubmit<>VK_SUCCESS) then + begin + Assert(false,'QueueSubmit'); + end; + + r:=CmdBuffer.Wait(QWORD(-1)); + + Writeln('CmdBuffer:',r); + writeln; + + CmdBuffer.ReleaseResource; + + CmdBuffer.Free; +end; + +procedure pm4_EventWriteEop(node:p_pm4_node_EventWriteEop); +begin + + Case node^.dataSel of + // + EVENTWRITEEOP_DATA_SEL_DISCARD :; + EVENTWRITEEOP_DATA_SEL_SEND_DATA32 :PDWORD(node^.addr)^:=node^.data; + EVENTWRITEEOP_DATA_SEL_SEND_DATA64 :PQWORD(node^.addr)^:=node^.data; + EVENTWRITEEOP_DATA_SEL_SEND_GPU_CLOCK :; //system 100Mhz global clock. + EVENTWRITEEOP_DATA_SEL_SEND_CP_PERFCOUNTER:; //GPU 800Mhz clock. + else; + end; + + //node^.intSel end; procedure pm4_me_thread(me:p_pm4_me); SysV_ABI_CDecl; @@ -284,7 +489,8 @@ begin Writeln('+',node^.ntype); case node^.ntype of - ntDrawIndex2:pm4_DrawIndex2(Pointer(node)); + ntDrawIndex2 :pm4_DrawIndex2 (Pointer(node)); + ntEventWriteEop:pm4_EventWriteEop(Pointer(node)); else end; diff --git a/chip/pm4_pfp.pas b/chip/pm4_pfp.pas index f06a1540..c68ae18b 100644 --- a/chip/pm4_pfp.pas +++ b/chip/pm4_pfp.pas @@ -92,6 +92,7 @@ end; function pm4_ibuf_init(ibuf:p_pm4_ibuffer;buf:PPM4CMDINDIRECTBUFFER;icb:t_pm4_parse_cb):Boolean; var + op:DWORD; ib_base:QWORD; ib_size:QWORD; addr:Pointer; @@ -99,9 +100,22 @@ var begin Result:=False; + op:=buf^.header; + + if ((op<>$c0023300) and (op<>$c0023f00)) then + begin + Assert(false,'init not indirect buffer'); + end; + ib_base:=QWORD(buf^.ibBase); ib_size:=QWORD(buf^.ibSize)*sizeof(DWORD); + case op of + $c0023300:Writeln('INDIRECT_BUFFER (ccb) 0x',HexStr(ib_base,10)); + $c0023f00:Writeln('INDIRECT_BUFFER (dcb) 0x',HexStr(ib_base,10)); + else; + end; + addr:=nil; size:=0; @@ -902,6 +916,7 @@ begin if (Body^.destTcL2<>0) then Exit; //write to L2 + { Case Body^.dataSel of // EVENTWRITEEOP_DATA_SEL_DISCARD :; @@ -911,6 +926,7 @@ begin EVENTWRITEEOP_DATA_SEL_SEND_CP_PERFCOUNTER:; //GPU 800Mhz clock. else; end; + } addr:=nil; size:=0; diff --git a/sys/dev/dev_gc.pas b/sys/dev/dev_gc.pas index d3f5ed30..2d59501d 100644 --- a/sys/dev/dev_gc.pas +++ b/sys/dev/dev_gc.pas @@ -207,10 +207,10 @@ begin end; - pm4_me_gfx.Push(pfp_ctx.stream_dcb); pm4_me_gfx.Push(pfp_ctx.stream_ccb); + pm4_me_gfx.Push(pfp_ctx.stream_dcb); - gc_ring_pm4_drain(@ring_gfx,size-i); + gc_ring_pm4_drain(@ring_gfx,size); end; msleep_td(100); diff --git a/sys/dev/display_soft.pas b/sys/dev/display_soft.pas index 02c276b2..52f8d012 100644 --- a/sys/dev/display_soft.pas +++ b/sys/dev/display_soft.pas @@ -25,6 +25,8 @@ type attr :QWORD; left :Pointer; //buffer ptr right:Pointer; //Stereo ptr + left_dmem :Pointer; //buffer ptr + right_dmem:Pointer; //Stereo ptr end; PQNode=^TQNode; @@ -202,6 +204,8 @@ var left :Pointer; right:Pointer; + left_dmem :Pointer; + right_dmem:Pointer; begin i:=buf^.index; a:=buf^.attrid; @@ -214,8 +218,11 @@ begin if (left=nil) then Exit(EINVAL); +left_dmem :=nil; +right_dmem:=nil; + //TODO: check size! - if not get_dmem_ptr(left,@left,nil) then + if not get_dmem_ptr(left,@left_dmem,nil) then begin Exit(EINVAL); end; @@ -223,7 +230,7 @@ begin if (right<>nil) then begin //TODO: check size! - if not get_dmem_ptr(right,@right,nil) then + if not get_dmem_ptr(right,@right_dmem,nil) then begin Exit(EINVAL); end; @@ -233,6 +240,9 @@ begin m_bufs[i].attr :=a; m_bufs[i].left :=left; m_bufs[i].right:=right; + m_bufs[i].left_dmem :=left_dmem; + m_bufs[i].right_dmem:=right_dmem; + Result:=0; end; @@ -506,13 +516,13 @@ begin dst:=p_dst^; - //detile32bppBuf_slow(attr,bi.bmiHeader.biWidth,buf^.left,dst); - detile32bppBuf_AVX(attr,bi.bmiHeader.biWidth,buf^.left,dst); + //detile32bppBuf_slow(attr,bi.bmiHeader.biWidth,buf^.left_dmem,dst); + detile32bppBuf_AVX(attr,bi.bmiHeader.biWidth,buf^.left_dmem,dst); end else begin bi.bmiHeader.biWidth:=(bi.bmiHeader.biWidth+63) and (not 63); - dst:=buf^.left; + dst:=buf^.left_dmem; end; //flip @@ -539,7 +549,7 @@ begin attr^.attr.width, attr^.attr.height, 0, 0, 0, attr^.attr.height, - buf^.left, bi, DIB_RGB_COLORS); + buf^.left_dmem, bi, DIB_RGB_COLORS); } ReleaseDC(hWindow, hdc); diff --git a/vulkan/vCmdBuffer.pas b/vulkan/vCmdBuffer.pas index 3365958c..0a3f26ca 100644 --- a/vulkan/vCmdBuffer.pas +++ b/vulkan/vCmdBuffer.pas @@ -16,7 +16,7 @@ uses vDevice, vMemory, //vShader, - //vShaderExt, + vShaderExt, vImage, vPipeline, //vSetsPools, @@ -74,7 +74,8 @@ type Function IsRenderPass:Boolean; Procedure EndRenderPass; - function QueueSubmit:Boolean; + function QueueSubmit:TVkResult; + function Wait(timeout:TVkUInt64):TVkResult; Procedure ReleaseResource; Procedure AddWaitSemaphore(S:TvSemaphore;W:TVkPipelineStageFlags); @@ -85,6 +86,8 @@ type Procedure PushConstant(BindPoint:TVkPipelineBindPoint;stageFlags:TVkShaderStageFlags;offset,size:TVkUInt32;const pValues:PVkVoid); Procedure DispatchDirect(X,Y,Z:TVkUInt32); + Procedure SetVertexInput(const FAttrBuilder:TvAttrBuilder); + Procedure BindVertexBuffer(Binding:TVkUInt32; Buffer:TVkBuffer; Offset:TVkDeviceSize); @@ -152,6 +155,7 @@ begin if (FCmdbuf=VK_NULL_HANDLE) then Exit; FFence:=TvFence.Create(true); + FFence.Reset; FSignalSemaphore:=TvSemaphore.Create; @@ -251,6 +255,7 @@ end; function TvCmdBuffer.BeginRenderPass(RT:TvRenderTargets):Boolean; var info:TVkRenderPassBeginInfo; + info2:TVkRenderPassAttachmentBeginInfo; begin Result:=False; @@ -267,7 +272,7 @@ begin if (RT.FFramebuffer=nil) then Exit; //if (not RT.FRenderPass.Compile) then Exit; - if (not RT.FPipeline.Compile) then Exit; + //if (not RT.FPipeline.Compile) then Exit; //if (not RT.FFramebuffer.Compile) then Exit; if (RT.FRenderPass.FHandle=FRenderPass) then Exit(True); @@ -277,6 +282,9 @@ begin EndRenderPass; info:=RT.GetInfo; + info2:=RT.GetInfo2; + + info.pNext:=@info2; FCurrPipeline[0]:=RT.FPipeline.FHandle; FCurrLayout [0]:=RT.FPipeline.Key.FShaderGroup.FLayout.FHandle; @@ -333,9 +341,8 @@ begin Result:=True; end; -function TvCustomCmdBuffer.QueueSubmit:Boolean; +function TvCustomCmdBuffer.QueueSubmit:TVkResult; var - r:TVkResult; info:TVkSubmitInfo; FFenceHandle:TVkFence; @@ -346,7 +353,8 @@ var i:Integer; t:TvSemaphoreWaitSet.Iterator; begin - Result:=False; + Result:=VK_ERROR_UNKNOWN; + if (Self=nil) then Exit; if (FCmdbuf=VK_NULL_HANDLE) then Exit; @@ -392,16 +400,24 @@ begin FFenceHandle:=FFence.FHandle; end; - r:=FQueue.Submit(1,@info,FFenceHandle); + Result:=FQueue.Submit(1,@info,FFenceHandle); - ret:=Integer(r); - if (r<>VK_SUCCESS) then + ret:=Integer(Result); + if (Result<>VK_SUCCESS) then begin - Writeln(StdErr,'vkQueueSubmit:',r); - exit; + Writeln(StdErr,'vkQueueSubmit:',Result); end; - Result:=True; +end; + +function TvCustomCmdBuffer.Wait(timeout:TVkUInt64):TVkResult; +begin + Result:=VK_ERROR_UNKNOWN; + + if (Self=nil) then Exit; + if (FFence=nil) then Exit; + + Result:=FFence.Wait(timeout); end; Procedure TvCustomCmdBuffer.ReleaseResource; @@ -496,6 +512,30 @@ begin vkCmdDispatch(FCmdbuf,X,Y,Z); end; +Procedure TvCustomCmdBuffer.SetVertexInput(const FAttrBuilder:TvAttrBuilder); +var + input:TvVertexInputEXT; +begin + if (Self=nil) then Exit; + + if not limits.VK_EXT_vertex_input_dynamic_state then Exit; + + if (not BeginCmdBuffer) then Exit; + + FAttrBuilder.Export2(input); + + if (vkCmdSetVertexInputEXT=nil) then + begin + TPFN_vkVoidFunction(vkCmdSetVertexInputEXT):=vkGetInstanceProcAddr(VulkanApp.FInstance,'vkCmdSetVertexInputEXT'); + end; + + vkCmdSetVertexInputEXT(FCmdbuf, + input.vertexBindingDescriptionCount, + @input.VertexBindingDescriptions[0], + input.vertexAttributeDescriptionCount, + @input.VertexAttributeDescriptions[0]); +end; + Procedure TvCustomCmdBuffer.BindVertexBuffer(Binding:TVkUInt32; Buffer:TVkBuffer; Offset:TVkDeviceSize); diff --git a/vulkan/vDevice.pas b/vulkan/vDevice.pas index 1635baf0..3d727674 100644 --- a/vulkan/vDevice.pas +++ b/vulkan/vDevice.pas @@ -1569,6 +1569,7 @@ begin end; Result:=LoadVulkanLibrary; + if Result then begin Result:=LoadVulkanGlobalCommands; @@ -1611,16 +1612,6 @@ begin FillDeviceExtension(VulkanApp.FPhysicalDevice); FillDeviceProperties(VulkanApp.FPhysicalDevice); - if not limits.VK_KHR_swapchain then - begin - raise Exception.Create('VK_KHR_swapchain not support!'); - end; - - if not limits.VK_EXT_external_memory_host then - begin - raise Exception.Create('VK_EXT_external_memory_host not support!'); - end; - DeviceInfo:=TvDeviceCreateInfo.Create; if (VulkanApp.FGFamilyCount>1) then @@ -1636,10 +1627,24 @@ begin DeviceInfo.add_queue(VulkanApp.FGFamily,@FlipQueue .FHandle); end; - DeviceInfo.add_ext(VK_KHR_SWAPCHAIN_EXTENSION_NAME); + if limits.VK_KHR_swapchain then + begin + DeviceInfo.add_ext(VK_KHR_SWAPCHAIN_EXTENSION_NAME); + end else + begin + Writeln(stderr,'VK_KHR_swapchain not support!'); + //raise Exception.Create('VK_KHR_swapchain not support!'); + end; - DeviceInfo.add_ext(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME); - DeviceInfo.add_ext(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME); + if limits.VK_EXT_external_memory_host then + begin + DeviceInfo.add_ext(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME); + DeviceInfo.add_ext(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME); + end else + begin + Writeln(stderr,'VK_EXT_external_memory_host not support!'); + //raise Exception.Create('VK_EXT_external_memory_host not support!'); + end; if limits.VK_AMD_device_coherent_memory then begin diff --git a/vulkan/vHostBufferManager.pas b/vulkan/vHostBufferManager.pas index f58a005e..4dc596ee 100644 --- a/vulkan/vHostBufferManager.pas +++ b/vulkan/vHostBufferManager.pas @@ -106,7 +106,7 @@ begin _repeat: - It:=FHostBufferSet.find(key); + It:=FHostBufferSet.find_be(key); while (It.Item<>nil) do begin diff --git a/vulkan/vImage.pas b/vulkan/vImage.pas index 6f41170e..a1880861 100644 --- a/vulkan/vImage.pas +++ b/vulkan/vImage.pas @@ -905,8 +905,8 @@ begin begin sType :=VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO; pNext :=nil; - flags :=0; - usage :=GET_VK_IMAGE_USAGE_DEFAULT(Key.cformat); + flags :=GET_VK_IMAGE_CREATE_DEFAULT(Key.cformat); + usage :=GET_VK_IMAGE_USAGE_DEFAULT (Key.cformat); width :=Key.params.width; height :=Key.params.height; layerCount :=key.params.arrayLayers; @@ -926,7 +926,7 @@ var imgs:TVkFramebufferAttachmentsCreateInfo; begin Result:=False; - if (FHandle<>VK_NULL_HANDLE) then Exit(True); + if (FHandle<>VK_NULL_HANDLE) then Exit(True); if (Key.FRenderPass=nil) then Exit; if (Key.FRenderPass.FHandle=VK_NULL_HANDLE) then Exit; @@ -1191,6 +1191,8 @@ begin cinfo:=GetImageInfo; cinfo.format:=vkFixFormatSupport(cinfo.format,cinfo.tiling,cinfo.usage); + cinfo.pNext:=@clist; + MUTABLE:=GET_VK_IMAGE_MUTABLE(cinfo.format); clist:=Default(TVkImageFormatListCreateInfo); diff --git a/vulkan/vMemory.pas b/vulkan/vMemory.pas index a0ea2803..f65c4fd7 100644 --- a/vulkan/vMemory.pas +++ b/vulkan/vMemory.pas @@ -281,7 +281,11 @@ begin cinfo.size :=64*1024; cinfo.usage :=ord(VK_BUFFER_USAGE_TRANSFER_SRC_BIT) or ord(VK_BUFFER_USAGE_TRANSFER_DST_BIT); cinfo.sharingMode:=VK_SHARING_MODE_EXCLUSIVE; - cinfo.pNext :=@buf_ext; + + if limits.VK_EXT_external_memory_host then + begin + cinfo.pNext:=@buf_ext; + end; r:=vkCreateBuffer(Device.FHandle,@cinfo,nil,@FHandle); if (r=VK_SUCCESS) then @@ -353,6 +357,8 @@ begin LoadMemoryHeaps; PrintMemoryHeaps; + + TAILQ_INIT(@FHosts); end; function TvMemManager.findMemoryType(Filter:TVkUInt32;prop:TVkMemoryPropertyFlags):Integer; @@ -1071,8 +1077,8 @@ begin node:=TvHostMemory.Create(FHandle,tmp,mtindex,@FProperties.memoryTypes[mtindex]); - node.FStart:=FStart; - node.F__End:=F__End; + node.FStart:=FStart_align; + node.F__End:=F__End_align; node.Acquire; TAILQ_INSERT_HEAD(@FHosts,node,@node.entry); @@ -1121,6 +1127,7 @@ begin ainfo.sType :=VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ainfo.allocationSize :=Size; ainfo.memoryTypeIndex:=mtindex; + // Result:=VK_NULL_HANDLE; r:=vkAllocateMemory(device,@ainfo,nil,@Result); if (r<>VK_SUCCESS) then @@ -1140,10 +1147,12 @@ begin ainfo.allocationSize :=Size; ainfo.memoryTypeIndex:=mtindex; ainfo.pNext:=@import; + // import:=Default(TVkImportMemoryHostPointerInfoEXT); - import.sType:=VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT; - import.handleType:=VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT; + import.sType :=VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT; + import.handleType :=VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT; import.pHostPointer:=adr; + // Result:=VK_NULL_HANDLE; r:=vkAllocateMemory(device,@ainfo,nil,@Result); if (r<>VK_SUCCESS) then diff --git a/vulkan/vPipelineManager.pas b/vulkan/vPipelineManager.pas index 32c8baba..ac2b9e73 100644 --- a/vulkan/vPipelineManager.pas +++ b/vulkan/vPipelineManager.pas @@ -51,7 +51,7 @@ type emulate_primtype:Byte; Procedure Clear; - Procedure SetVertexInput(var FAttrBuilder:TvAttrBuilder); + Procedure SetVertexInput(const FAttrBuilder:TvAttrBuilder); Procedure SetPrimType(t:TVkPrimitiveTopology); Procedure SetPrimReset(enable:TVkBool32); Procedure SetProvoking(t:TVkProvokingVertexModeEXT); @@ -137,7 +137,7 @@ begin DepthStencil.depthCompareOp:=VK_COMPARE_OP_LESS; end; -Procedure TvGraphicsPipelineKey.SetVertexInput(var FAttrBuilder:TvAttrBuilder); +Procedure TvGraphicsPipelineKey.SetVertexInput(const FAttrBuilder:TvAttrBuilder); begin vertexInputInfo.vertexBindingDescriptionCount :=FAttrBuilder.FBindDescsCount; vertexInputInfo.vertexAttributeDescriptionCount:=FAttrBuilder.FAttrDescsCount; @@ -230,8 +230,11 @@ var vertexInputInfo:TVkPipelineVertexInputStateCreateInfo; viewportState :TVkPipelineViewportStateCreateInfo; colorBlending :TVkPipelineColorBlendStateCreateInfo; + dynamicState :TVkPipelineDynamicStateCreateInfo; rasterizer :TVkPipelineRasterizationStateCreateInfo; ProvokingVertex:TVkPipelineRasterizationProvokingVertexStateCreateInfoEXT; + + dynamicStates :array[0..0] of TVkDynamicState; //dynamicState.dynamicStateCount begin Result:=False; @@ -259,8 +262,8 @@ begin vertexInputInfo.sType :=VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vertexInputInfo.vertexBindingDescriptionCount :=Key.vertexInputInfo.vertexBindingDescriptionCount; vertexInputInfo.vertexAttributeDescriptionCount:=Key.vertexInputInfo.vertexAttributeDescriptionCount; - vertexInputInfo.pVertexBindingDescriptions :=@Key.vertexInputInfo.VertexBindingDescriptions; - vertexInputInfo.pVertexAttributeDescriptions :=@Key.vertexInputInfo.VertexAttributeDescriptions; + vertexInputInfo.pVertexBindingDescriptions :=@Key.vertexInputInfo.VertexBindingDescriptions[0]; + vertexInputInfo.pVertexAttributeDescriptions :=@Key.vertexInputInfo.VertexAttributeDescriptions[0]; viewportState:=Default(TVkPipelineViewportStateCreateInfo); viewportState.sType :=VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; @@ -276,6 +279,17 @@ begin colorBlending.attachmentCount:=Key.colorBlending.attachmentCount; colorBlending.pAttachments :=@Key.ColorBlends; + dynamicState:=Default(TVkPipelineDynamicStateCreateInfo); + dynamicState.sType:=VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + + if limits.VK_EXT_vertex_input_dynamic_state then + begin + dynamicStates[0]:=VK_DYNAMIC_STATE_VERTEX_INPUT_EXT; + // + dynamicState.dynamicStateCount:=1; + dynamicState.pDynamicStates :=@dynamicStates[0]; + end; + rasterizer:=Key.rasterizer; if limits.VK_EXT_provoking_vertex then @@ -298,7 +312,7 @@ begin info.pMultisampleState :=@Key.multisampling; info.pDepthStencilState :=@Key.DepthStencil; info.pColorBlendState :=@colorBlending; - info.pDynamicState :=nil; + info.pDynamicState :=@dynamicState; info.layout :=Key.FShaderGroup.FLayout.FHandle; info.renderPass :=Key.FRenderPass.FHandle; info.subpass :=0; diff --git a/vulkan/vRegs2Vulkan.pas b/vulkan/vRegs2Vulkan.pas index a6403a25..bab06859 100644 --- a/vulkan/vRegs2Vulkan.pas +++ b/vulkan/vRegs2Vulkan.pas @@ -1208,7 +1208,7 @@ begin Result.rasterizerDiscardEnable:=CX_REG^.DB_SHADER_CONTROL.KILL_ENABLE; Result.polygonMode :=get_polygon_mode(SU_SC_MODE_CNTL); Result.cullMode :=get_cull_mode (SU_SC_MODE_CNTL); - Result.frontFace :=TVkFrontFace (SU_SC_MODE_CNTL.FACE); + Result.frontFace :=TVkFrontFace (SU_SC_MODE_CNTL.FACE); //1:1 Result.lineWidth :=(CX_REG^.PA_SU_LINE_CNTL.WIDTH/8); if (DWORD(CX_REG^.PA_SU_POLY_OFFSET_DB_FMT_CNTL)<>0) then diff --git a/vulkan/vRender.pas b/vulkan/vRender.pas index a2ddb834..66c4a64f 100644 --- a/vulkan/vRender.pas +++ b/vulkan/vRender.pas @@ -90,14 +90,20 @@ type FPipeline :TvGraphicsPipeline2; FFramebuffer:TvFramebuffer; FRenderArea :TVkRect2D; - + // FClearValuesCount:TVkUInt32; FClearValues:array[0..8] of TVkClearValue; // + FImagesCount:TVkUInt32; + FImageViews :AvImageViews; + // FRefs:ptruint; // Procedure AddClearColor(clr:TVkClearValue); + Procedure AddClearColor(clr:TVkClearColorValue); + Procedure AddImageView(v:TvImageView); Function GetInfo:TVkRenderPassBeginInfo; + Function GetInfo2:TVkRenderPassAttachmentBeginInfo; class function c(const a,b:TvRenderTargets):Integer; Destructor Destroy; override; Procedure Acquire(Sender:TObject); @@ -605,6 +611,19 @@ begin Inc(FClearValuesCount); end; +Procedure TvRenderTargets.AddClearColor(clr:TVkClearColorValue); +begin + AddClearColor(TVkClearValue(clr)); +end; + +Procedure TvRenderTargets.AddImageView(v:TvImageView); +begin + if (v=nil) then Exit; + if (FImagesCount>=Length(AvImageViews)) then Exit; + FImageViews[FImagesCount]:=v.FHandle; + Inc(FImagesCount); +end; + Function TvRenderTargets.GetInfo:TVkRenderPassBeginInfo; begin Result:=Default(TVkRenderPassBeginInfo); @@ -612,10 +631,18 @@ begin Result.renderPass :=FRenderPass.FHandle; Result.renderArea :=FRenderArea; Result.clearValueCount:=FClearValuesCount; - Result.pClearValues :=FClearValues; + Result.pClearValues :=@FClearValues[0]; Result.framebuffer :=FFramebuffer.FHandle; end; +Function TvRenderTargets.GetInfo2:TVkRenderPassAttachmentBeginInfo; +begin + Result:=Default(TVkRenderPassAttachmentBeginInfo); + Result.sType :=VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO; + Result.attachmentCount:=FImagesCount; + Result.pAttachments :=@FImageViews[0]; +end; + class function TvRenderTargets.c(const a,b:TvRenderTargets):Integer; begin Result:=CompareByte(a,b,SizeOf(Pointer)); diff --git a/vulkan/vShaderExt.pas b/vulkan/vShaderExt.pas index 61f64e94..77689a03 100644 --- a/vulkan/vShaderExt.pas +++ b/vulkan/vShaderExt.pas @@ -115,9 +115,19 @@ type Function GetSize:TVkUInt32; end; - AvVertexInputBindingDescription =array[0..31] of TVkVertexInputBindingDescription; - AvBindVertexBuffer =array[0..31] of TvBindVertexBuffer; - AvVertexInputAttributeDescription=array[0..31] of TVkVertexInputAttributeDescription; + AvVertexInputBindingDescription =array[0..31] of TVkVertexInputBindingDescription; + AvBindVertexBuffer =array[0..31] of TvBindVertexBuffer; + AvVertexInputAttributeDescription =array[0..31] of TVkVertexInputAttributeDescription; + + AvVertexInputBindingDescription2 =array[0..31] of TVkVertexInputBindingDescription2EXT; + AvVertexInputAttributeDescription2=array[0..31] of TVkVertexInputAttributeDescription2EXT; + + TvVertexInputEXT=record + vertexBindingDescriptionCount :TVkUInt32; + vertexAttributeDescriptionCount:TVkUInt32; + VertexBindingDescriptions :AvVertexInputBindingDescription2; + VertexAttributeDescriptions :AvVertexInputAttributeDescription2; + end; TvAttrBuilder=object const @@ -136,6 +146,7 @@ type procedure PatchAttr(binding,offset:TVkUInt32); Procedure AddVSharp(PV:PVSharpResource4;location:DWord); procedure AddAttr(const v:TvCustomLayout;Fset:TVkUInt32;FData:PDWORD); + Procedure Export2(var input:TvVertexInputEXT); end; TBufBindExt=packed record @@ -669,6 +680,51 @@ begin AddVSharp(PV,v.bind); end; +{ +TvAttrBuilder=object + const + maxVertexInputBindingStride=16383; + maxVertexInputBindings =32; + maxVertexInputAttributes =32; + var + FBindDescsCount:Byte; + FAttrDescsCount:Byte; + FBindDescs:AvVertexInputBindingDescription; + FBindVBufs:AvBindVertexBuffer; + FAttrDescs:AvVertexInputAttributeDescription; +} + +Procedure TvAttrBuilder.Export2(var input:TvVertexInputEXT); +var + i:Byte; +begin + input:=Default(TvVertexInputEXT); + + input.vertexBindingDescriptionCount :=FBindDescsCount; + input.vertexAttributeDescriptionCount:=FAttrDescsCount; + + if (FBindDescsCount<>0) then + For i:=0 to FBindDescsCount-1 do + begin + input.VertexBindingDescriptions[i].sType :=VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT; + input.VertexBindingDescriptions[i].binding :=FBindDescs[i].binding; + input.VertexBindingDescriptions[i].stride :=FBindDescs[i].stride; + input.VertexBindingDescriptions[i].inputRate:=FBindDescs[i].inputRate; + input.VertexBindingDescriptions[i].divisor :=1; + end; + + if (FAttrDescsCount<>0) then + For i:=0 to FAttrDescsCount-1 do + begin + input.VertexAttributeDescriptions[i].sType :=VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT; + input.VertexAttributeDescriptions[i].location:=FAttrDescs[i].location; + input.VertexAttributeDescriptions[i].binding :=FAttrDescs[i].binding; + input.VertexAttributeDescriptions[i].format :=FAttrDescs[i].format; + input.VertexAttributeDescriptions[i].offset :=FAttrDescs[i].offset; + end; + +end; + // Procedure TvUniformBuilder.AddVSharp(PV:PVSharpResource4;fset,bind,offset:DWord);