Vulkan backend (#2518)

* WIP Vulkan implementation

* No need to initialize attributes on the SPIR-V backend anymore

* Allow multithreading shaderc and vkCreateShaderModule

You'll only really see the benefit here with threaded-gal or parallel shader cache compile.

Fix shaderc multithreaded changes

Thread safety for shaderc Options constructor

Dunno how they managed to make a constructor not thread safe, but you do you. May avoid some freezes.

* Support multiple levels/layers for blit.

Fixes MK8D when scaled, maybe a few other games. AMD software "safe" blit not supported right now.

* TextureStorage should hold a ref of the foreign storage, otherwise it might be freed while in use

* New depth-stencil blit method for AMD

* Workaround for AMD driver bug

* Fix some tessellation related issues (still doesn't work?)

* Submit command buffer before Texture GetData. (UE4 fix)

* DrawTexture support

* Fix BGRA on OpenGL backend

* Fix rebase build break

* Support format aliasing on SetImage

* Fix uniform buffers being lost when bindings are out of order

* Fix storage buffers being lost when bindings are out of order

(also avoid allocations when changing bindings)

* Use current command buffer for unscaled copy (perf)

Avoids flushing commands and renting a command buffer when fulfilling copy dependencies and when games do unscaled copies.

* Update to .net6

* Update Silk.NET to version 2.10.1

Somehow, massive performance boost. Seems like their vtable for looking up vulkan methods was really slow before.

* Fix PrimitivesGenerated query, disable Transform Feedback queries for now

Lets Splatoon 2 work on nvidia. (mostly)

* Update counter queue to be similar to the OGL one

Fixes softlocks when games had to flush counters.

* Don't throw when ending conditional rendering for now

This should be re-enabled when conditional rendering is enabled on nvidia etc.

* Update findMSB/findLSB to match master's instruction enum

* Fix triangle overlay on SMO, Captain Toad, maybe others?

* Don't make Intel Mesa pay for Intel Windows bugs

* Fix samplers with MinFilter Linear or Nearest (fixes New Super Mario Bros U Deluxe black borders)

* Update Spv.Generator

* Add alpha test emulation on shader (but no shader specialisation yet...)

* Fix R4G4B4A4Unorm texture format permutation

* Validation layers should be enabled for any log level other than None

* Add barriers around vkCmdCopyImage

Write->Read barrier for src image (we want to wait for a write to read it)
Write->Read barrier for dst image (we want to wait for the copy to complete before use)

* Be a bit more careful with texture access flags, since it can be used for anything

* Device local mapping for all buffers

May avoid issues with drivers with NVIDIA on linux/older gpus on windows when using large buffers (?)
Also some performance things and fixes issues with opengl games loading textures weird.

* Cleanup, disable device local buffers for now.

* Add single queue support

Multiqueue seems to be a bit more responsive on NVIDIA. Should fix texture flush on intel. AMD has been forced to single queue for an experiment.

* Fix some validation errors around extended dynamic state

* Remove Intel bug workaround, it was fixed on the latest driver

* Use circular queue for checking consumption on command buffers

Speeds up games that spam command buffers a little. Avoids checking multiple command buffers if multiple are active at once.

* Use SupportBufferUpdater, add single layer flush

* Fix counter queue leak when game decides to use host conditional rendering

* Force device local storage for textures (fixes linux performance)

* Port #3019

* Insert barriers around vkCmdBlitImage (may fix some amd flicker)

* Fix transform feedback on Intel, gl_Position feedback and clears to inexistent depth buffers

* Don't pause transform feedback for multi draw

* Fix draw outside of render pass and missing capability

* Workaround for wrong last attribute on AMD (affects FFVII, STRIKERS1945, probably more)

* Better workaround for AMD vertex buffer size alignment issue

* More instructions + fixes on SPIR-V backend

* Allow custom aspect ratio on Vulkan

* Correct GTK UI status bar positions

* SPIR-V: Functions must always end with a return

* SPIR-V: Fix ImageQuerySizeLod

* SPIR-V: Set DepthReplacing execution mode when FragDepth is modified

* SPIR-V: Implement LoopContinue IR instruction

* SPIR-V: Geometry shader support

* SPIR-V: Use correct binding number on storage buffers array

* Reduce allocations for Spir-v serialization

Passes BinaryWriter instead of the stream to Write and WriteOperand

- Removes creation of BinaryWriter for each instruction
- Removes allocations for literal string

* Some optimizations to Spv.Generator

- Dictionary for lookups of type declarations, constants, extinst
- LiteralInteger internal data format -> ushort
- Deterministic HashCode implementation to avoid spirv result not being the same between runs
- Inline operand list instead of List<T>, falls back to array if many operands. (large performance boost)

TODO: improve instruction allocation, structured program creator, ssa?

* Pool Spv.Generator resources, cache delegates, spv opts

- Pools for Instructions and LiteralIntegers. Can be passed in when creating the generator module.
  - NewInstruction is called instead of new Instruction()
  - Ryujinx SpirvGenerator passes in some pools that are static. The idea is for these to be shared between threads eventually.
- Estimate code size when creating the output MemoryStream
- LiteralInteger pools using ThreadStatic pools that are initialized before and after creation... not sure of a better way since the way these are created is via implicit cast.

Also, cache delegates for Spv.Generator for functions that are passed around to GenerateBinary etc, since passing the function raw creates a delegate on each call.

TODO: update python spv cs generator to make the coregrammar with NewInstruction and the `params` overloads.

* LocalDefMap for Ssa Rewriter

Rather than allocating a large array of all registers for each block in the shader, allocate one array of all registers and clear it between blocks. Reduces allocations in the shader translator.

* SPIR-V: Transform feedback support

* SPIR-V: Fragment shader interlock support (and image coherency)

* SPIR-V: Add early fragment tests support

* SPIR-V: Implement SwizzleAdd, add missing Triangles ExecutionMode for geometry shaders, remove SamplerType field from TextureMeta

* Don't pass depth clip state right now (fix decals)

Explicitly disabling it is incorrect. OpenGL currently automatically disables based on depth clamp, which is the behaviour if this state is omitted.

* Multisampling support

* Multisampling: Use resolve if src samples count > dst samples count

* Multisampling: We can only resolve for unscaled copies

* SPIR-V: Only add FSI exec mode if used.

* SPIR-V: Use ConstantComposite for Texture Offset Vector

Fixes a bunch of freezes with SPIR-V on AMD hardware, and validation errors. Note: Obviously assumes input offsets are constant, which they currently are.

* SPIR-V: Don't OpReturn if we already OpExit'ed

Fixes spir-v parse failure and stack smashing in RADV (obviously you still need bolist)

* SPIR-V: Only use input attribute type for input attributes

Output vertex attributes should always be of type float.

* Multithreaded Pipeline Compilation

* Address some feedback

* Make this 32

* Update topology with GpuAccessorState

* Cleanup for merge (note: disables spir-v)

* Make more robust to shader compilation failure

- Don't freeze when GLSL compilation fails
- Background SPIR-V pipeline compile failure results in skipped draws, similar to GLSL compilation failure.

* Fix Multisampling

* Only update fragment scale count if a vertex texture needs a scale.

Fixes a performance regression introduced by texture scaling in the vertex stage where support buffer updates would be very frequent, even at 1x, if any textures were used on the vertex stage.

This check doesn't exactly look cheap (a flag in the shader stage would probably be preferred), but it is much cheaper than uploading scales in both vulkan and opengl, so it will do for now.

* Use a bitmap to do granular tracking for buffer uploads.

This path is only taken if the much faster check of "is the buffer rented at all" is triggered, so it doesn't actually end up costing too much, and the time saved by not ending render passes (and on gpu for not waiting on barriers) is probably helpful.

Avoids ending render passes to update buffer data (not all the time)
- 140-180 to 35-45 in SMO metro kingdom (these updates are in the UI)
- Very variable 60-150(!) to 16-25 in mario kart 8 (these updates are in the UI)

As well as allowing more data to be preloaded persistently, this will also allow more data to be loaded in the preload buffer, which should be faster as it doesn't need to insert barriers between draws. (and on tbdr, does not need to flush and reload tile memory)

Improves performance in GPU limited scenarios. Should notably improve performance on TBDR gpus. Still a lot more to do here.

* Copy query results after RP ends, rather than ending to copy

We need to end the render pass to get the data (submit command buffer) anyways...

Reduces render passes created in games that use queries.

* Rework Query stuff a bit to avoid render pass end

Tries to reset returned queries in background when possible, rather than ending the render pass.

Still ends render pass when resetting a counter after draws, but maybe that can be solved too. (by just pulling an empty object off the pool?)

* Remove unnecessary lines

Was for testing

* Fix validation error for query reset

Need to think of a better way to do this.

* SPIR-V: Fix SwizzleAdd and some validation errors

* SPIR-V: Implement attribute indexing and StoreAttribute

* SPIR-V: Fix TextureSize for MS and Buffer sampler types

* Fix relaunch issues

* SPIR-V: Implement LogicalExclusiveOr

* SPIR-V: Constant buffer indexing support

* Ignore unsupported attributes rather than throwing (matches current GLSL behaviour)

* SPIR-V: Implement tessellation support

* SPIR-V: Geometry shader passthrough support

* SPIR-V: Implement StoreShader8/16 and StoreStorage8/16

* SPIR-V: Resolution scale support and fix TextureSample multisample with LOD bug

* SPIR-V: Fix field index for scale count

* SPIR-V: Fix another case of wrong field index

* SPIRV/GLSL: More scaling related fixes

* SPIR-V: Fix ImageLoad CompositeExtract component type

* SPIR-V: Workaround for Intel FrontFacing bug

* Enable SPIR-V backend by default

* Allow null samplers (samplers are not required when only using texelFetch to access the texture)

* Fix some validation errors related to texel block view usage flag and invalid image barrier base level

* Use explicit subgroup size if we can (might fix some block flickering on AMD)

* Take componentMask and scissor into account when clearing framebuffer attachments

* Add missing barriers around CmdFillBuffer (fixes Monster Hunter Rise flickering on NVIDIA)

* Use ClampToEdge for Clamp sampler address mode on Vulkan (fixes Hollow Knight)

Clamp is unsupported on Vulkan, but ClampToEdge behaves almost the same. ClampToBorder on the other hand (which was being used before) is pretty different

* Shader specialization for new Vulkan required state (fixes remaining alpha test issues, vertex stretching on AMD on Crash Bandicoot, etc)

* Check if the subgroup size is supported before passing a explicit size

* Only enable ShaderFloat64 if the GPU supports it

* We don't need to recompile shaders if alpha test state changed but alpha test is disabled

* Enable shader cache on Vulkan and implement MultiplyHighS32/U32 on SPIR-V (missed those before)

* Fix pipeline state saving before it is updated.

This should fix a few warnings and potential stutters due to bad pipeline states being saved in the cache. You may need to clear your guest cache.

* Allow null samplers on OpenGL backend

* _unit0Sampler should be set only for binding 0

* Remove unused PipelineConverter format variable (was causing IOR)

* Raise textures limit to 64 on Vulkan

* No need to pack the shader binaries if shader cache is disabled

* Fix backbuffer not being cleared and scissor not being re-enabled on OpenGL

* Do not clear unbound framebuffer color attachments

* Geometry shader passthrough emulation

* Consolidate UpdateDepthMode and GetDepthMode implementation

* Fix A1B5G5R5 texture format and support R4G4 on Vulkan

* Add barrier before use of some modified images

* Report 32 bit query result on AMD windows (smo issue)

* Add texture recompression support (disabled for now)

It recompresses ASTC textures into BC7, which might reduce VRAM usage significantly on games that uses ASTC textures

* Do not report R4G4 format as supported on Vulkan

It was causing mario head to become white on Super Mario 64 (???)

* Improvements to -1 to 1 depth mode.

- Transformation is only applied on the last stage in the vertex pipeline.
- Should fix some issues with geometry and tessellation (hopefully)
- Reading back FragCoord Z on fragment will transform back to -1 to 1.

* Geometry Shader index count from ThreadsPerInputPrimitive

Generally fixes SPIR-V emitting too many triangles, may change games in OpenGL

* Remove gl_FragDepth scaling

This is always 0-1; the other two issues were causing the problems. Fixes regression with Xenoblade.

* Add Gl StencilOp enum values to Vulkan

* Update guest cache to v1.1 (due to specialization state changes)

This will explode your shader cache from earlier vulkan build, but it must be done. 😔

* Vulkan/SPIR-V support for viewport inverse

* Fix typo

* Don't create query pools for unsupported query types

* Return of the Vector Indexing Bug

One day, everyone will get this right.

* Check for transform feedback query support

Sometimes transform feedback is supported without the query type.

* Fix gl_FragCoord.z transformation

FragCoord.z is always in 0-1, even when the real depth range is -1 to 1. Turns out the only bug was geo and tess stage outputs.

Fixes Pokemon Sword/Shield, possibly others.

* Fix Avalonia Rebase

Vulkan is currently not available on Avalonia, but the build does work and you can use opengl.

* Fix headless build

* Add support for BC6 and BC7 decompression, decompress all BC formats if they are not supported by the host

* Fix BCn 4/5 conversion, GetTextureTarget

BCn 4/5 could generate invalid data when a line's size in bytes was not divisible by 4, which both backends expect.

GetTextureTarget was not creating a view with the replacement format.

* Fix dependency

* Fix inverse viewport transform vector type on SPIR-V

* Do not require null descriptors support

* If MultiViewport is not supported, do not try to set more than one viewport/scissor

* Bounds check on bitmap add.

* Flush queries on attachment change rather than program change

Occlusion queries are usually used in a depth only pass so the attachments changing is a better indication of the query block ending.

Write mask changes are also considered since some games do depth only pass by setting 0 write mask on all the colour targets.

* Add support for avalonia (#6)

* add avalonia support

* only lock around skia flush

* addressed review

* cleanup

* add fallback size if avalonia attempts to render but the window size is 0. read desktop scale after enabling dpi check

* fix getting window handle on linux. skip render is size is 0

* Combine non-buffer with buffer image descriptor sets

* Support multisample texture copy with automatic resolve on Vulkan

* Remove old CompileShader methods from the Vulkan backend

* Add minimal pipeline layouts that only contains used bindings

They are used by helper shaders, the intention is avoiding needing to recompile the shaders (from GLSL to SPIR-V) if the bindings changes on the translated guest shaders

* Pre-compile helper shader as SPIR-V, and some fixes

* Remove pre-compiled shaderc binary for Windows as its no longer needed by default

* Workaround RADV crash

Enabling the descriptor indexing extension, even if it is not used, forces the radv driver to use "bolist".

* Use RobustBufferAccess on NVIDIA gpus

Avoids the SMO waterfall triangle on older NVIDIA gpus.

* Implement GPU selector and expose texture recompression on the UI and config

* Fix and enable background compute shader compilation

Also disables warnings from shader cache pipeline misses.

* Fix error due to missing subpass dependency when Attachment Write -> Shader Read barriers are added

* If S8D24 is not supported, use D32FS8

* Ensure all fences are destroyed on dispose

* Pre-allocate arrays up front on DescriptorSetUpdater, allows the removal of some checks

* Add missing clear layer parameter after rebase

* Use selected gpu from config for avalonia (#7)

* use configured device

* address review

* Fix D32S8 copy workaround (AMD)

Fixes water in Pokemon Legends Arceus on AMD GPUs. Possibly fixes other things.

* Use push descriptors for uniform buffer updates (disabled for now)

* Push descriptor support check, buffer redundancy checks

Should make push descriptors faster, needs more testing though.

* Increase light command buffer pool to 2 command buffers, throw rather than returning invalid cbs

* Adjust bindings array sizes

* Force submit command buffers if memory in use by its resources is high

* Add workaround for AMD GCN cubemap view sins

`ImageCreateCubeCompatibleBit` seems to generally break 2D array textures with mipmaps... even if they are eventually aliased as a cubemap with mipmaps. Forcing a copy here works around the issue.

This could be used in future if enabling this bit reduces performance on certain GPUs. (mobile class is generally a worry)

Currently also enabled on Linux as I don't know if they managed to dodge this bug (someone please tell me). Not enabled on Vega at the moment, but easy to add if the issue is there.

* Add mobile, non-RX variants to the GCN regex.

Also make sure that the 3 digit ones only include numbers starting with 7 or 8.

* Increase image limit per stage from 8 to 16

Xenoblade Chronicles 2 was hiting the limit of 8

* Minor code cleanup

* Fix NRE caused by SupportBufferUpdater calling pipeline ClearBuffer

* Add gpu selector to Avalonia (#8)

* Add gpu selector to avalonia settings

* show backend label on window

* some fixes

* address review

* Minor changes to the Avalonia UI

* Update graphics window UI and locales. (#9)

* Update xaml and update locales

* locale updates

Did my best here but likely needs to be checked by native speakers, especially the use of ampersands in greek, russian and turkish?

* Fix locales with more (?) correct translations.

* add separator to render widget

* fix spanish and portuguese

* Add new IdList, replaces buffer list that could not remove elements and had unbounded growth

* Don't crash the settings window if Vulkan is not supported

* Fix Actions menu not being clickable on GTK UI after relaunch

* Rename VulkanGraphicsDevice to VulkanRenderer and Renderer to OpenGLRenderer

* Fix IdList and make it not thread safe

* Revert useless OpenGL format table changes

* Fix headless project build

* List throws ArgumentOutOfRangeException

* SPIR-V: Fix tessellation

* Increase shader cache version due to tessellation fix

* Reduce number of Sync objects created (improves perf in some specific titles)

* Fix vulkan validation errors for NPOT compressed upload and GCN workaround.

* Add timestamp to the shader cache and force rebuild if host cache is outdated

* Prefer Mail box present mode for popups (#11)

* Prefer Mail box present mode

* fix debug

* switch present mode when vsync is toggled

* only disable vsync on the main window

* SPIR-V: Fix geometry shader input load with transform feedback

* BC7 Encoder: Prefer more precision on alpha rather than RGB when alpha is 0

* Fix Avalonia build

* Address initial PR feedback

* Only set transform feedback outputs on last vertex stage

* Address riperiperi PR feedback

* Remove outdated comment

* Remove unused constructor

* Only throw for negative results

* Throw for QueueSubmit and other errors

No point in delaying the inevitable

* Transform feedback decorations inside gl_PerVertex struct breaks the NVIDIA compiler

* Fix some resolution scale issues

* No need for two UpdateScale calls

* Fix comments on SPIR-V generator project

* Try to fix shader local memory size

On DOOM, a shader is using local memory, but both Low and High size are 0, CRS size is 1536, it seems to store on that region?

* Remove RectangleF that is now unused

* Fix ImageGather with multiple offsets

Needs ImageGatherExtended capability, and must use `ConstantComposite` instead of `CompositeConstruct`

* Address PR feedback from jD in all projects except Avalonia

* Address most of jD PR feedback on Avalonia

* Remove unsafe

* Fix VulkanSkiaGpu

* move present mode request out of Create Swapchain method

* split more parts of create swapchain

* addressed reviews

* addressed review

* Address second batch of jD PR feedback

* Fix buffer <-> image copy row length and height alignment

AlignUp helper does not support NPOT alignment, and ASTC textures can have NPOT block sizes

* Better fix for NPOT alignment issue

* Use switch expressions on Vulkan EnumConversion

Thanks jD

* Fix Avalonia build

* Add Vulkan selection prompt on startup

* Grammar fixes on Vulkan prompt message

* Add missing Vulkan migration flag

Co-authored-by: riperiperi <rhy3756547@hotmail.com>
Co-authored-by: Emmanuel Hansen <emmausssss@gmail.com>
Co-authored-by: MutantAura <44103205+MutantAura@users.noreply.github.com>
This commit is contained in:
gdkchan 2022-07-31 18:26:06 -03:00 committed by GitHub
parent 14ce9e1567
commit 2232e4ae87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
302 changed files with 38968 additions and 3663 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,441 @@
// AUTOGENERATED: DO NOT EDIT
// Last update date: 2021-01-06 23:02:26.955269
#region Grammar License
// Copyright (c) 2014-2016 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and/or associated documentation files (the "Materials"),
// to deal in the Materials without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Materials, and to permit persons to whom the
// Materials are furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Materials.
//
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
// STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
// HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
// IN THE MATERIALS.
#endregion
using static Spv.Specification;
namespace Spv.Generator
{
public partial class Module
{
public Instruction GlslRound(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 1, x);
}
public Instruction GlslRoundEven(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 2, x);
}
public Instruction GlslTrunc(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 3, x);
}
public Instruction GlslFAbs(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 4, x);
}
public Instruction GlslSAbs(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 5, x);
}
public Instruction GlslFSign(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 6, x);
}
public Instruction GlslSSign(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 7, x);
}
public Instruction GlslFloor(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 8, x);
}
public Instruction GlslCeil(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 9, x);
}
public Instruction GlslFract(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 10, x);
}
public Instruction GlslRadians(Instruction resultType, Instruction degrees)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 11, degrees);
}
public Instruction GlslDegrees(Instruction resultType, Instruction radians)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 12, radians);
}
public Instruction GlslSin(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 13, x);
}
public Instruction GlslCos(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 14, x);
}
public Instruction GlslTan(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 15, x);
}
public Instruction GlslAsin(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 16, x);
}
public Instruction GlslAcos(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 17, x);
}
public Instruction GlslAtan(Instruction resultType, Instruction y_over_x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 18, y_over_x);
}
public Instruction GlslSinh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 19, x);
}
public Instruction GlslCosh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 20, x);
}
public Instruction GlslTanh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 21, x);
}
public Instruction GlslAsinh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 22, x);
}
public Instruction GlslAcosh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 23, x);
}
public Instruction GlslAtanh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 24, x);
}
public Instruction GlslAtan2(Instruction resultType, Instruction y, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 25, y, x);
}
public Instruction GlslPow(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 26, x, y);
}
public Instruction GlslExp(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 27, x);
}
public Instruction GlslLog(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 28, x);
}
public Instruction GlslExp2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 29, x);
}
public Instruction GlslLog2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 30, x);
}
public Instruction GlslSqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 31, x);
}
public Instruction GlslInverseSqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 32, x);
}
public Instruction GlslDeterminant(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 33, x);
}
public Instruction GlslMatrixInverse(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 34, x);
}
public Instruction GlslModf(Instruction resultType, Instruction x, Instruction i)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 35, x, i);
}
public Instruction GlslModfStruct(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 36, x);
}
public Instruction GlslFMin(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 37, x, y);
}
public Instruction GlslUMin(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 38, x, y);
}
public Instruction GlslSMin(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 39, x, y);
}
public Instruction GlslFMax(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 40, x, y);
}
public Instruction GlslUMax(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 41, x, y);
}
public Instruction GlslSMax(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 42, x, y);
}
public Instruction GlslFClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 43, x, minVal, maxVal);
}
public Instruction GlslUClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 44, x, minVal, maxVal);
}
public Instruction GlslSClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 45, x, minVal, maxVal);
}
public Instruction GlslFMix(Instruction resultType, Instruction x, Instruction y, Instruction a)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 46, x, y, a);
}
public Instruction GlslIMix(Instruction resultType, Instruction x, Instruction y, Instruction a)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 47, x, y, a);
}
public Instruction GlslStep(Instruction resultType, Instruction edge, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 48, edge, x);
}
public Instruction GlslSmoothStep(Instruction resultType, Instruction edge0, Instruction edge1, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 49, edge0, edge1, x);
}
public Instruction GlslFma(Instruction resultType, Instruction a, Instruction b, Instruction c)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 50, a, b, c);
}
public Instruction GlslFrexp(Instruction resultType, Instruction x, Instruction exp)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 51, x, exp);
}
public Instruction GlslFrexpStruct(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 52, x);
}
public Instruction GlslLdexp(Instruction resultType, Instruction x, Instruction exp)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 53, x, exp);
}
public Instruction GlslPackSnorm4x8(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 54, v);
}
public Instruction GlslPackUnorm4x8(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 55, v);
}
public Instruction GlslPackSnorm2x16(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 56, v);
}
public Instruction GlslPackUnorm2x16(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 57, v);
}
public Instruction GlslPackHalf2x16(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 58, v);
}
public Instruction GlslPackDouble2x32(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 59, v);
}
public Instruction GlslUnpackSnorm2x16(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 60, p);
}
public Instruction GlslUnpackUnorm2x16(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 61, p);
}
public Instruction GlslUnpackHalf2x16(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 62, v);
}
public Instruction GlslUnpackSnorm4x8(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 63, p);
}
public Instruction GlslUnpackUnorm4x8(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 64, p);
}
public Instruction GlslUnpackDouble2x32(Instruction resultType, Instruction v)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 65, v);
}
public Instruction GlslLength(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 66, x);
}
public Instruction GlslDistance(Instruction resultType, Instruction p0, Instruction p1)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 67, p0, p1);
}
public Instruction GlslCross(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 68, x, y);
}
public Instruction GlslNormalize(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 69, x);
}
public Instruction GlslFaceForward(Instruction resultType, Instruction n, Instruction i, Instruction nref)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 70, n, i, nref);
}
public Instruction GlslReflect(Instruction resultType, Instruction i, Instruction n)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 71, i, n);
}
public Instruction GlslRefract(Instruction resultType, Instruction i, Instruction n, Instruction eta)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 72, i, n, eta);
}
public Instruction GlslFindILsb(Instruction resultType, Instruction value)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 73, value);
}
public Instruction GlslFindSMsb(Instruction resultType, Instruction value)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 74, value);
}
public Instruction GlslFindUMsb(Instruction resultType, Instruction value)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 75, value);
}
public Instruction GlslInterpolateAtCentroid(Instruction resultType, Instruction interpolant)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 76, interpolant);
}
public Instruction GlslInterpolateAtSample(Instruction resultType, Instruction interpolant, Instruction sample)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 77, interpolant, sample);
}
public Instruction GlslInterpolateAtOffset(Instruction resultType, Instruction interpolant, Instruction offset)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 78, interpolant, offset);
}
public Instruction GlslNMin(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 79, x, y);
}
public Instruction GlslNMax(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 80, x, y);
}
public Instruction GlslNClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
{
return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 81, x, minVal, maxVal);
}
}
}

View file

@ -0,0 +1,841 @@
// AUTOGENERATED: DO NOT EDIT
// Last update date: 2021-01-06 23:02:27.020534
#region Grammar License
// Copyright (c) 2014-2016 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and/or associated documentation files (the "Materials"),
// to deal in the Materials without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Materials, and to permit persons to whom the
// Materials are furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Materials.
//
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
// STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
// HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
// IN THE MATERIALS.
#endregion
using static Spv.Specification;
namespace Spv.Generator
{
public partial class Module
{
public Instruction OpenClAcos(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 0, x);
}
public Instruction OpenClAcosh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 1, x);
}
public Instruction OpenClAcospi(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 2, x);
}
public Instruction OpenClAsin(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 3, x);
}
public Instruction OpenClAsinh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 4, x);
}
public Instruction OpenClAsinpi(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 5, x);
}
public Instruction OpenClAtan(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 6, x);
}
public Instruction OpenClAtan2(Instruction resultType, Instruction y, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 7, y, x);
}
public Instruction OpenClAtanh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 8, x);
}
public Instruction OpenClAtanpi(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 9, x);
}
public Instruction OpenClAtan2pi(Instruction resultType, Instruction y, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 10, y, x);
}
public Instruction OpenClCbrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 11, x);
}
public Instruction OpenClCeil(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 12, x);
}
public Instruction OpenClCopysign(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 13, x, y);
}
public Instruction OpenClCos(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 14, x);
}
public Instruction OpenClCosh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 15, x);
}
public Instruction OpenClCospi(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 16, x);
}
public Instruction OpenClErfc(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 17, x);
}
public Instruction OpenClErf(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 18, x);
}
public Instruction OpenClExp(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 19, x);
}
public Instruction OpenClExp2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 20, x);
}
public Instruction OpenClExp10(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 21, x);
}
public Instruction OpenClExpm1(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 22, x);
}
public Instruction OpenClFabs(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 23, x);
}
public Instruction OpenClFdim(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 24, x, y);
}
public Instruction OpenClFloor(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 25, x);
}
public Instruction OpenClFma(Instruction resultType, Instruction a, Instruction b, Instruction c)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 26, a, b, c);
}
public Instruction OpenClFmax(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 27, x, y);
}
public Instruction OpenClFmin(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 28, x, y);
}
public Instruction OpenClFmod(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 29, x, y);
}
public Instruction OpenClFract(Instruction resultType, Instruction x, Instruction ptr)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 30, x, ptr);
}
public Instruction OpenClFrexp(Instruction resultType, Instruction x, Instruction exp)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 31, x, exp);
}
public Instruction OpenClHypot(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 32, x, y);
}
public Instruction OpenClIlogb(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 33, x);
}
public Instruction OpenClLdexp(Instruction resultType, Instruction x, Instruction k)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 34, x, k);
}
public Instruction OpenClLgamma(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 35, x);
}
public Instruction OpenClLgamma_r(Instruction resultType, Instruction x, Instruction signp)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 36, x, signp);
}
public Instruction OpenClLog(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 37, x);
}
public Instruction OpenClLog2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 38, x);
}
public Instruction OpenClLog10(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 39, x);
}
public Instruction OpenClLog1p(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 40, x);
}
public Instruction OpenClLogb(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 41, x);
}
public Instruction OpenClMad(Instruction resultType, Instruction a, Instruction b, Instruction c)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 42, a, b, c);
}
public Instruction OpenClMaxmag(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 43, x, y);
}
public Instruction OpenClMinmag(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 44, x, y);
}
public Instruction OpenClModf(Instruction resultType, Instruction x, Instruction iptr)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 45, x, iptr);
}
public Instruction OpenClNan(Instruction resultType, Instruction nancode)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 46, nancode);
}
public Instruction OpenClNextafter(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 47, x, y);
}
public Instruction OpenClPow(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 48, x, y);
}
public Instruction OpenClPown(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 49, x, y);
}
public Instruction OpenClPowr(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 50, x, y);
}
public Instruction OpenClRemainder(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 51, x, y);
}
public Instruction OpenClRemquo(Instruction resultType, Instruction x, Instruction y, Instruction quo)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 52, x, y, quo);
}
public Instruction OpenClRint(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 53, x);
}
public Instruction OpenClRootn(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 54, x, y);
}
public Instruction OpenClRound(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 55, x);
}
public Instruction OpenClRsqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 56, x);
}
public Instruction OpenClSin(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 57, x);
}
public Instruction OpenClSincos(Instruction resultType, Instruction x, Instruction cosval)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 58, x, cosval);
}
public Instruction OpenClSinh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 59, x);
}
public Instruction OpenClSinpi(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 60, x);
}
public Instruction OpenClSqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 61, x);
}
public Instruction OpenClTan(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 62, x);
}
public Instruction OpenClTanh(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 63, x);
}
public Instruction OpenClTanpi(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 64, x);
}
public Instruction OpenClTgamma(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 65, x);
}
public Instruction OpenClTrunc(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 66, x);
}
public Instruction OpenClHalf_cos(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 67, x);
}
public Instruction OpenClHalf_divide(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 68, x, y);
}
public Instruction OpenClHalf_exp(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 69, x);
}
public Instruction OpenClHalf_exp2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 70, x);
}
public Instruction OpenClHalf_exp10(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 71, x);
}
public Instruction OpenClHalf_log(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 72, x);
}
public Instruction OpenClHalf_log2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 73, x);
}
public Instruction OpenClHalf_log10(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 74, x);
}
public Instruction OpenClHalf_powr(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 75, x, y);
}
public Instruction OpenClHalf_recip(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 76, x);
}
public Instruction OpenClHalf_rsqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 77, x);
}
public Instruction OpenClHalf_sin(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 78, x);
}
public Instruction OpenClHalf_sqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 79, x);
}
public Instruction OpenClHalf_tan(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 80, x);
}
public Instruction OpenClNative_cos(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 81, x);
}
public Instruction OpenClNative_divide(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 82, x, y);
}
public Instruction OpenClNative_exp(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 83, x);
}
public Instruction OpenClNative_exp2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 84, x);
}
public Instruction OpenClNative_exp10(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 85, x);
}
public Instruction OpenClNative_log(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 86, x);
}
public Instruction OpenClNative_log2(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 87, x);
}
public Instruction OpenClNative_log10(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 88, x);
}
public Instruction OpenClNative_powr(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 89, x, y);
}
public Instruction OpenClNative_recip(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 90, x);
}
public Instruction OpenClNative_rsqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 91, x);
}
public Instruction OpenClNative_sin(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 92, x);
}
public Instruction OpenClNative_sqrt(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 93, x);
}
public Instruction OpenClNative_tan(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 94, x);
}
public Instruction OpenClS_abs(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 141, x);
}
public Instruction OpenClS_abs_diff(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 142, x, y);
}
public Instruction OpenClS_add_sat(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 143, x, y);
}
public Instruction OpenClU_add_sat(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 144, x, y);
}
public Instruction OpenClS_hadd(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 145, x, y);
}
public Instruction OpenClU_hadd(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 146, x, y);
}
public Instruction OpenClS_rhadd(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 147, x, y);
}
public Instruction OpenClU_rhadd(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 148, x, y);
}
public Instruction OpenClS_clamp(Instruction resultType, Instruction x, Instruction minval, Instruction maxval)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 149, x, minval, maxval);
}
public Instruction OpenClU_clamp(Instruction resultType, Instruction x, Instruction minval, Instruction maxval)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 150, x, minval, maxval);
}
public Instruction OpenClClz(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 151, x);
}
public Instruction OpenClCtz(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 152, x);
}
public Instruction OpenClS_mad_hi(Instruction resultType, Instruction a, Instruction b, Instruction c)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 153, a, b, c);
}
public Instruction OpenClU_mad_sat(Instruction resultType, Instruction x, Instruction y, Instruction z)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 154, x, y, z);
}
public Instruction OpenClS_mad_sat(Instruction resultType, Instruction x, Instruction y, Instruction z)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 155, x, y, z);
}
public Instruction OpenClS_max(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 156, x, y);
}
public Instruction OpenClU_max(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 157, x, y);
}
public Instruction OpenClS_min(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 158, x, y);
}
public Instruction OpenClU_min(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 159, x, y);
}
public Instruction OpenClS_mul_hi(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 160, x, y);
}
public Instruction OpenClRotate(Instruction resultType, Instruction v, Instruction i)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 161, v, i);
}
public Instruction OpenClS_sub_sat(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 162, x, y);
}
public Instruction OpenClU_sub_sat(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 163, x, y);
}
public Instruction OpenClU_upsample(Instruction resultType, Instruction hi, Instruction lo)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 164, hi, lo);
}
public Instruction OpenClS_upsample(Instruction resultType, Instruction hi, Instruction lo)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 165, hi, lo);
}
public Instruction OpenClPopcount(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 166, x);
}
public Instruction OpenClS_mad24(Instruction resultType, Instruction x, Instruction y, Instruction z)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 167, x, y, z);
}
public Instruction OpenClU_mad24(Instruction resultType, Instruction x, Instruction y, Instruction z)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 168, x, y, z);
}
public Instruction OpenClS_mul24(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 169, x, y);
}
public Instruction OpenClU_mul24(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 170, x, y);
}
public Instruction OpenClU_abs(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 201, x);
}
public Instruction OpenClU_abs_diff(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 202, x, y);
}
public Instruction OpenClU_mul_hi(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 203, x, y);
}
public Instruction OpenClU_mad_hi(Instruction resultType, Instruction a, Instruction b, Instruction c)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 204, a, b, c);
}
public Instruction OpenClFclamp(Instruction resultType, Instruction x, Instruction minval, Instruction maxval)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 95, x, minval, maxval);
}
public Instruction OpenClDegrees(Instruction resultType, Instruction radians)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 96, radians);
}
public Instruction OpenClFmax_common(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 97, x, y);
}
public Instruction OpenClFmin_common(Instruction resultType, Instruction x, Instruction y)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 98, x, y);
}
public Instruction OpenClMix(Instruction resultType, Instruction x, Instruction y, Instruction a)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 99, x, y, a);
}
public Instruction OpenClRadians(Instruction resultType, Instruction degrees)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 100, degrees);
}
public Instruction OpenClStep(Instruction resultType, Instruction edge, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 101, edge, x);
}
public Instruction OpenClSmoothstep(Instruction resultType, Instruction edge0, Instruction edge1, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 102, edge0, edge1, x);
}
public Instruction OpenClSign(Instruction resultType, Instruction x)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 103, x);
}
public Instruction OpenClCross(Instruction resultType, Instruction p0, Instruction p1)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 104, p0, p1);
}
public Instruction OpenClDistance(Instruction resultType, Instruction p0, Instruction p1)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 105, p0, p1);
}
public Instruction OpenClLength(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 106, p);
}
public Instruction OpenClNormalize(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 107, p);
}
public Instruction OpenClFast_distance(Instruction resultType, Instruction p0, Instruction p1)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 108, p0, p1);
}
public Instruction OpenClFast_length(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 109, p);
}
public Instruction OpenClFast_normalize(Instruction resultType, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 110, p);
}
public Instruction OpenClBitselect(Instruction resultType, Instruction a, Instruction b, Instruction c)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 186, a, b, c);
}
public Instruction OpenClSelect(Instruction resultType, Instruction a, Instruction b, Instruction c)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 187, a, b, c);
}
public Instruction OpenClVloadn(Instruction resultType, Instruction offset, Instruction p, LiteralInteger n)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 171, offset, p, n);
}
public Instruction OpenClVstoren(Instruction resultType, Instruction data, Instruction offset, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 172, data, offset, p);
}
public Instruction OpenClVload_half(Instruction resultType, Instruction offset, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 173, offset, p);
}
public Instruction OpenClVload_halfn(Instruction resultType, Instruction offset, Instruction p, LiteralInteger n)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 174, offset, p, n);
}
public Instruction OpenClVstore_half(Instruction resultType, Instruction data, Instruction offset, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 175, data, offset, p);
}
public Instruction OpenClVstore_half_r(Instruction resultType, Instruction data, Instruction offset, Instruction p, FPRoundingMode mode)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 176, data, offset, p, LiteralInteger.CreateForEnum(mode));
}
public Instruction OpenClVstore_halfn(Instruction resultType, Instruction data, Instruction offset, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 177, data, offset, p);
}
public Instruction OpenClVstore_halfn_r(Instruction resultType, Instruction data, Instruction offset, Instruction p, FPRoundingMode mode)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 178, data, offset, p, LiteralInteger.CreateForEnum(mode));
}
public Instruction OpenClVloada_halfn(Instruction resultType, Instruction offset, Instruction p, LiteralInteger n)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 179, offset, p, n);
}
public Instruction OpenClVstorea_halfn(Instruction resultType, Instruction data, Instruction offset, Instruction p)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 180, data, offset, p);
}
public Instruction OpenClVstorea_halfn_r(Instruction resultType, Instruction data, Instruction offset, Instruction p, FPRoundingMode mode)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 181, data, offset, p, LiteralInteger.CreateForEnum(mode));
}
public Instruction OpenClShuffle(Instruction resultType, Instruction x, Instruction shufflemask)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 182, x, shufflemask);
}
public Instruction OpenClShuffle2(Instruction resultType, Instruction x, Instruction y, Instruction shufflemask)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 183, x, y, shufflemask);
}
public Instruction OpenClPrefetch(Instruction resultType, Instruction ptr, Instruction numelements)
{
return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 185, ptr, numelements);
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace Spv.Generator
{
internal struct ConstantKey : IEquatable<ConstantKey>
{
private Instruction _constant;
public ConstantKey(Instruction constant)
{
_constant = constant;
}
public override int GetHashCode()
{
return HashCode.Combine(_constant.Opcode, _constant.GetHashCodeContent(), _constant.GetHashCodeResultType());
}
public bool Equals(ConstantKey other)
{
return _constant.Opcode == other._constant.Opcode && _constant.EqualsContent(other._constant) && _constant.EqualsResultType(other._constant);
}
public override bool Equals([NotNullWhen(true)] object obj)
{
return obj is ConstantKey && Equals((ConstantKey)obj);
}
}
}

View file

@ -0,0 +1,109 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Spv.Generator
{
/// <summary>
/// Similar to System.HashCode, but without introducing random values.
/// The same primes and shifts are used.
/// </summary>
internal static class DeterministicHashCode
{
private const uint Prime1 = 2654435761U;
private const uint Prime2 = 2246822519U;
private const uint Prime3 = 3266489917U;
private const uint Prime4 = 668265263U;
public static int GetHashCode(string value)
{
uint hash = (uint)value.Length + Prime1;
for (int i = 0; i < value.Length; i++)
{
hash += (hash << 7) ^ value[i];
}
return (int)MixFinal(hash);
}
public static int Combine<T>(ReadOnlySpan<T> values)
{
uint hashCode = Prime2;
hashCode += 4 * (uint)values.Length;
foreach (T value in values)
{
uint hc = (uint)(value?.GetHashCode() ?? 0);
hashCode = MixStep(hashCode, hc);
}
return (int)MixFinal(hashCode);
}
public static int Combine<T1, T2>(T1 value1, T2 value2)
{
uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
uint hash = Prime2;
hash += 8;
hash = MixStep(hash, hc1);
hash = MixStep(hash, hc2);
return (int)MixFinal(hash);
}
public static int Combine<T1, T2, T3>(T1 value1, T2 value2, T3 value3)
{
uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
uint hash = Prime2;
hash += 12;
hash = MixStep(hash, hc1);
hash = MixStep(hash, hc2);
hash = MixStep(hash, hc3);
return (int)MixFinal(hash);
}
public static int Combine<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4)
{
uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
uint hc4 = (uint)(value4?.GetHashCode() ?? 0);
uint hash = Prime2;
hash += 16;
hash = MixStep(hash, hc1);
hash = MixStep(hash, hc2);
hash = MixStep(hash, hc3);
hash = MixStep(hash, hc4);
return (int)MixFinal(hash);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint MixStep(uint hashCode, uint mixValue)
{
return BitOperations.RotateLeft(hashCode + mixValue * Prime3, 17) * Prime4;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint MixFinal(uint hash)
{
hash ^= hash >> 15;
hash *= Prime2;
hash ^= hash >> 13;
hash *= Prime3;
hash ^= hash >> 16;
return hash;
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace Spv.Generator
{
internal class DeterministicStringKey : IEquatable<DeterministicStringKey>
{
private string _value;
public DeterministicStringKey(string value)
{
_value = value;
}
public override int GetHashCode()
{
return DeterministicHashCode.GetHashCode(_value);
}
public bool Equals(DeterministicStringKey other)
{
return _value == other._value;
}
public override bool Equals([NotNullWhen(true)] object obj)
{
return obj is DeterministicStringKey && Equals((DeterministicStringKey)obj);
}
}
}

View file

@ -0,0 +1,58 @@
using System.Collections.Generic;
namespace Spv.Generator
{
public class GeneratorPool<T> where T : class, new()
{
private List<T[]> _pool;
private int _chunkIndex = -1;
private int _poolIndex = -1;
private int _initialSize;
private int _poolSizeIncrement;
public GeneratorPool(): this(1000, 200) { }
public GeneratorPool(int chunkSizeLimit, int poolSizeIncrement)
{
_initialSize = chunkSizeLimit;
_poolSizeIncrement = poolSizeIncrement;
_pool = new(chunkSizeLimit * 2);
AddChunkIfNeeded();
}
public T Allocate()
{
if (++_poolIndex >= _poolSizeIncrement)
{
AddChunkIfNeeded();
_poolIndex = 0;
}
return _pool[_chunkIndex][_poolIndex];
}
private void AddChunkIfNeeded()
{
if (++_chunkIndex >= _pool.Count)
{
T[] pool = new T[_poolSizeIncrement];
for (int i = 0; i < _poolSizeIncrement; i++)
{
pool[i] = new T();
}
_pool.Add(pool);
}
}
public void Clear()
{
_chunkIndex = 0;
_poolIndex = -1;
}
}
}

View file

@ -0,0 +1,232 @@
using System;
using System.Diagnostics;
using System.IO;
namespace Spv.Generator
{
public sealed class Instruction : Operand, IEquatable<Instruction>
{
public const uint InvalidId = uint.MaxValue;
public Specification.Op Opcode { get; private set; }
private Instruction _resultType;
private InstructionOperands _operands;
public uint Id { get; set; }
public Instruction() { }
public void Set(Specification.Op opcode, uint id = InvalidId, Instruction resultType = null)
{
Opcode = opcode;
Id = id;
_resultType = resultType;
_operands = new InstructionOperands();
}
public void SetId(uint id)
{
Id = id;
}
public OperandType Type => OperandType.Instruction;
public ushort GetTotalWordCount()
{
ushort result = WordCount;
if (Id != InvalidId)
{
result++;
}
if (_resultType != null)
{
result += _resultType.WordCount;
}
Span<Operand> operands = _operands.ToSpan();
for (int i = 0; i < operands.Length; i++)
{
result += operands[i].WordCount;
}
return result;
}
public ushort WordCount => 1;
public void AddOperand(Operand value)
{
Debug.Assert(value != null);
_operands.Add(value);
}
public void AddOperand(Operand[] value)
{
foreach (Operand instruction in value)
{
AddOperand(instruction);
}
}
public void AddOperand(LiteralInteger[] value)
{
foreach (LiteralInteger instruction in value)
{
AddOperand(instruction);
}
}
public void AddOperand(LiteralInteger value)
{
AddOperand((Operand)value);
}
public void AddOperand(Instruction[] value)
{
foreach (Instruction instruction in value)
{
AddOperand(instruction);
}
}
public void AddOperand(Instruction value)
{
AddOperand((Operand)value);
}
public void AddOperand(string value)
{
AddOperand(new LiteralString(value));
}
public void AddOperand<T>(T value) where T: Enum
{
AddOperand(LiteralInteger.CreateForEnum(value));
}
public void Write(BinaryWriter writer)
{
// Word 0
writer.Write((ushort)Opcode);
writer.Write(GetTotalWordCount());
_resultType?.WriteOperand(writer);
if (Id != InvalidId)
{
writer.Write(Id);
}
Span<Operand> operands = _operands.ToSpan();
for (int i = 0; i < operands.Length; i++)
{
operands[i].WriteOperand(writer);
}
}
public void WriteOperand(BinaryWriter writer)
{
Debug.Assert(Id != InvalidId);
if (Id == InvalidId)
{
string methodToCall;
if (Opcode == Specification.Op.OpVariable)
{
methodToCall = "AddLocalVariable or AddGlobalVariable";
}
else if (Opcode == Specification.Op.OpLabel)
{
methodToCall = "AddLabel";
}
else
{
throw new InvalidOperationException("Internal error");
}
throw new InvalidOperationException($"Id wasn't bound to the module, please make sure to call {methodToCall}");
}
writer.Write(Id);
}
public override bool Equals(object obj)
{
return obj is Instruction instruction && Equals(instruction);
}
public bool Equals(Instruction cmpObj)
{
bool result = Type == cmpObj.Type && Id == cmpObj.Id;
if (result)
{
if (_resultType != null && cmpObj._resultType != null)
{
result &= _resultType.Equals(cmpObj._resultType);
}
else if (_resultType != null || cmpObj._resultType != null)
{
return false;
}
}
if (result)
{
result &= EqualsContent(cmpObj);
}
return result;
}
public bool EqualsContent(Instruction cmpObj)
{
Span<Operand> thisOperands = _operands.ToSpan();
Span<Operand> cmpOperands = cmpObj._operands.ToSpan();
if (thisOperands.Length != cmpOperands.Length)
{
return false;
}
for (int i = 0; i < thisOperands.Length; i++)
{
if (!thisOperands[i].Equals(cmpOperands[i]))
{
return false;
}
}
return true;
}
public bool EqualsResultType(Instruction cmpObj)
{
return _resultType.Opcode == cmpObj._resultType.Opcode && _resultType.EqualsContent(cmpObj._resultType);
}
public int GetHashCodeContent()
{
return DeterministicHashCode.Combine<Operand>(_operands.ToSpan());
}
public int GetHashCodeResultType()
{
return DeterministicHashCode.Combine(_resultType.Opcode, _resultType.GetHashCodeContent());
}
public override int GetHashCode()
{
return DeterministicHashCode.Combine(Opcode, Id, _resultType, DeterministicHashCode.Combine<Operand>(_operands.ToSpan()));
}
public bool Equals(Operand obj)
{
return obj is Instruction instruction && Equals(instruction);
}
}
}

View file

@ -0,0 +1,53 @@
using System;
using System.Runtime.InteropServices;
namespace Spv.Generator
{
public struct InstructionOperands
{
private const int InternalCount = 5;
public int Count;
public Operand Operand1;
public Operand Operand2;
public Operand Operand3;
public Operand Operand4;
public Operand Operand5;
public Operand[] Overflow;
public Span<Operand> ToSpan()
{
if (Count > InternalCount)
{
return MemoryMarshal.CreateSpan(ref this.Overflow[0], Count);
}
else
{
return MemoryMarshal.CreateSpan(ref this.Operand1, Count);
}
}
public void Add(Operand operand)
{
if (Count < InternalCount)
{
MemoryMarshal.CreateSpan(ref this.Operand1, Count + 1)[Count] = operand;
Count++;
}
else
{
if (Overflow == null)
{
Overflow = new Operand[InternalCount * 2];
MemoryMarshal.CreateSpan(ref this.Operand1, InternalCount).CopyTo(Overflow.AsSpan());
}
else if (Count == Overflow.Length)
{
Array.Resize(ref Overflow, Overflow.Length * 2);
}
Overflow[Count++] = operand;
}
}
}
}

23
Spv.Generator/LICENSE Normal file
View file

@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,103 @@
using System;
using System.IO;
namespace Spv.Generator
{
public class LiteralInteger : Operand, IEquatable<LiteralInteger>
{
[ThreadStatic]
private static GeneratorPool<LiteralInteger> _pool;
internal static void RegisterPool(GeneratorPool<LiteralInteger> pool)
{
_pool = pool;
}
internal static void UnregisterPool()
{
_pool = null;
}
public OperandType Type => OperandType.Number;
private enum IntegerType
{
UInt32,
Int32,
UInt64,
Int64,
Float32,
Float64,
}
private IntegerType _integerType;
private ulong _data;
public ushort WordCount { get; private set; }
public LiteralInteger() { }
private static LiteralInteger New()
{
return _pool.Allocate();
}
private LiteralInteger Set(ulong data, IntegerType integerType, ushort wordCount)
{
_data = data;
_integerType = integerType;
WordCount = wordCount;
return this;
}
public static implicit operator LiteralInteger(int value) => New().Set((ulong)value, IntegerType.Int32, 1);
public static implicit operator LiteralInteger(uint value) => New().Set(value, IntegerType.UInt32, 1);
public static implicit operator LiteralInteger(long value) => New().Set((ulong)value, IntegerType.Int64, 2);
public static implicit operator LiteralInteger(ulong value) => New().Set(value, IntegerType.UInt64, 2);
public static implicit operator LiteralInteger(float value) => New().Set(BitConverter.SingleToUInt32Bits(value), IntegerType.Float32, 1);
public static implicit operator LiteralInteger(double value) => New().Set(BitConverter.DoubleToUInt64Bits(value), IntegerType.Float64, 2);
public static implicit operator LiteralInteger(Enum value) => New().Set((ulong)(int)(object)value, IntegerType.Int32, 1);
// NOTE: this is not in the standard, but this is some syntax sugar useful in some instructions (TypeInt ect)
public static implicit operator LiteralInteger(bool value) => New().Set(Convert.ToUInt64(value), IntegerType.Int32, 1);
public static LiteralInteger CreateForEnum<T>(T value) where T : Enum
{
return value;
}
public void WriteOperand(BinaryWriter writer)
{
if (WordCount == 1)
{
writer.Write((uint)_data);
}
else
{
writer.Write(_data);
}
}
public override bool Equals(object obj)
{
return obj is LiteralInteger literalInteger && Equals(literalInteger);
}
public bool Equals(LiteralInteger cmpObj)
{
return Type == cmpObj.Type && _integerType == cmpObj._integerType && _data == cmpObj._data;
}
public override int GetHashCode()
{
return DeterministicHashCode.Combine(Type, _data);
}
public bool Equals(Operand obj)
{
return obj is LiteralInteger literalInteger && Equals(literalInteger);
}
}
}

View file

@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Text;
namespace Spv.Generator
{
public class LiteralString : Operand, IEquatable<LiteralString>
{
public OperandType Type => OperandType.String;
private string _value;
public LiteralString(string value)
{
_value = value;
}
public ushort WordCount => (ushort)(_value.Length / 4 + 1);
public void WriteOperand(BinaryWriter writer)
{
writer.Write(_value.AsSpan());
// String must be padded to the word size (which is 4 bytes).
int paddingSize = 4 - (Encoding.ASCII.GetByteCount(_value) % 4);
Span<byte> padding = stackalloc byte[paddingSize];
writer.Write(padding);
}
public override bool Equals(object obj)
{
return obj is LiteralString literalString && Equals(literalString);
}
public bool Equals(LiteralString cmpObj)
{
return Type == cmpObj.Type && _value.Equals(cmpObj._value);
}
public override int GetHashCode()
{
return DeterministicHashCode.Combine(Type, DeterministicHashCode.GetHashCode(_value));
}
public bool Equals(Operand obj)
{
return obj is LiteralString literalString && Equals(literalString);
}
}
}

365
Spv.Generator/Module.cs Normal file
View file

@ -0,0 +1,365 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using static Spv.Specification;
namespace Spv.Generator
{
public partial class Module
{
// TODO: Register on SPIR-V registry.
private const int GeneratorId = 0;
private readonly uint _version;
private uint _bound;
// Follow spec order here while keeping it as simple as possible.
private List<Capability> _capabilities;
private List<string> _extensions;
private Dictionary<DeterministicStringKey, Instruction> _extInstImports;
private AddressingModel _addressingModel;
private MemoryModel _memoryModel;
private List<Instruction> _entrypoints;
private List<Instruction> _executionModes;
private List<Instruction> _debug;
private List<Instruction> _annotations;
// In the declaration block.
private Dictionary<TypeDeclarationKey, Instruction> _typeDeclarations;
// In the declaration block.
private List<Instruction> _globals;
// In the declaration block.
private Dictionary<ConstantKey, Instruction> _constants;
// In the declaration block, for function that aren't defined in the module.
private List<Instruction> _functionsDeclarations;
private List<Instruction> _functionsDefinitions;
private GeneratorPool<Instruction> _instPool;
private GeneratorPool<LiteralInteger> _integerPool;
public Module(uint version, GeneratorPool<Instruction> instPool = null, GeneratorPool<LiteralInteger> integerPool = null)
{
_version = version;
_bound = 1;
_capabilities = new List<Capability>();
_extensions = new List<string>();
_extInstImports = new Dictionary<DeterministicStringKey, Instruction>();
_addressingModel = AddressingModel.Logical;
_memoryModel = MemoryModel.Simple;
_entrypoints = new List<Instruction>();
_executionModes = new List<Instruction>();
_debug = new List<Instruction>();
_annotations = new List<Instruction>();
_typeDeclarations = new Dictionary<TypeDeclarationKey, Instruction>();
_constants = new Dictionary<ConstantKey, Instruction>();
_globals = new List<Instruction>();
_functionsDeclarations = new List<Instruction>();
_functionsDefinitions = new List<Instruction>();
_instPool = instPool ?? new GeneratorPool<Instruction>();
_integerPool = integerPool ?? new GeneratorPool<LiteralInteger>();
LiteralInteger.RegisterPool(_integerPool);
}
private uint GetNewId()
{
return _bound++;
}
public void AddCapability(Capability capability)
{
_capabilities.Add(capability);
}
public void AddExtension(string extension)
{
_extensions.Add(extension);
}
public Instruction NewInstruction(Op opcode, uint id = Instruction.InvalidId, Instruction resultType = null)
{
var result = _instPool.Allocate();
result.Set(opcode, id, resultType);
return result;
}
public Instruction AddExtInstImport(string import)
{
var key = new DeterministicStringKey(import);
if (_extInstImports.TryGetValue(key, out Instruction extInstImport))
{
// Update the duplicate instance to use the good id so it ends up being encoded correctly.
return extInstImport;
}
Instruction instruction = NewInstruction(Op.OpExtInstImport);
instruction.AddOperand(import);
instruction.SetId(GetNewId());
_extInstImports.Add(key, instruction);
return instruction;
}
private void AddTypeDeclaration(Instruction instruction, bool forceIdAllocation)
{
var key = new TypeDeclarationKey(instruction);
if (!forceIdAllocation)
{
if (_typeDeclarations.TryGetValue(key, out Instruction typeDeclaration))
{
// Update the duplicate instance to use the good id so it ends up being encoded correctly.
instruction.SetId(typeDeclaration.Id);
return;
}
}
instruction.SetId(GetNewId());
_typeDeclarations.Add(key, instruction);
}
public void AddEntryPoint(ExecutionModel executionModel, Instruction function, string name, params Instruction[] interfaces)
{
Debug.Assert(function.Opcode == Op.OpFunction);
Instruction entryPoint = NewInstruction(Op.OpEntryPoint);
entryPoint.AddOperand(executionModel);
entryPoint.AddOperand(function);
entryPoint.AddOperand(name);
entryPoint.AddOperand(interfaces);
_entrypoints.Add(entryPoint);
}
public void AddExecutionMode(Instruction function, ExecutionMode mode, params Operand[] parameters)
{
Debug.Assert(function.Opcode == Op.OpFunction);
Instruction executionModeInstruction = NewInstruction(Op.OpExecutionMode);
executionModeInstruction.AddOperand(function);
executionModeInstruction.AddOperand(mode);
executionModeInstruction.AddOperand(parameters);
_executionModes.Add(executionModeInstruction);
}
private void AddToFunctionDefinitions(Instruction instruction)
{
Debug.Assert(instruction.Opcode != Op.OpTypeInt);
_functionsDefinitions.Add(instruction);
}
private void AddAnnotation(Instruction annotation)
{
_annotations.Add(annotation);
}
private void AddDebug(Instruction debug)
{
_debug.Add(debug);
}
public void AddLabel(Instruction label)
{
Debug.Assert(label.Opcode == Op.OpLabel);
label.SetId(GetNewId());
AddToFunctionDefinitions(label);
}
public void AddLocalVariable(Instruction variable)
{
// TODO: Ensure it has the local modifier.
Debug.Assert(variable.Opcode == Op.OpVariable);
variable.SetId(GetNewId());
AddToFunctionDefinitions(variable);
}
public void AddGlobalVariable(Instruction variable)
{
// TODO: Ensure it has the global modifier.
// TODO: All constants opcodes (OpSpecXXX and the rest of the OpConstantXXX).
Debug.Assert(variable.Opcode == Op.OpVariable);
variable.SetId(GetNewId());
_globals.Add(variable);
}
private void AddConstant(Instruction constant)
{
Debug.Assert(constant.Opcode == Op.OpConstant ||
constant.Opcode == Op.OpConstantFalse ||
constant.Opcode == Op.OpConstantTrue ||
constant.Opcode == Op.OpConstantNull ||
constant.Opcode == Op.OpConstantComposite);
var key = new ConstantKey(constant);
if (_constants.TryGetValue(key, out Instruction global))
{
// Update the duplicate instance to use the good id so it ends up being encoded correctly.
constant.SetId(global.Id);
return;
}
constant.SetId(GetNewId());
_constants.Add(key, constant);
}
public Instruction ExtInst(Instruction resultType, Instruction set, LiteralInteger instruction, params Operand[] parameters)
{
Instruction result = NewInstruction(Op.OpExtInst, GetNewId(), resultType);
result.AddOperand(set);
result.AddOperand(instruction);
result.AddOperand(parameters);
AddToFunctionDefinitions(result);
return result;
}
public void SetMemoryModel(AddressingModel addressingModel, MemoryModel memoryModel)
{
_addressingModel = addressingModel;
_memoryModel = memoryModel;
}
// TODO: Find a way to make the auto generate one used.
public Instruction OpenClPrintf(Instruction resultType, Instruction format, params Instruction[] additionalarguments)
{
Instruction result = NewInstruction(Op.OpExtInst, GetNewId(), resultType);
result.AddOperand(AddExtInstImport("OpenCL.std"));
result.AddOperand((LiteralInteger)184);
result.AddOperand(format);
result.AddOperand(additionalarguments);
AddToFunctionDefinitions(result);
return result;
}
public byte[] Generate()
{
// Estimate the size needed for the generated code, to avoid expanding the MemoryStream.
int sizeEstimate = 1024 + _functionsDefinitions.Count * 32;
using (MemoryStream stream = new MemoryStream(sizeEstimate))
{
BinaryWriter writer = new BinaryWriter(stream, System.Text.Encoding.ASCII);
// Header
writer.Write(MagicNumber);
writer.Write(_version);
writer.Write(GeneratorId);
writer.Write(_bound);
writer.Write(0u);
// 1.
foreach (Capability capability in _capabilities)
{
Instruction capabilityInstruction = NewInstruction(Op.OpCapability);
capabilityInstruction.AddOperand(capability);
capabilityInstruction.Write(writer);
}
// 2.
foreach (string extension in _extensions)
{
Instruction extensionInstruction = NewInstruction(Op.OpExtension);
extensionInstruction.AddOperand(extension);
extensionInstruction.Write(writer);
}
// 3.
foreach (Instruction extInstImport in _extInstImports.Values)
{
extInstImport.Write(writer);
}
// 4.
Instruction memoryModelInstruction = NewInstruction(Op.OpMemoryModel);
memoryModelInstruction.AddOperand(_addressingModel);
memoryModelInstruction.AddOperand(_memoryModel);
memoryModelInstruction.Write(writer);
// 5.
foreach (Instruction entrypoint in _entrypoints)
{
entrypoint.Write(writer);
}
// 6.
foreach (Instruction executionMode in _executionModes)
{
executionMode.Write(writer);
}
// 7.
// TODO: Order debug information correctly.
foreach (Instruction debug in _debug)
{
debug.Write(writer);
}
// 8.
foreach (Instruction annotation in _annotations)
{
annotation.Write(writer);
}
// Ensure that everything is in the right order in the declarations section.
List<Instruction> declarations = new List<Instruction>();
declarations.AddRange(_typeDeclarations.Values);
declarations.AddRange(_globals);
declarations.AddRange(_constants.Values);
declarations.Sort((Instruction x, Instruction y) => x.Id.CompareTo(y.Id));
// 9.
foreach (Instruction declaration in declarations)
{
declaration.Write(writer);
}
// 10.
foreach (Instruction functionDeclaration in _functionsDeclarations)
{
functionDeclaration.Write(writer);
}
// 11.
foreach (Instruction functionDefinition in _functionsDefinitions)
{
functionDefinition.Write(writer);
}
_instPool.Clear();
_integerPool.Clear();
LiteralInteger.UnregisterPool();
return stream.ToArray();
}
}
}
}

14
Spv.Generator/Operand.cs Normal file
View file

@ -0,0 +1,14 @@
using System;
using System.IO;
namespace Spv.Generator
{
public interface Operand : IEquatable<Operand>
{
OperandType Type { get; }
ushort WordCount { get; }
void WriteOperand(BinaryWriter writer);
}
}

View file

@ -0,0 +1,10 @@
namespace Spv.Generator
{
public enum OperandType
{
Invalid,
Number,
String,
Instruction,
}
}

View file

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,30 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace Spv.Generator
{
internal struct TypeDeclarationKey : IEquatable<TypeDeclarationKey>
{
private Instruction _typeDeclaration;
public TypeDeclarationKey(Instruction typeDeclaration)
{
_typeDeclaration = typeDeclaration;
}
public override int GetHashCode()
{
return DeterministicHashCode.Combine(_typeDeclaration.Opcode, _typeDeclaration.GetHashCodeContent());
}
public bool Equals(TypeDeclarationKey other)
{
return _typeDeclaration.Opcode == other._typeDeclaration.Opcode && _typeDeclaration.EqualsContent(other._typeDeclaration);
}
public override bool Equals([NotNullWhen(true)] object obj)
{
return obj is TypeDeclarationKey && Equals((TypeDeclarationKey)obj);
}
}
}

1625
Spv.Generator/spirv.cs Normal file

File diff suppressed because it is too large Load diff