Float -> UNORM

This commit is contained in:
red-prig 2023-11-07 23:40:48 +03:00
parent 981d350b76
commit 18e08ac658
2 changed files with 42 additions and 2 deletions

View File

@ -127,6 +127,7 @@ type
function OpFMulToS(src0:PsrRegNode;src1:Single;ppLine:PPspirvOp=nil):PsrRegNode;
//
function OpUToF(src:PsrRegNode;rtype:TsrDataType;ppLine:PPspirvOp=nil):PsrRegNode;
function OpFToU(src:PsrRegNode;rtype:TsrDataType;ppLine:PPspirvOp=nil):PsrRegNode;
function OpSToF(src:PsrRegNode;rtype:TsrDataType;ppLine:PPspirvOp=nil):PsrRegNode;
function OpUToU(src:PsrRegNode;rtype:TsrDataType;ppLine:PPspirvOp=nil):PsrRegNode;
function OpSToS(src:PsrRegNode;rtype:TsrDataType;ppLine:PPspirvOp=nil):PsrRegNode;
@ -1210,6 +1211,14 @@ begin
_Op1(_get_line(ppLine),Op.OpConvertUToF,Result,src);
end;
function TEmitOp.OpFToU(src:PsrRegNode;rtype:TsrDataType;ppLine:PPspirvOp=nil):PsrRegNode;
begin
if (src=nil) then Exit(src);
Result:=NewReg(rtype);
_Op1(_get_line(ppLine),Op.OpConvertFToU,Result,src);
end;
function TEmitOp.OpSToF(src:PsrRegNode;rtype:TsrDataType;ppLine:PPspirvOp=nil):PsrRegNode;
begin
if (src=nil) then Exit(src);

View File

@ -104,15 +104,46 @@ begin
end;
end;
if (lc.elem_resl<>lc.elem_orig) then
begin
case lc.elem_resl of
dtFloat32: //isScalar
begin
Case lc.info.NFMT of
BUF_NUM_FORMAT_UNORM:
begin
For i:=0 to lc.elem_count-1 do
begin
lc.elm[i]:=OpFMulToS(lc.elm[i],255);
lc.elm[i]:=OpFToU(lc.elm[i],lc.elem_orig);
end;
end;
else
Assert(false,'TODO CONVERT');
end;
end;
dtUint32,
dtInt32 : //isInt
begin
Assert(false,'TODO CONVERT');
end;
else
Assert(False);
end;
end;
Case lc.elem_count of
1:rsl:=lc.elm[0];
else
begin
rsl:=OpMakeVec(line,lc.elem_resl.AsVector(lc.elem_count),@lc.elm);
rsl:=OpMakeVec(line,lc.elem_orig.AsVector(lc.elem_count),@lc.elm);
//rsl:=OpMakeVec(line,lc.elem_resl.AsVector(lc.elem_count),@lc.elm);
end;
end;
Assert(lc.elem_resl=lc.elem_orig,'TODO CONVERT');
//Assert(lc.elem_resl=lc.elem_orig,'TODO CONVERT');
csize:=Min(lc.info.GetElemSize*lc.elem_count,lc.info.GetSizeFormat);
orig:=lc.v.data[0];