flat assembler
Message board for the users of flat assembler.

Index > Programming Language Design > [fasmg] type checking

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 3307
Location: vpcmipstrm
bitRAKE
Code:
if ~ defined SPIRV
define SPIRV
redefine SPIRV SPIRV
namespace SPIRV

element Capability
iterate n, Matrix,Shader,Geometry,Tessellation,Addresses,Linkage,Kernel,\
  Vector16,Float16Buffer,Float16,Float64,Int64,Int64Atomics,ImageBasic,\
  ImageReadWrite,ImageMipmap ; <truncated>

  element Capability.n: Capability + % - 1
end iterate

;calminstruction(id) enum type,name
struc(id) enum type,name
if defined SPIRV.type.name
        id = 1 metadataof SPIRV.type.name - 1 elementof (1 metadataof SPIRV.type.name)
else
        err `name, " not of type ", `type
end if
end struc

end namespace ; SPIRV

macro OpCapability C
        local id
        dw 17,2
        id SPIRV.enum Capability,C
        dd id
end macro

end if

OpCapability Shader
OpCapability GroupNonUniformArithmetic    
Not knowing if the names would collide with later names, I'm aiming for maximum isolation of enumerations.

SPIR-V reference.

_________________
¯\(°_o)/¯ unlicense.org
Post 21 Mar 2021, 22:43
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1081
Roman
O! Vulkan API
Post 23 Mar 2021, 05:45
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3307
Location: vpcmipstrm
bitRAKE
I'm reading through the spec and trying to implement all the error conditions specified.
Code:
struc(base) ENUM line& ; define enum group
        element base
        iterate L,line
                match name==id,L
                        element base.name : base + id
                else
                        err "translation failure"
                end match
        end iterate
end struc    
It's about 100 lines of code to encapsulate all the internal constants. Implementing all the rules and relationships will take me a while. The type system can be generalize in the above way, but some error check should be done for other terms in the linear polynomial.

If no error checking is desired instructions can be coded quite quickly:
Code:
; instructions requiring no parameters (size 1)
iterate <op,N>,\
        OpNop,0,\
        OpFunctionEnd,56,\
        OpEmitVertex,218,\; Geometry, (IGNORED) requires only one stream present
        OpEndPrimitive,219,\; Geometry, (IGNORED) requires only one stream present
        OpKill,252,\; (IGNORED) only valid in Fragment Execution Model
        OpReturn,253,\; (IGNORED) return type must be void, and last instruction in block
        OpUnreachable,255,\
        OpNoLine,317,\
        \; RESERVED:
        OpTerminateInvocation,4416,\
        OpIgnoreIntersectionKHR,4448,\
        OpTerminateRayKHR,4449,\
        OpIgnoreIntersectionNV,5335,\
        OpTerminateRayNV,5336,\
        OpBeginInvocationInterlockEXT,5364,\
        OpEndInvocationInterlockEXT,5365,\
        OpDemoteToHelperInvocationEXT,5380
macro op
dw N,1
end macro
end iterate


; instructions selecting from an enum group (size 2):
iterate <op,N,group>,\
        OpCapability,17,Capability
macro op G
        dw N,2
        SPIRV.enum_out group,G
end macro
end iterate


; instructions requiring only a string parameter (size 2+)
iterate <op,N>,\
        OpSourceContinued,2,\; (IGNORED) OpSourceContinued requires previous instruction to be OpSourceContinued or OpSource
        OpSourceExtension,4,\
        OpExtension,10,\
        OpModuleProcessed,330
macro op line&
local start,words
start:
dw N,words
SPIRV.string line
words := ($ - start) shr 2
end macro
end iterate    
Presently, I think types and a LastInstr parameter is sufficient to implement all the error checking - without adding branches to every instruction definition.
Post 23 Mar 2021, 15:18
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3307
Location: vpcmipstrm
bitRAKE
Once we can code SPIR-V along side x86, it becomes easier to adapt shaders to the hardware instead of being limit to a static execution model on the GPU.

https://github.com/Erkaman/vulkan_minimal_compute/blob/master/src/main.cpp

_________________
¯\(°_o)/¯ unlicense.org
Post 24 Mar 2021, 15:50
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.