diff --git a/chip/ps4_gpu_regs.pas b/chip/ps4_gpu_regs.pas index 3f80f277..0924d2c4 100644 --- a/chip/ps4_gpu_regs.pas +++ b/chip/ps4_gpu_regs.pas @@ -409,7 +409,10 @@ function _get_tsharp4_cformat(PT:PTSharpResource4):TVkFormat; function _get_tsharp4_min_lod(PT:PTSharpResource4):TVkImageViewMinLodCreateInfoEXT; function _get_tsharp4_image_info(PT:PTSharpResource4):TvImageKey; +function _get_tsharp8_image_info(PT:PTSharpResource8):TvImageKey; + function _get_tsharp4_image_view(PT:PTSharpResource4):TvImageViewKey; +function _get_tsharp8_image_view(PT:PTSharpResource8):TvImageViewKey; function _get_ssharp_info(PS:PSSharpResource4):TVkSamplerCreateInfo; @@ -1831,12 +1834,12 @@ begin if _img_is_msaa(PT^._type) then begin - Result.params.samples :=PT^.last_level; + Result.params.samples :=PT^.last_level+1; Result.params.mipLevels:=1; end else begin Result.params.samples :=1; - Result.params.mipLevels:=PT^.last_level-PT^.base_level+1; + Result.params.mipLevels:=PT^.last_level+1; end; //Assert(Result.params.mipLevels=1,'TODO'); @@ -1845,6 +1848,29 @@ begin Result.params.arrayLayers:=1; end; +function _get_tsharp8_image_info(PT:PTSharpResource8):TvImageKey; +begin + Result:=_get_tsharp4_image_info(PTSharpResource4(PT)); + // + Case PT^._type of + SQ_RSRC_IMG_3D: + begin + Result.params.extend.depth:=PT^.depth+1; + end; + else; + end; + // + Case PT^._type of + SQ_RSRC_IMG_1D_ARRAY , + SQ_RSRC_IMG_2D_ARRAY , + SQ_RSRC_IMG_2D_MSAA_ARRAY: + begin + Result.params.arrayLayers:=PT^.last_array+1; + end + else; + end; +end; + function _get_dst_sel_swizzle(b:Byte):Byte; begin Case b of @@ -1921,9 +1947,23 @@ begin Result.base_level:=0; ///// Result.last_level:=0; ///// - end; +function _get_tsharp8_image_view(PT:PTSharpResource8):TvImageViewKey; +begin + Result:=_get_tsharp4_image_view(PTSharpResource4(PT)); + // + Case PT^._type of + SQ_RSRC_IMG_1D_ARRAY , + SQ_RSRC_IMG_2D_ARRAY , + SQ_RSRC_IMG_2D_MSAA_ARRAY: + begin + Result.base_array:=PT^.base_array; + Result.last_array:=PT^.last_array; + end + else; + end; +end; function _get_xy_filter(b:Byte):TVkFilter; begin diff --git a/chip/ps4_shader.pas b/chip/ps4_shader.pas index de0119f5..59e2918c 100644 --- a/chip/ps4_shader.pas +++ b/chip/ps4_shader.pas @@ -300,7 +300,7 @@ type pow2pad:bit1; //memory footprint is padded to power of 2 dimensions mtype_L1M:bit1; reserved:bit1; - _type:bit4; //values [8..15] are 1D, 2D, 3D, Cube, 1D array, 2D array, 2D MSAA, 2D MSAA array; 0 is V#, 1-7 reserved + _type:bit4; //values [8..15] are 1D, 2D, 3D, Cube, 1D array, 2D array, 2D MSAA, 2D MSAA array; 0 is V#, 1-7 reserved //32 depth:bit13; //3D texture depth (0..8192) pitch:bit14; //texture pitch in texels (0..16383); defaults to width diff --git a/spirv/emit_mimg.pas b/spirv/emit_mimg.pas index 44810f66..a84e819d 100644 --- a/spirv/emit_mimg.pas +++ b/spirv/emit_mimg.pas @@ -32,8 +32,8 @@ type procedure emit_MIMG; procedure DistribDmask(DMASK:Byte;dst:PsrRegNode;info:PsrImageInfo); function GatherDmask(telem:TsrDataType):PsrRegNode; - Function GatherCoord_f(var offset:DWORD;dim_id:Byte):PsrRegNode; - Function GatherCoord_u(var offset:DWORD;dim_id:Byte):PsrRegNode; + Function GatherCoord_f(var offset:DWORD;info:PsrImageInfo):PsrRegNode; + Function GatherCoord_u(var offset:DWORD;info:PsrImageInfo):PsrRegNode; Function Gather_value(var offset:DWORD;rtype:TsrDataType):PsrRegNode; Function Gather_packed_offset(var offset:DWORD;dim:Byte):PsrRegNode; procedure Gather_sample_param(var p:TImgSampleParam;info:PsrImageInfo); @@ -42,6 +42,7 @@ type procedure emit_image_sample_gather(Tgrp:PsrNode;info:PsrImageInfo); procedure emit_image_load(Tgrp:PsrNode;info:PsrImageInfo); procedure emit_image_store(Tgrp:PsrNode;info:PsrImageInfo); + procedure emit_get_resinfo(Tgrp:PsrNode;info:PsrImageInfo); end; implementation @@ -372,6 +373,7 @@ begin Dim.Dim2D:Result:=2; Dim.Dim3D:Result:=3; Dim.Cube :Result:=3; + else; end; end; @@ -488,8 +490,12 @@ end; procedure TEmit_MIMG.DistribDmask(DMASK:Byte;dst:PsrRegNode;info:PsrImageInfo); //result var pSlot:PsrRegSlot; - i,d:Byte; + dtype:TsrDataType; + i,d,max:Byte; begin + dtype:=dst^.dtype.Child; + max :=dst^.dtype.Count; + d:=0; For i:=0 to 3 do if DMASK.TestBit(i) then @@ -505,11 +511,17 @@ begin MakeCopy(pSlot,dst); end else begin - SetConst_i(pSlot,info^.dtype,0); + SetConst_i(pSlot,dtype,0); end; end else begin - OpExtract(line,pSlot^.New(line,info^.dtype),dst,i); + if (i0) then Inc(count); //slice - if (dim_id=Dim.Cube) then + if (info^.tinfo.Dim=Dim.Cube) then begin //x,y,slice,(face_id+slice*8) @@ -566,6 +578,12 @@ begin src[0]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+0,dtFloat32); //x src[1]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+1,dtFloat32); //y src[2]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+2,dtFloat32); //face + + if (info^.tinfo.Arrayed<>0) then //is array + begin + Inc(count); + src[3]:=NewReg_s(dtFloat32,0); + end; end; Result:=OpMakeCub(line,TsrDataType(dtFloat32).AsVector(count),@src); @@ -578,6 +596,15 @@ begin src[i]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+i,dtFloat32); end; + if (info^.tinfo.Arrayed<>0) and //is array + (FSPI.MIMG.DA=0) then //not slice + begin + i:=count; + Inc(count); + + src[i]:=NewReg_s(dtFloat32,0); + end; + if (count=1) then begin Result:=src[0]; @@ -591,17 +618,17 @@ begin offset:=offset+count; end; -Function TEmit_MIMG.GatherCoord_u(var offset:DWORD;dim_id:Byte):PsrRegNode; //src +Function TEmit_MIMG.GatherCoord_u(var offset:DWORD;info:PsrImageInfo):PsrRegNode; //src var src:array[0..3] of PsrRegNode; i,count:Byte; begin Result:=nil; - count:=GetDimCount(dim_id); + count:=GetDimCount(info^.tinfo.Dim); if (FSPI.MIMG.DA<>0) then Inc(count); //slice - if (dim_id=Dim.Cube) then + if (info^.tinfo.Dim=Dim.Cube) then begin //x,y,slice,(face_id+slice*8) @@ -616,6 +643,12 @@ begin src[0]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+0,dtInt32); //x src[1]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+1,dtInt32); //y src[2]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+2,dtInt32); //face + + if (info^.tinfo.Arrayed<>0) then //is array + begin + Inc(count); + src[3]:=NewReg_i(dtInt32,0); + end; end; Result:=OpMakeCub(line,TsrDataType(dtInt32).AsVector(count),@src); @@ -628,6 +661,15 @@ begin src[i]:=fetch_vsrc8(FSPI.MIMG.VADDR+offset+i,dtInt32); end; + if (info^.tinfo.Arrayed<>0) and //is array + (FSPI.MIMG.DA=0) then //not slice + begin + i:=count; + Inc(count); + + src[i]:=NewReg_i(dtInt32,0); + end; + if (count=1) then begin Result:=src[0]; @@ -695,7 +737,7 @@ begin Assert(false,'TODO imGrad'); end; - p.coord:=GatherCoord_f(p.roffset,info^.tinfo.Dim); + p.coord:=GatherCoord_f(p.roffset,info); if (imLod in p.mods) then begin @@ -894,7 +936,7 @@ begin Case FSPI.MIMG.OP of IMAGE_LOAD: begin - coord:=GatherCoord_u(roffset,info^.tinfo.Dim); + coord:=GatherCoord_u(roffset,info); node:=OpImageFetch(line,Tgrp,dst,coord); if (info^.tinfo.MS<>0) then //fragid T# 2D MSAA @@ -907,7 +949,7 @@ begin end; IMAGE_LOAD_MIP: //All except MSAA begin - coord:=GatherCoord_u(roffset,info^.tinfo.Dim); + coord:=GatherCoord_u(roffset,info); node:=OpImageFetch(line,Tgrp,dst,coord); lod:=Gather_value(roffset,dtUint32); @@ -937,7 +979,7 @@ begin Case FSPI.MIMG.OP of IMAGE_STORE: begin - coord:=GatherCoord_u(roffset,info^.tinfo.Dim); + coord:=GatherCoord_u(roffset,info); node:=OpImageWrite(line,Tgrp,coord,dst); if (info^.tinfo.MS<>0) then //fragid T# 2D MSAA @@ -950,7 +992,7 @@ begin end; IMAGE_STORE_MIP: //All except MSAA begin - coord:=GatherCoord_u(roffset,info^.tinfo.Dim); + coord:=GatherCoord_u(roffset,info); node:=OpImageWrite(line,Tgrp,coord,dst); lod:=Gather_value(roffset,dtUint32); @@ -964,6 +1006,37 @@ begin end; +procedure TEmit_MIMG.emit_get_resinfo(Tgrp:PsrNode;info:PsrImageInfo); +var + offset:DWORD; + dst,lod:PsrRegNode; + + dvec:TsrDataType; + count:Byte; +begin + offset:=0; + lod:=Gather_value(offset,dtUint32); + + count:=1; + Case info^.tinfo.Dim of + Dim.Dim2D:count:=2; + Dim.Cube :count:=2; + Dim.Dim3D:count:=3; + else; + end; + if (info^.tinfo.Arrayed<>0) then Inc(count); + + dvec:=TsrDataType(dtUint32).AsVector(count); + + dst:=NewReg(dvec); + + _Op2(line,Op.OpImageQuerySizeLod,dst,PsrRegNode(Tgrp),lod); + + DistribDmask(FSPI.MIMG.DMASK,dst,info); + + AddCapability(Capability.ImageQuery); +end; + procedure TEmit_MIMG.emit_MIMG; var src:array[0..7] of PsrRegSlot; @@ -977,15 +1050,15 @@ begin pLayout:=nil; Case FSPI.MIMG.R128 of - 0: + 0: //256=8 *4*8 begin if not get_srsrc(FSPI.MIMG.SRSRC,8,@src) then Assert(false); - pLayout:=GroupingSharp(src,rtTSharp4); + pLayout:=GroupingSharp(src,rtTSharp8); end; - 1: + 1: //128=4 *4*8 begin if not get_srsrc(FSPI.MIMG.SRSRC,4,@src) then Assert(false); - pLayout:=GroupingSharp(src,rtTSharp8); + pLayout:=GroupingSharp(src,rtTSharp4); end; end; @@ -1033,6 +1106,14 @@ begin emit_image_store(Tgrp,@info); end; + IMAGE_GET_RESINFO: //get info by mip + begin + info.tinfo.Sampled:=1; + Tgrp:=FetchImage(pLayout,info.dtype,info.tinfo); + + emit_GET_RESINFO(Tgrp,@info); + end; + else Assert(false,'MIMG?'+IntToStr(FSPI.MIMG.OP)); end; diff --git a/vulkan/vImageTiling.pas b/vulkan/vImageTiling.pas index 0b4f49b1..db3c2c3d 100644 --- a/vulkan/vImageTiling.pas +++ b/vulkan/vImageTiling.pas @@ -64,12 +64,12 @@ begin begin extend.width :=(extend.width +3) div 4; extend.height :=(extend.height +3) div 4; - extend.depth :=(extend.depth +3) div 4; end; Result:=extend.width* extend.height* extend.depth* + image.key.params.arrayLayers* getFormatSize(image.key.cformat); end; @@ -274,7 +274,7 @@ var //tp:TilingParameters; tiler:Tiler1d; //mtm:Byte; - size,i,x,y,z:QWORD; + size,i,x,y,z,a:QWORD; m_bytePerElement:Word; m_bitsPerElement:Word; @@ -402,10 +402,7 @@ begin //m_tilesPerRow = m_paddedWidth / kMicroTileWidth; //m_tilesPerSlice = std::max(m_tilesPerRow * (m_paddedHeight / kMicroTileHeight), 1U); - size:=tiler.m_linearWidth* - tiler.m_linearHeight* - tiler.m_linearDepth* - m_bytePerElement; + size:=tiler.m_linearSizeBytes*image.key.params.arrayLayers; buf:=TvTempBuffer.Create(size,ord(VK_BUFFER_USAGE_TRANSFER_SRC_BIT),nil); buf.Fhost:=MemManager.Alloc(buf.GetRequirements,ord(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)); @@ -423,17 +420,18 @@ begin m_slice_size:=(tiler.m_linearWidth*tiler.m_linearHeight); - For z:=0 to tiler.m_linearDepth-1 do - For y:=0 to tiler.m_linearHeight-1 do - For x:=0 to tiler.m_linearWidth-1 do - begin - i:=0; - tiler.getTiledElementBitOffset(i,x,y,z); - i:=i div 8; - pSrc:=@PByte(image.key.Addr)[i]; - pDst:=@PByte(pData)[(z*m_slice_size+y*tiler.m_linearWidth+x)*m_bytePerElement]; - Move(pSrc^,pDst^,m_bytePerElement); - end; + For a:=0 to image.key.params.arrayLayers-1 do + For z:=0 to tiler.m_linearDepth-1 do + For y:=0 to tiler.m_linearHeight-1 do + For x:=0 to tiler.m_linearWidth-1 do + begin + i:=0; + tiler.getTiledElementBitOffset(i,x,y,z); + i:=i div 8; + pSrc:=@PByte(image.key.Addr)[a*tiler.m_tiledSizeBytes+i]; + pDst:=@PByte(pData)[a*tiler.m_linearSizeBytes+(z*m_slice_size+y*tiler.m_linearWidth+x)*m_bytePerElement]; + Move(pSrc^,pDst^,m_bytePerElement); + end; //Move(pData^,image.key.Addr^,size); //FreeMem(pData); diff --git a/vulkan/vShaderExt.pas b/vulkan/vShaderExt.pas index 36048e7e..881d6495 100644 --- a/vulkan/vShaderExt.pas +++ b/vulkan/vShaderExt.pas @@ -169,6 +169,7 @@ type Procedure AddBufPtr(P:Pointer;fset,size,bind,offset:DWord); Procedure AddTSharp4(PT:PTSharpResource4;fset,bind:DWord); + Procedure AddTSharp8(PT:PTSharpResource8;fset,bind:DWord); Procedure AddSSharp4(PS:PSSharpResource4;fset,bind:DWord); procedure AddAttr(const b:TvCustomLayout;Fset:TVkUInt32;FData:PDWORD); end; @@ -695,6 +696,28 @@ begin FImages[i]:=b; end; +Procedure TvUniformBuilder.AddTSharp8(PT:PTSharpResource8;fset,bind:DWord); +var + b:TImageBindExt; + i:Integer; +begin + Assert(PT<>nil); + if (PT=nil) then Exit; + + //print_tsharp8(PT); + + b:=Default(TImageBindExt); + b.fset:=fset; + b.bind:=bind; + + b.FImage:=_get_tsharp8_image_info(PT); + b.FView :=_get_tsharp8_image_view(PT); + + i:=Length(FImages); + SetLength(FImages,i+1); + FImages[i]:=b; +end; + procedure TvUniformBuilder.AddAttr(const b:TvCustomLayout;Fset:TVkUInt32;FData:PDWORD); var P:Pointer; @@ -713,11 +736,7 @@ begin VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: Case b.addr[0].rtype of vtTSharp4:AddTSharp4(P,fset,b.bind); - vtTSharp8: - begin - print_tsharp8(P); - Assert(false); - end; + vtTSharp8:AddTSharp8(P,fset,b.bind); else Assert(false); end;