diff --git a/README.md b/README.md index 0215e79173..dd434e82fb 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,15 @@ client sees one pad either way. Connect a controller and the on-screen one disap and it comes back. Anywhere the controls are not is a touchpad: touch moves the pointer and a tap clicks, which is how the client's own on-screen keyboard is used to sign in. +## Frame generation + +Extra frames are generated between the real ones on the way to the screen — inside the app's +compositor, on gamescope's final output — so it works for any game with nothing changed in the +runtime. **Win-FG** is built in. **LSFG** uses the shader chain from your own copy of Lossless +Scaling: install it from the Steam client in this app and the app reads its `Lossless.dll` from +the runtime's Steam library (parsed as data, never executed; nothing of it is redistributed). +Pick an engine and 2×/3×/4× on the main screen; it applies immediately, mid-game included. + ## Background and foreground A session belongs to a foreground service, not to the activity, so leaving Big Picture does not diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 1653647cfb..59e0e17bbf 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -6,6 +6,33 @@ project(steamdeck C CXX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wno-unused-function -Wimplicit-function-declaration") add_subdirectory(adrenotools) + +# DXVK's DXBC->SPIR-V translator (zlib licence), vendored under thirdparty/dxbc from the same +# subset upstream lsfg-vk uses. Native LSFG frame generation needs it: the Lossless Scaling +# shader chain is DXBC in every build downloadable from Steam. +add_subdirectory(thirdparty/dxbc) + +# The Win-FG chain self-identifies by two halves: the upstream tag it was copied from (hand-set, +# UPDATE IT when re-copying) and a hash over the sources themselves, computed here, which cannot +# rot. The compositor's frame-generation leg (waylandcomp/CMakeLists.txt) stamps both in. +set(WINFG_UPSTREAM "v0.3.0") +set(WINFG_CHAIN_SRC + winlator/winfg/framegen.cpp + winlator/winfg/framegen.hpp + winlator/winfg/record_impl.inc + winlator/winfg/config.hpp + winlator/winfg/embedded_shaders.hpp + winlator/winfg/winfg_engine.cpp +) +set(WINFG_HASH_INPUT "") +foreach(f ${WINFG_CHAIN_SRC}) + file(SHA256 "${CMAKE_CURRENT_SOURCE_DIR}/${f}" _h) + string(APPEND WINFG_HASH_INPUT "${_h}") +endforeach() +string(SHA256 WINFG_CHAIN_HASH_FULL "${WINFG_HASH_INPUT}") +string(SUBSTRING "${WINFG_CHAIN_HASH_FULL}" 0 12 WINFG_CHAIN_HASH) +message(STATUS "win-fg chain: ${WINFG_UPSTREAM} (src ${WINFG_CHAIN_HASH})") + add_subdirectory(waylandcomp) add_library(sdnative SHARED sdnative/sdnative.c) target_link_libraries(sdnative log) diff --git a/app/src/main/cpp/thirdparty/dxbc/.gitignore b/app/src/main/cpp/thirdparty/dxbc/.gitignore new file mode 100644 index 0000000000..4522fe54d2 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/.gitignore @@ -0,0 +1,3 @@ +# cmake files +.cache/ +build/ diff --git a/app/src/main/cpp/thirdparty/dxbc/CMakeLists.txt b/app/src/main/cpp/thirdparty/dxbc/CMakeLists.txt new file mode 100644 index 0000000000..2651d7b8dd --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.10) + +project(dxbc + VERSION 2.6.2 + DESCRIPTION "DXVK's DXBC" + LANGUAGES CXX) + +file(GLOB SOURCES + "src/dxbc/*.cpp" + "src/spirv/*.cpp" + "src/util/*.cpp" +) + +add_library(dxbc STATIC ${SOURCES}) + +# target +set_target_properties(dxbc PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON) +target_include_directories(dxbc SYSTEM + PUBLIC include/dxbc + PUBLIC include/spirv include/util include/dxvk) +target_compile_options(dxbc PRIVATE + -fPIC) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set_target_properties(dxbc PROPERTIES + EXPORT_COMPILE_COMMANDS ON) +endif() diff --git a/app/src/main/cpp/thirdparty/dxbc/LICENSE.md b/app/src/main/cpp/thirdparty/dxbc/LICENSE.md new file mode 100644 index 0000000000..35d56c0baa --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/LICENSE.md @@ -0,0 +1,24 @@ + Copyright (c) 2017 Philip Rebohle + Copyright (c) 2019 Joshua Ashton + Copyright (c) 2019 Robin Kertels + Copyright (c) 2023 Jeffrey Ellison + + zlib/libpng license + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +– The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + +– Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. + +– This notice may not be removed or altered from any source distribution. diff --git a/app/src/main/cpp/thirdparty/dxbc/README.md b/app/src/main/cpp/thirdparty/dxbc/README.md new file mode 100644 index 0000000000..ac2b636656 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/README.md @@ -0,0 +1,4 @@ +This GitHub repo hosts the files for running DXVK's shader translation independently of DXVK. + +Please check out the original project: +https://github.com/doitsujin/dxvk diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_analysis.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_analysis.h new file mode 100644 index 0000000000..6c8b0325ba --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_analysis.h @@ -0,0 +1,110 @@ +#pragma once + +#include "dxbc_chunk_isgn.h" +#include "dxbc_decoder.h" +#include "dxbc_defs.h" +#include "dxbc_names.h" +#include "dxbc_modinfo.h" +#include "dxbc_util.h" + +namespace dxvk { + + /** + * \brief Info about unordered access views + * + * Stores whether an UAV is accessed with typed + * read or atomic instructions. This information + * will be used to generate image types. + */ + struct DxbcUavInfo { + bool accessTypedLoad = false; + bool accessAtomicOp = false; + bool sparseFeedback = false; + bool nonInvariantAccess = false; + DxvkAccessOp accessOp = DxvkAccessOp::None; + VkAccessFlags accessFlags = 0; + }; + + /** + * \brief Info about shader resource views + * + * Stores whether an SRV is accessed with + * sparse feedback. Useful for buffers. + */ + struct DxbcSrvInfo { + bool sparseFeedback = false; + }; + + /** + * \brief Counts cull and clip distances + */ + struct DxbcClipCullInfo { + uint32_t numClipPlanes = 0; + uint32_t numCullPlanes = 0; + }; + + /** + * \brief Shader analysis info + */ + struct DxbcAnalysisInfo { + std::array uavInfos; + std::array srvInfos; + std::array xRegMasks; + + DxbcClipCullInfo clipCullIn; + DxbcClipCullInfo clipCullOut; + + DxbcBindingMask bindings = { }; + + bool usesDerivatives = false; + bool usesKill = false; + }; + + /** + * \brief DXBC shader analysis pass + * + * Collects information about the shader itself + * and the resources used by the shader, which + * will later be used by the actual compiler. + */ + class DxbcAnalyzer { + + public: + + DxbcAnalyzer( + const DxbcModuleInfo& moduleInfo, + const DxbcProgramInfo& programInfo, + const Rc& isgn, + const Rc& osgn, + const Rc& psgn, + DxbcAnalysisInfo& analysis); + + ~DxbcAnalyzer(); + + /** + * \brief Processes a single instruction + * \param [in] ins The instruction + */ + void processInstruction( + const DxbcShaderInstruction& ins); + + private: + + Rc m_isgn; + Rc m_osgn; + Rc m_psgn; + + DxbcAnalysisInfo* m_analysis = nullptr; + + DxbcClipCullInfo getClipCullInfo( + const Rc& sgn) const; + + void setUavAccessOp(uint32_t uav, DxvkAccessOp op); + + static DxvkAccessOp getStoreAccessOp(DxbcRegMask writeMask, const DxbcRegister& src); + + static DxvkAccessOp getConstantStoreOp(uint32_t value); + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_chunk_isgn.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_chunk_isgn.h new file mode 100644 index 0000000000..9b4b79186d --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_chunk_isgn.h @@ -0,0 +1,68 @@ +#pragma once + +#include + +#include "dxbc_common.h" +#include "dxbc_decoder.h" +#include "dxbc_enums.h" +#include "dxbc_reader.h" + +namespace dxvk { + + /** + * \brief Signature entry + * + * Stores the semantic name of an input or + * output and the corresponding register. + */ + struct DxbcSgnEntry { + std::string semanticName; + uint32_t semanticIndex; + uint32_t registerId; + DxbcRegMask componentMask; + DxbcRegMask componentUsed; + DxbcScalarType componentType; + DxbcSystemValue systemValue; + uint32_t streamId; + }; + + /** + * \brief Input/Output signature chunk + * + * Stores information about the input and + * output registers used by the shader stage. + */ + class DxbcIsgn : public RcObject { + + public: + + DxbcIsgn(DxbcReader reader, DxbcTag tag); + ~DxbcIsgn(); + + auto begin() const { return m_entries.cbegin(); } + auto end () const { return m_entries.cend(); } + + const DxbcSgnEntry* findByRegister( + uint32_t registerId) const; + + const DxbcSgnEntry* find( + const std::string& semanticName, + uint32_t semanticIndex, + uint32_t streamIndex) const; + + DxbcRegMask regMask( + uint32_t registerId) const; + + uint32_t maxRegisterCount() const; + + static bool compareSemanticNames( + const std::string& a, + const std::string& b); + + private: + + std::vector m_entries; + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_chunk_shex.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_chunk_shex.h new file mode 100644 index 0000000000..8deecc8675 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_chunk_shex.h @@ -0,0 +1,39 @@ +#pragma once + +#include "dxbc_common.h" +#include "dxbc_decoder.h" +#include "dxbc_reader.h" + +namespace dxvk { + + /** + * \brief Shader code chunk + * + * Stores the DXBC shader code itself, as well + * as some meta info about the shader, i.e. what + * type of shader this is. + */ + class DxbcShex : public RcObject { + + public: + + DxbcShex(DxbcReader reader); + ~DxbcShex(); + + DxbcProgramInfo programInfo() const { + return m_programInfo; + } + + DxbcCodeSlice slice() const { + return DxbcCodeSlice(m_code.data(), + m_code.data() + m_code.size()); + } + + private: + + DxbcProgramInfo m_programInfo; + std::vector m_code; + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_common.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_common.h new file mode 100644 index 0000000000..d9d4207673 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_common.h @@ -0,0 +1,72 @@ +#pragma once + +#include "dxbc_include.h" + +namespace dxvk { + + /** + * \brief DXBC Program type + * + * Defines the shader stage that a DXBC + * module has been compiled form. + */ + enum class DxbcProgramType : uint16_t { + PixelShader = 0, + VertexShader = 1, + GeometryShader = 2, + HullShader = 3, + DomainShader = 4, + ComputeShader = 5, + + Count + }; + + using DxbcProgramTypeFlags = Flags; + + + /** + * \brief DXBC shader info + * + * Stores the shader program type. + */ + class DxbcProgramInfo { + + public: + + DxbcProgramInfo() { } + DxbcProgramInfo(DxbcProgramType type) + : m_type(type) { } + + /** + * \brief Program type + * \returns Program type + */ + DxbcProgramType type() const { + return m_type; + } + + /** + * \brief Vulkan shader stage + * + * The \c VkShaderStageFlagBits constant + * that corresponds to the program type. + * \returns Vulkan shaer stage + */ + VkShaderStageFlagBits shaderStage() const; + + /** + * \brief SPIR-V execution model + * + * The execution model that corresponds + * to the Vulkan shader stage. + * \returns SPIR-V execution model + */ + spv::ExecutionModel executionModel() const; + + private: + + DxbcProgramType m_type = DxbcProgramType::PixelShader; + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_compiler.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_compiler.h new file mode 100644 index 0000000000..f63d1e11a1 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_compiler.h @@ -0,0 +1,1292 @@ +#pragma once + +#include +#include +#include + +#include "../spirv/spirv_module.h" + +#include "dxbc_analysis.h" +#include "dxbc_chunk_isgn.h" +#include "dxbc_decoder.h" +#include "dxbc_defs.h" +#include "dxbc_modinfo.h" +#include "dxbc_names.h" +#include "dxbc_util.h" + +namespace dxvk { + + /** + * \brief Vector type + * + * Convenience struct that stores a scalar + * type and a component count. The compiler + * can use this to generate SPIR-V types. + */ + struct DxbcVectorType { + DxbcScalarType ctype; + uint32_t ccount; + }; + + + /** + * \brief Array type + * + * Convenience struct that stores a scalar type, a + * component count and an array size. An array of + * length 0 will be evaluated to a vector type. The + * compiler can use this to generate SPIR-V types. + */ + struct DxbcArrayType { + DxbcScalarType ctype; + uint32_t ccount; + uint32_t alength; + }; + + + /** + * \brief Register info + * + * Stores the array type of a register and + * its storage class. The compiler can use + * this to generate SPIR-V pointer types. + */ + struct DxbcRegisterInfo { + DxbcArrayType type; + spv::StorageClass sclass; + }; + + + /** + * \brief Register value + * + * Stores a vector type and a SPIR-V ID that + * represents an intermediate value. This is + * used to track the type of such values. + */ + struct DxbcRegisterValue { + DxbcVectorType type; + uint32_t id; + }; + + + /** + * \brief Register pointer + * + * Stores a vector type and a SPIR-V ID that + * represents a pointer to such a vector. This + * can be used to load registers conveniently. + */ + struct DxbcRegisterPointer { + DxbcVectorType type; + uint32_t id; + }; + + + struct DxbcXreg { + uint32_t ccount = 0; + uint32_t alength = 0; + uint32_t varId = 0; + }; + + + struct DxbcGreg { + DxbcResourceType type = DxbcResourceType::Raw; + uint32_t elementStride = 0; + uint32_t elementCount = 0; + uint32_t varId = 0; + }; + + + /** + * \brief Specialization constant properties + * + * Stores the name, data type and initial + * value of a specialization constant. + */ + struct DxbcSpecConstant { + DxbcScalarType ctype; + uint32_t ccount; + uint32_t value; + const char* name; + }; + + + /** + * \brief Helper struct for conditional execution + * + * Stores a set of labels required to implement either + * an if-then block or an if-then-else block. This is + * not used to implement control flow instructions. + */ + struct DxbcConditional { + uint32_t labelIf = 0; + uint32_t labelElse = 0; + uint32_t labelEnd = 0; + }; + + + struct DxbcXfbVar { + uint32_t varId = 0; + uint32_t streamId = 0; + uint32_t outputId = 0; + DxbcRegMask srcMask = 0; + DxbcRegMask dstMask = 0; + uint32_t location = 0; + uint32_t component = 0; + }; + + + struct DxbcIndexRange { + DxbcOperandType type; + uint32_t start; + uint32_t length; + }; + + + /** + * \brief Vertex shader-specific structure + */ + struct DxbcCompilerVsPart { + uint32_t functionId = 0; + + uint32_t builtinVertexId = 0; + uint32_t builtinInstanceId = 0; + uint32_t builtinBaseVertex = 0; + uint32_t builtinBaseInstance = 0; + }; + + + /** + * \brief Geometry shader-specific structure + */ + struct DxbcCompilerGsPart { + DxbcPrimitive inputPrimitive = DxbcPrimitive::Undefined; + DxbcPrimitiveTopology outputTopology = DxbcPrimitiveTopology::Undefined; + uint32_t outputVertexCount = 0; + uint32_t functionId = 0; + + uint32_t builtinLayer = 0; + uint32_t builtinViewportId = 0; + uint32_t builtinInvocationId = 0; + uint32_t invocationCount = 0; + + bool needsOutputSetup = false; + }; + + + /** + * \brief Pixel shader-specific structure + */ + struct DxbcCompilerPsPart { + uint32_t functionId = 0; + + uint32_t builtinFragCoord = 0; + uint32_t builtinDepth = 0; + uint32_t builtinStencilRef = 0; + uint32_t builtinIsFrontFace = 0; + uint32_t builtinSampleId = 0; + uint32_t builtinSampleMaskIn = 0; + uint32_t builtinSampleMaskOut = 0; + uint32_t builtinLayer = 0; + uint32_t builtinViewportId = 0; + uint32_t builtinInnerCoverageId = 0; + + uint32_t pushConstantId = 0; + }; + + + /** + * \brief Compute shader-specific structure + */ + struct DxbcCompilerCsPart { + uint32_t functionId = 0; + + uint32_t workgroupSizeX = 0; + uint32_t workgroupSizeY = 0; + uint32_t workgroupSizeZ = 0; + + uint32_t builtinGlobalInvocationId = 0; + uint32_t builtinLocalInvocationId = 0; + uint32_t builtinLocalInvocationIndex = 0; + uint32_t builtinWorkgroupId = 0; + }; + + + /** + * \brief Hull shader fork/join phase + * + * Defines a function and built-in variables + * for a single fork or join phase sub-program. + */ + struct DxbcCompilerHsForkJoinPhase { + uint32_t functionId = 0; + uint32_t instanceCount = 1; + + uint32_t instanceId = 0; + uint32_t instanceIdPtr = 0; + }; + + + /** + * \brief Hull shader control point phase + * + * Defines the function for the control + * point phase program of a hull shader. + */ + struct DxbcCompilerHsControlPointPhase { + uint32_t functionId = 0; + }; + + + /** + * \brief Hull shader phase + * + * Used to identify the current + * phase and function ID. + */ + enum class DxbcCompilerHsPhase : uint32_t { + None, ///< No active phase + Decl, ///< \c hs_decls + ControlPoint, ///< \c hs_control_point_phase + Fork, ///< \c hs_fork_phase + Join, ///< \c hs_join_phase + }; + + + /** + * \brief Hull shader-specific structure + */ + struct DxbcCompilerHsPart { + DxbcCompilerHsPhase currPhaseType = DxbcCompilerHsPhase::None; + size_t currPhaseId = 0; + + float maxTessFactor = 64.0f; + + uint32_t vertexCountIn = 0; + uint32_t vertexCountOut = 0; + + uint32_t builtinInvocationId = 0; + uint32_t builtinTessLevelOuter = 0; + uint32_t builtinTessLevelInner = 0; + + uint32_t outputPerPatch = 0; + uint32_t outputPerVertex = 0; + + uint32_t invocationBlockBegin = 0; + uint32_t invocationBlockEnd = 0; + + uint32_t outputPerPatchMask = 0; + + DxbcCompilerHsControlPointPhase cpPhase; + std::vector forkPhases; + std::vector joinPhases; + }; + + + /** + * \brief Domain shader-specific structure + */ + struct DxbcCompilerDsPart { + uint32_t functionId = 0; + + uint32_t builtinTessCoord = 0; + uint32_t builtinTessLevelOuter = 0; + uint32_t builtinTessLevelInner = 0; + + uint32_t vertexCountIn = 0; + + uint32_t inputPerPatch = 0; + uint32_t inputPerVertex = 0; + }; + + + enum class DxbcCfgBlockType : uint32_t { + If, Loop, Switch, + }; + + + struct DxbcCfgBlockIf { + uint32_t ztestId; + uint32_t labelIf; + uint32_t labelElse; + uint32_t labelEnd; + size_t headerPtr; + }; + + + struct DxbcCfgBlockLoop { + uint32_t labelHeader; + uint32_t labelBegin; + uint32_t labelContinue; + uint32_t labelBreak; + }; + + + struct DxbcSwitchLabel { + SpirvSwitchCaseLabel desc; + DxbcSwitchLabel* next; + }; + + + struct DxbcCfgBlockSwitch { + size_t insertPtr; + uint32_t selectorId; + uint32_t labelBreak; + uint32_t labelCase; + uint32_t labelDefault; + DxbcSwitchLabel* labelCases; + }; + + + struct DxbcCfgBlock { + DxbcCfgBlockType type; + + union { + DxbcCfgBlockIf b_if; + DxbcCfgBlockLoop b_loop; + DxbcCfgBlockSwitch b_switch; + }; + }; + + + struct DxbcBufferInfo { + DxbcImageInfo image; + DxbcScalarType stype; + DxbcResourceType type; + uint32_t typeId; + uint32_t varId; + uint32_t stride; + uint32_t coherence; + bool isSsbo; + }; + + + /** + * \brief DXBC to SPIR-V shader compiler + * + * Processes instructions from a DXBC shader and creates + * a DXVK shader object, which contains the SPIR-V module + * and information about the shader resource bindings. + */ + class DxbcCompiler { + + public: + + DxbcCompiler( + const std::string& fileName, + const DxbcModuleInfo& moduleInfo, + const DxbcProgramInfo& programInfo, + const Rc& isgn, + const Rc& osgn, + const Rc& psgn, + const DxbcAnalysisInfo& analysis); + ~DxbcCompiler(); + + /** + * \brief Processes a single instruction + * \param [in] ins The instruction + */ + void processInstruction( + const DxbcShaderInstruction& ins); + + /** + * \brief Emits transform feedback passthrough + * + * Writes all captured input variables to the + * corresponding xfb outputs, and sets up the + * geometry shader for point-to-point mode. + */ + void processXfbPassthrough(); + + /** + * \brief Finalizes the shader + * \returns The final shader object + */ + SpirvCodeBuffer finalize(); + + /** + * \brief Extracts immediate constant buffer data + * + * Only defined if the ICB needs to be backed by a + * uniform buffer. + * \returns Immediate constant buffer data + */ + std::vector getIcbData() const { + return std::move(m_icbData); + } + + private: + + DxbcModuleInfo m_moduleInfo; + DxbcProgramInfo m_programInfo; + SpirvModule m_module; + + Rc m_isgn; + Rc m_osgn; + Rc m_psgn; + + const DxbcAnalysisInfo* m_analysis; + + /////////////////////////////////////////////////////// + // Resource slot description for the shader. This will + // be used to map D3D11 bindings to DXVK bindings. + std::vector m_bindings; + + //////////////////////////////////////////////// + // Temporary r# vector registers with immediate + // indexing, and x# vector array registers. + std::vector m_rRegs; + std::vector m_xRegs; + + ///////////////////////////////////////////// + // Thread group shared memory (g#) registers + std::vector m_gRegs; + + /////////////////////////////////////////////////////////// + // v# registers as defined by the shader. The type of each + // of these inputs is either float4 or an array of float4. + std::array< + DxbcRegisterPointer, + DxbcMaxInterfaceRegs> m_vRegs; + std::vector m_vMappings; + + ////////////////////////////////////////////////////////// + // o# registers as defined by the shader. In the fragment + // shader stage, these registers are typed by the signature, + // in all other stages, they are float4 registers or arrays. + std::array< + DxbcRegisterPointer, + DxbcMaxInterfaceRegs> m_oRegs; + std::vector m_oMappings; + + ///////////////////////////////////////////// + // xfb output registers for geometry shaders + std::vector m_xfbVars; + + ///////////////////////////////////////////// + // Dynamically indexed input and output regs + std::vector m_indexRanges = { }; + + ////////////////////////////////////////////////////// + // Shader resource variables. These provide access to + // constant buffers, samplers, textures, and UAVs. + std::array m_constantBuffers; + std::array m_samplers; + std::array m_textures; + std::array m_uavs; + + bool m_hasGloballyCoherentUav = false; + bool m_hasRasterizerOrderedUav = false; + + /////////////////////////////////////////////// + // Control flow information. Stores labels for + // currently active if-else blocks and loops. + std::vector m_controlFlowBlocks; + + bool m_topLevelIsUniform = true; + + uint64_t m_uavRdMask = 0u; + uint64_t m_uavWrMask = 0u; + + ////////////////////////////////////////////// + // Function state tracking. Required in order + // to properly end functions in some cases. + bool m_insideFunction = false; + + /////////////////////////////////////////////////////////// + // Array of input values. Since v# registers are indexable + // in DXBC, we need to copy them into an array first. + uint32_t m_vArrayLength = 0; + uint32_t m_vArrayLengthId = 0; + + uint32_t m_vArray = 0; + + //////////////////////////////////////////////////// + // Per-vertex input and output blocks. Depending on + // the shader stage, these may be declared as arrays. + uint32_t m_positionIn = 0; + uint32_t m_positionOut = 0; + + uint32_t m_clipDistances = 0; + uint32_t m_cullDistances = 0; + + uint32_t m_primitiveIdIn = 0; + uint32_t m_primitiveIdOut = 0; + + ////////////////////////////////////////////////// + // Immediate constant buffer. If defined, this is + // an array of four-component uint32 vectors. + uint32_t m_icbArray = 0; + std::vector m_icbData; + + uint32_t m_icbComponents = 0u; + uint32_t m_icbSize = 0u; + + /////////////////////////////////////////////////// + // Sample pos array. If defined, this iis an array + // of 32 four-component float vectors. + uint32_t m_samplePositions = 0; + + //////////////////////////////////////////// + // Struct type used for UAV counter buffers + uint32_t m_uavCtrStructType = 0; + uint32_t m_uavCtrPointerType = 0; + + //////////////////////////////// + // Function IDs for subroutines + std::unordered_map m_subroutines; + + /////////////////////////////////////////////////// + // Entry point description - we'll need to declare + // the function ID and all input/output variables. + uint32_t m_entryPointId = 0; + bool m_hasRawAccessChains = false; + + //////////////////////////////////////////// + // Inter-stage shader interface slots. Also + // covers vertex input and fragment output. + uint32_t m_inputMask = 0u; + uint32_t m_outputMask = 0u; + + /////////////////////////////////// + // Shader-specific data structures + DxbcCompilerVsPart m_vs; + DxbcCompilerHsPart m_hs; + DxbcCompilerDsPart m_ds; + DxbcCompilerGsPart m_gs; + DxbcCompilerPsPart m_ps; + DxbcCompilerCsPart m_cs; + + ////////////////////// + // Global state stuff + bool m_precise = true; + + DxbcOpcode m_lastOp = DxbcOpcode::Nop; + DxbcOpcode m_currOp = DxbcOpcode::Nop; + + VkPrimitiveTopology m_inputTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; + VkPrimitiveTopology m_outputTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; + + ///////////////////////////////////////////////////// + // Shader interface and metadata declaration methods + void emitDcl( + const DxbcShaderInstruction& ins); + + void emitDclGlobalFlags( + const DxbcShaderInstruction& ins); + + void emitDclIndexRange( + const DxbcShaderInstruction& ins); + + void emitDclTemps( + const DxbcShaderInstruction& ins); + + void emitDclIndexableTemp( + const DxbcShaderInstruction& ins); + + void emitDclInterfaceReg( + const DxbcShaderInstruction& ins); + + void emitDclInput( + uint32_t regIdx, + uint32_t regDim, + DxbcRegMask regMask, + DxbcSystemValue sv, + DxbcInterpolationMode im); + + void emitDclOutput( + uint32_t regIdx, + uint32_t regDim, + DxbcRegMask regMask, + DxbcSystemValue sv, + DxbcInterpolationMode im); + + void emitDclConstantBuffer( + const DxbcShaderInstruction& ins); + + void emitDclConstantBufferVar( + uint32_t regIdx, + uint32_t numConstants, + uint32_t numComponents, + const char* name); + + void emitDclSampler( + const DxbcShaderInstruction& ins); + + void emitDclStream( + const DxbcShaderInstruction& ins); + + void emitDclResourceTyped( + const DxbcShaderInstruction& ins); + + void emitDclResourceRawStructured( + const DxbcShaderInstruction& ins); + + void emitDclThreadGroupSharedMemory( + const DxbcShaderInstruction& ins); + + void emitDclGsInputPrimitive( + const DxbcShaderInstruction& ins); + + void emitDclGsOutputTopology( + const DxbcShaderInstruction& ins); + + void emitDclMaxOutputVertexCount( + const DxbcShaderInstruction& ins); + + void emitDclInputControlPointCount( + const DxbcShaderInstruction& ins); + + void emitDclOutputControlPointCount( + const DxbcShaderInstruction& ins); + + void emitDclHsMaxTessFactor( + const DxbcShaderInstruction& ins); + + void emitDclTessDomain( + const DxbcShaderInstruction& ins); + + void emitDclTessPartitioning( + const DxbcShaderInstruction& ins); + + void emitDclTessOutputPrimitive( + const DxbcShaderInstruction& ins); + + void emitDclThreadGroup( + const DxbcShaderInstruction& ins); + + void emitDclGsInstanceCount( + const DxbcShaderInstruction& ins); + + uint32_t emitDclUavCounter( + uint32_t regId); + + //////////////////////// + // Custom data handlers + void emitDclImmediateConstantBuffer( + const DxbcShaderInstruction& ins); + + void emitDclImmediateConstantBufferBaked( + uint32_t dwordCount, + const uint32_t* dwordArray, + uint32_t componentCount); + + void emitDclImmediateConstantBufferUbo( + uint32_t dwordCount, + const uint32_t* dwordArray, + uint32_t componentCount); + + void emitCustomData( + const DxbcShaderInstruction& ins); + + ////////////////////////////// + // Instruction class handlers + void emitVectorAlu( + const DxbcShaderInstruction& ins); + + void emitVectorCmov( + const DxbcShaderInstruction& ins); + + void emitVectorCmp( + const DxbcShaderInstruction& ins); + + void emitVectorDeriv( + const DxbcShaderInstruction& ins); + + void emitVectorDot( + const DxbcShaderInstruction& ins); + + void emitVectorIdiv( + const DxbcShaderInstruction& ins); + + void emitVectorImul( + const DxbcShaderInstruction& ins); + + void emitVectorMsad( + const DxbcShaderInstruction& ins); + + void emitVectorShift( + const DxbcShaderInstruction& ins); + + void emitVectorSinCos( + const DxbcShaderInstruction& ins); + + void emitGeometryEmit( + const DxbcShaderInstruction& ins); + + void emitAtomic( + const DxbcShaderInstruction& ins); + + void emitAtomicCounter( + const DxbcShaderInstruction& ins); + + void emitBarrier( + const DxbcShaderInstruction& ins); + + void emitBitExtract( + const DxbcShaderInstruction& ins); + + void emitBitInsert( + const DxbcShaderInstruction& ins); + + void emitBitScan( + const DxbcShaderInstruction& ins); + + void emitBufferQuery( + const DxbcShaderInstruction& ins); + + void emitBufferLoad( + const DxbcShaderInstruction& ins); + + void emitBufferStore( + const DxbcShaderInstruction& ins); + + void emitConvertFloat16( + const DxbcShaderInstruction& ins); + + void emitConvertFloat64( + const DxbcShaderInstruction& ins); + + void emitHullShaderPhase( + const DxbcShaderInstruction& ins); + + void emitHullShaderInstCnt( + const DxbcShaderInstruction& ins); + + void emitInterpolate( + const DxbcShaderInstruction& ins); + + void emitSparseCheckAccess( + const DxbcShaderInstruction& ins); + + void emitTextureQuery( + const DxbcShaderInstruction& ins); + + void emitTextureQueryLod( + const DxbcShaderInstruction& ins); + + void emitTextureQueryMs( + const DxbcShaderInstruction& ins); + + void emitTextureQueryMsPos( + const DxbcShaderInstruction& ins); + + void emitTextureFetch( + const DxbcShaderInstruction& ins); + + void emitTextureGather( + const DxbcShaderInstruction& ins); + + void emitTextureSample( + const DxbcShaderInstruction& ins); + + void emitTypedUavLoad( + const DxbcShaderInstruction& ins); + + void emitTypedUavStore( + const DxbcShaderInstruction& ins); + + ///////////////////////////////////// + // Control flow instruction handlers + void emitControlFlowIf( + const DxbcShaderInstruction& ins); + + void emitControlFlowElse( + const DxbcShaderInstruction& ins); + + void emitControlFlowEndIf( + const DxbcShaderInstruction& ins); + + void emitControlFlowSwitch( + const DxbcShaderInstruction& ins); + + void emitControlFlowCase( + const DxbcShaderInstruction& ins); + + void emitControlFlowDefault( + const DxbcShaderInstruction& ins); + + void emitControlFlowEndSwitch( + const DxbcShaderInstruction& ins); + + void emitControlFlowLoop( + const DxbcShaderInstruction& ins); + + void emitControlFlowEndLoop( + const DxbcShaderInstruction& ins); + + void emitControlFlowBreak( + const DxbcShaderInstruction& ins); + + void emitControlFlowBreakc( + const DxbcShaderInstruction& ins); + + void emitControlFlowRet( + const DxbcShaderInstruction& ins); + + void emitControlFlowRetc( + const DxbcShaderInstruction& ins); + + void emitControlFlowDiscard( + const DxbcShaderInstruction& ins); + + void emitControlFlowLabel( + const DxbcShaderInstruction& ins); + + void emitControlFlowCall( + const DxbcShaderInstruction& ins); + + void emitControlFlowCallc( + const DxbcShaderInstruction& ins); + + void emitControlFlow( + const DxbcShaderInstruction& ins); + + //////////////////////////////////////////////// + // Constant building methods. These are used to + // generate constant vectors that store the same + // value in each component. + DxbcRegisterValue emitBuildConstVecf32( + float x, + float y, + float z, + float w, + const DxbcRegMask& writeMask); + + DxbcRegisterValue emitBuildConstVecu32( + uint32_t x, + uint32_t y, + uint32_t z, + uint32_t w, + const DxbcRegMask& writeMask); + + DxbcRegisterValue emitBuildConstVeci32( + int32_t x, + int32_t y, + int32_t z, + int32_t w, + const DxbcRegMask& writeMask); + + DxbcRegisterValue emitBuildConstVecf64( + double xy, + double zw, + const DxbcRegMask& writeMask); + + DxbcRegisterValue emitBuildVector( + DxbcRegisterValue scalar, + uint32_t count); + + DxbcRegisterValue emitBuildZeroVector( + DxbcVectorType type); + + ///////////////////////////////////////// + // Generic register manipulation methods + DxbcRegisterValue emitRegisterBitcast( + DxbcRegisterValue srcValue, + DxbcScalarType dstType); + + DxbcRegisterValue emitRegisterSwizzle( + DxbcRegisterValue value, + DxbcRegSwizzle swizzle, + DxbcRegMask writeMask); + + DxbcRegisterValue emitRegisterExtract( + DxbcRegisterValue value, + DxbcRegMask mask); + + DxbcRegisterValue emitRegisterInsert( + DxbcRegisterValue dstValue, + DxbcRegisterValue srcValue, + DxbcRegMask srcMask); + + DxbcRegisterValue emitRegisterConcat( + DxbcRegisterValue value1, + DxbcRegisterValue value2); + + DxbcRegisterValue emitRegisterExtend( + DxbcRegisterValue value, + uint32_t size); + + DxbcRegisterValue emitRegisterAbsolute( + DxbcRegisterValue value); + + DxbcRegisterValue emitRegisterNegate( + DxbcRegisterValue value); + + DxbcRegisterValue emitRegisterZeroTest( + DxbcRegisterValue value, + DxbcZeroTest test); + + DxbcRegisterValue emitRegisterMaskBits( + DxbcRegisterValue value, + uint32_t mask); + + DxbcRegisterValue emitSrcOperandModifiers( + DxbcRegisterValue value, + DxbcRegModifiers modifiers); + + DxbcRegisterValue emitDstOperandModifiers( + DxbcRegisterValue value, + DxbcOpModifiers modifiers); + + /////////////////////////// + // Sparse feedback methods + uint32_t emitExtractSparseTexel( + uint32_t texelTypeId, + uint32_t resultId); + + void emitStoreSparseFeedback( + const DxbcRegister& feedbackRegister, + uint32_t resultId); + + //////////////////////////////// + // Pointer manipulation methods + DxbcRegisterPointer emitArrayAccess( + DxbcRegisterPointer pointer, + spv::StorageClass sclass, + uint32_t index); + + /////////////////////////////////////// + // Image register manipulation methods + uint32_t emitLoadSampledImage( + const DxbcShaderResource& textureResource, + const DxbcSampler& samplerResource, + bool isDepthCompare); + + //////////////////////// + // Address load methods + DxbcRegisterPointer emitGetTempPtr( + const DxbcRegister& operand); + + DxbcRegisterPointer emitGetIndexableTempPtr( + const DxbcRegister& operand); + + DxbcRegisterPointer emitGetInputPtr( + const DxbcRegister& operand); + + DxbcRegisterPointer emitGetOutputPtr( + const DxbcRegister& operand); + + DxbcRegisterPointer emitGetConstBufPtr( + const DxbcRegister& operand); + + DxbcRegisterPointer emitGetImmConstBufPtr( + const DxbcRegister& operand); + + DxbcRegisterPointer emitGetOperandPtr( + const DxbcRegister& operand); + + DxbcRegisterPointer emitGetAtomicPointer( + const DxbcRegister& operand, + const DxbcRegister& address); + + ////////////////////////// + // Resource query methods + DxbcRegisterValue emitQueryBufferSize( + const DxbcRegister& resource); + + DxbcRegisterValue emitQueryTexelBufferSize( + const DxbcRegister& resource); + + DxbcRegisterValue emitQueryTextureLods( + const DxbcRegister& resource); + + DxbcRegisterValue emitQueryTextureSamples( + const DxbcRegister& resource); + + DxbcRegisterValue emitQueryTextureSize( + const DxbcRegister& resource, + DxbcRegisterValue lod); + + //////////////////////////////////// + // Buffer index calculation methods + DxbcRegisterValue emitCalcBufferIndexStructured( + DxbcRegisterValue structId, + DxbcRegisterValue structOffset, + uint32_t structStride); + + DxbcRegisterValue emitCalcBufferIndexRaw( + DxbcRegisterValue byteOffset); + + DxbcRegisterValue emitCalcTexCoord( + DxbcRegisterValue coordVector, + const DxbcImageInfo& imageInfo); + + DxbcRegisterValue emitLoadTexCoord( + const DxbcRegister& coordReg, + const DxbcImageInfo& imageInfo); + + ////////////////////////////// + // Operand load/store methods + DxbcRegisterValue emitIndexLoad( + DxbcRegIndex index); + + DxbcRegisterValue emitValueLoad( + DxbcRegisterPointer ptr); + + void emitValueStore( + DxbcRegisterPointer ptr, + DxbcRegisterValue value, + DxbcRegMask writeMask); + + DxbcRegisterValue emitRegisterLoadRaw( + const DxbcRegister& reg); + + DxbcRegisterValue emitConstantBufferLoad( + const DxbcRegister& reg, + DxbcRegMask writeMask); + + DxbcRegisterValue emitRegisterLoad( + const DxbcRegister& reg, + DxbcRegMask writeMask); + + void emitRegisterStore( + const DxbcRegister& reg, + DxbcRegisterValue value); + + //////////////////////////// + // Input/output preparation + void emitInputSetup(); + void emitInputSetup(uint32_t vertexCount); + + void emitOutputSetup(); + void emitOutputDepthClamp(); + + void emitInitWorkgroupMemory(); + + ////////////////////////////////////////// + // System value load methods (per shader) + DxbcRegisterValue emitVsSystemValueLoad( + DxbcSystemValue sv, + DxbcRegMask mask); + + DxbcRegisterValue emitGsSystemValueLoad( + DxbcSystemValue sv, + DxbcRegMask mask, + uint32_t vertexId); + + DxbcRegisterValue emitPsSystemValueLoad( + DxbcSystemValue sv, + DxbcRegMask mask); + + /////////////////////////////////////////// + // System value store methods (per shader) + void emitVsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value); + + void emitHsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value); + + void emitDsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value); + + void emitGsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value); + + void emitPsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value); + + /////////////////////////////// + // Special system value stores + void emitClipCullStore( + DxbcSystemValue sv, + uint32_t dstArray); + + void emitClipCullLoad( + DxbcSystemValue sv, + uint32_t srcArray); + + void emitPointSizeStore(); + + ////////////////////////////////////// + // Common function definition methods + void emitInit(); + + void emitFunctionBegin( + uint32_t entryPoint, + uint32_t returnType, + uint32_t funcType); + + void emitFunctionEnd(); + + void emitFunctionLabel(); + + void emitMainFunctionBegin(); + + ///////////////////////////////// + // Shader initialization methods + void emitVsInit(); + void emitHsInit(); + void emitDsInit(); + void emitGsInit(); + void emitPsInit(); + void emitCsInit(); + + /////////////////////////////// + // Shader finalization methods + void emitVsFinalize(); + void emitHsFinalize(); + void emitDsFinalize(); + void emitGsFinalize(); + void emitPsFinalize(); + void emitCsFinalize(); + + /////////////////////// + // Xfb related methods + void emitXfbOutputDeclarations(); + + void emitXfbOutputSetup( + uint32_t streamId, + bool passthrough); + + /////////////////////////////// + // Hull shader phase methods + void emitHsControlPointPhase( + const DxbcCompilerHsControlPointPhase& phase); + + void emitHsForkJoinPhase( + const DxbcCompilerHsForkJoinPhase& phase); + + void emitHsPhaseBarrier(); + + void emitHsInvocationBlockBegin( + uint32_t count); + + void emitHsInvocationBlockEnd(); + + void emitHsOutputSetup(); + + uint32_t emitTessInterfacePerPatch( + spv::StorageClass storageClass); + + uint32_t emitTessInterfacePerVertex( + spv::StorageClass storageClass, + uint32_t vertexCount); + + ////////////// + // Misc stuff + void emitDclInputArray( + uint32_t vertexCount); + + uint32_t emitDclClipCullDistanceArray( + uint32_t length, + spv::BuiltIn builtIn, + spv::StorageClass storageClass); + + DxbcCompilerHsControlPointPhase emitNewHullShaderControlPointPhase(); + + DxbcCompilerHsControlPointPhase emitNewHullShaderPassthroughPhase(); + + DxbcCompilerHsForkJoinPhase emitNewHullShaderForkJoinPhase(); + + uint32_t emitSamplePosArray(); + + void emitFloatControl(); + + /////////////////////////////// + // Variable definition methods + uint32_t emitNewVariable( + const DxbcRegisterInfo& info); + + uint32_t emitNewBuiltinVariable( + const DxbcRegisterInfo& info, + spv::BuiltIn builtIn, + const char* name); + + uint32_t emitBuiltinTessLevelOuter( + spv::StorageClass storageClass); + + uint32_t emitBuiltinTessLevelInner( + spv::StorageClass storageClass); + + uint32_t emitPushConstants(); + + //////////////// + // Misc methods + DxbcCfgBlock* cfgFindBlock( + const std::initializer_list& types); + + DxbcBufferInfo getBufferInfo( + const DxbcRegister& reg); + + uint32_t getTexSizeDim( + const DxbcImageInfo& imageType) const; + + uint32_t getTexLayerDim( + const DxbcImageInfo& imageType) const; + + uint32_t getTexCoordDim( + const DxbcImageInfo& imageType) const; + + DxbcRegMask getTexCoordMask( + const DxbcImageInfo& imageType) const; + + DxbcVectorType getInputRegType( + uint32_t regIdx) const; + + DxbcVectorType getOutputRegType( + uint32_t regIdx) const; + + DxbcImageInfo getResourceType( + DxbcResourceDim resourceType, + bool isUav) const; + + spv::ImageFormat getScalarImageFormat( + DxbcScalarType type) const; + + bool isDoubleType( + DxbcScalarType type) const; + + DxbcRegisterPointer getIndexableTempPtr( + const DxbcRegister& operand, + DxbcRegisterValue vectorId); + + bool caseBlockIsFallthrough() const; + + uint32_t getUavCoherence( + uint32_t registerId, + DxbcUavFlags flags); + + bool ignoreInputSystemValue( + DxbcSystemValue sv) const; + + void emitUavBarrier( + uint64_t readMask, + uint64_t writeMask); + + /////////////////////////// + // Type definition methods + uint32_t getScalarTypeId( + DxbcScalarType type); + + uint32_t getVectorTypeId( + const DxbcVectorType& type); + + uint32_t getArrayTypeId( + const DxbcArrayType& type); + + uint32_t getPointerTypeId( + const DxbcRegisterInfo& type); + + uint32_t getSparseResultTypeId( + uint32_t baseType); + + uint32_t getFunctionId( + uint32_t functionNr); + + DxbcCompilerHsForkJoinPhase* getCurrentHsForkJoinPhase(); + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_decoder.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_decoder.h new file mode 100644 index 0000000000..771837152e --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_decoder.h @@ -0,0 +1,509 @@ +#pragma once + +#include + +#include "dxbc_common.h" +#include "dxbc_decoder.h" +#include "dxbc_defs.h" +#include "dxbc_enums.h" +#include "dxbc_names.h" + +namespace dxvk { + + constexpr size_t DxbcMaxRegIndexDim = 3; + + struct DxbcRegister; + + /** + * \brief Source operand modifiers + * + * These are applied after loading + * an operand register. + */ + enum class DxbcRegModifier : uint32_t { + Neg = 0, + Abs = 1, + }; + + using DxbcRegModifiers = Flags; + + + /** + * \brief Constant buffer binding + * + * Stores information required to + * access a constant buffer. + */ + struct DxbcConstantBuffer { + uint32_t varId = 0; + uint32_t size = 0; + }; + + /** + * \brief Sampler binding + * + * Stores a sampler variable that can be + * used together with a texture resource. + */ + struct DxbcSampler { + uint32_t varId = 0; + uint32_t typeId = 0; + }; + + + /** + * \brief Image type information + */ + struct DxbcImageInfo { + spv::Dim dim = spv::Dim1D; + uint32_t array = 0; + uint32_t ms = 0; + uint32_t sampled = 0; + VkImageViewType vtype = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + }; + + + /** + * \brief Shader resource binding + * + * Stores a resource variable + * and associated type IDs. + */ + struct DxbcShaderResource { + DxbcResourceType type = DxbcResourceType::Typed; + DxbcImageInfo imageInfo; + uint32_t varId = 0; + uint32_t specId = 0; + DxbcScalarType sampledType = DxbcScalarType::Float32; + uint32_t sampledTypeId = 0; + uint32_t imageTypeId = 0; + uint32_t colorTypeId = 0; + uint32_t depthTypeId = 0; + uint32_t structStride = 0; + bool isRawSsbo = false; + }; + + + /** + * \brief Unordered access binding + * + * Stores a resource variable that is provided + * by a UAV, as well as associated type IDs. + */ + struct DxbcUav { + DxbcResourceType type = DxbcResourceType::Typed; + DxbcImageInfo imageInfo; + uint32_t varId = 0; + uint32_t ctrId = 0; + uint32_t specId = 0; + DxbcScalarType sampledType = DxbcScalarType::Float32; + uint32_t sampledTypeId = 0; + uint32_t imageTypeId = 0; + uint32_t structStride = 0; + uint32_t coherence = 0; + bool isRawSsbo = false; + }; + + + /** + * \brief Component swizzle + * + * Maps vector components to + * other vector components. + */ + class DxbcRegSwizzle { + + public: + + DxbcRegSwizzle() { } + DxbcRegSwizzle(uint32_t x, uint32_t y, uint32_t z, uint32_t w) + : m_mask((x << 0) | (y << 2) | (z << 4) | (w << 6)) { } + + uint32_t operator [] (uint32_t id) const { + return (m_mask >> (id + id)) & 0x3; + } + + bool operator == (const DxbcRegSwizzle& other) const { return m_mask == other.m_mask; } + bool operator != (const DxbcRegSwizzle& other) const { return m_mask != other.m_mask; } + + private: + + uint8_t m_mask = 0; + + }; + + + /** + * \brief Component mask + * + * Enables access to certain + * subset of vector components. + */ + class DxbcRegMask { + + public: + + DxbcRegMask() { } + DxbcRegMask(uint32_t mask) : m_mask(mask) { } + DxbcRegMask(bool x, bool y, bool z, bool w) + : m_mask((x ? 0x1 : 0) | (y ? 0x2 : 0) + | (z ? 0x4 : 0) | (w ? 0x8 : 0)) { } + + uint32_t raw() const { + return m_mask; + } + + bool operator [] (uint32_t id) const { + return (m_mask >> id) & 1; + } + + uint32_t popCount() const { + const uint8_t n[16] = { 0, 1, 1, 2, 1, 2, 2, 3, + 1, 2, 2, 3, 2, 3, 3, 4 }; + return n[m_mask & 0xF]; + } + + uint32_t firstSet() const { + const uint8_t n[16] = { 4, 0, 1, 0, 2, 0, 1, 0, + 3, 0, 1, 0, 2, 0, 1, 0 }; + return n[m_mask & 0xF]; + } + + uint32_t minComponents() const { + const uint8_t n[16] = { 0, 1, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4 }; + return n[m_mask & 0xF]; + } + + bool operator == (const DxbcRegMask& other) const { return m_mask == other.m_mask; } + bool operator != (const DxbcRegMask& other) const { return m_mask != other.m_mask; } + + DxbcRegMask& operator |= (const DxbcRegMask& other) { + m_mask |= other.m_mask; + return *this; + } + + static DxbcRegMask firstN(uint32_t n) { + return DxbcRegMask(n >= 1, n >= 2, n >= 3, n >= 4); + } + + static DxbcRegMask select(uint32_t n) { + return DxbcRegMask(n == 0, n == 1, n == 2, n == 3); + } + + std::string maskString() const { + std::string out = ""; + out += (m_mask & 0x1) ? "x" : ""; + out += (m_mask & 0x2) ? "y" : ""; + out += (m_mask & 0x4) ? "z" : ""; + out += (m_mask & 0x8) ? "w" : ""; + return out; + } + + explicit operator bool () const { + return m_mask != 0; + } + + private: + + uint8_t m_mask = 0; + + }; + + + /** + * \brief System value mapping + * + * Maps a system value to a given set of + * components of an input or output register. + */ + struct DxbcSvMapping { + uint32_t regId; + DxbcRegMask regMask; + DxbcSystemValue sv; + }; + + + struct DxbcRegIndex { + DxbcRegister* relReg; + int32_t offset; + }; + + + /** + * \brief Instruction operand + */ + struct DxbcRegister { + DxbcOperandType type; + DxbcScalarType dataType; + DxbcComponentCount componentCount; + + uint32_t idxDim; + DxbcRegIndex idx[DxbcMaxRegIndexDim]; + + DxbcRegMask mask; + DxbcRegSwizzle swizzle; + DxbcRegModifiers modifiers; + + union { + uint32_t u32_4[4]; + uint32_t u32_1; + } imm; + }; + + + /** + * \brief Instruction result modifiers + * + * Modifiers that are applied + * to all destination operands. + */ + struct DxbcOpModifiers { + bool saturate; + bool precise; + }; + + + /** + * \brief Opcode controls + * + * Instruction-specific controls. Usually, + * only one of the members will be valid. + */ + class DxbcShaderOpcodeControls { + + public: + + DxbcShaderOpcodeControls() + : m_bits(0) { } + + DxbcShaderOpcodeControls(uint32_t bits) + : m_bits(bits) { } + + DxbcInstructionReturnType returnType() const { + return DxbcInstructionReturnType(bit::extract(m_bits, 11, 11)); + } + + DxbcGlobalFlags globalFlags() const { + return DxbcGlobalFlags(bit::extract(m_bits, 11, 14)); + } + + DxbcZeroTest zeroTest() const { + return DxbcZeroTest(bit::extract(m_bits, 18, 18)); + } + + DxbcSyncFlags syncFlags() const { + return DxbcSyncFlags(bit::extract(m_bits, 11, 14)); + } + + DxbcResourceDim resourceDim() const { + return DxbcResourceDim(bit::extract(m_bits, 11, 15)); + } + + DxbcResinfoType resinfoType() const { + return DxbcResinfoType(bit::extract(m_bits, 11, 12)); + } + + DxbcInterpolationMode interpolation() const { + return DxbcInterpolationMode(bit::extract(m_bits, 11, 14)); + } + + DxbcSamplerMode samplerMode() const { + return DxbcSamplerMode(bit::extract(m_bits, 11, 14)); + } + + DxbcPrimitiveTopology primitiveTopology() const { + return DxbcPrimitiveTopology(bit::extract(m_bits, 11, 17)); + } + + DxbcPrimitive primitive() const { + return DxbcPrimitive(bit::extract(m_bits, 11, 16)); + } + + DxbcTessDomain tessDomain() const { + return DxbcTessDomain(bit::extract(m_bits, 11, 12)); + } + + DxbcTessOutputPrimitive tessOutputPrimitive() const { + return DxbcTessOutputPrimitive(bit::extract(m_bits, 11, 13)); + } + + DxbcTessPartitioning tessPartitioning() const { + return DxbcTessPartitioning(bit::extract(m_bits, 11, 13)); + } + + DxbcUavFlags uavFlags() const { + return DxbcUavFlags(bit::extract(m_bits, 16, 17)); + } + + DxbcConstantBufferAccessType accessType() const { + return DxbcConstantBufferAccessType(bit::extract(m_bits, 11, 11)); + } + + uint32_t controlPointCount() const { + return bit::extract(m_bits, 11, 16); + } + + bool precise() const { + return bit::extract(m_bits, 19, 22) != 0; + } + + private: + + uint32_t m_bits; + + }; + + + /** + * \brief Sample controls + * + * Constant texel offset with + * values raning from -8 to 7. + */ + struct DxbcShaderSampleControls { + int u, v, w; + }; + + + /** + * \brief Immediate value + * + * Immediate argument represented either + * as a 32-bit or 64-bit unsigned integer, + * or a 32-bit or 32-bit floating point number. + */ + union DxbcImmediate { + float f32; + double f64; + uint32_t u32; + uint64_t u64; + }; + + + /** + * \brief Shader instruction + * + * Note that this structure may store pointer to + * external structures, such as the original code + * buffer. This is safe to use if and only if: + * - The \ref DxbcDecodeContext that created it + * still exists and was not moved + * - The code buffer that was being decoded + * still exists and was not moved. + */ + struct DxbcShaderInstruction { + DxbcOpcode op; + DxbcInstClass opClass; + DxbcOpModifiers modifiers; + DxbcShaderOpcodeControls controls; + DxbcShaderSampleControls sampleControls; + + uint32_t dstCount; + uint32_t srcCount; + uint32_t immCount; + + const DxbcRegister* dst; + const DxbcRegister* src; + const DxbcImmediate* imm; + + DxbcCustomDataClass customDataType; + uint32_t customDataSize; + const uint32_t* customData; + }; + + + /** + * \brief DXBC code slice + * + * Convenient pointer pair that allows + * reading the code word stream safely. + */ + class DxbcCodeSlice { + + public: + + DxbcCodeSlice( + const uint32_t* ptr, + const uint32_t* end) + : m_ptr(ptr), m_end(end) { } + + const uint32_t* ptrAt(uint32_t id) const; + + uint32_t at(uint32_t id) const; + uint32_t read(); + + DxbcCodeSlice take(uint32_t n) const; + DxbcCodeSlice skip(uint32_t n) const; + + bool atEnd() const { + return m_ptr == m_end; + } + + private: + + const uint32_t* m_ptr = nullptr; + const uint32_t* m_end = nullptr; + + }; + + + /** + * \brief Decode context + * + * Stores data that is required to decode a single + * instruction. This data is not persistent, so it + * should be forwarded to the compiler right away. + */ + class DxbcDecodeContext { + + public: + + /** + * \brief Retrieves current instruction + * + * This is only valid after a call to \ref decode. + * \returns Reference to last decoded instruction + */ + const DxbcShaderInstruction& getInstruction() const { + return m_instruction; + } + + /** + * \brief Decodes an instruction + * + * This also advances the given code slice by the + * number of dwords consumed by the instruction. + * \param [in] code Code slice + */ + void decodeInstruction(DxbcCodeSlice& code); + + private: + + DxbcShaderInstruction m_instruction; + + std::array m_dstOperands; + std::array m_srcOperands; + std::array m_immOperands; + std::array m_indices; + + // Index into the indices array. Used when decoding + // instruction operands with relative indexing. + uint32_t m_indexId = 0; + + void decodeCustomData(DxbcCodeSlice code); + void decodeOperation(DxbcCodeSlice code); + + void decodeComponentSelection(DxbcRegister& reg, uint32_t token); + void decodeOperandExtensions(DxbcCodeSlice& code, DxbcRegister& reg, uint32_t token); + void decodeOperandImmediates(DxbcCodeSlice& code, DxbcRegister& reg); + void decodeOperandIndex(DxbcCodeSlice& code, DxbcRegister& reg, uint32_t token); + + void decodeRegister(DxbcCodeSlice& code, DxbcRegister& reg, DxbcScalarType type); + void decodeImm32(DxbcCodeSlice& code, DxbcImmediate& imm, DxbcScalarType type); + + void decodeOperand(DxbcCodeSlice& code, const DxbcInstOperandFormat& format); + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_defs.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_defs.h new file mode 100644 index 0000000000..8782481aff --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_defs.h @@ -0,0 +1,104 @@ +#pragma once + +#include "dxbc_enums.h" + +namespace dxvk { + + constexpr size_t DxbcMaxInterfaceRegs = 32; + constexpr size_t DxbcMaxOperandCount = 8; + + /** + * \brief Operand kind + * + * In the instruction format definition, this specified + * whether an operand uses an actual operand token, or + * whether it is stored as an immediate value. + */ + enum class DxbcOperandKind { + DstReg, ///< Destination register + SrcReg, ///< Source register + Imm32, ///< Constant number + }; + + /** + * \brief Instruction class + * + * Instructions with a similar format are grouped into + * instruction classes in order to make implementing + * new instructions easier. + */ + enum class DxbcInstClass { + Declaration, ///< Interface or resource declaration + CustomData, ///< Immediate constant buffer + ControlFlow, ///< Control flow instructions + GeometryEmit, ///< Special geometry shader instructions + Atomic, ///< Atomic operations + AtomicCounter, ///< Atomic counter operations + Barrier, ///< Execution or memory barrier + BitExtract, ///< Bit field extract operations + BitInsert, ///< Bit field insert operations + BitScan, ///< Bit scan operations + BufferQuery, ///< Buffer query instruction + BufferLoad, ///< Structured or raw buffer load + BufferStore, ///< Structured or raw buffer store + ConvertFloat16, ///< 16-bit float packing/unpacking + ConvertFloat64, ///< 64-bit float conversion + HullShaderPhase, ///< Hull shader phase declaration + HullShaderInstCnt, ///< Hull shader phase instance count + Interpolate, ///< Input attribute interpolation + NoOperation, ///< The most useful instruction class + SparseCheckAccess, ///< Verifies sparse resource access + TextureQuery, ///< Texture query instruction + TextureQueryLod, ///< Texture LOD query instruction + TextureQueryMs, ///< Multisample texture query + TextureQueryMsPos, ///< Sample position query + TextureFetch, ///< Texture fetch instruction + TextureGather, ///< Texture gather instruction + TextureSample, ///< Texture sampling instruction + TypedUavLoad, ///< Typed UAV load + TypedUavStore, ///< Typed UAV store + VectorAlu, ///< Component-wise vector instructions + VectorCmov, ///< Component-wise conditional move + VectorCmp, ///< Component-wise vector comparison + VectorDeriv, ///< Vector derivatives + VectorDot, ///< Dot product instruction + VectorIdiv, ///< Component-wise integer division + VectorImul, ///< Component-wise integer multiplication + VectorMsad, ///< Component-wise sum of absolute difference + VectorShift, ///< Bit shift operations on vectors + VectorSinCos, ///< Sine and Cosine instruction + Undefined, ///< Instruction code not defined + }; + + /** + * \brief Instruction operand format + * + * Stores the kind and the expected data type + * of an operand. Used when parsing instructions. + */ + struct DxbcInstOperandFormat { + DxbcOperandKind kind; + DxbcScalarType type; + }; + + /** + * \brief Instruction format + * + * Defines the instruction class as well as + * the format of the insttruction operands. + */ + struct DxbcInstFormat { + uint32_t operandCount = 0; + DxbcInstClass instructionClass = DxbcInstClass::Undefined; + DxbcInstOperandFormat operands[DxbcMaxOperandCount]; + }; + + /** + * \brief Retrieves instruction format info + * + * \param [in] opcode The opcode to retrieve + * \returns Instruction format info + */ + DxbcInstFormat dxbcInstructionFormat(DxbcOpcode opcode); + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_enums.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_enums.h new file mode 100644 index 0000000000..f6d29a5b87 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_enums.h @@ -0,0 +1,654 @@ +#pragma once + +#include "dxbc_include.h" + +namespace dxvk { + + /** + * \brief Instruction code listing + */ + enum class DxbcOpcode : uint32_t { + Add = 0, + And = 1, + Break = 2, + Breakc = 3, + Call = 4, + Callc = 5, + Case = 6, + Continue = 7, + Continuec = 8, + Cut = 9, + Default = 10, + DerivRtx = 11, + DerivRty = 12, + Discard = 13, + Div = 14, + Dp2 = 15, + Dp3 = 16, + Dp4 = 17, + Else = 18, + Emit = 19, + EmitThenCut = 20, + EndIf = 21, + EndLoop = 22, + EndSwitch = 23, + Eq = 24, + Exp = 25, + Frc = 26, + FtoI = 27, + FtoU = 28, + Ge = 29, + IAdd = 30, + If = 31, + IEq = 32, + IGe = 33, + ILt = 34, + IMad = 35, + IMax = 36, + IMin = 37, + IMul = 38, + INe = 39, + INeg = 40, + IShl = 41, + IShr = 42, + ItoF = 43, + Label = 44, + Ld = 45, + LdMs = 46, + Log = 47, + Loop = 48, + Lt = 49, + Mad = 50, + Min = 51, + Max = 52, + CustomData = 53, + Mov = 54, + Movc = 55, + Mul = 56, + Ne = 57, + Nop = 58, + Not = 59, + Or = 60, + ResInfo = 61, + Ret = 62, + Retc = 63, + RoundNe = 64, + RoundNi = 65, + RoundPi = 66, + RoundZ = 67, + Rsq = 68, + Sample = 69, + SampleC = 70, + SampleClz = 71, + SampleL = 72, + SampleD = 73, + SampleB = 74, + Sqrt = 75, + Switch = 76, + SinCos = 77, + UDiv = 78, + ULt = 79, + UGe = 80, + UMul = 81, + UMad = 82, + UMax = 83, + UMin = 84, + UShr = 85, + UtoF = 86, + Xor = 87, + DclResource = 88, + DclConstantBuffer = 89, + DclSampler = 90, + DclIndexRange = 91, + DclGsOutputPrimitiveTopology = 92, + DclGsInputPrimitive = 93, + DclMaxOutputVertexCount = 94, + DclInput = 95, + DclInputSgv = 96, + DclInputSiv = 97, + DclInputPs = 98, + DclInputPsSgv = 99, + DclInputPsSiv = 100, + DclOutput = 101, + DclOutputSgv = 102, + DclOutputSiv = 103, + DclTemps = 104, + DclIndexableTemp = 105, + DclGlobalFlags = 106, + Reserved0 = 107, + Lod = 108, + Gather4 = 109, + SamplePos = 110, + SampleInfo = 111, + Reserved1 = 112, + HsDecls = 113, + HsControlPointPhase = 114, + HsForkPhase = 115, + HsJoinPhase = 116, + EmitStream = 117, + CutStream = 118, + EmitThenCutStream = 119, + InterfaceCall = 120, + BufInfo = 121, + DerivRtxCoarse = 122, + DerivRtxFine = 123, + DerivRtyCoarse = 124, + DerivRtyFine = 125, + Gather4C = 126, + Gather4Po = 127, + Gather4PoC = 128, + Rcp = 129, + F32toF16 = 130, + F16toF32 = 131, + UAddc = 132, + USubb = 133, + CountBits = 134, + FirstBitHi = 135, + FirstBitLo = 136, + FirstBitShi = 137, + UBfe = 138, + IBfe = 139, + Bfi = 140, + BfRev = 141, + Swapc = 142, + DclStream = 143, + DclFunctionBody = 144, + DclFunctionTable = 145, + DclInterface = 146, + DclInputControlPointCount = 147, + DclOutputControlPointCount = 148, + DclTessDomain = 149, + DclTessPartitioning = 150, + DclTessOutputPrimitive = 151, + DclHsMaxTessFactor = 152, + DclHsForkPhaseInstanceCount = 153, + DclHsJoinPhaseInstanceCount = 154, + DclThreadGroup = 155, + DclUavTyped = 156, + DclUavRaw = 157, + DclUavStructured = 158, + DclThreadGroupSharedMemoryRaw = 159, + DclThreadGroupSharedMemoryStructured = 160, + DclResourceRaw = 161, + DclResourceStructured = 162, + LdUavTyped = 163, + StoreUavTyped = 164, + LdRaw = 165, + StoreRaw = 166, + LdStructured = 167, + StoreStructured = 168, + AtomicAnd = 169, + AtomicOr = 170, + AtomicXor = 171, + AtomicCmpStore = 172, + AtomicIAdd = 173, + AtomicIMax = 174, + AtomicIMin = 175, + AtomicUMax = 176, + AtomicUMin = 177, + ImmAtomicAlloc = 178, + ImmAtomicConsume = 179, + ImmAtomicIAdd = 180, + ImmAtomicAnd = 181, + ImmAtomicOr = 182, + ImmAtomicXor = 183, + ImmAtomicExch = 184, + ImmAtomicCmpExch = 185, + ImmAtomicIMax = 186, + ImmAtomicIMin = 187, + ImmAtomicUMax = 188, + ImmAtomicUMin = 189, + Sync = 190, + DAdd = 191, + DMax = 192, + DMin = 193, + DMul = 194, + DEq = 195, + DGe = 196, + DLt = 197, + DNe = 198, + DMov = 199, + DMovc = 200, + DtoF = 201, + FtoD = 202, + EvalSnapped = 203, + EvalSampleIndex = 204, + EvalCentroid = 205, + DclGsInstanceCount = 206, + Abort = 207, + DebugBreak = 208, + ReservedBegin11_1 = 209, + DDiv = 210, + DFma = 211, + DRcp = 212, + Msad = 213, + DtoI = 214, + DtoU = 215, + ItoD = 216, + UtoD = 217, + ReservedBegin11_2 = 218, + Gather4S = 219, + Gather4CS = 220, + Gather4PoS = 221, + Gather4PoCS = 222, + LdS = 223, + LdMsS = 224, + LdUavTypedS = 225, + LdRawS = 226, + LdStructuredS = 227, + SampleLS = 228, + SampleClzS = 229, + SampleClampS = 230, + SampleBClampS = 231, + SampleDClampS = 232, + SampleCClampS = 233, + CheckAccessFullyMapped = 234, + }; + + + /** + * \brief Extended opcode + */ + enum class DxbcExtOpcode : uint32_t { + Empty = 0, + SampleControls = 1, + ResourceDim = 2, + ResourceReturnType = 3, + }; + + + /** + * \brief Operand type + * + * Selects the 'register file' from which + * to retrieve an operand's value. + */ + enum class DxbcOperandType : uint32_t { + Temp = 0, + Input = 1, + Output = 2, + IndexableTemp = 3, + Imm32 = 4, + Imm64 = 5, + Sampler = 6, + Resource = 7, + ConstantBuffer = 8, + ImmediateConstantBuffer = 9, + Label = 10, + InputPrimitiveId = 11, + OutputDepth = 12, + Null = 13, + Rasterizer = 14, + OutputCoverageMask = 15, + Stream = 16, + FunctionBody = 17, + FunctionTable = 18, + Interface = 19, + FunctionInput = 20, + FunctionOutput = 21, + OutputControlPointId = 22, + InputForkInstanceId = 23, + InputJoinInstanceId = 24, + InputControlPoint = 25, + OutputControlPoint = 26, + InputPatchConstant = 27, + InputDomainPoint = 28, + ThisPointer = 29, + UnorderedAccessView = 30, + ThreadGroupSharedMemory = 31, + InputThreadId = 32, + InputThreadGroupId = 33, + InputThreadIdInGroup = 34, + InputCoverageMask = 35, + InputThreadIndexInGroup = 36, + InputGsInstanceId = 37, + OutputDepthGe = 38, + OutputDepthLe = 39, + CycleCounter = 40, + OutputStencilRef = 41, + InputInnerCoverage = 42, + }; + + + /** + * \brief Number of components + * + * Used by operands to determine whether the + * operand has one, four or zero components. + */ + enum class DxbcComponentCount : uint32_t { + Component0 = 0, + Component1 = 1, + Component4 = 2, + }; + + + /** + * \brief Component selection mode + * + * When an operand has four components, the + * component selection mode deterines which + * components are used for the operation. + */ + enum class DxbcRegMode : uint32_t { + Mask = 0, + Swizzle = 1, + Select1 = 2, + }; + + + /** + * \brief Index representation + * + * Determines how an operand + * register index is stored. + */ + enum class DxbcOperandIndexRepresentation : uint32_t { + Imm32 = 0, + Imm64 = 1, + Relative = 2, + Imm32Relative = 3, + Imm64Relative = 4, + }; + + + /** + * \brief Extended operand type + */ + enum class DxbcOperandExt : uint32_t { + OperandModifier = 1, + }; + + + /** + * \brief Resource dimension + * The type of a resource. + */ + enum class DxbcResourceDim : uint32_t { + Unknown = 0, + Buffer = 1, + Texture1D = 2, + Texture2D = 3, + Texture2DMs = 4, + Texture3D = 5, + TextureCube = 6, + Texture1DArr = 7, + Texture2DArr = 8, + Texture2DMsArr = 9, + TextureCubeArr = 10, + RawBuffer = 11, + StructuredBuffer = 12, + }; + + + /** + * \brief Resource return type + * Data type for resource read ops. + */ + enum class DxbcResourceReturnType : uint32_t { + Unorm = 1, + Snorm = 2, + Sint = 3, + Uint = 4, + Float = 5, + Mixed = 6, /// ? + Double = 7, + Continued = 8, /// ? + Unused = 9, /// ? + }; + + + /** + * \brief Register component type + * Data type of a register component. + */ + enum class DxbcRegisterComponentType : uint32_t { + Unknown = 0, + Uint32 = 1, + Sint32 = 2, + Float32 = 3, + }; + + + /** + * \brief Instruction return type + */ + enum class DxbcInstructionReturnType : uint32_t { + Float = 0, + Uint = 1, + }; + + + enum class DxbcSystemValue : uint32_t { + None = 0, + Position = 1, + ClipDistance = 2, + CullDistance = 3, + RenderTargetId = 4, + ViewportId = 5, + VertexId = 6, + PrimitiveId = 7, + InstanceId = 8, + IsFrontFace = 9, + SampleIndex = 10, + FinalQuadUeq0EdgeTessFactor = 11, + FinalQuadVeq0EdgeTessFactor = 12, + FinalQuadUeq1EdgeTessFactor = 13, + FinalQuadVeq1EdgeTessFactor = 14, + FinalQuadUInsideTessFactor = 15, + FinalQuadVInsideTessFactor = 16, + FinalTriUeq0EdgeTessFactor = 17, + FinalTriVeq0EdgeTessFactor = 18, + FinalTriWeq0EdgeTessFactor = 19, + FinalTriInsideTessFactor = 20, + FinalLineDetailTessFactor = 21, + FinalLineDensityTessFactor = 22, + Target = 64, + Depth = 65, + Coverage = 66, + DepthGe = 67, + DepthLe = 68 + }; + + + enum class DxbcInterpolationMode : uint32_t { + Undefined = 0, + Constant = 1, + Linear = 2, + LinearCentroid = 3, + LinearNoPerspective = 4, + LinearNoPerspectiveCentroid = 5, + LinearSample = 6, + LinearNoPerspectiveSample = 7, + }; + + + enum class DxbcGlobalFlag : uint32_t { + RefactoringAllowed = 0, + DoublePrecision = 1, + EarlyFragmentTests = 2, + RawStructuredBuffers = 3, + }; + + using DxbcGlobalFlags = Flags; + + enum class DxbcZeroTest : uint32_t { + TestZ = 0, + TestNz = 1, + }; + + enum class DxbcResinfoType : uint32_t { + Float = 0, + RcpFloat = 1, + Uint = 2, + }; + + enum class DxbcSyncFlag : uint32_t { + ThreadsInGroup = 0, + ThreadGroupSharedMemory = 1, + UavMemoryGroup = 2, + UavMemoryGlobal = 3, + }; + + using DxbcSyncFlags = Flags; + + + /** + * \brief Geometry shader input primitive + */ + enum class DxbcPrimitive : uint32_t { + Undefined = 0, + Point = 1, + Line = 2, + Triangle = 3, + LineAdj = 6, + TriangleAdj = 7, + Patch1 = 8, + Patch2 = 9, + Patch3 = 10, + Patch4 = 11, + Patch5 = 12, + Patch6 = 13, + Patch7 = 14, + Patch8 = 15, + Patch9 = 16, + Patch10 = 17, + Patch11 = 18, + Patch12 = 19, + Patch13 = 20, + Patch14 = 21, + Patch15 = 22, + Patch16 = 23, + Patch17 = 24, + Patch18 = 25, + Patch19 = 26, + Patch20 = 27, + Patch21 = 28, + Patch22 = 29, + Patch23 = 30, + Patch24 = 31, + Patch25 = 32, + Patch26 = 33, + Patch27 = 34, + Patch28 = 35, + Patch29 = 36, + Patch30 = 37, + Patch31 = 38, + Patch32 = 39, + }; + + + /** + * \brief Geometry shader output topology + */ + enum class DxbcPrimitiveTopology : uint32_t { + Undefined = 0, + PointList = 1, + LineList = 2, + LineStrip = 3, + TriangleList = 4, + TriangleStrip = 5, + LineListAdj = 10, + LineStripAdj = 11, + TriangleListAdj = 12, + TriangleStripAdj = 13, + }; + + + /** + * \brief Sampler operation mode + */ + enum class DxbcSamplerMode : uint32_t { + Default = 0, + Comparison = 1, + Mono = 2, + }; + + + /** + * \brief Scalar value type + * + * Enumerates possible register component + * types. Scalar types are represented as + * a one-component vector type. + */ + enum class DxbcScalarType : uint32_t { + Uint32 = 0, + Uint64 = 1, + Sint32 = 2, + Sint64 = 3, + Float32 = 4, + Float64 = 5, + Bool = 6, + }; + + + /** + * \brief Tessellator domain + */ + enum class DxbcTessDomain : uint32_t { + Undefined = 0, + Isolines = 1, + Triangles = 2, + Quads = 3, + }; + + /** + * \brief Tessellator partitioning + */ + enum class DxbcTessPartitioning : uint32_t { + Undefined = 0, + Integer = 1, + Pow2 = 2, + FractOdd = 3, + FractEven = 4, + }; + + /** + * \brief UAV definition flags + */ + enum class DxbcUavFlag : uint32_t { + GloballyCoherent = 0, + RasterizerOrdered = 1, + }; + + using DxbcUavFlags = Flags; + + /** + * \brief Tessellator output primitive + */ + enum class DxbcTessOutputPrimitive : uint32_t { + Undefined = 0, + Point = 1, + Line = 2, + TriangleCw = 3, + TriangleCcw = 4, + }; + + /** + * \brief Custom data class + * + * Stores which type of custom data is + * referenced by the instruction. + */ + enum class DxbcCustomDataClass : uint32_t { + Comment = 0, + DebugInfo = 1, + Opaque = 2, + ImmConstBuf = 3, + }; + + + enum class DxbcResourceType : uint32_t { + Typed = 0, + Raw = 1, + Structured = 2, + }; + + + enum class DxbcConstantBufferAccessType : uint32_t { + StaticallyIndexed = 0, + DynamicallyIndexed = 1, + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_header.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_header.h new file mode 100644 index 0000000000..8eca0d499c --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_header.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +#include "dxbc_reader.h" + +namespace dxvk { + + /** + * \brief DXBC header + * + * Stores information about the shader file itself + * and the data chunks stored inside the file. + */ + class DxbcHeader { + + public: + + DxbcHeader(DxbcReader& reader); + ~DxbcHeader(); + + /** + * \brief Number of chunks + * \returns Chunk count + */ + uint32_t numChunks() const { + return m_chunkOffsets.size(); + } + + /** + * \brief Chunk offset + * + * Retrieves the offset of a chunk, in + * bytes, from the start of the file. + * \param [in] chunkId Chunk index + * \returns Byte offset of that chunk + */ + uint32_t chunkOffset(uint32_t chunkId) const { + return m_chunkOffsets.at(chunkId); + } + + private: + + std::vector m_chunkOffsets; + + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_include.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_include.h new file mode 100644 index 0000000000..b33162227e --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_include.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include "dxvk_limits.h" +#include "dxvk_pipelayout.h" + +#include "log/log.h" +#include "log/log_debug.h" + +#include "rc/util_rc.h" +#include "rc/util_rc_ptr.h" + +#include "util_bit.h" +#include "util_enum.h" +#include "util_error.h" +#include "util_string.h" +#include "util_flags.h" +#include "util_small_vector.h" diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_modinfo.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_modinfo.h new file mode 100644 index 0000000000..13e733dde2 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_modinfo.h @@ -0,0 +1,59 @@ +#pragma once + +#include "dxbc_options.h" + +namespace dxvk { + + /** + * \brief Tessellation info + * + * Stores the maximum tessellation factor + * to export from tessellation shaders. + */ + struct DxbcTessInfo { + float maxTessFactor; + }; + + /** + * \brief Xfb capture entry + * + * Stores an output variable to capture, + * as well as the buffer to write it to. + */ + struct DxbcXfbEntry { + const char* semanticName; + uint32_t semanticIndex; + uint32_t componentIndex; + uint32_t componentCount; + uint32_t streamId; + uint32_t bufferId; + uint32_t offset; + }; + + /** + * \brief Xfb info + * + * Stores capture entries and output buffer + * strides. This structure must only be + * defined if \c entryCount is non-zero. + */ + struct DxbcXfbInfo { + uint32_t entryCount; + DxbcXfbEntry entries[128]; + uint32_t strides[4]; + int32_t rasterizedStream; + }; + + /** + * \brief Shader module info + * + * Stores information which may affect shader compilation. + * This data can be supplied by the client API implementation. + */ + struct DxbcModuleInfo { + DxbcOptions options; + DxbcTessInfo* tess; + DxbcXfbInfo* xfb; + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_module.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_module.h new file mode 100644 index 0000000000..3ef75cfe17 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_module.h @@ -0,0 +1,137 @@ +#pragma once + +#include "dxbc_chunk_isgn.h" +#include "dxbc_chunk_shex.h" +#include "dxbc_header.h" +#include "dxbc_modinfo.h" +#include "dxbc_reader.h" +#include "dxbc_util.h" + +#include "spirv_code_buffer.h" + +#include + +// References used for figuring out DXBC: +// - https://github.com/tgjones/slimshader-cpp +// - Wine + +namespace dxvk { + + class DxbcAnalyzer; + class DxbcCompiler; + + /** + * \brief Immediate constant buffer properties + */ + struct DxbcIcbInfo { + size_t size = 0u; + const void* data = nullptr; + }; + + + /** + * \brief DXBC shader module + * + * Reads the DXBC byte code and extracts information + * about the resource bindings and the instruction + * stream. A module can then be compiled to SPIR-V. + */ + class DxbcModule { + + public: + + DxbcModule(DxbcReader& reader); + ~DxbcModule(); + + /** + * \brief Shader type + * \returns Shader type + */ + std::optional programInfo() const { + if (m_shexChunk == nullptr) + return std::nullopt; + + return m_shexChunk->programInfo(); + } + + /** + * \brief Queries shader binding mask + * + * Only valid after successfully compiling the shader. + */ + std::optional bindings() const { + return m_bindings; + } + + /** + * \brief Retrieves immediate constant buffer info + * + * Only valid after successfully compiling the shader. + * \returns Immediate constant buffer data + */ + DxbcIcbInfo icbInfo() const { + DxbcIcbInfo result = { }; + result.size = m_icb.size() * sizeof(uint32_t); + result.data = m_icb.data(); + return result; + } + + /** + * \brief Input and output signature chunks + * + * Parts of the D3D11 API need access to the + * input or output signature of the shader. + */ + Rc isgn() const { return m_isgnChunk; } + Rc osgn() const { return m_osgnChunk; } + + /** + * \brief Compiles DXBC shader to SPIR-V module + * + * \param [in] moduleInfo DXBC module info + * \param [in] fileName File name, will be added to + * the compiled SPIR-V for debugging purposes. + * \returns The compiled shader object + */ + SpirvCodeBuffer compile( + const DxbcModuleInfo& moduleInfo, + const std::string& fileName); + + /** + * \brief Compiles a pass-through geometry shader + * + * Applications can pass a vertex shader to create + * a geometry shader with stream output. In this + * case, we have to create a passthrough geometry + * shader, which operates in point to point mode. + * \param [in] moduleInfo DXBC module info + * \param [in] fileName SPIR-V shader name + */ + SpirvCodeBuffer compilePassthroughShader( + const DxbcModuleInfo& moduleInfo, + const std::string& fileName) const; + + private: + + DxbcHeader m_header; + + Rc m_isgnChunk; + Rc m_osgnChunk; + Rc m_psgnChunk; + Rc m_shexChunk; + + std::vector m_icb; + + std::optional m_bindings; + + void runAnalyzer( + DxbcAnalyzer& analyzer, + DxbcCodeSlice slice) const; + + void runCompiler( + DxbcCompiler& compiler, + DxbcCodeSlice slice) const; + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_names.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_names.h new file mode 100644 index 0000000000..52235ae593 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_names.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include "dxbc_common.h" +#include "dxbc_enums.h" + +namespace dxvk { + + std::ostream& operator << (std::ostream& os, DxbcOpcode e); + std::ostream& operator << (std::ostream& os, DxbcExtOpcode e); + std::ostream& operator << (std::ostream& os, DxbcOperandType e); + std::ostream& operator << (std::ostream& os, DxbcOperandExt e); + std::ostream& operator << (std::ostream& os, DxbcComponentCount e); + std::ostream& operator << (std::ostream& os, DxbcRegMode e); + std::ostream& operator << (std::ostream& os, DxbcOperandIndexRepresentation e); + std::ostream& operator << (std::ostream& os, DxbcResourceDim e); + std::ostream& operator << (std::ostream& os, DxbcResourceReturnType e); + std::ostream& operator << (std::ostream& os, DxbcRegisterComponentType e); + std::ostream& operator << (std::ostream& os, DxbcInstructionReturnType e); + std::ostream& operator << (std::ostream& os, DxbcSystemValue e); + std::ostream& operator << (std::ostream& os, DxbcProgramType e); + std::ostream& operator << (std::ostream& os, DxbcCustomDataClass e); + std::ostream& operator << (std::ostream& os, DxbcScalarType e); + +} // namespace dxvk diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_options.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_options.h new file mode 100644 index 0000000000..0fe46a767a --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_options.h @@ -0,0 +1,74 @@ +#pragma once + +#include + +#include "util_flags.h" + +namespace dxvk { + + struct D3D11Options; + + enum class DxbcFloatControlFlag : uint32_t { + DenormFlushToZero32, + DenormPreserve64, + PreserveNan32, + PreserveNan64, + }; + + using DxbcFloatControlFlags = Flags; + + struct DxbcOptions { + DxbcOptions() {} + + // Clamp oDepth in fragment shaders if the depth + // clip device feature is not supported + bool useDepthClipWorkaround = false; + + /// Determines whether format qualifiers + /// on typed UAV loads are required + bool supportsTypedUavLoadR32 = false; + + /// Determines whether raw access chains are supported + bool supportsRawAccessChains = false; + + /// Clear thread-group shared memory to zero + bool zeroInitWorkgroupMemory = false; + + /// Declare vertex positions as invariant + bool invariantPosition = false; + + /// Insert memory barriers after TGSM stoes + bool forceVolatileTgsmAccess = false; + + /// Try to detect hazards in UAV access and insert + /// barriers when we know control flow is uniform. + bool forceComputeUavBarriers = false; + + /// Replace ld_ms with ld + bool disableMsaa = false; + + /// Force sample rate shading by using sample + /// interpolation for fragment shader inputs + bool forceSampleRateShading = false; + + // Enable per-sample interlock if supported + bool enableSampleShadingInterlock = false; + + /// Use tightly packed arrays for immediate + /// constant buffers if possible + bool supportsTightIcbPacking = false; + + /// Whether exporting point size is required + bool needsPointSizeExport = true; + + /// Whether to enable sincos emulation + bool sincosEmulation = false; + + /// Float control flags + DxbcFloatControlFlags floatControl; + + /// Minimum storage buffer alignment + VkDeviceSize minSsboAlignment = 0; + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_reader.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_reader.h new file mode 100644 index 0000000000..a16000179b --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_reader.h @@ -0,0 +1,78 @@ +#pragma once + +#include +#include + +#include "dxbc_tag.h" + +namespace dxvk { + + /** + * \brief DXBC bytecode reader + * + * Holds references to the shader byte code and + * provides methods to read + */ + class DxbcReader { + + public: + + DxbcReader(const char* data, size_t size) + : DxbcReader(data, size, 0) { } + + auto readu8 () { return this->readNum (); } + auto readu16() { return this->readNum(); } + auto readu32() { return this->readNum(); } + auto readu64() { return this->readNum(); } + + auto readi8 () { return this->readNum (); } + auto readi16() { return this->readNum (); } + auto readi32() { return this->readNum (); } + auto readi64() { return this->readNum (); } + + auto readf32() { return this->readNum (); } + auto readf64() { return this->readNum (); } + + template + auto readEnum() { + using Tx = std::underlying_type_t; + return static_cast(this->readNum()); + } + + DxbcTag readTag(); + + std::string readString(); + + void read(void* dst, size_t n); + + void skip(size_t n); + + DxbcReader clone(size_t pos) const; + + DxbcReader resize(size_t size) const; + + bool eof() const { + return m_pos >= m_size; + } + + void store(std::ostream&& stream) const; + + private: + + DxbcReader(const char* data, size_t size, size_t pos) + : m_data(data), m_size(size), m_pos(pos) { } + + const char* m_data = nullptr; + size_t m_size = 0; + size_t m_pos = 0; + + template + T readNum() { + T result; + this->read(&result, sizeof(result)); + return result; + } + + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_tag.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_tag.h new file mode 100644 index 0000000000..2ba17509c5 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_tag.h @@ -0,0 +1,47 @@ +#pragma once + +#include "dxbc_include.h" + +namespace dxvk { + + /** + * \brief Four-character tag + * + * Used to identify chunks in the + * compiled DXBC file by name. + */ + class DxbcTag { + + public: + + DxbcTag() { + for (size_t i = 0; i < 4; i++) + m_chars[i] = '\0'; + } + + DxbcTag(const char* tag) { + for (size_t i = 0; i < 4; i++) + m_chars[i] = tag[i]; + } + + bool operator == (const DxbcTag& other) const { + bool result = true; + for (size_t i = 0; i < 4; i++) + result &= m_chars[i] == other.m_chars[i]; + return result; + } + + bool operator != (const DxbcTag& other) const { + return !this->operator == (other); + } + + const char* operator & () const { return m_chars; } + char* operator & () { return m_chars; } + + private: + + char m_chars[4]; + + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_util.h b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_util.h new file mode 100644 index 0000000000..7d98af6ee3 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxbc/dxbc_util.h @@ -0,0 +1,164 @@ +#pragma once + +#include "dxbc_common.h" +#include "dxbc_enums.h" + +namespace dxvk { + + /** + * \brief Push constant struct + */ + struct DxbcPushConstants { + uint32_t rasterizerSampleCount; + }; + + + /** + * \brief Binding numbers and properties + */ + enum DxbcBindingProperties : uint32_t { + DxbcConstBufBindingIndex = 0, + DxbcConstBufBindingCount = 16, + DxbcSamplerBindingIndex = DxbcConstBufBindingIndex + + DxbcConstBufBindingCount, + DxbcSamplerBindingCount = 16, + DxbcResourceBindingIndex = DxbcSamplerBindingIndex + + DxbcSamplerBindingCount, + DxbcResourceBindingCount = 128, + DxbcStageBindingCount = DxbcConstBufBindingCount + + DxbcSamplerBindingCount + + DxbcResourceBindingCount, + DxbcUavBindingIndex = DxbcStageBindingCount * 6, + DxbcUavBindingCount = 64, + }; + + + /** + * \brief Shader binding mask + * + * Stores a bit masks of resource bindings + * that are accessed by any given shader. + */ + struct DxbcBindingMask { + uint32_t cbvMask = 0u; + uint32_t samplerMask = 0u; + uint64_t uavMask = 0u; + std::array srvMask = { }; + + void reset() { + cbvMask = 0u; + samplerMask = 0u; + uavMask = 0u; + srvMask = { }; + } + + bool empty() const { + uint64_t mask = (uint64_t(cbvMask) | uint64_t(samplerMask) << 32u) + | (uavMask | srvMask[0] | srvMask[1]); + return !mask; + } + + DxbcBindingMask operator & (const DxbcBindingMask& other) const { + DxbcBindingMask result = *this; + result.cbvMask &= other.cbvMask; + result.samplerMask &= other.samplerMask; + result.uavMask &= other.uavMask; + result.srvMask[0] &= other.srvMask[0]; + result.srvMask[1] &= other.srvMask[1]; + return result; + } + }; + + + /** + * \brief Computes first binding index for a given stage + * + * \param [in] stage The shader stage + * \returns Index of first binding + */ + inline uint32_t computeStageBindingOffset(DxbcProgramType stage) { + return DxbcStageBindingCount * uint32_t(stage); + } + + + /** + * \brief Computes first UAV binding index offset for a given stage + * + * \param [in] stage The shader stage + * \returns Index of first UAV binding + */ + inline uint32_t computeStageUavBindingOffset(DxbcProgramType stage) { + return DxbcUavBindingIndex + + DxbcUavBindingCount * (stage == DxbcProgramType::ComputeShader ? 2 : 0); + } + + + /** + * \brief Computes constant buffer binding index + * + * \param [in] stage Shader stage + * \param [in] index Constant buffer index + * \returns Binding index + */ + inline uint32_t computeConstantBufferBinding(DxbcProgramType stage, uint32_t index) { + return computeStageBindingOffset(stage) + DxbcConstBufBindingIndex + index; + } + + + /** + * \brief Computes sampler binding index + * + * \param [in] stage Shader stage + * \param [in] index Sampler index + * \returns Binding index + */ + inline uint32_t computeSamplerBinding(DxbcProgramType stage, uint32_t index) { + return computeStageBindingOffset(stage) + DxbcSamplerBindingIndex + index; + } + + + /** + * \brief Computes resource binding index + * + * \param [in] stage Shader stage + * \param [in] index Resource index + * \returns Binding index + */ + inline uint32_t computeSrvBinding(DxbcProgramType stage, uint32_t index) { + return computeStageBindingOffset(stage) + DxbcResourceBindingIndex + index; + } + + + /** + * \brief Computes UAV binding offset + * + * \param [in] stage Shader stage + * \param [in] index UAV index + * \returns Binding index + */ + inline uint32_t computeUavBinding(DxbcProgramType stage, uint32_t index) { + return computeStageUavBindingOffset(stage) + index; + } + + + /** + * \brief Computes UAV counter binding offset + * + * \param [in] stage Shader stage + * \param [in] index UAV index + * \returns Binding index + */ + inline uint32_t computeUavCounterBinding(DxbcProgramType stage, uint32_t index) { + return computeStageUavBindingOffset(stage) + DxbcUavBindingCount + index; + } + + /** + * \brief Primitive vertex count + * + * Calculates the number of vertices + * for a given primitive type. + */ + uint32_t primitiveVertexCount( + DxbcPrimitive primitive); + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_hash.h b/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_hash.h new file mode 100644 index 0000000000..120e268cb2 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_hash.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +namespace dxvk { + + struct DxvkEq { + template + size_t operator () (const T& a, const T& b) const { + return a.eq(b); + } + }; + + struct DxvkHash { + template + size_t operator () (const T& object) const { + return object.hash(); + } + }; + + class DxvkHashState { + + public: + + void add(size_t hash) { + m_value ^= hash + 0x9e3779b9 + + (m_value << 6) + + (m_value >> 2); + } + + operator size_t () const { + return m_value; + } + + private: + + size_t m_value = 0; + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_limits.h b/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_limits.h new file mode 100644 index 0000000000..4903c32cef --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_limits.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace dxvk { + + enum DxvkLimits : size_t { + MaxNumRenderTargets = 8, + MaxNumVertexAttributes = 32, + MaxNumVertexBindings = 32, + MaxNumXfbBuffers = 4, + MaxNumXfbStreams = 4, + MaxNumViewports = 16, + MaxNumResourceSlots = 1216, + MaxNumQueuedCommandBuffers = 32, + MaxNumQueryCountPerPool = 128, + MaxNumSpecConstants = 12, + MaxUniformBufferSize = 65536, + MaxVertexBindingStride = 2048, + MaxPushConstantSize = 128, + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_pipelayout.h b/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_pipelayout.h new file mode 100644 index 0000000000..9873719c70 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/dxvk/dxvk_pipelayout.h @@ -0,0 +1,107 @@ +#pragma once + +#include + +#include + +#include "dxvk_hash.h" + +#include "util_math.h" +#include "util_bit.h" +#include "util_flags.h" + +namespace dxvk { + + class DxvkDevice; + class DxvkPipelineManager; + + /** + * \brief Order-invariant atomic access operation + * + * Information used to optimize barriers when a resource + * is accessed exlusively via order-invariant stores. + */ + struct DxvkAccessOp { + enum OpType : uint16_t { + None = 0x0u, + Or = 0x1u, + And = 0x2u, + Xor = 0x3u, + Add = 0x4u, + IMin = 0x5u, + IMax = 0x6u, + UMin = 0x7u, + UMax = 0x8u, + + StoreF = 0xdu, + StoreUi = 0xeu, + StoreSi = 0xfu, + }; + + DxvkAccessOp() = default; + DxvkAccessOp(OpType t) + : op(uint16_t(t)) { } + + DxvkAccessOp(OpType t, uint16_t constant) + : op(uint16_t(t) | (constant << 4u)) { } + + uint16_t op = 0u; + + bool operator == (const DxvkAccessOp& t) const { return op == t.op; } + bool operator != (const DxvkAccessOp& t) const { return op != t.op; } + + template, bool> = true> + explicit operator T() const { return op; } + }; + + static_assert(sizeof(DxvkAccessOp) == sizeof(uint16_t)); + + /** + * \brief Binding info + * + * Stores metadata for a single binding in + * a given shader, or for the whole pipeline. + */ + struct DxvkBindingInfo { + VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_MAX_ENUM; ///< Vulkan descriptor type + uint32_t resourceBinding = 0u; ///< API binding slot for the resource + VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_MAX_ENUM; ///< Image view type + VkShaderStageFlagBits stage = VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM; ///< Shader stage + VkAccessFlags access = 0u; ///< Access mask for the resource + DxvkAccessOp accessOp = DxvkAccessOp::None; ///< Order-invariant store type, if any + bool uboSet = false; ///< Whether to include this in the UBO set + bool isMultisampled = false; ///< Multisampled binding + + /** + * \brief Computes descriptor set index for the given binding + * + * This is determines based on the shader stages that use the binding. + * \returns Descriptor set index + */ + uint32_t computeSetIndex() const; + + /** + * \brief Numeric value of the binding + * + * Used when sorting bindings. + * \returns Numeric value + */ + uint32_t value() const; + + /** + * \brief Checks for equality + * + * \param [in] other Binding to compare to + * \returns \c true if both bindings are equal + */ + bool eq(const DxvkBindingInfo& other) const; + + /** + * \brief Hashes binding info + * \returns Binding hash + */ + size_t hash() const; + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_code_buffer.h b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_code_buffer.h new file mode 100644 index 0000000000..4e33d6dcb0 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_code_buffer.h @@ -0,0 +1,236 @@ +#pragma once + +#include +#include +#include + +#include "spirv_instruction.h" + +namespace dxvk { + + /** + * \brief SPIR-V code buffer + * + * Helper class for generating SPIR-V shaders. + * Stores arbitrary SPIR-V instructions in a + * format that can be read by Vulkan drivers. + */ + class SpirvCodeBuffer { + + public: + + SpirvCodeBuffer(); + explicit SpirvCodeBuffer(uint32_t size); + SpirvCodeBuffer(const SpirvCodeBuffer &) = default; + SpirvCodeBuffer(SpirvCodeBuffer &&) = default; + SpirvCodeBuffer(uint32_t size, const uint32_t* data); + SpirvCodeBuffer(std::istream& stream); + + template + SpirvCodeBuffer(const uint32_t (&data)[N]) + : SpirvCodeBuffer(N, data) { } + + ~SpirvCodeBuffer(); + + SpirvCodeBuffer &operator=(const SpirvCodeBuffer &) = default; + SpirvCodeBuffer &operator=(SpirvCodeBuffer &&) = default; + + /** + * \brief Code data + * \returns Code data + */ + const uint32_t* data() const { return m_code.data(); } + uint32_t* data() { return m_code.data(); } + + /** + * \brief Code size, in dwords + * \returns Code size, in dwords + */ + uint32_t dwords() const { + return m_code.size(); + } + + /** + * \brief Code size, in bytes + * \returns Code size, in bytes + */ + size_t size() const { + return m_code.size() * sizeof(uint32_t); + } + + /** + * \brief Begin instruction iterator + * + * Points to the first instruction in the instruction + * block. The header, if any, will be skipped over. + * \returns Instruction iterator + */ + SpirvInstructionIterator begin() { + return SpirvInstructionIterator( + m_code.data(), 0, m_code.size()); + } + + /** + * \brief End instruction iterator + * + * Points to the end of the instruction block. + * \returns Instruction iterator + */ + SpirvInstructionIterator end() { + return SpirvInstructionIterator(nullptr, 0, 0); + } + + /** + * \brief Allocates a new ID + * + * Returns a new valid ID and increments the + * maximum ID count stored in the header. + * \returns The new SPIR-V ID + */ + uint32_t allocId(); + + /** + * \brief Appends an instruction + * + * Slightly faster than individually adding words. + * \param [in] ins Instruction + */ + void append(const SpirvInstruction& ins); + + /** + * \brief Merges two code buffers + * + * This is useful to generate declarations or + * the SPIR-V header at the same time as the + * code when doing so in advance is impossible. + * \param [in] other Code buffer to append + */ + void append(const SpirvCodeBuffer& other); + + /** + * \brief Appends an 32-bit word to the buffer + * \param [in] word The word to append + */ + void putWord(uint32_t word); + + /** + * \brief Appends an instruction word to the buffer + * + * Adds a single word containing both the word count + * and the op code number for a single instruction. + * \param [in] opCode Operand code + * \param [in] wordCount Number of words + */ + void putIns(spv::Op opCode, uint16_t wordCount); + + /** + * \brief Appends a 32-bit integer to the buffer + * \param [in] value The number to add + */ + void putInt32(uint32_t word); + + /** + * \brief Appends a 64-bit integer to the buffer + * + * A 64-bit integer will take up two 32-bit words. + * \param [in] value 64-bit value to add + */ + void putInt64(uint64_t value); + + /** + * \brief Appends a 32-bit float to the buffer + * \param [in] value The number to add + */ + void putFloat32(float value); + + /** + * \brief Appends a 64-bit float to the buffer + * \param [in] value The number to add + */ + void putFloat64(double value); + + /** + * \brief Appends a literal string to the buffer + * \param [in] str String to append to the buffer + */ + void putStr(const char* str); + + /** + * \brief Adds the header to the buffer + * + * \param [in] version SPIR-V version + * \param [in] boundIds Number of bound IDs + */ + void putHeader(uint32_t version, uint32_t boundIds); + + /** + * \brief Erases given number of dwords + * + * Removes data from the code buffer, starting + * at the current insertion offset. + * \param [in] size Number of words to remove + */ + void erase(size_t size); + + /** + * \brief Computes length of a literal string + * + * \param [in] str The string to check + * \returns Number of words consumed by a string + */ + uint32_t strLen(const char* str); + + /** + * \brief Stores the SPIR-V module to a stream + * + * The ability to save modules to a file + * exists mostly for debugging purposes. + * \param [in] stream Output stream + */ + void store(std::ostream& stream) const; + + /** + * \brief Retrieves current insertion pointer + * + * Sometimes it may be necessay to insert code into the + * middle of the stream rather than appending it. This + * retrieves the current function pointer. Note that the + * pointer will become invalid if any code is inserted + * before the current pointer location. + * \returns Current instruction pointr + */ + size_t getInsertionPtr() const { + return m_ptr; + } + + /** + * \brief Sets insertion pointer to a specific value + * + * Sets the insertion pointer to a value that was + * previously retrieved by \ref getInsertionPtr. + * \returns Current instruction pointr + */ + void beginInsertion(size_t ptr) { + m_ptr = ptr; + } + + /** + * \brief Sets insertion pointer to the end + * + * After this call, new instructions will be + * appended to the stream. In other words, + * this will restore default behaviour. + * \returns Previous instruction pointer + */ + size_t endInsertion() { + return std::exchange(m_ptr, m_code.size()); + } + + private: + + std::vector m_code; + size_t m_ptr = 0; + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_include.h b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_include.h new file mode 100644 index 0000000000..36651dcb17 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_include.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include "log/log.h" +#include "log/log_debug.h" + +#include "util_error.h" +#include "util_flags.h" +#include "util_likely.h" +#include "util_string.h" + +#include "rc/util_rc.h" +#include "rc/util_rc_ptr.h" diff --git a/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_instruction.h b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_instruction.h new file mode 100644 index 0000000000..1f93141578 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_instruction.h @@ -0,0 +1,158 @@ +#pragma once + +#include "spirv_include.h" + +namespace dxvk { + + /** + * \brief SPIR-V instruction + * + * Helps parsing a single instruction, providing + * access to the op code, instruction length and + * instruction arguments. + */ + class SpirvInstruction { + + public: + + SpirvInstruction() { } + SpirvInstruction(uint32_t* code, uint32_t offset, uint32_t length) + : m_code(code), m_offset(offset), m_length(length) { } + + /** + * \brief SPIR-V Op code + * \returns The op code + */ + spv::Op opCode() const { + return static_cast( + this->arg(0) & spv::OpCodeMask); + } + + /** + * \brief Instruction length + * \returns Number of DWORDs + */ + uint32_t length() const { + return this->arg(0) >> spv::WordCountShift; + } + + /** + * \brief Instruction offset + * \returns Offset in DWORDs + */ + uint32_t offset() const { + return m_offset; + } + + /** + * \brief Argument value + * + * Retrieves an argument DWORD. Note that some instructions + * take 64-bit arguments which require more than one DWORD. + * Arguments start at index 1. Calling this method with an + * argument ID of 0 will return the opcode token. + * \param [in] idx Argument index, starting at 1 + * \returns The argument value + */ + uint32_t arg(uint32_t idx) const { + const uint32_t index = m_offset + idx; + return index < m_length ? m_code[index] : 0; + } + + /** + * \brief Argument string + * + * Retrieves a pointer to a UTF-8-encoded string. + * \param [in] idx Argument index, starting at 1 + * \returns Pointer to the literal string + */ + const char* chr(uint32_t idx) const { + const uint32_t index = m_offset + idx; + return index < m_length ? reinterpret_cast(&m_code[index]) : nullptr; + } + + /** + * \brief Changes the value of an argument + * + * \param [in] idx Argument index, starting at 1 + * \param [in] word New argument word + */ + void setArg(uint32_t idx, uint32_t word) const { + if (m_offset + idx < m_length) + m_code[m_offset + idx] = word; + } + + private: + + uint32_t* m_code = nullptr; + uint32_t m_offset = 0; + uint32_t m_length = 0; + + }; + + + /** + * \brief SPIR-V instruction iterator + * + * Convenient iterator that can be used + * to process raw SPIR-V shader code. + */ + class SpirvInstructionIterator { + + public: + + SpirvInstructionIterator() { } + SpirvInstructionIterator(uint32_t* code, uint32_t offset, uint32_t length) + : m_code (length != 0 ? code : nullptr), + m_offset(length != 0 ? offset : 0), + m_length(length) { + if ((length >= 5) && (offset == 0) && (m_code[0] == spv::MagicNumber)) + this->advance(5); + } + + SpirvInstructionIterator& operator ++ () { + this->advance(SpirvInstruction(m_code, m_offset, m_length).length()); + return *this; + } + + SpirvInstructionIterator operator ++ (int) { + SpirvInstructionIterator result = *this; + this->advance(SpirvInstruction(m_code, m_offset, m_length).length()); + return result; + } + + SpirvInstruction operator * () const { + return SpirvInstruction(m_code, m_offset, m_length); + } + + bool operator == (const SpirvInstructionIterator& other) const { + return this->m_code == other.m_code + && this->m_offset == other.m_offset + && this->m_length == other.m_length; + } + + bool operator != (const SpirvInstructionIterator& other) const { + return this->m_code != other.m_code + || this->m_offset != other.m_offset + || this->m_length != other.m_length; + } + + private: + + uint32_t* m_code = nullptr; + uint32_t m_offset = 0; + uint32_t m_length = 0; + + void advance(uint32_t n) { + if (m_offset + n < m_length) { + m_offset += n; + } else { + m_code = nullptr; + m_offset = 0; + m_length = 0; + } + } + + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_module.h b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_module.h new file mode 100644 index 0000000000..02b7b7cf77 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/spirv/spirv_module.h @@ -0,0 +1,1350 @@ +#pragma once + +#include +#include +#include + +#include "spirv_code_buffer.h" + +namespace dxvk { + + struct SpirvPhiLabel { + uint32_t varId = 0; + uint32_t labelId = 0; + }; + + struct SpirvSwitchCaseLabel { + uint32_t literal = 0; + uint32_t labelId = 0; + }; + + struct SpirvMemoryOperands { + uint32_t flags = 0; + uint32_t alignment = 0; + uint32_t makeAvailable = 0; + uint32_t makeVisible = 0; + }; + + struct SpirvImageOperands { + uint32_t flags = 0; + uint32_t sLodBias = 0; + uint32_t sLod = 0; + uint32_t sConstOffset = 0; + uint32_t sGradX = 0; + uint32_t sGradY = 0; + uint32_t gOffset = 0; + uint32_t gConstOffsets = 0; + uint32_t sSampleId = 0; + uint32_t sMinLod = 0; + uint32_t makeAvailable = 0; + uint32_t makeVisible = 0; + bool sparse = false; + }; + + constexpr uint32_t spvVersion(uint32_t major, uint32_t minor) { + return (major << 16) | (minor << 8); + } + + /** + * \brief SPIR-V module + * + * This class generates a code buffer containing a full + * SPIR-V shader module. Ensures that the module layout + * is valid, as defined in the SPIR-V 1.0 specification, + * section 2.4 "Logical Layout of a Module". + */ + class SpirvModule { + + public: + + explicit SpirvModule(uint32_t version); + + ~SpirvModule(); + + SpirvCodeBuffer compile(); + + size_t getInsertionPtr() { + return m_code.getInsertionPtr(); + } + + void beginInsertion(size_t ptr) { + m_code.beginInsertion(ptr); + } + + void endInsertion() { + m_code.endInsertion(); + } + + uint32_t getBlockId() const { + return m_blockId; + } + + uint32_t allocateId(); + + bool hasCapability( + spv::Capability capability); + + void enableCapability( + spv::Capability capability); + + void enableExtension( + const char* extensionName); + + void addEntryPoint( + uint32_t entryPointId, + spv::ExecutionModel executionModel, + const char* name); + + void setMemoryModel( + spv::AddressingModel addressModel, + spv::MemoryModel memoryModel); + + void setExecutionMode( + uint32_t entryPointId, + spv::ExecutionMode executionMode); + + void setExecutionMode( + uint32_t entryPointId, + spv::ExecutionMode executionMode, + uint32_t argCount, + const uint32_t* args); + + void setInvocations( + uint32_t entryPointId, + uint32_t invocations); + + void setLocalSize( + uint32_t entryPointId, + uint32_t x, + uint32_t y, + uint32_t z); + + void setOutputVertices( + uint32_t entryPointId, + uint32_t vertexCount); + + uint32_t addDebugString( + const char* string); + + void setDebugSource( + spv::SourceLanguage language, + uint32_t version, + uint32_t file, + const char* source); + + void setDebugName( + uint32_t expressionId, + const char* debugName); + + void setDebugMemberName( + uint32_t structId, + uint32_t memberId, + const char* debugName); + + uint32_t constBool( + bool v); + + uint32_t consti32( + int32_t v); + + uint32_t consti64( + int64_t v); + + uint32_t constu32( + uint32_t v); + + uint32_t constu64( + uint64_t v); + + uint32_t constf32( + float v); + + uint32_t constf64( + double v); + + uint32_t constvec4i32( + int32_t x, + int32_t y, + int32_t z, + int32_t w); + + uint32_t constvec4b32( + bool x, + bool y, + bool z, + bool w); + + uint32_t constvec4u32( + uint32_t x, + uint32_t y, + uint32_t z, + uint32_t w); + + uint32_t constvec2f32( + float x, + float y); + + uint32_t constvec3f32( + float x, + float y, + float z); + + uint32_t constvec4f32( + float x, + float y, + float z, + float w); + + uint32_t constfReplicant( + float replicant, + uint32_t count); + + uint32_t constbReplicant( + bool replicant, + uint32_t count); + + uint32_t constiReplicant( + int32_t replicant, + uint32_t count); + + uint32_t constuReplicant( + int32_t replicant, + uint32_t count); + + uint32_t constComposite( + uint32_t typeId, + uint32_t constCount, + const uint32_t* constIds); + + uint32_t constUndef( + uint32_t typeId); + + uint32_t constNull( + uint32_t typeId); + + uint32_t lateConst32( + uint32_t typeId); + + void setLateConst( + uint32_t constId, + const uint32_t* argIds); + + uint32_t specConstBool( + bool v); + + uint32_t specConst32( + uint32_t typeId, + uint32_t value); + + void decorate( + uint32_t object, + spv::Decoration decoration); + + void decorateArrayStride( + uint32_t object, + uint32_t stride); + + void decorateBinding( + uint32_t object, + uint32_t binding); + + void decorateBlock( + uint32_t object); + + void decorateBuiltIn( + uint32_t object, + spv::BuiltIn builtIn); + + void decorateComponent( + uint32_t object, + uint32_t location); + + void decorateDescriptorSet( + uint32_t object, + uint32_t set); + + void decorateIndex( + uint32_t object, + uint32_t index); + + void decorateLocation( + uint32_t object, + uint32_t location); + + void decorateSpecId( + uint32_t object, + uint32_t specId); + + void decorateXfb( + uint32_t object, + uint32_t streamId, + uint32_t bufferId, + uint32_t offset, + uint32_t stride); + + void memberDecorateBuiltIn( + uint32_t structId, + uint32_t memberId, + spv::BuiltIn builtIn); + + void memberDecorate( + uint32_t structId, + uint32_t memberId, + spv::Decoration decoration); + + void memberDecorateMatrixStride( + uint32_t structId, + uint32_t memberId, + uint32_t stride); + + void memberDecorateOffset( + uint32_t structId, + uint32_t memberId, + uint32_t offset); + + uint32_t defVoidType(); + + uint32_t defBoolType(); + + uint32_t defIntType( + uint32_t width, + uint32_t isSigned); + + uint32_t defFloatType( + uint32_t width); + + uint32_t defVectorType( + uint32_t elementType, + uint32_t elementCount); + + uint32_t defMatrixType( + uint32_t columnType, + uint32_t columnCount); + + uint32_t defArrayType( + uint32_t typeId, + uint32_t length); + + uint32_t defArrayTypeUnique( + uint32_t typeId, + uint32_t length); + + uint32_t defRuntimeArrayType( + uint32_t typeId); + + uint32_t defRuntimeArrayTypeUnique( + uint32_t typeId); + + uint32_t defFunctionType( + uint32_t returnType, + uint32_t argCount, + const uint32_t* argTypes); + + uint32_t defStructType( + uint32_t memberCount, + const uint32_t* memberTypes); + + uint32_t defStructTypeUnique( + uint32_t memberCount, + const uint32_t* memberTypes); + + uint32_t defPointerType( + uint32_t variableType, + spv::StorageClass storageClass); + + uint32_t defSamplerType(); + + uint32_t defImageType( + uint32_t sampledType, + spv::Dim dimensionality, + uint32_t depth, + uint32_t arrayed, + uint32_t multisample, + uint32_t sampled, + spv::ImageFormat format); + + uint32_t defSampledImageType( + uint32_t imageType); + + uint32_t newVar( + uint32_t pointerType, + spv::StorageClass storageClass); + + uint32_t newVarInit( + uint32_t pointerType, + spv::StorageClass storageClass, + uint32_t initialValue); + + void functionBegin( + uint32_t returnType, + uint32_t functionId, + uint32_t functionType, + spv::FunctionControlMask functionControl); + + uint32_t functionParameter( + uint32_t parameterType); + + void functionEnd(); + + uint32_t opAccessChain( + uint32_t resultType, + uint32_t composite, + uint32_t indexCount, + const uint32_t* indexArray); + + uint32_t opArrayLength( + uint32_t resultType, + uint32_t structure, + uint32_t memberId); + + uint32_t opAny( + uint32_t resultType, + uint32_t vector); + + uint32_t opAll( + uint32_t resultType, + uint32_t vector); + + uint32_t opAtomicLoad( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics); + + void opAtomicStore( + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicExchange( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicCompareExchange( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t equal, + uint32_t unequal, + uint32_t value, + uint32_t comparator); + + uint32_t opAtomicIIncrement( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics); + + uint32_t opAtomicIDecrement( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics); + + uint32_t opAtomicIAdd( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicISub( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicSMin( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicSMax( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicUMin( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicUMax( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicAnd( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicOr( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opAtomicXor( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value); + + uint32_t opBitcast( + uint32_t resultType, + uint32_t operand); + + uint32_t opBitCount( + uint32_t resultType, + uint32_t operand); + + uint32_t opBitReverse( + uint32_t resultType, + uint32_t operand); + + uint32_t opFindILsb( + uint32_t resultType, + uint32_t operand); + + uint32_t opFindUMsb( + uint32_t resultType, + uint32_t operand); + + uint32_t opFindSMsb( + uint32_t resultType, + uint32_t operand); + + uint32_t opBitFieldInsert( + uint32_t resultType, + uint32_t base, + uint32_t insert, + uint32_t offset, + uint32_t count); + + uint32_t opBitFieldSExtract( + uint32_t resultType, + uint32_t base, + uint32_t offset, + uint32_t count); + + uint32_t opBitFieldUExtract( + uint32_t resultType, + uint32_t base, + uint32_t offset, + uint32_t count); + + uint32_t opBitwiseAnd( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2); + + uint32_t opBitwiseOr( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2); + + uint32_t opBitwiseXor( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2); + + uint32_t opNot( + uint32_t resultType, + uint32_t operand); + + uint32_t opShiftLeftLogical( + uint32_t resultType, + uint32_t base, + uint32_t shift); + + uint32_t opShiftRightArithmetic( + uint32_t resultType, + uint32_t base, + uint32_t shift); + + uint32_t opShiftRightLogical( + uint32_t resultType, + uint32_t base, + uint32_t shift); + + uint32_t opConvertFtoS( + uint32_t resultType, + uint32_t operand); + + uint32_t opConvertFtoU( + uint32_t resultType, + uint32_t operand); + + uint32_t opConvertStoF( + uint32_t resultType, + uint32_t operand); + + uint32_t opConvertUtoF( + uint32_t resultType, + uint32_t operand); + + uint32_t opCompositeConstruct( + uint32_t resultType, + uint32_t valueCount, + const uint32_t* valueArray); + + uint32_t opCompositeExtract( + uint32_t resultType, + uint32_t composite, + uint32_t indexCount, + const uint32_t* indexArray); + + uint32_t opCompositeInsert( + uint32_t resultType, + uint32_t object, + uint32_t composite, + uint32_t indexCount, + const uint32_t* indexArray); + + uint32_t opDpdx( + uint32_t resultType, + uint32_t operand); + + uint32_t opDpdy( + uint32_t resultType, + uint32_t operand); + + uint32_t opDpdxCoarse( + uint32_t resultType, + uint32_t operand); + + uint32_t opDpdyCoarse( + uint32_t resultType, + uint32_t operand); + + uint32_t opDpdxFine( + uint32_t resultType, + uint32_t operand); + + uint32_t opDpdyFine( + uint32_t resultType, + uint32_t operand); + + uint32_t opVectorExtractDynamic( + uint32_t resultType, + uint32_t vector, + uint32_t index); + + uint32_t opVectorShuffle( + uint32_t resultType, + uint32_t vectorLeft, + uint32_t vectorRight, + uint32_t indexCount, + const uint32_t* indexArray); + + uint32_t opSNegate( + uint32_t resultType, + uint32_t operand); + + uint32_t opFNegate( + uint32_t resultType, + uint32_t operand); + + uint32_t opSAbs( + uint32_t resultType, + uint32_t operand); + + uint32_t opFAbs( + uint32_t resultType, + uint32_t operand); + + uint32_t opFSign( + uint32_t resultType, + uint32_t operand); + + uint32_t opFMix( + uint32_t resultType, + uint32_t x, + uint32_t y, + uint32_t a); + + uint32_t opCross( + uint32_t resultType, + uint32_t x, + uint32_t y); + + uint32_t opIAdd( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opISub( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opFAdd( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opFSub( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opSDiv( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opUDiv( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opSRem( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opUMod( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opFDiv( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opIMul( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opFMul( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opVectorTimesScalar( + uint32_t resultType, + uint32_t vector, + uint32_t scalar); + + uint32_t opMatrixTimesMatrix( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opMatrixTimesVector( + uint32_t resultType, + uint32_t matrix, + uint32_t vector); + + uint32_t opVectorTimesMatrix( + uint32_t resultType, + uint32_t vector, + uint32_t matrix); + + uint32_t opTranspose( + uint32_t resultType, + uint32_t matrix); + + uint32_t opInverse( + uint32_t resultType, + uint32_t matrix); + + uint32_t opFFma( + uint32_t resultType, + uint32_t a, + uint32_t b, + uint32_t c); + + uint32_t opFMax( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opFMin( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opNMax( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opNMin( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opSMax( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opSMin( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opUMax( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opUMin( + uint32_t resultType, + uint32_t a, + uint32_t b); + + uint32_t opFClamp( + uint32_t resultType, + uint32_t x, + uint32_t minVal, + uint32_t maxVal); + + uint32_t opNClamp( + uint32_t resultType, + uint32_t x, + uint32_t minVal, + uint32_t maxVal); + + uint32_t opIEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opINotEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opSLessThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opSLessThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opSGreaterThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opSGreaterThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opULessThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opULessThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opUGreaterThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opUGreaterThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opFOrdEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opFUnordNotEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opFOrdLessThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opFOrdLessThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opFOrdGreaterThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opFOrdGreaterThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opLogicalEqual( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2); + + uint32_t opLogicalNotEqual( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2); + + uint32_t opLogicalAnd( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2); + + uint32_t opLogicalOr( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2); + + uint32_t opLogicalNot( + uint32_t resultType, + uint32_t operand); + + uint32_t opDot( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2); + + uint32_t opSin( + uint32_t resultType, + uint32_t vector); + + uint32_t opCos( + uint32_t resultType, + uint32_t vector); + + uint32_t opSqrt( + uint32_t resultType, + uint32_t operand); + + uint32_t opInverseSqrt( + uint32_t resultType, + uint32_t operand); + + uint32_t opNormalize( + uint32_t resultType, + uint32_t operand); + + uint32_t opRawAccessChain( + uint32_t resultType, + uint32_t base, + uint32_t stride, + uint32_t index, + uint32_t offset, + uint32_t operand); + + uint32_t opReflect( + uint32_t resultType, + uint32_t incident, + uint32_t normal); + + uint32_t opLength( + uint32_t resultType, + uint32_t operand); + + uint32_t opExp2( + uint32_t resultType, + uint32_t operand); + + uint32_t opExp( + uint32_t resultType, + uint32_t operand); + + uint32_t opLog2( + uint32_t resultType, + uint32_t operand); + + uint32_t opPow( + uint32_t resultType, + uint32_t base, + uint32_t exponent); + + uint32_t opFract( + uint32_t resultType, + uint32_t operand); + + uint32_t opCeil( + uint32_t resultType, + uint32_t operand); + + uint32_t opFloor( + uint32_t resultType, + uint32_t operand); + + uint32_t opRound( + uint32_t resultType, + uint32_t operand); + + uint32_t opRoundEven( + uint32_t resultType, + uint32_t operand); + + uint32_t opTrunc( + uint32_t resultType, + uint32_t operand); + + uint32_t opFConvert( + uint32_t resultType, + uint32_t operand); + + uint32_t opPackHalf2x16( + uint32_t resultType, + uint32_t operand); + + uint32_t opUnpackHalf2x16( + uint32_t resultType, + uint32_t operand); + + uint32_t opSelect( + uint32_t resultType, + uint32_t condition, + uint32_t operand1, + uint32_t operand2); + + uint32_t opIsNan( + uint32_t resultType, + uint32_t operand); + + uint32_t opIsInf( + uint32_t resultType, + uint32_t operand); + + uint32_t opFunctionCall( + uint32_t resultType, + uint32_t functionId, + uint32_t argCount, + const uint32_t* argIds); + + void opLabel( + uint32_t labelId); + + uint32_t opLoad( + uint32_t typeId, + uint32_t pointerId); + + uint32_t opLoad( + uint32_t typeId, + uint32_t pointerId, + const SpirvMemoryOperands& operands); + + void opStore( + uint32_t pointerId, + uint32_t valueId); + + void opStore( + uint32_t pointerId, + uint32_t valueId, + const SpirvMemoryOperands& operands); + + uint32_t opInterpolateAtCentroid( + uint32_t resultType, + uint32_t interpolant); + + uint32_t opInterpolateAtSample( + uint32_t resultType, + uint32_t interpolant, + uint32_t sample); + + uint32_t opInterpolateAtOffset( + uint32_t resultType, + uint32_t interpolant, + uint32_t offset); + + uint32_t opImage( + uint32_t resultType, + uint32_t sampledImage); + + uint32_t opImageRead( + uint32_t resultType, + uint32_t image, + uint32_t coordinates, + const SpirvImageOperands& operands); + + void opImageWrite( + uint32_t image, + uint32_t coordinates, + uint32_t texel, + const SpirvImageOperands& operands); + + uint32_t opImageSparseTexelsResident( + uint32_t resultType, + uint32_t residentCode); + + uint32_t opImageTexelPointer( + uint32_t resultType, + uint32_t image, + uint32_t coordinates, + uint32_t sample); + + uint32_t opSampledImage( + uint32_t resultType, + uint32_t image, + uint32_t sampler); + + uint32_t opImageQuerySizeLod( + uint32_t resultType, + uint32_t image, + uint32_t lod); + + uint32_t opImageQuerySize( + uint32_t resultType, + uint32_t image); + + uint32_t opImageQueryLevels( + uint32_t resultType, + uint32_t image); + + uint32_t opImageQueryLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates); + + uint32_t opImageQuerySamples( + uint32_t resultType, + uint32_t image); + + uint32_t opImageFetch( + uint32_t resultType, + uint32_t image, + uint32_t coordinates, + const SpirvImageOperands& operands); + + uint32_t opImageGather( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t component, + const SpirvImageOperands& operands); + + uint32_t opImageDrefGather( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands); + + uint32_t opImageSampleImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands); + + uint32_t opImageSampleExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands); + + uint32_t opImageSampleProjImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands); + + uint32_t opImageSampleProjExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands); + + uint32_t opImageSampleDrefImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands); + + uint32_t opImageSampleDrefExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands); + + uint32_t opImageSampleProjDrefImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands); + + uint32_t opImageSampleProjDrefExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands); + + uint32_t opGroupNonUniformBallot( + uint32_t resultType, + uint32_t execution, + uint32_t predicate); + + uint32_t opGroupNonUniformBallotBitCount( + uint32_t resultType, + uint32_t execution, + uint32_t operation, + uint32_t ballot); + + uint32_t opGroupNonUniformElect( + uint32_t resultType, + uint32_t execution); + + uint32_t opGroupNonUniformBroadcastFirst( + uint32_t resultType, + uint32_t execution, + uint32_t value); + + void opControlBarrier( + uint32_t execution, + uint32_t memory, + uint32_t semantics); + + void opMemoryBarrier( + uint32_t memory, + uint32_t semantics); + + void opLoopMerge( + uint32_t mergeBlock, + uint32_t continueTarget, + uint32_t loopControl); + + void opSelectionMerge( + uint32_t mergeBlock, + uint32_t selectionControl); + + void opBranch( + uint32_t label); + + void opBranchConditional( + uint32_t condition, + uint32_t trueLabel, + uint32_t falseLabel); + + void opSwitch( + uint32_t selector, + uint32_t jumpDefault, + uint32_t caseCount, + const SpirvSwitchCaseLabel* caseLabels); + + uint32_t opPhi( + uint32_t resultType, + uint32_t sourceCount, + const SpirvPhiLabel* sourceLabels); + + void opReturn(); + + void opDemoteToHelperInvocation(); + + void opEmitVertex( + uint32_t streamId); + + void opEndPrimitive( + uint32_t streamId); + + void opBeginInvocationInterlock(); + + void opEndInvocationInterlock(); + + uint32_t opSinCos( + uint32_t x, + bool useBuiltIn); + + private: + + uint32_t m_version; + uint32_t m_id = 1; + uint32_t m_instExtGlsl450 = 0; + uint32_t m_blockId = 0; + + SpirvCodeBuffer m_capabilities; + SpirvCodeBuffer m_extensions; + SpirvCodeBuffer m_instExt; + SpirvCodeBuffer m_memoryModel; + SpirvCodeBuffer m_entryPoints; + SpirvCodeBuffer m_execModeInfo; + SpirvCodeBuffer m_debugNames; + SpirvCodeBuffer m_annotations; + SpirvCodeBuffer m_typeConstDefs; + SpirvCodeBuffer m_variables; + SpirvCodeBuffer m_code; + + std::unordered_set m_lateConsts; + + std::vector m_interfaceVars; + + uint32_t defType( + spv::Op op, + uint32_t argCount, + const uint32_t* argIds); + + uint32_t defConst( + spv::Op op, + uint32_t typeId, + uint32_t argCount, + const uint32_t* argIds); + + void instImportGlsl450(); + + uint32_t getMemoryOperandWordCount( + const SpirvMemoryOperands& op) const; + + void putMemoryOperands( + const SpirvMemoryOperands& op); + + uint32_t getImageOperandWordCount( + const SpirvImageOperands& op) const; + + void putImageOperands( + const SpirvImageOperands& op); + + bool isInterfaceVar( + spv::StorageClass sclass) const; + + void classifyBlocks( + std::unordered_set& reachableBlocks, + std::unordered_set& mergeBlocks); + + static constexpr double sincosTaylorFactor(uint32_t power) { + double result = 1.0; + + for (uint32_t i = 1; i <= power; i++) + result *= pi * 0.25f / double(i); + + return result; + } + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/spirv/thirdparty/GLSL.std.450.h b/app/src/main/cpp/thirdparty/dxbc/include/spirv/thirdparty/GLSL.std.450.h new file mode 100644 index 0000000000..0594f907a1 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/spirv/thirdparty/GLSL.std.450.h @@ -0,0 +1,131 @@ +/* +** Copyright (c) 2014-2024 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. +*/ + +#ifndef GLSLstd450_H +#define GLSLstd450_H + +static const int GLSLstd450Version = 100; +static const int GLSLstd450Revision = 3; + +enum GLSLstd450 { + GLSLstd450Bad = 0, // Don't use + + GLSLstd450Round = 1, + GLSLstd450RoundEven = 2, + GLSLstd450Trunc = 3, + GLSLstd450FAbs = 4, + GLSLstd450SAbs = 5, + GLSLstd450FSign = 6, + GLSLstd450SSign = 7, + GLSLstd450Floor = 8, + GLSLstd450Ceil = 9, + GLSLstd450Fract = 10, + + GLSLstd450Radians = 11, + GLSLstd450Degrees = 12, + GLSLstd450Sin = 13, + GLSLstd450Cos = 14, + GLSLstd450Tan = 15, + GLSLstd450Asin = 16, + GLSLstd450Acos = 17, + GLSLstd450Atan = 18, + GLSLstd450Sinh = 19, + GLSLstd450Cosh = 20, + GLSLstd450Tanh = 21, + GLSLstd450Asinh = 22, + GLSLstd450Acosh = 23, + GLSLstd450Atanh = 24, + GLSLstd450Atan2 = 25, + + GLSLstd450Pow = 26, + GLSLstd450Exp = 27, + GLSLstd450Log = 28, + GLSLstd450Exp2 = 29, + GLSLstd450Log2 = 30, + GLSLstd450Sqrt = 31, + GLSLstd450InverseSqrt = 32, + + GLSLstd450Determinant = 33, + GLSLstd450MatrixInverse = 34, + + GLSLstd450Modf = 35, // second operand needs an OpVariable to write to + GLSLstd450ModfStruct = 36, // no OpVariable operand + GLSLstd450FMin = 37, + GLSLstd450UMin = 38, + GLSLstd450SMin = 39, + GLSLstd450FMax = 40, + GLSLstd450UMax = 41, + GLSLstd450SMax = 42, + GLSLstd450FClamp = 43, + GLSLstd450UClamp = 44, + GLSLstd450SClamp = 45, + GLSLstd450FMix = 46, + GLSLstd450IMix = 47, // Reserved + GLSLstd450Step = 48, + GLSLstd450SmoothStep = 49, + + GLSLstd450Fma = 50, + GLSLstd450Frexp = 51, // second operand needs an OpVariable to write to + GLSLstd450FrexpStruct = 52, // no OpVariable operand + GLSLstd450Ldexp = 53, + + GLSLstd450PackSnorm4x8 = 54, + GLSLstd450PackUnorm4x8 = 55, + GLSLstd450PackSnorm2x16 = 56, + GLSLstd450PackUnorm2x16 = 57, + GLSLstd450PackHalf2x16 = 58, + GLSLstd450PackDouble2x32 = 59, + GLSLstd450UnpackSnorm2x16 = 60, + GLSLstd450UnpackUnorm2x16 = 61, + GLSLstd450UnpackHalf2x16 = 62, + GLSLstd450UnpackSnorm4x8 = 63, + GLSLstd450UnpackUnorm4x8 = 64, + GLSLstd450UnpackDouble2x32 = 65, + + GLSLstd450Length = 66, + GLSLstd450Distance = 67, + GLSLstd450Cross = 68, + GLSLstd450Normalize = 69, + GLSLstd450FaceForward = 70, + GLSLstd450Reflect = 71, + GLSLstd450Refract = 72, + + GLSLstd450FindILsb = 73, + GLSLstd450FindSMsb = 74, + GLSLstd450FindUMsb = 75, + + GLSLstd450InterpolateAtCentroid = 76, + GLSLstd450InterpolateAtSample = 77, + GLSLstd450InterpolateAtOffset = 78, + + GLSLstd450NMin = 79, + GLSLstd450NMax = 80, + GLSLstd450NClamp = 81, + + GLSLstd450Count +}; + +#endif // #ifndef GLSLstd450_H diff --git a/app/src/main/cpp/thirdparty/dxbc/include/spirv/thirdparty/spirv.hpp b/app/src/main/cpp/thirdparty/dxbc/include/spirv/thirdparty/spirv.hpp new file mode 100644 index 0000000000..f439e472f1 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/spirv/thirdparty/spirv.hpp @@ -0,0 +1,5214 @@ +// Copyright (c) 2014-2024 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. + +// This header is automatically generated by the same tool that creates +// the Binary Section of the SPIR-V specification. + +// Enumeration tokens for SPIR-V, in various styles: +// C, C++, C++11, JSON, Lua, Python, C#, D, Beef +// +// - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL +// - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL +// - C++11 will use enum classes in the spv namespace, e.g.: spv::SourceLanguage::GLSL +// - Lua will use tables, e.g.: spv.SourceLanguage.GLSL +// - Python will use dictionaries, e.g.: spv['SourceLanguage']['GLSL'] +// - C# will use enum classes in the Specification class located in the "Spv" namespace, +// e.g.: Spv.Specification.SourceLanguage.GLSL +// - D will have tokens under the "spv" module, e.g: spv.SourceLanguage.GLSL +// - Beef will use enum classes in the Specification class located in the "Spv" namespace, +// e.g.: Spv.Specification.SourceLanguage.GLSL +// +// Some tokens act like mask values, which can be OR'd together, +// while others are mutually exclusive. The mask-like ones have +// "Mask" in their name, and a parallel enum that has the shift +// amount (1 << x) for each corresponding enumerant. + +#ifndef spirv_HPP +#define spirv_HPP + +namespace spv { + +typedef unsigned int Id; + +#define SPV_VERSION 0x10600 +#define SPV_REVISION 1 + +static const unsigned int MagicNumber = 0x07230203; +static const unsigned int Version = 0x00010600; +static const unsigned int Revision = 1; +static const unsigned int OpCodeMask = 0xffff; +static const unsigned int WordCountShift = 16; + +enum SourceLanguage { + SourceLanguageUnknown = 0, + SourceLanguageESSL = 1, + SourceLanguageGLSL = 2, + SourceLanguageOpenCL_C = 3, + SourceLanguageOpenCL_CPP = 4, + SourceLanguageHLSL = 5, + SourceLanguageCPP_for_OpenCL = 6, + SourceLanguageSYCL = 7, + SourceLanguageHERO_C = 8, + SourceLanguageNZSL = 9, + SourceLanguageWGSL = 10, + SourceLanguageSlang = 11, + SourceLanguageZig = 12, + SourceLanguageRust = 13, + SourceLanguageMax = 0x7fffffff, +}; + +enum ExecutionModel { + ExecutionModelVertex = 0, + ExecutionModelTessellationControl = 1, + ExecutionModelTessellationEvaluation = 2, + ExecutionModelGeometry = 3, + ExecutionModelFragment = 4, + ExecutionModelGLCompute = 5, + ExecutionModelKernel = 6, + ExecutionModelTaskNV = 5267, + ExecutionModelMeshNV = 5268, + ExecutionModelRayGenerationKHR = 5313, + ExecutionModelRayGenerationNV = 5313, + ExecutionModelIntersectionKHR = 5314, + ExecutionModelIntersectionNV = 5314, + ExecutionModelAnyHitKHR = 5315, + ExecutionModelAnyHitNV = 5315, + ExecutionModelClosestHitKHR = 5316, + ExecutionModelClosestHitNV = 5316, + ExecutionModelMissKHR = 5317, + ExecutionModelMissNV = 5317, + ExecutionModelCallableKHR = 5318, + ExecutionModelCallableNV = 5318, + ExecutionModelTaskEXT = 5364, + ExecutionModelMeshEXT = 5365, + ExecutionModelMax = 0x7fffffff, +}; + +enum AddressingModel { + AddressingModelLogical = 0, + AddressingModelPhysical32 = 1, + AddressingModelPhysical64 = 2, + AddressingModelPhysicalStorageBuffer64 = 5348, + AddressingModelPhysicalStorageBuffer64EXT = 5348, + AddressingModelMax = 0x7fffffff, +}; + +enum MemoryModel { + MemoryModelSimple = 0, + MemoryModelGLSL450 = 1, + MemoryModelOpenCL = 2, + MemoryModelVulkan = 3, + MemoryModelVulkanKHR = 3, + MemoryModelMax = 0x7fffffff, +}; + +enum ExecutionMode { + ExecutionModeInvocations = 0, + ExecutionModeSpacingEqual = 1, + ExecutionModeSpacingFractionalEven = 2, + ExecutionModeSpacingFractionalOdd = 3, + ExecutionModeVertexOrderCw = 4, + ExecutionModeVertexOrderCcw = 5, + ExecutionModePixelCenterInteger = 6, + ExecutionModeOriginUpperLeft = 7, + ExecutionModeOriginLowerLeft = 8, + ExecutionModeEarlyFragmentTests = 9, + ExecutionModePointMode = 10, + ExecutionModeXfb = 11, + ExecutionModeDepthReplacing = 12, + ExecutionModeDepthGreater = 14, + ExecutionModeDepthLess = 15, + ExecutionModeDepthUnchanged = 16, + ExecutionModeLocalSize = 17, + ExecutionModeLocalSizeHint = 18, + ExecutionModeInputPoints = 19, + ExecutionModeInputLines = 20, + ExecutionModeInputLinesAdjacency = 21, + ExecutionModeTriangles = 22, + ExecutionModeInputTrianglesAdjacency = 23, + ExecutionModeQuads = 24, + ExecutionModeIsolines = 25, + ExecutionModeOutputVertices = 26, + ExecutionModeOutputPoints = 27, + ExecutionModeOutputLineStrip = 28, + ExecutionModeOutputTriangleStrip = 29, + ExecutionModeVecTypeHint = 30, + ExecutionModeContractionOff = 31, + ExecutionModeInitializer = 33, + ExecutionModeFinalizer = 34, + ExecutionModeSubgroupSize = 35, + ExecutionModeSubgroupsPerWorkgroup = 36, + ExecutionModeSubgroupsPerWorkgroupId = 37, + ExecutionModeLocalSizeId = 38, + ExecutionModeLocalSizeHintId = 39, + ExecutionModeNonCoherentColorAttachmentReadEXT = 4169, + ExecutionModeNonCoherentDepthAttachmentReadEXT = 4170, + ExecutionModeNonCoherentStencilAttachmentReadEXT = 4171, + ExecutionModeSubgroupUniformControlFlowKHR = 4421, + ExecutionModePostDepthCoverage = 4446, + ExecutionModeDenormPreserve = 4459, + ExecutionModeDenormFlushToZero = 4460, + ExecutionModeSignedZeroInfNanPreserve = 4461, + ExecutionModeRoundingModeRTE = 4462, + ExecutionModeRoundingModeRTZ = 4463, + ExecutionModeNonCoherentTileAttachmentReadQCOM = 4489, + ExecutionModeTileShadingRateQCOM = 4490, + ExecutionModeEarlyAndLateFragmentTestsAMD = 5017, + ExecutionModeStencilRefReplacingEXT = 5027, + ExecutionModeCoalescingAMDX = 5069, + ExecutionModeIsApiEntryAMDX = 5070, + ExecutionModeMaxNodeRecursionAMDX = 5071, + ExecutionModeStaticNumWorkgroupsAMDX = 5072, + ExecutionModeShaderIndexAMDX = 5073, + ExecutionModeMaxNumWorkgroupsAMDX = 5077, + ExecutionModeStencilRefUnchangedFrontAMD = 5079, + ExecutionModeStencilRefGreaterFrontAMD = 5080, + ExecutionModeStencilRefLessFrontAMD = 5081, + ExecutionModeStencilRefUnchangedBackAMD = 5082, + ExecutionModeStencilRefGreaterBackAMD = 5083, + ExecutionModeStencilRefLessBackAMD = 5084, + ExecutionModeQuadDerivativesKHR = 5088, + ExecutionModeRequireFullQuadsKHR = 5089, + ExecutionModeSharesInputWithAMDX = 5102, + ExecutionModeOutputLinesEXT = 5269, + ExecutionModeOutputLinesNV = 5269, + ExecutionModeOutputPrimitivesEXT = 5270, + ExecutionModeOutputPrimitivesNV = 5270, + ExecutionModeDerivativeGroupQuadsKHR = 5289, + ExecutionModeDerivativeGroupQuadsNV = 5289, + ExecutionModeDerivativeGroupLinearKHR = 5290, + ExecutionModeDerivativeGroupLinearNV = 5290, + ExecutionModeOutputTrianglesEXT = 5298, + ExecutionModeOutputTrianglesNV = 5298, + ExecutionModePixelInterlockOrderedEXT = 5366, + ExecutionModePixelInterlockUnorderedEXT = 5367, + ExecutionModeSampleInterlockOrderedEXT = 5368, + ExecutionModeSampleInterlockUnorderedEXT = 5369, + ExecutionModeShadingRateInterlockOrderedEXT = 5370, + ExecutionModeShadingRateInterlockUnorderedEXT = 5371, + ExecutionModeSharedLocalMemorySizeINTEL = 5618, + ExecutionModeRoundingModeRTPINTEL = 5620, + ExecutionModeRoundingModeRTNINTEL = 5621, + ExecutionModeFloatingPointModeALTINTEL = 5622, + ExecutionModeFloatingPointModeIEEEINTEL = 5623, + ExecutionModeMaxWorkgroupSizeINTEL = 5893, + ExecutionModeMaxWorkDimINTEL = 5894, + ExecutionModeNoGlobalOffsetINTEL = 5895, + ExecutionModeNumSIMDWorkitemsINTEL = 5896, + ExecutionModeSchedulerTargetFmaxMhzINTEL = 5903, + ExecutionModeMaximallyReconvergesKHR = 6023, + ExecutionModeFPFastMathDefault = 6028, + ExecutionModeStreamingInterfaceINTEL = 6154, + ExecutionModeRegisterMapInterfaceINTEL = 6160, + ExecutionModeNamedBarrierCountINTEL = 6417, + ExecutionModeMaximumRegistersINTEL = 6461, + ExecutionModeMaximumRegistersIdINTEL = 6462, + ExecutionModeNamedMaximumRegistersINTEL = 6463, + ExecutionModeMax = 0x7fffffff, +}; + +enum StorageClass { + StorageClassUniformConstant = 0, + StorageClassInput = 1, + StorageClassUniform = 2, + StorageClassOutput = 3, + StorageClassWorkgroup = 4, + StorageClassCrossWorkgroup = 5, + StorageClassPrivate = 6, + StorageClassFunction = 7, + StorageClassGeneric = 8, + StorageClassPushConstant = 9, + StorageClassAtomicCounter = 10, + StorageClassImage = 11, + StorageClassStorageBuffer = 12, + StorageClassTileImageEXT = 4172, + StorageClassTileAttachmentQCOM = 4491, + StorageClassNodePayloadAMDX = 5068, + StorageClassCallableDataKHR = 5328, + StorageClassCallableDataNV = 5328, + StorageClassIncomingCallableDataKHR = 5329, + StorageClassIncomingCallableDataNV = 5329, + StorageClassRayPayloadKHR = 5338, + StorageClassRayPayloadNV = 5338, + StorageClassHitAttributeKHR = 5339, + StorageClassHitAttributeNV = 5339, + StorageClassIncomingRayPayloadKHR = 5342, + StorageClassIncomingRayPayloadNV = 5342, + StorageClassShaderRecordBufferKHR = 5343, + StorageClassShaderRecordBufferNV = 5343, + StorageClassPhysicalStorageBuffer = 5349, + StorageClassPhysicalStorageBufferEXT = 5349, + StorageClassHitObjectAttributeNV = 5385, + StorageClassTaskPayloadWorkgroupEXT = 5402, + StorageClassCodeSectionINTEL = 5605, + StorageClassDeviceOnlyINTEL = 5936, + StorageClassHostOnlyINTEL = 5937, + StorageClassMax = 0x7fffffff, +}; + +enum Dim { + Dim1D = 0, + Dim2D = 1, + Dim3D = 2, + DimCube = 3, + DimRect = 4, + DimBuffer = 5, + DimSubpassData = 6, + DimTileImageDataEXT = 4173, + DimMax = 0x7fffffff, +}; + +enum SamplerAddressingMode { + SamplerAddressingModeNone = 0, + SamplerAddressingModeClampToEdge = 1, + SamplerAddressingModeClamp = 2, + SamplerAddressingModeRepeat = 3, + SamplerAddressingModeRepeatMirrored = 4, + SamplerAddressingModeMax = 0x7fffffff, +}; + +enum SamplerFilterMode { + SamplerFilterModeNearest = 0, + SamplerFilterModeLinear = 1, + SamplerFilterModeMax = 0x7fffffff, +}; + +enum ImageFormat { + ImageFormatUnknown = 0, + ImageFormatRgba32f = 1, + ImageFormatRgba16f = 2, + ImageFormatR32f = 3, + ImageFormatRgba8 = 4, + ImageFormatRgba8Snorm = 5, + ImageFormatRg32f = 6, + ImageFormatRg16f = 7, + ImageFormatR11fG11fB10f = 8, + ImageFormatR16f = 9, + ImageFormatRgba16 = 10, + ImageFormatRgb10A2 = 11, + ImageFormatRg16 = 12, + ImageFormatRg8 = 13, + ImageFormatR16 = 14, + ImageFormatR8 = 15, + ImageFormatRgba16Snorm = 16, + ImageFormatRg16Snorm = 17, + ImageFormatRg8Snorm = 18, + ImageFormatR16Snorm = 19, + ImageFormatR8Snorm = 20, + ImageFormatRgba32i = 21, + ImageFormatRgba16i = 22, + ImageFormatRgba8i = 23, + ImageFormatR32i = 24, + ImageFormatRg32i = 25, + ImageFormatRg16i = 26, + ImageFormatRg8i = 27, + ImageFormatR16i = 28, + ImageFormatR8i = 29, + ImageFormatRgba32ui = 30, + ImageFormatRgba16ui = 31, + ImageFormatRgba8ui = 32, + ImageFormatR32ui = 33, + ImageFormatRgb10a2ui = 34, + ImageFormatRg32ui = 35, + ImageFormatRg16ui = 36, + ImageFormatRg8ui = 37, + ImageFormatR16ui = 38, + ImageFormatR8ui = 39, + ImageFormatR64ui = 40, + ImageFormatR64i = 41, + ImageFormatMax = 0x7fffffff, +}; + +enum ImageChannelOrder { + ImageChannelOrderR = 0, + ImageChannelOrderA = 1, + ImageChannelOrderRG = 2, + ImageChannelOrderRA = 3, + ImageChannelOrderRGB = 4, + ImageChannelOrderRGBA = 5, + ImageChannelOrderBGRA = 6, + ImageChannelOrderARGB = 7, + ImageChannelOrderIntensity = 8, + ImageChannelOrderLuminance = 9, + ImageChannelOrderRx = 10, + ImageChannelOrderRGx = 11, + ImageChannelOrderRGBx = 12, + ImageChannelOrderDepth = 13, + ImageChannelOrderDepthStencil = 14, + ImageChannelOrdersRGB = 15, + ImageChannelOrdersRGBx = 16, + ImageChannelOrdersRGBA = 17, + ImageChannelOrdersBGRA = 18, + ImageChannelOrderABGR = 19, + ImageChannelOrderMax = 0x7fffffff, +}; + +enum ImageChannelDataType { + ImageChannelDataTypeSnormInt8 = 0, + ImageChannelDataTypeSnormInt16 = 1, + ImageChannelDataTypeUnormInt8 = 2, + ImageChannelDataTypeUnormInt16 = 3, + ImageChannelDataTypeUnormShort565 = 4, + ImageChannelDataTypeUnormShort555 = 5, + ImageChannelDataTypeUnormInt101010 = 6, + ImageChannelDataTypeSignedInt8 = 7, + ImageChannelDataTypeSignedInt16 = 8, + ImageChannelDataTypeSignedInt32 = 9, + ImageChannelDataTypeUnsignedInt8 = 10, + ImageChannelDataTypeUnsignedInt16 = 11, + ImageChannelDataTypeUnsignedInt32 = 12, + ImageChannelDataTypeHalfFloat = 13, + ImageChannelDataTypeFloat = 14, + ImageChannelDataTypeUnormInt24 = 15, + ImageChannelDataTypeUnormInt101010_2 = 16, + ImageChannelDataTypeUnormInt10X6EXT = 17, + ImageChannelDataTypeUnsignedIntRaw10EXT = 19, + ImageChannelDataTypeUnsignedIntRaw12EXT = 20, + ImageChannelDataTypeUnormInt2_101010EXT = 21, + ImageChannelDataTypeUnsignedInt10X6EXT = 22, + ImageChannelDataTypeUnsignedInt12X4EXT = 23, + ImageChannelDataTypeUnsignedInt14X2EXT = 24, + ImageChannelDataTypeUnormInt12X4EXT = 25, + ImageChannelDataTypeUnormInt14X2EXT = 26, + ImageChannelDataTypeMax = 0x7fffffff, +}; + +enum ImageOperandsShift { + ImageOperandsBiasShift = 0, + ImageOperandsLodShift = 1, + ImageOperandsGradShift = 2, + ImageOperandsConstOffsetShift = 3, + ImageOperandsOffsetShift = 4, + ImageOperandsConstOffsetsShift = 5, + ImageOperandsSampleShift = 6, + ImageOperandsMinLodShift = 7, + ImageOperandsMakeTexelAvailableShift = 8, + ImageOperandsMakeTexelAvailableKHRShift = 8, + ImageOperandsMakeTexelVisibleShift = 9, + ImageOperandsMakeTexelVisibleKHRShift = 9, + ImageOperandsNonPrivateTexelShift = 10, + ImageOperandsNonPrivateTexelKHRShift = 10, + ImageOperandsVolatileTexelShift = 11, + ImageOperandsVolatileTexelKHRShift = 11, + ImageOperandsSignExtendShift = 12, + ImageOperandsZeroExtendShift = 13, + ImageOperandsNontemporalShift = 14, + ImageOperandsOffsetsShift = 16, + ImageOperandsMax = 0x7fffffff, +}; + +enum ImageOperandsMask { + ImageOperandsMaskNone = 0, + ImageOperandsBiasMask = 0x00000001, + ImageOperandsLodMask = 0x00000002, + ImageOperandsGradMask = 0x00000004, + ImageOperandsConstOffsetMask = 0x00000008, + ImageOperandsOffsetMask = 0x00000010, + ImageOperandsConstOffsetsMask = 0x00000020, + ImageOperandsSampleMask = 0x00000040, + ImageOperandsMinLodMask = 0x00000080, + ImageOperandsMakeTexelAvailableMask = 0x00000100, + ImageOperandsMakeTexelAvailableKHRMask = 0x00000100, + ImageOperandsMakeTexelVisibleMask = 0x00000200, + ImageOperandsMakeTexelVisibleKHRMask = 0x00000200, + ImageOperandsNonPrivateTexelMask = 0x00000400, + ImageOperandsNonPrivateTexelKHRMask = 0x00000400, + ImageOperandsVolatileTexelMask = 0x00000800, + ImageOperandsVolatileTexelKHRMask = 0x00000800, + ImageOperandsSignExtendMask = 0x00001000, + ImageOperandsZeroExtendMask = 0x00002000, + ImageOperandsNontemporalMask = 0x00004000, + ImageOperandsOffsetsMask = 0x00010000, +}; + +enum FPFastMathModeShift { + FPFastMathModeNotNaNShift = 0, + FPFastMathModeNotInfShift = 1, + FPFastMathModeNSZShift = 2, + FPFastMathModeAllowRecipShift = 3, + FPFastMathModeFastShift = 4, + FPFastMathModeAllowContractShift = 16, + FPFastMathModeAllowContractFastINTELShift = 16, + FPFastMathModeAllowReassocShift = 17, + FPFastMathModeAllowReassocINTELShift = 17, + FPFastMathModeAllowTransformShift = 18, + FPFastMathModeMax = 0x7fffffff, +}; + +enum FPFastMathModeMask { + FPFastMathModeMaskNone = 0, + FPFastMathModeNotNaNMask = 0x00000001, + FPFastMathModeNotInfMask = 0x00000002, + FPFastMathModeNSZMask = 0x00000004, + FPFastMathModeAllowRecipMask = 0x00000008, + FPFastMathModeFastMask = 0x00000010, + FPFastMathModeAllowContractMask = 0x00010000, + FPFastMathModeAllowContractFastINTELMask = 0x00010000, + FPFastMathModeAllowReassocMask = 0x00020000, + FPFastMathModeAllowReassocINTELMask = 0x00020000, + FPFastMathModeAllowTransformMask = 0x00040000, +}; + +enum FPRoundingMode { + FPRoundingModeRTE = 0, + FPRoundingModeRTZ = 1, + FPRoundingModeRTP = 2, + FPRoundingModeRTN = 3, + FPRoundingModeMax = 0x7fffffff, +}; + +enum LinkageType { + LinkageTypeExport = 0, + LinkageTypeImport = 1, + LinkageTypeLinkOnceODR = 2, + LinkageTypeMax = 0x7fffffff, +}; + +enum AccessQualifier { + AccessQualifierReadOnly = 0, + AccessQualifierWriteOnly = 1, + AccessQualifierReadWrite = 2, + AccessQualifierMax = 0x7fffffff, +}; + +enum FunctionParameterAttribute { + FunctionParameterAttributeZext = 0, + FunctionParameterAttributeSext = 1, + FunctionParameterAttributeByVal = 2, + FunctionParameterAttributeSret = 3, + FunctionParameterAttributeNoAlias = 4, + FunctionParameterAttributeNoCapture = 5, + FunctionParameterAttributeNoWrite = 6, + FunctionParameterAttributeNoReadWrite = 7, + FunctionParameterAttributeRuntimeAlignedINTEL = 5940, + FunctionParameterAttributeMax = 0x7fffffff, +}; + +enum Decoration { + DecorationRelaxedPrecision = 0, + DecorationSpecId = 1, + DecorationBlock = 2, + DecorationBufferBlock = 3, + DecorationRowMajor = 4, + DecorationColMajor = 5, + DecorationArrayStride = 6, + DecorationMatrixStride = 7, + DecorationGLSLShared = 8, + DecorationGLSLPacked = 9, + DecorationCPacked = 10, + DecorationBuiltIn = 11, + DecorationNoPerspective = 13, + DecorationFlat = 14, + DecorationPatch = 15, + DecorationCentroid = 16, + DecorationSample = 17, + DecorationInvariant = 18, + DecorationRestrict = 19, + DecorationAliased = 20, + DecorationVolatile = 21, + DecorationConstant = 22, + DecorationCoherent = 23, + DecorationNonWritable = 24, + DecorationNonReadable = 25, + DecorationUniform = 26, + DecorationUniformId = 27, + DecorationSaturatedConversion = 28, + DecorationStream = 29, + DecorationLocation = 30, + DecorationComponent = 31, + DecorationIndex = 32, + DecorationBinding = 33, + DecorationDescriptorSet = 34, + DecorationOffset = 35, + DecorationXfbBuffer = 36, + DecorationXfbStride = 37, + DecorationFuncParamAttr = 38, + DecorationFPRoundingMode = 39, + DecorationFPFastMathMode = 40, + DecorationLinkageAttributes = 41, + DecorationNoContraction = 42, + DecorationInputAttachmentIndex = 43, + DecorationAlignment = 44, + DecorationMaxByteOffset = 45, + DecorationAlignmentId = 46, + DecorationMaxByteOffsetId = 47, + DecorationNoSignedWrap = 4469, + DecorationNoUnsignedWrap = 4470, + DecorationWeightTextureQCOM = 4487, + DecorationBlockMatchTextureQCOM = 4488, + DecorationBlockMatchSamplerQCOM = 4499, + DecorationExplicitInterpAMD = 4999, + DecorationNodeSharesPayloadLimitsWithAMDX = 5019, + DecorationNodeMaxPayloadsAMDX = 5020, + DecorationTrackFinishWritingAMDX = 5078, + DecorationPayloadNodeNameAMDX = 5091, + DecorationPayloadNodeBaseIndexAMDX = 5098, + DecorationPayloadNodeSparseArrayAMDX = 5099, + DecorationPayloadNodeArraySizeAMDX = 5100, + DecorationPayloadDispatchIndirectAMDX = 5105, + DecorationOverrideCoverageNV = 5248, + DecorationPassthroughNV = 5250, + DecorationViewportRelativeNV = 5252, + DecorationSecondaryViewportRelativeNV = 5256, + DecorationPerPrimitiveEXT = 5271, + DecorationPerPrimitiveNV = 5271, + DecorationPerViewNV = 5272, + DecorationPerTaskNV = 5273, + DecorationPerVertexKHR = 5285, + DecorationPerVertexNV = 5285, + DecorationNonUniform = 5300, + DecorationNonUniformEXT = 5300, + DecorationRestrictPointer = 5355, + DecorationRestrictPointerEXT = 5355, + DecorationAliasedPointer = 5356, + DecorationAliasedPointerEXT = 5356, + DecorationHitObjectShaderRecordBufferNV = 5386, + DecorationBindlessSamplerNV = 5398, + DecorationBindlessImageNV = 5399, + DecorationBoundSamplerNV = 5400, + DecorationBoundImageNV = 5401, + DecorationSIMTCallINTEL = 5599, + DecorationReferencedIndirectlyINTEL = 5602, + DecorationClobberINTEL = 5607, + DecorationSideEffectsINTEL = 5608, + DecorationVectorComputeVariableINTEL = 5624, + DecorationFuncParamIOKindINTEL = 5625, + DecorationVectorComputeFunctionINTEL = 5626, + DecorationStackCallINTEL = 5627, + DecorationGlobalVariableOffsetINTEL = 5628, + DecorationCounterBuffer = 5634, + DecorationHlslCounterBufferGOOGLE = 5634, + DecorationHlslSemanticGOOGLE = 5635, + DecorationUserSemantic = 5635, + DecorationUserTypeGOOGLE = 5636, + DecorationFunctionRoundingModeINTEL = 5822, + DecorationFunctionDenormModeINTEL = 5823, + DecorationRegisterINTEL = 5825, + DecorationMemoryINTEL = 5826, + DecorationNumbanksINTEL = 5827, + DecorationBankwidthINTEL = 5828, + DecorationMaxPrivateCopiesINTEL = 5829, + DecorationSinglepumpINTEL = 5830, + DecorationDoublepumpINTEL = 5831, + DecorationMaxReplicatesINTEL = 5832, + DecorationSimpleDualPortINTEL = 5833, + DecorationMergeINTEL = 5834, + DecorationBankBitsINTEL = 5835, + DecorationForcePow2DepthINTEL = 5836, + DecorationStridesizeINTEL = 5883, + DecorationWordsizeINTEL = 5884, + DecorationTrueDualPortINTEL = 5885, + DecorationBurstCoalesceINTEL = 5899, + DecorationCacheSizeINTEL = 5900, + DecorationDontStaticallyCoalesceINTEL = 5901, + DecorationPrefetchINTEL = 5902, + DecorationStallEnableINTEL = 5905, + DecorationFuseLoopsInFunctionINTEL = 5907, + DecorationMathOpDSPModeINTEL = 5909, + DecorationAliasScopeINTEL = 5914, + DecorationNoAliasINTEL = 5915, + DecorationInitiationIntervalINTEL = 5917, + DecorationMaxConcurrencyINTEL = 5918, + DecorationPipelineEnableINTEL = 5919, + DecorationBufferLocationINTEL = 5921, + DecorationIOPipeStorageINTEL = 5944, + DecorationFunctionFloatingPointModeINTEL = 6080, + DecorationSingleElementVectorINTEL = 6085, + DecorationVectorComputeCallableFunctionINTEL = 6087, + DecorationMediaBlockIOINTEL = 6140, + DecorationStallFreeINTEL = 6151, + DecorationFPMaxErrorDecorationINTEL = 6170, + DecorationLatencyControlLabelINTEL = 6172, + DecorationLatencyControlConstraintINTEL = 6173, + DecorationConduitKernelArgumentINTEL = 6175, + DecorationRegisterMapKernelArgumentINTEL = 6176, + DecorationMMHostInterfaceAddressWidthINTEL = 6177, + DecorationMMHostInterfaceDataWidthINTEL = 6178, + DecorationMMHostInterfaceLatencyINTEL = 6179, + DecorationMMHostInterfaceReadWriteModeINTEL = 6180, + DecorationMMHostInterfaceMaxBurstINTEL = 6181, + DecorationMMHostInterfaceWaitRequestINTEL = 6182, + DecorationStableKernelArgumentINTEL = 6183, + DecorationHostAccessINTEL = 6188, + DecorationInitModeINTEL = 6190, + DecorationImplementInRegisterMapINTEL = 6191, + DecorationCacheControlLoadINTEL = 6442, + DecorationCacheControlStoreINTEL = 6443, + DecorationMax = 0x7fffffff, +}; + +enum BuiltIn { + BuiltInPosition = 0, + BuiltInPointSize = 1, + BuiltInClipDistance = 3, + BuiltInCullDistance = 4, + BuiltInVertexId = 5, + BuiltInInstanceId = 6, + BuiltInPrimitiveId = 7, + BuiltInInvocationId = 8, + BuiltInLayer = 9, + BuiltInViewportIndex = 10, + BuiltInTessLevelOuter = 11, + BuiltInTessLevelInner = 12, + BuiltInTessCoord = 13, + BuiltInPatchVertices = 14, + BuiltInFragCoord = 15, + BuiltInPointCoord = 16, + BuiltInFrontFacing = 17, + BuiltInSampleId = 18, + BuiltInSamplePosition = 19, + BuiltInSampleMask = 20, + BuiltInFragDepth = 22, + BuiltInHelperInvocation = 23, + BuiltInNumWorkgroups = 24, + BuiltInWorkgroupSize = 25, + BuiltInWorkgroupId = 26, + BuiltInLocalInvocationId = 27, + BuiltInGlobalInvocationId = 28, + BuiltInLocalInvocationIndex = 29, + BuiltInWorkDim = 30, + BuiltInGlobalSize = 31, + BuiltInEnqueuedWorkgroupSize = 32, + BuiltInGlobalOffset = 33, + BuiltInGlobalLinearId = 34, + BuiltInSubgroupSize = 36, + BuiltInSubgroupMaxSize = 37, + BuiltInNumSubgroups = 38, + BuiltInNumEnqueuedSubgroups = 39, + BuiltInSubgroupId = 40, + BuiltInSubgroupLocalInvocationId = 41, + BuiltInVertexIndex = 42, + BuiltInInstanceIndex = 43, + BuiltInCoreIDARM = 4160, + BuiltInCoreCountARM = 4161, + BuiltInCoreMaxIDARM = 4162, + BuiltInWarpIDARM = 4163, + BuiltInWarpMaxIDARM = 4164, + BuiltInSubgroupEqMask = 4416, + BuiltInSubgroupEqMaskKHR = 4416, + BuiltInSubgroupGeMask = 4417, + BuiltInSubgroupGeMaskKHR = 4417, + BuiltInSubgroupGtMask = 4418, + BuiltInSubgroupGtMaskKHR = 4418, + BuiltInSubgroupLeMask = 4419, + BuiltInSubgroupLeMaskKHR = 4419, + BuiltInSubgroupLtMask = 4420, + BuiltInSubgroupLtMaskKHR = 4420, + BuiltInBaseVertex = 4424, + BuiltInBaseInstance = 4425, + BuiltInDrawIndex = 4426, + BuiltInPrimitiveShadingRateKHR = 4432, + BuiltInDeviceIndex = 4438, + BuiltInViewIndex = 4440, + BuiltInShadingRateKHR = 4444, + BuiltInTileOffsetQCOM = 4492, + BuiltInTileDimensionQCOM = 4493, + BuiltInTileApronSizeQCOM = 4494, + BuiltInBaryCoordNoPerspAMD = 4992, + BuiltInBaryCoordNoPerspCentroidAMD = 4993, + BuiltInBaryCoordNoPerspSampleAMD = 4994, + BuiltInBaryCoordSmoothAMD = 4995, + BuiltInBaryCoordSmoothCentroidAMD = 4996, + BuiltInBaryCoordSmoothSampleAMD = 4997, + BuiltInBaryCoordPullModelAMD = 4998, + BuiltInFragStencilRefEXT = 5014, + BuiltInRemainingRecursionLevelsAMDX = 5021, + BuiltInShaderIndexAMDX = 5073, + BuiltInViewportMaskNV = 5253, + BuiltInSecondaryPositionNV = 5257, + BuiltInSecondaryViewportMaskNV = 5258, + BuiltInPositionPerViewNV = 5261, + BuiltInViewportMaskPerViewNV = 5262, + BuiltInFullyCoveredEXT = 5264, + BuiltInTaskCountNV = 5274, + BuiltInPrimitiveCountNV = 5275, + BuiltInPrimitiveIndicesNV = 5276, + BuiltInClipDistancePerViewNV = 5277, + BuiltInCullDistancePerViewNV = 5278, + BuiltInLayerPerViewNV = 5279, + BuiltInMeshViewCountNV = 5280, + BuiltInMeshViewIndicesNV = 5281, + BuiltInBaryCoordKHR = 5286, + BuiltInBaryCoordNV = 5286, + BuiltInBaryCoordNoPerspKHR = 5287, + BuiltInBaryCoordNoPerspNV = 5287, + BuiltInFragSizeEXT = 5292, + BuiltInFragmentSizeNV = 5292, + BuiltInFragInvocationCountEXT = 5293, + BuiltInInvocationsPerPixelNV = 5293, + BuiltInPrimitivePointIndicesEXT = 5294, + BuiltInPrimitiveLineIndicesEXT = 5295, + BuiltInPrimitiveTriangleIndicesEXT = 5296, + BuiltInCullPrimitiveEXT = 5299, + BuiltInLaunchIdKHR = 5319, + BuiltInLaunchIdNV = 5319, + BuiltInLaunchSizeKHR = 5320, + BuiltInLaunchSizeNV = 5320, + BuiltInWorldRayOriginKHR = 5321, + BuiltInWorldRayOriginNV = 5321, + BuiltInWorldRayDirectionKHR = 5322, + BuiltInWorldRayDirectionNV = 5322, + BuiltInObjectRayOriginKHR = 5323, + BuiltInObjectRayOriginNV = 5323, + BuiltInObjectRayDirectionKHR = 5324, + BuiltInObjectRayDirectionNV = 5324, + BuiltInRayTminKHR = 5325, + BuiltInRayTminNV = 5325, + BuiltInRayTmaxKHR = 5326, + BuiltInRayTmaxNV = 5326, + BuiltInInstanceCustomIndexKHR = 5327, + BuiltInInstanceCustomIndexNV = 5327, + BuiltInObjectToWorldKHR = 5330, + BuiltInObjectToWorldNV = 5330, + BuiltInWorldToObjectKHR = 5331, + BuiltInWorldToObjectNV = 5331, + BuiltInHitTNV = 5332, + BuiltInHitKindKHR = 5333, + BuiltInHitKindNV = 5333, + BuiltInCurrentRayTimeNV = 5334, + BuiltInHitTriangleVertexPositionsKHR = 5335, + BuiltInHitMicroTriangleVertexPositionsNV = 5337, + BuiltInHitMicroTriangleVertexBarycentricsNV = 5344, + BuiltInIncomingRayFlagsKHR = 5351, + BuiltInIncomingRayFlagsNV = 5351, + BuiltInRayGeometryIndexKHR = 5352, + BuiltInHitIsSphereNV = 5359, + BuiltInHitIsLSSNV = 5360, + BuiltInHitSpherePositionNV = 5361, + BuiltInWarpsPerSMNV = 5374, + BuiltInSMCountNV = 5375, + BuiltInWarpIDNV = 5376, + BuiltInSMIDNV = 5377, + BuiltInHitLSSPositionsNV = 5396, + BuiltInHitKindFrontFacingMicroTriangleNV = 5405, + BuiltInHitKindBackFacingMicroTriangleNV = 5406, + BuiltInHitSphereRadiusNV = 5420, + BuiltInHitLSSRadiiNV = 5421, + BuiltInClusterIDNV = 5436, + BuiltInCullMaskKHR = 6021, + BuiltInMax = 0x7fffffff, +}; + +enum SelectionControlShift { + SelectionControlFlattenShift = 0, + SelectionControlDontFlattenShift = 1, + SelectionControlMax = 0x7fffffff, +}; + +enum SelectionControlMask { + SelectionControlMaskNone = 0, + SelectionControlFlattenMask = 0x00000001, + SelectionControlDontFlattenMask = 0x00000002, +}; + +enum LoopControlShift { + LoopControlUnrollShift = 0, + LoopControlDontUnrollShift = 1, + LoopControlDependencyInfiniteShift = 2, + LoopControlDependencyLengthShift = 3, + LoopControlMinIterationsShift = 4, + LoopControlMaxIterationsShift = 5, + LoopControlIterationMultipleShift = 6, + LoopControlPeelCountShift = 7, + LoopControlPartialCountShift = 8, + LoopControlInitiationIntervalINTELShift = 16, + LoopControlMaxConcurrencyINTELShift = 17, + LoopControlDependencyArrayINTELShift = 18, + LoopControlPipelineEnableINTELShift = 19, + LoopControlLoopCoalesceINTELShift = 20, + LoopControlMaxInterleavingINTELShift = 21, + LoopControlSpeculatedIterationsINTELShift = 22, + LoopControlNoFusionINTELShift = 23, + LoopControlLoopCountINTELShift = 24, + LoopControlMaxReinvocationDelayINTELShift = 25, + LoopControlMax = 0x7fffffff, +}; + +enum LoopControlMask { + LoopControlMaskNone = 0, + LoopControlUnrollMask = 0x00000001, + LoopControlDontUnrollMask = 0x00000002, + LoopControlDependencyInfiniteMask = 0x00000004, + LoopControlDependencyLengthMask = 0x00000008, + LoopControlMinIterationsMask = 0x00000010, + LoopControlMaxIterationsMask = 0x00000020, + LoopControlIterationMultipleMask = 0x00000040, + LoopControlPeelCountMask = 0x00000080, + LoopControlPartialCountMask = 0x00000100, + LoopControlInitiationIntervalINTELMask = 0x00010000, + LoopControlMaxConcurrencyINTELMask = 0x00020000, + LoopControlDependencyArrayINTELMask = 0x00040000, + LoopControlPipelineEnableINTELMask = 0x00080000, + LoopControlLoopCoalesceINTELMask = 0x00100000, + LoopControlMaxInterleavingINTELMask = 0x00200000, + LoopControlSpeculatedIterationsINTELMask = 0x00400000, + LoopControlNoFusionINTELMask = 0x00800000, + LoopControlLoopCountINTELMask = 0x01000000, + LoopControlMaxReinvocationDelayINTELMask = 0x02000000, +}; + +enum FunctionControlShift { + FunctionControlInlineShift = 0, + FunctionControlDontInlineShift = 1, + FunctionControlPureShift = 2, + FunctionControlConstShift = 3, + FunctionControlOptNoneEXTShift = 16, + FunctionControlOptNoneINTELShift = 16, + FunctionControlMax = 0x7fffffff, +}; + +enum FunctionControlMask { + FunctionControlMaskNone = 0, + FunctionControlInlineMask = 0x00000001, + FunctionControlDontInlineMask = 0x00000002, + FunctionControlPureMask = 0x00000004, + FunctionControlConstMask = 0x00000008, + FunctionControlOptNoneEXTMask = 0x00010000, + FunctionControlOptNoneINTELMask = 0x00010000, +}; + +enum MemorySemanticsShift { + MemorySemanticsAcquireShift = 1, + MemorySemanticsReleaseShift = 2, + MemorySemanticsAcquireReleaseShift = 3, + MemorySemanticsSequentiallyConsistentShift = 4, + MemorySemanticsUniformMemoryShift = 6, + MemorySemanticsSubgroupMemoryShift = 7, + MemorySemanticsWorkgroupMemoryShift = 8, + MemorySemanticsCrossWorkgroupMemoryShift = 9, + MemorySemanticsAtomicCounterMemoryShift = 10, + MemorySemanticsImageMemoryShift = 11, + MemorySemanticsOutputMemoryShift = 12, + MemorySemanticsOutputMemoryKHRShift = 12, + MemorySemanticsMakeAvailableShift = 13, + MemorySemanticsMakeAvailableKHRShift = 13, + MemorySemanticsMakeVisibleShift = 14, + MemorySemanticsMakeVisibleKHRShift = 14, + MemorySemanticsVolatileShift = 15, + MemorySemanticsMax = 0x7fffffff, +}; + +enum MemorySemanticsMask { + MemorySemanticsMaskNone = 0, + MemorySemanticsAcquireMask = 0x00000002, + MemorySemanticsReleaseMask = 0x00000004, + MemorySemanticsAcquireReleaseMask = 0x00000008, + MemorySemanticsSequentiallyConsistentMask = 0x00000010, + MemorySemanticsUniformMemoryMask = 0x00000040, + MemorySemanticsSubgroupMemoryMask = 0x00000080, + MemorySemanticsWorkgroupMemoryMask = 0x00000100, + MemorySemanticsCrossWorkgroupMemoryMask = 0x00000200, + MemorySemanticsAtomicCounterMemoryMask = 0x00000400, + MemorySemanticsImageMemoryMask = 0x00000800, + MemorySemanticsOutputMemoryMask = 0x00001000, + MemorySemanticsOutputMemoryKHRMask = 0x00001000, + MemorySemanticsMakeAvailableMask = 0x00002000, + MemorySemanticsMakeAvailableKHRMask = 0x00002000, + MemorySemanticsMakeVisibleMask = 0x00004000, + MemorySemanticsMakeVisibleKHRMask = 0x00004000, + MemorySemanticsVolatileMask = 0x00008000, +}; + +enum MemoryAccessShift { + MemoryAccessVolatileShift = 0, + MemoryAccessAlignedShift = 1, + MemoryAccessNontemporalShift = 2, + MemoryAccessMakePointerAvailableShift = 3, + MemoryAccessMakePointerAvailableKHRShift = 3, + MemoryAccessMakePointerVisibleShift = 4, + MemoryAccessMakePointerVisibleKHRShift = 4, + MemoryAccessNonPrivatePointerShift = 5, + MemoryAccessNonPrivatePointerKHRShift = 5, + MemoryAccessAliasScopeINTELMaskShift = 16, + MemoryAccessNoAliasINTELMaskShift = 17, + MemoryAccessMax = 0x7fffffff, +}; + +enum MemoryAccessMask { + MemoryAccessMaskNone = 0, + MemoryAccessVolatileMask = 0x00000001, + MemoryAccessAlignedMask = 0x00000002, + MemoryAccessNontemporalMask = 0x00000004, + MemoryAccessMakePointerAvailableMask = 0x00000008, + MemoryAccessMakePointerAvailableKHRMask = 0x00000008, + MemoryAccessMakePointerVisibleMask = 0x00000010, + MemoryAccessMakePointerVisibleKHRMask = 0x00000010, + MemoryAccessNonPrivatePointerMask = 0x00000020, + MemoryAccessNonPrivatePointerKHRMask = 0x00000020, + MemoryAccessAliasScopeINTELMaskMask = 0x00010000, + MemoryAccessNoAliasINTELMaskMask = 0x00020000, +}; + +enum Scope { + ScopeCrossDevice = 0, + ScopeDevice = 1, + ScopeWorkgroup = 2, + ScopeSubgroup = 3, + ScopeInvocation = 4, + ScopeQueueFamily = 5, + ScopeQueueFamilyKHR = 5, + ScopeShaderCallKHR = 6, + ScopeMax = 0x7fffffff, +}; + +enum GroupOperation { + GroupOperationReduce = 0, + GroupOperationInclusiveScan = 1, + GroupOperationExclusiveScan = 2, + GroupOperationClusteredReduce = 3, + GroupOperationPartitionedReduceNV = 6, + GroupOperationPartitionedInclusiveScanNV = 7, + GroupOperationPartitionedExclusiveScanNV = 8, + GroupOperationMax = 0x7fffffff, +}; + +enum KernelEnqueueFlags { + KernelEnqueueFlagsNoWait = 0, + KernelEnqueueFlagsWaitKernel = 1, + KernelEnqueueFlagsWaitWorkGroup = 2, + KernelEnqueueFlagsMax = 0x7fffffff, +}; + +enum KernelProfilingInfoShift { + KernelProfilingInfoCmdExecTimeShift = 0, + KernelProfilingInfoMax = 0x7fffffff, +}; + +enum KernelProfilingInfoMask { + KernelProfilingInfoMaskNone = 0, + KernelProfilingInfoCmdExecTimeMask = 0x00000001, +}; + +enum Capability { + CapabilityMatrix = 0, + CapabilityShader = 1, + CapabilityGeometry = 2, + CapabilityTessellation = 3, + CapabilityAddresses = 4, + CapabilityLinkage = 5, + CapabilityKernel = 6, + CapabilityVector16 = 7, + CapabilityFloat16Buffer = 8, + CapabilityFloat16 = 9, + CapabilityFloat64 = 10, + CapabilityInt64 = 11, + CapabilityInt64Atomics = 12, + CapabilityImageBasic = 13, + CapabilityImageReadWrite = 14, + CapabilityImageMipmap = 15, + CapabilityPipes = 17, + CapabilityGroups = 18, + CapabilityDeviceEnqueue = 19, + CapabilityLiteralSampler = 20, + CapabilityAtomicStorage = 21, + CapabilityInt16 = 22, + CapabilityTessellationPointSize = 23, + CapabilityGeometryPointSize = 24, + CapabilityImageGatherExtended = 25, + CapabilityStorageImageMultisample = 27, + CapabilityUniformBufferArrayDynamicIndexing = 28, + CapabilitySampledImageArrayDynamicIndexing = 29, + CapabilityStorageBufferArrayDynamicIndexing = 30, + CapabilityStorageImageArrayDynamicIndexing = 31, + CapabilityClipDistance = 32, + CapabilityCullDistance = 33, + CapabilityImageCubeArray = 34, + CapabilitySampleRateShading = 35, + CapabilityImageRect = 36, + CapabilitySampledRect = 37, + CapabilityGenericPointer = 38, + CapabilityInt8 = 39, + CapabilityInputAttachment = 40, + CapabilitySparseResidency = 41, + CapabilityMinLod = 42, + CapabilitySampled1D = 43, + CapabilityImage1D = 44, + CapabilitySampledCubeArray = 45, + CapabilitySampledBuffer = 46, + CapabilityImageBuffer = 47, + CapabilityImageMSArray = 48, + CapabilityStorageImageExtendedFormats = 49, + CapabilityImageQuery = 50, + CapabilityDerivativeControl = 51, + CapabilityInterpolationFunction = 52, + CapabilityTransformFeedback = 53, + CapabilityGeometryStreams = 54, + CapabilityStorageImageReadWithoutFormat = 55, + CapabilityStorageImageWriteWithoutFormat = 56, + CapabilityMultiViewport = 57, + CapabilitySubgroupDispatch = 58, + CapabilityNamedBarrier = 59, + CapabilityPipeStorage = 60, + CapabilityGroupNonUniform = 61, + CapabilityGroupNonUniformVote = 62, + CapabilityGroupNonUniformArithmetic = 63, + CapabilityGroupNonUniformBallot = 64, + CapabilityGroupNonUniformShuffle = 65, + CapabilityGroupNonUniformShuffleRelative = 66, + CapabilityGroupNonUniformClustered = 67, + CapabilityGroupNonUniformQuad = 68, + CapabilityShaderLayer = 69, + CapabilityShaderViewportIndex = 70, + CapabilityUniformDecoration = 71, + CapabilityCoreBuiltinsARM = 4165, + CapabilityTileImageColorReadAccessEXT = 4166, + CapabilityTileImageDepthReadAccessEXT = 4167, + CapabilityTileImageStencilReadAccessEXT = 4168, + CapabilityCooperativeMatrixLayoutsARM = 4201, + CapabilityFragmentShadingRateKHR = 4422, + CapabilitySubgroupBallotKHR = 4423, + CapabilityDrawParameters = 4427, + CapabilityWorkgroupMemoryExplicitLayoutKHR = 4428, + CapabilityWorkgroupMemoryExplicitLayout8BitAccessKHR = 4429, + CapabilityWorkgroupMemoryExplicitLayout16BitAccessKHR = 4430, + CapabilitySubgroupVoteKHR = 4431, + CapabilityStorageBuffer16BitAccess = 4433, + CapabilityStorageUniformBufferBlock16 = 4433, + CapabilityStorageUniform16 = 4434, + CapabilityUniformAndStorageBuffer16BitAccess = 4434, + CapabilityStoragePushConstant16 = 4435, + CapabilityStorageInputOutput16 = 4436, + CapabilityDeviceGroup = 4437, + CapabilityMultiView = 4439, + CapabilityVariablePointersStorageBuffer = 4441, + CapabilityVariablePointers = 4442, + CapabilityAtomicStorageOps = 4445, + CapabilitySampleMaskPostDepthCoverage = 4447, + CapabilityStorageBuffer8BitAccess = 4448, + CapabilityUniformAndStorageBuffer8BitAccess = 4449, + CapabilityStoragePushConstant8 = 4450, + CapabilityDenormPreserve = 4464, + CapabilityDenormFlushToZero = 4465, + CapabilitySignedZeroInfNanPreserve = 4466, + CapabilityRoundingModeRTE = 4467, + CapabilityRoundingModeRTZ = 4468, + CapabilityRayQueryProvisionalKHR = 4471, + CapabilityRayQueryKHR = 4472, + CapabilityUntypedPointersKHR = 4473, + CapabilityRayTraversalPrimitiveCullingKHR = 4478, + CapabilityRayTracingKHR = 4479, + CapabilityTextureSampleWeightedQCOM = 4484, + CapabilityTextureBoxFilterQCOM = 4485, + CapabilityTextureBlockMatchQCOM = 4486, + CapabilityTileShadingQCOM = 4495, + CapabilityTextureBlockMatch2QCOM = 4498, + CapabilityFloat16ImageAMD = 5008, + CapabilityImageGatherBiasLodAMD = 5009, + CapabilityFragmentMaskAMD = 5010, + CapabilityStencilExportEXT = 5013, + CapabilityImageReadWriteLodAMD = 5015, + CapabilityInt64ImageEXT = 5016, + CapabilityShaderClockKHR = 5055, + CapabilityShaderEnqueueAMDX = 5067, + CapabilityQuadControlKHR = 5087, + CapabilityBFloat16TypeKHR = 5116, + CapabilityBFloat16DotProductKHR = 5117, + CapabilityBFloat16CooperativeMatrixKHR = 5118, + CapabilitySampleMaskOverrideCoverageNV = 5249, + CapabilityGeometryShaderPassthroughNV = 5251, + CapabilityShaderViewportIndexLayerEXT = 5254, + CapabilityShaderViewportIndexLayerNV = 5254, + CapabilityShaderViewportMaskNV = 5255, + CapabilityShaderStereoViewNV = 5259, + CapabilityPerViewAttributesNV = 5260, + CapabilityFragmentFullyCoveredEXT = 5265, + CapabilityMeshShadingNV = 5266, + CapabilityImageFootprintNV = 5282, + CapabilityMeshShadingEXT = 5283, + CapabilityFragmentBarycentricKHR = 5284, + CapabilityFragmentBarycentricNV = 5284, + CapabilityComputeDerivativeGroupQuadsKHR = 5288, + CapabilityComputeDerivativeGroupQuadsNV = 5288, + CapabilityFragmentDensityEXT = 5291, + CapabilityShadingRateNV = 5291, + CapabilityGroupNonUniformPartitionedNV = 5297, + CapabilityShaderNonUniform = 5301, + CapabilityShaderNonUniformEXT = 5301, + CapabilityRuntimeDescriptorArray = 5302, + CapabilityRuntimeDescriptorArrayEXT = 5302, + CapabilityInputAttachmentArrayDynamicIndexing = 5303, + CapabilityInputAttachmentArrayDynamicIndexingEXT = 5303, + CapabilityUniformTexelBufferArrayDynamicIndexing = 5304, + CapabilityUniformTexelBufferArrayDynamicIndexingEXT = 5304, + CapabilityStorageTexelBufferArrayDynamicIndexing = 5305, + CapabilityStorageTexelBufferArrayDynamicIndexingEXT = 5305, + CapabilityUniformBufferArrayNonUniformIndexing = 5306, + CapabilityUniformBufferArrayNonUniformIndexingEXT = 5306, + CapabilitySampledImageArrayNonUniformIndexing = 5307, + CapabilitySampledImageArrayNonUniformIndexingEXT = 5307, + CapabilityStorageBufferArrayNonUniformIndexing = 5308, + CapabilityStorageBufferArrayNonUniformIndexingEXT = 5308, + CapabilityStorageImageArrayNonUniformIndexing = 5309, + CapabilityStorageImageArrayNonUniformIndexingEXT = 5309, + CapabilityInputAttachmentArrayNonUniformIndexing = 5310, + CapabilityInputAttachmentArrayNonUniformIndexingEXT = 5310, + CapabilityUniformTexelBufferArrayNonUniformIndexing = 5311, + CapabilityUniformTexelBufferArrayNonUniformIndexingEXT = 5311, + CapabilityStorageTexelBufferArrayNonUniformIndexing = 5312, + CapabilityStorageTexelBufferArrayNonUniformIndexingEXT = 5312, + CapabilityRayTracingPositionFetchKHR = 5336, + CapabilityRayTracingNV = 5340, + CapabilityRayTracingMotionBlurNV = 5341, + CapabilityVulkanMemoryModel = 5345, + CapabilityVulkanMemoryModelKHR = 5345, + CapabilityVulkanMemoryModelDeviceScope = 5346, + CapabilityVulkanMemoryModelDeviceScopeKHR = 5346, + CapabilityPhysicalStorageBufferAddresses = 5347, + CapabilityPhysicalStorageBufferAddressesEXT = 5347, + CapabilityComputeDerivativeGroupLinearKHR = 5350, + CapabilityComputeDerivativeGroupLinearNV = 5350, + CapabilityRayTracingProvisionalKHR = 5353, + CapabilityCooperativeMatrixNV = 5357, + CapabilityFragmentShaderSampleInterlockEXT = 5363, + CapabilityFragmentShaderShadingRateInterlockEXT = 5372, + CapabilityShaderSMBuiltinsNV = 5373, + CapabilityFragmentShaderPixelInterlockEXT = 5378, + CapabilityDemoteToHelperInvocation = 5379, + CapabilityDemoteToHelperInvocationEXT = 5379, + CapabilityDisplacementMicromapNV = 5380, + CapabilityRayTracingOpacityMicromapEXT = 5381, + CapabilityShaderInvocationReorderNV = 5383, + CapabilityBindlessTextureNV = 5390, + CapabilityRayQueryPositionFetchKHR = 5391, + CapabilityCooperativeVectorNV = 5394, + CapabilityAtomicFloat16VectorNV = 5404, + CapabilityRayTracingDisplacementMicromapNV = 5409, + CapabilityRawAccessChainsNV = 5414, + CapabilityRayTracingSpheresGeometryNV = 5418, + CapabilityRayTracingLinearSweptSpheresGeometryNV = 5419, + CapabilityCooperativeMatrixReductionsNV = 5430, + CapabilityCooperativeMatrixConversionsNV = 5431, + CapabilityCooperativeMatrixPerElementOperationsNV = 5432, + CapabilityCooperativeMatrixTensorAddressingNV = 5433, + CapabilityCooperativeMatrixBlockLoadsNV = 5434, + CapabilityCooperativeVectorTrainingNV = 5435, + CapabilityRayTracingClusterAccelerationStructureNV = 5437, + CapabilityTensorAddressingNV = 5439, + CapabilitySubgroupShuffleINTEL = 5568, + CapabilitySubgroupBufferBlockIOINTEL = 5569, + CapabilitySubgroupImageBlockIOINTEL = 5570, + CapabilitySubgroupImageMediaBlockIOINTEL = 5579, + CapabilityRoundToInfinityINTEL = 5582, + CapabilityFloatingPointModeINTEL = 5583, + CapabilityIntegerFunctions2INTEL = 5584, + CapabilityFunctionPointersINTEL = 5603, + CapabilityIndirectReferencesINTEL = 5604, + CapabilityAsmINTEL = 5606, + CapabilityAtomicFloat32MinMaxEXT = 5612, + CapabilityAtomicFloat64MinMaxEXT = 5613, + CapabilityAtomicFloat16MinMaxEXT = 5616, + CapabilityVectorComputeINTEL = 5617, + CapabilityVectorAnyINTEL = 5619, + CapabilityExpectAssumeKHR = 5629, + CapabilitySubgroupAvcMotionEstimationINTEL = 5696, + CapabilitySubgroupAvcMotionEstimationIntraINTEL = 5697, + CapabilitySubgroupAvcMotionEstimationChromaINTEL = 5698, + CapabilityVariableLengthArrayINTEL = 5817, + CapabilityFunctionFloatControlINTEL = 5821, + CapabilityFPGAMemoryAttributesINTEL = 5824, + CapabilityFPFastMathModeINTEL = 5837, + CapabilityArbitraryPrecisionIntegersINTEL = 5844, + CapabilityArbitraryPrecisionFloatingPointINTEL = 5845, + CapabilityUnstructuredLoopControlsINTEL = 5886, + CapabilityFPGALoopControlsINTEL = 5888, + CapabilityKernelAttributesINTEL = 5892, + CapabilityFPGAKernelAttributesINTEL = 5897, + CapabilityFPGAMemoryAccessesINTEL = 5898, + CapabilityFPGAClusterAttributesINTEL = 5904, + CapabilityLoopFuseINTEL = 5906, + CapabilityFPGADSPControlINTEL = 5908, + CapabilityMemoryAccessAliasingINTEL = 5910, + CapabilityFPGAInvocationPipeliningAttributesINTEL = 5916, + CapabilityFPGABufferLocationINTEL = 5920, + CapabilityArbitraryPrecisionFixedPointINTEL = 5922, + CapabilityUSMStorageClassesINTEL = 5935, + CapabilityRuntimeAlignedAttributeINTEL = 5939, + CapabilityIOPipesINTEL = 5943, + CapabilityBlockingPipesINTEL = 5945, + CapabilityFPGARegINTEL = 5948, + CapabilityDotProductInputAll = 6016, + CapabilityDotProductInputAllKHR = 6016, + CapabilityDotProductInput4x8Bit = 6017, + CapabilityDotProductInput4x8BitKHR = 6017, + CapabilityDotProductInput4x8BitPacked = 6018, + CapabilityDotProductInput4x8BitPackedKHR = 6018, + CapabilityDotProduct = 6019, + CapabilityDotProductKHR = 6019, + CapabilityRayCullMaskKHR = 6020, + CapabilityCooperativeMatrixKHR = 6022, + CapabilityReplicatedCompositesEXT = 6024, + CapabilityBitInstructions = 6025, + CapabilityGroupNonUniformRotateKHR = 6026, + CapabilityFloatControls2 = 6029, + CapabilityAtomicFloat32AddEXT = 6033, + CapabilityAtomicFloat64AddEXT = 6034, + CapabilityLongCompositesINTEL = 6089, + CapabilityOptNoneEXT = 6094, + CapabilityOptNoneINTEL = 6094, + CapabilityAtomicFloat16AddEXT = 6095, + CapabilityDebugInfoModuleINTEL = 6114, + CapabilityBFloat16ConversionINTEL = 6115, + CapabilitySplitBarrierINTEL = 6141, + CapabilityArithmeticFenceEXT = 6144, + CapabilityFPGAClusterAttributesV2INTEL = 6150, + CapabilityFPGAKernelAttributesv2INTEL = 6161, + CapabilityTaskSequenceINTEL = 6162, + CapabilityFPMaxErrorINTEL = 6169, + CapabilityFPGALatencyControlINTEL = 6171, + CapabilityFPGAArgumentInterfacesINTEL = 6174, + CapabilityGlobalVariableHostAccessINTEL = 6187, + CapabilityGlobalVariableFPGADecorationsINTEL = 6189, + CapabilitySubgroupBufferPrefetchINTEL = 6220, + CapabilitySubgroup2DBlockIOINTEL = 6228, + CapabilitySubgroup2DBlockTransformINTEL = 6229, + CapabilitySubgroup2DBlockTransposeINTEL = 6230, + CapabilitySubgroupMatrixMultiplyAccumulateINTEL = 6236, + CapabilityTernaryBitwiseFunctionINTEL = 6241, + CapabilityGroupUniformArithmeticKHR = 6400, + CapabilityTensorFloat32RoundingINTEL = 6425, + CapabilityMaskedGatherScatterINTEL = 6427, + CapabilityCacheControlsINTEL = 6441, + CapabilityRegisterLimitsINTEL = 6460, + CapabilityMax = 0x7fffffff, +}; + +enum RayFlagsShift { + RayFlagsOpaqueKHRShift = 0, + RayFlagsNoOpaqueKHRShift = 1, + RayFlagsTerminateOnFirstHitKHRShift = 2, + RayFlagsSkipClosestHitShaderKHRShift = 3, + RayFlagsCullBackFacingTrianglesKHRShift = 4, + RayFlagsCullFrontFacingTrianglesKHRShift = 5, + RayFlagsCullOpaqueKHRShift = 6, + RayFlagsCullNoOpaqueKHRShift = 7, + RayFlagsSkipBuiltinPrimitivesNVShift = 8, + RayFlagsSkipTrianglesKHRShift = 8, + RayFlagsSkipAABBsKHRShift = 9, + RayFlagsForceOpacityMicromap2StateEXTShift = 10, + RayFlagsMax = 0x7fffffff, +}; + +enum RayFlagsMask { + RayFlagsMaskNone = 0, + RayFlagsOpaqueKHRMask = 0x00000001, + RayFlagsNoOpaqueKHRMask = 0x00000002, + RayFlagsTerminateOnFirstHitKHRMask = 0x00000004, + RayFlagsSkipClosestHitShaderKHRMask = 0x00000008, + RayFlagsCullBackFacingTrianglesKHRMask = 0x00000010, + RayFlagsCullFrontFacingTrianglesKHRMask = 0x00000020, + RayFlagsCullOpaqueKHRMask = 0x00000040, + RayFlagsCullNoOpaqueKHRMask = 0x00000080, + RayFlagsSkipBuiltinPrimitivesNVMask = 0x00000100, + RayFlagsSkipTrianglesKHRMask = 0x00000100, + RayFlagsSkipAABBsKHRMask = 0x00000200, + RayFlagsForceOpacityMicromap2StateEXTMask = 0x00000400, +}; + +enum RayQueryIntersection { + RayQueryIntersectionRayQueryCandidateIntersectionKHR = 0, + RayQueryIntersectionRayQueryCommittedIntersectionKHR = 1, + RayQueryIntersectionMax = 0x7fffffff, +}; + +enum RayQueryCommittedIntersectionType { + RayQueryCommittedIntersectionTypeRayQueryCommittedIntersectionNoneKHR = 0, + RayQueryCommittedIntersectionTypeRayQueryCommittedIntersectionTriangleKHR = 1, + RayQueryCommittedIntersectionTypeRayQueryCommittedIntersectionGeneratedKHR = 2, + RayQueryCommittedIntersectionTypeMax = 0x7fffffff, +}; + +enum RayQueryCandidateIntersectionType { + RayQueryCandidateIntersectionTypeRayQueryCandidateIntersectionTriangleKHR = 0, + RayQueryCandidateIntersectionTypeRayQueryCandidateIntersectionAABBKHR = 1, + RayQueryCandidateIntersectionTypeMax = 0x7fffffff, +}; + +enum FragmentShadingRateShift { + FragmentShadingRateVertical2PixelsShift = 0, + FragmentShadingRateVertical4PixelsShift = 1, + FragmentShadingRateHorizontal2PixelsShift = 2, + FragmentShadingRateHorizontal4PixelsShift = 3, + FragmentShadingRateMax = 0x7fffffff, +}; + +enum FragmentShadingRateMask { + FragmentShadingRateMaskNone = 0, + FragmentShadingRateVertical2PixelsMask = 0x00000001, + FragmentShadingRateVertical4PixelsMask = 0x00000002, + FragmentShadingRateHorizontal2PixelsMask = 0x00000004, + FragmentShadingRateHorizontal4PixelsMask = 0x00000008, +}; + +enum FPDenormMode { + FPDenormModePreserve = 0, + FPDenormModeFlushToZero = 1, + FPDenormModeMax = 0x7fffffff, +}; + +enum FPOperationMode { + FPOperationModeIEEE = 0, + FPOperationModeALT = 1, + FPOperationModeMax = 0x7fffffff, +}; + +enum QuantizationModes { + QuantizationModesTRN = 0, + QuantizationModesTRN_ZERO = 1, + QuantizationModesRND = 2, + QuantizationModesRND_ZERO = 3, + QuantizationModesRND_INF = 4, + QuantizationModesRND_MIN_INF = 5, + QuantizationModesRND_CONV = 6, + QuantizationModesRND_CONV_ODD = 7, + QuantizationModesMax = 0x7fffffff, +}; + +enum OverflowModes { + OverflowModesWRAP = 0, + OverflowModesSAT = 1, + OverflowModesSAT_ZERO = 2, + OverflowModesSAT_SYM = 3, + OverflowModesMax = 0x7fffffff, +}; + +enum PackedVectorFormat { + PackedVectorFormatPackedVectorFormat4x8Bit = 0, + PackedVectorFormatPackedVectorFormat4x8BitKHR = 0, + PackedVectorFormatMax = 0x7fffffff, +}; + +enum CooperativeMatrixOperandsShift { + CooperativeMatrixOperandsMatrixASignedComponentsKHRShift = 0, + CooperativeMatrixOperandsMatrixBSignedComponentsKHRShift = 1, + CooperativeMatrixOperandsMatrixCSignedComponentsKHRShift = 2, + CooperativeMatrixOperandsMatrixResultSignedComponentsKHRShift = 3, + CooperativeMatrixOperandsSaturatingAccumulationKHRShift = 4, + CooperativeMatrixOperandsMax = 0x7fffffff, +}; + +enum CooperativeMatrixOperandsMask { + CooperativeMatrixOperandsMaskNone = 0, + CooperativeMatrixOperandsMatrixASignedComponentsKHRMask = 0x00000001, + CooperativeMatrixOperandsMatrixBSignedComponentsKHRMask = 0x00000002, + CooperativeMatrixOperandsMatrixCSignedComponentsKHRMask = 0x00000004, + CooperativeMatrixOperandsMatrixResultSignedComponentsKHRMask = 0x00000008, + CooperativeMatrixOperandsSaturatingAccumulationKHRMask = 0x00000010, +}; + +enum CooperativeMatrixLayout { + CooperativeMatrixLayoutRowMajorKHR = 0, + CooperativeMatrixLayoutColumnMajorKHR = 1, + CooperativeMatrixLayoutRowBlockedInterleavedARM = 4202, + CooperativeMatrixLayoutColumnBlockedInterleavedARM = 4203, + CooperativeMatrixLayoutMax = 0x7fffffff, +}; + +enum CooperativeMatrixUse { + CooperativeMatrixUseMatrixAKHR = 0, + CooperativeMatrixUseMatrixBKHR = 1, + CooperativeMatrixUseMatrixAccumulatorKHR = 2, + CooperativeMatrixUseMax = 0x7fffffff, +}; + +enum CooperativeMatrixReduceShift { + CooperativeMatrixReduceRowShift = 0, + CooperativeMatrixReduceColumnShift = 1, + CooperativeMatrixReduce2x2Shift = 2, + CooperativeMatrixReduceMax = 0x7fffffff, +}; + +enum CooperativeMatrixReduceMask { + CooperativeMatrixReduceMaskNone = 0, + CooperativeMatrixReduceRowMask = 0x00000001, + CooperativeMatrixReduceColumnMask = 0x00000002, + CooperativeMatrixReduce2x2Mask = 0x00000004, +}; + +enum TensorClampMode { + TensorClampModeUndefined = 0, + TensorClampModeConstant = 1, + TensorClampModeClampToEdge = 2, + TensorClampModeRepeat = 3, + TensorClampModeRepeatMirrored = 4, + TensorClampModeMax = 0x7fffffff, +}; + +enum TensorAddressingOperandsShift { + TensorAddressingOperandsTensorViewShift = 0, + TensorAddressingOperandsDecodeFuncShift = 1, + TensorAddressingOperandsMax = 0x7fffffff, +}; + +enum TensorAddressingOperandsMask { + TensorAddressingOperandsMaskNone = 0, + TensorAddressingOperandsTensorViewMask = 0x00000001, + TensorAddressingOperandsDecodeFuncMask = 0x00000002, +}; + +enum InitializationModeQualifier { + InitializationModeQualifierInitOnDeviceReprogramINTEL = 0, + InitializationModeQualifierInitOnDeviceResetINTEL = 1, + InitializationModeQualifierMax = 0x7fffffff, +}; + +enum HostAccessQualifier { + HostAccessQualifierNoneINTEL = 0, + HostAccessQualifierReadINTEL = 1, + HostAccessQualifierWriteINTEL = 2, + HostAccessQualifierReadWriteINTEL = 3, + HostAccessQualifierMax = 0x7fffffff, +}; + +enum LoadCacheControl { + LoadCacheControlUncachedINTEL = 0, + LoadCacheControlCachedINTEL = 1, + LoadCacheControlStreamingINTEL = 2, + LoadCacheControlInvalidateAfterReadINTEL = 3, + LoadCacheControlConstCachedINTEL = 4, + LoadCacheControlMax = 0x7fffffff, +}; + +enum StoreCacheControl { + StoreCacheControlUncachedINTEL = 0, + StoreCacheControlWriteThroughINTEL = 1, + StoreCacheControlWriteBackINTEL = 2, + StoreCacheControlStreamingINTEL = 3, + StoreCacheControlMax = 0x7fffffff, +}; + +enum NamedMaximumNumberOfRegisters { + NamedMaximumNumberOfRegistersAutoINTEL = 0, + NamedMaximumNumberOfRegistersMax = 0x7fffffff, +}; + +enum MatrixMultiplyAccumulateOperandsShift { + MatrixMultiplyAccumulateOperandsMatrixASignedComponentsINTELShift = 0, + MatrixMultiplyAccumulateOperandsMatrixBSignedComponentsINTELShift = 1, + MatrixMultiplyAccumulateOperandsMatrixCBFloat16INTELShift = 2, + MatrixMultiplyAccumulateOperandsMatrixResultBFloat16INTELShift = 3, + MatrixMultiplyAccumulateOperandsMatrixAPackedInt8INTELShift = 4, + MatrixMultiplyAccumulateOperandsMatrixBPackedInt8INTELShift = 5, + MatrixMultiplyAccumulateOperandsMatrixAPackedInt4INTELShift = 6, + MatrixMultiplyAccumulateOperandsMatrixBPackedInt4INTELShift = 7, + MatrixMultiplyAccumulateOperandsMatrixATF32INTELShift = 8, + MatrixMultiplyAccumulateOperandsMatrixBTF32INTELShift = 9, + MatrixMultiplyAccumulateOperandsMatrixAPackedFloat16INTELShift = 10, + MatrixMultiplyAccumulateOperandsMatrixBPackedFloat16INTELShift = 11, + MatrixMultiplyAccumulateOperandsMatrixAPackedBFloat16INTELShift = 12, + MatrixMultiplyAccumulateOperandsMatrixBPackedBFloat16INTELShift = 13, + MatrixMultiplyAccumulateOperandsMax = 0x7fffffff, +}; + +enum MatrixMultiplyAccumulateOperandsMask { + MatrixMultiplyAccumulateOperandsMaskNone = 0, + MatrixMultiplyAccumulateOperandsMatrixASignedComponentsINTELMask = 0x00000001, + MatrixMultiplyAccumulateOperandsMatrixBSignedComponentsINTELMask = 0x00000002, + MatrixMultiplyAccumulateOperandsMatrixCBFloat16INTELMask = 0x00000004, + MatrixMultiplyAccumulateOperandsMatrixResultBFloat16INTELMask = 0x00000008, + MatrixMultiplyAccumulateOperandsMatrixAPackedInt8INTELMask = 0x00000010, + MatrixMultiplyAccumulateOperandsMatrixBPackedInt8INTELMask = 0x00000020, + MatrixMultiplyAccumulateOperandsMatrixAPackedInt4INTELMask = 0x00000040, + MatrixMultiplyAccumulateOperandsMatrixBPackedInt4INTELMask = 0x00000080, + MatrixMultiplyAccumulateOperandsMatrixATF32INTELMask = 0x00000100, + MatrixMultiplyAccumulateOperandsMatrixBTF32INTELMask = 0x00000200, + MatrixMultiplyAccumulateOperandsMatrixAPackedFloat16INTELMask = 0x00000400, + MatrixMultiplyAccumulateOperandsMatrixBPackedFloat16INTELMask = 0x00000800, + MatrixMultiplyAccumulateOperandsMatrixAPackedBFloat16INTELMask = 0x00001000, + MatrixMultiplyAccumulateOperandsMatrixBPackedBFloat16INTELMask = 0x00002000, +}; + +enum RawAccessChainOperandsShift { + RawAccessChainOperandsRobustnessPerComponentNVShift = 0, + RawAccessChainOperandsRobustnessPerElementNVShift = 1, + RawAccessChainOperandsMax = 0x7fffffff, +}; + +enum RawAccessChainOperandsMask { + RawAccessChainOperandsMaskNone = 0, + RawAccessChainOperandsRobustnessPerComponentNVMask = 0x00000001, + RawAccessChainOperandsRobustnessPerElementNVMask = 0x00000002, +}; + +enum FPEncoding { + FPEncodingBFloat16KHR = 0, + FPEncodingMax = 0x7fffffff, +}; + +enum CooperativeVectorMatrixLayout { + CooperativeVectorMatrixLayoutRowMajorNV = 0, + CooperativeVectorMatrixLayoutColumnMajorNV = 1, + CooperativeVectorMatrixLayoutInferencingOptimalNV = 2, + CooperativeVectorMatrixLayoutTrainingOptimalNV = 3, + CooperativeVectorMatrixLayoutMax = 0x7fffffff, +}; + +enum ComponentType { + ComponentTypeFloat16NV = 0, + ComponentTypeFloat32NV = 1, + ComponentTypeFloat64NV = 2, + ComponentTypeSignedInt8NV = 3, + ComponentTypeSignedInt16NV = 4, + ComponentTypeSignedInt32NV = 5, + ComponentTypeSignedInt64NV = 6, + ComponentTypeUnsignedInt8NV = 7, + ComponentTypeUnsignedInt16NV = 8, + ComponentTypeUnsignedInt32NV = 9, + ComponentTypeUnsignedInt64NV = 10, + ComponentTypeSignedInt8PackedNV = 1000491000, + ComponentTypeUnsignedInt8PackedNV = 1000491001, + ComponentTypeFloatE4M3NV = 1000491002, + ComponentTypeFloatE5M2NV = 1000491003, + ComponentTypeMax = 0x7fffffff, +}; + +enum Op { + OpNop = 0, + OpUndef = 1, + OpSourceContinued = 2, + OpSource = 3, + OpSourceExtension = 4, + OpName = 5, + OpMemberName = 6, + OpString = 7, + OpLine = 8, + OpExtension = 10, + OpExtInstImport = 11, + OpExtInst = 12, + OpMemoryModel = 14, + OpEntryPoint = 15, + OpExecutionMode = 16, + OpCapability = 17, + OpTypeVoid = 19, + OpTypeBool = 20, + OpTypeInt = 21, + OpTypeFloat = 22, + OpTypeVector = 23, + OpTypeMatrix = 24, + OpTypeImage = 25, + OpTypeSampler = 26, + OpTypeSampledImage = 27, + OpTypeArray = 28, + OpTypeRuntimeArray = 29, + OpTypeStruct = 30, + OpTypeOpaque = 31, + OpTypePointer = 32, + OpTypeFunction = 33, + OpTypeEvent = 34, + OpTypeDeviceEvent = 35, + OpTypeReserveId = 36, + OpTypeQueue = 37, + OpTypePipe = 38, + OpTypeForwardPointer = 39, + OpConstantTrue = 41, + OpConstantFalse = 42, + OpConstant = 43, + OpConstantComposite = 44, + OpConstantSampler = 45, + OpConstantNull = 46, + OpSpecConstantTrue = 48, + OpSpecConstantFalse = 49, + OpSpecConstant = 50, + OpSpecConstantComposite = 51, + OpSpecConstantOp = 52, + OpFunction = 54, + OpFunctionParameter = 55, + OpFunctionEnd = 56, + OpFunctionCall = 57, + OpVariable = 59, + OpImageTexelPointer = 60, + OpLoad = 61, + OpStore = 62, + OpCopyMemory = 63, + OpCopyMemorySized = 64, + OpAccessChain = 65, + OpInBoundsAccessChain = 66, + OpPtrAccessChain = 67, + OpArrayLength = 68, + OpGenericPtrMemSemantics = 69, + OpInBoundsPtrAccessChain = 70, + OpDecorate = 71, + OpMemberDecorate = 72, + OpDecorationGroup = 73, + OpGroupDecorate = 74, + OpGroupMemberDecorate = 75, + OpVectorExtractDynamic = 77, + OpVectorInsertDynamic = 78, + OpVectorShuffle = 79, + OpCompositeConstruct = 80, + OpCompositeExtract = 81, + OpCompositeInsert = 82, + OpCopyObject = 83, + OpTranspose = 84, + OpSampledImage = 86, + OpImageSampleImplicitLod = 87, + OpImageSampleExplicitLod = 88, + OpImageSampleDrefImplicitLod = 89, + OpImageSampleDrefExplicitLod = 90, + OpImageSampleProjImplicitLod = 91, + OpImageSampleProjExplicitLod = 92, + OpImageSampleProjDrefImplicitLod = 93, + OpImageSampleProjDrefExplicitLod = 94, + OpImageFetch = 95, + OpImageGather = 96, + OpImageDrefGather = 97, + OpImageRead = 98, + OpImageWrite = 99, + OpImage = 100, + OpImageQueryFormat = 101, + OpImageQueryOrder = 102, + OpImageQuerySizeLod = 103, + OpImageQuerySize = 104, + OpImageQueryLod = 105, + OpImageQueryLevels = 106, + OpImageQuerySamples = 107, + OpConvertFToU = 109, + OpConvertFToS = 110, + OpConvertSToF = 111, + OpConvertUToF = 112, + OpUConvert = 113, + OpSConvert = 114, + OpFConvert = 115, + OpQuantizeToF16 = 116, + OpConvertPtrToU = 117, + OpSatConvertSToU = 118, + OpSatConvertUToS = 119, + OpConvertUToPtr = 120, + OpPtrCastToGeneric = 121, + OpGenericCastToPtr = 122, + OpGenericCastToPtrExplicit = 123, + OpBitcast = 124, + OpSNegate = 126, + OpFNegate = 127, + OpIAdd = 128, + OpFAdd = 129, + OpISub = 130, + OpFSub = 131, + OpIMul = 132, + OpFMul = 133, + OpUDiv = 134, + OpSDiv = 135, + OpFDiv = 136, + OpUMod = 137, + OpSRem = 138, + OpSMod = 139, + OpFRem = 140, + OpFMod = 141, + OpVectorTimesScalar = 142, + OpMatrixTimesScalar = 143, + OpVectorTimesMatrix = 144, + OpMatrixTimesVector = 145, + OpMatrixTimesMatrix = 146, + OpOuterProduct = 147, + OpDot = 148, + OpIAddCarry = 149, + OpISubBorrow = 150, + OpUMulExtended = 151, + OpSMulExtended = 152, + OpAny = 154, + OpAll = 155, + OpIsNan = 156, + OpIsInf = 157, + OpIsFinite = 158, + OpIsNormal = 159, + OpSignBitSet = 160, + OpLessOrGreater = 161, + OpOrdered = 162, + OpUnordered = 163, + OpLogicalEqual = 164, + OpLogicalNotEqual = 165, + OpLogicalOr = 166, + OpLogicalAnd = 167, + OpLogicalNot = 168, + OpSelect = 169, + OpIEqual = 170, + OpINotEqual = 171, + OpUGreaterThan = 172, + OpSGreaterThan = 173, + OpUGreaterThanEqual = 174, + OpSGreaterThanEqual = 175, + OpULessThan = 176, + OpSLessThan = 177, + OpULessThanEqual = 178, + OpSLessThanEqual = 179, + OpFOrdEqual = 180, + OpFUnordEqual = 181, + OpFOrdNotEqual = 182, + OpFUnordNotEqual = 183, + OpFOrdLessThan = 184, + OpFUnordLessThan = 185, + OpFOrdGreaterThan = 186, + OpFUnordGreaterThan = 187, + OpFOrdLessThanEqual = 188, + OpFUnordLessThanEqual = 189, + OpFOrdGreaterThanEqual = 190, + OpFUnordGreaterThanEqual = 191, + OpShiftRightLogical = 194, + OpShiftRightArithmetic = 195, + OpShiftLeftLogical = 196, + OpBitwiseOr = 197, + OpBitwiseXor = 198, + OpBitwiseAnd = 199, + OpNot = 200, + OpBitFieldInsert = 201, + OpBitFieldSExtract = 202, + OpBitFieldUExtract = 203, + OpBitReverse = 204, + OpBitCount = 205, + OpDPdx = 207, + OpDPdy = 208, + OpFwidth = 209, + OpDPdxFine = 210, + OpDPdyFine = 211, + OpFwidthFine = 212, + OpDPdxCoarse = 213, + OpDPdyCoarse = 214, + OpFwidthCoarse = 215, + OpEmitVertex = 218, + OpEndPrimitive = 219, + OpEmitStreamVertex = 220, + OpEndStreamPrimitive = 221, + OpControlBarrier = 224, + OpMemoryBarrier = 225, + OpAtomicLoad = 227, + OpAtomicStore = 228, + OpAtomicExchange = 229, + OpAtomicCompareExchange = 230, + OpAtomicCompareExchangeWeak = 231, + OpAtomicIIncrement = 232, + OpAtomicIDecrement = 233, + OpAtomicIAdd = 234, + OpAtomicISub = 235, + OpAtomicSMin = 236, + OpAtomicUMin = 237, + OpAtomicSMax = 238, + OpAtomicUMax = 239, + OpAtomicAnd = 240, + OpAtomicOr = 241, + OpAtomicXor = 242, + OpPhi = 245, + OpLoopMerge = 246, + OpSelectionMerge = 247, + OpLabel = 248, + OpBranch = 249, + OpBranchConditional = 250, + OpSwitch = 251, + OpKill = 252, + OpReturn = 253, + OpReturnValue = 254, + OpUnreachable = 255, + OpLifetimeStart = 256, + OpLifetimeStop = 257, + OpGroupAsyncCopy = 259, + OpGroupWaitEvents = 260, + OpGroupAll = 261, + OpGroupAny = 262, + OpGroupBroadcast = 263, + OpGroupIAdd = 264, + OpGroupFAdd = 265, + OpGroupFMin = 266, + OpGroupUMin = 267, + OpGroupSMin = 268, + OpGroupFMax = 269, + OpGroupUMax = 270, + OpGroupSMax = 271, + OpReadPipe = 274, + OpWritePipe = 275, + OpReservedReadPipe = 276, + OpReservedWritePipe = 277, + OpReserveReadPipePackets = 278, + OpReserveWritePipePackets = 279, + OpCommitReadPipe = 280, + OpCommitWritePipe = 281, + OpIsValidReserveId = 282, + OpGetNumPipePackets = 283, + OpGetMaxPipePackets = 284, + OpGroupReserveReadPipePackets = 285, + OpGroupReserveWritePipePackets = 286, + OpGroupCommitReadPipe = 287, + OpGroupCommitWritePipe = 288, + OpEnqueueMarker = 291, + OpEnqueueKernel = 292, + OpGetKernelNDrangeSubGroupCount = 293, + OpGetKernelNDrangeMaxSubGroupSize = 294, + OpGetKernelWorkGroupSize = 295, + OpGetKernelPreferredWorkGroupSizeMultiple = 296, + OpRetainEvent = 297, + OpReleaseEvent = 298, + OpCreateUserEvent = 299, + OpIsValidEvent = 300, + OpSetUserEventStatus = 301, + OpCaptureEventProfilingInfo = 302, + OpGetDefaultQueue = 303, + OpBuildNDRange = 304, + OpImageSparseSampleImplicitLod = 305, + OpImageSparseSampleExplicitLod = 306, + OpImageSparseSampleDrefImplicitLod = 307, + OpImageSparseSampleDrefExplicitLod = 308, + OpImageSparseSampleProjImplicitLod = 309, + OpImageSparseSampleProjExplicitLod = 310, + OpImageSparseSampleProjDrefImplicitLod = 311, + OpImageSparseSampleProjDrefExplicitLod = 312, + OpImageSparseFetch = 313, + OpImageSparseGather = 314, + OpImageSparseDrefGather = 315, + OpImageSparseTexelsResident = 316, + OpNoLine = 317, + OpAtomicFlagTestAndSet = 318, + OpAtomicFlagClear = 319, + OpImageSparseRead = 320, + OpSizeOf = 321, + OpTypePipeStorage = 322, + OpConstantPipeStorage = 323, + OpCreatePipeFromPipeStorage = 324, + OpGetKernelLocalSizeForSubgroupCount = 325, + OpGetKernelMaxNumSubgroups = 326, + OpTypeNamedBarrier = 327, + OpNamedBarrierInitialize = 328, + OpMemoryNamedBarrier = 329, + OpModuleProcessed = 330, + OpExecutionModeId = 331, + OpDecorateId = 332, + OpGroupNonUniformElect = 333, + OpGroupNonUniformAll = 334, + OpGroupNonUniformAny = 335, + OpGroupNonUniformAllEqual = 336, + OpGroupNonUniformBroadcast = 337, + OpGroupNonUniformBroadcastFirst = 338, + OpGroupNonUniformBallot = 339, + OpGroupNonUniformInverseBallot = 340, + OpGroupNonUniformBallotBitExtract = 341, + OpGroupNonUniformBallotBitCount = 342, + OpGroupNonUniformBallotFindLSB = 343, + OpGroupNonUniformBallotFindMSB = 344, + OpGroupNonUniformShuffle = 345, + OpGroupNonUniformShuffleXor = 346, + OpGroupNonUniformShuffleUp = 347, + OpGroupNonUniformShuffleDown = 348, + OpGroupNonUniformIAdd = 349, + OpGroupNonUniformFAdd = 350, + OpGroupNonUniformIMul = 351, + OpGroupNonUniformFMul = 352, + OpGroupNonUniformSMin = 353, + OpGroupNonUniformUMin = 354, + OpGroupNonUniformFMin = 355, + OpGroupNonUniformSMax = 356, + OpGroupNonUniformUMax = 357, + OpGroupNonUniformFMax = 358, + OpGroupNonUniformBitwiseAnd = 359, + OpGroupNonUniformBitwiseOr = 360, + OpGroupNonUniformBitwiseXor = 361, + OpGroupNonUniformLogicalAnd = 362, + OpGroupNonUniformLogicalOr = 363, + OpGroupNonUniformLogicalXor = 364, + OpGroupNonUniformQuadBroadcast = 365, + OpGroupNonUniformQuadSwap = 366, + OpCopyLogical = 400, + OpPtrEqual = 401, + OpPtrNotEqual = 402, + OpPtrDiff = 403, + OpColorAttachmentReadEXT = 4160, + OpDepthAttachmentReadEXT = 4161, + OpStencilAttachmentReadEXT = 4162, + OpTerminateInvocation = 4416, + OpTypeUntypedPointerKHR = 4417, + OpUntypedVariableKHR = 4418, + OpUntypedAccessChainKHR = 4419, + OpUntypedInBoundsAccessChainKHR = 4420, + OpSubgroupBallotKHR = 4421, + OpSubgroupFirstInvocationKHR = 4422, + OpUntypedPtrAccessChainKHR = 4423, + OpUntypedInBoundsPtrAccessChainKHR = 4424, + OpUntypedArrayLengthKHR = 4425, + OpUntypedPrefetchKHR = 4426, + OpSubgroupAllKHR = 4428, + OpSubgroupAnyKHR = 4429, + OpSubgroupAllEqualKHR = 4430, + OpGroupNonUniformRotateKHR = 4431, + OpSubgroupReadInvocationKHR = 4432, + OpExtInstWithForwardRefsKHR = 4433, + OpTraceRayKHR = 4445, + OpExecuteCallableKHR = 4446, + OpConvertUToAccelerationStructureKHR = 4447, + OpIgnoreIntersectionKHR = 4448, + OpTerminateRayKHR = 4449, + OpSDot = 4450, + OpSDotKHR = 4450, + OpUDot = 4451, + OpUDotKHR = 4451, + OpSUDot = 4452, + OpSUDotKHR = 4452, + OpSDotAccSat = 4453, + OpSDotAccSatKHR = 4453, + OpUDotAccSat = 4454, + OpUDotAccSatKHR = 4454, + OpSUDotAccSat = 4455, + OpSUDotAccSatKHR = 4455, + OpTypeCooperativeMatrixKHR = 4456, + OpCooperativeMatrixLoadKHR = 4457, + OpCooperativeMatrixStoreKHR = 4458, + OpCooperativeMatrixMulAddKHR = 4459, + OpCooperativeMatrixLengthKHR = 4460, + OpConstantCompositeReplicateEXT = 4461, + OpSpecConstantCompositeReplicateEXT = 4462, + OpCompositeConstructReplicateEXT = 4463, + OpTypeRayQueryKHR = 4472, + OpRayQueryInitializeKHR = 4473, + OpRayQueryTerminateKHR = 4474, + OpRayQueryGenerateIntersectionKHR = 4475, + OpRayQueryConfirmIntersectionKHR = 4476, + OpRayQueryProceedKHR = 4477, + OpRayQueryGetIntersectionTypeKHR = 4479, + OpImageSampleWeightedQCOM = 4480, + OpImageBoxFilterQCOM = 4481, + OpImageBlockMatchSSDQCOM = 4482, + OpImageBlockMatchSADQCOM = 4483, + OpImageBlockMatchWindowSSDQCOM = 4500, + OpImageBlockMatchWindowSADQCOM = 4501, + OpImageBlockMatchGatherSSDQCOM = 4502, + OpImageBlockMatchGatherSADQCOM = 4503, + OpGroupIAddNonUniformAMD = 5000, + OpGroupFAddNonUniformAMD = 5001, + OpGroupFMinNonUniformAMD = 5002, + OpGroupUMinNonUniformAMD = 5003, + OpGroupSMinNonUniformAMD = 5004, + OpGroupFMaxNonUniformAMD = 5005, + OpGroupUMaxNonUniformAMD = 5006, + OpGroupSMaxNonUniformAMD = 5007, + OpFragmentMaskFetchAMD = 5011, + OpFragmentFetchAMD = 5012, + OpReadClockKHR = 5056, + OpAllocateNodePayloadsAMDX = 5074, + OpEnqueueNodePayloadsAMDX = 5075, + OpTypeNodePayloadArrayAMDX = 5076, + OpFinishWritingNodePayloadAMDX = 5078, + OpNodePayloadArrayLengthAMDX = 5090, + OpIsNodePayloadValidAMDX = 5101, + OpConstantStringAMDX = 5103, + OpSpecConstantStringAMDX = 5104, + OpGroupNonUniformQuadAllKHR = 5110, + OpGroupNonUniformQuadAnyKHR = 5111, + OpHitObjectRecordHitMotionNV = 5249, + OpHitObjectRecordHitWithIndexMotionNV = 5250, + OpHitObjectRecordMissMotionNV = 5251, + OpHitObjectGetWorldToObjectNV = 5252, + OpHitObjectGetObjectToWorldNV = 5253, + OpHitObjectGetObjectRayDirectionNV = 5254, + OpHitObjectGetObjectRayOriginNV = 5255, + OpHitObjectTraceRayMotionNV = 5256, + OpHitObjectGetShaderRecordBufferHandleNV = 5257, + OpHitObjectGetShaderBindingTableRecordIndexNV = 5258, + OpHitObjectRecordEmptyNV = 5259, + OpHitObjectTraceRayNV = 5260, + OpHitObjectRecordHitNV = 5261, + OpHitObjectRecordHitWithIndexNV = 5262, + OpHitObjectRecordMissNV = 5263, + OpHitObjectExecuteShaderNV = 5264, + OpHitObjectGetCurrentTimeNV = 5265, + OpHitObjectGetAttributesNV = 5266, + OpHitObjectGetHitKindNV = 5267, + OpHitObjectGetPrimitiveIndexNV = 5268, + OpHitObjectGetGeometryIndexNV = 5269, + OpHitObjectGetInstanceIdNV = 5270, + OpHitObjectGetInstanceCustomIndexNV = 5271, + OpHitObjectGetWorldRayDirectionNV = 5272, + OpHitObjectGetWorldRayOriginNV = 5273, + OpHitObjectGetRayTMaxNV = 5274, + OpHitObjectGetRayTMinNV = 5275, + OpHitObjectIsEmptyNV = 5276, + OpHitObjectIsHitNV = 5277, + OpHitObjectIsMissNV = 5278, + OpReorderThreadWithHitObjectNV = 5279, + OpReorderThreadWithHintNV = 5280, + OpTypeHitObjectNV = 5281, + OpImageSampleFootprintNV = 5283, + OpTypeCooperativeVectorNV = 5288, + OpCooperativeVectorMatrixMulNV = 5289, + OpCooperativeVectorOuterProductAccumulateNV = 5290, + OpCooperativeVectorReduceSumAccumulateNV = 5291, + OpCooperativeVectorMatrixMulAddNV = 5292, + OpCooperativeMatrixConvertNV = 5293, + OpEmitMeshTasksEXT = 5294, + OpSetMeshOutputsEXT = 5295, + OpGroupNonUniformPartitionNV = 5296, + OpWritePackedPrimitiveIndices4x8NV = 5299, + OpFetchMicroTriangleVertexPositionNV = 5300, + OpFetchMicroTriangleVertexBarycentricNV = 5301, + OpCooperativeVectorLoadNV = 5302, + OpCooperativeVectorStoreNV = 5303, + OpReportIntersectionKHR = 5334, + OpReportIntersectionNV = 5334, + OpIgnoreIntersectionNV = 5335, + OpTerminateRayNV = 5336, + OpTraceNV = 5337, + OpTraceMotionNV = 5338, + OpTraceRayMotionNV = 5339, + OpRayQueryGetIntersectionTriangleVertexPositionsKHR = 5340, + OpTypeAccelerationStructureKHR = 5341, + OpTypeAccelerationStructureNV = 5341, + OpExecuteCallableNV = 5344, + OpRayQueryGetClusterIdNV = 5345, + OpHitObjectGetClusterIdNV = 5346, + OpTypeCooperativeMatrixNV = 5358, + OpCooperativeMatrixLoadNV = 5359, + OpCooperativeMatrixStoreNV = 5360, + OpCooperativeMatrixMulAddNV = 5361, + OpCooperativeMatrixLengthNV = 5362, + OpBeginInvocationInterlockEXT = 5364, + OpEndInvocationInterlockEXT = 5365, + OpCooperativeMatrixReduceNV = 5366, + OpCooperativeMatrixLoadTensorNV = 5367, + OpCooperativeMatrixStoreTensorNV = 5368, + OpCooperativeMatrixPerElementOpNV = 5369, + OpTypeTensorLayoutNV = 5370, + OpTypeTensorViewNV = 5371, + OpCreateTensorLayoutNV = 5372, + OpTensorLayoutSetDimensionNV = 5373, + OpTensorLayoutSetStrideNV = 5374, + OpTensorLayoutSliceNV = 5375, + OpTensorLayoutSetClampValueNV = 5376, + OpCreateTensorViewNV = 5377, + OpTensorViewSetDimensionNV = 5378, + OpTensorViewSetStrideNV = 5379, + OpDemoteToHelperInvocation = 5380, + OpDemoteToHelperInvocationEXT = 5380, + OpIsHelperInvocationEXT = 5381, + OpTensorViewSetClipNV = 5382, + OpTensorLayoutSetBlockSizeNV = 5384, + OpCooperativeMatrixTransposeNV = 5390, + OpConvertUToImageNV = 5391, + OpConvertUToSamplerNV = 5392, + OpConvertImageToUNV = 5393, + OpConvertSamplerToUNV = 5394, + OpConvertUToSampledImageNV = 5395, + OpConvertSampledImageToUNV = 5396, + OpSamplerImageAddressingModeNV = 5397, + OpRawAccessChainNV = 5398, + OpRayQueryGetIntersectionSpherePositionNV = 5427, + OpRayQueryGetIntersectionSphereRadiusNV = 5428, + OpRayQueryGetIntersectionLSSPositionsNV = 5429, + OpRayQueryGetIntersectionLSSRadiiNV = 5430, + OpRayQueryGetIntersectionLSSHitValueNV = 5431, + OpHitObjectGetSpherePositionNV = 5432, + OpHitObjectGetSphereRadiusNV = 5433, + OpHitObjectGetLSSPositionsNV = 5434, + OpHitObjectGetLSSRadiiNV = 5435, + OpHitObjectIsSphereHitNV = 5436, + OpHitObjectIsLSSHitNV = 5437, + OpRayQueryIsSphereHitNV = 5438, + OpRayQueryIsLSSHitNV = 5439, + OpSubgroupShuffleINTEL = 5571, + OpSubgroupShuffleDownINTEL = 5572, + OpSubgroupShuffleUpINTEL = 5573, + OpSubgroupShuffleXorINTEL = 5574, + OpSubgroupBlockReadINTEL = 5575, + OpSubgroupBlockWriteINTEL = 5576, + OpSubgroupImageBlockReadINTEL = 5577, + OpSubgroupImageBlockWriteINTEL = 5578, + OpSubgroupImageMediaBlockReadINTEL = 5580, + OpSubgroupImageMediaBlockWriteINTEL = 5581, + OpUCountLeadingZerosINTEL = 5585, + OpUCountTrailingZerosINTEL = 5586, + OpAbsISubINTEL = 5587, + OpAbsUSubINTEL = 5588, + OpIAddSatINTEL = 5589, + OpUAddSatINTEL = 5590, + OpIAverageINTEL = 5591, + OpUAverageINTEL = 5592, + OpIAverageRoundedINTEL = 5593, + OpUAverageRoundedINTEL = 5594, + OpISubSatINTEL = 5595, + OpUSubSatINTEL = 5596, + OpIMul32x16INTEL = 5597, + OpUMul32x16INTEL = 5598, + OpConstantFunctionPointerINTEL = 5600, + OpFunctionPointerCallINTEL = 5601, + OpAsmTargetINTEL = 5609, + OpAsmINTEL = 5610, + OpAsmCallINTEL = 5611, + OpAtomicFMinEXT = 5614, + OpAtomicFMaxEXT = 5615, + OpAssumeTrueKHR = 5630, + OpExpectKHR = 5631, + OpDecorateString = 5632, + OpDecorateStringGOOGLE = 5632, + OpMemberDecorateString = 5633, + OpMemberDecorateStringGOOGLE = 5633, + OpVmeImageINTEL = 5699, + OpTypeVmeImageINTEL = 5700, + OpTypeAvcImePayloadINTEL = 5701, + OpTypeAvcRefPayloadINTEL = 5702, + OpTypeAvcSicPayloadINTEL = 5703, + OpTypeAvcMcePayloadINTEL = 5704, + OpTypeAvcMceResultINTEL = 5705, + OpTypeAvcImeResultINTEL = 5706, + OpTypeAvcImeResultSingleReferenceStreamoutINTEL = 5707, + OpTypeAvcImeResultDualReferenceStreamoutINTEL = 5708, + OpTypeAvcImeSingleReferenceStreaminINTEL = 5709, + OpTypeAvcImeDualReferenceStreaminINTEL = 5710, + OpTypeAvcRefResultINTEL = 5711, + OpTypeAvcSicResultINTEL = 5712, + OpSubgroupAvcMceGetDefaultInterBaseMultiReferencePenaltyINTEL = 5713, + OpSubgroupAvcMceSetInterBaseMultiReferencePenaltyINTEL = 5714, + OpSubgroupAvcMceGetDefaultInterShapePenaltyINTEL = 5715, + OpSubgroupAvcMceSetInterShapePenaltyINTEL = 5716, + OpSubgroupAvcMceGetDefaultInterDirectionPenaltyINTEL = 5717, + OpSubgroupAvcMceSetInterDirectionPenaltyINTEL = 5718, + OpSubgroupAvcMceGetDefaultIntraLumaShapePenaltyINTEL = 5719, + OpSubgroupAvcMceGetDefaultInterMotionVectorCostTableINTEL = 5720, + OpSubgroupAvcMceGetDefaultHighPenaltyCostTableINTEL = 5721, + OpSubgroupAvcMceGetDefaultMediumPenaltyCostTableINTEL = 5722, + OpSubgroupAvcMceGetDefaultLowPenaltyCostTableINTEL = 5723, + OpSubgroupAvcMceSetMotionVectorCostFunctionINTEL = 5724, + OpSubgroupAvcMceGetDefaultIntraLumaModePenaltyINTEL = 5725, + OpSubgroupAvcMceGetDefaultNonDcLumaIntraPenaltyINTEL = 5726, + OpSubgroupAvcMceGetDefaultIntraChromaModeBasePenaltyINTEL = 5727, + OpSubgroupAvcMceSetAcOnlyHaarINTEL = 5728, + OpSubgroupAvcMceSetSourceInterlacedFieldPolarityINTEL = 5729, + OpSubgroupAvcMceSetSingleReferenceInterlacedFieldPolarityINTEL = 5730, + OpSubgroupAvcMceSetDualReferenceInterlacedFieldPolaritiesINTEL = 5731, + OpSubgroupAvcMceConvertToImePayloadINTEL = 5732, + OpSubgroupAvcMceConvertToImeResultINTEL = 5733, + OpSubgroupAvcMceConvertToRefPayloadINTEL = 5734, + OpSubgroupAvcMceConvertToRefResultINTEL = 5735, + OpSubgroupAvcMceConvertToSicPayloadINTEL = 5736, + OpSubgroupAvcMceConvertToSicResultINTEL = 5737, + OpSubgroupAvcMceGetMotionVectorsINTEL = 5738, + OpSubgroupAvcMceGetInterDistortionsINTEL = 5739, + OpSubgroupAvcMceGetBestInterDistortionsINTEL = 5740, + OpSubgroupAvcMceGetInterMajorShapeINTEL = 5741, + OpSubgroupAvcMceGetInterMinorShapeINTEL = 5742, + OpSubgroupAvcMceGetInterDirectionsINTEL = 5743, + OpSubgroupAvcMceGetInterMotionVectorCountINTEL = 5744, + OpSubgroupAvcMceGetInterReferenceIdsINTEL = 5745, + OpSubgroupAvcMceGetInterReferenceInterlacedFieldPolaritiesINTEL = 5746, + OpSubgroupAvcImeInitializeINTEL = 5747, + OpSubgroupAvcImeSetSingleReferenceINTEL = 5748, + OpSubgroupAvcImeSetDualReferenceINTEL = 5749, + OpSubgroupAvcImeRefWindowSizeINTEL = 5750, + OpSubgroupAvcImeAdjustRefOffsetINTEL = 5751, + OpSubgroupAvcImeConvertToMcePayloadINTEL = 5752, + OpSubgroupAvcImeSetMaxMotionVectorCountINTEL = 5753, + OpSubgroupAvcImeSetUnidirectionalMixDisableINTEL = 5754, + OpSubgroupAvcImeSetEarlySearchTerminationThresholdINTEL = 5755, + OpSubgroupAvcImeSetWeightedSadINTEL = 5756, + OpSubgroupAvcImeEvaluateWithSingleReferenceINTEL = 5757, + OpSubgroupAvcImeEvaluateWithDualReferenceINTEL = 5758, + OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminINTEL = 5759, + OpSubgroupAvcImeEvaluateWithDualReferenceStreaminINTEL = 5760, + OpSubgroupAvcImeEvaluateWithSingleReferenceStreamoutINTEL = 5761, + OpSubgroupAvcImeEvaluateWithDualReferenceStreamoutINTEL = 5762, + OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminoutINTEL = 5763, + OpSubgroupAvcImeEvaluateWithDualReferenceStreaminoutINTEL = 5764, + OpSubgroupAvcImeConvertToMceResultINTEL = 5765, + OpSubgroupAvcImeGetSingleReferenceStreaminINTEL = 5766, + OpSubgroupAvcImeGetDualReferenceStreaminINTEL = 5767, + OpSubgroupAvcImeStripSingleReferenceStreamoutINTEL = 5768, + OpSubgroupAvcImeStripDualReferenceStreamoutINTEL = 5769, + OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeMotionVectorsINTEL = 5770, + OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeDistortionsINTEL = 5771, + OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeReferenceIdsINTEL = 5772, + OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeMotionVectorsINTEL = 5773, + OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeDistortionsINTEL = 5774, + OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeReferenceIdsINTEL = 5775, + OpSubgroupAvcImeGetBorderReachedINTEL = 5776, + OpSubgroupAvcImeGetTruncatedSearchIndicationINTEL = 5777, + OpSubgroupAvcImeGetUnidirectionalEarlySearchTerminationINTEL = 5778, + OpSubgroupAvcImeGetWeightingPatternMinimumMotionVectorINTEL = 5779, + OpSubgroupAvcImeGetWeightingPatternMinimumDistortionINTEL = 5780, + OpSubgroupAvcFmeInitializeINTEL = 5781, + OpSubgroupAvcBmeInitializeINTEL = 5782, + OpSubgroupAvcRefConvertToMcePayloadINTEL = 5783, + OpSubgroupAvcRefSetBidirectionalMixDisableINTEL = 5784, + OpSubgroupAvcRefSetBilinearFilterEnableINTEL = 5785, + OpSubgroupAvcRefEvaluateWithSingleReferenceINTEL = 5786, + OpSubgroupAvcRefEvaluateWithDualReferenceINTEL = 5787, + OpSubgroupAvcRefEvaluateWithMultiReferenceINTEL = 5788, + OpSubgroupAvcRefEvaluateWithMultiReferenceInterlacedINTEL = 5789, + OpSubgroupAvcRefConvertToMceResultINTEL = 5790, + OpSubgroupAvcSicInitializeINTEL = 5791, + OpSubgroupAvcSicConfigureSkcINTEL = 5792, + OpSubgroupAvcSicConfigureIpeLumaINTEL = 5793, + OpSubgroupAvcSicConfigureIpeLumaChromaINTEL = 5794, + OpSubgroupAvcSicGetMotionVectorMaskINTEL = 5795, + OpSubgroupAvcSicConvertToMcePayloadINTEL = 5796, + OpSubgroupAvcSicSetIntraLumaShapePenaltyINTEL = 5797, + OpSubgroupAvcSicSetIntraLumaModeCostFunctionINTEL = 5798, + OpSubgroupAvcSicSetIntraChromaModeCostFunctionINTEL = 5799, + OpSubgroupAvcSicSetBilinearFilterEnableINTEL = 5800, + OpSubgroupAvcSicSetSkcForwardTransformEnableINTEL = 5801, + OpSubgroupAvcSicSetBlockBasedRawSkipSadINTEL = 5802, + OpSubgroupAvcSicEvaluateIpeINTEL = 5803, + OpSubgroupAvcSicEvaluateWithSingleReferenceINTEL = 5804, + OpSubgroupAvcSicEvaluateWithDualReferenceINTEL = 5805, + OpSubgroupAvcSicEvaluateWithMultiReferenceINTEL = 5806, + OpSubgroupAvcSicEvaluateWithMultiReferenceInterlacedINTEL = 5807, + OpSubgroupAvcSicConvertToMceResultINTEL = 5808, + OpSubgroupAvcSicGetIpeLumaShapeINTEL = 5809, + OpSubgroupAvcSicGetBestIpeLumaDistortionINTEL = 5810, + OpSubgroupAvcSicGetBestIpeChromaDistortionINTEL = 5811, + OpSubgroupAvcSicGetPackedIpeLumaModesINTEL = 5812, + OpSubgroupAvcSicGetIpeChromaModeINTEL = 5813, + OpSubgroupAvcSicGetPackedSkcLumaCountThresholdINTEL = 5814, + OpSubgroupAvcSicGetPackedSkcLumaSumThresholdINTEL = 5815, + OpSubgroupAvcSicGetInterRawSadsINTEL = 5816, + OpVariableLengthArrayINTEL = 5818, + OpSaveMemoryINTEL = 5819, + OpRestoreMemoryINTEL = 5820, + OpArbitraryFloatSinCosPiINTEL = 5840, + OpArbitraryFloatCastINTEL = 5841, + OpArbitraryFloatCastFromIntINTEL = 5842, + OpArbitraryFloatCastToIntINTEL = 5843, + OpArbitraryFloatAddINTEL = 5846, + OpArbitraryFloatSubINTEL = 5847, + OpArbitraryFloatMulINTEL = 5848, + OpArbitraryFloatDivINTEL = 5849, + OpArbitraryFloatGTINTEL = 5850, + OpArbitraryFloatGEINTEL = 5851, + OpArbitraryFloatLTINTEL = 5852, + OpArbitraryFloatLEINTEL = 5853, + OpArbitraryFloatEQINTEL = 5854, + OpArbitraryFloatRecipINTEL = 5855, + OpArbitraryFloatRSqrtINTEL = 5856, + OpArbitraryFloatCbrtINTEL = 5857, + OpArbitraryFloatHypotINTEL = 5858, + OpArbitraryFloatSqrtINTEL = 5859, + OpArbitraryFloatLogINTEL = 5860, + OpArbitraryFloatLog2INTEL = 5861, + OpArbitraryFloatLog10INTEL = 5862, + OpArbitraryFloatLog1pINTEL = 5863, + OpArbitraryFloatExpINTEL = 5864, + OpArbitraryFloatExp2INTEL = 5865, + OpArbitraryFloatExp10INTEL = 5866, + OpArbitraryFloatExpm1INTEL = 5867, + OpArbitraryFloatSinINTEL = 5868, + OpArbitraryFloatCosINTEL = 5869, + OpArbitraryFloatSinCosINTEL = 5870, + OpArbitraryFloatSinPiINTEL = 5871, + OpArbitraryFloatCosPiINTEL = 5872, + OpArbitraryFloatASinINTEL = 5873, + OpArbitraryFloatASinPiINTEL = 5874, + OpArbitraryFloatACosINTEL = 5875, + OpArbitraryFloatACosPiINTEL = 5876, + OpArbitraryFloatATanINTEL = 5877, + OpArbitraryFloatATanPiINTEL = 5878, + OpArbitraryFloatATan2INTEL = 5879, + OpArbitraryFloatPowINTEL = 5880, + OpArbitraryFloatPowRINTEL = 5881, + OpArbitraryFloatPowNINTEL = 5882, + OpLoopControlINTEL = 5887, + OpAliasDomainDeclINTEL = 5911, + OpAliasScopeDeclINTEL = 5912, + OpAliasScopeListDeclINTEL = 5913, + OpFixedSqrtINTEL = 5923, + OpFixedRecipINTEL = 5924, + OpFixedRsqrtINTEL = 5925, + OpFixedSinINTEL = 5926, + OpFixedCosINTEL = 5927, + OpFixedSinCosINTEL = 5928, + OpFixedSinPiINTEL = 5929, + OpFixedCosPiINTEL = 5930, + OpFixedSinCosPiINTEL = 5931, + OpFixedLogINTEL = 5932, + OpFixedExpINTEL = 5933, + OpPtrCastToCrossWorkgroupINTEL = 5934, + OpCrossWorkgroupCastToPtrINTEL = 5938, + OpReadPipeBlockingINTEL = 5946, + OpWritePipeBlockingINTEL = 5947, + OpFPGARegINTEL = 5949, + OpRayQueryGetRayTMinKHR = 6016, + OpRayQueryGetRayFlagsKHR = 6017, + OpRayQueryGetIntersectionTKHR = 6018, + OpRayQueryGetIntersectionInstanceCustomIndexKHR = 6019, + OpRayQueryGetIntersectionInstanceIdKHR = 6020, + OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR = 6021, + OpRayQueryGetIntersectionGeometryIndexKHR = 6022, + OpRayQueryGetIntersectionPrimitiveIndexKHR = 6023, + OpRayQueryGetIntersectionBarycentricsKHR = 6024, + OpRayQueryGetIntersectionFrontFaceKHR = 6025, + OpRayQueryGetIntersectionCandidateAABBOpaqueKHR = 6026, + OpRayQueryGetIntersectionObjectRayDirectionKHR = 6027, + OpRayQueryGetIntersectionObjectRayOriginKHR = 6028, + OpRayQueryGetWorldRayDirectionKHR = 6029, + OpRayQueryGetWorldRayOriginKHR = 6030, + OpRayQueryGetIntersectionObjectToWorldKHR = 6031, + OpRayQueryGetIntersectionWorldToObjectKHR = 6032, + OpAtomicFAddEXT = 6035, + OpTypeBufferSurfaceINTEL = 6086, + OpTypeStructContinuedINTEL = 6090, + OpConstantCompositeContinuedINTEL = 6091, + OpSpecConstantCompositeContinuedINTEL = 6092, + OpCompositeConstructContinuedINTEL = 6096, + OpConvertFToBF16INTEL = 6116, + OpConvertBF16ToFINTEL = 6117, + OpControlBarrierArriveINTEL = 6142, + OpControlBarrierWaitINTEL = 6143, + OpArithmeticFenceEXT = 6145, + OpTaskSequenceCreateINTEL = 6163, + OpTaskSequenceAsyncINTEL = 6164, + OpTaskSequenceGetINTEL = 6165, + OpTaskSequenceReleaseINTEL = 6166, + OpTypeTaskSequenceINTEL = 6199, + OpSubgroupBlockPrefetchINTEL = 6221, + OpSubgroup2DBlockLoadINTEL = 6231, + OpSubgroup2DBlockLoadTransformINTEL = 6232, + OpSubgroup2DBlockLoadTransposeINTEL = 6233, + OpSubgroup2DBlockPrefetchINTEL = 6234, + OpSubgroup2DBlockStoreINTEL = 6235, + OpSubgroupMatrixMultiplyAccumulateINTEL = 6237, + OpBitwiseFunctionINTEL = 6242, + OpGroupIMulKHR = 6401, + OpGroupFMulKHR = 6402, + OpGroupBitwiseAndKHR = 6403, + OpGroupBitwiseOrKHR = 6404, + OpGroupBitwiseXorKHR = 6405, + OpGroupLogicalAndKHR = 6406, + OpGroupLogicalOrKHR = 6407, + OpGroupLogicalXorKHR = 6408, + OpRoundFToTF32INTEL = 6426, + OpMaskedGatherINTEL = 6428, + OpMaskedScatterINTEL = 6429, + OpMax = 0x7fffffff, +}; + +#ifdef SPV_ENABLE_UTILITY_CODE +#ifndef __cplusplus +#include +#endif +inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) { + *hasResult = *hasResultType = false; + switch (opcode) { + default: /* unknown opcode */ break; + case OpNop: *hasResult = false; *hasResultType = false; break; + case OpUndef: *hasResult = true; *hasResultType = true; break; + case OpSourceContinued: *hasResult = false; *hasResultType = false; break; + case OpSource: *hasResult = false; *hasResultType = false; break; + case OpSourceExtension: *hasResult = false; *hasResultType = false; break; + case OpName: *hasResult = false; *hasResultType = false; break; + case OpMemberName: *hasResult = false; *hasResultType = false; break; + case OpString: *hasResult = true; *hasResultType = false; break; + case OpLine: *hasResult = false; *hasResultType = false; break; + case OpExtension: *hasResult = false; *hasResultType = false; break; + case OpExtInstImport: *hasResult = true; *hasResultType = false; break; + case OpExtInst: *hasResult = true; *hasResultType = true; break; + case OpMemoryModel: *hasResult = false; *hasResultType = false; break; + case OpEntryPoint: *hasResult = false; *hasResultType = false; break; + case OpExecutionMode: *hasResult = false; *hasResultType = false; break; + case OpCapability: *hasResult = false; *hasResultType = false; break; + case OpTypeVoid: *hasResult = true; *hasResultType = false; break; + case OpTypeBool: *hasResult = true; *hasResultType = false; break; + case OpTypeInt: *hasResult = true; *hasResultType = false; break; + case OpTypeFloat: *hasResult = true; *hasResultType = false; break; + case OpTypeVector: *hasResult = true; *hasResultType = false; break; + case OpTypeMatrix: *hasResult = true; *hasResultType = false; break; + case OpTypeImage: *hasResult = true; *hasResultType = false; break; + case OpTypeSampler: *hasResult = true; *hasResultType = false; break; + case OpTypeSampledImage: *hasResult = true; *hasResultType = false; break; + case OpTypeArray: *hasResult = true; *hasResultType = false; break; + case OpTypeRuntimeArray: *hasResult = true; *hasResultType = false; break; + case OpTypeStruct: *hasResult = true; *hasResultType = false; break; + case OpTypeOpaque: *hasResult = true; *hasResultType = false; break; + case OpTypePointer: *hasResult = true; *hasResultType = false; break; + case OpTypeFunction: *hasResult = true; *hasResultType = false; break; + case OpTypeEvent: *hasResult = true; *hasResultType = false; break; + case OpTypeDeviceEvent: *hasResult = true; *hasResultType = false; break; + case OpTypeReserveId: *hasResult = true; *hasResultType = false; break; + case OpTypeQueue: *hasResult = true; *hasResultType = false; break; + case OpTypePipe: *hasResult = true; *hasResultType = false; break; + case OpTypeForwardPointer: *hasResult = false; *hasResultType = false; break; + case OpConstantTrue: *hasResult = true; *hasResultType = true; break; + case OpConstantFalse: *hasResult = true; *hasResultType = true; break; + case OpConstant: *hasResult = true; *hasResultType = true; break; + case OpConstantComposite: *hasResult = true; *hasResultType = true; break; + case OpConstantSampler: *hasResult = true; *hasResultType = true; break; + case OpConstantNull: *hasResult = true; *hasResultType = true; break; + case OpSpecConstantTrue: *hasResult = true; *hasResultType = true; break; + case OpSpecConstantFalse: *hasResult = true; *hasResultType = true; break; + case OpSpecConstant: *hasResult = true; *hasResultType = true; break; + case OpSpecConstantComposite: *hasResult = true; *hasResultType = true; break; + case OpSpecConstantOp: *hasResult = true; *hasResultType = true; break; + case OpFunction: *hasResult = true; *hasResultType = true; break; + case OpFunctionParameter: *hasResult = true; *hasResultType = true; break; + case OpFunctionEnd: *hasResult = false; *hasResultType = false; break; + case OpFunctionCall: *hasResult = true; *hasResultType = true; break; + case OpVariable: *hasResult = true; *hasResultType = true; break; + case OpImageTexelPointer: *hasResult = true; *hasResultType = true; break; + case OpLoad: *hasResult = true; *hasResultType = true; break; + case OpStore: *hasResult = false; *hasResultType = false; break; + case OpCopyMemory: *hasResult = false; *hasResultType = false; break; + case OpCopyMemorySized: *hasResult = false; *hasResultType = false; break; + case OpAccessChain: *hasResult = true; *hasResultType = true; break; + case OpInBoundsAccessChain: *hasResult = true; *hasResultType = true; break; + case OpPtrAccessChain: *hasResult = true; *hasResultType = true; break; + case OpArrayLength: *hasResult = true; *hasResultType = true; break; + case OpGenericPtrMemSemantics: *hasResult = true; *hasResultType = true; break; + case OpInBoundsPtrAccessChain: *hasResult = true; *hasResultType = true; break; + case OpDecorate: *hasResult = false; *hasResultType = false; break; + case OpMemberDecorate: *hasResult = false; *hasResultType = false; break; + case OpDecorationGroup: *hasResult = true; *hasResultType = false; break; + case OpGroupDecorate: *hasResult = false; *hasResultType = false; break; + case OpGroupMemberDecorate: *hasResult = false; *hasResultType = false; break; + case OpVectorExtractDynamic: *hasResult = true; *hasResultType = true; break; + case OpVectorInsertDynamic: *hasResult = true; *hasResultType = true; break; + case OpVectorShuffle: *hasResult = true; *hasResultType = true; break; + case OpCompositeConstruct: *hasResult = true; *hasResultType = true; break; + case OpCompositeExtract: *hasResult = true; *hasResultType = true; break; + case OpCompositeInsert: *hasResult = true; *hasResultType = true; break; + case OpCopyObject: *hasResult = true; *hasResultType = true; break; + case OpTranspose: *hasResult = true; *hasResultType = true; break; + case OpSampledImage: *hasResult = true; *hasResultType = true; break; + case OpImageSampleImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSampleExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSampleDrefImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSampleDrefExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSampleProjImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSampleProjExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSampleProjDrefImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSampleProjDrefExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageFetch: *hasResult = true; *hasResultType = true; break; + case OpImageGather: *hasResult = true; *hasResultType = true; break; + case OpImageDrefGather: *hasResult = true; *hasResultType = true; break; + case OpImageRead: *hasResult = true; *hasResultType = true; break; + case OpImageWrite: *hasResult = false; *hasResultType = false; break; + case OpImage: *hasResult = true; *hasResultType = true; break; + case OpImageQueryFormat: *hasResult = true; *hasResultType = true; break; + case OpImageQueryOrder: *hasResult = true; *hasResultType = true; break; + case OpImageQuerySizeLod: *hasResult = true; *hasResultType = true; break; + case OpImageQuerySize: *hasResult = true; *hasResultType = true; break; + case OpImageQueryLod: *hasResult = true; *hasResultType = true; break; + case OpImageQueryLevels: *hasResult = true; *hasResultType = true; break; + case OpImageQuerySamples: *hasResult = true; *hasResultType = true; break; + case OpConvertFToU: *hasResult = true; *hasResultType = true; break; + case OpConvertFToS: *hasResult = true; *hasResultType = true; break; + case OpConvertSToF: *hasResult = true; *hasResultType = true; break; + case OpConvertUToF: *hasResult = true; *hasResultType = true; break; + case OpUConvert: *hasResult = true; *hasResultType = true; break; + case OpSConvert: *hasResult = true; *hasResultType = true; break; + case OpFConvert: *hasResult = true; *hasResultType = true; break; + case OpQuantizeToF16: *hasResult = true; *hasResultType = true; break; + case OpConvertPtrToU: *hasResult = true; *hasResultType = true; break; + case OpSatConvertSToU: *hasResult = true; *hasResultType = true; break; + case OpSatConvertUToS: *hasResult = true; *hasResultType = true; break; + case OpConvertUToPtr: *hasResult = true; *hasResultType = true; break; + case OpPtrCastToGeneric: *hasResult = true; *hasResultType = true; break; + case OpGenericCastToPtr: *hasResult = true; *hasResultType = true; break; + case OpGenericCastToPtrExplicit: *hasResult = true; *hasResultType = true; break; + case OpBitcast: *hasResult = true; *hasResultType = true; break; + case OpSNegate: *hasResult = true; *hasResultType = true; break; + case OpFNegate: *hasResult = true; *hasResultType = true; break; + case OpIAdd: *hasResult = true; *hasResultType = true; break; + case OpFAdd: *hasResult = true; *hasResultType = true; break; + case OpISub: *hasResult = true; *hasResultType = true; break; + case OpFSub: *hasResult = true; *hasResultType = true; break; + case OpIMul: *hasResult = true; *hasResultType = true; break; + case OpFMul: *hasResult = true; *hasResultType = true; break; + case OpUDiv: *hasResult = true; *hasResultType = true; break; + case OpSDiv: *hasResult = true; *hasResultType = true; break; + case OpFDiv: *hasResult = true; *hasResultType = true; break; + case OpUMod: *hasResult = true; *hasResultType = true; break; + case OpSRem: *hasResult = true; *hasResultType = true; break; + case OpSMod: *hasResult = true; *hasResultType = true; break; + case OpFRem: *hasResult = true; *hasResultType = true; break; + case OpFMod: *hasResult = true; *hasResultType = true; break; + case OpVectorTimesScalar: *hasResult = true; *hasResultType = true; break; + case OpMatrixTimesScalar: *hasResult = true; *hasResultType = true; break; + case OpVectorTimesMatrix: *hasResult = true; *hasResultType = true; break; + case OpMatrixTimesVector: *hasResult = true; *hasResultType = true; break; + case OpMatrixTimesMatrix: *hasResult = true; *hasResultType = true; break; + case OpOuterProduct: *hasResult = true; *hasResultType = true; break; + case OpDot: *hasResult = true; *hasResultType = true; break; + case OpIAddCarry: *hasResult = true; *hasResultType = true; break; + case OpISubBorrow: *hasResult = true; *hasResultType = true; break; + case OpUMulExtended: *hasResult = true; *hasResultType = true; break; + case OpSMulExtended: *hasResult = true; *hasResultType = true; break; + case OpAny: *hasResult = true; *hasResultType = true; break; + case OpAll: *hasResult = true; *hasResultType = true; break; + case OpIsNan: *hasResult = true; *hasResultType = true; break; + case OpIsInf: *hasResult = true; *hasResultType = true; break; + case OpIsFinite: *hasResult = true; *hasResultType = true; break; + case OpIsNormal: *hasResult = true; *hasResultType = true; break; + case OpSignBitSet: *hasResult = true; *hasResultType = true; break; + case OpLessOrGreater: *hasResult = true; *hasResultType = true; break; + case OpOrdered: *hasResult = true; *hasResultType = true; break; + case OpUnordered: *hasResult = true; *hasResultType = true; break; + case OpLogicalEqual: *hasResult = true; *hasResultType = true; break; + case OpLogicalNotEqual: *hasResult = true; *hasResultType = true; break; + case OpLogicalOr: *hasResult = true; *hasResultType = true; break; + case OpLogicalAnd: *hasResult = true; *hasResultType = true; break; + case OpLogicalNot: *hasResult = true; *hasResultType = true; break; + case OpSelect: *hasResult = true; *hasResultType = true; break; + case OpIEqual: *hasResult = true; *hasResultType = true; break; + case OpINotEqual: *hasResult = true; *hasResultType = true; break; + case OpUGreaterThan: *hasResult = true; *hasResultType = true; break; + case OpSGreaterThan: *hasResult = true; *hasResultType = true; break; + case OpUGreaterThanEqual: *hasResult = true; *hasResultType = true; break; + case OpSGreaterThanEqual: *hasResult = true; *hasResultType = true; break; + case OpULessThan: *hasResult = true; *hasResultType = true; break; + case OpSLessThan: *hasResult = true; *hasResultType = true; break; + case OpULessThanEqual: *hasResult = true; *hasResultType = true; break; + case OpSLessThanEqual: *hasResult = true; *hasResultType = true; break; + case OpFOrdEqual: *hasResult = true; *hasResultType = true; break; + case OpFUnordEqual: *hasResult = true; *hasResultType = true; break; + case OpFOrdNotEqual: *hasResult = true; *hasResultType = true; break; + case OpFUnordNotEqual: *hasResult = true; *hasResultType = true; break; + case OpFOrdLessThan: *hasResult = true; *hasResultType = true; break; + case OpFUnordLessThan: *hasResult = true; *hasResultType = true; break; + case OpFOrdGreaterThan: *hasResult = true; *hasResultType = true; break; + case OpFUnordGreaterThan: *hasResult = true; *hasResultType = true; break; + case OpFOrdLessThanEqual: *hasResult = true; *hasResultType = true; break; + case OpFUnordLessThanEqual: *hasResult = true; *hasResultType = true; break; + case OpFOrdGreaterThanEqual: *hasResult = true; *hasResultType = true; break; + case OpFUnordGreaterThanEqual: *hasResult = true; *hasResultType = true; break; + case OpShiftRightLogical: *hasResult = true; *hasResultType = true; break; + case OpShiftRightArithmetic: *hasResult = true; *hasResultType = true; break; + case OpShiftLeftLogical: *hasResult = true; *hasResultType = true; break; + case OpBitwiseOr: *hasResult = true; *hasResultType = true; break; + case OpBitwiseXor: *hasResult = true; *hasResultType = true; break; + case OpBitwiseAnd: *hasResult = true; *hasResultType = true; break; + case OpNot: *hasResult = true; *hasResultType = true; break; + case OpBitFieldInsert: *hasResult = true; *hasResultType = true; break; + case OpBitFieldSExtract: *hasResult = true; *hasResultType = true; break; + case OpBitFieldUExtract: *hasResult = true; *hasResultType = true; break; + case OpBitReverse: *hasResult = true; *hasResultType = true; break; + case OpBitCount: *hasResult = true; *hasResultType = true; break; + case OpDPdx: *hasResult = true; *hasResultType = true; break; + case OpDPdy: *hasResult = true; *hasResultType = true; break; + case OpFwidth: *hasResult = true; *hasResultType = true; break; + case OpDPdxFine: *hasResult = true; *hasResultType = true; break; + case OpDPdyFine: *hasResult = true; *hasResultType = true; break; + case OpFwidthFine: *hasResult = true; *hasResultType = true; break; + case OpDPdxCoarse: *hasResult = true; *hasResultType = true; break; + case OpDPdyCoarse: *hasResult = true; *hasResultType = true; break; + case OpFwidthCoarse: *hasResult = true; *hasResultType = true; break; + case OpEmitVertex: *hasResult = false; *hasResultType = false; break; + case OpEndPrimitive: *hasResult = false; *hasResultType = false; break; + case OpEmitStreamVertex: *hasResult = false; *hasResultType = false; break; + case OpEndStreamPrimitive: *hasResult = false; *hasResultType = false; break; + case OpControlBarrier: *hasResult = false; *hasResultType = false; break; + case OpMemoryBarrier: *hasResult = false; *hasResultType = false; break; + case OpAtomicLoad: *hasResult = true; *hasResultType = true; break; + case OpAtomicStore: *hasResult = false; *hasResultType = false; break; + case OpAtomicExchange: *hasResult = true; *hasResultType = true; break; + case OpAtomicCompareExchange: *hasResult = true; *hasResultType = true; break; + case OpAtomicCompareExchangeWeak: *hasResult = true; *hasResultType = true; break; + case OpAtomicIIncrement: *hasResult = true; *hasResultType = true; break; + case OpAtomicIDecrement: *hasResult = true; *hasResultType = true; break; + case OpAtomicIAdd: *hasResult = true; *hasResultType = true; break; + case OpAtomicISub: *hasResult = true; *hasResultType = true; break; + case OpAtomicSMin: *hasResult = true; *hasResultType = true; break; + case OpAtomicUMin: *hasResult = true; *hasResultType = true; break; + case OpAtomicSMax: *hasResult = true; *hasResultType = true; break; + case OpAtomicUMax: *hasResult = true; *hasResultType = true; break; + case OpAtomicAnd: *hasResult = true; *hasResultType = true; break; + case OpAtomicOr: *hasResult = true; *hasResultType = true; break; + case OpAtomicXor: *hasResult = true; *hasResultType = true; break; + case OpPhi: *hasResult = true; *hasResultType = true; break; + case OpLoopMerge: *hasResult = false; *hasResultType = false; break; + case OpSelectionMerge: *hasResult = false; *hasResultType = false; break; + case OpLabel: *hasResult = true; *hasResultType = false; break; + case OpBranch: *hasResult = false; *hasResultType = false; break; + case OpBranchConditional: *hasResult = false; *hasResultType = false; break; + case OpSwitch: *hasResult = false; *hasResultType = false; break; + case OpKill: *hasResult = false; *hasResultType = false; break; + case OpReturn: *hasResult = false; *hasResultType = false; break; + case OpReturnValue: *hasResult = false; *hasResultType = false; break; + case OpUnreachable: *hasResult = false; *hasResultType = false; break; + case OpLifetimeStart: *hasResult = false; *hasResultType = false; break; + case OpLifetimeStop: *hasResult = false; *hasResultType = false; break; + case OpGroupAsyncCopy: *hasResult = true; *hasResultType = true; break; + case OpGroupWaitEvents: *hasResult = false; *hasResultType = false; break; + case OpGroupAll: *hasResult = true; *hasResultType = true; break; + case OpGroupAny: *hasResult = true; *hasResultType = true; break; + case OpGroupBroadcast: *hasResult = true; *hasResultType = true; break; + case OpGroupIAdd: *hasResult = true; *hasResultType = true; break; + case OpGroupFAdd: *hasResult = true; *hasResultType = true; break; + case OpGroupFMin: *hasResult = true; *hasResultType = true; break; + case OpGroupUMin: *hasResult = true; *hasResultType = true; break; + case OpGroupSMin: *hasResult = true; *hasResultType = true; break; + case OpGroupFMax: *hasResult = true; *hasResultType = true; break; + case OpGroupUMax: *hasResult = true; *hasResultType = true; break; + case OpGroupSMax: *hasResult = true; *hasResultType = true; break; + case OpReadPipe: *hasResult = true; *hasResultType = true; break; + case OpWritePipe: *hasResult = true; *hasResultType = true; break; + case OpReservedReadPipe: *hasResult = true; *hasResultType = true; break; + case OpReservedWritePipe: *hasResult = true; *hasResultType = true; break; + case OpReserveReadPipePackets: *hasResult = true; *hasResultType = true; break; + case OpReserveWritePipePackets: *hasResult = true; *hasResultType = true; break; + case OpCommitReadPipe: *hasResult = false; *hasResultType = false; break; + case OpCommitWritePipe: *hasResult = false; *hasResultType = false; break; + case OpIsValidReserveId: *hasResult = true; *hasResultType = true; break; + case OpGetNumPipePackets: *hasResult = true; *hasResultType = true; break; + case OpGetMaxPipePackets: *hasResult = true; *hasResultType = true; break; + case OpGroupReserveReadPipePackets: *hasResult = true; *hasResultType = true; break; + case OpGroupReserveWritePipePackets: *hasResult = true; *hasResultType = true; break; + case OpGroupCommitReadPipe: *hasResult = false; *hasResultType = false; break; + case OpGroupCommitWritePipe: *hasResult = false; *hasResultType = false; break; + case OpEnqueueMarker: *hasResult = true; *hasResultType = true; break; + case OpEnqueueKernel: *hasResult = true; *hasResultType = true; break; + case OpGetKernelNDrangeSubGroupCount: *hasResult = true; *hasResultType = true; break; + case OpGetKernelNDrangeMaxSubGroupSize: *hasResult = true; *hasResultType = true; break; + case OpGetKernelWorkGroupSize: *hasResult = true; *hasResultType = true; break; + case OpGetKernelPreferredWorkGroupSizeMultiple: *hasResult = true; *hasResultType = true; break; + case OpRetainEvent: *hasResult = false; *hasResultType = false; break; + case OpReleaseEvent: *hasResult = false; *hasResultType = false; break; + case OpCreateUserEvent: *hasResult = true; *hasResultType = true; break; + case OpIsValidEvent: *hasResult = true; *hasResultType = true; break; + case OpSetUserEventStatus: *hasResult = false; *hasResultType = false; break; + case OpCaptureEventProfilingInfo: *hasResult = false; *hasResultType = false; break; + case OpGetDefaultQueue: *hasResult = true; *hasResultType = true; break; + case OpBuildNDRange: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleDrefImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleDrefExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleProjImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleProjExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleProjDrefImplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseSampleProjDrefExplicitLod: *hasResult = true; *hasResultType = true; break; + case OpImageSparseFetch: *hasResult = true; *hasResultType = true; break; + case OpImageSparseGather: *hasResult = true; *hasResultType = true; break; + case OpImageSparseDrefGather: *hasResult = true; *hasResultType = true; break; + case OpImageSparseTexelsResident: *hasResult = true; *hasResultType = true; break; + case OpNoLine: *hasResult = false; *hasResultType = false; break; + case OpAtomicFlagTestAndSet: *hasResult = true; *hasResultType = true; break; + case OpAtomicFlagClear: *hasResult = false; *hasResultType = false; break; + case OpImageSparseRead: *hasResult = true; *hasResultType = true; break; + case OpSizeOf: *hasResult = true; *hasResultType = true; break; + case OpTypePipeStorage: *hasResult = true; *hasResultType = false; break; + case OpConstantPipeStorage: *hasResult = true; *hasResultType = true; break; + case OpCreatePipeFromPipeStorage: *hasResult = true; *hasResultType = true; break; + case OpGetKernelLocalSizeForSubgroupCount: *hasResult = true; *hasResultType = true; break; + case OpGetKernelMaxNumSubgroups: *hasResult = true; *hasResultType = true; break; + case OpTypeNamedBarrier: *hasResult = true; *hasResultType = false; break; + case OpNamedBarrierInitialize: *hasResult = true; *hasResultType = true; break; + case OpMemoryNamedBarrier: *hasResult = false; *hasResultType = false; break; + case OpModuleProcessed: *hasResult = false; *hasResultType = false; break; + case OpExecutionModeId: *hasResult = false; *hasResultType = false; break; + case OpDecorateId: *hasResult = false; *hasResultType = false; break; + case OpGroupNonUniformElect: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformAll: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformAny: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformAllEqual: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBroadcast: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBroadcastFirst: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBallot: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformInverseBallot: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBallotBitExtract: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBallotBitCount: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBallotFindLSB: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBallotFindMSB: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformShuffle: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformShuffleXor: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformShuffleUp: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformShuffleDown: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformIAdd: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformFAdd: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformIMul: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformFMul: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformSMin: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformUMin: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformFMin: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformSMax: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformUMax: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformFMax: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBitwiseAnd: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBitwiseOr: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformBitwiseXor: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformLogicalAnd: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformLogicalOr: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformLogicalXor: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformQuadBroadcast: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformQuadSwap: *hasResult = true; *hasResultType = true; break; + case OpCopyLogical: *hasResult = true; *hasResultType = true; break; + case OpPtrEqual: *hasResult = true; *hasResultType = true; break; + case OpPtrNotEqual: *hasResult = true; *hasResultType = true; break; + case OpPtrDiff: *hasResult = true; *hasResultType = true; break; + case OpColorAttachmentReadEXT: *hasResult = true; *hasResultType = true; break; + case OpDepthAttachmentReadEXT: *hasResult = true; *hasResultType = true; break; + case OpStencilAttachmentReadEXT: *hasResult = true; *hasResultType = true; break; + case OpTerminateInvocation: *hasResult = false; *hasResultType = false; break; + case OpTypeUntypedPointerKHR: *hasResult = true; *hasResultType = false; break; + case OpUntypedVariableKHR: *hasResult = true; *hasResultType = true; break; + case OpUntypedAccessChainKHR: *hasResult = true; *hasResultType = true; break; + case OpUntypedInBoundsAccessChainKHR: *hasResult = true; *hasResultType = true; break; + case OpSubgroupBallotKHR: *hasResult = true; *hasResultType = true; break; + case OpSubgroupFirstInvocationKHR: *hasResult = true; *hasResultType = true; break; + case OpUntypedPtrAccessChainKHR: *hasResult = true; *hasResultType = true; break; + case OpUntypedInBoundsPtrAccessChainKHR: *hasResult = true; *hasResultType = true; break; + case OpUntypedArrayLengthKHR: *hasResult = true; *hasResultType = true; break; + case OpUntypedPrefetchKHR: *hasResult = false; *hasResultType = false; break; + case OpSubgroupAllKHR: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAnyKHR: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAllEqualKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformRotateKHR: *hasResult = true; *hasResultType = true; break; + case OpSubgroupReadInvocationKHR: *hasResult = true; *hasResultType = true; break; + case OpExtInstWithForwardRefsKHR: *hasResult = true; *hasResultType = true; break; + case OpTraceRayKHR: *hasResult = false; *hasResultType = false; break; + case OpExecuteCallableKHR: *hasResult = false; *hasResultType = false; break; + case OpConvertUToAccelerationStructureKHR: *hasResult = true; *hasResultType = true; break; + case OpIgnoreIntersectionKHR: *hasResult = false; *hasResultType = false; break; + case OpTerminateRayKHR: *hasResult = false; *hasResultType = false; break; + case OpSDot: *hasResult = true; *hasResultType = true; break; + case OpUDot: *hasResult = true; *hasResultType = true; break; + case OpSUDot: *hasResult = true; *hasResultType = true; break; + case OpSDotAccSat: *hasResult = true; *hasResultType = true; break; + case OpUDotAccSat: *hasResult = true; *hasResultType = true; break; + case OpSUDotAccSat: *hasResult = true; *hasResultType = true; break; + case OpTypeCooperativeMatrixKHR: *hasResult = true; *hasResultType = false; break; + case OpCooperativeMatrixLoadKHR: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixStoreKHR: *hasResult = false; *hasResultType = false; break; + case OpCooperativeMatrixMulAddKHR: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixLengthKHR: *hasResult = true; *hasResultType = true; break; + case OpConstantCompositeReplicateEXT: *hasResult = true; *hasResultType = true; break; + case OpSpecConstantCompositeReplicateEXT: *hasResult = true; *hasResultType = true; break; + case OpCompositeConstructReplicateEXT: *hasResult = true; *hasResultType = true; break; + case OpTypeRayQueryKHR: *hasResult = true; *hasResultType = false; break; + case OpRayQueryInitializeKHR: *hasResult = false; *hasResultType = false; break; + case OpRayQueryTerminateKHR: *hasResult = false; *hasResultType = false; break; + case OpRayQueryGenerateIntersectionKHR: *hasResult = false; *hasResultType = false; break; + case OpRayQueryConfirmIntersectionKHR: *hasResult = false; *hasResultType = false; break; + case OpRayQueryProceedKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionTypeKHR: *hasResult = true; *hasResultType = true; break; + case OpImageSampleWeightedQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBoxFilterQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchSSDQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchSADQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchWindowSSDQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchWindowSADQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchGatherSSDQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchGatherSADQCOM: *hasResult = true; *hasResultType = true; break; + case OpGroupIAddNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpGroupFAddNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpGroupFMinNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpGroupUMinNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpGroupSMinNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpGroupFMaxNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpGroupUMaxNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpGroupSMaxNonUniformAMD: *hasResult = true; *hasResultType = true; break; + case OpFragmentMaskFetchAMD: *hasResult = true; *hasResultType = true; break; + case OpFragmentFetchAMD: *hasResult = true; *hasResultType = true; break; + case OpReadClockKHR: *hasResult = true; *hasResultType = true; break; + case OpAllocateNodePayloadsAMDX: *hasResult = true; *hasResultType = true; break; + case OpEnqueueNodePayloadsAMDX: *hasResult = false; *hasResultType = false; break; + case OpTypeNodePayloadArrayAMDX: *hasResult = true; *hasResultType = false; break; + case OpFinishWritingNodePayloadAMDX: *hasResult = true; *hasResultType = true; break; + case OpNodePayloadArrayLengthAMDX: *hasResult = true; *hasResultType = true; break; + case OpIsNodePayloadValidAMDX: *hasResult = true; *hasResultType = true; break; + case OpConstantStringAMDX: *hasResult = true; *hasResultType = false; break; + case OpSpecConstantStringAMDX: *hasResult = true; *hasResultType = false; break; + case OpGroupNonUniformQuadAllKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformQuadAnyKHR: *hasResult = true; *hasResultType = true; break; + case OpHitObjectRecordHitMotionNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectRecordHitWithIndexMotionNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectRecordMissMotionNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectGetWorldToObjectNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetObjectToWorldNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetObjectRayDirectionNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetObjectRayOriginNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectTraceRayMotionNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectGetShaderRecordBufferHandleNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetShaderBindingTableRecordIndexNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectRecordEmptyNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectTraceRayNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectRecordHitNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectRecordHitWithIndexNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectRecordMissNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectExecuteShaderNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectGetCurrentTimeNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetAttributesNV: *hasResult = false; *hasResultType = false; break; + case OpHitObjectGetHitKindNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetPrimitiveIndexNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetGeometryIndexNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetInstanceIdNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetInstanceCustomIndexNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetWorldRayDirectionNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetWorldRayOriginNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetRayTMaxNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetRayTMinNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectIsEmptyNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectIsHitNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectIsMissNV: *hasResult = true; *hasResultType = true; break; + case OpReorderThreadWithHitObjectNV: *hasResult = false; *hasResultType = false; break; + case OpReorderThreadWithHintNV: *hasResult = false; *hasResultType = false; break; + case OpTypeHitObjectNV: *hasResult = true; *hasResultType = false; break; + case OpImageSampleFootprintNV: *hasResult = true; *hasResultType = true; break; + case OpTypeCooperativeVectorNV: *hasResult = true; *hasResultType = false; break; + case OpCooperativeVectorMatrixMulNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeVectorOuterProductAccumulateNV: *hasResult = false; *hasResultType = false; break; + case OpCooperativeVectorReduceSumAccumulateNV: *hasResult = false; *hasResultType = false; break; + case OpCooperativeVectorMatrixMulAddNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixConvertNV: *hasResult = true; *hasResultType = true; break; + case OpEmitMeshTasksEXT: *hasResult = false; *hasResultType = false; break; + case OpSetMeshOutputsEXT: *hasResult = false; *hasResultType = false; break; + case OpGroupNonUniformPartitionNV: *hasResult = true; *hasResultType = true; break; + case OpWritePackedPrimitiveIndices4x8NV: *hasResult = false; *hasResultType = false; break; + case OpFetchMicroTriangleVertexPositionNV: *hasResult = true; *hasResultType = true; break; + case OpFetchMicroTriangleVertexBarycentricNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeVectorLoadNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeVectorStoreNV: *hasResult = false; *hasResultType = false; break; + case OpReportIntersectionKHR: *hasResult = true; *hasResultType = true; break; + case OpIgnoreIntersectionNV: *hasResult = false; *hasResultType = false; break; + case OpTerminateRayNV: *hasResult = false; *hasResultType = false; break; + case OpTraceNV: *hasResult = false; *hasResultType = false; break; + case OpTraceMotionNV: *hasResult = false; *hasResultType = false; break; + case OpTraceRayMotionNV: *hasResult = false; *hasResultType = false; break; + case OpRayQueryGetIntersectionTriangleVertexPositionsKHR: *hasResult = true; *hasResultType = true; break; + case OpTypeAccelerationStructureKHR: *hasResult = true; *hasResultType = false; break; + case OpExecuteCallableNV: *hasResult = false; *hasResultType = false; break; + case OpRayQueryGetClusterIdNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetClusterIdNV: *hasResult = true; *hasResultType = true; break; + case OpTypeCooperativeMatrixNV: *hasResult = true; *hasResultType = false; break; + case OpCooperativeMatrixLoadNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixStoreNV: *hasResult = false; *hasResultType = false; break; + case OpCooperativeMatrixMulAddNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixLengthNV: *hasResult = true; *hasResultType = true; break; + case OpBeginInvocationInterlockEXT: *hasResult = false; *hasResultType = false; break; + case OpEndInvocationInterlockEXT: *hasResult = false; *hasResultType = false; break; + case OpCooperativeMatrixReduceNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixLoadTensorNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixStoreTensorNV: *hasResult = false; *hasResultType = false; break; + case OpCooperativeMatrixPerElementOpNV: *hasResult = true; *hasResultType = true; break; + case OpTypeTensorLayoutNV: *hasResult = true; *hasResultType = false; break; + case OpTypeTensorViewNV: *hasResult = true; *hasResultType = false; break; + case OpCreateTensorLayoutNV: *hasResult = true; *hasResultType = true; break; + case OpTensorLayoutSetDimensionNV: *hasResult = true; *hasResultType = true; break; + case OpTensorLayoutSetStrideNV: *hasResult = true; *hasResultType = true; break; + case OpTensorLayoutSliceNV: *hasResult = true; *hasResultType = true; break; + case OpTensorLayoutSetClampValueNV: *hasResult = true; *hasResultType = true; break; + case OpCreateTensorViewNV: *hasResult = true; *hasResultType = true; break; + case OpTensorViewSetDimensionNV: *hasResult = true; *hasResultType = true; break; + case OpTensorViewSetStrideNV: *hasResult = true; *hasResultType = true; break; + case OpDemoteToHelperInvocation: *hasResult = false; *hasResultType = false; break; + case OpIsHelperInvocationEXT: *hasResult = true; *hasResultType = true; break; + case OpTensorViewSetClipNV: *hasResult = true; *hasResultType = true; break; + case OpTensorLayoutSetBlockSizeNV: *hasResult = true; *hasResultType = true; break; + case OpCooperativeMatrixTransposeNV: *hasResult = true; *hasResultType = true; break; + case OpConvertUToImageNV: *hasResult = true; *hasResultType = true; break; + case OpConvertUToSamplerNV: *hasResult = true; *hasResultType = true; break; + case OpConvertImageToUNV: *hasResult = true; *hasResultType = true; break; + case OpConvertSamplerToUNV: *hasResult = true; *hasResultType = true; break; + case OpConvertUToSampledImageNV: *hasResult = true; *hasResultType = true; break; + case OpConvertSampledImageToUNV: *hasResult = true; *hasResultType = true; break; + case OpSamplerImageAddressingModeNV: *hasResult = false; *hasResultType = false; break; + case OpRawAccessChainNV: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionSpherePositionNV: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionSphereRadiusNV: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionLSSPositionsNV: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionLSSRadiiNV: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionLSSHitValueNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetSpherePositionNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetSphereRadiusNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetLSSPositionsNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectGetLSSRadiiNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectIsSphereHitNV: *hasResult = true; *hasResultType = true; break; + case OpHitObjectIsLSSHitNV: *hasResult = true; *hasResultType = true; break; + case OpRayQueryIsSphereHitNV: *hasResult = true; *hasResultType = true; break; + case OpRayQueryIsLSSHitNV: *hasResult = true; *hasResultType = true; break; + case OpSubgroupShuffleINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupShuffleDownINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupShuffleUpINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupShuffleXorINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupBlockReadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupBlockWriteINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroupImageBlockReadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupImageBlockWriteINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroupImageMediaBlockReadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupImageMediaBlockWriteINTEL: *hasResult = false; *hasResultType = false; break; + case OpUCountLeadingZerosINTEL: *hasResult = true; *hasResultType = true; break; + case OpUCountTrailingZerosINTEL: *hasResult = true; *hasResultType = true; break; + case OpAbsISubINTEL: *hasResult = true; *hasResultType = true; break; + case OpAbsUSubINTEL: *hasResult = true; *hasResultType = true; break; + case OpIAddSatINTEL: *hasResult = true; *hasResultType = true; break; + case OpUAddSatINTEL: *hasResult = true; *hasResultType = true; break; + case OpIAverageINTEL: *hasResult = true; *hasResultType = true; break; + case OpUAverageINTEL: *hasResult = true; *hasResultType = true; break; + case OpIAverageRoundedINTEL: *hasResult = true; *hasResultType = true; break; + case OpUAverageRoundedINTEL: *hasResult = true; *hasResultType = true; break; + case OpISubSatINTEL: *hasResult = true; *hasResultType = true; break; + case OpUSubSatINTEL: *hasResult = true; *hasResultType = true; break; + case OpIMul32x16INTEL: *hasResult = true; *hasResultType = true; break; + case OpUMul32x16INTEL: *hasResult = true; *hasResultType = true; break; + case OpConstantFunctionPointerINTEL: *hasResult = true; *hasResultType = true; break; + case OpFunctionPointerCallINTEL: *hasResult = true; *hasResultType = true; break; + case OpAsmTargetINTEL: *hasResult = true; *hasResultType = false; break; + case OpAsmINTEL: *hasResult = true; *hasResultType = true; break; + case OpAsmCallINTEL: *hasResult = true; *hasResultType = true; break; + case OpAtomicFMinEXT: *hasResult = true; *hasResultType = true; break; + case OpAtomicFMaxEXT: *hasResult = true; *hasResultType = true; break; + case OpAssumeTrueKHR: *hasResult = false; *hasResultType = false; break; + case OpExpectKHR: *hasResult = true; *hasResultType = true; break; + case OpDecorateString: *hasResult = false; *hasResultType = false; break; + case OpMemberDecorateString: *hasResult = false; *hasResultType = false; break; + case OpVmeImageINTEL: *hasResult = true; *hasResultType = true; break; + case OpTypeVmeImageINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcImePayloadINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcRefPayloadINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcSicPayloadINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcMcePayloadINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcMceResultINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcImeResultINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcImeResultSingleReferenceStreamoutINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcImeResultDualReferenceStreamoutINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcImeSingleReferenceStreaminINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcImeDualReferenceStreaminINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcRefResultINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeAvcSicResultINTEL: *hasResult = true; *hasResultType = false; break; + case OpSubgroupAvcMceGetDefaultInterBaseMultiReferencePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetInterBaseMultiReferencePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultInterShapePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetInterShapePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultInterDirectionPenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetInterDirectionPenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultIntraLumaShapePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultInterMotionVectorCostTableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultHighPenaltyCostTableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultMediumPenaltyCostTableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultLowPenaltyCostTableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetMotionVectorCostFunctionINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultIntraLumaModePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultNonDcLumaIntraPenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetDefaultIntraChromaModeBasePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetAcOnlyHaarINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetSourceInterlacedFieldPolarityINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetSingleReferenceInterlacedFieldPolarityINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceSetDualReferenceInterlacedFieldPolaritiesINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceConvertToImePayloadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceConvertToImeResultINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceConvertToRefPayloadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceConvertToRefResultINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceConvertToSicPayloadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceConvertToSicResultINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetMotionVectorsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetInterDistortionsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetBestInterDistortionsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetInterMajorShapeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetInterMinorShapeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetInterDirectionsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetInterMotionVectorCountINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetInterReferenceIdsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcMceGetInterReferenceInterlacedFieldPolaritiesINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeInitializeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeSetSingleReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeSetDualReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeRefWindowSizeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeAdjustRefOffsetINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeConvertToMcePayloadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeSetMaxMotionVectorCountINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeSetUnidirectionalMixDisableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeSetEarlySearchTerminationThresholdINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeSetWeightedSadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithSingleReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithDualReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithDualReferenceStreaminINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithSingleReferenceStreamoutINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithDualReferenceStreamoutINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminoutINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeEvaluateWithDualReferenceStreaminoutINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeConvertToMceResultINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetSingleReferenceStreaminINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetDualReferenceStreaminINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeStripSingleReferenceStreamoutINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeStripDualReferenceStreamoutINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeMotionVectorsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeDistortionsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeReferenceIdsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeMotionVectorsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeDistortionsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeReferenceIdsINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetBorderReachedINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetTruncatedSearchIndicationINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetUnidirectionalEarlySearchTerminationINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetWeightingPatternMinimumMotionVectorINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcImeGetWeightingPatternMinimumDistortionINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcFmeInitializeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcBmeInitializeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefConvertToMcePayloadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefSetBidirectionalMixDisableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefSetBilinearFilterEnableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefEvaluateWithSingleReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefEvaluateWithDualReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefEvaluateWithMultiReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefEvaluateWithMultiReferenceInterlacedINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcRefConvertToMceResultINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicInitializeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicConfigureSkcINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicConfigureIpeLumaINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicConfigureIpeLumaChromaINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetMotionVectorMaskINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicConvertToMcePayloadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicSetIntraLumaShapePenaltyINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicSetIntraLumaModeCostFunctionINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicSetIntraChromaModeCostFunctionINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicSetBilinearFilterEnableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicSetSkcForwardTransformEnableINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicSetBlockBasedRawSkipSadINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicEvaluateIpeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicEvaluateWithSingleReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicEvaluateWithDualReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicEvaluateWithMultiReferenceINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicEvaluateWithMultiReferenceInterlacedINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicConvertToMceResultINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetIpeLumaShapeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetBestIpeLumaDistortionINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetBestIpeChromaDistortionINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetPackedIpeLumaModesINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetIpeChromaModeINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetPackedSkcLumaCountThresholdINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetPackedSkcLumaSumThresholdINTEL: *hasResult = true; *hasResultType = true; break; + case OpSubgroupAvcSicGetInterRawSadsINTEL: *hasResult = true; *hasResultType = true; break; + case OpVariableLengthArrayINTEL: *hasResult = true; *hasResultType = true; break; + case OpSaveMemoryINTEL: *hasResult = true; *hasResultType = true; break; + case OpRestoreMemoryINTEL: *hasResult = false; *hasResultType = false; break; + case OpArbitraryFloatSinCosPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatCastINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatCastFromIntINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatCastToIntINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatAddINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatSubINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatMulINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatDivINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatGTINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatGEINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatLTINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatLEINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatEQINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatRecipINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatRSqrtINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatCbrtINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatHypotINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatSqrtINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatLogINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatLog2INTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatLog10INTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatLog1pINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatExpINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatExp2INTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatExp10INTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatExpm1INTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatSinINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatCosINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatSinCosINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatSinPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatCosPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatASinINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatASinPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatACosINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatACosPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatATanINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatATanPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatATan2INTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatPowINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatPowRINTEL: *hasResult = true; *hasResultType = true; break; + case OpArbitraryFloatPowNINTEL: *hasResult = true; *hasResultType = true; break; + case OpLoopControlINTEL: *hasResult = false; *hasResultType = false; break; + case OpAliasDomainDeclINTEL: *hasResult = true; *hasResultType = false; break; + case OpAliasScopeDeclINTEL: *hasResult = true; *hasResultType = false; break; + case OpAliasScopeListDeclINTEL: *hasResult = true; *hasResultType = false; break; + case OpFixedSqrtINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedRecipINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedRsqrtINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedSinINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedCosINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedSinCosINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedSinPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedCosPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedSinCosPiINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedLogINTEL: *hasResult = true; *hasResultType = true; break; + case OpFixedExpINTEL: *hasResult = true; *hasResultType = true; break; + case OpPtrCastToCrossWorkgroupINTEL: *hasResult = true; *hasResultType = true; break; + case OpCrossWorkgroupCastToPtrINTEL: *hasResult = true; *hasResultType = true; break; + case OpReadPipeBlockingINTEL: *hasResult = true; *hasResultType = true; break; + case OpWritePipeBlockingINTEL: *hasResult = true; *hasResultType = true; break; + case OpFPGARegINTEL: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetRayTMinKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetRayFlagsKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionTKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionInstanceCustomIndexKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionInstanceIdKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionGeometryIndexKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionPrimitiveIndexKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionBarycentricsKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionFrontFaceKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionCandidateAABBOpaqueKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionObjectRayDirectionKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionObjectRayOriginKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetWorldRayDirectionKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetWorldRayOriginKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionObjectToWorldKHR: *hasResult = true; *hasResultType = true; break; + case OpRayQueryGetIntersectionWorldToObjectKHR: *hasResult = true; *hasResultType = true; break; + case OpAtomicFAddEXT: *hasResult = true; *hasResultType = true; break; + case OpTypeBufferSurfaceINTEL: *hasResult = true; *hasResultType = false; break; + case OpTypeStructContinuedINTEL: *hasResult = false; *hasResultType = false; break; + case OpConstantCompositeContinuedINTEL: *hasResult = false; *hasResultType = false; break; + case OpSpecConstantCompositeContinuedINTEL: *hasResult = false; *hasResultType = false; break; + case OpCompositeConstructContinuedINTEL: *hasResult = true; *hasResultType = true; break; + case OpConvertFToBF16INTEL: *hasResult = true; *hasResultType = true; break; + case OpConvertBF16ToFINTEL: *hasResult = true; *hasResultType = true; break; + case OpControlBarrierArriveINTEL: *hasResult = false; *hasResultType = false; break; + case OpControlBarrierWaitINTEL: *hasResult = false; *hasResultType = false; break; + case OpArithmeticFenceEXT: *hasResult = true; *hasResultType = true; break; + case OpTaskSequenceCreateINTEL: *hasResult = true; *hasResultType = true; break; + case OpTaskSequenceAsyncINTEL: *hasResult = false; *hasResultType = false; break; + case OpTaskSequenceGetINTEL: *hasResult = true; *hasResultType = true; break; + case OpTaskSequenceReleaseINTEL: *hasResult = false; *hasResultType = false; break; + case OpTypeTaskSequenceINTEL: *hasResult = true; *hasResultType = false; break; + case OpSubgroupBlockPrefetchINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroup2DBlockLoadINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroup2DBlockLoadTransformINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroup2DBlockLoadTransposeINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroup2DBlockPrefetchINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroup2DBlockStoreINTEL: *hasResult = false; *hasResultType = false; break; + case OpSubgroupMatrixMultiplyAccumulateINTEL: *hasResult = true; *hasResultType = true; break; + case OpBitwiseFunctionINTEL: *hasResult = true; *hasResultType = true; break; + case OpGroupIMulKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupFMulKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupBitwiseAndKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupBitwiseOrKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupBitwiseXorKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupLogicalAndKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupLogicalOrKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupLogicalXorKHR: *hasResult = true; *hasResultType = true; break; + case OpRoundFToTF32INTEL: *hasResult = true; *hasResultType = true; break; + case OpMaskedGatherINTEL: *hasResult = true; *hasResultType = true; break; + case OpMaskedScatterINTEL: *hasResult = false; *hasResultType = false; break; + } +} +inline const char* SourceLanguageToString(SourceLanguage value) { + switch (value) { + case SourceLanguageUnknown: return "Unknown"; + case SourceLanguageESSL: return "ESSL"; + case SourceLanguageGLSL: return "GLSL"; + case SourceLanguageOpenCL_C: return "OpenCL_C"; + case SourceLanguageOpenCL_CPP: return "OpenCL_CPP"; + case SourceLanguageHLSL: return "HLSL"; + case SourceLanguageCPP_for_OpenCL: return "CPP_for_OpenCL"; + case SourceLanguageSYCL: return "SYCL"; + case SourceLanguageHERO_C: return "HERO_C"; + case SourceLanguageNZSL: return "NZSL"; + case SourceLanguageWGSL: return "WGSL"; + case SourceLanguageSlang: return "Slang"; + case SourceLanguageZig: return "Zig"; + case SourceLanguageRust: return "Rust"; + default: return "Unknown"; + } +} + +inline const char* ExecutionModelToString(ExecutionModel value) { + switch (value) { + case ExecutionModelVertex: return "Vertex"; + case ExecutionModelTessellationControl: return "TessellationControl"; + case ExecutionModelTessellationEvaluation: return "TessellationEvaluation"; + case ExecutionModelGeometry: return "Geometry"; + case ExecutionModelFragment: return "Fragment"; + case ExecutionModelGLCompute: return "GLCompute"; + case ExecutionModelKernel: return "Kernel"; + case ExecutionModelTaskNV: return "TaskNV"; + case ExecutionModelMeshNV: return "MeshNV"; + case ExecutionModelRayGenerationKHR: return "RayGenerationKHR"; + case ExecutionModelIntersectionKHR: return "IntersectionKHR"; + case ExecutionModelAnyHitKHR: return "AnyHitKHR"; + case ExecutionModelClosestHitKHR: return "ClosestHitKHR"; + case ExecutionModelMissKHR: return "MissKHR"; + case ExecutionModelCallableKHR: return "CallableKHR"; + case ExecutionModelTaskEXT: return "TaskEXT"; + case ExecutionModelMeshEXT: return "MeshEXT"; + default: return "Unknown"; + } +} + +inline const char* AddressingModelToString(AddressingModel value) { + switch (value) { + case AddressingModelLogical: return "Logical"; + case AddressingModelPhysical32: return "Physical32"; + case AddressingModelPhysical64: return "Physical64"; + case AddressingModelPhysicalStorageBuffer64: return "PhysicalStorageBuffer64"; + default: return "Unknown"; + } +} + +inline const char* MemoryModelToString(MemoryModel value) { + switch (value) { + case MemoryModelSimple: return "Simple"; + case MemoryModelGLSL450: return "GLSL450"; + case MemoryModelOpenCL: return "OpenCL"; + case MemoryModelVulkan: return "Vulkan"; + default: return "Unknown"; + } +} + +inline const char* ExecutionModeToString(ExecutionMode value) { + switch (value) { + case ExecutionModeInvocations: return "Invocations"; + case ExecutionModeSpacingEqual: return "SpacingEqual"; + case ExecutionModeSpacingFractionalEven: return "SpacingFractionalEven"; + case ExecutionModeSpacingFractionalOdd: return "SpacingFractionalOdd"; + case ExecutionModeVertexOrderCw: return "VertexOrderCw"; + case ExecutionModeVertexOrderCcw: return "VertexOrderCcw"; + case ExecutionModePixelCenterInteger: return "PixelCenterInteger"; + case ExecutionModeOriginUpperLeft: return "OriginUpperLeft"; + case ExecutionModeOriginLowerLeft: return "OriginLowerLeft"; + case ExecutionModeEarlyFragmentTests: return "EarlyFragmentTests"; + case ExecutionModePointMode: return "PointMode"; + case ExecutionModeXfb: return "Xfb"; + case ExecutionModeDepthReplacing: return "DepthReplacing"; + case ExecutionModeDepthGreater: return "DepthGreater"; + case ExecutionModeDepthLess: return "DepthLess"; + case ExecutionModeDepthUnchanged: return "DepthUnchanged"; + case ExecutionModeLocalSize: return "LocalSize"; + case ExecutionModeLocalSizeHint: return "LocalSizeHint"; + case ExecutionModeInputPoints: return "InputPoints"; + case ExecutionModeInputLines: return "InputLines"; + case ExecutionModeInputLinesAdjacency: return "InputLinesAdjacency"; + case ExecutionModeTriangles: return "Triangles"; + case ExecutionModeInputTrianglesAdjacency: return "InputTrianglesAdjacency"; + case ExecutionModeQuads: return "Quads"; + case ExecutionModeIsolines: return "Isolines"; + case ExecutionModeOutputVertices: return "OutputVertices"; + case ExecutionModeOutputPoints: return "OutputPoints"; + case ExecutionModeOutputLineStrip: return "OutputLineStrip"; + case ExecutionModeOutputTriangleStrip: return "OutputTriangleStrip"; + case ExecutionModeVecTypeHint: return "VecTypeHint"; + case ExecutionModeContractionOff: return "ContractionOff"; + case ExecutionModeInitializer: return "Initializer"; + case ExecutionModeFinalizer: return "Finalizer"; + case ExecutionModeSubgroupSize: return "SubgroupSize"; + case ExecutionModeSubgroupsPerWorkgroup: return "SubgroupsPerWorkgroup"; + case ExecutionModeSubgroupsPerWorkgroupId: return "SubgroupsPerWorkgroupId"; + case ExecutionModeLocalSizeId: return "LocalSizeId"; + case ExecutionModeLocalSizeHintId: return "LocalSizeHintId"; + case ExecutionModeNonCoherentColorAttachmentReadEXT: return "NonCoherentColorAttachmentReadEXT"; + case ExecutionModeNonCoherentDepthAttachmentReadEXT: return "NonCoherentDepthAttachmentReadEXT"; + case ExecutionModeNonCoherentStencilAttachmentReadEXT: return "NonCoherentStencilAttachmentReadEXT"; + case ExecutionModeSubgroupUniformControlFlowKHR: return "SubgroupUniformControlFlowKHR"; + case ExecutionModePostDepthCoverage: return "PostDepthCoverage"; + case ExecutionModeDenormPreserve: return "DenormPreserve"; + case ExecutionModeDenormFlushToZero: return "DenormFlushToZero"; + case ExecutionModeSignedZeroInfNanPreserve: return "SignedZeroInfNanPreserve"; + case ExecutionModeRoundingModeRTE: return "RoundingModeRTE"; + case ExecutionModeRoundingModeRTZ: return "RoundingModeRTZ"; + case ExecutionModeNonCoherentTileAttachmentReadQCOM: return "NonCoherentTileAttachmentReadQCOM"; + case ExecutionModeTileShadingRateQCOM: return "TileShadingRateQCOM"; + case ExecutionModeEarlyAndLateFragmentTestsAMD: return "EarlyAndLateFragmentTestsAMD"; + case ExecutionModeStencilRefReplacingEXT: return "StencilRefReplacingEXT"; + case ExecutionModeCoalescingAMDX: return "CoalescingAMDX"; + case ExecutionModeIsApiEntryAMDX: return "IsApiEntryAMDX"; + case ExecutionModeMaxNodeRecursionAMDX: return "MaxNodeRecursionAMDX"; + case ExecutionModeStaticNumWorkgroupsAMDX: return "StaticNumWorkgroupsAMDX"; + case ExecutionModeShaderIndexAMDX: return "ShaderIndexAMDX"; + case ExecutionModeMaxNumWorkgroupsAMDX: return "MaxNumWorkgroupsAMDX"; + case ExecutionModeStencilRefUnchangedFrontAMD: return "StencilRefUnchangedFrontAMD"; + case ExecutionModeStencilRefGreaterFrontAMD: return "StencilRefGreaterFrontAMD"; + case ExecutionModeStencilRefLessFrontAMD: return "StencilRefLessFrontAMD"; + case ExecutionModeStencilRefUnchangedBackAMD: return "StencilRefUnchangedBackAMD"; + case ExecutionModeStencilRefGreaterBackAMD: return "StencilRefGreaterBackAMD"; + case ExecutionModeStencilRefLessBackAMD: return "StencilRefLessBackAMD"; + case ExecutionModeQuadDerivativesKHR: return "QuadDerivativesKHR"; + case ExecutionModeRequireFullQuadsKHR: return "RequireFullQuadsKHR"; + case ExecutionModeSharesInputWithAMDX: return "SharesInputWithAMDX"; + case ExecutionModeOutputLinesEXT: return "OutputLinesEXT"; + case ExecutionModeOutputPrimitivesEXT: return "OutputPrimitivesEXT"; + case ExecutionModeDerivativeGroupQuadsKHR: return "DerivativeGroupQuadsKHR"; + case ExecutionModeDerivativeGroupLinearKHR: return "DerivativeGroupLinearKHR"; + case ExecutionModeOutputTrianglesEXT: return "OutputTrianglesEXT"; + case ExecutionModePixelInterlockOrderedEXT: return "PixelInterlockOrderedEXT"; + case ExecutionModePixelInterlockUnorderedEXT: return "PixelInterlockUnorderedEXT"; + case ExecutionModeSampleInterlockOrderedEXT: return "SampleInterlockOrderedEXT"; + case ExecutionModeSampleInterlockUnorderedEXT: return "SampleInterlockUnorderedEXT"; + case ExecutionModeShadingRateInterlockOrderedEXT: return "ShadingRateInterlockOrderedEXT"; + case ExecutionModeShadingRateInterlockUnorderedEXT: return "ShadingRateInterlockUnorderedEXT"; + case ExecutionModeSharedLocalMemorySizeINTEL: return "SharedLocalMemorySizeINTEL"; + case ExecutionModeRoundingModeRTPINTEL: return "RoundingModeRTPINTEL"; + case ExecutionModeRoundingModeRTNINTEL: return "RoundingModeRTNINTEL"; + case ExecutionModeFloatingPointModeALTINTEL: return "FloatingPointModeALTINTEL"; + case ExecutionModeFloatingPointModeIEEEINTEL: return "FloatingPointModeIEEEINTEL"; + case ExecutionModeMaxWorkgroupSizeINTEL: return "MaxWorkgroupSizeINTEL"; + case ExecutionModeMaxWorkDimINTEL: return "MaxWorkDimINTEL"; + case ExecutionModeNoGlobalOffsetINTEL: return "NoGlobalOffsetINTEL"; + case ExecutionModeNumSIMDWorkitemsINTEL: return "NumSIMDWorkitemsINTEL"; + case ExecutionModeSchedulerTargetFmaxMhzINTEL: return "SchedulerTargetFmaxMhzINTEL"; + case ExecutionModeMaximallyReconvergesKHR: return "MaximallyReconvergesKHR"; + case ExecutionModeFPFastMathDefault: return "FPFastMathDefault"; + case ExecutionModeStreamingInterfaceINTEL: return "StreamingInterfaceINTEL"; + case ExecutionModeRegisterMapInterfaceINTEL: return "RegisterMapInterfaceINTEL"; + case ExecutionModeNamedBarrierCountINTEL: return "NamedBarrierCountINTEL"; + case ExecutionModeMaximumRegistersINTEL: return "MaximumRegistersINTEL"; + case ExecutionModeMaximumRegistersIdINTEL: return "MaximumRegistersIdINTEL"; + case ExecutionModeNamedMaximumRegistersINTEL: return "NamedMaximumRegistersINTEL"; + default: return "Unknown"; + } +} + +inline const char* StorageClassToString(StorageClass value) { + switch (value) { + case StorageClassUniformConstant: return "UniformConstant"; + case StorageClassInput: return "Input"; + case StorageClassUniform: return "Uniform"; + case StorageClassOutput: return "Output"; + case StorageClassWorkgroup: return "Workgroup"; + case StorageClassCrossWorkgroup: return "CrossWorkgroup"; + case StorageClassPrivate: return "Private"; + case StorageClassFunction: return "Function"; + case StorageClassGeneric: return "Generic"; + case StorageClassPushConstant: return "PushConstant"; + case StorageClassAtomicCounter: return "AtomicCounter"; + case StorageClassImage: return "Image"; + case StorageClassStorageBuffer: return "StorageBuffer"; + case StorageClassTileImageEXT: return "TileImageEXT"; + case StorageClassTileAttachmentQCOM: return "TileAttachmentQCOM"; + case StorageClassNodePayloadAMDX: return "NodePayloadAMDX"; + case StorageClassCallableDataKHR: return "CallableDataKHR"; + case StorageClassIncomingCallableDataKHR: return "IncomingCallableDataKHR"; + case StorageClassRayPayloadKHR: return "RayPayloadKHR"; + case StorageClassHitAttributeKHR: return "HitAttributeKHR"; + case StorageClassIncomingRayPayloadKHR: return "IncomingRayPayloadKHR"; + case StorageClassShaderRecordBufferKHR: return "ShaderRecordBufferKHR"; + case StorageClassPhysicalStorageBuffer: return "PhysicalStorageBuffer"; + case StorageClassHitObjectAttributeNV: return "HitObjectAttributeNV"; + case StorageClassTaskPayloadWorkgroupEXT: return "TaskPayloadWorkgroupEXT"; + case StorageClassCodeSectionINTEL: return "CodeSectionINTEL"; + case StorageClassDeviceOnlyINTEL: return "DeviceOnlyINTEL"; + case StorageClassHostOnlyINTEL: return "HostOnlyINTEL"; + default: return "Unknown"; + } +} + +inline const char* DimToString(Dim value) { + switch (value) { + case Dim1D: return "1D"; + case Dim2D: return "2D"; + case Dim3D: return "3D"; + case DimCube: return "Cube"; + case DimRect: return "Rect"; + case DimBuffer: return "Buffer"; + case DimSubpassData: return "SubpassData"; + case DimTileImageDataEXT: return "TileImageDataEXT"; + default: return "Unknown"; + } +} + +inline const char* SamplerAddressingModeToString(SamplerAddressingMode value) { + switch (value) { + case SamplerAddressingModeNone: return "None"; + case SamplerAddressingModeClampToEdge: return "ClampToEdge"; + case SamplerAddressingModeClamp: return "Clamp"; + case SamplerAddressingModeRepeat: return "Repeat"; + case SamplerAddressingModeRepeatMirrored: return "RepeatMirrored"; + default: return "Unknown"; + } +} + +inline const char* SamplerFilterModeToString(SamplerFilterMode value) { + switch (value) { + case SamplerFilterModeNearest: return "Nearest"; + case SamplerFilterModeLinear: return "Linear"; + default: return "Unknown"; + } +} + +inline const char* ImageFormatToString(ImageFormat value) { + switch (value) { + case ImageFormatUnknown: return "Unknown"; + case ImageFormatRgba32f: return "Rgba32f"; + case ImageFormatRgba16f: return "Rgba16f"; + case ImageFormatR32f: return "R32f"; + case ImageFormatRgba8: return "Rgba8"; + case ImageFormatRgba8Snorm: return "Rgba8Snorm"; + case ImageFormatRg32f: return "Rg32f"; + case ImageFormatRg16f: return "Rg16f"; + case ImageFormatR11fG11fB10f: return "R11fG11fB10f"; + case ImageFormatR16f: return "R16f"; + case ImageFormatRgba16: return "Rgba16"; + case ImageFormatRgb10A2: return "Rgb10A2"; + case ImageFormatRg16: return "Rg16"; + case ImageFormatRg8: return "Rg8"; + case ImageFormatR16: return "R16"; + case ImageFormatR8: return "R8"; + case ImageFormatRgba16Snorm: return "Rgba16Snorm"; + case ImageFormatRg16Snorm: return "Rg16Snorm"; + case ImageFormatRg8Snorm: return "Rg8Snorm"; + case ImageFormatR16Snorm: return "R16Snorm"; + case ImageFormatR8Snorm: return "R8Snorm"; + case ImageFormatRgba32i: return "Rgba32i"; + case ImageFormatRgba16i: return "Rgba16i"; + case ImageFormatRgba8i: return "Rgba8i"; + case ImageFormatR32i: return "R32i"; + case ImageFormatRg32i: return "Rg32i"; + case ImageFormatRg16i: return "Rg16i"; + case ImageFormatRg8i: return "Rg8i"; + case ImageFormatR16i: return "R16i"; + case ImageFormatR8i: return "R8i"; + case ImageFormatRgba32ui: return "Rgba32ui"; + case ImageFormatRgba16ui: return "Rgba16ui"; + case ImageFormatRgba8ui: return "Rgba8ui"; + case ImageFormatR32ui: return "R32ui"; + case ImageFormatRgb10a2ui: return "Rgb10a2ui"; + case ImageFormatRg32ui: return "Rg32ui"; + case ImageFormatRg16ui: return "Rg16ui"; + case ImageFormatRg8ui: return "Rg8ui"; + case ImageFormatR16ui: return "R16ui"; + case ImageFormatR8ui: return "R8ui"; + case ImageFormatR64ui: return "R64ui"; + case ImageFormatR64i: return "R64i"; + default: return "Unknown"; + } +} + +inline const char* ImageChannelOrderToString(ImageChannelOrder value) { + switch (value) { + case ImageChannelOrderR: return "R"; + case ImageChannelOrderA: return "A"; + case ImageChannelOrderRG: return "RG"; + case ImageChannelOrderRA: return "RA"; + case ImageChannelOrderRGB: return "RGB"; + case ImageChannelOrderRGBA: return "RGBA"; + case ImageChannelOrderBGRA: return "BGRA"; + case ImageChannelOrderARGB: return "ARGB"; + case ImageChannelOrderIntensity: return "Intensity"; + case ImageChannelOrderLuminance: return "Luminance"; + case ImageChannelOrderRx: return "Rx"; + case ImageChannelOrderRGx: return "RGx"; + case ImageChannelOrderRGBx: return "RGBx"; + case ImageChannelOrderDepth: return "Depth"; + case ImageChannelOrderDepthStencil: return "DepthStencil"; + case ImageChannelOrdersRGB: return "sRGB"; + case ImageChannelOrdersRGBx: return "sRGBx"; + case ImageChannelOrdersRGBA: return "sRGBA"; + case ImageChannelOrdersBGRA: return "sBGRA"; + case ImageChannelOrderABGR: return "ABGR"; + default: return "Unknown"; + } +} + +inline const char* ImageChannelDataTypeToString(ImageChannelDataType value) { + switch (value) { + case ImageChannelDataTypeSnormInt8: return "SnormInt8"; + case ImageChannelDataTypeSnormInt16: return "SnormInt16"; + case ImageChannelDataTypeUnormInt8: return "UnormInt8"; + case ImageChannelDataTypeUnormInt16: return "UnormInt16"; + case ImageChannelDataTypeUnormShort565: return "UnormShort565"; + case ImageChannelDataTypeUnormShort555: return "UnormShort555"; + case ImageChannelDataTypeUnormInt101010: return "UnormInt101010"; + case ImageChannelDataTypeSignedInt8: return "SignedInt8"; + case ImageChannelDataTypeSignedInt16: return "SignedInt16"; + case ImageChannelDataTypeSignedInt32: return "SignedInt32"; + case ImageChannelDataTypeUnsignedInt8: return "UnsignedInt8"; + case ImageChannelDataTypeUnsignedInt16: return "UnsignedInt16"; + case ImageChannelDataTypeUnsignedInt32: return "UnsignedInt32"; + case ImageChannelDataTypeHalfFloat: return "HalfFloat"; + case ImageChannelDataTypeFloat: return "Float"; + case ImageChannelDataTypeUnormInt24: return "UnormInt24"; + case ImageChannelDataTypeUnormInt101010_2: return "UnormInt101010_2"; + case ImageChannelDataTypeUnormInt10X6EXT: return "UnormInt10X6EXT"; + case ImageChannelDataTypeUnsignedIntRaw10EXT: return "UnsignedIntRaw10EXT"; + case ImageChannelDataTypeUnsignedIntRaw12EXT: return "UnsignedIntRaw12EXT"; + case ImageChannelDataTypeUnormInt2_101010EXT: return "UnormInt2_101010EXT"; + case ImageChannelDataTypeUnsignedInt10X6EXT: return "UnsignedInt10X6EXT"; + case ImageChannelDataTypeUnsignedInt12X4EXT: return "UnsignedInt12X4EXT"; + case ImageChannelDataTypeUnsignedInt14X2EXT: return "UnsignedInt14X2EXT"; + case ImageChannelDataTypeUnormInt12X4EXT: return "UnormInt12X4EXT"; + case ImageChannelDataTypeUnormInt14X2EXT: return "UnormInt14X2EXT"; + default: return "Unknown"; + } +} + +inline const char* FPRoundingModeToString(FPRoundingMode value) { + switch (value) { + case FPRoundingModeRTE: return "RTE"; + case FPRoundingModeRTZ: return "RTZ"; + case FPRoundingModeRTP: return "RTP"; + case FPRoundingModeRTN: return "RTN"; + default: return "Unknown"; + } +} + +inline const char* LinkageTypeToString(LinkageType value) { + switch (value) { + case LinkageTypeExport: return "Export"; + case LinkageTypeImport: return "Import"; + case LinkageTypeLinkOnceODR: return "LinkOnceODR"; + default: return "Unknown"; + } +} + +inline const char* AccessQualifierToString(AccessQualifier value) { + switch (value) { + case AccessQualifierReadOnly: return "ReadOnly"; + case AccessQualifierWriteOnly: return "WriteOnly"; + case AccessQualifierReadWrite: return "ReadWrite"; + default: return "Unknown"; + } +} + +inline const char* FunctionParameterAttributeToString(FunctionParameterAttribute value) { + switch (value) { + case FunctionParameterAttributeZext: return "Zext"; + case FunctionParameterAttributeSext: return "Sext"; + case FunctionParameterAttributeByVal: return "ByVal"; + case FunctionParameterAttributeSret: return "Sret"; + case FunctionParameterAttributeNoAlias: return "NoAlias"; + case FunctionParameterAttributeNoCapture: return "NoCapture"; + case FunctionParameterAttributeNoWrite: return "NoWrite"; + case FunctionParameterAttributeNoReadWrite: return "NoReadWrite"; + case FunctionParameterAttributeRuntimeAlignedINTEL: return "RuntimeAlignedINTEL"; + default: return "Unknown"; + } +} + +inline const char* DecorationToString(Decoration value) { + switch (value) { + case DecorationRelaxedPrecision: return "RelaxedPrecision"; + case DecorationSpecId: return "SpecId"; + case DecorationBlock: return "Block"; + case DecorationBufferBlock: return "BufferBlock"; + case DecorationRowMajor: return "RowMajor"; + case DecorationColMajor: return "ColMajor"; + case DecorationArrayStride: return "ArrayStride"; + case DecorationMatrixStride: return "MatrixStride"; + case DecorationGLSLShared: return "GLSLShared"; + case DecorationGLSLPacked: return "GLSLPacked"; + case DecorationCPacked: return "CPacked"; + case DecorationBuiltIn: return "BuiltIn"; + case DecorationNoPerspective: return "NoPerspective"; + case DecorationFlat: return "Flat"; + case DecorationPatch: return "Patch"; + case DecorationCentroid: return "Centroid"; + case DecorationSample: return "Sample"; + case DecorationInvariant: return "Invariant"; + case DecorationRestrict: return "Restrict"; + case DecorationAliased: return "Aliased"; + case DecorationVolatile: return "Volatile"; + case DecorationConstant: return "Constant"; + case DecorationCoherent: return "Coherent"; + case DecorationNonWritable: return "NonWritable"; + case DecorationNonReadable: return "NonReadable"; + case DecorationUniform: return "Uniform"; + case DecorationUniformId: return "UniformId"; + case DecorationSaturatedConversion: return "SaturatedConversion"; + case DecorationStream: return "Stream"; + case DecorationLocation: return "Location"; + case DecorationComponent: return "Component"; + case DecorationIndex: return "Index"; + case DecorationBinding: return "Binding"; + case DecorationDescriptorSet: return "DescriptorSet"; + case DecorationOffset: return "Offset"; + case DecorationXfbBuffer: return "XfbBuffer"; + case DecorationXfbStride: return "XfbStride"; + case DecorationFuncParamAttr: return "FuncParamAttr"; + case DecorationFPRoundingMode: return "FPRoundingMode"; + case DecorationFPFastMathMode: return "FPFastMathMode"; + case DecorationLinkageAttributes: return "LinkageAttributes"; + case DecorationNoContraction: return "NoContraction"; + case DecorationInputAttachmentIndex: return "InputAttachmentIndex"; + case DecorationAlignment: return "Alignment"; + case DecorationMaxByteOffset: return "MaxByteOffset"; + case DecorationAlignmentId: return "AlignmentId"; + case DecorationMaxByteOffsetId: return "MaxByteOffsetId"; + case DecorationNoSignedWrap: return "NoSignedWrap"; + case DecorationNoUnsignedWrap: return "NoUnsignedWrap"; + case DecorationWeightTextureQCOM: return "WeightTextureQCOM"; + case DecorationBlockMatchTextureQCOM: return "BlockMatchTextureQCOM"; + case DecorationBlockMatchSamplerQCOM: return "BlockMatchSamplerQCOM"; + case DecorationExplicitInterpAMD: return "ExplicitInterpAMD"; + case DecorationNodeSharesPayloadLimitsWithAMDX: return "NodeSharesPayloadLimitsWithAMDX"; + case DecorationNodeMaxPayloadsAMDX: return "NodeMaxPayloadsAMDX"; + case DecorationTrackFinishWritingAMDX: return "TrackFinishWritingAMDX"; + case DecorationPayloadNodeNameAMDX: return "PayloadNodeNameAMDX"; + case DecorationPayloadNodeBaseIndexAMDX: return "PayloadNodeBaseIndexAMDX"; + case DecorationPayloadNodeSparseArrayAMDX: return "PayloadNodeSparseArrayAMDX"; + case DecorationPayloadNodeArraySizeAMDX: return "PayloadNodeArraySizeAMDX"; + case DecorationPayloadDispatchIndirectAMDX: return "PayloadDispatchIndirectAMDX"; + case DecorationOverrideCoverageNV: return "OverrideCoverageNV"; + case DecorationPassthroughNV: return "PassthroughNV"; + case DecorationViewportRelativeNV: return "ViewportRelativeNV"; + case DecorationSecondaryViewportRelativeNV: return "SecondaryViewportRelativeNV"; + case DecorationPerPrimitiveEXT: return "PerPrimitiveEXT"; + case DecorationPerViewNV: return "PerViewNV"; + case DecorationPerTaskNV: return "PerTaskNV"; + case DecorationPerVertexKHR: return "PerVertexKHR"; + case DecorationNonUniform: return "NonUniform"; + case DecorationRestrictPointer: return "RestrictPointer"; + case DecorationAliasedPointer: return "AliasedPointer"; + case DecorationHitObjectShaderRecordBufferNV: return "HitObjectShaderRecordBufferNV"; + case DecorationBindlessSamplerNV: return "BindlessSamplerNV"; + case DecorationBindlessImageNV: return "BindlessImageNV"; + case DecorationBoundSamplerNV: return "BoundSamplerNV"; + case DecorationBoundImageNV: return "BoundImageNV"; + case DecorationSIMTCallINTEL: return "SIMTCallINTEL"; + case DecorationReferencedIndirectlyINTEL: return "ReferencedIndirectlyINTEL"; + case DecorationClobberINTEL: return "ClobberINTEL"; + case DecorationSideEffectsINTEL: return "SideEffectsINTEL"; + case DecorationVectorComputeVariableINTEL: return "VectorComputeVariableINTEL"; + case DecorationFuncParamIOKindINTEL: return "FuncParamIOKindINTEL"; + case DecorationVectorComputeFunctionINTEL: return "VectorComputeFunctionINTEL"; + case DecorationStackCallINTEL: return "StackCallINTEL"; + case DecorationGlobalVariableOffsetINTEL: return "GlobalVariableOffsetINTEL"; + case DecorationCounterBuffer: return "CounterBuffer"; + case DecorationHlslSemanticGOOGLE: return "HlslSemanticGOOGLE"; + case DecorationUserTypeGOOGLE: return "UserTypeGOOGLE"; + case DecorationFunctionRoundingModeINTEL: return "FunctionRoundingModeINTEL"; + case DecorationFunctionDenormModeINTEL: return "FunctionDenormModeINTEL"; + case DecorationRegisterINTEL: return "RegisterINTEL"; + case DecorationMemoryINTEL: return "MemoryINTEL"; + case DecorationNumbanksINTEL: return "NumbanksINTEL"; + case DecorationBankwidthINTEL: return "BankwidthINTEL"; + case DecorationMaxPrivateCopiesINTEL: return "MaxPrivateCopiesINTEL"; + case DecorationSinglepumpINTEL: return "SinglepumpINTEL"; + case DecorationDoublepumpINTEL: return "DoublepumpINTEL"; + case DecorationMaxReplicatesINTEL: return "MaxReplicatesINTEL"; + case DecorationSimpleDualPortINTEL: return "SimpleDualPortINTEL"; + case DecorationMergeINTEL: return "MergeINTEL"; + case DecorationBankBitsINTEL: return "BankBitsINTEL"; + case DecorationForcePow2DepthINTEL: return "ForcePow2DepthINTEL"; + case DecorationStridesizeINTEL: return "StridesizeINTEL"; + case DecorationWordsizeINTEL: return "WordsizeINTEL"; + case DecorationTrueDualPortINTEL: return "TrueDualPortINTEL"; + case DecorationBurstCoalesceINTEL: return "BurstCoalesceINTEL"; + case DecorationCacheSizeINTEL: return "CacheSizeINTEL"; + case DecorationDontStaticallyCoalesceINTEL: return "DontStaticallyCoalesceINTEL"; + case DecorationPrefetchINTEL: return "PrefetchINTEL"; + case DecorationStallEnableINTEL: return "StallEnableINTEL"; + case DecorationFuseLoopsInFunctionINTEL: return "FuseLoopsInFunctionINTEL"; + case DecorationMathOpDSPModeINTEL: return "MathOpDSPModeINTEL"; + case DecorationAliasScopeINTEL: return "AliasScopeINTEL"; + case DecorationNoAliasINTEL: return "NoAliasINTEL"; + case DecorationInitiationIntervalINTEL: return "InitiationIntervalINTEL"; + case DecorationMaxConcurrencyINTEL: return "MaxConcurrencyINTEL"; + case DecorationPipelineEnableINTEL: return "PipelineEnableINTEL"; + case DecorationBufferLocationINTEL: return "BufferLocationINTEL"; + case DecorationIOPipeStorageINTEL: return "IOPipeStorageINTEL"; + case DecorationFunctionFloatingPointModeINTEL: return "FunctionFloatingPointModeINTEL"; + case DecorationSingleElementVectorINTEL: return "SingleElementVectorINTEL"; + case DecorationVectorComputeCallableFunctionINTEL: return "VectorComputeCallableFunctionINTEL"; + case DecorationMediaBlockIOINTEL: return "MediaBlockIOINTEL"; + case DecorationStallFreeINTEL: return "StallFreeINTEL"; + case DecorationFPMaxErrorDecorationINTEL: return "FPMaxErrorDecorationINTEL"; + case DecorationLatencyControlLabelINTEL: return "LatencyControlLabelINTEL"; + case DecorationLatencyControlConstraintINTEL: return "LatencyControlConstraintINTEL"; + case DecorationConduitKernelArgumentINTEL: return "ConduitKernelArgumentINTEL"; + case DecorationRegisterMapKernelArgumentINTEL: return "RegisterMapKernelArgumentINTEL"; + case DecorationMMHostInterfaceAddressWidthINTEL: return "MMHostInterfaceAddressWidthINTEL"; + case DecorationMMHostInterfaceDataWidthINTEL: return "MMHostInterfaceDataWidthINTEL"; + case DecorationMMHostInterfaceLatencyINTEL: return "MMHostInterfaceLatencyINTEL"; + case DecorationMMHostInterfaceReadWriteModeINTEL: return "MMHostInterfaceReadWriteModeINTEL"; + case DecorationMMHostInterfaceMaxBurstINTEL: return "MMHostInterfaceMaxBurstINTEL"; + case DecorationMMHostInterfaceWaitRequestINTEL: return "MMHostInterfaceWaitRequestINTEL"; + case DecorationStableKernelArgumentINTEL: return "StableKernelArgumentINTEL"; + case DecorationHostAccessINTEL: return "HostAccessINTEL"; + case DecorationInitModeINTEL: return "InitModeINTEL"; + case DecorationImplementInRegisterMapINTEL: return "ImplementInRegisterMapINTEL"; + case DecorationCacheControlLoadINTEL: return "CacheControlLoadINTEL"; + case DecorationCacheControlStoreINTEL: return "CacheControlStoreINTEL"; + default: return "Unknown"; + } +} + +inline const char* BuiltInToString(BuiltIn value) { + switch (value) { + case BuiltInPosition: return "Position"; + case BuiltInPointSize: return "PointSize"; + case BuiltInClipDistance: return "ClipDistance"; + case BuiltInCullDistance: return "CullDistance"; + case BuiltInVertexId: return "VertexId"; + case BuiltInInstanceId: return "InstanceId"; + case BuiltInPrimitiveId: return "PrimitiveId"; + case BuiltInInvocationId: return "InvocationId"; + case BuiltInLayer: return "Layer"; + case BuiltInViewportIndex: return "ViewportIndex"; + case BuiltInTessLevelOuter: return "TessLevelOuter"; + case BuiltInTessLevelInner: return "TessLevelInner"; + case BuiltInTessCoord: return "TessCoord"; + case BuiltInPatchVertices: return "PatchVertices"; + case BuiltInFragCoord: return "FragCoord"; + case BuiltInPointCoord: return "PointCoord"; + case BuiltInFrontFacing: return "FrontFacing"; + case BuiltInSampleId: return "SampleId"; + case BuiltInSamplePosition: return "SamplePosition"; + case BuiltInSampleMask: return "SampleMask"; + case BuiltInFragDepth: return "FragDepth"; + case BuiltInHelperInvocation: return "HelperInvocation"; + case BuiltInNumWorkgroups: return "NumWorkgroups"; + case BuiltInWorkgroupSize: return "WorkgroupSize"; + case BuiltInWorkgroupId: return "WorkgroupId"; + case BuiltInLocalInvocationId: return "LocalInvocationId"; + case BuiltInGlobalInvocationId: return "GlobalInvocationId"; + case BuiltInLocalInvocationIndex: return "LocalInvocationIndex"; + case BuiltInWorkDim: return "WorkDim"; + case BuiltInGlobalSize: return "GlobalSize"; + case BuiltInEnqueuedWorkgroupSize: return "EnqueuedWorkgroupSize"; + case BuiltInGlobalOffset: return "GlobalOffset"; + case BuiltInGlobalLinearId: return "GlobalLinearId"; + case BuiltInSubgroupSize: return "SubgroupSize"; + case BuiltInSubgroupMaxSize: return "SubgroupMaxSize"; + case BuiltInNumSubgroups: return "NumSubgroups"; + case BuiltInNumEnqueuedSubgroups: return "NumEnqueuedSubgroups"; + case BuiltInSubgroupId: return "SubgroupId"; + case BuiltInSubgroupLocalInvocationId: return "SubgroupLocalInvocationId"; + case BuiltInVertexIndex: return "VertexIndex"; + case BuiltInInstanceIndex: return "InstanceIndex"; + case BuiltInCoreIDARM: return "CoreIDARM"; + case BuiltInCoreCountARM: return "CoreCountARM"; + case BuiltInCoreMaxIDARM: return "CoreMaxIDARM"; + case BuiltInWarpIDARM: return "WarpIDARM"; + case BuiltInWarpMaxIDARM: return "WarpMaxIDARM"; + case BuiltInSubgroupEqMask: return "SubgroupEqMask"; + case BuiltInSubgroupGeMask: return "SubgroupGeMask"; + case BuiltInSubgroupGtMask: return "SubgroupGtMask"; + case BuiltInSubgroupLeMask: return "SubgroupLeMask"; + case BuiltInSubgroupLtMask: return "SubgroupLtMask"; + case BuiltInBaseVertex: return "BaseVertex"; + case BuiltInBaseInstance: return "BaseInstance"; + case BuiltInDrawIndex: return "DrawIndex"; + case BuiltInPrimitiveShadingRateKHR: return "PrimitiveShadingRateKHR"; + case BuiltInDeviceIndex: return "DeviceIndex"; + case BuiltInViewIndex: return "ViewIndex"; + case BuiltInShadingRateKHR: return "ShadingRateKHR"; + case BuiltInTileOffsetQCOM: return "TileOffsetQCOM"; + case BuiltInTileDimensionQCOM: return "TileDimensionQCOM"; + case BuiltInTileApronSizeQCOM: return "TileApronSizeQCOM"; + case BuiltInBaryCoordNoPerspAMD: return "BaryCoordNoPerspAMD"; + case BuiltInBaryCoordNoPerspCentroidAMD: return "BaryCoordNoPerspCentroidAMD"; + case BuiltInBaryCoordNoPerspSampleAMD: return "BaryCoordNoPerspSampleAMD"; + case BuiltInBaryCoordSmoothAMD: return "BaryCoordSmoothAMD"; + case BuiltInBaryCoordSmoothCentroidAMD: return "BaryCoordSmoothCentroidAMD"; + case BuiltInBaryCoordSmoothSampleAMD: return "BaryCoordSmoothSampleAMD"; + case BuiltInBaryCoordPullModelAMD: return "BaryCoordPullModelAMD"; + case BuiltInFragStencilRefEXT: return "FragStencilRefEXT"; + case BuiltInRemainingRecursionLevelsAMDX: return "RemainingRecursionLevelsAMDX"; + case BuiltInShaderIndexAMDX: return "ShaderIndexAMDX"; + case BuiltInViewportMaskNV: return "ViewportMaskNV"; + case BuiltInSecondaryPositionNV: return "SecondaryPositionNV"; + case BuiltInSecondaryViewportMaskNV: return "SecondaryViewportMaskNV"; + case BuiltInPositionPerViewNV: return "PositionPerViewNV"; + case BuiltInViewportMaskPerViewNV: return "ViewportMaskPerViewNV"; + case BuiltInFullyCoveredEXT: return "FullyCoveredEXT"; + case BuiltInTaskCountNV: return "TaskCountNV"; + case BuiltInPrimitiveCountNV: return "PrimitiveCountNV"; + case BuiltInPrimitiveIndicesNV: return "PrimitiveIndicesNV"; + case BuiltInClipDistancePerViewNV: return "ClipDistancePerViewNV"; + case BuiltInCullDistancePerViewNV: return "CullDistancePerViewNV"; + case BuiltInLayerPerViewNV: return "LayerPerViewNV"; + case BuiltInMeshViewCountNV: return "MeshViewCountNV"; + case BuiltInMeshViewIndicesNV: return "MeshViewIndicesNV"; + case BuiltInBaryCoordKHR: return "BaryCoordKHR"; + case BuiltInBaryCoordNoPerspKHR: return "BaryCoordNoPerspKHR"; + case BuiltInFragSizeEXT: return "FragSizeEXT"; + case BuiltInFragInvocationCountEXT: return "FragInvocationCountEXT"; + case BuiltInPrimitivePointIndicesEXT: return "PrimitivePointIndicesEXT"; + case BuiltInPrimitiveLineIndicesEXT: return "PrimitiveLineIndicesEXT"; + case BuiltInPrimitiveTriangleIndicesEXT: return "PrimitiveTriangleIndicesEXT"; + case BuiltInCullPrimitiveEXT: return "CullPrimitiveEXT"; + case BuiltInLaunchIdKHR: return "LaunchIdKHR"; + case BuiltInLaunchSizeKHR: return "LaunchSizeKHR"; + case BuiltInWorldRayOriginKHR: return "WorldRayOriginKHR"; + case BuiltInWorldRayDirectionKHR: return "WorldRayDirectionKHR"; + case BuiltInObjectRayOriginKHR: return "ObjectRayOriginKHR"; + case BuiltInObjectRayDirectionKHR: return "ObjectRayDirectionKHR"; + case BuiltInRayTminKHR: return "RayTminKHR"; + case BuiltInRayTmaxKHR: return "RayTmaxKHR"; + case BuiltInInstanceCustomIndexKHR: return "InstanceCustomIndexKHR"; + case BuiltInObjectToWorldKHR: return "ObjectToWorldKHR"; + case BuiltInWorldToObjectKHR: return "WorldToObjectKHR"; + case BuiltInHitTNV: return "HitTNV"; + case BuiltInHitKindKHR: return "HitKindKHR"; + case BuiltInCurrentRayTimeNV: return "CurrentRayTimeNV"; + case BuiltInHitTriangleVertexPositionsKHR: return "HitTriangleVertexPositionsKHR"; + case BuiltInHitMicroTriangleVertexPositionsNV: return "HitMicroTriangleVertexPositionsNV"; + case BuiltInHitMicroTriangleVertexBarycentricsNV: return "HitMicroTriangleVertexBarycentricsNV"; + case BuiltInIncomingRayFlagsKHR: return "IncomingRayFlagsKHR"; + case BuiltInRayGeometryIndexKHR: return "RayGeometryIndexKHR"; + case BuiltInHitIsSphereNV: return "HitIsSphereNV"; + case BuiltInHitIsLSSNV: return "HitIsLSSNV"; + case BuiltInHitSpherePositionNV: return "HitSpherePositionNV"; + case BuiltInWarpsPerSMNV: return "WarpsPerSMNV"; + case BuiltInSMCountNV: return "SMCountNV"; + case BuiltInWarpIDNV: return "WarpIDNV"; + case BuiltInSMIDNV: return "SMIDNV"; + case BuiltInHitLSSPositionsNV: return "HitLSSPositionsNV"; + case BuiltInHitKindFrontFacingMicroTriangleNV: return "HitKindFrontFacingMicroTriangleNV"; + case BuiltInHitKindBackFacingMicroTriangleNV: return "HitKindBackFacingMicroTriangleNV"; + case BuiltInHitSphereRadiusNV: return "HitSphereRadiusNV"; + case BuiltInHitLSSRadiiNV: return "HitLSSRadiiNV"; + case BuiltInClusterIDNV: return "ClusterIDNV"; + case BuiltInCullMaskKHR: return "CullMaskKHR"; + default: return "Unknown"; + } +} + +inline const char* ScopeToString(Scope value) { + switch (value) { + case ScopeCrossDevice: return "CrossDevice"; + case ScopeDevice: return "Device"; + case ScopeWorkgroup: return "Workgroup"; + case ScopeSubgroup: return "Subgroup"; + case ScopeInvocation: return "Invocation"; + case ScopeQueueFamily: return "QueueFamily"; + case ScopeShaderCallKHR: return "ShaderCallKHR"; + default: return "Unknown"; + } +} + +inline const char* GroupOperationToString(GroupOperation value) { + switch (value) { + case GroupOperationReduce: return "Reduce"; + case GroupOperationInclusiveScan: return "InclusiveScan"; + case GroupOperationExclusiveScan: return "ExclusiveScan"; + case GroupOperationClusteredReduce: return "ClusteredReduce"; + case GroupOperationPartitionedReduceNV: return "PartitionedReduceNV"; + case GroupOperationPartitionedInclusiveScanNV: return "PartitionedInclusiveScanNV"; + case GroupOperationPartitionedExclusiveScanNV: return "PartitionedExclusiveScanNV"; + default: return "Unknown"; + } +} + +inline const char* KernelEnqueueFlagsToString(KernelEnqueueFlags value) { + switch (value) { + case KernelEnqueueFlagsNoWait: return "NoWait"; + case KernelEnqueueFlagsWaitKernel: return "WaitKernel"; + case KernelEnqueueFlagsWaitWorkGroup: return "WaitWorkGroup"; + default: return "Unknown"; + } +} + +inline const char* CapabilityToString(Capability value) { + switch (value) { + case CapabilityMatrix: return "Matrix"; + case CapabilityShader: return "Shader"; + case CapabilityGeometry: return "Geometry"; + case CapabilityTessellation: return "Tessellation"; + case CapabilityAddresses: return "Addresses"; + case CapabilityLinkage: return "Linkage"; + case CapabilityKernel: return "Kernel"; + case CapabilityVector16: return "Vector16"; + case CapabilityFloat16Buffer: return "Float16Buffer"; + case CapabilityFloat16: return "Float16"; + case CapabilityFloat64: return "Float64"; + case CapabilityInt64: return "Int64"; + case CapabilityInt64Atomics: return "Int64Atomics"; + case CapabilityImageBasic: return "ImageBasic"; + case CapabilityImageReadWrite: return "ImageReadWrite"; + case CapabilityImageMipmap: return "ImageMipmap"; + case CapabilityPipes: return "Pipes"; + case CapabilityGroups: return "Groups"; + case CapabilityDeviceEnqueue: return "DeviceEnqueue"; + case CapabilityLiteralSampler: return "LiteralSampler"; + case CapabilityAtomicStorage: return "AtomicStorage"; + case CapabilityInt16: return "Int16"; + case CapabilityTessellationPointSize: return "TessellationPointSize"; + case CapabilityGeometryPointSize: return "GeometryPointSize"; + case CapabilityImageGatherExtended: return "ImageGatherExtended"; + case CapabilityStorageImageMultisample: return "StorageImageMultisample"; + case CapabilityUniformBufferArrayDynamicIndexing: return "UniformBufferArrayDynamicIndexing"; + case CapabilitySampledImageArrayDynamicIndexing: return "SampledImageArrayDynamicIndexing"; + case CapabilityStorageBufferArrayDynamicIndexing: return "StorageBufferArrayDynamicIndexing"; + case CapabilityStorageImageArrayDynamicIndexing: return "StorageImageArrayDynamicIndexing"; + case CapabilityClipDistance: return "ClipDistance"; + case CapabilityCullDistance: return "CullDistance"; + case CapabilityImageCubeArray: return "ImageCubeArray"; + case CapabilitySampleRateShading: return "SampleRateShading"; + case CapabilityImageRect: return "ImageRect"; + case CapabilitySampledRect: return "SampledRect"; + case CapabilityGenericPointer: return "GenericPointer"; + case CapabilityInt8: return "Int8"; + case CapabilityInputAttachment: return "InputAttachment"; + case CapabilitySparseResidency: return "SparseResidency"; + case CapabilityMinLod: return "MinLod"; + case CapabilitySampled1D: return "Sampled1D"; + case CapabilityImage1D: return "Image1D"; + case CapabilitySampledCubeArray: return "SampledCubeArray"; + case CapabilitySampledBuffer: return "SampledBuffer"; + case CapabilityImageBuffer: return "ImageBuffer"; + case CapabilityImageMSArray: return "ImageMSArray"; + case CapabilityStorageImageExtendedFormats: return "StorageImageExtendedFormats"; + case CapabilityImageQuery: return "ImageQuery"; + case CapabilityDerivativeControl: return "DerivativeControl"; + case CapabilityInterpolationFunction: return "InterpolationFunction"; + case CapabilityTransformFeedback: return "TransformFeedback"; + case CapabilityGeometryStreams: return "GeometryStreams"; + case CapabilityStorageImageReadWithoutFormat: return "StorageImageReadWithoutFormat"; + case CapabilityStorageImageWriteWithoutFormat: return "StorageImageWriteWithoutFormat"; + case CapabilityMultiViewport: return "MultiViewport"; + case CapabilitySubgroupDispatch: return "SubgroupDispatch"; + case CapabilityNamedBarrier: return "NamedBarrier"; + case CapabilityPipeStorage: return "PipeStorage"; + case CapabilityGroupNonUniform: return "GroupNonUniform"; + case CapabilityGroupNonUniformVote: return "GroupNonUniformVote"; + case CapabilityGroupNonUniformArithmetic: return "GroupNonUniformArithmetic"; + case CapabilityGroupNonUniformBallot: return "GroupNonUniformBallot"; + case CapabilityGroupNonUniformShuffle: return "GroupNonUniformShuffle"; + case CapabilityGroupNonUniformShuffleRelative: return "GroupNonUniformShuffleRelative"; + case CapabilityGroupNonUniformClustered: return "GroupNonUniformClustered"; + case CapabilityGroupNonUniformQuad: return "GroupNonUniformQuad"; + case CapabilityShaderLayer: return "ShaderLayer"; + case CapabilityShaderViewportIndex: return "ShaderViewportIndex"; + case CapabilityUniformDecoration: return "UniformDecoration"; + case CapabilityCoreBuiltinsARM: return "CoreBuiltinsARM"; + case CapabilityTileImageColorReadAccessEXT: return "TileImageColorReadAccessEXT"; + case CapabilityTileImageDepthReadAccessEXT: return "TileImageDepthReadAccessEXT"; + case CapabilityTileImageStencilReadAccessEXT: return "TileImageStencilReadAccessEXT"; + case CapabilityCooperativeMatrixLayoutsARM: return "CooperativeMatrixLayoutsARM"; + case CapabilityFragmentShadingRateKHR: return "FragmentShadingRateKHR"; + case CapabilitySubgroupBallotKHR: return "SubgroupBallotKHR"; + case CapabilityDrawParameters: return "DrawParameters"; + case CapabilityWorkgroupMemoryExplicitLayoutKHR: return "WorkgroupMemoryExplicitLayoutKHR"; + case CapabilityWorkgroupMemoryExplicitLayout8BitAccessKHR: return "WorkgroupMemoryExplicitLayout8BitAccessKHR"; + case CapabilityWorkgroupMemoryExplicitLayout16BitAccessKHR: return "WorkgroupMemoryExplicitLayout16BitAccessKHR"; + case CapabilitySubgroupVoteKHR: return "SubgroupVoteKHR"; + case CapabilityStorageBuffer16BitAccess: return "StorageBuffer16BitAccess"; + case CapabilityStorageUniform16: return "StorageUniform16"; + case CapabilityStoragePushConstant16: return "StoragePushConstant16"; + case CapabilityStorageInputOutput16: return "StorageInputOutput16"; + case CapabilityDeviceGroup: return "DeviceGroup"; + case CapabilityMultiView: return "MultiView"; + case CapabilityVariablePointersStorageBuffer: return "VariablePointersStorageBuffer"; + case CapabilityVariablePointers: return "VariablePointers"; + case CapabilityAtomicStorageOps: return "AtomicStorageOps"; + case CapabilitySampleMaskPostDepthCoverage: return "SampleMaskPostDepthCoverage"; + case CapabilityStorageBuffer8BitAccess: return "StorageBuffer8BitAccess"; + case CapabilityUniformAndStorageBuffer8BitAccess: return "UniformAndStorageBuffer8BitAccess"; + case CapabilityStoragePushConstant8: return "StoragePushConstant8"; + case CapabilityDenormPreserve: return "DenormPreserve"; + case CapabilityDenormFlushToZero: return "DenormFlushToZero"; + case CapabilitySignedZeroInfNanPreserve: return "SignedZeroInfNanPreserve"; + case CapabilityRoundingModeRTE: return "RoundingModeRTE"; + case CapabilityRoundingModeRTZ: return "RoundingModeRTZ"; + case CapabilityRayQueryProvisionalKHR: return "RayQueryProvisionalKHR"; + case CapabilityRayQueryKHR: return "RayQueryKHR"; + case CapabilityUntypedPointersKHR: return "UntypedPointersKHR"; + case CapabilityRayTraversalPrimitiveCullingKHR: return "RayTraversalPrimitiveCullingKHR"; + case CapabilityRayTracingKHR: return "RayTracingKHR"; + case CapabilityTextureSampleWeightedQCOM: return "TextureSampleWeightedQCOM"; + case CapabilityTextureBoxFilterQCOM: return "TextureBoxFilterQCOM"; + case CapabilityTextureBlockMatchQCOM: return "TextureBlockMatchQCOM"; + case CapabilityTileShadingQCOM: return "TileShadingQCOM"; + case CapabilityTextureBlockMatch2QCOM: return "TextureBlockMatch2QCOM"; + case CapabilityFloat16ImageAMD: return "Float16ImageAMD"; + case CapabilityImageGatherBiasLodAMD: return "ImageGatherBiasLodAMD"; + case CapabilityFragmentMaskAMD: return "FragmentMaskAMD"; + case CapabilityStencilExportEXT: return "StencilExportEXT"; + case CapabilityImageReadWriteLodAMD: return "ImageReadWriteLodAMD"; + case CapabilityInt64ImageEXT: return "Int64ImageEXT"; + case CapabilityShaderClockKHR: return "ShaderClockKHR"; + case CapabilityShaderEnqueueAMDX: return "ShaderEnqueueAMDX"; + case CapabilityQuadControlKHR: return "QuadControlKHR"; + case CapabilityBFloat16TypeKHR: return "BFloat16TypeKHR"; + case CapabilityBFloat16DotProductKHR: return "BFloat16DotProductKHR"; + case CapabilityBFloat16CooperativeMatrixKHR: return "BFloat16CooperativeMatrixKHR"; + case CapabilitySampleMaskOverrideCoverageNV: return "SampleMaskOverrideCoverageNV"; + case CapabilityGeometryShaderPassthroughNV: return "GeometryShaderPassthroughNV"; + case CapabilityShaderViewportIndexLayerEXT: return "ShaderViewportIndexLayerEXT"; + case CapabilityShaderViewportMaskNV: return "ShaderViewportMaskNV"; + case CapabilityShaderStereoViewNV: return "ShaderStereoViewNV"; + case CapabilityPerViewAttributesNV: return "PerViewAttributesNV"; + case CapabilityFragmentFullyCoveredEXT: return "FragmentFullyCoveredEXT"; + case CapabilityMeshShadingNV: return "MeshShadingNV"; + case CapabilityImageFootprintNV: return "ImageFootprintNV"; + case CapabilityMeshShadingEXT: return "MeshShadingEXT"; + case CapabilityFragmentBarycentricKHR: return "FragmentBarycentricKHR"; + case CapabilityComputeDerivativeGroupQuadsKHR: return "ComputeDerivativeGroupQuadsKHR"; + case CapabilityFragmentDensityEXT: return "FragmentDensityEXT"; + case CapabilityGroupNonUniformPartitionedNV: return "GroupNonUniformPartitionedNV"; + case CapabilityShaderNonUniform: return "ShaderNonUniform"; + case CapabilityRuntimeDescriptorArray: return "RuntimeDescriptorArray"; + case CapabilityInputAttachmentArrayDynamicIndexing: return "InputAttachmentArrayDynamicIndexing"; + case CapabilityUniformTexelBufferArrayDynamicIndexing: return "UniformTexelBufferArrayDynamicIndexing"; + case CapabilityStorageTexelBufferArrayDynamicIndexing: return "StorageTexelBufferArrayDynamicIndexing"; + case CapabilityUniformBufferArrayNonUniformIndexing: return "UniformBufferArrayNonUniformIndexing"; + case CapabilitySampledImageArrayNonUniformIndexing: return "SampledImageArrayNonUniformIndexing"; + case CapabilityStorageBufferArrayNonUniformIndexing: return "StorageBufferArrayNonUniformIndexing"; + case CapabilityStorageImageArrayNonUniformIndexing: return "StorageImageArrayNonUniformIndexing"; + case CapabilityInputAttachmentArrayNonUniformIndexing: return "InputAttachmentArrayNonUniformIndexing"; + case CapabilityUniformTexelBufferArrayNonUniformIndexing: return "UniformTexelBufferArrayNonUniformIndexing"; + case CapabilityStorageTexelBufferArrayNonUniformIndexing: return "StorageTexelBufferArrayNonUniformIndexing"; + case CapabilityRayTracingPositionFetchKHR: return "RayTracingPositionFetchKHR"; + case CapabilityRayTracingNV: return "RayTracingNV"; + case CapabilityRayTracingMotionBlurNV: return "RayTracingMotionBlurNV"; + case CapabilityVulkanMemoryModel: return "VulkanMemoryModel"; + case CapabilityVulkanMemoryModelDeviceScope: return "VulkanMemoryModelDeviceScope"; + case CapabilityPhysicalStorageBufferAddresses: return "PhysicalStorageBufferAddresses"; + case CapabilityComputeDerivativeGroupLinearKHR: return "ComputeDerivativeGroupLinearKHR"; + case CapabilityRayTracingProvisionalKHR: return "RayTracingProvisionalKHR"; + case CapabilityCooperativeMatrixNV: return "CooperativeMatrixNV"; + case CapabilityFragmentShaderSampleInterlockEXT: return "FragmentShaderSampleInterlockEXT"; + case CapabilityFragmentShaderShadingRateInterlockEXT: return "FragmentShaderShadingRateInterlockEXT"; + case CapabilityShaderSMBuiltinsNV: return "ShaderSMBuiltinsNV"; + case CapabilityFragmentShaderPixelInterlockEXT: return "FragmentShaderPixelInterlockEXT"; + case CapabilityDemoteToHelperInvocation: return "DemoteToHelperInvocation"; + case CapabilityDisplacementMicromapNV: return "DisplacementMicromapNV"; + case CapabilityRayTracingOpacityMicromapEXT: return "RayTracingOpacityMicromapEXT"; + case CapabilityShaderInvocationReorderNV: return "ShaderInvocationReorderNV"; + case CapabilityBindlessTextureNV: return "BindlessTextureNV"; + case CapabilityRayQueryPositionFetchKHR: return "RayQueryPositionFetchKHR"; + case CapabilityCooperativeVectorNV: return "CooperativeVectorNV"; + case CapabilityAtomicFloat16VectorNV: return "AtomicFloat16VectorNV"; + case CapabilityRayTracingDisplacementMicromapNV: return "RayTracingDisplacementMicromapNV"; + case CapabilityRawAccessChainsNV: return "RawAccessChainsNV"; + case CapabilityRayTracingSpheresGeometryNV: return "RayTracingSpheresGeometryNV"; + case CapabilityRayTracingLinearSweptSpheresGeometryNV: return "RayTracingLinearSweptSpheresGeometryNV"; + case CapabilityCooperativeMatrixReductionsNV: return "CooperativeMatrixReductionsNV"; + case CapabilityCooperativeMatrixConversionsNV: return "CooperativeMatrixConversionsNV"; + case CapabilityCooperativeMatrixPerElementOperationsNV: return "CooperativeMatrixPerElementOperationsNV"; + case CapabilityCooperativeMatrixTensorAddressingNV: return "CooperativeMatrixTensorAddressingNV"; + case CapabilityCooperativeMatrixBlockLoadsNV: return "CooperativeMatrixBlockLoadsNV"; + case CapabilityCooperativeVectorTrainingNV: return "CooperativeVectorTrainingNV"; + case CapabilityRayTracingClusterAccelerationStructureNV: return "RayTracingClusterAccelerationStructureNV"; + case CapabilityTensorAddressingNV: return "TensorAddressingNV"; + case CapabilitySubgroupShuffleINTEL: return "SubgroupShuffleINTEL"; + case CapabilitySubgroupBufferBlockIOINTEL: return "SubgroupBufferBlockIOINTEL"; + case CapabilitySubgroupImageBlockIOINTEL: return "SubgroupImageBlockIOINTEL"; + case CapabilitySubgroupImageMediaBlockIOINTEL: return "SubgroupImageMediaBlockIOINTEL"; + case CapabilityRoundToInfinityINTEL: return "RoundToInfinityINTEL"; + case CapabilityFloatingPointModeINTEL: return "FloatingPointModeINTEL"; + case CapabilityIntegerFunctions2INTEL: return "IntegerFunctions2INTEL"; + case CapabilityFunctionPointersINTEL: return "FunctionPointersINTEL"; + case CapabilityIndirectReferencesINTEL: return "IndirectReferencesINTEL"; + case CapabilityAsmINTEL: return "AsmINTEL"; + case CapabilityAtomicFloat32MinMaxEXT: return "AtomicFloat32MinMaxEXT"; + case CapabilityAtomicFloat64MinMaxEXT: return "AtomicFloat64MinMaxEXT"; + case CapabilityAtomicFloat16MinMaxEXT: return "AtomicFloat16MinMaxEXT"; + case CapabilityVectorComputeINTEL: return "VectorComputeINTEL"; + case CapabilityVectorAnyINTEL: return "VectorAnyINTEL"; + case CapabilityExpectAssumeKHR: return "ExpectAssumeKHR"; + case CapabilitySubgroupAvcMotionEstimationINTEL: return "SubgroupAvcMotionEstimationINTEL"; + case CapabilitySubgroupAvcMotionEstimationIntraINTEL: return "SubgroupAvcMotionEstimationIntraINTEL"; + case CapabilitySubgroupAvcMotionEstimationChromaINTEL: return "SubgroupAvcMotionEstimationChromaINTEL"; + case CapabilityVariableLengthArrayINTEL: return "VariableLengthArrayINTEL"; + case CapabilityFunctionFloatControlINTEL: return "FunctionFloatControlINTEL"; + case CapabilityFPGAMemoryAttributesINTEL: return "FPGAMemoryAttributesINTEL"; + case CapabilityFPFastMathModeINTEL: return "FPFastMathModeINTEL"; + case CapabilityArbitraryPrecisionIntegersINTEL: return "ArbitraryPrecisionIntegersINTEL"; + case CapabilityArbitraryPrecisionFloatingPointINTEL: return "ArbitraryPrecisionFloatingPointINTEL"; + case CapabilityUnstructuredLoopControlsINTEL: return "UnstructuredLoopControlsINTEL"; + case CapabilityFPGALoopControlsINTEL: return "FPGALoopControlsINTEL"; + case CapabilityKernelAttributesINTEL: return "KernelAttributesINTEL"; + case CapabilityFPGAKernelAttributesINTEL: return "FPGAKernelAttributesINTEL"; + case CapabilityFPGAMemoryAccessesINTEL: return "FPGAMemoryAccessesINTEL"; + case CapabilityFPGAClusterAttributesINTEL: return "FPGAClusterAttributesINTEL"; + case CapabilityLoopFuseINTEL: return "LoopFuseINTEL"; + case CapabilityFPGADSPControlINTEL: return "FPGADSPControlINTEL"; + case CapabilityMemoryAccessAliasingINTEL: return "MemoryAccessAliasingINTEL"; + case CapabilityFPGAInvocationPipeliningAttributesINTEL: return "FPGAInvocationPipeliningAttributesINTEL"; + case CapabilityFPGABufferLocationINTEL: return "FPGABufferLocationINTEL"; + case CapabilityArbitraryPrecisionFixedPointINTEL: return "ArbitraryPrecisionFixedPointINTEL"; + case CapabilityUSMStorageClassesINTEL: return "USMStorageClassesINTEL"; + case CapabilityRuntimeAlignedAttributeINTEL: return "RuntimeAlignedAttributeINTEL"; + case CapabilityIOPipesINTEL: return "IOPipesINTEL"; + case CapabilityBlockingPipesINTEL: return "BlockingPipesINTEL"; + case CapabilityFPGARegINTEL: return "FPGARegINTEL"; + case CapabilityDotProductInputAll: return "DotProductInputAll"; + case CapabilityDotProductInput4x8Bit: return "DotProductInput4x8Bit"; + case CapabilityDotProductInput4x8BitPacked: return "DotProductInput4x8BitPacked"; + case CapabilityDotProduct: return "DotProduct"; + case CapabilityRayCullMaskKHR: return "RayCullMaskKHR"; + case CapabilityCooperativeMatrixKHR: return "CooperativeMatrixKHR"; + case CapabilityReplicatedCompositesEXT: return "ReplicatedCompositesEXT"; + case CapabilityBitInstructions: return "BitInstructions"; + case CapabilityGroupNonUniformRotateKHR: return "GroupNonUniformRotateKHR"; + case CapabilityFloatControls2: return "FloatControls2"; + case CapabilityAtomicFloat32AddEXT: return "AtomicFloat32AddEXT"; + case CapabilityAtomicFloat64AddEXT: return "AtomicFloat64AddEXT"; + case CapabilityLongCompositesINTEL: return "LongCompositesINTEL"; + case CapabilityOptNoneEXT: return "OptNoneEXT"; + case CapabilityAtomicFloat16AddEXT: return "AtomicFloat16AddEXT"; + case CapabilityDebugInfoModuleINTEL: return "DebugInfoModuleINTEL"; + case CapabilityBFloat16ConversionINTEL: return "BFloat16ConversionINTEL"; + case CapabilitySplitBarrierINTEL: return "SplitBarrierINTEL"; + case CapabilityArithmeticFenceEXT: return "ArithmeticFenceEXT"; + case CapabilityFPGAClusterAttributesV2INTEL: return "FPGAClusterAttributesV2INTEL"; + case CapabilityFPGAKernelAttributesv2INTEL: return "FPGAKernelAttributesv2INTEL"; + case CapabilityTaskSequenceINTEL: return "TaskSequenceINTEL"; + case CapabilityFPMaxErrorINTEL: return "FPMaxErrorINTEL"; + case CapabilityFPGALatencyControlINTEL: return "FPGALatencyControlINTEL"; + case CapabilityFPGAArgumentInterfacesINTEL: return "FPGAArgumentInterfacesINTEL"; + case CapabilityGlobalVariableHostAccessINTEL: return "GlobalVariableHostAccessINTEL"; + case CapabilityGlobalVariableFPGADecorationsINTEL: return "GlobalVariableFPGADecorationsINTEL"; + case CapabilitySubgroupBufferPrefetchINTEL: return "SubgroupBufferPrefetchINTEL"; + case CapabilitySubgroup2DBlockIOINTEL: return "Subgroup2DBlockIOINTEL"; + case CapabilitySubgroup2DBlockTransformINTEL: return "Subgroup2DBlockTransformINTEL"; + case CapabilitySubgroup2DBlockTransposeINTEL: return "Subgroup2DBlockTransposeINTEL"; + case CapabilitySubgroupMatrixMultiplyAccumulateINTEL: return "SubgroupMatrixMultiplyAccumulateINTEL"; + case CapabilityTernaryBitwiseFunctionINTEL: return "TernaryBitwiseFunctionINTEL"; + case CapabilityGroupUniformArithmeticKHR: return "GroupUniformArithmeticKHR"; + case CapabilityTensorFloat32RoundingINTEL: return "TensorFloat32RoundingINTEL"; + case CapabilityMaskedGatherScatterINTEL: return "MaskedGatherScatterINTEL"; + case CapabilityCacheControlsINTEL: return "CacheControlsINTEL"; + case CapabilityRegisterLimitsINTEL: return "RegisterLimitsINTEL"; + default: return "Unknown"; + } +} + +inline const char* RayQueryIntersectionToString(RayQueryIntersection value) { + switch (value) { + case RayQueryIntersectionRayQueryCandidateIntersectionKHR: return "RayQueryCandidateIntersectionKHR"; + case RayQueryIntersectionRayQueryCommittedIntersectionKHR: return "RayQueryCommittedIntersectionKHR"; + default: return "Unknown"; + } +} + +inline const char* RayQueryCommittedIntersectionTypeToString(RayQueryCommittedIntersectionType value) { + switch (value) { + case RayQueryCommittedIntersectionTypeRayQueryCommittedIntersectionNoneKHR: return "RayQueryCommittedIntersectionNoneKHR"; + case RayQueryCommittedIntersectionTypeRayQueryCommittedIntersectionTriangleKHR: return "RayQueryCommittedIntersectionTriangleKHR"; + case RayQueryCommittedIntersectionTypeRayQueryCommittedIntersectionGeneratedKHR: return "RayQueryCommittedIntersectionGeneratedKHR"; + default: return "Unknown"; + } +} + +inline const char* RayQueryCandidateIntersectionTypeToString(RayQueryCandidateIntersectionType value) { + switch (value) { + case RayQueryCandidateIntersectionTypeRayQueryCandidateIntersectionTriangleKHR: return "RayQueryCandidateIntersectionTriangleKHR"; + case RayQueryCandidateIntersectionTypeRayQueryCandidateIntersectionAABBKHR: return "RayQueryCandidateIntersectionAABBKHR"; + default: return "Unknown"; + } +} + +inline const char* FPDenormModeToString(FPDenormMode value) { + switch (value) { + case FPDenormModePreserve: return "Preserve"; + case FPDenormModeFlushToZero: return "FlushToZero"; + default: return "Unknown"; + } +} + +inline const char* FPOperationModeToString(FPOperationMode value) { + switch (value) { + case FPOperationModeIEEE: return "IEEE"; + case FPOperationModeALT: return "ALT"; + default: return "Unknown"; + } +} + +inline const char* QuantizationModesToString(QuantizationModes value) { + switch (value) { + case QuantizationModesTRN: return "TRN"; + case QuantizationModesTRN_ZERO: return "TRN_ZERO"; + case QuantizationModesRND: return "RND"; + case QuantizationModesRND_ZERO: return "RND_ZERO"; + case QuantizationModesRND_INF: return "RND_INF"; + case QuantizationModesRND_MIN_INF: return "RND_MIN_INF"; + case QuantizationModesRND_CONV: return "RND_CONV"; + case QuantizationModesRND_CONV_ODD: return "RND_CONV_ODD"; + default: return "Unknown"; + } +} + +inline const char* OverflowModesToString(OverflowModes value) { + switch (value) { + case OverflowModesWRAP: return "WRAP"; + case OverflowModesSAT: return "SAT"; + case OverflowModesSAT_ZERO: return "SAT_ZERO"; + case OverflowModesSAT_SYM: return "SAT_SYM"; + default: return "Unknown"; + } +} + +inline const char* PackedVectorFormatToString(PackedVectorFormat value) { + switch (value) { + case PackedVectorFormatPackedVectorFormat4x8Bit: return "PackedVectorFormat4x8Bit"; + default: return "Unknown"; + } +} + +inline const char* CooperativeMatrixLayoutToString(CooperativeMatrixLayout value) { + switch (value) { + case CooperativeMatrixLayoutRowMajorKHR: return "RowMajorKHR"; + case CooperativeMatrixLayoutColumnMajorKHR: return "ColumnMajorKHR"; + case CooperativeMatrixLayoutRowBlockedInterleavedARM: return "RowBlockedInterleavedARM"; + case CooperativeMatrixLayoutColumnBlockedInterleavedARM: return "ColumnBlockedInterleavedARM"; + default: return "Unknown"; + } +} + +inline const char* CooperativeMatrixUseToString(CooperativeMatrixUse value) { + switch (value) { + case CooperativeMatrixUseMatrixAKHR: return "MatrixAKHR"; + case CooperativeMatrixUseMatrixBKHR: return "MatrixBKHR"; + case CooperativeMatrixUseMatrixAccumulatorKHR: return "MatrixAccumulatorKHR"; + default: return "Unknown"; + } +} + +inline const char* TensorClampModeToString(TensorClampMode value) { + switch (value) { + case TensorClampModeUndefined: return "Undefined"; + case TensorClampModeConstant: return "Constant"; + case TensorClampModeClampToEdge: return "ClampToEdge"; + case TensorClampModeRepeat: return "Repeat"; + case TensorClampModeRepeatMirrored: return "RepeatMirrored"; + default: return "Unknown"; + } +} + +inline const char* InitializationModeQualifierToString(InitializationModeQualifier value) { + switch (value) { + case InitializationModeQualifierInitOnDeviceReprogramINTEL: return "InitOnDeviceReprogramINTEL"; + case InitializationModeQualifierInitOnDeviceResetINTEL: return "InitOnDeviceResetINTEL"; + default: return "Unknown"; + } +} + +inline const char* HostAccessQualifierToString(HostAccessQualifier value) { + switch (value) { + case HostAccessQualifierNoneINTEL: return "NoneINTEL"; + case HostAccessQualifierReadINTEL: return "ReadINTEL"; + case HostAccessQualifierWriteINTEL: return "WriteINTEL"; + case HostAccessQualifierReadWriteINTEL: return "ReadWriteINTEL"; + default: return "Unknown"; + } +} + +inline const char* LoadCacheControlToString(LoadCacheControl value) { + switch (value) { + case LoadCacheControlUncachedINTEL: return "UncachedINTEL"; + case LoadCacheControlCachedINTEL: return "CachedINTEL"; + case LoadCacheControlStreamingINTEL: return "StreamingINTEL"; + case LoadCacheControlInvalidateAfterReadINTEL: return "InvalidateAfterReadINTEL"; + case LoadCacheControlConstCachedINTEL: return "ConstCachedINTEL"; + default: return "Unknown"; + } +} + +inline const char* StoreCacheControlToString(StoreCacheControl value) { + switch (value) { + case StoreCacheControlUncachedINTEL: return "UncachedINTEL"; + case StoreCacheControlWriteThroughINTEL: return "WriteThroughINTEL"; + case StoreCacheControlWriteBackINTEL: return "WriteBackINTEL"; + case StoreCacheControlStreamingINTEL: return "StreamingINTEL"; + default: return "Unknown"; + } +} + +inline const char* NamedMaximumNumberOfRegistersToString(NamedMaximumNumberOfRegisters value) { + switch (value) { + case NamedMaximumNumberOfRegistersAutoINTEL: return "AutoINTEL"; + default: return "Unknown"; + } +} + +inline const char* FPEncodingToString(FPEncoding value) { + switch (value) { + case FPEncodingBFloat16KHR: return "BFloat16KHR"; + default: return "Unknown"; + } +} + +inline const char* CooperativeVectorMatrixLayoutToString(CooperativeVectorMatrixLayout value) { + switch (value) { + case CooperativeVectorMatrixLayoutRowMajorNV: return "RowMajorNV"; + case CooperativeVectorMatrixLayoutColumnMajorNV: return "ColumnMajorNV"; + case CooperativeVectorMatrixLayoutInferencingOptimalNV: return "InferencingOptimalNV"; + case CooperativeVectorMatrixLayoutTrainingOptimalNV: return "TrainingOptimalNV"; + default: return "Unknown"; + } +} + +inline const char* ComponentTypeToString(ComponentType value) { + switch (value) { + case ComponentTypeFloat16NV: return "Float16NV"; + case ComponentTypeFloat32NV: return "Float32NV"; + case ComponentTypeFloat64NV: return "Float64NV"; + case ComponentTypeSignedInt8NV: return "SignedInt8NV"; + case ComponentTypeSignedInt16NV: return "SignedInt16NV"; + case ComponentTypeSignedInt32NV: return "SignedInt32NV"; + case ComponentTypeSignedInt64NV: return "SignedInt64NV"; + case ComponentTypeUnsignedInt8NV: return "UnsignedInt8NV"; + case ComponentTypeUnsignedInt16NV: return "UnsignedInt16NV"; + case ComponentTypeUnsignedInt32NV: return "UnsignedInt32NV"; + case ComponentTypeUnsignedInt64NV: return "UnsignedInt64NV"; + case ComponentTypeSignedInt8PackedNV: return "SignedInt8PackedNV"; + case ComponentTypeUnsignedInt8PackedNV: return "UnsignedInt8PackedNV"; + case ComponentTypeFloatE4M3NV: return "FloatE4M3NV"; + case ComponentTypeFloatE5M2NV: return "FloatE5M2NV"; + default: return "Unknown"; + } +} + +inline const char* OpToString(Op value) { + switch (value) { + case OpNop: return "OpNop"; + case OpUndef: return "OpUndef"; + case OpSourceContinued: return "OpSourceContinued"; + case OpSource: return "OpSource"; + case OpSourceExtension: return "OpSourceExtension"; + case OpName: return "OpName"; + case OpMemberName: return "OpMemberName"; + case OpString: return "OpString"; + case OpLine: return "OpLine"; + case OpExtension: return "OpExtension"; + case OpExtInstImport: return "OpExtInstImport"; + case OpExtInst: return "OpExtInst"; + case OpMemoryModel: return "OpMemoryModel"; + case OpEntryPoint: return "OpEntryPoint"; + case OpExecutionMode: return "OpExecutionMode"; + case OpCapability: return "OpCapability"; + case OpTypeVoid: return "OpTypeVoid"; + case OpTypeBool: return "OpTypeBool"; + case OpTypeInt: return "OpTypeInt"; + case OpTypeFloat: return "OpTypeFloat"; + case OpTypeVector: return "OpTypeVector"; + case OpTypeMatrix: return "OpTypeMatrix"; + case OpTypeImage: return "OpTypeImage"; + case OpTypeSampler: return "OpTypeSampler"; + case OpTypeSampledImage: return "OpTypeSampledImage"; + case OpTypeArray: return "OpTypeArray"; + case OpTypeRuntimeArray: return "OpTypeRuntimeArray"; + case OpTypeStruct: return "OpTypeStruct"; + case OpTypeOpaque: return "OpTypeOpaque"; + case OpTypePointer: return "OpTypePointer"; + case OpTypeFunction: return "OpTypeFunction"; + case OpTypeEvent: return "OpTypeEvent"; + case OpTypeDeviceEvent: return "OpTypeDeviceEvent"; + case OpTypeReserveId: return "OpTypeReserveId"; + case OpTypeQueue: return "OpTypeQueue"; + case OpTypePipe: return "OpTypePipe"; + case OpTypeForwardPointer: return "OpTypeForwardPointer"; + case OpConstantTrue: return "OpConstantTrue"; + case OpConstantFalse: return "OpConstantFalse"; + case OpConstant: return "OpConstant"; + case OpConstantComposite: return "OpConstantComposite"; + case OpConstantSampler: return "OpConstantSampler"; + case OpConstantNull: return "OpConstantNull"; + case OpSpecConstantTrue: return "OpSpecConstantTrue"; + case OpSpecConstantFalse: return "OpSpecConstantFalse"; + case OpSpecConstant: return "OpSpecConstant"; + case OpSpecConstantComposite: return "OpSpecConstantComposite"; + case OpSpecConstantOp: return "OpSpecConstantOp"; + case OpFunction: return "OpFunction"; + case OpFunctionParameter: return "OpFunctionParameter"; + case OpFunctionEnd: return "OpFunctionEnd"; + case OpFunctionCall: return "OpFunctionCall"; + case OpVariable: return "OpVariable"; + case OpImageTexelPointer: return "OpImageTexelPointer"; + case OpLoad: return "OpLoad"; + case OpStore: return "OpStore"; + case OpCopyMemory: return "OpCopyMemory"; + case OpCopyMemorySized: return "OpCopyMemorySized"; + case OpAccessChain: return "OpAccessChain"; + case OpInBoundsAccessChain: return "OpInBoundsAccessChain"; + case OpPtrAccessChain: return "OpPtrAccessChain"; + case OpArrayLength: return "OpArrayLength"; + case OpGenericPtrMemSemantics: return "OpGenericPtrMemSemantics"; + case OpInBoundsPtrAccessChain: return "OpInBoundsPtrAccessChain"; + case OpDecorate: return "OpDecorate"; + case OpMemberDecorate: return "OpMemberDecorate"; + case OpDecorationGroup: return "OpDecorationGroup"; + case OpGroupDecorate: return "OpGroupDecorate"; + case OpGroupMemberDecorate: return "OpGroupMemberDecorate"; + case OpVectorExtractDynamic: return "OpVectorExtractDynamic"; + case OpVectorInsertDynamic: return "OpVectorInsertDynamic"; + case OpVectorShuffle: return "OpVectorShuffle"; + case OpCompositeConstruct: return "OpCompositeConstruct"; + case OpCompositeExtract: return "OpCompositeExtract"; + case OpCompositeInsert: return "OpCompositeInsert"; + case OpCopyObject: return "OpCopyObject"; + case OpTranspose: return "OpTranspose"; + case OpSampledImage: return "OpSampledImage"; + case OpImageSampleImplicitLod: return "OpImageSampleImplicitLod"; + case OpImageSampleExplicitLod: return "OpImageSampleExplicitLod"; + case OpImageSampleDrefImplicitLod: return "OpImageSampleDrefImplicitLod"; + case OpImageSampleDrefExplicitLod: return "OpImageSampleDrefExplicitLod"; + case OpImageSampleProjImplicitLod: return "OpImageSampleProjImplicitLod"; + case OpImageSampleProjExplicitLod: return "OpImageSampleProjExplicitLod"; + case OpImageSampleProjDrefImplicitLod: return "OpImageSampleProjDrefImplicitLod"; + case OpImageSampleProjDrefExplicitLod: return "OpImageSampleProjDrefExplicitLod"; + case OpImageFetch: return "OpImageFetch"; + case OpImageGather: return "OpImageGather"; + case OpImageDrefGather: return "OpImageDrefGather"; + case OpImageRead: return "OpImageRead"; + case OpImageWrite: return "OpImageWrite"; + case OpImage: return "OpImage"; + case OpImageQueryFormat: return "OpImageQueryFormat"; + case OpImageQueryOrder: return "OpImageQueryOrder"; + case OpImageQuerySizeLod: return "OpImageQuerySizeLod"; + case OpImageQuerySize: return "OpImageQuerySize"; + case OpImageQueryLod: return "OpImageQueryLod"; + case OpImageQueryLevels: return "OpImageQueryLevels"; + case OpImageQuerySamples: return "OpImageQuerySamples"; + case OpConvertFToU: return "OpConvertFToU"; + case OpConvertFToS: return "OpConvertFToS"; + case OpConvertSToF: return "OpConvertSToF"; + case OpConvertUToF: return "OpConvertUToF"; + case OpUConvert: return "OpUConvert"; + case OpSConvert: return "OpSConvert"; + case OpFConvert: return "OpFConvert"; + case OpQuantizeToF16: return "OpQuantizeToF16"; + case OpConvertPtrToU: return "OpConvertPtrToU"; + case OpSatConvertSToU: return "OpSatConvertSToU"; + case OpSatConvertUToS: return "OpSatConvertUToS"; + case OpConvertUToPtr: return "OpConvertUToPtr"; + case OpPtrCastToGeneric: return "OpPtrCastToGeneric"; + case OpGenericCastToPtr: return "OpGenericCastToPtr"; + case OpGenericCastToPtrExplicit: return "OpGenericCastToPtrExplicit"; + case OpBitcast: return "OpBitcast"; + case OpSNegate: return "OpSNegate"; + case OpFNegate: return "OpFNegate"; + case OpIAdd: return "OpIAdd"; + case OpFAdd: return "OpFAdd"; + case OpISub: return "OpISub"; + case OpFSub: return "OpFSub"; + case OpIMul: return "OpIMul"; + case OpFMul: return "OpFMul"; + case OpUDiv: return "OpUDiv"; + case OpSDiv: return "OpSDiv"; + case OpFDiv: return "OpFDiv"; + case OpUMod: return "OpUMod"; + case OpSRem: return "OpSRem"; + case OpSMod: return "OpSMod"; + case OpFRem: return "OpFRem"; + case OpFMod: return "OpFMod"; + case OpVectorTimesScalar: return "OpVectorTimesScalar"; + case OpMatrixTimesScalar: return "OpMatrixTimesScalar"; + case OpVectorTimesMatrix: return "OpVectorTimesMatrix"; + case OpMatrixTimesVector: return "OpMatrixTimesVector"; + case OpMatrixTimesMatrix: return "OpMatrixTimesMatrix"; + case OpOuterProduct: return "OpOuterProduct"; + case OpDot: return "OpDot"; + case OpIAddCarry: return "OpIAddCarry"; + case OpISubBorrow: return "OpISubBorrow"; + case OpUMulExtended: return "OpUMulExtended"; + case OpSMulExtended: return "OpSMulExtended"; + case OpAny: return "OpAny"; + case OpAll: return "OpAll"; + case OpIsNan: return "OpIsNan"; + case OpIsInf: return "OpIsInf"; + case OpIsFinite: return "OpIsFinite"; + case OpIsNormal: return "OpIsNormal"; + case OpSignBitSet: return "OpSignBitSet"; + case OpLessOrGreater: return "OpLessOrGreater"; + case OpOrdered: return "OpOrdered"; + case OpUnordered: return "OpUnordered"; + case OpLogicalEqual: return "OpLogicalEqual"; + case OpLogicalNotEqual: return "OpLogicalNotEqual"; + case OpLogicalOr: return "OpLogicalOr"; + case OpLogicalAnd: return "OpLogicalAnd"; + case OpLogicalNot: return "OpLogicalNot"; + case OpSelect: return "OpSelect"; + case OpIEqual: return "OpIEqual"; + case OpINotEqual: return "OpINotEqual"; + case OpUGreaterThan: return "OpUGreaterThan"; + case OpSGreaterThan: return "OpSGreaterThan"; + case OpUGreaterThanEqual: return "OpUGreaterThanEqual"; + case OpSGreaterThanEqual: return "OpSGreaterThanEqual"; + case OpULessThan: return "OpULessThan"; + case OpSLessThan: return "OpSLessThan"; + case OpULessThanEqual: return "OpULessThanEqual"; + case OpSLessThanEqual: return "OpSLessThanEqual"; + case OpFOrdEqual: return "OpFOrdEqual"; + case OpFUnordEqual: return "OpFUnordEqual"; + case OpFOrdNotEqual: return "OpFOrdNotEqual"; + case OpFUnordNotEqual: return "OpFUnordNotEqual"; + case OpFOrdLessThan: return "OpFOrdLessThan"; + case OpFUnordLessThan: return "OpFUnordLessThan"; + case OpFOrdGreaterThan: return "OpFOrdGreaterThan"; + case OpFUnordGreaterThan: return "OpFUnordGreaterThan"; + case OpFOrdLessThanEqual: return "OpFOrdLessThanEqual"; + case OpFUnordLessThanEqual: return "OpFUnordLessThanEqual"; + case OpFOrdGreaterThanEqual: return "OpFOrdGreaterThanEqual"; + case OpFUnordGreaterThanEqual: return "OpFUnordGreaterThanEqual"; + case OpShiftRightLogical: return "OpShiftRightLogical"; + case OpShiftRightArithmetic: return "OpShiftRightArithmetic"; + case OpShiftLeftLogical: return "OpShiftLeftLogical"; + case OpBitwiseOr: return "OpBitwiseOr"; + case OpBitwiseXor: return "OpBitwiseXor"; + case OpBitwiseAnd: return "OpBitwiseAnd"; + case OpNot: return "OpNot"; + case OpBitFieldInsert: return "OpBitFieldInsert"; + case OpBitFieldSExtract: return "OpBitFieldSExtract"; + case OpBitFieldUExtract: return "OpBitFieldUExtract"; + case OpBitReverse: return "OpBitReverse"; + case OpBitCount: return "OpBitCount"; + case OpDPdx: return "OpDPdx"; + case OpDPdy: return "OpDPdy"; + case OpFwidth: return "OpFwidth"; + case OpDPdxFine: return "OpDPdxFine"; + case OpDPdyFine: return "OpDPdyFine"; + case OpFwidthFine: return "OpFwidthFine"; + case OpDPdxCoarse: return "OpDPdxCoarse"; + case OpDPdyCoarse: return "OpDPdyCoarse"; + case OpFwidthCoarse: return "OpFwidthCoarse"; + case OpEmitVertex: return "OpEmitVertex"; + case OpEndPrimitive: return "OpEndPrimitive"; + case OpEmitStreamVertex: return "OpEmitStreamVertex"; + case OpEndStreamPrimitive: return "OpEndStreamPrimitive"; + case OpControlBarrier: return "OpControlBarrier"; + case OpMemoryBarrier: return "OpMemoryBarrier"; + case OpAtomicLoad: return "OpAtomicLoad"; + case OpAtomicStore: return "OpAtomicStore"; + case OpAtomicExchange: return "OpAtomicExchange"; + case OpAtomicCompareExchange: return "OpAtomicCompareExchange"; + case OpAtomicCompareExchangeWeak: return "OpAtomicCompareExchangeWeak"; + case OpAtomicIIncrement: return "OpAtomicIIncrement"; + case OpAtomicIDecrement: return "OpAtomicIDecrement"; + case OpAtomicIAdd: return "OpAtomicIAdd"; + case OpAtomicISub: return "OpAtomicISub"; + case OpAtomicSMin: return "OpAtomicSMin"; + case OpAtomicUMin: return "OpAtomicUMin"; + case OpAtomicSMax: return "OpAtomicSMax"; + case OpAtomicUMax: return "OpAtomicUMax"; + case OpAtomicAnd: return "OpAtomicAnd"; + case OpAtomicOr: return "OpAtomicOr"; + case OpAtomicXor: return "OpAtomicXor"; + case OpPhi: return "OpPhi"; + case OpLoopMerge: return "OpLoopMerge"; + case OpSelectionMerge: return "OpSelectionMerge"; + case OpLabel: return "OpLabel"; + case OpBranch: return "OpBranch"; + case OpBranchConditional: return "OpBranchConditional"; + case OpSwitch: return "OpSwitch"; + case OpKill: return "OpKill"; + case OpReturn: return "OpReturn"; + case OpReturnValue: return "OpReturnValue"; + case OpUnreachable: return "OpUnreachable"; + case OpLifetimeStart: return "OpLifetimeStart"; + case OpLifetimeStop: return "OpLifetimeStop"; + case OpGroupAsyncCopy: return "OpGroupAsyncCopy"; + case OpGroupWaitEvents: return "OpGroupWaitEvents"; + case OpGroupAll: return "OpGroupAll"; + case OpGroupAny: return "OpGroupAny"; + case OpGroupBroadcast: return "OpGroupBroadcast"; + case OpGroupIAdd: return "OpGroupIAdd"; + case OpGroupFAdd: return "OpGroupFAdd"; + case OpGroupFMin: return "OpGroupFMin"; + case OpGroupUMin: return "OpGroupUMin"; + case OpGroupSMin: return "OpGroupSMin"; + case OpGroupFMax: return "OpGroupFMax"; + case OpGroupUMax: return "OpGroupUMax"; + case OpGroupSMax: return "OpGroupSMax"; + case OpReadPipe: return "OpReadPipe"; + case OpWritePipe: return "OpWritePipe"; + case OpReservedReadPipe: return "OpReservedReadPipe"; + case OpReservedWritePipe: return "OpReservedWritePipe"; + case OpReserveReadPipePackets: return "OpReserveReadPipePackets"; + case OpReserveWritePipePackets: return "OpReserveWritePipePackets"; + case OpCommitReadPipe: return "OpCommitReadPipe"; + case OpCommitWritePipe: return "OpCommitWritePipe"; + case OpIsValidReserveId: return "OpIsValidReserveId"; + case OpGetNumPipePackets: return "OpGetNumPipePackets"; + case OpGetMaxPipePackets: return "OpGetMaxPipePackets"; + case OpGroupReserveReadPipePackets: return "OpGroupReserveReadPipePackets"; + case OpGroupReserveWritePipePackets: return "OpGroupReserveWritePipePackets"; + case OpGroupCommitReadPipe: return "OpGroupCommitReadPipe"; + case OpGroupCommitWritePipe: return "OpGroupCommitWritePipe"; + case OpEnqueueMarker: return "OpEnqueueMarker"; + case OpEnqueueKernel: return "OpEnqueueKernel"; + case OpGetKernelNDrangeSubGroupCount: return "OpGetKernelNDrangeSubGroupCount"; + case OpGetKernelNDrangeMaxSubGroupSize: return "OpGetKernelNDrangeMaxSubGroupSize"; + case OpGetKernelWorkGroupSize: return "OpGetKernelWorkGroupSize"; + case OpGetKernelPreferredWorkGroupSizeMultiple: return "OpGetKernelPreferredWorkGroupSizeMultiple"; + case OpRetainEvent: return "OpRetainEvent"; + case OpReleaseEvent: return "OpReleaseEvent"; + case OpCreateUserEvent: return "OpCreateUserEvent"; + case OpIsValidEvent: return "OpIsValidEvent"; + case OpSetUserEventStatus: return "OpSetUserEventStatus"; + case OpCaptureEventProfilingInfo: return "OpCaptureEventProfilingInfo"; + case OpGetDefaultQueue: return "OpGetDefaultQueue"; + case OpBuildNDRange: return "OpBuildNDRange"; + case OpImageSparseSampleImplicitLod: return "OpImageSparseSampleImplicitLod"; + case OpImageSparseSampleExplicitLod: return "OpImageSparseSampleExplicitLod"; + case OpImageSparseSampleDrefImplicitLod: return "OpImageSparseSampleDrefImplicitLod"; + case OpImageSparseSampleDrefExplicitLod: return "OpImageSparseSampleDrefExplicitLod"; + case OpImageSparseSampleProjImplicitLod: return "OpImageSparseSampleProjImplicitLod"; + case OpImageSparseSampleProjExplicitLod: return "OpImageSparseSampleProjExplicitLod"; + case OpImageSparseSampleProjDrefImplicitLod: return "OpImageSparseSampleProjDrefImplicitLod"; + case OpImageSparseSampleProjDrefExplicitLod: return "OpImageSparseSampleProjDrefExplicitLod"; + case OpImageSparseFetch: return "OpImageSparseFetch"; + case OpImageSparseGather: return "OpImageSparseGather"; + case OpImageSparseDrefGather: return "OpImageSparseDrefGather"; + case OpImageSparseTexelsResident: return "OpImageSparseTexelsResident"; + case OpNoLine: return "OpNoLine"; + case OpAtomicFlagTestAndSet: return "OpAtomicFlagTestAndSet"; + case OpAtomicFlagClear: return "OpAtomicFlagClear"; + case OpImageSparseRead: return "OpImageSparseRead"; + case OpSizeOf: return "OpSizeOf"; + case OpTypePipeStorage: return "OpTypePipeStorage"; + case OpConstantPipeStorage: return "OpConstantPipeStorage"; + case OpCreatePipeFromPipeStorage: return "OpCreatePipeFromPipeStorage"; + case OpGetKernelLocalSizeForSubgroupCount: return "OpGetKernelLocalSizeForSubgroupCount"; + case OpGetKernelMaxNumSubgroups: return "OpGetKernelMaxNumSubgroups"; + case OpTypeNamedBarrier: return "OpTypeNamedBarrier"; + case OpNamedBarrierInitialize: return "OpNamedBarrierInitialize"; + case OpMemoryNamedBarrier: return "OpMemoryNamedBarrier"; + case OpModuleProcessed: return "OpModuleProcessed"; + case OpExecutionModeId: return "OpExecutionModeId"; + case OpDecorateId: return "OpDecorateId"; + case OpGroupNonUniformElect: return "OpGroupNonUniformElect"; + case OpGroupNonUniformAll: return "OpGroupNonUniformAll"; + case OpGroupNonUniformAny: return "OpGroupNonUniformAny"; + case OpGroupNonUniformAllEqual: return "OpGroupNonUniformAllEqual"; + case OpGroupNonUniformBroadcast: return "OpGroupNonUniformBroadcast"; + case OpGroupNonUniformBroadcastFirst: return "OpGroupNonUniformBroadcastFirst"; + case OpGroupNonUniformBallot: return "OpGroupNonUniformBallot"; + case OpGroupNonUniformInverseBallot: return "OpGroupNonUniformInverseBallot"; + case OpGroupNonUniformBallotBitExtract: return "OpGroupNonUniformBallotBitExtract"; + case OpGroupNonUniformBallotBitCount: return "OpGroupNonUniformBallotBitCount"; + case OpGroupNonUniformBallotFindLSB: return "OpGroupNonUniformBallotFindLSB"; + case OpGroupNonUniformBallotFindMSB: return "OpGroupNonUniformBallotFindMSB"; + case OpGroupNonUniformShuffle: return "OpGroupNonUniformShuffle"; + case OpGroupNonUniformShuffleXor: return "OpGroupNonUniformShuffleXor"; + case OpGroupNonUniformShuffleUp: return "OpGroupNonUniformShuffleUp"; + case OpGroupNonUniformShuffleDown: return "OpGroupNonUniformShuffleDown"; + case OpGroupNonUniformIAdd: return "OpGroupNonUniformIAdd"; + case OpGroupNonUniformFAdd: return "OpGroupNonUniformFAdd"; + case OpGroupNonUniformIMul: return "OpGroupNonUniformIMul"; + case OpGroupNonUniformFMul: return "OpGroupNonUniformFMul"; + case OpGroupNonUniformSMin: return "OpGroupNonUniformSMin"; + case OpGroupNonUniformUMin: return "OpGroupNonUniformUMin"; + case OpGroupNonUniformFMin: return "OpGroupNonUniformFMin"; + case OpGroupNonUniformSMax: return "OpGroupNonUniformSMax"; + case OpGroupNonUniformUMax: return "OpGroupNonUniformUMax"; + case OpGroupNonUniformFMax: return "OpGroupNonUniformFMax"; + case OpGroupNonUniformBitwiseAnd: return "OpGroupNonUniformBitwiseAnd"; + case OpGroupNonUniformBitwiseOr: return "OpGroupNonUniformBitwiseOr"; + case OpGroupNonUniformBitwiseXor: return "OpGroupNonUniformBitwiseXor"; + case OpGroupNonUniformLogicalAnd: return "OpGroupNonUniformLogicalAnd"; + case OpGroupNonUniformLogicalOr: return "OpGroupNonUniformLogicalOr"; + case OpGroupNonUniformLogicalXor: return "OpGroupNonUniformLogicalXor"; + case OpGroupNonUniformQuadBroadcast: return "OpGroupNonUniformQuadBroadcast"; + case OpGroupNonUniformQuadSwap: return "OpGroupNonUniformQuadSwap"; + case OpCopyLogical: return "OpCopyLogical"; + case OpPtrEqual: return "OpPtrEqual"; + case OpPtrNotEqual: return "OpPtrNotEqual"; + case OpPtrDiff: return "OpPtrDiff"; + case OpColorAttachmentReadEXT: return "OpColorAttachmentReadEXT"; + case OpDepthAttachmentReadEXT: return "OpDepthAttachmentReadEXT"; + case OpStencilAttachmentReadEXT: return "OpStencilAttachmentReadEXT"; + case OpTerminateInvocation: return "OpTerminateInvocation"; + case OpTypeUntypedPointerKHR: return "OpTypeUntypedPointerKHR"; + case OpUntypedVariableKHR: return "OpUntypedVariableKHR"; + case OpUntypedAccessChainKHR: return "OpUntypedAccessChainKHR"; + case OpUntypedInBoundsAccessChainKHR: return "OpUntypedInBoundsAccessChainKHR"; + case OpSubgroupBallotKHR: return "OpSubgroupBallotKHR"; + case OpSubgroupFirstInvocationKHR: return "OpSubgroupFirstInvocationKHR"; + case OpUntypedPtrAccessChainKHR: return "OpUntypedPtrAccessChainKHR"; + case OpUntypedInBoundsPtrAccessChainKHR: return "OpUntypedInBoundsPtrAccessChainKHR"; + case OpUntypedArrayLengthKHR: return "OpUntypedArrayLengthKHR"; + case OpUntypedPrefetchKHR: return "OpUntypedPrefetchKHR"; + case OpSubgroupAllKHR: return "OpSubgroupAllKHR"; + case OpSubgroupAnyKHR: return "OpSubgroupAnyKHR"; + case OpSubgroupAllEqualKHR: return "OpSubgroupAllEqualKHR"; + case OpGroupNonUniformRotateKHR: return "OpGroupNonUniformRotateKHR"; + case OpSubgroupReadInvocationKHR: return "OpSubgroupReadInvocationKHR"; + case OpExtInstWithForwardRefsKHR: return "OpExtInstWithForwardRefsKHR"; + case OpTraceRayKHR: return "OpTraceRayKHR"; + case OpExecuteCallableKHR: return "OpExecuteCallableKHR"; + case OpConvertUToAccelerationStructureKHR: return "OpConvertUToAccelerationStructureKHR"; + case OpIgnoreIntersectionKHR: return "OpIgnoreIntersectionKHR"; + case OpTerminateRayKHR: return "OpTerminateRayKHR"; + case OpSDot: return "OpSDot"; + case OpUDot: return "OpUDot"; + case OpSUDot: return "OpSUDot"; + case OpSDotAccSat: return "OpSDotAccSat"; + case OpUDotAccSat: return "OpUDotAccSat"; + case OpSUDotAccSat: return "OpSUDotAccSat"; + case OpTypeCooperativeMatrixKHR: return "OpTypeCooperativeMatrixKHR"; + case OpCooperativeMatrixLoadKHR: return "OpCooperativeMatrixLoadKHR"; + case OpCooperativeMatrixStoreKHR: return "OpCooperativeMatrixStoreKHR"; + case OpCooperativeMatrixMulAddKHR: return "OpCooperativeMatrixMulAddKHR"; + case OpCooperativeMatrixLengthKHR: return "OpCooperativeMatrixLengthKHR"; + case OpConstantCompositeReplicateEXT: return "OpConstantCompositeReplicateEXT"; + case OpSpecConstantCompositeReplicateEXT: return "OpSpecConstantCompositeReplicateEXT"; + case OpCompositeConstructReplicateEXT: return "OpCompositeConstructReplicateEXT"; + case OpTypeRayQueryKHR: return "OpTypeRayQueryKHR"; + case OpRayQueryInitializeKHR: return "OpRayQueryInitializeKHR"; + case OpRayQueryTerminateKHR: return "OpRayQueryTerminateKHR"; + case OpRayQueryGenerateIntersectionKHR: return "OpRayQueryGenerateIntersectionKHR"; + case OpRayQueryConfirmIntersectionKHR: return "OpRayQueryConfirmIntersectionKHR"; + case OpRayQueryProceedKHR: return "OpRayQueryProceedKHR"; + case OpRayQueryGetIntersectionTypeKHR: return "OpRayQueryGetIntersectionTypeKHR"; + case OpImageSampleWeightedQCOM: return "OpImageSampleWeightedQCOM"; + case OpImageBoxFilterQCOM: return "OpImageBoxFilterQCOM"; + case OpImageBlockMatchSSDQCOM: return "OpImageBlockMatchSSDQCOM"; + case OpImageBlockMatchSADQCOM: return "OpImageBlockMatchSADQCOM"; + case OpImageBlockMatchWindowSSDQCOM: return "OpImageBlockMatchWindowSSDQCOM"; + case OpImageBlockMatchWindowSADQCOM: return "OpImageBlockMatchWindowSADQCOM"; + case OpImageBlockMatchGatherSSDQCOM: return "OpImageBlockMatchGatherSSDQCOM"; + case OpImageBlockMatchGatherSADQCOM: return "OpImageBlockMatchGatherSADQCOM"; + case OpGroupIAddNonUniformAMD: return "OpGroupIAddNonUniformAMD"; + case OpGroupFAddNonUniformAMD: return "OpGroupFAddNonUniformAMD"; + case OpGroupFMinNonUniformAMD: return "OpGroupFMinNonUniformAMD"; + case OpGroupUMinNonUniformAMD: return "OpGroupUMinNonUniformAMD"; + case OpGroupSMinNonUniformAMD: return "OpGroupSMinNonUniformAMD"; + case OpGroupFMaxNonUniformAMD: return "OpGroupFMaxNonUniformAMD"; + case OpGroupUMaxNonUniformAMD: return "OpGroupUMaxNonUniformAMD"; + case OpGroupSMaxNonUniformAMD: return "OpGroupSMaxNonUniformAMD"; + case OpFragmentMaskFetchAMD: return "OpFragmentMaskFetchAMD"; + case OpFragmentFetchAMD: return "OpFragmentFetchAMD"; + case OpReadClockKHR: return "OpReadClockKHR"; + case OpAllocateNodePayloadsAMDX: return "OpAllocateNodePayloadsAMDX"; + case OpEnqueueNodePayloadsAMDX: return "OpEnqueueNodePayloadsAMDX"; + case OpTypeNodePayloadArrayAMDX: return "OpTypeNodePayloadArrayAMDX"; + case OpFinishWritingNodePayloadAMDX: return "OpFinishWritingNodePayloadAMDX"; + case OpNodePayloadArrayLengthAMDX: return "OpNodePayloadArrayLengthAMDX"; + case OpIsNodePayloadValidAMDX: return "OpIsNodePayloadValidAMDX"; + case OpConstantStringAMDX: return "OpConstantStringAMDX"; + case OpSpecConstantStringAMDX: return "OpSpecConstantStringAMDX"; + case OpGroupNonUniformQuadAllKHR: return "OpGroupNonUniformQuadAllKHR"; + case OpGroupNonUniformQuadAnyKHR: return "OpGroupNonUniformQuadAnyKHR"; + case OpHitObjectRecordHitMotionNV: return "OpHitObjectRecordHitMotionNV"; + case OpHitObjectRecordHitWithIndexMotionNV: return "OpHitObjectRecordHitWithIndexMotionNV"; + case OpHitObjectRecordMissMotionNV: return "OpHitObjectRecordMissMotionNV"; + case OpHitObjectGetWorldToObjectNV: return "OpHitObjectGetWorldToObjectNV"; + case OpHitObjectGetObjectToWorldNV: return "OpHitObjectGetObjectToWorldNV"; + case OpHitObjectGetObjectRayDirectionNV: return "OpHitObjectGetObjectRayDirectionNV"; + case OpHitObjectGetObjectRayOriginNV: return "OpHitObjectGetObjectRayOriginNV"; + case OpHitObjectTraceRayMotionNV: return "OpHitObjectTraceRayMotionNV"; + case OpHitObjectGetShaderRecordBufferHandleNV: return "OpHitObjectGetShaderRecordBufferHandleNV"; + case OpHitObjectGetShaderBindingTableRecordIndexNV: return "OpHitObjectGetShaderBindingTableRecordIndexNV"; + case OpHitObjectRecordEmptyNV: return "OpHitObjectRecordEmptyNV"; + case OpHitObjectTraceRayNV: return "OpHitObjectTraceRayNV"; + case OpHitObjectRecordHitNV: return "OpHitObjectRecordHitNV"; + case OpHitObjectRecordHitWithIndexNV: return "OpHitObjectRecordHitWithIndexNV"; + case OpHitObjectRecordMissNV: return "OpHitObjectRecordMissNV"; + case OpHitObjectExecuteShaderNV: return "OpHitObjectExecuteShaderNV"; + case OpHitObjectGetCurrentTimeNV: return "OpHitObjectGetCurrentTimeNV"; + case OpHitObjectGetAttributesNV: return "OpHitObjectGetAttributesNV"; + case OpHitObjectGetHitKindNV: return "OpHitObjectGetHitKindNV"; + case OpHitObjectGetPrimitiveIndexNV: return "OpHitObjectGetPrimitiveIndexNV"; + case OpHitObjectGetGeometryIndexNV: return "OpHitObjectGetGeometryIndexNV"; + case OpHitObjectGetInstanceIdNV: return "OpHitObjectGetInstanceIdNV"; + case OpHitObjectGetInstanceCustomIndexNV: return "OpHitObjectGetInstanceCustomIndexNV"; + case OpHitObjectGetWorldRayDirectionNV: return "OpHitObjectGetWorldRayDirectionNV"; + case OpHitObjectGetWorldRayOriginNV: return "OpHitObjectGetWorldRayOriginNV"; + case OpHitObjectGetRayTMaxNV: return "OpHitObjectGetRayTMaxNV"; + case OpHitObjectGetRayTMinNV: return "OpHitObjectGetRayTMinNV"; + case OpHitObjectIsEmptyNV: return "OpHitObjectIsEmptyNV"; + case OpHitObjectIsHitNV: return "OpHitObjectIsHitNV"; + case OpHitObjectIsMissNV: return "OpHitObjectIsMissNV"; + case OpReorderThreadWithHitObjectNV: return "OpReorderThreadWithHitObjectNV"; + case OpReorderThreadWithHintNV: return "OpReorderThreadWithHintNV"; + case OpTypeHitObjectNV: return "OpTypeHitObjectNV"; + case OpImageSampleFootprintNV: return "OpImageSampleFootprintNV"; + case OpTypeCooperativeVectorNV: return "OpTypeCooperativeVectorNV"; + case OpCooperativeVectorMatrixMulNV: return "OpCooperativeVectorMatrixMulNV"; + case OpCooperativeVectorOuterProductAccumulateNV: return "OpCooperativeVectorOuterProductAccumulateNV"; + case OpCooperativeVectorReduceSumAccumulateNV: return "OpCooperativeVectorReduceSumAccumulateNV"; + case OpCooperativeVectorMatrixMulAddNV: return "OpCooperativeVectorMatrixMulAddNV"; + case OpCooperativeMatrixConvertNV: return "OpCooperativeMatrixConvertNV"; + case OpEmitMeshTasksEXT: return "OpEmitMeshTasksEXT"; + case OpSetMeshOutputsEXT: return "OpSetMeshOutputsEXT"; + case OpGroupNonUniformPartitionNV: return "OpGroupNonUniformPartitionNV"; + case OpWritePackedPrimitiveIndices4x8NV: return "OpWritePackedPrimitiveIndices4x8NV"; + case OpFetchMicroTriangleVertexPositionNV: return "OpFetchMicroTriangleVertexPositionNV"; + case OpFetchMicroTriangleVertexBarycentricNV: return "OpFetchMicroTriangleVertexBarycentricNV"; + case OpCooperativeVectorLoadNV: return "OpCooperativeVectorLoadNV"; + case OpCooperativeVectorStoreNV: return "OpCooperativeVectorStoreNV"; + case OpReportIntersectionKHR: return "OpReportIntersectionKHR"; + case OpIgnoreIntersectionNV: return "OpIgnoreIntersectionNV"; + case OpTerminateRayNV: return "OpTerminateRayNV"; + case OpTraceNV: return "OpTraceNV"; + case OpTraceMotionNV: return "OpTraceMotionNV"; + case OpTraceRayMotionNV: return "OpTraceRayMotionNV"; + case OpRayQueryGetIntersectionTriangleVertexPositionsKHR: return "OpRayQueryGetIntersectionTriangleVertexPositionsKHR"; + case OpTypeAccelerationStructureKHR: return "OpTypeAccelerationStructureKHR"; + case OpExecuteCallableNV: return "OpExecuteCallableNV"; + case OpRayQueryGetClusterIdNV: return "OpRayQueryGetClusterIdNV"; + case OpHitObjectGetClusterIdNV: return "OpHitObjectGetClusterIdNV"; + case OpTypeCooperativeMatrixNV: return "OpTypeCooperativeMatrixNV"; + case OpCooperativeMatrixLoadNV: return "OpCooperativeMatrixLoadNV"; + case OpCooperativeMatrixStoreNV: return "OpCooperativeMatrixStoreNV"; + case OpCooperativeMatrixMulAddNV: return "OpCooperativeMatrixMulAddNV"; + case OpCooperativeMatrixLengthNV: return "OpCooperativeMatrixLengthNV"; + case OpBeginInvocationInterlockEXT: return "OpBeginInvocationInterlockEXT"; + case OpEndInvocationInterlockEXT: return "OpEndInvocationInterlockEXT"; + case OpCooperativeMatrixReduceNV: return "OpCooperativeMatrixReduceNV"; + case OpCooperativeMatrixLoadTensorNV: return "OpCooperativeMatrixLoadTensorNV"; + case OpCooperativeMatrixStoreTensorNV: return "OpCooperativeMatrixStoreTensorNV"; + case OpCooperativeMatrixPerElementOpNV: return "OpCooperativeMatrixPerElementOpNV"; + case OpTypeTensorLayoutNV: return "OpTypeTensorLayoutNV"; + case OpTypeTensorViewNV: return "OpTypeTensorViewNV"; + case OpCreateTensorLayoutNV: return "OpCreateTensorLayoutNV"; + case OpTensorLayoutSetDimensionNV: return "OpTensorLayoutSetDimensionNV"; + case OpTensorLayoutSetStrideNV: return "OpTensorLayoutSetStrideNV"; + case OpTensorLayoutSliceNV: return "OpTensorLayoutSliceNV"; + case OpTensorLayoutSetClampValueNV: return "OpTensorLayoutSetClampValueNV"; + case OpCreateTensorViewNV: return "OpCreateTensorViewNV"; + case OpTensorViewSetDimensionNV: return "OpTensorViewSetDimensionNV"; + case OpTensorViewSetStrideNV: return "OpTensorViewSetStrideNV"; + case OpDemoteToHelperInvocation: return "OpDemoteToHelperInvocation"; + case OpIsHelperInvocationEXT: return "OpIsHelperInvocationEXT"; + case OpTensorViewSetClipNV: return "OpTensorViewSetClipNV"; + case OpTensorLayoutSetBlockSizeNV: return "OpTensorLayoutSetBlockSizeNV"; + case OpCooperativeMatrixTransposeNV: return "OpCooperativeMatrixTransposeNV"; + case OpConvertUToImageNV: return "OpConvertUToImageNV"; + case OpConvertUToSamplerNV: return "OpConvertUToSamplerNV"; + case OpConvertImageToUNV: return "OpConvertImageToUNV"; + case OpConvertSamplerToUNV: return "OpConvertSamplerToUNV"; + case OpConvertUToSampledImageNV: return "OpConvertUToSampledImageNV"; + case OpConvertSampledImageToUNV: return "OpConvertSampledImageToUNV"; + case OpSamplerImageAddressingModeNV: return "OpSamplerImageAddressingModeNV"; + case OpRawAccessChainNV: return "OpRawAccessChainNV"; + case OpRayQueryGetIntersectionSpherePositionNV: return "OpRayQueryGetIntersectionSpherePositionNV"; + case OpRayQueryGetIntersectionSphereRadiusNV: return "OpRayQueryGetIntersectionSphereRadiusNV"; + case OpRayQueryGetIntersectionLSSPositionsNV: return "OpRayQueryGetIntersectionLSSPositionsNV"; + case OpRayQueryGetIntersectionLSSRadiiNV: return "OpRayQueryGetIntersectionLSSRadiiNV"; + case OpRayQueryGetIntersectionLSSHitValueNV: return "OpRayQueryGetIntersectionLSSHitValueNV"; + case OpHitObjectGetSpherePositionNV: return "OpHitObjectGetSpherePositionNV"; + case OpHitObjectGetSphereRadiusNV: return "OpHitObjectGetSphereRadiusNV"; + case OpHitObjectGetLSSPositionsNV: return "OpHitObjectGetLSSPositionsNV"; + case OpHitObjectGetLSSRadiiNV: return "OpHitObjectGetLSSRadiiNV"; + case OpHitObjectIsSphereHitNV: return "OpHitObjectIsSphereHitNV"; + case OpHitObjectIsLSSHitNV: return "OpHitObjectIsLSSHitNV"; + case OpRayQueryIsSphereHitNV: return "OpRayQueryIsSphereHitNV"; + case OpRayQueryIsLSSHitNV: return "OpRayQueryIsLSSHitNV"; + case OpSubgroupShuffleINTEL: return "OpSubgroupShuffleINTEL"; + case OpSubgroupShuffleDownINTEL: return "OpSubgroupShuffleDownINTEL"; + case OpSubgroupShuffleUpINTEL: return "OpSubgroupShuffleUpINTEL"; + case OpSubgroupShuffleXorINTEL: return "OpSubgroupShuffleXorINTEL"; + case OpSubgroupBlockReadINTEL: return "OpSubgroupBlockReadINTEL"; + case OpSubgroupBlockWriteINTEL: return "OpSubgroupBlockWriteINTEL"; + case OpSubgroupImageBlockReadINTEL: return "OpSubgroupImageBlockReadINTEL"; + case OpSubgroupImageBlockWriteINTEL: return "OpSubgroupImageBlockWriteINTEL"; + case OpSubgroupImageMediaBlockReadINTEL: return "OpSubgroupImageMediaBlockReadINTEL"; + case OpSubgroupImageMediaBlockWriteINTEL: return "OpSubgroupImageMediaBlockWriteINTEL"; + case OpUCountLeadingZerosINTEL: return "OpUCountLeadingZerosINTEL"; + case OpUCountTrailingZerosINTEL: return "OpUCountTrailingZerosINTEL"; + case OpAbsISubINTEL: return "OpAbsISubINTEL"; + case OpAbsUSubINTEL: return "OpAbsUSubINTEL"; + case OpIAddSatINTEL: return "OpIAddSatINTEL"; + case OpUAddSatINTEL: return "OpUAddSatINTEL"; + case OpIAverageINTEL: return "OpIAverageINTEL"; + case OpUAverageINTEL: return "OpUAverageINTEL"; + case OpIAverageRoundedINTEL: return "OpIAverageRoundedINTEL"; + case OpUAverageRoundedINTEL: return "OpUAverageRoundedINTEL"; + case OpISubSatINTEL: return "OpISubSatINTEL"; + case OpUSubSatINTEL: return "OpUSubSatINTEL"; + case OpIMul32x16INTEL: return "OpIMul32x16INTEL"; + case OpUMul32x16INTEL: return "OpUMul32x16INTEL"; + case OpConstantFunctionPointerINTEL: return "OpConstantFunctionPointerINTEL"; + case OpFunctionPointerCallINTEL: return "OpFunctionPointerCallINTEL"; + case OpAsmTargetINTEL: return "OpAsmTargetINTEL"; + case OpAsmINTEL: return "OpAsmINTEL"; + case OpAsmCallINTEL: return "OpAsmCallINTEL"; + case OpAtomicFMinEXT: return "OpAtomicFMinEXT"; + case OpAtomicFMaxEXT: return "OpAtomicFMaxEXT"; + case OpAssumeTrueKHR: return "OpAssumeTrueKHR"; + case OpExpectKHR: return "OpExpectKHR"; + case OpDecorateString: return "OpDecorateString"; + case OpMemberDecorateString: return "OpMemberDecorateString"; + case OpVmeImageINTEL: return "OpVmeImageINTEL"; + case OpTypeVmeImageINTEL: return "OpTypeVmeImageINTEL"; + case OpTypeAvcImePayloadINTEL: return "OpTypeAvcImePayloadINTEL"; + case OpTypeAvcRefPayloadINTEL: return "OpTypeAvcRefPayloadINTEL"; + case OpTypeAvcSicPayloadINTEL: return "OpTypeAvcSicPayloadINTEL"; + case OpTypeAvcMcePayloadINTEL: return "OpTypeAvcMcePayloadINTEL"; + case OpTypeAvcMceResultINTEL: return "OpTypeAvcMceResultINTEL"; + case OpTypeAvcImeResultINTEL: return "OpTypeAvcImeResultINTEL"; + case OpTypeAvcImeResultSingleReferenceStreamoutINTEL: return "OpTypeAvcImeResultSingleReferenceStreamoutINTEL"; + case OpTypeAvcImeResultDualReferenceStreamoutINTEL: return "OpTypeAvcImeResultDualReferenceStreamoutINTEL"; + case OpTypeAvcImeSingleReferenceStreaminINTEL: return "OpTypeAvcImeSingleReferenceStreaminINTEL"; + case OpTypeAvcImeDualReferenceStreaminINTEL: return "OpTypeAvcImeDualReferenceStreaminINTEL"; + case OpTypeAvcRefResultINTEL: return "OpTypeAvcRefResultINTEL"; + case OpTypeAvcSicResultINTEL: return "OpTypeAvcSicResultINTEL"; + case OpSubgroupAvcMceGetDefaultInterBaseMultiReferencePenaltyINTEL: return "OpSubgroupAvcMceGetDefaultInterBaseMultiReferencePenaltyINTEL"; + case OpSubgroupAvcMceSetInterBaseMultiReferencePenaltyINTEL: return "OpSubgroupAvcMceSetInterBaseMultiReferencePenaltyINTEL"; + case OpSubgroupAvcMceGetDefaultInterShapePenaltyINTEL: return "OpSubgroupAvcMceGetDefaultInterShapePenaltyINTEL"; + case OpSubgroupAvcMceSetInterShapePenaltyINTEL: return "OpSubgroupAvcMceSetInterShapePenaltyINTEL"; + case OpSubgroupAvcMceGetDefaultInterDirectionPenaltyINTEL: return "OpSubgroupAvcMceGetDefaultInterDirectionPenaltyINTEL"; + case OpSubgroupAvcMceSetInterDirectionPenaltyINTEL: return "OpSubgroupAvcMceSetInterDirectionPenaltyINTEL"; + case OpSubgroupAvcMceGetDefaultIntraLumaShapePenaltyINTEL: return "OpSubgroupAvcMceGetDefaultIntraLumaShapePenaltyINTEL"; + case OpSubgroupAvcMceGetDefaultInterMotionVectorCostTableINTEL: return "OpSubgroupAvcMceGetDefaultInterMotionVectorCostTableINTEL"; + case OpSubgroupAvcMceGetDefaultHighPenaltyCostTableINTEL: return "OpSubgroupAvcMceGetDefaultHighPenaltyCostTableINTEL"; + case OpSubgroupAvcMceGetDefaultMediumPenaltyCostTableINTEL: return "OpSubgroupAvcMceGetDefaultMediumPenaltyCostTableINTEL"; + case OpSubgroupAvcMceGetDefaultLowPenaltyCostTableINTEL: return "OpSubgroupAvcMceGetDefaultLowPenaltyCostTableINTEL"; + case OpSubgroupAvcMceSetMotionVectorCostFunctionINTEL: return "OpSubgroupAvcMceSetMotionVectorCostFunctionINTEL"; + case OpSubgroupAvcMceGetDefaultIntraLumaModePenaltyINTEL: return "OpSubgroupAvcMceGetDefaultIntraLumaModePenaltyINTEL"; + case OpSubgroupAvcMceGetDefaultNonDcLumaIntraPenaltyINTEL: return "OpSubgroupAvcMceGetDefaultNonDcLumaIntraPenaltyINTEL"; + case OpSubgroupAvcMceGetDefaultIntraChromaModeBasePenaltyINTEL: return "OpSubgroupAvcMceGetDefaultIntraChromaModeBasePenaltyINTEL"; + case OpSubgroupAvcMceSetAcOnlyHaarINTEL: return "OpSubgroupAvcMceSetAcOnlyHaarINTEL"; + case OpSubgroupAvcMceSetSourceInterlacedFieldPolarityINTEL: return "OpSubgroupAvcMceSetSourceInterlacedFieldPolarityINTEL"; + case OpSubgroupAvcMceSetSingleReferenceInterlacedFieldPolarityINTEL: return "OpSubgroupAvcMceSetSingleReferenceInterlacedFieldPolarityINTEL"; + case OpSubgroupAvcMceSetDualReferenceInterlacedFieldPolaritiesINTEL: return "OpSubgroupAvcMceSetDualReferenceInterlacedFieldPolaritiesINTEL"; + case OpSubgroupAvcMceConvertToImePayloadINTEL: return "OpSubgroupAvcMceConvertToImePayloadINTEL"; + case OpSubgroupAvcMceConvertToImeResultINTEL: return "OpSubgroupAvcMceConvertToImeResultINTEL"; + case OpSubgroupAvcMceConvertToRefPayloadINTEL: return "OpSubgroupAvcMceConvertToRefPayloadINTEL"; + case OpSubgroupAvcMceConvertToRefResultINTEL: return "OpSubgroupAvcMceConvertToRefResultINTEL"; + case OpSubgroupAvcMceConvertToSicPayloadINTEL: return "OpSubgroupAvcMceConvertToSicPayloadINTEL"; + case OpSubgroupAvcMceConvertToSicResultINTEL: return "OpSubgroupAvcMceConvertToSicResultINTEL"; + case OpSubgroupAvcMceGetMotionVectorsINTEL: return "OpSubgroupAvcMceGetMotionVectorsINTEL"; + case OpSubgroupAvcMceGetInterDistortionsINTEL: return "OpSubgroupAvcMceGetInterDistortionsINTEL"; + case OpSubgroupAvcMceGetBestInterDistortionsINTEL: return "OpSubgroupAvcMceGetBestInterDistortionsINTEL"; + case OpSubgroupAvcMceGetInterMajorShapeINTEL: return "OpSubgroupAvcMceGetInterMajorShapeINTEL"; + case OpSubgroupAvcMceGetInterMinorShapeINTEL: return "OpSubgroupAvcMceGetInterMinorShapeINTEL"; + case OpSubgroupAvcMceGetInterDirectionsINTEL: return "OpSubgroupAvcMceGetInterDirectionsINTEL"; + case OpSubgroupAvcMceGetInterMotionVectorCountINTEL: return "OpSubgroupAvcMceGetInterMotionVectorCountINTEL"; + case OpSubgroupAvcMceGetInterReferenceIdsINTEL: return "OpSubgroupAvcMceGetInterReferenceIdsINTEL"; + case OpSubgroupAvcMceGetInterReferenceInterlacedFieldPolaritiesINTEL: return "OpSubgroupAvcMceGetInterReferenceInterlacedFieldPolaritiesINTEL"; + case OpSubgroupAvcImeInitializeINTEL: return "OpSubgroupAvcImeInitializeINTEL"; + case OpSubgroupAvcImeSetSingleReferenceINTEL: return "OpSubgroupAvcImeSetSingleReferenceINTEL"; + case OpSubgroupAvcImeSetDualReferenceINTEL: return "OpSubgroupAvcImeSetDualReferenceINTEL"; + case OpSubgroupAvcImeRefWindowSizeINTEL: return "OpSubgroupAvcImeRefWindowSizeINTEL"; + case OpSubgroupAvcImeAdjustRefOffsetINTEL: return "OpSubgroupAvcImeAdjustRefOffsetINTEL"; + case OpSubgroupAvcImeConvertToMcePayloadINTEL: return "OpSubgroupAvcImeConvertToMcePayloadINTEL"; + case OpSubgroupAvcImeSetMaxMotionVectorCountINTEL: return "OpSubgroupAvcImeSetMaxMotionVectorCountINTEL"; + case OpSubgroupAvcImeSetUnidirectionalMixDisableINTEL: return "OpSubgroupAvcImeSetUnidirectionalMixDisableINTEL"; + case OpSubgroupAvcImeSetEarlySearchTerminationThresholdINTEL: return "OpSubgroupAvcImeSetEarlySearchTerminationThresholdINTEL"; + case OpSubgroupAvcImeSetWeightedSadINTEL: return "OpSubgroupAvcImeSetWeightedSadINTEL"; + case OpSubgroupAvcImeEvaluateWithSingleReferenceINTEL: return "OpSubgroupAvcImeEvaluateWithSingleReferenceINTEL"; + case OpSubgroupAvcImeEvaluateWithDualReferenceINTEL: return "OpSubgroupAvcImeEvaluateWithDualReferenceINTEL"; + case OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminINTEL: return "OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminINTEL"; + case OpSubgroupAvcImeEvaluateWithDualReferenceStreaminINTEL: return "OpSubgroupAvcImeEvaluateWithDualReferenceStreaminINTEL"; + case OpSubgroupAvcImeEvaluateWithSingleReferenceStreamoutINTEL: return "OpSubgroupAvcImeEvaluateWithSingleReferenceStreamoutINTEL"; + case OpSubgroupAvcImeEvaluateWithDualReferenceStreamoutINTEL: return "OpSubgroupAvcImeEvaluateWithDualReferenceStreamoutINTEL"; + case OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminoutINTEL: return "OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminoutINTEL"; + case OpSubgroupAvcImeEvaluateWithDualReferenceStreaminoutINTEL: return "OpSubgroupAvcImeEvaluateWithDualReferenceStreaminoutINTEL"; + case OpSubgroupAvcImeConvertToMceResultINTEL: return "OpSubgroupAvcImeConvertToMceResultINTEL"; + case OpSubgroupAvcImeGetSingleReferenceStreaminINTEL: return "OpSubgroupAvcImeGetSingleReferenceStreaminINTEL"; + case OpSubgroupAvcImeGetDualReferenceStreaminINTEL: return "OpSubgroupAvcImeGetDualReferenceStreaminINTEL"; + case OpSubgroupAvcImeStripSingleReferenceStreamoutINTEL: return "OpSubgroupAvcImeStripSingleReferenceStreamoutINTEL"; + case OpSubgroupAvcImeStripDualReferenceStreamoutINTEL: return "OpSubgroupAvcImeStripDualReferenceStreamoutINTEL"; + case OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeMotionVectorsINTEL: return "OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeMotionVectorsINTEL"; + case OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeDistortionsINTEL: return "OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeDistortionsINTEL"; + case OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeReferenceIdsINTEL: return "OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeReferenceIdsINTEL"; + case OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeMotionVectorsINTEL: return "OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeMotionVectorsINTEL"; + case OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeDistortionsINTEL: return "OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeDistortionsINTEL"; + case OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeReferenceIdsINTEL: return "OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeReferenceIdsINTEL"; + case OpSubgroupAvcImeGetBorderReachedINTEL: return "OpSubgroupAvcImeGetBorderReachedINTEL"; + case OpSubgroupAvcImeGetTruncatedSearchIndicationINTEL: return "OpSubgroupAvcImeGetTruncatedSearchIndicationINTEL"; + case OpSubgroupAvcImeGetUnidirectionalEarlySearchTerminationINTEL: return "OpSubgroupAvcImeGetUnidirectionalEarlySearchTerminationINTEL"; + case OpSubgroupAvcImeGetWeightingPatternMinimumMotionVectorINTEL: return "OpSubgroupAvcImeGetWeightingPatternMinimumMotionVectorINTEL"; + case OpSubgroupAvcImeGetWeightingPatternMinimumDistortionINTEL: return "OpSubgroupAvcImeGetWeightingPatternMinimumDistortionINTEL"; + case OpSubgroupAvcFmeInitializeINTEL: return "OpSubgroupAvcFmeInitializeINTEL"; + case OpSubgroupAvcBmeInitializeINTEL: return "OpSubgroupAvcBmeInitializeINTEL"; + case OpSubgroupAvcRefConvertToMcePayloadINTEL: return "OpSubgroupAvcRefConvertToMcePayloadINTEL"; + case OpSubgroupAvcRefSetBidirectionalMixDisableINTEL: return "OpSubgroupAvcRefSetBidirectionalMixDisableINTEL"; + case OpSubgroupAvcRefSetBilinearFilterEnableINTEL: return "OpSubgroupAvcRefSetBilinearFilterEnableINTEL"; + case OpSubgroupAvcRefEvaluateWithSingleReferenceINTEL: return "OpSubgroupAvcRefEvaluateWithSingleReferenceINTEL"; + case OpSubgroupAvcRefEvaluateWithDualReferenceINTEL: return "OpSubgroupAvcRefEvaluateWithDualReferenceINTEL"; + case OpSubgroupAvcRefEvaluateWithMultiReferenceINTEL: return "OpSubgroupAvcRefEvaluateWithMultiReferenceINTEL"; + case OpSubgroupAvcRefEvaluateWithMultiReferenceInterlacedINTEL: return "OpSubgroupAvcRefEvaluateWithMultiReferenceInterlacedINTEL"; + case OpSubgroupAvcRefConvertToMceResultINTEL: return "OpSubgroupAvcRefConvertToMceResultINTEL"; + case OpSubgroupAvcSicInitializeINTEL: return "OpSubgroupAvcSicInitializeINTEL"; + case OpSubgroupAvcSicConfigureSkcINTEL: return "OpSubgroupAvcSicConfigureSkcINTEL"; + case OpSubgroupAvcSicConfigureIpeLumaINTEL: return "OpSubgroupAvcSicConfigureIpeLumaINTEL"; + case OpSubgroupAvcSicConfigureIpeLumaChromaINTEL: return "OpSubgroupAvcSicConfigureIpeLumaChromaINTEL"; + case OpSubgroupAvcSicGetMotionVectorMaskINTEL: return "OpSubgroupAvcSicGetMotionVectorMaskINTEL"; + case OpSubgroupAvcSicConvertToMcePayloadINTEL: return "OpSubgroupAvcSicConvertToMcePayloadINTEL"; + case OpSubgroupAvcSicSetIntraLumaShapePenaltyINTEL: return "OpSubgroupAvcSicSetIntraLumaShapePenaltyINTEL"; + case OpSubgroupAvcSicSetIntraLumaModeCostFunctionINTEL: return "OpSubgroupAvcSicSetIntraLumaModeCostFunctionINTEL"; + case OpSubgroupAvcSicSetIntraChromaModeCostFunctionINTEL: return "OpSubgroupAvcSicSetIntraChromaModeCostFunctionINTEL"; + case OpSubgroupAvcSicSetBilinearFilterEnableINTEL: return "OpSubgroupAvcSicSetBilinearFilterEnableINTEL"; + case OpSubgroupAvcSicSetSkcForwardTransformEnableINTEL: return "OpSubgroupAvcSicSetSkcForwardTransformEnableINTEL"; + case OpSubgroupAvcSicSetBlockBasedRawSkipSadINTEL: return "OpSubgroupAvcSicSetBlockBasedRawSkipSadINTEL"; + case OpSubgroupAvcSicEvaluateIpeINTEL: return "OpSubgroupAvcSicEvaluateIpeINTEL"; + case OpSubgroupAvcSicEvaluateWithSingleReferenceINTEL: return "OpSubgroupAvcSicEvaluateWithSingleReferenceINTEL"; + case OpSubgroupAvcSicEvaluateWithDualReferenceINTEL: return "OpSubgroupAvcSicEvaluateWithDualReferenceINTEL"; + case OpSubgroupAvcSicEvaluateWithMultiReferenceINTEL: return "OpSubgroupAvcSicEvaluateWithMultiReferenceINTEL"; + case OpSubgroupAvcSicEvaluateWithMultiReferenceInterlacedINTEL: return "OpSubgroupAvcSicEvaluateWithMultiReferenceInterlacedINTEL"; + case OpSubgroupAvcSicConvertToMceResultINTEL: return "OpSubgroupAvcSicConvertToMceResultINTEL"; + case OpSubgroupAvcSicGetIpeLumaShapeINTEL: return "OpSubgroupAvcSicGetIpeLumaShapeINTEL"; + case OpSubgroupAvcSicGetBestIpeLumaDistortionINTEL: return "OpSubgroupAvcSicGetBestIpeLumaDistortionINTEL"; + case OpSubgroupAvcSicGetBestIpeChromaDistortionINTEL: return "OpSubgroupAvcSicGetBestIpeChromaDistortionINTEL"; + case OpSubgroupAvcSicGetPackedIpeLumaModesINTEL: return "OpSubgroupAvcSicGetPackedIpeLumaModesINTEL"; + case OpSubgroupAvcSicGetIpeChromaModeINTEL: return "OpSubgroupAvcSicGetIpeChromaModeINTEL"; + case OpSubgroupAvcSicGetPackedSkcLumaCountThresholdINTEL: return "OpSubgroupAvcSicGetPackedSkcLumaCountThresholdINTEL"; + case OpSubgroupAvcSicGetPackedSkcLumaSumThresholdINTEL: return "OpSubgroupAvcSicGetPackedSkcLumaSumThresholdINTEL"; + case OpSubgroupAvcSicGetInterRawSadsINTEL: return "OpSubgroupAvcSicGetInterRawSadsINTEL"; + case OpVariableLengthArrayINTEL: return "OpVariableLengthArrayINTEL"; + case OpSaveMemoryINTEL: return "OpSaveMemoryINTEL"; + case OpRestoreMemoryINTEL: return "OpRestoreMemoryINTEL"; + case OpArbitraryFloatSinCosPiINTEL: return "OpArbitraryFloatSinCosPiINTEL"; + case OpArbitraryFloatCastINTEL: return "OpArbitraryFloatCastINTEL"; + case OpArbitraryFloatCastFromIntINTEL: return "OpArbitraryFloatCastFromIntINTEL"; + case OpArbitraryFloatCastToIntINTEL: return "OpArbitraryFloatCastToIntINTEL"; + case OpArbitraryFloatAddINTEL: return "OpArbitraryFloatAddINTEL"; + case OpArbitraryFloatSubINTEL: return "OpArbitraryFloatSubINTEL"; + case OpArbitraryFloatMulINTEL: return "OpArbitraryFloatMulINTEL"; + case OpArbitraryFloatDivINTEL: return "OpArbitraryFloatDivINTEL"; + case OpArbitraryFloatGTINTEL: return "OpArbitraryFloatGTINTEL"; + case OpArbitraryFloatGEINTEL: return "OpArbitraryFloatGEINTEL"; + case OpArbitraryFloatLTINTEL: return "OpArbitraryFloatLTINTEL"; + case OpArbitraryFloatLEINTEL: return "OpArbitraryFloatLEINTEL"; + case OpArbitraryFloatEQINTEL: return "OpArbitraryFloatEQINTEL"; + case OpArbitraryFloatRecipINTEL: return "OpArbitraryFloatRecipINTEL"; + case OpArbitraryFloatRSqrtINTEL: return "OpArbitraryFloatRSqrtINTEL"; + case OpArbitraryFloatCbrtINTEL: return "OpArbitraryFloatCbrtINTEL"; + case OpArbitraryFloatHypotINTEL: return "OpArbitraryFloatHypotINTEL"; + case OpArbitraryFloatSqrtINTEL: return "OpArbitraryFloatSqrtINTEL"; + case OpArbitraryFloatLogINTEL: return "OpArbitraryFloatLogINTEL"; + case OpArbitraryFloatLog2INTEL: return "OpArbitraryFloatLog2INTEL"; + case OpArbitraryFloatLog10INTEL: return "OpArbitraryFloatLog10INTEL"; + case OpArbitraryFloatLog1pINTEL: return "OpArbitraryFloatLog1pINTEL"; + case OpArbitraryFloatExpINTEL: return "OpArbitraryFloatExpINTEL"; + case OpArbitraryFloatExp2INTEL: return "OpArbitraryFloatExp2INTEL"; + case OpArbitraryFloatExp10INTEL: return "OpArbitraryFloatExp10INTEL"; + case OpArbitraryFloatExpm1INTEL: return "OpArbitraryFloatExpm1INTEL"; + case OpArbitraryFloatSinINTEL: return "OpArbitraryFloatSinINTEL"; + case OpArbitraryFloatCosINTEL: return "OpArbitraryFloatCosINTEL"; + case OpArbitraryFloatSinCosINTEL: return "OpArbitraryFloatSinCosINTEL"; + case OpArbitraryFloatSinPiINTEL: return "OpArbitraryFloatSinPiINTEL"; + case OpArbitraryFloatCosPiINTEL: return "OpArbitraryFloatCosPiINTEL"; + case OpArbitraryFloatASinINTEL: return "OpArbitraryFloatASinINTEL"; + case OpArbitraryFloatASinPiINTEL: return "OpArbitraryFloatASinPiINTEL"; + case OpArbitraryFloatACosINTEL: return "OpArbitraryFloatACosINTEL"; + case OpArbitraryFloatACosPiINTEL: return "OpArbitraryFloatACosPiINTEL"; + case OpArbitraryFloatATanINTEL: return "OpArbitraryFloatATanINTEL"; + case OpArbitraryFloatATanPiINTEL: return "OpArbitraryFloatATanPiINTEL"; + case OpArbitraryFloatATan2INTEL: return "OpArbitraryFloatATan2INTEL"; + case OpArbitraryFloatPowINTEL: return "OpArbitraryFloatPowINTEL"; + case OpArbitraryFloatPowRINTEL: return "OpArbitraryFloatPowRINTEL"; + case OpArbitraryFloatPowNINTEL: return "OpArbitraryFloatPowNINTEL"; + case OpLoopControlINTEL: return "OpLoopControlINTEL"; + case OpAliasDomainDeclINTEL: return "OpAliasDomainDeclINTEL"; + case OpAliasScopeDeclINTEL: return "OpAliasScopeDeclINTEL"; + case OpAliasScopeListDeclINTEL: return "OpAliasScopeListDeclINTEL"; + case OpFixedSqrtINTEL: return "OpFixedSqrtINTEL"; + case OpFixedRecipINTEL: return "OpFixedRecipINTEL"; + case OpFixedRsqrtINTEL: return "OpFixedRsqrtINTEL"; + case OpFixedSinINTEL: return "OpFixedSinINTEL"; + case OpFixedCosINTEL: return "OpFixedCosINTEL"; + case OpFixedSinCosINTEL: return "OpFixedSinCosINTEL"; + case OpFixedSinPiINTEL: return "OpFixedSinPiINTEL"; + case OpFixedCosPiINTEL: return "OpFixedCosPiINTEL"; + case OpFixedSinCosPiINTEL: return "OpFixedSinCosPiINTEL"; + case OpFixedLogINTEL: return "OpFixedLogINTEL"; + case OpFixedExpINTEL: return "OpFixedExpINTEL"; + case OpPtrCastToCrossWorkgroupINTEL: return "OpPtrCastToCrossWorkgroupINTEL"; + case OpCrossWorkgroupCastToPtrINTEL: return "OpCrossWorkgroupCastToPtrINTEL"; + case OpReadPipeBlockingINTEL: return "OpReadPipeBlockingINTEL"; + case OpWritePipeBlockingINTEL: return "OpWritePipeBlockingINTEL"; + case OpFPGARegINTEL: return "OpFPGARegINTEL"; + case OpRayQueryGetRayTMinKHR: return "OpRayQueryGetRayTMinKHR"; + case OpRayQueryGetRayFlagsKHR: return "OpRayQueryGetRayFlagsKHR"; + case OpRayQueryGetIntersectionTKHR: return "OpRayQueryGetIntersectionTKHR"; + case OpRayQueryGetIntersectionInstanceCustomIndexKHR: return "OpRayQueryGetIntersectionInstanceCustomIndexKHR"; + case OpRayQueryGetIntersectionInstanceIdKHR: return "OpRayQueryGetIntersectionInstanceIdKHR"; + case OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR: return "OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR"; + case OpRayQueryGetIntersectionGeometryIndexKHR: return "OpRayQueryGetIntersectionGeometryIndexKHR"; + case OpRayQueryGetIntersectionPrimitiveIndexKHR: return "OpRayQueryGetIntersectionPrimitiveIndexKHR"; + case OpRayQueryGetIntersectionBarycentricsKHR: return "OpRayQueryGetIntersectionBarycentricsKHR"; + case OpRayQueryGetIntersectionFrontFaceKHR: return "OpRayQueryGetIntersectionFrontFaceKHR"; + case OpRayQueryGetIntersectionCandidateAABBOpaqueKHR: return "OpRayQueryGetIntersectionCandidateAABBOpaqueKHR"; + case OpRayQueryGetIntersectionObjectRayDirectionKHR: return "OpRayQueryGetIntersectionObjectRayDirectionKHR"; + case OpRayQueryGetIntersectionObjectRayOriginKHR: return "OpRayQueryGetIntersectionObjectRayOriginKHR"; + case OpRayQueryGetWorldRayDirectionKHR: return "OpRayQueryGetWorldRayDirectionKHR"; + case OpRayQueryGetWorldRayOriginKHR: return "OpRayQueryGetWorldRayOriginKHR"; + case OpRayQueryGetIntersectionObjectToWorldKHR: return "OpRayQueryGetIntersectionObjectToWorldKHR"; + case OpRayQueryGetIntersectionWorldToObjectKHR: return "OpRayQueryGetIntersectionWorldToObjectKHR"; + case OpAtomicFAddEXT: return "OpAtomicFAddEXT"; + case OpTypeBufferSurfaceINTEL: return "OpTypeBufferSurfaceINTEL"; + case OpTypeStructContinuedINTEL: return "OpTypeStructContinuedINTEL"; + case OpConstantCompositeContinuedINTEL: return "OpConstantCompositeContinuedINTEL"; + case OpSpecConstantCompositeContinuedINTEL: return "OpSpecConstantCompositeContinuedINTEL"; + case OpCompositeConstructContinuedINTEL: return "OpCompositeConstructContinuedINTEL"; + case OpConvertFToBF16INTEL: return "OpConvertFToBF16INTEL"; + case OpConvertBF16ToFINTEL: return "OpConvertBF16ToFINTEL"; + case OpControlBarrierArriveINTEL: return "OpControlBarrierArriveINTEL"; + case OpControlBarrierWaitINTEL: return "OpControlBarrierWaitINTEL"; + case OpArithmeticFenceEXT: return "OpArithmeticFenceEXT"; + case OpTaskSequenceCreateINTEL: return "OpTaskSequenceCreateINTEL"; + case OpTaskSequenceAsyncINTEL: return "OpTaskSequenceAsyncINTEL"; + case OpTaskSequenceGetINTEL: return "OpTaskSequenceGetINTEL"; + case OpTaskSequenceReleaseINTEL: return "OpTaskSequenceReleaseINTEL"; + case OpTypeTaskSequenceINTEL: return "OpTypeTaskSequenceINTEL"; + case OpSubgroupBlockPrefetchINTEL: return "OpSubgroupBlockPrefetchINTEL"; + case OpSubgroup2DBlockLoadINTEL: return "OpSubgroup2DBlockLoadINTEL"; + case OpSubgroup2DBlockLoadTransformINTEL: return "OpSubgroup2DBlockLoadTransformINTEL"; + case OpSubgroup2DBlockLoadTransposeINTEL: return "OpSubgroup2DBlockLoadTransposeINTEL"; + case OpSubgroup2DBlockPrefetchINTEL: return "OpSubgroup2DBlockPrefetchINTEL"; + case OpSubgroup2DBlockStoreINTEL: return "OpSubgroup2DBlockStoreINTEL"; + case OpSubgroupMatrixMultiplyAccumulateINTEL: return "OpSubgroupMatrixMultiplyAccumulateINTEL"; + case OpBitwiseFunctionINTEL: return "OpBitwiseFunctionINTEL"; + case OpGroupIMulKHR: return "OpGroupIMulKHR"; + case OpGroupFMulKHR: return "OpGroupFMulKHR"; + case OpGroupBitwiseAndKHR: return "OpGroupBitwiseAndKHR"; + case OpGroupBitwiseOrKHR: return "OpGroupBitwiseOrKHR"; + case OpGroupBitwiseXorKHR: return "OpGroupBitwiseXorKHR"; + case OpGroupLogicalAndKHR: return "OpGroupLogicalAndKHR"; + case OpGroupLogicalOrKHR: return "OpGroupLogicalOrKHR"; + case OpGroupLogicalXorKHR: return "OpGroupLogicalXorKHR"; + case OpRoundFToTF32INTEL: return "OpRoundFToTF32INTEL"; + case OpMaskedGatherINTEL: return "OpMaskedGatherINTEL"; + case OpMaskedScatterINTEL: return "OpMaskedScatterINTEL"; + default: return "Unknown"; + } +} + +#endif /* SPV_ENABLE_UTILITY_CODE */ + +// Overload bitwise operators for mask bit combining + +inline ImageOperandsMask operator|(ImageOperandsMask a, ImageOperandsMask b) { return ImageOperandsMask(unsigned(a) | unsigned(b)); } +inline ImageOperandsMask operator&(ImageOperandsMask a, ImageOperandsMask b) { return ImageOperandsMask(unsigned(a) & unsigned(b)); } +inline ImageOperandsMask operator^(ImageOperandsMask a, ImageOperandsMask b) { return ImageOperandsMask(unsigned(a) ^ unsigned(b)); } +inline ImageOperandsMask operator~(ImageOperandsMask a) { return ImageOperandsMask(~unsigned(a)); } +inline FPFastMathModeMask operator|(FPFastMathModeMask a, FPFastMathModeMask b) { return FPFastMathModeMask(unsigned(a) | unsigned(b)); } +inline FPFastMathModeMask operator&(FPFastMathModeMask a, FPFastMathModeMask b) { return FPFastMathModeMask(unsigned(a) & unsigned(b)); } +inline FPFastMathModeMask operator^(FPFastMathModeMask a, FPFastMathModeMask b) { return FPFastMathModeMask(unsigned(a) ^ unsigned(b)); } +inline FPFastMathModeMask operator~(FPFastMathModeMask a) { return FPFastMathModeMask(~unsigned(a)); } +inline SelectionControlMask operator|(SelectionControlMask a, SelectionControlMask b) { return SelectionControlMask(unsigned(a) | unsigned(b)); } +inline SelectionControlMask operator&(SelectionControlMask a, SelectionControlMask b) { return SelectionControlMask(unsigned(a) & unsigned(b)); } +inline SelectionControlMask operator^(SelectionControlMask a, SelectionControlMask b) { return SelectionControlMask(unsigned(a) ^ unsigned(b)); } +inline SelectionControlMask operator~(SelectionControlMask a) { return SelectionControlMask(~unsigned(a)); } +inline LoopControlMask operator|(LoopControlMask a, LoopControlMask b) { return LoopControlMask(unsigned(a) | unsigned(b)); } +inline LoopControlMask operator&(LoopControlMask a, LoopControlMask b) { return LoopControlMask(unsigned(a) & unsigned(b)); } +inline LoopControlMask operator^(LoopControlMask a, LoopControlMask b) { return LoopControlMask(unsigned(a) ^ unsigned(b)); } +inline LoopControlMask operator~(LoopControlMask a) { return LoopControlMask(~unsigned(a)); } +inline FunctionControlMask operator|(FunctionControlMask a, FunctionControlMask b) { return FunctionControlMask(unsigned(a) | unsigned(b)); } +inline FunctionControlMask operator&(FunctionControlMask a, FunctionControlMask b) { return FunctionControlMask(unsigned(a) & unsigned(b)); } +inline FunctionControlMask operator^(FunctionControlMask a, FunctionControlMask b) { return FunctionControlMask(unsigned(a) ^ unsigned(b)); } +inline FunctionControlMask operator~(FunctionControlMask a) { return FunctionControlMask(~unsigned(a)); } +inline MemorySemanticsMask operator|(MemorySemanticsMask a, MemorySemanticsMask b) { return MemorySemanticsMask(unsigned(a) | unsigned(b)); } +inline MemorySemanticsMask operator&(MemorySemanticsMask a, MemorySemanticsMask b) { return MemorySemanticsMask(unsigned(a) & unsigned(b)); } +inline MemorySemanticsMask operator^(MemorySemanticsMask a, MemorySemanticsMask b) { return MemorySemanticsMask(unsigned(a) ^ unsigned(b)); } +inline MemorySemanticsMask operator~(MemorySemanticsMask a) { return MemorySemanticsMask(~unsigned(a)); } +inline MemoryAccessMask operator|(MemoryAccessMask a, MemoryAccessMask b) { return MemoryAccessMask(unsigned(a) | unsigned(b)); } +inline MemoryAccessMask operator&(MemoryAccessMask a, MemoryAccessMask b) { return MemoryAccessMask(unsigned(a) & unsigned(b)); } +inline MemoryAccessMask operator^(MemoryAccessMask a, MemoryAccessMask b) { return MemoryAccessMask(unsigned(a) ^ unsigned(b)); } +inline MemoryAccessMask operator~(MemoryAccessMask a) { return MemoryAccessMask(~unsigned(a)); } +inline KernelProfilingInfoMask operator|(KernelProfilingInfoMask a, KernelProfilingInfoMask b) { return KernelProfilingInfoMask(unsigned(a) | unsigned(b)); } +inline KernelProfilingInfoMask operator&(KernelProfilingInfoMask a, KernelProfilingInfoMask b) { return KernelProfilingInfoMask(unsigned(a) & unsigned(b)); } +inline KernelProfilingInfoMask operator^(KernelProfilingInfoMask a, KernelProfilingInfoMask b) { return KernelProfilingInfoMask(unsigned(a) ^ unsigned(b)); } +inline KernelProfilingInfoMask operator~(KernelProfilingInfoMask a) { return KernelProfilingInfoMask(~unsigned(a)); } +inline RayFlagsMask operator|(RayFlagsMask a, RayFlagsMask b) { return RayFlagsMask(unsigned(a) | unsigned(b)); } +inline RayFlagsMask operator&(RayFlagsMask a, RayFlagsMask b) { return RayFlagsMask(unsigned(a) & unsigned(b)); } +inline RayFlagsMask operator^(RayFlagsMask a, RayFlagsMask b) { return RayFlagsMask(unsigned(a) ^ unsigned(b)); } +inline RayFlagsMask operator~(RayFlagsMask a) { return RayFlagsMask(~unsigned(a)); } +inline FragmentShadingRateMask operator|(FragmentShadingRateMask a, FragmentShadingRateMask b) { return FragmentShadingRateMask(unsigned(a) | unsigned(b)); } +inline FragmentShadingRateMask operator&(FragmentShadingRateMask a, FragmentShadingRateMask b) { return FragmentShadingRateMask(unsigned(a) & unsigned(b)); } +inline FragmentShadingRateMask operator^(FragmentShadingRateMask a, FragmentShadingRateMask b) { return FragmentShadingRateMask(unsigned(a) ^ unsigned(b)); } +inline FragmentShadingRateMask operator~(FragmentShadingRateMask a) { return FragmentShadingRateMask(~unsigned(a)); } +inline CooperativeMatrixOperandsMask operator|(CooperativeMatrixOperandsMask a, CooperativeMatrixOperandsMask b) { return CooperativeMatrixOperandsMask(unsigned(a) | unsigned(b)); } +inline CooperativeMatrixOperandsMask operator&(CooperativeMatrixOperandsMask a, CooperativeMatrixOperandsMask b) { return CooperativeMatrixOperandsMask(unsigned(a) & unsigned(b)); } +inline CooperativeMatrixOperandsMask operator^(CooperativeMatrixOperandsMask a, CooperativeMatrixOperandsMask b) { return CooperativeMatrixOperandsMask(unsigned(a) ^ unsigned(b)); } +inline CooperativeMatrixOperandsMask operator~(CooperativeMatrixOperandsMask a) { return CooperativeMatrixOperandsMask(~unsigned(a)); } +inline CooperativeMatrixReduceMask operator|(CooperativeMatrixReduceMask a, CooperativeMatrixReduceMask b) { return CooperativeMatrixReduceMask(unsigned(a) | unsigned(b)); } +inline CooperativeMatrixReduceMask operator&(CooperativeMatrixReduceMask a, CooperativeMatrixReduceMask b) { return CooperativeMatrixReduceMask(unsigned(a) & unsigned(b)); } +inline CooperativeMatrixReduceMask operator^(CooperativeMatrixReduceMask a, CooperativeMatrixReduceMask b) { return CooperativeMatrixReduceMask(unsigned(a) ^ unsigned(b)); } +inline CooperativeMatrixReduceMask operator~(CooperativeMatrixReduceMask a) { return CooperativeMatrixReduceMask(~unsigned(a)); } +inline TensorAddressingOperandsMask operator|(TensorAddressingOperandsMask a, TensorAddressingOperandsMask b) { return TensorAddressingOperandsMask(unsigned(a) | unsigned(b)); } +inline TensorAddressingOperandsMask operator&(TensorAddressingOperandsMask a, TensorAddressingOperandsMask b) { return TensorAddressingOperandsMask(unsigned(a) & unsigned(b)); } +inline TensorAddressingOperandsMask operator^(TensorAddressingOperandsMask a, TensorAddressingOperandsMask b) { return TensorAddressingOperandsMask(unsigned(a) ^ unsigned(b)); } +inline TensorAddressingOperandsMask operator~(TensorAddressingOperandsMask a) { return TensorAddressingOperandsMask(~unsigned(a)); } +inline MatrixMultiplyAccumulateOperandsMask operator|(MatrixMultiplyAccumulateOperandsMask a, MatrixMultiplyAccumulateOperandsMask b) { return MatrixMultiplyAccumulateOperandsMask(unsigned(a) | unsigned(b)); } +inline MatrixMultiplyAccumulateOperandsMask operator&(MatrixMultiplyAccumulateOperandsMask a, MatrixMultiplyAccumulateOperandsMask b) { return MatrixMultiplyAccumulateOperandsMask(unsigned(a) & unsigned(b)); } +inline MatrixMultiplyAccumulateOperandsMask operator^(MatrixMultiplyAccumulateOperandsMask a, MatrixMultiplyAccumulateOperandsMask b) { return MatrixMultiplyAccumulateOperandsMask(unsigned(a) ^ unsigned(b)); } +inline MatrixMultiplyAccumulateOperandsMask operator~(MatrixMultiplyAccumulateOperandsMask a) { return MatrixMultiplyAccumulateOperandsMask(~unsigned(a)); } +inline RawAccessChainOperandsMask operator|(RawAccessChainOperandsMask a, RawAccessChainOperandsMask b) { return RawAccessChainOperandsMask(unsigned(a) | unsigned(b)); } +inline RawAccessChainOperandsMask operator&(RawAccessChainOperandsMask a, RawAccessChainOperandsMask b) { return RawAccessChainOperandsMask(unsigned(a) & unsigned(b)); } +inline RawAccessChainOperandsMask operator^(RawAccessChainOperandsMask a, RawAccessChainOperandsMask b) { return RawAccessChainOperandsMask(unsigned(a) ^ unsigned(b)); } +inline RawAccessChainOperandsMask operator~(RawAccessChainOperandsMask a) { return RawAccessChainOperandsMask(~unsigned(a)); } + +} // end namespace spv + +#endif // #ifndef spirv_HPP diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/log/log.h b/app/src/main/cpp/thirdparty/dxbc/include/util/log/log.h new file mode 100644 index 0000000000..b12428c08c --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/log/log.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include + +namespace dxvk { + + enum class LogLevel : uint32_t { + Trace = 0, + Debug = 1, + Info = 2, + Warn = 3, + Error = 4, + None = 5, + }; + + /** + * \brief Logger + * + * Logger for one DLL. Creates a text file and + * writes all log messages to that file. + */ + class Logger { + + public: + + Logger() {} + Logger(const std::string& file_name) {} + ~Logger() {} + + static void trace(const std::string& message) {} + static void debug(const std::string& message) {} + static void info (const std::string& message) {} + static void warn (const std::string& message) {} + static void err (const std::string& message) {} + static void log (LogLevel level, const std::string& message) {} + + static LogLevel logLevel() { + return LogLevel::Warn; + } + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/log/log_debug.h b/app/src/main/cpp/thirdparty/dxbc/include/util/log/log_debug.h new file mode 100644 index 0000000000..34c61106cf --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/log/log_debug.h @@ -0,0 +1,49 @@ +#pragma once + +#include + +#include "log/log.h" + +#ifdef _MSC_VER +#define METHOD_NAME __FUNCSIG__ +#else +#define METHOD_NAME __PRETTY_FUNCTION__ +#endif + +#define TRACE_ENABLED + +#ifdef TRACE_ENABLED +#define TRACE(...) \ + do { dxvk::debug::trace(METHOD_NAME, ##__VA_ARGS__); } while (0) +#else +#define TRACE(...) \ + do { } while (0) +#endif + +namespace dxvk::debug { + + std::string methodName(const std::string& prettyName); + + inline void traceArgs(std::stringstream& stream) { } + + template + void traceArgs(std::stringstream& stream, const Arg1& arg1) { + stream << arg1; + } + + template + void traceArgs(std::stringstream& stream, const Arg1& arg1, const Arg2& arg2, const Args&... args) { + stream << arg1 << ","; + traceArgs(stream, arg2, args...); + } + + template + void trace(const std::string& funcName, const Args&... args) { + std::stringstream stream; + stream << methodName(funcName) << "("; + traceArgs(stream, args...); + stream << ")"; + Logger::trace(stream.str()); + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/rc/util_rc.h b/app/src/main/cpp/thirdparty/dxbc/include/util/rc/util_rc.h new file mode 100644 index 0000000000..b92cf00b49 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/rc/util_rc.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include "../util_likely.h" + +namespace dxvk { + + /** + * \brief Reference-counted object + */ + class RcObject { + + public: + + /** + * \brief Increments reference count + * \returns New reference count + */ + force_inline uint32_t incRef() { + return ++m_refCount; + } + + /** + * \brief Decrements reference count + * \returns New reference count + */ + force_inline uint32_t decRef() { + return --m_refCount; + } + + private: + + std::atomic m_refCount = { 0u }; + + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/rc/util_rc_ptr.h b/app/src/main/cpp/thirdparty/dxbc/include/util/rc/util_rc_ptr.h new file mode 100644 index 0000000000..ac465758cc --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/rc/util_rc_ptr.h @@ -0,0 +1,189 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace dxvk { + + /** + * \brief Pointer for reference-counted objects + * + * This only requires the given type to implement \c incRef + * and \c decRef methods that adjust the reference count. + * \tparam T Object type + */ + template + class Rc { + template + friend class Rc; + public: + + Rc() = default; + Rc(std::nullptr_t) { } + + Rc(T* object) + : m_object(object) { + this->incRef(); + } + + Rc(const Rc& other) + : m_object(other.m_object) { + this->incRef(); + } + + template + Rc(const Rc& other) + : m_object(other.m_object) { + this->incRef(); + } + + Rc(Rc&& other) + : m_object(other.m_object) { + other.m_object = nullptr; + } + + template + Rc(Rc&& other) + : m_object(other.m_object) { + other.m_object = nullptr; + } + + Rc& operator = (std::nullptr_t) { + this->decRef(); + m_object = nullptr; + return *this; + } + + Rc& operator = (const Rc& other) { + other.incRef(); + this->decRef(); + m_object = other.m_object; + return *this; + } + + template + Rc& operator = (const Rc& other) { + other.incRef(); + this->decRef(); + m_object = other.m_object; + return *this; + } + + Rc& operator = (Rc&& other) { + this->decRef(); + this->m_object = other.m_object; + other.m_object = nullptr; + return *this; + } + + template + Rc& operator = (Rc&& other) { + this->decRef(); + this->m_object = other.m_object; + other.m_object = nullptr; + return *this; + } + + ~Rc() { + this->decRef(); + } + + T& operator * () const { return *m_object; } + T* operator -> () const { return m_object; } + T* ptr() const { return m_object; } + + template bool operator == (const Rc& other) const { return m_object == other.m_object; } + template bool operator != (const Rc& other) const { return m_object != other.m_object; } + + template bool operator == (Tx* other) const { return m_object == other; } + template bool operator != (Tx* other) const { return m_object != other; } + + bool operator == (std::nullptr_t) const { return m_object == nullptr; } + bool operator != (std::nullptr_t) const { return m_object != nullptr; } + + explicit operator bool () const { + return m_object != nullptr; + } + + /** + * \brief Sets pointer without acquiring a reference + * + * Must only be use when a reference has been taken via + * other means. + * \param [in] object Object pointer + */ + void unsafeInsert(T* object) { + this->decRef(); + m_object = object; + } + + /** + * \brief Extracts raw pointer + * + * Sets the smart pointer to null without decrementing the + * reference count. Must only be used when the reference + * count is decremented in some other way. + * \returns Pointer to owned object + */ + T* unsafeExtract() { + return std::exchange(m_object, nullptr); + } + + /** + * \brief Creates smart pointer without taking reference + * + * Must only be used when a refernece has been obtained via other means. + * \param [in] object Pointer to object to take ownership of + */ + static Rc unsafeCreate(T* object) { + return Rc(object, false); + } + + private: + + T* m_object = nullptr; + + explicit Rc(T* object, bool) + : m_object(object) { } + + force_inline void incRef() const { + if (m_object != nullptr) + m_object->incRef(); + } + + force_inline void decRef() const { + if (m_object != nullptr) { + if constexpr (std::is_void_vdecRef())>) { + m_object->decRef(); + } else { + // Deprecated, objects should manage themselves now. + if (!m_object->decRef()) + delete m_object; + } + } + } + + }; + + template + bool operator == (Tx* a, const Rc& b) { return b == a; } + + template + bool operator != (Tx* a, const Rc& b) { return b != a; } + + struct RcHash { + template + size_t operator () (const Rc& rc) const { + return reinterpret_cast(rc.ptr()) / sizeof(T); + } + }; + +} + +template +std::ostream& operator << (std::ostream& os, const dxvk::Rc& rc) { + return os << rc.ptr(); +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_bit.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_bit.h new file mode 100644 index 0000000000..2a53025818 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_bit.h @@ -0,0 +1,719 @@ +#pragma once + +#if (defined(__x86_64__) && !defined(__arm64ec__)) || (defined(_M_X64) && !defined(_M_ARM64EC)) \ + || defined(__i386__) || defined(_M_IX86) || defined(__e2k__) + #define DXVK_ARCH_X86 + #if defined(__x86_64__) || defined(_M_X64) || defined(__e2k__) + #define DXVK_ARCH_X86_64 + #endif +#elif defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) + #define DXVK_ARCH_ARM64 +#endif + +#ifdef DXVK_ARCH_X86 + #ifndef _MSC_VER + #if defined(_WIN32) && (defined(__AVX__) || defined(__AVX2__)) + #error "AVX-enabled builds not supported due to stack alignment issues." + #endif + #if defined(__WINE__) && defined(__clang__) + #pragma push_macro("_WIN32") + #undef _WIN32 + #endif + #include + #if defined(__WINE__) && defined(__clang__) + #pragma pop_macro("_WIN32") + #endif + #else + #include + #endif +#endif + +#include "util_likely.h" +#include "util_math.h" + +#include +#include +#include +#include +#include +#include + +namespace dxvk::bit { + + template + T cast(const J& src) { + static_assert(sizeof(T) == sizeof(J)); + static_assert(std::is_trivially_copyable::value && std::is_trivial::value); + + T dst; + std::memcpy(&dst, &src, sizeof(T)); + return dst; + } + + template + T extract(T value, uint32_t fst, uint32_t lst) { + return (value >> fst) & ~(~T(0) << (lst - fst + 1)); + } + + template + T popcnt(T n) { + n -= ((n >> 1u) & T(0x5555555555555555ull)); + n = (n & T(0x3333333333333333ull)) + ((n >> 2u) & T(0x3333333333333333ull)); + n = (n + (n >> 4u)) & T(0x0f0f0f0f0f0f0f0full); + n *= T(0x0101010101010101ull); + return n >> (8u * (sizeof(T) - 1u)); + } + + inline uint32_t tzcnt(uint32_t n) { + #if defined(_MSC_VER) && !defined(__clang__) + if(n == 0) + return 32; + return _tzcnt_u32(n); + #elif defined(__BMI__) + return __tzcnt_u32(n); + #elif defined(DXVK_ARCH_X86) && (defined(__GNUC__) || defined(__clang__)) + // tzcnt is encoded as rep bsf, so we can use it on all + // processors, but the behaviour of zero inputs differs: + // - bsf: zf = 1, cf = ?, result = ? + // - tzcnt: zf = 0, cf = 1, result = 32 + // We'll have to handle this case manually. + uint32_t res; + uint32_t tmp; + asm ( + "tzcnt %2, %0;" + "mov $32, %1;" + "test %2, %2;" + "cmovz %1, %0;" + : "=&r" (res), "=&r" (tmp) + : "r" (n) + : "cc"); + return res; + #elif defined(__GNUC__) || defined(__clang__) + return n != 0 ? __builtin_ctz(n) : 32; + #else + uint32_t r = 31; + n &= -n; + r -= (n & 0x0000FFFF) ? 16 : 0; + r -= (n & 0x00FF00FF) ? 8 : 0; + r -= (n & 0x0F0F0F0F) ? 4 : 0; + r -= (n & 0x33333333) ? 2 : 0; + r -= (n & 0x55555555) ? 1 : 0; + return n != 0 ? r : 32; + #endif + } + + inline uint32_t tzcnt(uint64_t n) { + #if defined(DXVK_ARCH_X86_64) && defined(_MSC_VER) && !defined(__clang__) + if(n == 0) + return 64; + return (uint32_t)_tzcnt_u64(n); + #elif defined(DXVK_ARCH_X86_64) && defined(__BMI__) + return __tzcnt_u64(n); + #elif defined(DXVK_ARCH_X86_64) && (defined(__GNUC__) || defined(__clang__)) + uint64_t res; + uint64_t tmp; + asm ( + "tzcnt %2, %0;" + "mov $64, %1;" + "test %2, %2;" + "cmovz %1, %0;" + : "=&r" (res), "=&r" (tmp) + : "r" (n) + : "cc"); + return res; + #elif defined(__GNUC__) || defined(__clang__) + return n != 0 ? __builtin_ctzll(n) : 64; + #else + uint32_t lo = uint32_t(n); + if (lo) { + return tzcnt(lo); + } else { + uint32_t hi = uint32_t(n >> 32); + return tzcnt(hi) + 32; + } + #endif + } + + inline uint32_t bsf(uint32_t n) { + #if (defined(__GNUC__) || defined(__clang__)) && !defined(__BMI__) && defined(DXVK_ARCH_X86) + uint32_t res; + asm ("tzcnt %1,%0" + : "=r" (res) + : "r" (n) + : "cc"); + return res; + #else + return tzcnt(n); + #endif + } + + inline uint32_t bsf(uint64_t n) { + #if (defined(__GNUC__) || defined(__clang__)) && !defined(__BMI__) && defined(DXVK_ARCH_X86_64) + uint64_t res; + asm ("tzcnt %1,%0" + : "=r" (res) + : "r" (n) + : "cc"); + return res; + #else + return tzcnt(n); + #endif + } + + inline uint32_t lzcnt(uint32_t n) { + #if defined(_MSC_VER) && !defined(__clang__) && !defined(__LZCNT__) + unsigned long bsr; + if(n == 0) + return 32; + _BitScanReverse(&bsr, n); + return 31-bsr; + #elif (defined(_MSC_VER) && !defined(__clang__)) || defined(__LZCNT__) + return _lzcnt_u32(n); + #elif defined(__GNUC__) || defined(__clang__) + return n != 0 ? __builtin_clz(n) : 32; + #else + uint32_t r = 0; + + if (n == 0) return 32; + + if (n <= 0x0000FFFF) { r += 16; n <<= 16; } + if (n <= 0x00FFFFFF) { r += 8; n <<= 8; } + if (n <= 0x0FFFFFFF) { r += 4; n <<= 4; } + if (n <= 0x3FFFFFFF) { r += 2; n <<= 2; } + if (n <= 0x7FFFFFFF) { r += 1; n <<= 1; } + + return r; + #endif + } + + inline uint32_t lzcnt(uint64_t n) { + #if defined(_MSC_VER) && !defined(__clang__) && !defined(__LZCNT__) && defined(DXVK_ARCH_X86_64) + unsigned long bsr; + if(n == 0) + return 64; + _BitScanReverse64(&bsr, n); + return 63-bsr; + #elif defined(DXVK_ARCH_X86_64) && ((defined(_MSC_VER) && !defined(__clang__)) && defined(__LZCNT__)) + return _lzcnt_u64(n); + #elif defined(DXVK_ARCH_X86_64) && (defined(__GNUC__) || defined(__clang__)) + return n != 0 ? __builtin_clzll(n) : 64; + #else + uint32_t lo = uint32_t(n); + uint32_t hi = uint32_t(n >> 32u); + return hi ? lzcnt(hi) : lzcnt(lo) + 32u; + #endif + } + + template + uint32_t pack(T& dst, uint32_t& shift, T src, uint32_t count) { + constexpr uint32_t Bits = 8 * sizeof(T); + if (likely(shift < Bits)) + dst |= src << shift; + shift += count; + return shift > Bits ? shift - Bits : 0; + } + + template + uint32_t unpack(T& dst, T src, uint32_t& shift, uint32_t count) { + constexpr uint32_t Bits = 8 * sizeof(T); + if (likely(shift < Bits)) + dst = (src >> shift) & ((T(1) << count) - 1); + shift += count; + return shift > Bits ? shift - Bits : 0; + } + + + /** + * \brief Clears cache lines of memory + * + * Uses non-temporal stores. The memory region offset + * and size are assumed to be aligned to 64 bytes. + * \param [in] mem Memory region to clear + * \param [in] size Number of bytes to clear + */ + inline void bclear(void* mem, size_t size) { + #if defined(DXVK_ARCH_X86) && (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)) + auto zero = _mm_setzero_si128(); + + #if defined(__clang__) + #pragma nounroll + #elif defined(__GNUC__) + #pragma GCC unroll 0 + #endif + for (size_t i = 0; i < size; i += 64u) { + auto* ptr = reinterpret_cast<__m128i*>(mem) + i / sizeof(zero); + _mm_stream_si128(ptr + 0u, zero); + _mm_stream_si128(ptr + 1u, zero); + _mm_stream_si128(ptr + 2u, zero); + _mm_stream_si128(ptr + 3u, zero); + } + #else + std::memset(mem, 0, size); + #endif + } + + + /** + * \brief Compares two aligned structs bit by bit + * + * \param [in] a First struct + * \param [in] b Second struct + * \returns \c true if the structs are equal + */ + template + bool bcmpeq(const T* a, const T* b) { + static_assert(alignof(T) >= 16); + #if defined(DXVK_ARCH_X86) && (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)) + auto ai = reinterpret_cast(a); + auto bi = reinterpret_cast(b); + + size_t i = 0; + + #if defined(__clang__) + #pragma nounroll + #elif defined(__GNUC__) + #pragma GCC unroll 0 + #endif + + for ( ; i < 2 * (sizeof(T) / 32); i += 2) { + __m128i eq0 = _mm_cmpeq_epi8( + _mm_load_si128(ai + i), + _mm_load_si128(bi + i)); + __m128i eq1 = _mm_cmpeq_epi8( + _mm_load_si128(ai + i + 1), + _mm_load_si128(bi + i + 1)); + __m128i eq = _mm_and_si128(eq0, eq1); + + int mask = _mm_movemask_epi8(eq); + if (mask != 0xFFFF) + return false; + } + + for ( ; i < sizeof(T) / 16; i++) { + __m128i eq = _mm_cmpeq_epi8( + _mm_load_si128(ai + i), + _mm_load_si128(bi + i)); + + int mask = _mm_movemask_epi8(eq); + if (mask != 0xFFFF) + return false; + } + + return true; + #else + return !std::memcmp(a, b, sizeof(T)); + #endif + } + + template + class bitset { + static constexpr size_t Dwords = align(Bits, 32) / 32; + public: + + constexpr bitset() + : m_dwords() { + + } + + constexpr bool get(uint32_t idx) const { + uint32_t dword = 0; + uint32_t bit = idx; + + // Compiler doesn't remove this otherwise. + if constexpr (Dwords > 1) { + dword = idx / 32; + bit = idx % 32; + } + + return m_dwords[dword] & (1u << bit); + } + + constexpr void set(uint32_t idx, bool value) { + uint32_t dword = 0; + uint32_t bit = idx; + + // Compiler doesn't remove this otherwise. + if constexpr (Dwords > 1) { + dword = idx / 32; + bit = idx % 32; + } + + if (value) + m_dwords[dword] |= 1u << bit; + else + m_dwords[dword] &= ~(1u << bit); + } + + constexpr bool exchange(uint32_t idx, bool value) { + bool oldValue = get(idx); + set(idx, value); + return oldValue; + } + + constexpr void flip(uint32_t idx) { + uint32_t dword = 0; + uint32_t bit = idx; + + // Compiler doesn't remove this otherwise. + if constexpr (Dwords > 1) { + dword = idx / 32; + bit = idx % 32; + } + + m_dwords[dword] ^= 1u << bit; + } + + constexpr void setAll() { + if constexpr (Bits % 32 == 0) { + for (size_t i = 0; i < Dwords; i++) + m_dwords[i] = std::numeric_limits::max(); + } + else { + for (size_t i = 0; i < Dwords - 1; i++) + m_dwords[i] = std::numeric_limits::max(); + + m_dwords[Dwords - 1] = (1u << (Bits % 32)) - 1; + } + } + + constexpr void clearAll() { + for (size_t i = 0; i < Dwords; i++) + m_dwords[i] = 0; + } + + constexpr bool any() const { + for (size_t i = 0; i < Dwords; i++) { + if (m_dwords[i] != 0) + return true; + } + + return false; + } + + constexpr uint32_t& dword(uint32_t idx) { + return m_dwords[idx]; + } + + constexpr size_t bitCount() { + return Bits; + } + + constexpr size_t dwordCount() { + return Dwords; + } + + constexpr bool operator [] (uint32_t idx) const { + return get(idx); + } + + constexpr void setN(uint32_t bits) { + uint32_t fullDwords = bits / 32; + uint32_t offset = bits % 32; + + for (size_t i = 0; i < fullDwords; i++) + m_dwords[i] = std::numeric_limits::max(); + + if (offset > 0) + m_dwords[fullDwords] = (1u << offset) - 1; + } + + private: + + uint32_t m_dwords[Dwords]; + + }; + + class bitvector { + public: + + bool get(uint32_t idx) const { + uint32_t dword = idx / 32; + uint32_t bit = idx % 32; + + return m_dwords[dword] & (1u << bit); + } + + void ensureSize(uint32_t bitCount) { + uint32_t dword = bitCount / 32; + if (unlikely(dword >= m_dwords.size())) { + m_dwords.resize(dword + 1); + } + m_bitCount = std::max(m_bitCount, bitCount); + } + + void set(uint32_t idx, bool value) { + ensureSize(idx + 1); + + uint32_t dword = 0; + uint32_t bit = idx; + + if (value) + m_dwords[dword] |= 1u << bit; + else + m_dwords[dword] &= ~(1u << bit); + } + + bool exchange(uint32_t idx, bool value) { + ensureSize(idx + 1); + + bool oldValue = get(idx); + set(idx, value); + return oldValue; + } + + void flip(uint32_t idx) { + ensureSize(idx + 1); + + uint32_t dword = idx / 32; + uint32_t bit = idx % 32; + + m_dwords[dword] ^= 1u << bit; + } + + void setAll() { + if (m_bitCount % 32 == 0) { + for (size_t i = 0; i < m_dwords.size(); i++) + m_dwords[i] = std::numeric_limits::max(); + } + else { + for (size_t i = 0; i < m_dwords.size() - 1; i++) + m_dwords[i] = std::numeric_limits::max(); + + m_dwords[m_dwords.size() - 1] = (1u << (m_bitCount % 32)) - 1; + } + } + + void clearAll() { + for (size_t i = 0; i < m_dwords.size(); i++) + m_dwords[i] = 0; + } + + bool any() const { + for (size_t i = 0; i < m_dwords.size(); i++) { + if (m_dwords[i] != 0) + return true; + } + + return false; + } + + uint32_t& dword(uint32_t idx) { + return m_dwords[idx]; + } + + size_t bitCount() const { + return m_bitCount; + } + + size_t dwordCount() const { + return m_dwords.size(); + } + + bool operator [] (uint32_t idx) const { + return get(idx); + } + + void setN(uint32_t bits) { + ensureSize(bits); + + uint32_t fullDwords = bits / 32; + uint32_t offset = bits % 32; + + for (size_t i = 0; i < fullDwords; i++) + m_dwords[i] = std::numeric_limits::max(); + + if (offset > 0) + m_dwords[fullDwords] = (1u << offset) - 1; + } + + private: + + std::vector m_dwords; + uint32_t m_bitCount = 0; + + }; + + template + class BitMask { + + public: + + class iterator { + public: + using iterator_category = std::input_iterator_tag; + using value_type = T; + using difference_type = T; + using pointer = const T*; + using reference = T; + + explicit iterator(T flags) + : m_mask(flags) { } + + iterator& operator ++ () { + m_mask &= m_mask - 1; + return *this; + } + + iterator operator ++ (int) { + iterator retval = *this; + m_mask &= m_mask - 1; + return retval; + } + + T operator * () const { + return bsf(m_mask); + } + + bool operator == (iterator other) const { return m_mask == other.m_mask; } + bool operator != (iterator other) const { return m_mask != other.m_mask; } + + private: + + T m_mask; + + }; + + BitMask() + : m_mask(0) { } + + explicit BitMask(T n) + : m_mask(n) { } + + iterator begin() { + return iterator(m_mask); + } + + iterator end() { + return iterator(0); + } + + private: + + T m_mask; + + }; + + + /** + * \brief Encodes float as fixed point + * + * Rounds away from zero. If this is not suitable for + * certain use cases, implement round to nearest even. + * \tparam T Integer type, may be signed + * \tparam I Integer bits + * \tparam F Fractional bits + * \param n Float to encode + * \returns Encoded fixed-point value + */ + template + T encodeFixed(float n) { + if (n != n) + return 0u; + + n *= float(1u << F); + + if constexpr (std::is_signed_v) { + n = std::max(n, -float(1u << (I + F - 1u))); + n = std::min(n, float(1u << (I + F - 1u)) - 1.0f); + n += n < 0.0f ? -0.5f : 0.5f; + } else { + n = std::max(n, 0.0f); + n = std::min(n, float(1u << (I + F)) - 1.0f); + n += 0.5f; + } + + T result = T(n); + + if constexpr (std::is_signed_v) + result &= ((T(1u) << (I + F)) - 1u); + + return result; + } + + + /** + * \brief Decodes fixed-point integer to float + * + * \tparam T Integer type, may be signed + * \tparam I Integer bits + * \tparam F Fractional bits + * \param n Number to decode + * \returns Decoded number + */ + template + float decodeFixed(T n) { + // Sign-extend as necessary + if constexpr (std::is_signed_v) + n -= (n & (T(1u) << (I + F - 1u))) << 1u; + + return float(n) / float(1u << F); + } + + + /** + * \brief Inserts one null bit after each bit + */ + inline uint32_t split2(uint32_t c) { + c = (c ^ (c << 8u)) & 0x00ff00ffu; + c = (c ^ (c << 4u)) & 0x0f0f0f0fu; + c = (c ^ (c << 2u)) & 0x33333333u; + c = (c ^ (c << 1u)) & 0x55555555u; + return c; + } + + + /** + * \brief Inserts two null bits after each bit + */ + inline uint64_t split3(uint64_t c) { + c = (c | c << 32u) & 0x001f00000000ffffull; + c = (c | c << 16u) & 0x001f0000ff0000ffull; + c = (c | c << 8u) & 0x100f00f00f00f00full; + c = (c | c << 4u) & 0x10c30c30c30c30c3ull; + c = (c | c << 2u) & 0x1249249249249249ull; + return c; + } + + + /** + * \brief Interleaves bits from two integers + * + * Both numbers must fit into 16 bits. + * \param [in] x X coordinate + * \param [in] y Y coordinate + * \returns Morton code of x and y + */ + inline uint32_t interleave(uint16_t x, uint16_t y) { + return split2(x) | (split2(y) << 1u); + } + + + /** + * \brief Interleaves bits from three integers + * + * All three numbers must fit into 16 bits. + */ + inline uint64_t interleave(uint16_t x, uint16_t y, uint16_t z) { + return split3(x) | (split3(y) << 1u) | (split3(z) << 2u); + } + + + /** + * \brief 48-bit integer storage type + */ + struct uint48_t { + explicit uint48_t(uint64_t n) + : a(uint16_t(n)), b(uint16_t(n >> 16)), c(uint16_t(n >> 32)) { } + + uint16_t a; + uint16_t b; + uint16_t c; + + explicit operator uint64_t () const { + // GCC generates worse code if we promote to uint64 directly + uint32_t lo = uint32_t(a) | (uint32_t(b) << 16); + return uint64_t(lo) | (uint64_t(c) << 32); + } + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_enum.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_enum.h new file mode 100644 index 0000000000..85b9b21b9f --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_enum.h @@ -0,0 +1,7 @@ +#pragma once + +#define ENUM_NAME(name) \ + case name: return os << #name + +#define ENUM_DEFAULT(name) \ + default: return os << static_cast(e) diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_error.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_error.h new file mode 100644 index 0000000000..2cfd45ffd0 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_error.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace dxvk { + + /** + * \brief DXVK error + * + * A generic exception class that stores a + * message. Exceptions should be logged. + */ + class DxvkError { + + public: + + DxvkError() { } + DxvkError(std::string&& message) + : m_message(std::move(message)) { } + + const std::string& message() const { + return m_message; + } + + private: + + std::string m_message; + + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_flags.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_flags.h new file mode 100644 index 0000000000..f67b4a2efa --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_flags.h @@ -0,0 +1,110 @@ +#pragma once + +#include + +#include "util_bit.h" + +namespace dxvk { + + template + class Flags { + + public: + + using IntType = std::underlying_type_t; + + Flags() { } + + Flags(IntType t) + : m_bits(t) { } + + template + Flags(T f, Tx... fx) { + this->set(f, fx...); + } + + template + void set(Tx... fx) { + m_bits |= bits(fx...); + } + + void set(Flags flags) { + m_bits |= flags.m_bits; + } + + template + void clr(Tx... fx) { + m_bits &= ~bits(fx...); + } + + void clr(Flags flags) { + m_bits &= ~flags.m_bits; + } + + template + bool any(Tx... fx) const { + return (m_bits & bits(fx...)) != 0; + } + + template + bool all(Tx... fx) const { + const IntType mask = bits(fx...); + return (m_bits & mask) == mask; + } + + bool test(T f) const { + return this->any(f); + } + + bool isClear() const { + return m_bits == 0; + } + + void clrAll() { + m_bits = 0; + } + + IntType raw() const { + return m_bits; + } + + Flags operator & (const Flags& other) const { + return Flags(m_bits & other.m_bits); + } + + Flags operator | (const Flags& other) const { + return Flags(m_bits | other.m_bits); + } + + Flags operator ^ (const Flags& other) const { + return Flags(m_bits ^ other.m_bits); + } + + bool operator == (const Flags& other) const { + return m_bits == other.m_bits; + } + + bool operator != (const Flags& other) const { + return m_bits != other.m_bits; + } + + private: + + IntType m_bits = 0; + + static IntType bit(T f) { + return IntType(1) << static_cast(f); + } + + template + static IntType bits(T f, Tx... fx) { + return bit(f) | bits(fx...); + } + + static IntType bits() { + return 0; + } + + }; + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_likely.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_likely.h new file mode 100644 index 0000000000..84795ba7ca --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_likely.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __GNUC__ +#define likely(x) __builtin_expect(bool(x),1) +#define unlikely(x) __builtin_expect(bool(x),0) +#define force_inline inline __attribute__((always_inline)) +#else +#define likely(x) (x) +#define unlikely(x) (x) +#define force_inline inline +#endif diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_math.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_math.h new file mode 100644 index 0000000000..9276d9337c --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_math.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +namespace dxvk { + + constexpr size_t CACHE_LINE_SIZE = 64; + constexpr double pi = 3.14159265359; + + template + constexpr T clamp(T n, T lo, T hi) { + if (n < lo) return lo; + if (n > hi) return hi; + return n; + } + + template + constexpr T align(T what, U to) { + return (what + to - 1) & ~(to - 1); + } + + template + constexpr T alignDown(T what, U to) { + return (what / to) * to; + } + + // Equivalent of std::clamp for use with floating point numbers + // Handles (-){INFINITY,NAN} cases. + // Will return min in cases of NAN, etc. + inline float fclamp(float value, float min, float max) { + return std::fmin( + std::fmax(value, min), max); + } + + template + inline T divCeil(T dividend, T divisor) { + return (dividend + divisor - 1) / divisor; + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_small_vector.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_small_vector.h new file mode 100644 index 0000000000..861c9e0e02 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_small_vector.h @@ -0,0 +1,214 @@ +#pragma once + +#include +#include +#include +#include + +#include "util_bit.h" +#include "util_likely.h" + +namespace dxvk { + + template + class small_vector { + using storage = std::aligned_storage_t; + public: + + constexpr static size_t MinCapacity = N; + + small_vector() { } + + small_vector(size_t size) { + resize(size); + } + + small_vector(const small_vector& other) { + reserve(other.m_size); + + for (size_t i = 0; i < other.m_size; i++) + *ptr(i) = *other.ptr(i); + + m_size = other.m_size; + } + + small_vector& operator = (const small_vector& other) { + for (size_t i = 0; i < m_size; i++) + ptr(i)->~T(); + + reserve(other.m_size); + + for (size_t i = 0; i < other.m_size; i++) + *ptr(i) = *other.ptr(i); + + m_size = other.m_size; + return *this; + } + + small_vector(small_vector&& other) { + if (other.m_size <= N) { + for (size_t i = 0; i < other.m_size; i++) + new (&u.m_data[i]) T(std::move(*other.ptr(i))); + } else { + u.m_ptr = other.u.m_ptr; + m_capacity = other.m_capacity; + + other.u.m_ptr = nullptr; + other.m_capacity = N; + } + + m_size = other.m_size; + other.m_size = 0; + } + + small_vector& operator = (small_vector&& other) { + for (size_t i = 0; i < m_size; i++) + ptr(i)->~T(); + + if (m_capacity > N) + delete[] u.m_ptr; + + if (other.m_size <= N) { + m_capacity = N; + + for (size_t i = 0; i < other.m_size; i++) + new (&u.m_data[i]) T(std::move(*other.ptr(i))); + } else { + u.m_ptr = other.u.m_ptr; + m_capacity = other.m_capacity; + + other.u.m_ptr = nullptr; + other.m_capacity = N; + } + + m_size = other.m_size; + other.m_size = 0; + return *this; + } + + ~small_vector() { + for (size_t i = 0; i < m_size; i++) + ptr(i)->~T(); + + if (m_capacity > N) + delete[] u.m_ptr; + } + + size_t size() const { + return m_size; + } + + void reserve(size_t n) { + if (likely(n <= m_capacity)) + return; + + n = pick_capacity(n); + + storage* data = new storage[n]; + + for (size_t i = 0; i < m_size; i++) { + new (&data[i]) T(std::move(*ptr(i))); + ptr(i)->~T(); + } + + if (m_capacity > N) + delete[] u.m_ptr; + + m_capacity = n; + u.m_ptr = data; + } + + const T* data() const { return ptr(0); } + T* data() { return ptr(0); } + + void resize(size_t n) { + reserve(n); + + for (size_t i = n; i < m_size; i++) + ptr(i)->~T(); + + for (size_t i = m_size; i < n; i++) + new (ptr(i)) T(); + + m_size = n; + } + + void push_back(const T& object) { + reserve(m_size + 1); + new (ptr(m_size++)) T(object); + } + + void push_back(T&& object) { + reserve(m_size + 1); + new (ptr(m_size++)) T(std::move(object)); + } + + template + T& emplace_back(Args... args) { + reserve(m_size + 1); + return *(new (ptr(m_size++)) T(std::forward(args)...)); + } + + void erase(size_t idx) { + ptr(idx)->~T(); + + for (size_t i = idx; i < m_size - 1; i++) { + new (ptr(i)) T(std::move(*ptr(i + 1))); + ptr(i + 1)->~T(); + } + } + + void pop_back() { + ptr(--m_size)->~T(); + } + + void clear() { + for (size_t i = 0; i < m_size; i++) + ptr(i)->~T(); + + m_size = 0; + } + + bool empty() const { + return m_size == 0; + } + + T& operator [] (size_t idx) { return *ptr(idx); } + const T& operator [] (size_t idx) const { return *ptr(idx); } + + T& front() { return *ptr(0); } + const T& front() const { return *ptr(0); } + + T& back() { return *ptr(m_size - 1); } + const T& back() const { return *ptr(m_size - 1); } + + private: + + size_t m_capacity = N; + size_t m_size = 0; + + union { + storage* m_ptr; + storage m_data[N]; + } u; + + size_t pick_capacity(size_t n) { + // Pick next largest power of two for the new capacity + return size_t(1u) << ((sizeof(n) * 8u) - bit::lzcnt(n - 1)); + } + + T* ptr(size_t idx) { + return m_capacity == N + ? reinterpret_cast(&u.m_data[idx]) + : reinterpret_cast(&u.m_ptr[idx]); + } + + const T* ptr(size_t idx) const { + return m_capacity == N + ? reinterpret_cast(&u.m_data[idx]) + : reinterpret_cast(&u.m_ptr[idx]); + } + + }; + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/include/util/util_string.h b/app/src/main/cpp/thirdparty/dxbc/include/util/util_string.h new file mode 100644 index 0000000000..5fe00fbf53 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/include/util/util_string.h @@ -0,0 +1,240 @@ +#pragma once + +#include +#include +#include +#include + +#include "util_bit.h" +#include "util_likely.h" + +namespace dxvk::str { + + template struct UnicodeChar { }; + template<> struct UnicodeChar<1> { using type = uint8_t; }; + template<> struct UnicodeChar<2> { using type = uint16_t; }; + template<> struct UnicodeChar<4> { using type = uint32_t; }; + + template + using UnicodeCharType = typename UnicodeChar::type; + + const uint8_t* decodeTypedChar( + const uint8_t* begin, + const uint8_t* end, + uint32_t& ch); + + const uint16_t* decodeTypedChar( + const uint16_t* begin, + const uint16_t* end, + uint32_t& ch); + + const uint32_t* decodeTypedChar( + const uint32_t* begin, + const uint32_t* end, + uint32_t& ch); + + size_t encodeTypedChar( + uint8_t* begin, + uint8_t* end, + uint32_t ch); + + size_t encodeTypedChar( + uint16_t* begin, + uint16_t* end, + uint32_t ch); + + size_t encodeTypedChar( + uint32_t* begin, + uint32_t* end, + uint32_t ch); + + /** + * \brief Decodes a single character + * + * Note that \c begin and \c end must not be equal. + * \param [in] begin Pointer to current position within the input string + * \param [in] end Pointer to the end of the input string + * \param [out] ch Pointer to the decoded character code + * \returns Pointer to next character in the input string + */ + template + const T* decodeChar( + const T* begin, + const T* end, + uint32_t& ch) { + using CharType = UnicodeCharType; + + const CharType* result = decodeTypedChar( + reinterpret_cast(begin), + reinterpret_cast(end), + ch); + + return reinterpret_cast(result); + } + + /** + * \brief Encodes a character + * + * Note that \c begin and \c end may be both be \c nullptr or equal, in + * which case only the length of the encoded character will be returned. + * \param [in] begin Pointer to current position within the output string + * \param [in] end Pointer to the end of the output string + * \param [in] ch Character to encode + * \returns If begin is \c nullptr , the number of units required to encode + * the character. Otherwise, the number of units written to the output. + * This may return \c 0 for characters that cannot be written or encoded. + */ + template + size_t encodeChar( + T* begin, + T* end, + uint32_t ch) { + using CharType = UnicodeCharType; + + return encodeTypedChar( + reinterpret_cast(begin), + reinterpret_cast(end), + ch); + } + + /** + * \brief Computes length of a null-terminated string + * + * \param [in] begin Start of input string + * \returns Number of characters in input string, + * excluding the terminating null character + */ + template + size_t length(const S* string) { + size_t result = 0; + + while (string[result]) + result += 1; + + return result; + } + + /** + * \brief Converts string from one encoding to another + * + * The output string arguments may be \c nullptr. In that case, the + * total length of the transcoded string will be returned, in units + * of the output character type. The output string will only be + * null-terminated if the input string is also null-terminated. + * \tparam D Output character type + * \tparam S Input character type + * \param [in] dstBegin Start of output string + * \param [in] dstLength Length of output string + * \param [in] srcBegin Start of input string + * \param [in] srcLength Length of input string + * \returns If \c dstBegin is \c nullptr , the total number of output + * characters required to store the output string. Otherwise, the + * total number of characters written to the output string. + */ + template + size_t transcodeString( + D* dstBegin, + size_t dstLength, + const S* srcBegin, + size_t srcLength) { + size_t totalLength = 0; + + auto dstEnd = dstBegin + dstLength; + auto srcEnd = srcBegin + srcLength; + + while (srcBegin < srcEnd) { + uint32_t ch; + + srcBegin = decodeChar(srcBegin, srcEnd, ch); + + if (dstBegin) + totalLength += encodeChar(dstBegin + totalLength, dstEnd, ch); + else + totalLength += encodeChar(nullptr, nullptr, ch); + + if (!ch) + break; + } + + return totalLength; + } + + /** + * \brief Creates string object from wide char array + * + * \param [in] ws Null-terminated wide string + * \returns Regular string object + */ + std::string fromws(const wchar_t* ws); + + /** + * \brief Creates wide string object from char array + * + * \param [in] mbs Null-terminated string + * \returns Wide string object + */ + std::wstring tows(const char* mbs); + +#ifdef _WIN32 + using path_string = std::wstring; + inline path_string topath(const char* mbs) { return tows(mbs); } +#else + using path_string = std::string; + inline path_string topath(const char* mbs) { return std::string(mbs); } +#endif + + inline void format1(std::stringstream&) { } + + template + void format1(std::stringstream& str, const wchar_t *arg, const Tx&... args) { + str << fromws(arg); + format1(str, args...); + } + + template + void format1(std::stringstream& str, const T& arg, const Tx&... args) { + str << arg; + format1(str, args...); + } + + template + std::string format(const Args&... args) { + std::stringstream stream; + format1(stream, args...); + return stream.str(); + } + + inline void strlcpy(char* dst, const char* src, size_t count) { + if (count > 0) { + std::strncpy(dst, src, count - 1); + dst[count - 1] = '\0'; + } + } + + /** + * \brief Split string at one or more delimiters characters + * + * \param [in] string String to split + * \param [in] delims Delimiter characters + * \returns Vector of substring views + */ + inline std::vector split(std::string_view string, std::string_view delims = " ") { + std::vector tokens; + + for (size_t start = 0; start < string.size(); ) { + // Find first delimiter + const auto end = string.find_first_of(delims, start); + + // Add non-empty tokens + if (start != end) + tokens.emplace_back(string.substr(start, end-start)); + + // Break at the end of string + if (end == std::string_view::npos) + break; + + start = end + 1; + } + return tokens; + } +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_analysis.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_analysis.cpp new file mode 100644 index 0000000000..6064e9ee5d --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_analysis.cpp @@ -0,0 +1,254 @@ +#include "dxbc_analysis.h" + +namespace dxvk { + + DxbcAnalyzer::DxbcAnalyzer( + const DxbcModuleInfo& moduleInfo, + const DxbcProgramInfo& programInfo, + const Rc& isgn, + const Rc& osgn, + const Rc& psgn, + DxbcAnalysisInfo& analysis) + : m_isgn (isgn), + m_osgn (osgn), + m_psgn (psgn), + m_analysis(&analysis) { + // Get number of clipping and culling planes from the + // input and output signatures. We will need this to + // declare the shader input and output interfaces. + m_analysis->clipCullIn = getClipCullInfo(m_isgn); + m_analysis->clipCullOut = getClipCullInfo(m_osgn); + } + + + DxbcAnalyzer::~DxbcAnalyzer() { + + } + + + void DxbcAnalyzer::processInstruction(const DxbcShaderInstruction& ins) { + switch (ins.opClass) { + case DxbcInstClass::Atomic: { + const uint32_t operandId = ins.dstCount - 1; + + if (ins.dst[operandId].type == DxbcOperandType::UnorderedAccessView) { + const uint32_t registerId = ins.dst[operandId].idx[0].offset; + m_analysis->uavInfos[registerId].accessAtomicOp = true; + m_analysis->uavInfos[registerId].accessFlags |= VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + + // Check whether the atomic operation is order-invariant + DxvkAccessOp op = DxvkAccessOp::None; + + switch (ins.op) { + case DxbcOpcode::AtomicAnd: op = DxvkAccessOp::And; break; + case DxbcOpcode::AtomicOr: op = DxvkAccessOp::Or; break; + case DxbcOpcode::AtomicXor: op = DxvkAccessOp::Xor; break; + case DxbcOpcode::AtomicIAdd: op = DxvkAccessOp::Add; break; + case DxbcOpcode::AtomicIMax: op = DxvkAccessOp::IMax; break; + case DxbcOpcode::AtomicIMin: op = DxvkAccessOp::IMin; break; + case DxbcOpcode::AtomicUMax: op = DxvkAccessOp::UMax; break; + case DxbcOpcode::AtomicUMin: op = DxvkAccessOp::UMin; break; + default: break; + } + + setUavAccessOp(registerId, op); + } + } break; + + case DxbcInstClass::TextureSample: + case DxbcInstClass::TextureGather: + case DxbcInstClass::TextureQueryLod: + case DxbcInstClass::VectorDeriv: { + m_analysis->usesDerivatives = true; + } break; + + case DxbcInstClass::ControlFlow: { + if (ins.op == DxbcOpcode::Discard) + m_analysis->usesKill = true; + } break; + + case DxbcInstClass::BufferLoad: { + uint32_t operandId = ins.op == DxbcOpcode::LdStructured ? 2 : 1; + bool sparseFeedback = ins.dstCount == 2; + + if (ins.src[operandId].type == DxbcOperandType::UnorderedAccessView) { + const uint32_t registerId = ins.src[operandId].idx[0].offset; + m_analysis->uavInfos[registerId].accessFlags |= VK_ACCESS_SHADER_READ_BIT; + m_analysis->uavInfos[registerId].sparseFeedback |= sparseFeedback; + + setUavAccessOp(registerId, DxvkAccessOp::None); + } else if (ins.src[operandId].type == DxbcOperandType::Resource) { + const uint32_t registerId = ins.src[operandId].idx[0].offset; + m_analysis->srvInfos[registerId].sparseFeedback |= sparseFeedback; + } + } break; + + case DxbcInstClass::BufferStore: { + if (ins.dst[0].type == DxbcOperandType::UnorderedAccessView) { + const uint32_t registerId = ins.dst[0].idx[0].offset; + m_analysis->uavInfos[registerId].accessFlags |= VK_ACCESS_SHADER_WRITE_BIT; + + setUavAccessOp(registerId, getStoreAccessOp(ins.dst[0].mask, ins.src[ins.srcCount - 1u])); + } + } break; + + case DxbcInstClass::TypedUavLoad: { + const uint32_t registerId = ins.src[1].idx[0].offset; + m_analysis->uavInfos[registerId].accessTypedLoad = true; + m_analysis->uavInfos[registerId].accessFlags |= VK_ACCESS_SHADER_READ_BIT; + + setUavAccessOp(registerId, DxvkAccessOp::None); + } break; + + case DxbcInstClass::TypedUavStore: { + const uint32_t registerId = ins.dst[0].idx[0].offset; + m_analysis->uavInfos[registerId].accessFlags |= VK_ACCESS_SHADER_WRITE_BIT; + + // The UAV format may change between dispatches, so be conservative here + // and only allow this optimization when the app is writing zeroes. + DxvkAccessOp storeOp = getStoreAccessOp(DxbcRegMask(0xf), ins.src[1u]); + + if (storeOp != DxvkAccessOp(DxvkAccessOp::OpType::StoreUi, 0u)) + storeOp = DxvkAccessOp::None; + + setUavAccessOp(registerId, storeOp); + } break; + + case DxbcInstClass::Declaration: { + switch (ins.op) { + case DxbcOpcode::DclConstantBuffer: { + uint32_t registerId = ins.dst[0].idx[0].offset; + + if (registerId < DxbcConstBufBindingCount) + m_analysis->bindings.cbvMask |= 1u << registerId; + } break; + + case DxbcOpcode::DclSampler: { + uint32_t registerId = ins.dst[0].idx[0].offset; + + if (registerId < DxbcSamplerBindingCount) + m_analysis->bindings.samplerMask |= 1u << registerId; + } break; + + case DxbcOpcode::DclResource: + case DxbcOpcode::DclResourceRaw: + case DxbcOpcode::DclResourceStructured: { + uint32_t registerId = ins.dst[0].idx[0].offset; + + uint32_t idx = registerId / 64u; + uint32_t bit = registerId % 64u; + + if (registerId < DxbcResourceBindingCount) + m_analysis->bindings.srvMask[idx] |= uint64_t(1u) << bit; + } break; + + case DxbcOpcode::DclUavTyped: + case DxbcOpcode::DclUavRaw: + case DxbcOpcode::DclUavStructured: { + uint32_t registerId = ins.dst[0].idx[0].offset; + + if (registerId < DxbcUavBindingCount) + m_analysis->bindings.uavMask |= uint64_t(1u) << registerId; + } break; + + default: ; + } + } break; + + default: + break; + } + + for (uint32_t i = 0; i < ins.dstCount; i++) { + if (ins.dst[i].type == DxbcOperandType::IndexableTemp) { + uint32_t index = ins.dst[i].idx[0].offset; + m_analysis->xRegMasks[index] |= ins.dst[i].mask; + } + } + } + + + DxbcClipCullInfo DxbcAnalyzer::getClipCullInfo(const Rc& sgn) const { + DxbcClipCullInfo result; + + if (sgn != nullptr) { + for (auto e = sgn->begin(); e != sgn->end(); e++) { + const uint32_t componentCount = e->componentMask.popCount(); + + if (e->systemValue == DxbcSystemValue::ClipDistance) + result.numClipPlanes += componentCount; + if (e->systemValue == DxbcSystemValue::CullDistance) + result.numCullPlanes += componentCount; + } + } + + return result; + } + + + void DxbcAnalyzer::setUavAccessOp(uint32_t uav, DxvkAccessOp op) { + if (m_analysis->uavInfos[uav].accessOp == DxvkAccessOp::None) + m_analysis->uavInfos[uav].accessOp = op; + + // Maintain ordering if the UAV is accessed via other operations as well + if (op == DxvkAccessOp::None || m_analysis->uavInfos[uav].accessOp != op) + m_analysis->uavInfos[uav].nonInvariantAccess = true; + } + + + DxvkAccessOp DxbcAnalyzer::getStoreAccessOp(DxbcRegMask writeMask, const DxbcRegister& src) { + if (src.type != DxbcOperandType::Imm32) + return DxvkAccessOp::None; + + // Trivial case, same value is written to all components + if (src.componentCount == DxbcComponentCount::Component1) + return getConstantStoreOp(src.imm.u32_1); + + if (src.componentCount != DxbcComponentCount::Component4) + return DxvkAccessOp::None; + + // Otherwise, make sure that all written components are equal + DxvkAccessOp op = DxvkAccessOp::None; + + for (uint32_t i = 0u; i < 4u; i++) { + if (!writeMask[i]) + continue; + + // If the written value can't be represented, skip + DxvkAccessOp scalarOp = getConstantStoreOp(src.imm.u32_4[i]); + + if (scalarOp == DxvkAccessOp::None) + return DxvkAccessOp::None; + + // First component written + if (op == DxvkAccessOp::None) + op = scalarOp; + + // Conflicting store ops + if (op != scalarOp) + return DxvkAccessOp::None; + } + + return op; + } + + + DxvkAccessOp DxbcAnalyzer::getConstantStoreOp(uint32_t value) { + constexpr uint32_t mask = 0xfffu; + + uint32_t ubits = value & mask; + uint32_t fbits = (value >> 20u); + + if (value == ubits) + return DxvkAccessOp(DxvkAccessOp::OpType::StoreUi, ubits); + + if (value == (ubits | ~mask)) + return DxvkAccessOp(DxvkAccessOp::OpType::StoreSi, ubits); + + if (value == (fbits << 20u)) + return DxvkAccessOp(DxvkAccessOp::OpType::StoreF, fbits); + + return DxvkAccessOp::None; + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_chunk_isgn.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_chunk_isgn.cpp new file mode 100644 index 0000000000..80e540f234 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_chunk_isgn.cpp @@ -0,0 +1,112 @@ +#include "dxbc_chunk_isgn.h" + +namespace dxvk { + + DxbcIsgn::DxbcIsgn(DxbcReader reader, DxbcTag tag) { + uint32_t elementCount = reader.readu32(); + reader.skip(sizeof(uint32_t)); + + std::array componentTypes = { + DxbcScalarType::Uint32, DxbcScalarType::Uint32, + DxbcScalarType::Sint32, DxbcScalarType::Float32, + }; + + // https://github.com/DarkStarSword/3d-fixes/blob/master/dx11shaderanalyse.py#L101 + bool hasStream = (tag == "ISG1") || (tag == "OSG1") || (tag == "PSG1") || (tag == "OSG5"); + bool hasPrecision = (tag == "ISG1") || (tag == "OSG1") || (tag == "PSG1"); + + for (uint32_t i = 0; i < elementCount; i++) { + DxbcSgnEntry entry; + entry.streamId = hasStream ? reader.readu32() : 0; + entry.semanticName = reader.clone(reader.readu32()).readString(); + entry.semanticIndex = reader.readu32(); + entry.systemValue = static_cast(reader.readu32()); + entry.componentType = componentTypes.at(reader.readu32()); + entry.registerId = reader.readu32(); + + uint32_t mask = reader.readu32(); + + entry.componentMask = bit::extract(mask, 0, 3); + entry.componentUsed = bit::extract(mask, 8, 11); + + if (hasPrecision) + reader.readu32(); + + m_entries.push_back(entry); + } + } + + + DxbcIsgn::~DxbcIsgn() { + + } + + + const DxbcSgnEntry* DxbcIsgn::findByRegister(uint32_t registerId) const { + for (auto e = this->begin(); e != this->end(); e++) { + if (e->registerId == registerId) + return &(*e); + } + + return nullptr; + } + + + const DxbcSgnEntry* DxbcIsgn::find( + const std::string& semanticName, + uint32_t semanticIndex, + uint32_t streamId) const { + for (auto e = this->begin(); e != this->end(); e++) { + if (e->semanticIndex == semanticIndex + && e->streamId == streamId + && compareSemanticNames(semanticName, e->semanticName)) + return &(*e); + } + + return nullptr; + } + + + DxbcRegMask DxbcIsgn::regMask( + uint32_t registerId) const { + DxbcRegMask mask; + + for (auto e = this->begin(); e != this->end(); e++) { + if (e->registerId == registerId) + mask |= e->componentMask; + } + + return mask; + } + + + uint32_t DxbcIsgn::maxRegisterCount() const { + uint32_t result = 0; + for (auto e = this->begin(); e != this->end(); e++) + result = std::max(result, e->registerId + 1); + return result; + } + + + bool DxbcIsgn::compareSemanticNames( + const std::string& a, const std::string& b) { + if (a.size() != b.size()) + return false; + + for (size_t i = 0; i < a.size(); i++) { + char ac = a[i]; + char bc = b[i]; + + if (ac != bc) { + if (ac >= 'A' && ac <= 'Z') ac += 'a' - 'A'; + if (bc >= 'A' && bc <= 'Z') bc += 'a' - 'A'; + + if (ac != bc) + return false; + } + } + + return true; + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_chunk_shex.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_chunk_shex.cpp new file mode 100644 index 0000000000..552329b882 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_chunk_shex.cpp @@ -0,0 +1,24 @@ +#include "dxbc_chunk_shex.h" + +namespace dxvk { + + DxbcShex::DxbcShex(DxbcReader reader) { + // The shader version and type are stored in a 32-bit unit, + // where the first byte contains the major and minor version + // numbers, and the high word contains the program type. + reader.skip(2); + auto pType = reader.readEnum(); + m_programInfo = DxbcProgramInfo(pType); + + // Read the actual shader code as an array of DWORDs. + auto codeLength = reader.readu32() - 2; + m_code.resize(codeLength); + reader.read(m_code.data(), codeLength * sizeof(uint32_t)); + } + + + DxbcShex::~DxbcShex() { + + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_common.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_common.cpp new file mode 100644 index 0000000000..db3d715291 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_common.cpp @@ -0,0 +1,30 @@ +#include "dxbc_common.h" + +namespace dxvk { + + VkShaderStageFlagBits DxbcProgramInfo::shaderStage() const { + switch (m_type) { + case DxbcProgramType::PixelShader : return VK_SHADER_STAGE_FRAGMENT_BIT; + case DxbcProgramType::VertexShader : return VK_SHADER_STAGE_VERTEX_BIT; + case DxbcProgramType::GeometryShader : return VK_SHADER_STAGE_GEOMETRY_BIT; + case DxbcProgramType::HullShader : return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + case DxbcProgramType::DomainShader : return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + case DxbcProgramType::ComputeShader : return VK_SHADER_STAGE_COMPUTE_BIT; + default: throw DxvkError("DxbcProgramInfo::shaderStage: Unsupported program type"); + } + } + + + spv::ExecutionModel DxbcProgramInfo::executionModel() const { + switch (m_type) { + case DxbcProgramType::PixelShader : return spv::ExecutionModelFragment; + case DxbcProgramType::VertexShader : return spv::ExecutionModelVertex; + case DxbcProgramType::GeometryShader : return spv::ExecutionModelGeometry; + case DxbcProgramType::HullShader : return spv::ExecutionModelTessellationControl; + case DxbcProgramType::DomainShader : return spv::ExecutionModelTessellationEvaluation; + case DxbcProgramType::ComputeShader : return spv::ExecutionModelGLCompute; + default: throw DxvkError("DxbcProgramInfo::executionModel: Unsupported program type"); + } + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_compiler.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_compiler.cpp new file mode 100644 index 0000000000..0b6286fe5d --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_compiler.cpp @@ -0,0 +1,8242 @@ +#include "dxbc_compiler.h" + +namespace dxvk { + + constexpr uint32_t Icb_BindingSlotId = 14; + constexpr uint32_t Icb_MaxBakedDwords = 64; + + DxbcCompiler::DxbcCompiler( + const std::string& fileName, + const DxbcModuleInfo& moduleInfo, + const DxbcProgramInfo& programInfo, + const Rc& isgn, + const Rc& osgn, + const Rc& psgn, + const DxbcAnalysisInfo& analysis) + : m_moduleInfo (moduleInfo), + m_programInfo(programInfo), + m_module (spvVersion(1, 6)), + m_isgn (isgn), + m_osgn (osgn), + m_psgn (psgn), + m_analysis (&analysis) { + // Declare an entry point ID. We'll need it during the + // initialization phase where the execution mode is set. + m_entryPointId = m_module.allocateId(); + + // Set the shader name so that we recognize it in renderdoc + m_module.setDebugSource( + spv::SourceLanguageUnknown, 0, + m_module.addDebugString(fileName.c_str()), + nullptr); + + // Set the memory model. This is the same for all shaders. + m_module.enableCapability( + spv::CapabilityVulkanMemoryModel); + + m_module.setMemoryModel( + spv::AddressingModelLogical, + spv::MemoryModelVulkan); + + // Make sure our interface registers are clear + for (uint32_t i = 0; i < DxbcMaxInterfaceRegs; i++) { + m_vRegs.at(i) = DxbcRegisterPointer { }; + m_oRegs.at(i) = DxbcRegisterPointer { }; + } + + this->emitInit(); + } + + + DxbcCompiler::~DxbcCompiler() { + + } + + + void DxbcCompiler::processInstruction(const DxbcShaderInstruction& ins) { + m_lastOp = m_currOp; + m_currOp = ins.op; + + switch (ins.opClass) { + case DxbcInstClass::Declaration: + return this->emitDcl(ins); + + case DxbcInstClass::CustomData: + return this->emitCustomData(ins); + + case DxbcInstClass::Atomic: + return this->emitAtomic(ins); + + case DxbcInstClass::AtomicCounter: + return this->emitAtomicCounter(ins); + + case DxbcInstClass::Barrier: + return this->emitBarrier(ins); + + case DxbcInstClass::BitExtract: + return this->emitBitExtract(ins); + + case DxbcInstClass::BitInsert: + return this->emitBitInsert(ins); + + case DxbcInstClass::BitScan: + return this->emitBitScan(ins); + + case DxbcInstClass::BufferQuery: + return this->emitBufferQuery(ins); + + case DxbcInstClass::BufferLoad: + return this->emitBufferLoad(ins); + + case DxbcInstClass::BufferStore: + return this->emitBufferStore(ins); + + case DxbcInstClass::ConvertFloat16: + return this->emitConvertFloat16(ins); + + case DxbcInstClass::ConvertFloat64: + return this->emitConvertFloat64(ins); + + case DxbcInstClass::ControlFlow: + return this->emitControlFlow(ins); + + case DxbcInstClass::GeometryEmit: + return this->emitGeometryEmit(ins); + + case DxbcInstClass::HullShaderPhase: + return this->emitHullShaderPhase(ins); + + case DxbcInstClass::HullShaderInstCnt: + return this->emitHullShaderInstCnt(ins); + + case DxbcInstClass::Interpolate: + return this->emitInterpolate(ins); + + case DxbcInstClass::NoOperation: + return; + + case DxbcInstClass::SparseCheckAccess: + return this->emitSparseCheckAccess(ins); + + case DxbcInstClass::TextureQuery: + return this->emitTextureQuery(ins); + + case DxbcInstClass::TextureQueryLod: + return this->emitTextureQueryLod(ins); + + case DxbcInstClass::TextureQueryMs: + return this->emitTextureQueryMs(ins); + + case DxbcInstClass::TextureQueryMsPos: + return this->emitTextureQueryMsPos(ins); + + case DxbcInstClass::TextureFetch: + return this->emitTextureFetch(ins); + + case DxbcInstClass::TextureGather: + return this->emitTextureGather(ins); + + case DxbcInstClass::TextureSample: + return this->emitTextureSample(ins); + + case DxbcInstClass::TypedUavLoad: + return this->emitTypedUavLoad(ins); + + case DxbcInstClass::TypedUavStore: + return this->emitTypedUavStore(ins); + + case DxbcInstClass::VectorAlu: + return this->emitVectorAlu(ins); + + case DxbcInstClass::VectorCmov: + return this->emitVectorCmov(ins); + + case DxbcInstClass::VectorCmp: + return this->emitVectorCmp(ins); + + case DxbcInstClass::VectorDeriv: + return this->emitVectorDeriv(ins); + + case DxbcInstClass::VectorDot: + return this->emitVectorDot(ins); + + case DxbcInstClass::VectorIdiv: + return this->emitVectorIdiv(ins); + + case DxbcInstClass::VectorImul: + return this->emitVectorImul(ins); + + case DxbcInstClass::VectorMsad: + return this->emitVectorMsad(ins); + + case DxbcInstClass::VectorShift: + return this->emitVectorShift(ins); + + case DxbcInstClass::VectorSinCos: + return this->emitVectorSinCos(ins); + + default: + Logger::warn( + str::format("DxbcCompiler: Unhandled opcode class: ", + ins.op)); + } + } + + + void DxbcCompiler::processXfbPassthrough() { + m_module.setExecutionMode (m_entryPointId, spv::ExecutionModeInputPoints); + m_module.setExecutionMode (m_entryPointId, spv::ExecutionModeOutputPoints); + m_module.setOutputVertices(m_entryPointId, 1); + + for (auto e = m_isgn->begin(); e != m_isgn->end(); e++) { + emitDclInput(e->registerId, 1, + e->componentMask, DxbcSystemValue::None, + DxbcInterpolationMode::Undefined); + } + + // Figure out which streams to enable + uint32_t streamMask = 0; + + for (size_t i = 0; i < m_xfbVars.size(); i++) + streamMask |= 1u << m_xfbVars[i].streamId; + + for (uint32_t streamId : bit::BitMask(streamMask)) { + emitXfbOutputSetup(streamId, true); + m_module.opEmitVertex(m_module.constu32(streamId)); + } + + // End the main function + emitFunctionEnd(); + + // For pass-through we always assume points + m_inputTopology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + } + + + SpirvCodeBuffer DxbcCompiler::finalize() { + // Depending on the shader type, this will prepare + // input registers, call various shader functions + // and write back the output registers. + switch (m_programInfo.type()) { + case DxbcProgramType::VertexShader: this->emitVsFinalize(); break; + case DxbcProgramType::HullShader: this->emitHsFinalize(); break; + case DxbcProgramType::DomainShader: this->emitDsFinalize(); break; + case DxbcProgramType::GeometryShader: this->emitGsFinalize(); break; + case DxbcProgramType::PixelShader: this->emitPsFinalize(); break; + case DxbcProgramType::ComputeShader: this->emitCsFinalize(); break; + default: throw DxvkError("Invalid shader stage"); + } + + // Emit float control mode if the extension is supported + this->emitFloatControl(); + + // Declare the entry point, we now have all the + // information we need, including the interfaces + m_module.addEntryPoint(m_entryPointId, + m_programInfo.executionModel(), "main"); + m_module.setDebugName(m_entryPointId, "main"); + + return m_module.compile(); + } + + + void DxbcCompiler::emitDcl(const DxbcShaderInstruction& ins) { + switch (ins.op) { + case DxbcOpcode::DclGlobalFlags: + return this->emitDclGlobalFlags(ins); + + case DxbcOpcode::DclIndexRange: + return this->emitDclIndexRange(ins); + + case DxbcOpcode::DclTemps: + return this->emitDclTemps(ins); + + case DxbcOpcode::DclIndexableTemp: + return this->emitDclIndexableTemp(ins); + + case DxbcOpcode::DclInput: + case DxbcOpcode::DclInputSgv: + case DxbcOpcode::DclInputSiv: + case DxbcOpcode::DclInputPs: + case DxbcOpcode::DclInputPsSgv: + case DxbcOpcode::DclInputPsSiv: + case DxbcOpcode::DclOutput: + case DxbcOpcode::DclOutputSgv: + case DxbcOpcode::DclOutputSiv: + return this->emitDclInterfaceReg(ins); + + case DxbcOpcode::DclConstantBuffer: + return this->emitDclConstantBuffer(ins); + + case DxbcOpcode::DclSampler: + return this->emitDclSampler(ins); + + case DxbcOpcode::DclStream: + return this->emitDclStream(ins); + + case DxbcOpcode::DclUavTyped: + case DxbcOpcode::DclResource: + return this->emitDclResourceTyped(ins); + + case DxbcOpcode::DclUavRaw: + case DxbcOpcode::DclResourceRaw: + case DxbcOpcode::DclUavStructured: + case DxbcOpcode::DclResourceStructured: + return this->emitDclResourceRawStructured(ins); + + case DxbcOpcode::DclThreadGroupSharedMemoryRaw: + case DxbcOpcode::DclThreadGroupSharedMemoryStructured: + return this->emitDclThreadGroupSharedMemory(ins); + + case DxbcOpcode::DclGsInputPrimitive: + return this->emitDclGsInputPrimitive(ins); + + case DxbcOpcode::DclGsOutputPrimitiveTopology: + return this->emitDclGsOutputTopology(ins); + + case DxbcOpcode::DclMaxOutputVertexCount: + return this->emitDclMaxOutputVertexCount(ins); + + case DxbcOpcode::DclInputControlPointCount: + return this->emitDclInputControlPointCount(ins); + + case DxbcOpcode::DclOutputControlPointCount: + return this->emitDclOutputControlPointCount(ins); + + case DxbcOpcode::DclHsMaxTessFactor: + return this->emitDclHsMaxTessFactor(ins); + + case DxbcOpcode::DclTessDomain: + return this->emitDclTessDomain(ins); + + case DxbcOpcode::DclTessPartitioning: + return this->emitDclTessPartitioning(ins); + + case DxbcOpcode::DclTessOutputPrimitive: + return this->emitDclTessOutputPrimitive(ins); + + case DxbcOpcode::DclThreadGroup: + return this->emitDclThreadGroup(ins); + + case DxbcOpcode::DclGsInstanceCount: + return this->emitDclGsInstanceCount(ins); + + default: + Logger::warn( + str::format("DxbcCompiler: Unhandled opcode: ", + ins.op)); + } + } + + + void DxbcCompiler::emitDclGlobalFlags(const DxbcShaderInstruction& ins) { + const DxbcGlobalFlags flags = ins.controls.globalFlags(); + + if (flags.test(DxbcGlobalFlag::RefactoringAllowed)) + m_precise = false; + + if (flags.test(DxbcGlobalFlag::EarlyFragmentTests)) + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeEarlyFragmentTests); + } + + + void DxbcCompiler::emitDclIndexRange(const DxbcShaderInstruction& ins) { + // dcl_index_range has one operand: + // (0) Range start, either an input or output register + // (1) Range end + uint32_t index = ins.dst[0].idxDim - 1u; + + DxbcIndexRange range = { }; + range.type = ins.dst[0].type; + range.start = ins.dst[0].idx[index].offset; + range.length = ins.imm[0].u32; + + m_indexRanges.push_back(range); + } + + + void DxbcCompiler::emitDclTemps(const DxbcShaderInstruction& ins) { + // dcl_temps has one operand: + // (imm0) Number of temp registers + + // Ignore this and declare temps on demand. + } + + + void DxbcCompiler::emitDclIndexableTemp(const DxbcShaderInstruction& ins) { + // dcl_indexable_temps has three operands: + // (imm0) Array register index (x#) + // (imm1) Number of vectors stored in the array + // (imm2) Component count of each individual vector. This is + // always 4 in fxc-generated binaries and therefore useless. + const uint32_t regId = ins.imm[0].u32; + + DxbcRegisterInfo info; + info.type.ctype = DxbcScalarType::Float32; + info.type.ccount = m_analysis->xRegMasks.at(regId).minComponents(); + info.type.alength = ins.imm[1].u32; + info.sclass = spv::StorageClassPrivate; + + if (regId >= m_xRegs.size()) + m_xRegs.resize(regId + 1); + + m_xRegs.at(regId).ccount = info.type.ccount; + m_xRegs.at(regId).alength = info.type.alength; + m_xRegs.at(regId).varId = emitNewVariable(info); + + m_module.setDebugName(m_xRegs.at(regId).varId, + str::format("x", regId).c_str()); + } + + + void DxbcCompiler::emitDclInterfaceReg(const DxbcShaderInstruction& ins) { + switch (ins.dst[0].type) { + case DxbcOperandType::InputControlPoint: + if (m_programInfo.type() != DxbcProgramType::HullShader) + break; + [[fallthrough]]; + + case DxbcOperandType::Input: + case DxbcOperandType::Output: { + // dcl_input and dcl_output instructions + // have the following operands: + // (dst0) The register to declare + // (imm0) The system value (optional) + uint32_t regDim = 0; + uint32_t regIdx = 0; + + // In the vertex and fragment shader stage, the + // operand indices will have the following format: + // (0) Register index + // + // In other stages, the input and output registers + // may be declared as arrays of a fixed size: + // (0) Array length + // (1) Register index + if (ins.dst[0].idxDim == 2) { + regDim = ins.dst[0].idx[0].offset; + regIdx = ins.dst[0].idx[1].offset; + } else if (ins.dst[0].idxDim == 1) { + regIdx = ins.dst[0].idx[0].offset; + } else { + Logger::err(str::format( + "DxbcCompiler: ", ins.op, + ": Invalid index dimension")); + return; + } + + // This declaration may map an output register to a system + // value. If that is the case, the system value type will + // be stored in the second operand. + const bool hasSv = + ins.op == DxbcOpcode::DclInputSgv + || ins.op == DxbcOpcode::DclInputSiv + || ins.op == DxbcOpcode::DclInputPsSgv + || ins.op == DxbcOpcode::DclInputPsSiv + || ins.op == DxbcOpcode::DclOutputSgv + || ins.op == DxbcOpcode::DclOutputSiv; + + DxbcSystemValue sv = DxbcSystemValue::None; + + if (hasSv) + sv = static_cast(ins.imm[0].u32); + + // In the pixel shader, inputs are declared with an + // interpolation mode that is part of the op token. + const bool hasInterpolationMode = + ins.op == DxbcOpcode::DclInputPs + || ins.op == DxbcOpcode::DclInputPsSiv; + + DxbcInterpolationMode im = DxbcInterpolationMode::Undefined; + + if (hasInterpolationMode) + im = ins.controls.interpolation(); + + // Declare the actual input/output variable + switch (ins.op) { + case DxbcOpcode::DclInput: + case DxbcOpcode::DclInputSgv: + case DxbcOpcode::DclInputSiv: + case DxbcOpcode::DclInputPs: + case DxbcOpcode::DclInputPsSgv: + case DxbcOpcode::DclInputPsSiv: + this->emitDclInput(regIdx, regDim, ins.dst[0].mask, sv, im); + break; + + case DxbcOpcode::DclOutput: + case DxbcOpcode::DclOutputSgv: + case DxbcOpcode::DclOutputSiv: + this->emitDclOutput(regIdx, regDim, ins.dst[0].mask, sv, im); + break; + + default: + Logger::err(str::format( + "DxbcCompiler: Unexpected opcode: ", + ins.op)); + } + } break; + + case DxbcOperandType::InputThreadId: { + m_cs.builtinGlobalInvocationId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 3, 0 }, + spv::StorageClassInput }, + spv::BuiltInGlobalInvocationId, + "vThreadId"); + } break; + + case DxbcOperandType::InputThreadGroupId: { + m_cs.builtinWorkgroupId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 3, 0 }, + spv::StorageClassInput }, + spv::BuiltInWorkgroupId, + "vThreadGroupId"); + } break; + + case DxbcOperandType::InputThreadIdInGroup: { + m_cs.builtinLocalInvocationId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 3, 0 }, + spv::StorageClassInput }, + spv::BuiltInLocalInvocationId, + "vThreadIdInGroup"); + } break; + + case DxbcOperandType::InputThreadIndexInGroup: { + m_cs.builtinLocalInvocationIndex = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInLocalInvocationIndex, + "vThreadIndexInGroup"); + } break; + + case DxbcOperandType::InputCoverageMask: { + m_ps.builtinSampleMaskIn = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 1 }, + spv::StorageClassInput }, + spv::BuiltInSampleMask, + "vCoverage"); + } break; + + case DxbcOperandType::OutputCoverageMask: { + m_ps.builtinSampleMaskOut = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 1 }, + spv::StorageClassOutput }, + spv::BuiltInSampleMask, + "oMask"); + } break; + + case DxbcOperandType::OutputDepth: { + m_module.setExecutionMode(m_entryPointId, + spv::ExecutionModeDepthReplacing); + m_ps.builtinDepth = emitNewBuiltinVariable({ + { DxbcScalarType::Float32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInFragDepth, + "oDepth"); + } break; + + case DxbcOperandType::OutputStencilRef: { + m_module.enableExtension("SPV_EXT_shader_stencil_export"); + m_module.enableCapability(spv::CapabilityStencilExportEXT); + m_module.setExecutionMode(m_entryPointId, + spv::ExecutionModeStencilRefReplacingEXT); + m_ps.builtinStencilRef = emitNewBuiltinVariable({ + { DxbcScalarType::Sint32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInFragStencilRefEXT, + "oStencilRef"); + } break; + + case DxbcOperandType::OutputDepthGe: { + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeDepthReplacing); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeDepthGreater); + m_ps.builtinDepth = emitNewBuiltinVariable({ + { DxbcScalarType::Float32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInFragDepth, + "oDepthGe"); + } break; + + case DxbcOperandType::OutputDepthLe: { + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeDepthReplacing); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeDepthLess); + m_ps.builtinDepth = emitNewBuiltinVariable({ + { DxbcScalarType::Float32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInFragDepth, + "oDepthLe"); + } break; + + case DxbcOperandType::InputPrimitiveId: { + m_primitiveIdIn = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInPrimitiveId, + "vPrim"); + } break; + + case DxbcOperandType::InputDomainPoint: { + m_ds.builtinTessCoord = emitNewBuiltinVariable({ + { DxbcScalarType::Float32, 3, 0 }, + spv::StorageClassInput }, + spv::BuiltInTessCoord, + "vDomain"); + } break; + + case DxbcOperandType::InputForkInstanceId: + case DxbcOperandType::InputJoinInstanceId: { + auto phase = this->getCurrentHsForkJoinPhase(); + + phase->instanceIdPtr = m_module.newVar( + m_module.defPointerType( + m_module.defIntType(32, 0), + spv::StorageClassFunction), + spv::StorageClassFunction); + + m_module.opStore(phase->instanceIdPtr, phase->instanceId); + m_module.setDebugName(phase->instanceIdPtr, + ins.dst[0].type == DxbcOperandType::InputForkInstanceId + ? "vForkInstanceId" : "vJoinInstanceId"); + } break; + + case DxbcOperandType::OutputControlPointId: { + // This system value map to the invocation + // ID, which has been declared already. + } break; + + case DxbcOperandType::InputPatchConstant: + case DxbcOperandType::OutputControlPoint: { + // These have been declared as global input and + // output arrays, so there's nothing left to do. + } break; + + case DxbcOperandType::InputGsInstanceId: { + m_gs.builtinInvocationId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInInvocationId, + "vInstanceID"); + } break; + + case DxbcOperandType::InputInnerCoverage: { + m_module.enableExtension("SPV_EXT_fragment_fully_covered"); + m_module.enableCapability(spv::CapabilityFragmentFullyCoveredEXT); + + // This is bool in SPIR-V but uint32 in DXBC. A bool value of + // false must be 0, and bit 1 must be set to represent true. + uint32_t builtinId = emitNewBuiltinVariable({ + { DxbcScalarType::Bool, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInFullyCoveredEXT, + nullptr); + + m_ps.builtinInnerCoverageId = emitNewVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassPrivate }); + + m_module.setDebugName(m_ps.builtinInnerCoverageId, "vInnerCoverage"); + + uint32_t boolTypeId = m_module.defBoolType(); + uint32_t uintTypeId = m_module.defIntType(32, 0); + + m_module.opStore(m_ps.builtinInnerCoverageId, + m_module.opSelect(uintTypeId, + m_module.opLoad(boolTypeId, builtinId), + m_module.constu32(1), + m_module.constu32(0))); + } break; + + default: + Logger::err(str::format( + "DxbcCompiler: Unsupported operand type declaration: ", + ins.dst[0].type)); + + } + } + + + void DxbcCompiler::emitDclInput( + uint32_t regIdx, + uint32_t regDim, + DxbcRegMask regMask, + DxbcSystemValue sv, + DxbcInterpolationMode im) { + // Avoid declaring the same variable multiple times. + // This may happen when multiple system values are + // mapped to different parts of the same register. + if (m_vRegs.at(regIdx).id == 0 && sv == DxbcSystemValue::None) { + const DxbcVectorType regType = getInputRegType(regIdx); + + DxbcRegisterInfo info; + info.type.ctype = regType.ctype; + info.type.ccount = regType.ccount; + info.type.alength = regDim; + info.sclass = spv::StorageClassInput; + + const uint32_t varId = emitNewVariable(info); + + m_module.decorateLocation(varId, regIdx); + m_module.setDebugName(varId, str::format("v", regIdx).c_str()); + + m_vRegs.at(regIdx) = { regType, varId }; + + // Interpolation mode, used in pixel shaders + if (im == DxbcInterpolationMode::Constant) + m_module.decorate(varId, spv::DecorationFlat); + + if (im == DxbcInterpolationMode::LinearCentroid + || im == DxbcInterpolationMode::LinearNoPerspectiveCentroid) + m_module.decorate(varId, spv::DecorationCentroid); + + if (im == DxbcInterpolationMode::LinearNoPerspective + || im == DxbcInterpolationMode::LinearNoPerspectiveCentroid + || im == DxbcInterpolationMode::LinearNoPerspectiveSample) + m_module.decorate(varId, spv::DecorationNoPerspective); + + if (im == DxbcInterpolationMode::LinearSample + || im == DxbcInterpolationMode::LinearNoPerspectiveSample) { + m_module.enableCapability(spv::CapabilitySampleRateShading); + m_module.decorate(varId, spv::DecorationSample); + } + + if (m_moduleInfo.options.forceSampleRateShading) { + if (im == DxbcInterpolationMode::Linear + || im == DxbcInterpolationMode::LinearNoPerspective) { + m_module.enableCapability(spv::CapabilitySampleRateShading); + m_module.decorate(varId, spv::DecorationSample); + } + } + + // Declare the input slot as defined + m_inputMask |= 1u << regIdx; + m_vArrayLength = std::max(m_vArrayLength, regIdx + 1); + } else if (sv != DxbcSystemValue::None) { + // Add a new system value mapping if needed + bool skipSv = sv == DxbcSystemValue::ClipDistance + || sv == DxbcSystemValue::CullDistance; + + if (!skipSv) + m_vMappings.push_back({ regIdx, regMask, sv }); + } + } + + + void DxbcCompiler::emitDclOutput( + uint32_t regIdx, + uint32_t regDim, + DxbcRegMask regMask, + DxbcSystemValue sv, + DxbcInterpolationMode im) { + // Add a new system value mapping if needed. Clip + // and cull distances are handled separately. + if (sv != DxbcSystemValue::None + && sv != DxbcSystemValue::ClipDistance + && sv != DxbcSystemValue::CullDistance) + m_oMappings.push_back({ regIdx, regMask, sv }); + + if (m_programInfo.type() == DxbcProgramType::HullShader) { + // Hull shaders don't use standard outputs + if (getCurrentHsForkJoinPhase() != nullptr) + m_hs.outputPerPatchMask |= 1 << regIdx; + } else if (m_oRegs.at(regIdx).id == 0) { + // Avoid declaring the same variable multiple times. + // This may happen when multiple system values are + // mapped to different parts of the same register. + const DxbcVectorType regType = getOutputRegType(regIdx); + + DxbcRegisterInfo info; + info.type.ctype = regType.ctype; + info.type.ccount = regType.ccount; + info.type.alength = regDim; + info.sclass = spv::StorageClassOutput; + + // In xfb mode, we set up the actual + // output vars when emitting a vertex + if (m_moduleInfo.xfb != nullptr) + info.sclass = spv::StorageClassPrivate; + + // In geometry shaders, don't duplicate system value outputs + // to stay within device limits. The pixel shader will read + // all GS system value outputs as system value inputs. + if (m_programInfo.type() == DxbcProgramType::GeometryShader && sv != DxbcSystemValue::None) + info.sclass = spv::StorageClassPrivate; + + const uint32_t varId = this->emitNewVariable(info); + m_module.setDebugName(varId, str::format("o", regIdx).c_str()); + + if (info.sclass == spv::StorageClassOutput) { + m_module.decorateLocation(varId, regIdx); + + // Add index decoration for potential dual-source blending + if (m_programInfo.type() == DxbcProgramType::PixelShader) + m_module.decorateIndex(varId, 0); + + // Declare vertex positions in all stages as invariant, even if + // this is not the last stage, to help with potential Z fighting. + if (sv == DxbcSystemValue::Position && m_moduleInfo.options.invariantPosition) + m_module.decorate(varId, spv::DecorationInvariant); + } + + m_oRegs.at(regIdx) = { regType, varId }; + + // Declare the output slot as defined + m_outputMask |= 1u << regIdx; + } + } + + + void DxbcCompiler::emitDclConstantBuffer(const DxbcShaderInstruction& ins) { + // dcl_constant_buffer has one operand with two indices: + // (0) Constant buffer register ID (cb#) + // (1) Number of constants in the buffer + uint32_t bufferId = ins.dst[0].idx[0].offset; + uint32_t elementCount = ins.dst[0].idx[1].offset; + + // With dynamic indexing, games will often index constant buffers + // out of bounds. Declare an upper bound to stay within spec. + if (ins.controls.accessType() == DxbcConstantBufferAccessType::DynamicallyIndexed) + elementCount = 4096; + + this->emitDclConstantBufferVar(bufferId, elementCount, 4u, + str::format("cb", bufferId).c_str()); + } + + + void DxbcCompiler::emitDclConstantBufferVar( + uint32_t regIdx, + uint32_t numConstants, + uint32_t numComponents, + const char* name) { + // Uniform buffer data is stored as a fixed-size array + // of 4x32-bit vectors. SPIR-V requires explicit strides. + const uint32_t arrayType = m_module.defArrayTypeUnique( + getVectorTypeId({ DxbcScalarType::Float32, numComponents }), + m_module.constu32(numConstants)); + m_module.decorateArrayStride(arrayType, sizeof(uint32_t) * numComponents); + + // SPIR-V requires us to put that array into a + // struct and decorate that struct as a block. + const uint32_t structType = m_module.defStructTypeUnique(1, &arrayType); + + m_module.decorate(structType, spv::DecorationBlock); + m_module.memberDecorateOffset(structType, 0, 0); + + m_module.setDebugName (structType, str::format(name, "_t").c_str()); + m_module.setDebugMemberName (structType, 0, "m"); + + // Variable that we'll use to access the buffer + const uint32_t varId = m_module.newVar( + m_module.defPointerType(structType, spv::StorageClassUniform), + spv::StorageClassUniform); + + m_module.setDebugName(varId, name); + + // Compute the DXVK binding slot index for the buffer. + // D3D11 needs to bind the actual buffers to this slot. + uint32_t bindingId = computeConstantBufferBinding( + m_programInfo.type(), regIdx); + + m_module.decorateDescriptorSet(varId, 0); + m_module.decorateBinding(varId, bindingId); + + DxbcConstantBuffer buf; + buf.varId = varId; + buf.size = numConstants; + m_constantBuffers.at(regIdx) = buf; + + // Store descriptor info for the shader interface + DxvkBindingInfo binding = { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER }; + binding.viewType = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + binding.access = VK_ACCESS_UNIFORM_READ_BIT; + binding.resourceBinding = bindingId; + binding.uboSet = true; + m_bindings.push_back(binding); + } + + + void DxbcCompiler::emitDclSampler(const DxbcShaderInstruction& ins) { + // dclSampler takes one operand: + // (dst0) The sampler register to declare + const uint32_t samplerId = ins.dst[0].idx[0].offset; + + // The sampler type is opaque, but we still have to + // define a pointer and a variable in oder to use it + const uint32_t samplerType = m_module.defSamplerType(); + const uint32_t samplerPtrType = m_module.defPointerType( + samplerType, spv::StorageClassUniformConstant); + + // Define the sampler variable + const uint32_t varId = m_module.newVar(samplerPtrType, + spv::StorageClassUniformConstant); + m_module.setDebugName(varId, + str::format("s", samplerId).c_str()); + + m_samplers.at(samplerId).varId = varId; + m_samplers.at(samplerId).typeId = samplerType; + + // Compute binding slot index for the sampler + uint32_t bindingId = computeSamplerBinding( + m_programInfo.type(), samplerId); + + m_module.decorateDescriptorSet(varId, 0); + m_module.decorateBinding(varId, bindingId); + + // Store descriptor info for the shader interface + DxvkBindingInfo binding = { VK_DESCRIPTOR_TYPE_SAMPLER }; + binding.viewType = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + binding.resourceBinding = bindingId; + m_bindings.push_back(binding); + } + + + void DxbcCompiler::emitDclStream(const DxbcShaderInstruction& ins) { + if (ins.dst[0].idx[0].offset != 0 && m_moduleInfo.xfb == nullptr) + Logger::err("Dxbc: Multiple streams not supported"); + } + + + void DxbcCompiler::emitDclResourceTyped(const DxbcShaderInstruction& ins) { + // dclResource takes two operands: + // (dst0) The resource register ID + // (imm0) The resource return type + const uint32_t registerId = ins.dst[0].idx[0].offset; + + // We also handle unordered access views here + const bool isUav = ins.op == DxbcOpcode::DclUavTyped; + + if (isUav) { + if (m_moduleInfo.options.supportsTypedUavLoadR32) + m_module.enableCapability(spv::CapabilityStorageImageReadWithoutFormat); + m_module.enableCapability(spv::CapabilityStorageImageWriteWithoutFormat); + } + + // Defines the type of the resource (texture2D, ...) + const DxbcResourceDim resourceType = ins.controls.resourceDim(); + + // Defines the type of a read operation. DXBC has the ability + // to define four different types whereas SPIR-V only allows + // one, but in practice this should not be much of a problem. + auto xType = static_cast( + bit::extract(ins.imm[0].u32, 0, 3)); + auto yType = static_cast( + bit::extract(ins.imm[0].u32, 4, 7)); + auto zType = static_cast( + bit::extract(ins.imm[0].u32, 8, 11)); + auto wType = static_cast( + bit::extract(ins.imm[0].u32, 12, 15)); + + if ((xType != yType) || (xType != zType) || (xType != wType)) + Logger::warn("DxbcCompiler: dcl_resource: Ignoring resource return types"); + + // Declare the actual sampled type + const DxbcScalarType sampledType = [xType] { + switch (xType) { + // FIXME is this correct? There's no documentation about it + case DxbcResourceReturnType::Mixed: return DxbcScalarType::Uint32; + // FIXME do we have to manually clamp writes to SNORM/UNORM resources? + case DxbcResourceReturnType::Snorm: return DxbcScalarType::Float32; + case DxbcResourceReturnType::Unorm: return DxbcScalarType::Float32; + case DxbcResourceReturnType::Float: return DxbcScalarType::Float32; + case DxbcResourceReturnType::Sint: return DxbcScalarType::Sint32; + case DxbcResourceReturnType::Uint: return DxbcScalarType::Uint32; + default: throw DxvkError(str::format("DxbcCompiler: Invalid sampled type: ", xType)); + } + }(); + + // Declare the resource type + const uint32_t sampledTypeId = getScalarTypeId(sampledType); + const DxbcImageInfo typeInfo = getResourceType(resourceType, isUav); + + // Declare additional capabilities if necessary + switch (resourceType) { + case DxbcResourceDim::Buffer: + m_module.enableCapability(isUav + ? spv::CapabilityImageBuffer + : spv::CapabilitySampledBuffer); + break; + + case DxbcResourceDim::Texture1D: + case DxbcResourceDim::Texture1DArr: + m_module.enableCapability(isUav + ? spv::CapabilityImage1D + : spv::CapabilitySampled1D); + break; + + case DxbcResourceDim::TextureCubeArr: + m_module.enableCapability( + spv::CapabilitySampledCubeArray); + break; + + default: + // No additional capabilities required + break; + } + + // If the read-without-format capability is not set and this + // image is access via a typed load, or if atomic operations + // are used,, we must define the image format explicitly. + spv::ImageFormat imageFormat = spv::ImageFormatUnknown; + + if (isUav) { + if ((m_analysis->uavInfos[registerId].accessAtomicOp) + || (m_analysis->uavInfos[registerId].accessTypedLoad + && !m_moduleInfo.options.supportsTypedUavLoadR32)) + imageFormat = getScalarImageFormat(sampledType); + } + + // We do not know whether the image is going to be used as + // a color image or a depth image yet, but we can pick the + // correct type when creating a sampled image object. + const uint32_t imageTypeId = m_module.defImageType(sampledTypeId, + typeInfo.dim, 0, typeInfo.array, typeInfo.ms, typeInfo.sampled, + imageFormat); + + // We'll declare the texture variable with the color type + // and decide which one to use when the texture is sampled. + const uint32_t resourcePtrType = m_module.defPointerType( + imageTypeId, spv::StorageClassUniformConstant); + + const uint32_t varId = m_module.newVar(resourcePtrType, + spv::StorageClassUniformConstant); + + m_module.setDebugName(varId, + str::format(isUav ? "u" : "t", registerId).c_str()); + + // Compute the DXVK binding slot index for the resource. + // D3D11 needs to bind the actual resource to this slot. + uint32_t bindingId = isUav + ? computeUavBinding(m_programInfo.type(), registerId) + : computeSrvBinding(m_programInfo.type(), registerId); + + m_module.decorateDescriptorSet(varId, 0); + m_module.decorateBinding(varId, bindingId); + + // Declare a specialization constant which will + // store whether or not the resource is bound. + if (isUav) { + DxbcUav uav; + uav.type = DxbcResourceType::Typed; + uav.imageInfo = typeInfo; + uav.varId = varId; + uav.ctrId = 0; + uav.sampledType = sampledType; + uav.sampledTypeId = sampledTypeId; + uav.imageTypeId = imageTypeId; + uav.structStride = 0; + uav.coherence = getUavCoherence(registerId, ins.controls.uavFlags()); + uav.isRawSsbo = false; + m_uavs.at(registerId) = uav; + } else { + DxbcShaderResource res; + res.type = DxbcResourceType::Typed; + res.imageInfo = typeInfo; + res.varId = varId; + res.sampledType = sampledType; + res.sampledTypeId = sampledTypeId; + res.imageTypeId = imageTypeId; + res.colorTypeId = imageTypeId; + res.depthTypeId = 0; + res.structStride = 0; + res.isRawSsbo = false; + + if ((sampledType == DxbcScalarType::Float32) + && (resourceType == DxbcResourceDim::Texture1D + || resourceType == DxbcResourceDim::Texture1DArr + || resourceType == DxbcResourceDim::Texture2D + || resourceType == DxbcResourceDim::Texture2DArr + || resourceType == DxbcResourceDim::TextureCube + || resourceType == DxbcResourceDim::TextureCubeArr)) { + res.depthTypeId = m_module.defImageType(sampledTypeId, + typeInfo.dim, 1, typeInfo.array, typeInfo.ms, typeInfo.sampled, + spv::ImageFormatUnknown); + } + + m_textures.at(registerId) = res; + } + + // Store descriptor info for the shader interface + DxvkBindingInfo binding = { }; + binding.viewType = typeInfo.vtype; + binding.resourceBinding = bindingId; + binding.isMultisampled = typeInfo.ms; + + if (isUav) { + binding.descriptorType = resourceType == DxbcResourceDim::Buffer + ? VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER + : VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + binding.access = m_analysis->uavInfos[registerId].accessFlags; + + if (!m_analysis->uavInfos[registerId].nonInvariantAccess) + binding.accessOp = m_analysis->uavInfos[registerId].accessOp; + + if (!(binding.access & VK_ACCESS_SHADER_WRITE_BIT)) + m_module.decorate(varId, spv::DecorationNonWritable); + if (!(binding.access & VK_ACCESS_SHADER_READ_BIT)) + m_module.decorate(varId, spv::DecorationNonReadable); + } else { + binding.descriptorType = resourceType == DxbcResourceDim::Buffer + ? VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER + : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + binding.access = VK_ACCESS_SHADER_READ_BIT; + } + + m_bindings.push_back(binding); + } + + + void DxbcCompiler::emitDclResourceRawStructured(const DxbcShaderInstruction& ins) { + // dcl_resource_raw and dcl_uav_raw take one argument: + // (dst0) The resource register ID + // dcl_resource_structured and dcl_uav_structured take two arguments: + // (dst0) The resource register ID + // (imm0) Structure stride, in bytes + const uint32_t registerId = ins.dst[0].idx[0].offset; + + const bool isUav = ins.op == DxbcOpcode::DclUavRaw + || ins.op == DxbcOpcode::DclUavStructured; + + const bool isStructured = ins.op == DxbcOpcode::DclUavStructured + || ins.op == DxbcOpcode::DclResourceStructured; + + const DxbcScalarType sampledType = DxbcScalarType::Uint32; + const uint32_t sampledTypeId = getScalarTypeId(sampledType); + + const DxbcImageInfo typeInfo = { spv::DimBuffer, 0, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_MAX_ENUM }; + + // Declare the resource type + uint32_t resTypeId = 0; + uint32_t varId = 0; + + // Write back resource info + DxbcResourceType resType = isStructured + ? DxbcResourceType::Structured + : DxbcResourceType::Raw; + + uint32_t resStride = isStructured + ? ins.imm[0].u32 + : 0; + + uint32_t resAlign = isStructured + ? (resStride & -resStride) + : 16; + + // Compute the DXVK binding slot index for the resource. + uint32_t bindingId = isUav + ? computeUavBinding(m_programInfo.type(), registerId) + : computeSrvBinding(m_programInfo.type(), registerId); + + // Test whether we should use a raw SSBO for this resource + bool hasSparseFeedback = isUav + ? m_analysis->uavInfos[registerId].sparseFeedback + : m_analysis->srvInfos[registerId].sparseFeedback; + + bool useRawSsbo = m_moduleInfo.options.minSsboAlignment <= resAlign && !hasSparseFeedback; + + if (useRawSsbo) { + uint32_t elemType = getScalarTypeId(DxbcScalarType::Uint32); + uint32_t arrayType = m_module.defRuntimeArrayTypeUnique(elemType); + uint32_t structType = m_module.defStructTypeUnique(1, &arrayType); + uint32_t ptrType = m_module.defPointerType(structType, spv::StorageClassStorageBuffer); + + resTypeId = m_module.defPointerType(elemType, spv::StorageClassStorageBuffer); + varId = m_module.newVar(ptrType, spv::StorageClassStorageBuffer); + + m_module.decorateArrayStride(arrayType, sizeof(uint32_t)); + m_module.decorate(structType, spv::DecorationBlock); + m_module.memberDecorateOffset(structType, 0, 0); + + m_module.setDebugName(structType, + str::format(isUav ? "u" : "t", registerId, "_t").c_str()); + m_module.setDebugMemberName(structType, 0, "m"); + } else { + // Structured and raw buffers are represented as + // texel buffers consisting of 32-bit integers. + m_module.enableCapability(isUav + ? spv::CapabilityImageBuffer + : spv::CapabilitySampledBuffer); + + resTypeId = m_module.defImageType(sampledTypeId, + typeInfo.dim, 0, typeInfo.array, typeInfo.ms, typeInfo.sampled, + spv::ImageFormatR32ui); + + varId = m_module.newVar( + m_module.defPointerType(resTypeId, spv::StorageClassUniformConstant), + spv::StorageClassUniformConstant); + } + + m_module.setDebugName(varId, + str::format(isUav ? "u" : "t", registerId).c_str()); + + m_module.decorateDescriptorSet(varId, 0); + m_module.decorateBinding(varId, bindingId); + + if (isUav) { + DxbcUav uav; + uav.type = resType; + uav.imageInfo = typeInfo; + uav.varId = varId; + uav.ctrId = 0; + uav.sampledType = sampledType; + uav.sampledTypeId = sampledTypeId; + uav.imageTypeId = resTypeId; + uav.structStride = resStride; + uav.coherence = getUavCoherence(registerId, ins.controls.uavFlags()); + uav.isRawSsbo = useRawSsbo; + m_uavs.at(registerId) = uav; + } else { + DxbcShaderResource res; + res.type = resType; + res.imageInfo = typeInfo; + res.varId = varId; + res.sampledType = sampledType; + res.sampledTypeId = sampledTypeId; + res.imageTypeId = resTypeId; + res.colorTypeId = resTypeId; + res.depthTypeId = 0; + res.structStride = resStride; + res.isRawSsbo = useRawSsbo; + m_textures.at(registerId) = res; + } + + // Store descriptor info for the shader interface + DxvkBindingInfo binding = { }; + binding.descriptorType = useRawSsbo + ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER + : (isUav ? VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER); + binding.viewType = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + binding.resourceBinding = bindingId; + binding.access = VK_ACCESS_SHADER_READ_BIT; + + if (isUav) { + binding.access = m_analysis->uavInfos[registerId].accessFlags; + + if (!m_analysis->uavInfos[registerId].nonInvariantAccess) + binding.accessOp = m_analysis->uavInfos[registerId].accessOp; + } + + if (useRawSsbo || isUav) { + if (!(binding.access & VK_ACCESS_SHADER_WRITE_BIT)) + m_module.decorate(varId, spv::DecorationNonWritable); + if (!(binding.access & VK_ACCESS_SHADER_READ_BIT)) + m_module.decorate(varId, spv::DecorationNonReadable); + } + + m_bindings.push_back(binding); + + // If supported, we'll be using raw access chains to access this + if (!m_hasRawAccessChains && m_moduleInfo.options.supportsRawAccessChains) { + m_module.enableExtension("SPV_NV_raw_access_chains"); + m_module.enableCapability(spv::CapabilityRawAccessChainsNV); + + m_hasRawAccessChains = true; + } + } + + + void DxbcCompiler::emitDclThreadGroupSharedMemory(const DxbcShaderInstruction& ins) { + // dcl_tgsm_raw takes two arguments: + // (dst0) The resource register ID + // (imm0) Block size, in bytes + // dcl_tgsm_structured takes three arguments: + // (dst0) The resource register ID + // (imm0) Structure stride, in bytes + // (imm1) Structure count + const bool isStructured = ins.op == DxbcOpcode::DclThreadGroupSharedMemoryStructured; + + const uint32_t regId = ins.dst[0].idx[0].offset; + + if (regId >= m_gRegs.size()) + m_gRegs.resize(regId + 1); + + const uint32_t elementStride = isStructured ? ins.imm[0].u32 : 0; + const uint32_t elementCount = isStructured ? ins.imm[1].u32 : ins.imm[0].u32; + + DxbcRegisterInfo varInfo; + varInfo.type.ctype = DxbcScalarType::Uint32; + varInfo.type.ccount = 1; + varInfo.type.alength = isStructured + ? elementCount * elementStride / 4 + : elementCount / 4; + varInfo.sclass = spv::StorageClassWorkgroup; + + m_gRegs[regId].type = isStructured + ? DxbcResourceType::Structured + : DxbcResourceType::Raw; + m_gRegs[regId].elementStride = elementStride; + m_gRegs[regId].elementCount = elementCount; + m_gRegs[regId].varId = emitNewVariable(varInfo); + + m_module.setDebugName(m_gRegs[regId].varId, + str::format("g", regId).c_str()); + } + + + void DxbcCompiler::emitDclGsInputPrimitive(const DxbcShaderInstruction& ins) { + // The input primitive type is stored within in the + // control bits of the opcode token. In SPIR-V, we + // have to define an execution mode. + const auto mode = [&] { + switch (ins.controls.primitive()) { + case DxbcPrimitive::Point: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_POINT_LIST, spv::ExecutionModeInputPoints); + case DxbcPrimitive::Line: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_LINE_LIST, spv::ExecutionModeInputLines); + case DxbcPrimitive::Triangle: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, spv::ExecutionModeTriangles); + case DxbcPrimitive::LineAdj: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, spv::ExecutionModeInputLinesAdjacency); + case DxbcPrimitive::TriangleAdj: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, spv::ExecutionModeInputTrianglesAdjacency); + default: throw DxvkError("DxbcCompiler: Unsupported primitive type"); + } + }(); + + m_gs.inputPrimitive = ins.controls.primitive(); + m_module.setExecutionMode(m_entryPointId, mode.second); + m_inputTopology = mode.first; + + emitDclInputArray(primitiveVertexCount(m_gs.inputPrimitive)); + } + + + void DxbcCompiler::emitDclGsOutputTopology(const DxbcShaderInstruction& ins) { + // The input primitive topology is stored within in the + // control bits of the opcode token. In SPIR-V, we have + // to define an execution mode. + auto mode = [&] { + switch (ins.controls.primitiveTopology()) { + case DxbcPrimitiveTopology::PointList: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_POINT_LIST, spv::ExecutionModeOutputPoints); + case DxbcPrimitiveTopology::LineStrip: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_LINE_LIST, spv::ExecutionModeOutputLineStrip); + case DxbcPrimitiveTopology::TriangleStrip: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, spv::ExecutionModeOutputTriangleStrip); + default: throw DxvkError("DxbcCompiler: Unsupported primitive topology"); + } + }(); + + m_outputTopology = mode.first; + m_module.setExecutionMode(m_entryPointId, mode.second); + } + + + void DxbcCompiler::emitDclMaxOutputVertexCount(const DxbcShaderInstruction& ins) { + // dcl_max_output_vertex_count has one operand: + // (imm0) The maximum number of vertices + m_gs.outputVertexCount = ins.imm[0].u32; + + m_module.setOutputVertices(m_entryPointId, m_gs.outputVertexCount); + } + + + void DxbcCompiler::emitDclInputControlPointCount(const DxbcShaderInstruction& ins) { + // dcl_input_control_points has the control point + // count embedded within the opcode token. + if (m_programInfo.type() == DxbcProgramType::HullShader) { + m_hs.vertexCountIn = ins.controls.controlPointCount(); + + emitDclInputArray(m_hs.vertexCountIn); + } else { + m_ds.vertexCountIn = ins.controls.controlPointCount(); + + m_ds.inputPerPatch = emitTessInterfacePerPatch (spv::StorageClassInput); + m_ds.inputPerVertex = emitTessInterfacePerVertex(spv::StorageClassInput, m_ds.vertexCountIn); + } + } + + + void DxbcCompiler::emitDclOutputControlPointCount(const DxbcShaderInstruction& ins) { + // dcl_output_control_points has the control point + // count embedded within the opcode token. + m_hs.vertexCountOut = ins.controls.controlPointCount(); + + m_hs.outputPerPatch = emitTessInterfacePerPatch(spv::StorageClassPrivate); + m_hs.outputPerVertex = emitTessInterfacePerVertex(spv::StorageClassOutput, m_hs.vertexCountOut); + + m_module.setOutputVertices(m_entryPointId, m_hs.vertexCountOut); + } + + + void DxbcCompiler::emitDclHsMaxTessFactor(const DxbcShaderInstruction& ins) { + m_hs.maxTessFactor = ins.imm[0].f32; + } + + + void DxbcCompiler::emitDclTessDomain(const DxbcShaderInstruction& ins) { + auto mode = [&] { + switch (ins.controls.tessDomain()) { + case DxbcTessDomain::Isolines: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_LINE_LIST, spv::ExecutionModeIsolines); + case DxbcTessDomain::Triangles: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, spv::ExecutionModeTriangles); + case DxbcTessDomain::Quads: return std::make_pair(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, spv::ExecutionModeQuads); + default: throw DxvkError("Dxbc: Invalid tess domain"); + } + }(); + + m_outputTopology = mode.first; + m_module.setExecutionMode(m_entryPointId, mode.second); + } + + + void DxbcCompiler::emitDclTessPartitioning(const DxbcShaderInstruction& ins) { + const spv::ExecutionMode executionMode = [&] { + switch (ins.controls.tessPartitioning()) { + case DxbcTessPartitioning::Pow2: + case DxbcTessPartitioning::Integer: return spv::ExecutionModeSpacingEqual; + case DxbcTessPartitioning::FractOdd: return spv::ExecutionModeSpacingFractionalOdd; + case DxbcTessPartitioning::FractEven: return spv::ExecutionModeSpacingFractionalEven; + default: throw DxvkError("Dxbc: Invalid tess partitioning"); + } + }(); + + m_module.setExecutionMode(m_entryPointId, executionMode); + } + + + void DxbcCompiler::emitDclTessOutputPrimitive(const DxbcShaderInstruction& ins) { + switch (ins.controls.tessOutputPrimitive()) { + case DxbcTessOutputPrimitive::Point: + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModePointMode); + break; + + case DxbcTessOutputPrimitive::Line: + break; + + case DxbcTessOutputPrimitive::TriangleCw: + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeVertexOrderCw); + break; + + case DxbcTessOutputPrimitive::TriangleCcw: + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeVertexOrderCcw); + break; + + default: + throw DxvkError("Dxbc: Invalid tess output primitive"); + } + } + + + void DxbcCompiler::emitDclThreadGroup(const DxbcShaderInstruction& ins) { + // dcl_thread_group has three operands: + // (imm0) Number of threads in X dimension + // (imm1) Number of threads in Y dimension + // (imm2) Number of threads in Z dimension + m_cs.workgroupSizeX = ins.imm[0].u32; + m_cs.workgroupSizeY = ins.imm[1].u32; + m_cs.workgroupSizeZ = ins.imm[2].u32; + + m_module.setLocalSize(m_entryPointId, + ins.imm[0].u32, ins.imm[1].u32, ins.imm[2].u32); + } + + + void DxbcCompiler::emitDclGsInstanceCount(const DxbcShaderInstruction& ins) { + // dcl_gs_instance_count has one operand: + // (imm0) Number of geometry shader invocations + m_module.setInvocations(m_entryPointId, ins.imm[0].u32); + m_gs.invocationCount = ins.imm[0].u32; + } + + + uint32_t DxbcCompiler::emitDclUavCounter(uint32_t regId) { + // Declare a structure type which holds the UAV counter + if (m_uavCtrStructType == 0) { + const uint32_t t_u32 = m_module.defIntType(32, 0); + const uint32_t t_struct = m_module.defStructTypeUnique(1, &t_u32); + + m_module.decorate(t_struct, spv::DecorationBlock); + m_module.memberDecorateOffset(t_struct, 0, 0); + + m_module.setDebugName (t_struct, "uav_meta"); + m_module.setDebugMemberName(t_struct, 0, "ctr"); + + m_uavCtrStructType = t_struct; + m_uavCtrPointerType = m_module.defPointerType( + t_struct, spv::StorageClassStorageBuffer); + } + + // Declare the buffer variable + const uint32_t varId = m_module.newVar( + m_uavCtrPointerType, spv::StorageClassStorageBuffer); + + m_module.setDebugName(varId, + str::format("u", regId, "_meta").c_str()); + + uint32_t bindingId = computeUavCounterBinding( + m_programInfo.type(), regId); + + m_module.decorateDescriptorSet(varId, 0); + m_module.decorateBinding(varId, bindingId); + + // Declare the storage buffer binding + DxvkBindingInfo binding = { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER }; + binding.resourceBinding = bindingId; + binding.viewType = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + binding.access = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + m_bindings.push_back(binding); + + return varId; + } + + + void DxbcCompiler::emitDclImmediateConstantBuffer(const DxbcShaderInstruction& ins) { + if (m_icbArray) + throw DxvkError("DxbcCompiler: Immediate constant buffer already declared"); + + if ((ins.customDataSize & 0x3) != 0) + throw DxvkError("DxbcCompiler: Immediate constant buffer size not a multiple of four DWORDs"); + + // A lot of the time we'll be dealing with a scalar or vec2 + // array here, there's no reason to emit all those zeroes. + uint32_t componentCount = 1u; + + for (uint32_t i = 0; i < ins.customDataSize; i += 4u) { + for (uint32_t c = componentCount; c < 4u; c++) { + if (ins.customData[i + c]) + componentCount = c + 1u; + } + + if (componentCount == 4u) + break; + } + + uint32_t vectorCount = (ins.customDataSize / 4u); + uint32_t dwordCount = vectorCount * componentCount; + + if (dwordCount <= Icb_MaxBakedDwords) { + this->emitDclImmediateConstantBufferBaked( + ins.customDataSize, ins.customData, componentCount); + } else { + this->emitDclImmediateConstantBufferUbo( + ins.customDataSize, ins.customData, componentCount); + } + } + + + void DxbcCompiler::emitDclImmediateConstantBufferBaked( + uint32_t dwordCount, + const uint32_t* dwordArray, + uint32_t componentCount) { + // Declare individual vector constants as 4x32-bit vectors + small_vector vectorIds; + + DxbcVectorType vecType; + vecType.ctype = DxbcScalarType::Uint32; + vecType.ccount = componentCount; + + uint32_t vectorTypeId = getVectorTypeId(vecType); + + for (uint32_t i = 0; i < dwordCount; i += 4u) { + std::array scalarIds = { }; + + for (uint32_t c = 0; c < componentCount; c++) + scalarIds[c] = m_module.constu32(dwordArray[i + c]); + + uint32_t id = scalarIds[0]; + + if (componentCount > 1u) + id = m_module.constComposite(vectorTypeId, componentCount, scalarIds.data()); + + vectorIds.push_back(id); + } + + // Pad array with one entry of zeroes so that we can + // handle out-of-bounds accesses more conveniently. + vectorIds.push_back(emitBuildZeroVector(vecType).id); + + // Declare the array that contains all the vectors + DxbcArrayType arrInfo; + arrInfo.ctype = DxbcScalarType::Uint32; + arrInfo.ccount = componentCount; + arrInfo.alength = vectorIds.size(); + + uint32_t arrayTypeId = getArrayTypeId(arrInfo); + uint32_t arrayId = m_module.constComposite( + arrayTypeId, vectorIds.size(), vectorIds.data()); + + // Declare the variable that will hold the constant + // data and initialize it with the constant array. + uint32_t pointerTypeId = m_module.defPointerType( + arrayTypeId, spv::StorageClassPrivate); + + m_icbArray = m_module.newVarInit( + pointerTypeId, spv::StorageClassPrivate, + arrayId); + + m_module.setDebugName(m_icbArray, "icb"); + m_module.decorate(m_icbArray, spv::DecorationNonWritable); + + m_icbComponents = componentCount; + m_icbSize = dwordCount / 4u; + } + + + void DxbcCompiler::emitDclImmediateConstantBufferUbo( + uint32_t dwordCount, + const uint32_t* dwordArray, + uint32_t componentCount) { + uint32_t vectorCount = dwordCount / 4u; + + // Tightly pack vec2 or scalar arrays if possible. Don't bother with + // vec3 since we'd rather have properly vectorized loads in that case. + if (m_moduleInfo.options.supportsTightIcbPacking && componentCount <= 2u) + m_icbComponents = componentCount; + else + m_icbComponents = 4u; + + // Immediate constant buffer can be read out of bounds, declare + // it with the maximum possible size and rely on robustness. + this->emitDclConstantBufferVar(Icb_BindingSlotId, 4096u, m_icbComponents, "icb"); + + m_icbData.reserve(vectorCount * componentCount); + + for (uint32_t i = 0; i < dwordCount; i += 4u) { + for (uint32_t c = 0; c < m_icbComponents; c++) + m_icbData.push_back(dwordArray[i + c]); + } + + m_icbSize = vectorCount; + } + + + void DxbcCompiler::emitCustomData(const DxbcShaderInstruction& ins) { + switch (ins.customDataType) { + case DxbcCustomDataClass::ImmConstBuf: + return emitDclImmediateConstantBuffer(ins); + + default: + Logger::warn(str::format( + "DxbcCompiler: Unsupported custom data block: ", + ins.customDataType)); + } + } + + + void DxbcCompiler::emitVectorAlu(const DxbcShaderInstruction& ins) { + std::array src; + + for (uint32_t i = 0; i < ins.srcCount; i++) + src.at(i) = emitRegisterLoad(ins.src[i], ins.dst[0].mask); + + DxbcRegisterValue dst; + dst.type.ctype = ins.dst[0].dataType; + dst.type.ccount = ins.dst[0].mask.popCount(); + + if (isDoubleType(ins.dst[0].dataType)) + dst.type.ccount /= 2; + + const uint32_t typeId = getVectorTypeId(dst.type); + + switch (ins.op) { + ///////////////////// + // Move instructions + case DxbcOpcode::Mov: + case DxbcOpcode::DMov: + dst.id = src.at(0).id; + break; + + ///////////////////////////////////// + // ALU operations on float32 numbers + case DxbcOpcode::Add: + case DxbcOpcode::DAdd: + dst.id = m_module.opFAdd(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Div: + case DxbcOpcode::DDiv: + dst.id = m_module.opFDiv(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Exp: + dst.id = m_module.opExp2( + typeId, src.at(0).id); + break; + + case DxbcOpcode::Frc: + dst.id = m_module.opFract( + typeId, src.at(0).id); + break; + + case DxbcOpcode::Log: + dst.id = m_module.opLog2( + typeId, src.at(0).id); + break; + + case DxbcOpcode::Mad: + case DxbcOpcode::DFma: + if (ins.controls.precise()) { + // FXC only emits precise mad if the shader explicitly uses + // the HLSL mad()/fma() intrinsics, let's preserve that. + dst.id = m_module.opFFma(typeId, + src.at(0).id, src.at(1).id, src.at(2).id); + } else { + dst.id = m_module.opFMul(typeId, src.at(0).id, src.at(1).id); + dst.id = m_module.opFAdd(typeId, dst.id, src.at(2).id); + } + break; + + case DxbcOpcode::Max: + case DxbcOpcode::DMax: + dst.id = m_module.opNMax(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Min: + case DxbcOpcode::DMin: + dst.id = m_module.opNMin(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Mul: + case DxbcOpcode::DMul: + dst.id = m_module.opFMul(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Rcp: + dst.id = m_module.opFDiv(typeId, + emitBuildConstVecf32( + 1.0f, 1.0f, 1.0f, 1.0f, + ins.dst[0].mask).id, + src.at(0).id); + break; + + case DxbcOpcode::DRcp: + dst.id = m_module.opFDiv(typeId, + emitBuildConstVecf64(1.0, 1.0, + ins.dst[0].mask).id, + src.at(0).id); + break; + + case DxbcOpcode::RoundNe: + dst.id = m_module.opRoundEven( + typeId, src.at(0).id); + break; + + case DxbcOpcode::RoundNi: + dst.id = m_module.opFloor( + typeId, src.at(0).id); + break; + + case DxbcOpcode::RoundPi: + dst.id = m_module.opCeil( + typeId, src.at(0).id); + break; + + case DxbcOpcode::RoundZ: + dst.id = m_module.opTrunc( + typeId, src.at(0).id); + break; + + case DxbcOpcode::Rsq: + dst.id = m_module.opInverseSqrt( + typeId, src.at(0).id); + break; + + case DxbcOpcode::Sqrt: + dst.id = m_module.opSqrt( + typeId, src.at(0).id); + break; + + ///////////////////////////////////// + // ALU operations on signed integers + case DxbcOpcode::IAdd: + dst.id = m_module.opIAdd(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::IMad: + case DxbcOpcode::UMad: + dst.id = m_module.opIAdd(typeId, + m_module.opIMul(typeId, + src.at(0).id, src.at(1).id), + src.at(2).id); + break; + + case DxbcOpcode::IMax: + dst.id = m_module.opSMax(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::IMin: + dst.id = m_module.opSMin(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::INeg: + dst.id = m_module.opSNegate( + typeId, src.at(0).id); + break; + + /////////////////////////////////////// + // ALU operations on unsigned integers + case DxbcOpcode::UMax: + dst.id = m_module.opUMax(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::UMin: + dst.id = m_module.opUMin(typeId, + src.at(0).id, src.at(1).id); + break; + + /////////////////////////////////////// + // Bit operations on unsigned integers + case DxbcOpcode::And: + dst.id = m_module.opBitwiseAnd(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Not: + dst.id = m_module.opNot( + typeId, src.at(0).id); + break; + + case DxbcOpcode::Or: + dst.id = m_module.opBitwiseOr(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Xor: + dst.id = m_module.opBitwiseXor(typeId, + src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::CountBits: + dst.id = m_module.opBitCount( + typeId, src.at(0).id); + break; + + case DxbcOpcode::BfRev: + dst.id = m_module.opBitReverse( + typeId, src.at(0).id); + break; + + /////////////////////////// + // Conversion instructions + case DxbcOpcode::ItoF: + dst.id = m_module.opConvertStoF( + typeId, src.at(0).id); + break; + + case DxbcOpcode::UtoF: + dst.id = m_module.opConvertUtoF( + typeId, src.at(0).id); + break; + + case DxbcOpcode::FtoI: + dst.id = m_module.opConvertFtoS( + typeId, src.at(0).id); + break; + + case DxbcOpcode::FtoU: + dst.id = m_module.opConvertFtoU( + typeId, src.at(0).id); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + + if (ins.controls.precise() || m_precise) + m_module.decorate(dst.id, spv::DecorationNoContraction); + + // Store computed value + dst = emitDstOperandModifiers(dst, ins.modifiers); + emitRegisterStore(ins.dst[0], dst); + } + + + void DxbcCompiler::emitVectorCmov(const DxbcShaderInstruction& ins) { + // movc and swapc have the following operands: + // (dst0) The first destination register + // (dst1) The second destination register (swapc only) + // (src0) The condition vector + // (src1) Vector to select from if the condition is not 0 + // (src2) Vector to select from if the condition is 0 + DxbcRegMask condMask = ins.dst[0].mask; + + if (ins.dst[0].dataType == DxbcScalarType::Float64) { + condMask = DxbcRegMask( + condMask[0] && condMask[1], + condMask[2] && condMask[3], + false, false); + } + + const DxbcRegisterValue condition = emitRegisterLoad(ins.src[0], condMask); + const DxbcRegisterValue selectTrue = emitRegisterLoad(ins.src[1], ins.dst[0].mask); + const DxbcRegisterValue selectFalse = emitRegisterLoad(ins.src[2], ins.dst[0].mask); + + uint32_t componentCount = condMask.popCount(); + + // We'll compare against a vector of zeroes to generate a + // boolean vector, which in turn will be used by OpSelect + uint32_t zeroType = m_module.defIntType(32, 0); + uint32_t boolType = m_module.defBoolType(); + + uint32_t zero = m_module.constu32(0); + + if (componentCount > 1) { + zeroType = m_module.defVectorType(zeroType, componentCount); + boolType = m_module.defVectorType(boolType, componentCount); + + const std::array zeroVec = { zero, zero, zero, zero }; + zero = m_module.constComposite(zeroType, componentCount, zeroVec.data()); + } + + // In case of swapc, the second destination operand receives + // the output that a cmov instruction would normally get + const uint32_t trueIndex = ins.op == DxbcOpcode::Swapc ? 1 : 0; + + for (uint32_t i = 0; i < ins.dstCount; i++) { + DxbcRegisterValue result; + result.type.ctype = ins.dst[i].dataType; + result.type.ccount = componentCount; + result.id = m_module.opSelect( + getVectorTypeId(result.type), + m_module.opINotEqual(boolType, condition.id, zero), + i == trueIndex ? selectTrue.id : selectFalse.id, + i != trueIndex ? selectTrue.id : selectFalse.id); + + result = emitDstOperandModifiers(result, ins.modifiers); + emitRegisterStore(ins.dst[i], result); + } + } + + void DxbcCompiler::emitVectorCmp(const DxbcShaderInstruction& ins) { + // Compare instructions have three operands: + // (dst0) The destination register + // (src0) The first vector to compare + // (src1) The second vector to compare + uint32_t componentCount = ins.dst[0].mask.popCount(); + + // For 64-bit operations, we'll return a 32-bit + // vector, so we have to adjust the read mask + DxbcRegMask srcMask = ins.dst[0].mask; + + if (isDoubleType(ins.src[0].dataType)) { + srcMask = DxbcRegMask( + componentCount > 0, componentCount > 0, + componentCount > 1, componentCount > 1); + } + + const std::array src = { + emitRegisterLoad(ins.src[0], srcMask), + emitRegisterLoad(ins.src[1], srcMask), + }; + + // Condition, which is a boolean vector used + // to select between the ~0u and 0u vectors. + uint32_t condition = 0; + uint32_t conditionType = m_module.defBoolType(); + + if (componentCount > 1) + conditionType = m_module.defVectorType(conditionType, componentCount); + + bool invert = false; + + switch (ins.op) { + case DxbcOpcode::Ne: + case DxbcOpcode::DNe: + invert = true; + [[fallthrough]]; + + case DxbcOpcode::Eq: + case DxbcOpcode::DEq: + condition = m_module.opFOrdEqual( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Ge: + case DxbcOpcode::DGe: + condition = m_module.opFOrdGreaterThanEqual( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::Lt: + case DxbcOpcode::DLt: + condition = m_module.opFOrdLessThan( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::IEq: + condition = m_module.opIEqual( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::IGe: + condition = m_module.opSGreaterThanEqual( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::ILt: + condition = m_module.opSLessThan( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::INe: + condition = m_module.opINotEqual( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::UGe: + condition = m_module.opUGreaterThanEqual( + conditionType, src.at(0).id, src.at(1).id); + break; + + case DxbcOpcode::ULt: + condition = m_module.opULessThan( + conditionType, src.at(0).id, src.at(1).id); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + + // Generate constant vectors for selection + uint32_t sFalse = m_module.constu32( 0u); + uint32_t sTrue = m_module.constu32(~0u); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = componentCount; + + const uint32_t typeId = getVectorTypeId(result.type); + + if (componentCount > 1) { + const std::array vFalse = { sFalse, sFalse, sFalse, sFalse }; + const std::array vTrue = { sTrue, sTrue, sTrue, sTrue }; + + sFalse = m_module.constComposite(typeId, componentCount, vFalse.data()); + sTrue = m_module.constComposite(typeId, componentCount, vTrue .data()); + } + + if (invert) + std::swap(sFalse, sTrue); + + // Perform component-wise mask selection + // based on the condition evaluated above. + result.id = m_module.opSelect( + typeId, condition, sTrue, sFalse); + + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitVectorDeriv(const DxbcShaderInstruction& ins) { + // Derivative instructions have two operands: + // (dst0) Destination register for the derivative + // (src0) The operand to compute the derivative of + DxbcRegisterValue value = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + const uint32_t typeId = getVectorTypeId(value.type); + + switch (ins.op) { + case DxbcOpcode::DerivRtx: + value.id = m_module.opDpdx(typeId, value.id); + break; + + case DxbcOpcode::DerivRty: + value.id = m_module.opDpdy(typeId, value.id); + break; + + case DxbcOpcode::DerivRtxCoarse: + value.id = m_module.opDpdxCoarse(typeId, value.id); + break; + + case DxbcOpcode::DerivRtyCoarse: + value.id = m_module.opDpdyCoarse(typeId, value.id); + break; + + case DxbcOpcode::DerivRtxFine: + value.id = m_module.opDpdxFine(typeId, value.id); + break; + + case DxbcOpcode::DerivRtyFine: + value.id = m_module.opDpdyFine(typeId, value.id); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + + value = emitDstOperandModifiers(value, ins.modifiers); + emitRegisterStore(ins.dst[0], value); + } + + + void DxbcCompiler::emitVectorDot(const DxbcShaderInstruction& ins) { + const DxbcRegMask srcMask(true, + ins.op >= DxbcOpcode::Dp2, + ins.op >= DxbcOpcode::Dp3, + ins.op >= DxbcOpcode::Dp4); + + const std::array src = { + emitRegisterLoad(ins.src[0], srcMask), + emitRegisterLoad(ins.src[1], srcMask), + }; + + DxbcRegisterValue dst; + dst.type.ctype = ins.dst[0].dataType; + dst.type.ccount = 1; + dst.id = 0; + + uint32_t componentType = getVectorTypeId(dst.type); + uint32_t componentCount = srcMask.popCount(); + + for (uint32_t i = 0; i < componentCount; i++) { + if (dst.id) { + dst.id = m_module.opFFma(componentType, + m_module.opCompositeExtract(componentType, src.at(0).id, 1, &i), + m_module.opCompositeExtract(componentType, src.at(1).id, 1, &i), + dst.id); + } else { + dst.id = m_module.opFMul(componentType, + m_module.opCompositeExtract(componentType, src.at(0).id, 1, &i), + m_module.opCompositeExtract(componentType, src.at(1).id, 1, &i)); + } + + // Unconditionally mark as precise since the exact order of operation + // matters for some games, even if the instruction itself is not marked + // as precise. + m_module.decorate(dst.id, spv::DecorationNoContraction); + } + + dst = emitDstOperandModifiers(dst, ins.modifiers); + emitRegisterStore(ins.dst[0], dst); + } + + + void DxbcCompiler::emitVectorIdiv(const DxbcShaderInstruction& ins) { + // udiv has four operands: + // (dst0) Quotient destination register + // (dst1) Remainder destination register + // (src0) The first vector to compare + // (src1) The second vector to compare + if (ins.dst[0].type == DxbcOperandType::Null + && ins.dst[1].type == DxbcOperandType::Null) + return; + + // FIXME support this if applications require it + if (ins.dst[0].type != DxbcOperandType::Null + && ins.dst[1].type != DxbcOperandType::Null + && ins.dst[0].mask != ins.dst[1].mask) { + Logger::warn("DxbcCompiler: Idiv with different destination masks not supported"); + return; + } + + // Load source operands as integers with the + // mask of one non-NULL destination operand + const DxbcRegMask srcMask = + ins.dst[0].type != DxbcOperandType::Null + ? ins.dst[0].mask + : ins.dst[1].mask; + + const std::array src = { + emitRegisterLoad(ins.src[0], srcMask), + emitRegisterLoad(ins.src[1], srcMask), + }; + + // Division by zero will return 0xffffffff for both results + auto bvecId = getVectorTypeId({ DxbcScalarType::Bool, srcMask.popCount() }); + + DxbcRegisterValue const0 = emitBuildConstVecu32( 0u, 0u, 0u, 0u, srcMask); + DxbcRegisterValue constff = emitBuildConstVecu32(~0u, ~0u, ~0u, ~0u, srcMask); + + uint32_t cmpValue = m_module.opINotEqual(bvecId, src.at(1).id, const0.id); + + // Compute results only if the destination + // operands are not NULL. + if (ins.dst[0].type != DxbcOperandType::Null) { + DxbcRegisterValue quotient; + quotient.type.ctype = ins.dst[0].dataType; + quotient.type.ccount = ins.dst[0].mask.popCount(); + + quotient.id = m_module.opUDiv( + getVectorTypeId(quotient.type), + src.at(0).id, src.at(1).id); + + quotient.id = m_module.opSelect( + getVectorTypeId(quotient.type), + cmpValue, quotient.id, constff.id); + + quotient = emitDstOperandModifiers(quotient, ins.modifiers); + emitRegisterStore(ins.dst[0], quotient); + } + + if (ins.dst[1].type != DxbcOperandType::Null) { + DxbcRegisterValue remainder; + remainder.type.ctype = ins.dst[1].dataType; + remainder.type.ccount = ins.dst[1].mask.popCount(); + + remainder.id = m_module.opUMod( + getVectorTypeId(remainder.type), + src.at(0).id, src.at(1).id); + + remainder.id = m_module.opSelect( + getVectorTypeId(remainder.type), + cmpValue, remainder.id, constff.id); + + remainder = emitDstOperandModifiers(remainder, ins.modifiers); + emitRegisterStore(ins.dst[1], remainder); + } + } + + + void DxbcCompiler::emitVectorImul(const DxbcShaderInstruction& ins) { + // imul and umul have four operands: + // (dst0) High destination register + // (dst1) Low destination register + // (src0) The first vector to compare + // (src1) The second vector to compare + if (ins.dst[0].type == DxbcOperandType::Null) { + if (ins.dst[1].type == DxbcOperandType::Null) + return; + + // If dst0 is NULL, this instruction behaves just + // like any other three-operand ALU instruction + const std::array src = { + emitRegisterLoad(ins.src[0], ins.dst[1].mask), + emitRegisterLoad(ins.src[1], ins.dst[1].mask), + }; + + DxbcRegisterValue result; + result.type.ctype = ins.dst[1].dataType; + result.type.ccount = ins.dst[1].mask.popCount(); + result.id = m_module.opIMul( + getVectorTypeId(result.type), + src.at(0).id, src.at(1).id); + + result = emitDstOperandModifiers(result, ins.modifiers); + emitRegisterStore(ins.dst[1], result); + } else { + // TODO implement this + Logger::warn("DxbcCompiler: Extended Imul not yet supported"); + } + } + + + void DxbcCompiler::emitVectorMsad(const DxbcShaderInstruction& ins) { + // msad has four operands: + // (dst0) Destination + // (src0) Reference (packed uint8) + // (src1) Source (packed uint8) + // (src2) Accumulator + DxbcRegisterValue refReg = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + DxbcRegisterValue srcReg = emitRegisterLoad(ins.src[1], ins.dst[0].mask); + DxbcRegisterValue result = emitRegisterLoad(ins.src[2], ins.dst[0].mask); + + auto typeId = getVectorTypeId(result.type); + auto bvecId = getVectorTypeId({ DxbcScalarType::Bool, result.type.ccount }); + + for (uint32_t i = 0; i < 4; i++) { + auto shift = m_module.constu32(8 * i); + auto count = m_module.constu32(8); + + auto ref = m_module.opBitFieldUExtract(typeId, refReg.id, shift, count); + auto src = m_module.opBitFieldUExtract(typeId, srcReg.id, shift, count); + + auto zero = emitBuildConstVecu32(0, 0, 0, 0, ins.dst[0].mask); + auto mask = m_module.opINotEqual(bvecId, ref, zero.id); + + auto diff = m_module.opSAbs(typeId, m_module.opISub(typeId, ref, src)); + result.id = m_module.opSelect(typeId, mask, m_module.opIAdd(typeId, result.id, diff), result.id); + } + + result = emitDstOperandModifiers(result, ins.modifiers); + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitVectorShift(const DxbcShaderInstruction& ins) { + // Shift operations have three operands: + // (dst0) The destination register + // (src0) The register to shift + // (src1) The shift amount (scalar) + DxbcRegisterValue shiftReg = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + DxbcRegisterValue countReg = emitRegisterLoad(ins.src[1], ins.dst[0].mask); + + if (ins.src[1].type != DxbcOperandType::Imm32) + countReg = emitRegisterMaskBits(countReg, 0x1F); + + if (countReg.type.ccount == 1) + countReg = emitRegisterExtend(countReg, shiftReg.type.ccount); + + DxbcRegisterValue result; + result.type.ctype = ins.dst[0].dataType; + result.type.ccount = ins.dst[0].mask.popCount(); + + switch (ins.op) { + case DxbcOpcode::IShl: + result.id = m_module.opShiftLeftLogical( + getVectorTypeId(result.type), + shiftReg.id, countReg.id); + break; + + case DxbcOpcode::IShr: + result.id = m_module.opShiftRightArithmetic( + getVectorTypeId(result.type), + shiftReg.id, countReg.id); + break; + + case DxbcOpcode::UShr: + result.id = m_module.opShiftRightLogical( + getVectorTypeId(result.type), + shiftReg.id, countReg.id); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + + result = emitDstOperandModifiers(result, ins.modifiers); + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitVectorSinCos(const DxbcShaderInstruction& ins) { + // sincos has three operands: + // (dst0) Destination register for sin(x) + // (dst1) Destination register for cos(x) + // (src0) Source operand x + + // Load source operand as 32-bit float vector. + const DxbcRegisterValue srcValue = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, true, true, true)); + + uint32_t typeId = getScalarTypeId(srcValue.type.ctype); + + DxbcRegisterValue sinVector = { }; + sinVector.type.ctype = DxbcScalarType::Float32; + + DxbcRegisterValue cosVector = { }; + cosVector.type.ctype = DxbcScalarType::Float32; + + // Only compute sincos for enabled components + std::array sinIds = { }; + std::array cosIds = { }; + + for (uint32_t i = 0; i < 4; i++) { + const uint32_t sinIndex = 0u; + const uint32_t cosIndex = 1u; + + if (ins.dst[0].mask[i] || ins.dst[1].mask[i]) { + uint32_t sincosId = m_module.opSinCos(m_module.opCompositeExtract(typeId, srcValue.id, 1u, &i), !m_moduleInfo.options.sincosEmulation); + + if (ins.dst[0].type != DxbcOperandType::Null && ins.dst[0].mask[i]) + sinIds[sinVector.type.ccount++] = m_module.opCompositeExtract(typeId, sincosId, 1u, &sinIndex); + + if (ins.dst[1].type != DxbcOperandType::Null && ins.dst[1].mask[i]) + cosIds[cosVector.type.ccount++] = m_module.opCompositeExtract(typeId, sincosId, 1u, &cosIndex); + } + } + + if (sinVector.type.ccount) { + sinVector.id = sinVector.type.ccount > 1u + ? m_module.opCompositeConstruct(getVectorTypeId(sinVector.type), sinVector.type.ccount, sinIds.data()) + : sinIds[0]; + + emitRegisterStore(ins.dst[0], sinVector); + } + + if (cosVector.type.ccount) { + cosVector.id = cosVector.type.ccount > 1u + ? m_module.opCompositeConstruct(getVectorTypeId(cosVector.type), cosVector.type.ccount, cosIds.data()) + : cosIds[0]; + + emitRegisterStore(ins.dst[1], cosVector); + } + } + + + void DxbcCompiler::emitGeometryEmit(const DxbcShaderInstruction& ins) { + // In xfb mode we might have multiple streams, so + // we have to figure out which stream to write to + uint32_t streamId = 0; + uint32_t streamVar = 0; + + if (m_moduleInfo.xfb != nullptr) { + streamId = ins.dstCount > 0 ? ins.dst[0].idx[0].offset : 0; + streamVar = m_module.constu32(streamId); + } + + // Checking the negation is easier for EmitThenCut/EmitThenCutStream + bool doEmit = ins.op != DxbcOpcode::Cut && ins.op != DxbcOpcode::CutStream; + bool doCut = ins.op != DxbcOpcode::Emit && ins.op != DxbcOpcode::EmitStream; + + if (doEmit) { + if (m_gs.needsOutputSetup) + emitOutputSetup(); + emitClipCullStore(DxbcSystemValue::ClipDistance, m_clipDistances); + emitClipCullStore(DxbcSystemValue::CullDistance, m_cullDistances); + emitXfbOutputSetup(streamId, false); + m_module.opEmitVertex(streamVar); + } + + if (doCut) + m_module.opEndPrimitive(streamVar); + } + + + void DxbcCompiler::emitAtomic(const DxbcShaderInstruction& ins) { + // atomic_* operations have the following operands: + // (dst0) Destination u# or g# register + // (src0) Index into the texture or buffer + // (src1) The source value for the operation + // (src2) Second source operand (optional) + // imm_atomic_* operations have the following operands: + // (dst0) Register that receives the result + // (dst1) Destination u# or g# register + // (srcX) As above + const DxbcBufferInfo bufferInfo = getBufferInfo(ins.dst[ins.dstCount - 1]); + + bool isImm = ins.dstCount == 2; + bool isUav = ins.dst[ins.dstCount - 1].type == DxbcOperandType::UnorderedAccessView; + bool isSsbo = bufferInfo.isSsbo; + + // Retrieve destination pointer for the atomic operation> + const DxbcRegisterPointer pointer = emitGetAtomicPointer( + ins.dst[ins.dstCount - 1], ins.src[0]); + + // Load source values + std::array src; + + for (uint32_t i = 1; i < ins.srcCount; i++) { + src[i - 1] = emitRegisterBitcast( + emitRegisterLoad(ins.src[i], DxbcRegMask(true, false, false, false)), + pointer.type.ctype); + } + + // Define memory scope and semantics based on the operands + uint32_t scope = 0; + uint32_t semantics = 0; + + if (isUav) { + scope = spv::ScopeQueueFamily; + semantics = spv::MemorySemanticsAcquireReleaseMask; + + semantics |= isSsbo + ? spv::MemorySemanticsUniformMemoryMask + : spv::MemorySemanticsImageMemoryMask; + } else { + scope = spv::ScopeWorkgroup; + semantics = spv::MemorySemanticsWorkgroupMemoryMask + | spv::MemorySemanticsAcquireReleaseMask; + } + + const uint32_t scopeId = m_module.constu32(scope); + const uint32_t semanticsId = m_module.constu32(semantics); + + // Perform the atomic operation on the given pointer + DxbcRegisterValue value; + value.type = pointer.type; + value.id = 0; + + // The result type, which is a scalar integer + const uint32_t typeId = getVectorTypeId(value.type); + + switch (ins.op) { + case DxbcOpcode::AtomicCmpStore: + case DxbcOpcode::ImmAtomicCmpExch: + value.id = m_module.opAtomicCompareExchange( + typeId, pointer.id, scopeId, semanticsId, + m_module.constu32(spv::MemorySemanticsMaskNone), + src[1].id, src[0].id); + break; + + case DxbcOpcode::ImmAtomicExch: + value.id = m_module.opAtomicExchange(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicIAdd: + case DxbcOpcode::ImmAtomicIAdd: + value.id = m_module.opAtomicIAdd(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicAnd: + case DxbcOpcode::ImmAtomicAnd: + value.id = m_module.opAtomicAnd(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicOr: + case DxbcOpcode::ImmAtomicOr: + value.id = m_module.opAtomicOr(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicXor: + case DxbcOpcode::ImmAtomicXor: + value.id = m_module.opAtomicXor(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicIMin: + case DxbcOpcode::ImmAtomicIMin: + value.id = m_module.opAtomicSMin(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicIMax: + case DxbcOpcode::ImmAtomicIMax: + value.id = m_module.opAtomicSMax(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicUMin: + case DxbcOpcode::ImmAtomicUMin: + value.id = m_module.opAtomicUMin(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + case DxbcOpcode::AtomicUMax: + case DxbcOpcode::ImmAtomicUMax: + value.id = m_module.opAtomicUMax(typeId, + pointer.id, scopeId, semanticsId, + src[0].id); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + + // Write back the result to the destination + // register if this is an imm_atomic_* opcode. + if (isImm) + emitRegisterStore(ins.dst[0], value); + } + + + void DxbcCompiler::emitAtomicCounter(const DxbcShaderInstruction& ins) { + // imm_atomic_alloc and imm_atomic_consume have the following operands: + // (dst0) The register that will hold the old counter value + // (dst1) The UAV whose counter is going to be modified + const uint32_t registerId = ins.dst[1].idx[0].offset; + + if (m_uavs.at(registerId).ctrId == 0) + m_uavs.at(registerId).ctrId = emitDclUavCounter(registerId); + + // Get a pointer to the atomic counter in question + DxbcRegisterInfo ptrType; + ptrType.type.ctype = DxbcScalarType::Uint32; + ptrType.type.ccount = 1; + ptrType.type.alength = 0; + ptrType.sclass = spv::StorageClassStorageBuffer; + + uint32_t zeroId = m_module.consti32(0); + uint32_t ptrId = m_module.opAccessChain( + getPointerTypeId(ptrType), + m_uavs.at(registerId).ctrId, + 1, &zeroId); + + // Define memory scope and semantics based on the operands + uint32_t scope = spv::ScopeQueueFamily; + uint32_t semantics = spv::MemorySemanticsUniformMemoryMask + | spv::MemorySemanticsAcquireReleaseMask; + + uint32_t scopeId = m_module.constu32(scope); + uint32_t semanticsId = m_module.constu32(semantics); + + // Compute the result value + DxbcRegisterValue value; + value.type.ctype = DxbcScalarType::Uint32; + value.type.ccount = 1; + + uint32_t typeId = getVectorTypeId(value.type); + + switch (ins.op) { + case DxbcOpcode::ImmAtomicAlloc: + value.id = m_module.opAtomicIAdd(typeId, ptrId, + scopeId, semanticsId, m_module.constu32(1)); + break; + + case DxbcOpcode::ImmAtomicConsume: + value.id = m_module.opAtomicISub(typeId, ptrId, + scopeId, semanticsId, m_module.constu32(1)); + value.id = m_module.opISub(typeId, value.id, + m_module.constu32(1)); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + + // Store the result + emitRegisterStore(ins.dst[0], value); + } + + + void DxbcCompiler::emitBarrier(const DxbcShaderInstruction& ins) { + // sync takes no operands. Instead, the synchronization + // scope is defined by the operand control bits. + const DxbcSyncFlags flags = ins.controls.syncFlags(); + + uint32_t executionScope = spv::ScopeInvocation; + uint32_t memoryScope = spv::ScopeInvocation; + uint32_t memorySemantics = 0; + + if (flags.test(DxbcSyncFlag::ThreadsInGroup)) + executionScope = spv::ScopeWorkgroup; + + if (flags.test(DxbcSyncFlag::ThreadGroupSharedMemory)) { + memoryScope = spv::ScopeWorkgroup; + memorySemantics |= spv::MemorySemanticsWorkgroupMemoryMask + | spv::MemorySemanticsAcquireReleaseMask + | spv::MemorySemanticsMakeAvailableMask + | spv::MemorySemanticsMakeVisibleMask; + } + + if (flags.test(DxbcSyncFlag::UavMemoryGroup)) { + memoryScope = spv::ScopeWorkgroup; + memorySemantics |= spv::MemorySemanticsImageMemoryMask + | spv::MemorySemanticsUniformMemoryMask + | spv::MemorySemanticsAcquireReleaseMask + | spv::MemorySemanticsMakeAvailableMask + | spv::MemorySemanticsMakeVisibleMask; + } + + if (flags.test(DxbcSyncFlag::UavMemoryGlobal)) { + memoryScope = spv::ScopeQueueFamily; + + if (m_programInfo.type() == DxbcProgramType::ComputeShader && !m_hasGloballyCoherentUav) + memoryScope = spv::ScopeWorkgroup; + + memorySemantics |= spv::MemorySemanticsImageMemoryMask + | spv::MemorySemanticsUniformMemoryMask + | spv::MemorySemanticsAcquireReleaseMask + | spv::MemorySemanticsMakeAvailableMask + | spv::MemorySemanticsMakeVisibleMask; + } + + if (executionScope != spv::ScopeInvocation) { + m_module.opControlBarrier( + m_module.constu32(executionScope), + m_module.constu32(memoryScope), + m_module.constu32(memorySemantics)); + } else if (memoryScope != spv::ScopeInvocation) { + m_module.opMemoryBarrier( + m_module.constu32(memoryScope), + m_module.constu32(memorySemantics)); + } else { + Logger::warn("DxbcCompiler: sync instruction has no effect"); + } + } + + + void DxbcCompiler::emitBitExtract(const DxbcShaderInstruction& ins) { + // ibfe and ubfe take the following arguments: + // (dst0) The destination register + // (src0) Number of bits to extact + // (src1) Offset of the bits to extract + // (src2) Register to extract bits from + const bool isSigned = ins.op == DxbcOpcode::IBfe; + + DxbcRegisterValue bitCnt = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + DxbcRegisterValue bitOfs = emitRegisterLoad(ins.src[1], ins.dst[0].mask); + + if (ins.src[0].type != DxbcOperandType::Imm32) + bitCnt = emitRegisterMaskBits(bitCnt, 0x1F); + + if (ins.src[1].type != DxbcOperandType::Imm32) + bitOfs = emitRegisterMaskBits(bitOfs, 0x1F); + + const DxbcRegisterValue src = emitRegisterLoad(ins.src[2], ins.dst[0].mask); + + const uint32_t componentCount = src.type.ccount; + std::array componentIds = {{ 0, 0, 0, 0 }}; + + for (uint32_t i = 0; i < componentCount; i++) { + const DxbcRegisterValue currBitCnt = emitRegisterExtract(bitCnt, DxbcRegMask::select(i)); + const DxbcRegisterValue currBitOfs = emitRegisterExtract(bitOfs, DxbcRegMask::select(i)); + const DxbcRegisterValue currSrc = emitRegisterExtract(src, DxbcRegMask::select(i)); + + const uint32_t typeId = getVectorTypeId(currSrc.type); + + componentIds[i] = isSigned + ? m_module.opBitFieldSExtract(typeId, currSrc.id, currBitOfs.id, currBitCnt.id) + : m_module.opBitFieldUExtract(typeId, currSrc.id, currBitOfs.id, currBitCnt.id); + } + + DxbcRegisterValue result; + result.type = src.type; + result.id = componentCount > 1 + ? m_module.opCompositeConstruct( + getVectorTypeId(result.type), + componentCount, componentIds.data()) + : componentIds[0]; + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitBitInsert(const DxbcShaderInstruction& ins) { + // ibfe and ubfe take the following arguments: + // (dst0) The destination register + // (src0) Number of bits to extact + // (src1) Offset of the bits to extract + // (src2) Register to take bits from + // (src3) Register to replace bits in + DxbcRegisterValue bitCnt = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + DxbcRegisterValue bitOfs = emitRegisterLoad(ins.src[1], ins.dst[0].mask); + + if (ins.src[0].type != DxbcOperandType::Imm32) + bitCnt = emitRegisterMaskBits(bitCnt, 0x1F); + + if (ins.src[1].type != DxbcOperandType::Imm32) + bitOfs = emitRegisterMaskBits(bitOfs, 0x1F); + + const DxbcRegisterValue insert = emitRegisterLoad(ins.src[2], ins.dst[0].mask); + const DxbcRegisterValue base = emitRegisterLoad(ins.src[3], ins.dst[0].mask); + + const uint32_t componentCount = base.type.ccount; + std::array componentIds = {{ 0, 0, 0, 0 }}; + + for (uint32_t i = 0; i < componentCount; i++) { + const DxbcRegisterValue currBitCnt = emitRegisterExtract(bitCnt, DxbcRegMask::select(i)); + const DxbcRegisterValue currBitOfs = emitRegisterExtract(bitOfs, DxbcRegMask::select(i)); + const DxbcRegisterValue currInsert = emitRegisterExtract(insert, DxbcRegMask::select(i)); + const DxbcRegisterValue currBase = emitRegisterExtract(base, DxbcRegMask::select(i)); + + componentIds[i] = m_module.opBitFieldInsert( + getVectorTypeId(currBase.type), + currBase.id, currInsert.id, + currBitOfs.id, currBitCnt.id); + } + + DxbcRegisterValue result; + result.type = base.type; + result.id = componentCount > 1 + ? m_module.opCompositeConstruct( + getVectorTypeId(result.type), + componentCount, componentIds.data()) + : componentIds[0]; + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitBitScan(const DxbcShaderInstruction& ins) { + // firstbit(lo|hi|shi) have two operands: + // (dst0) The destination operant + // (src0) Source operand to scan + DxbcRegisterValue src = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + + DxbcRegisterValue dst; + dst.type.ctype = ins.dst[0].dataType; + dst.type.ccount = ins.dst[0].mask.popCount(); + + // Result type, should be an unsigned integer + const uint32_t typeId = getVectorTypeId(dst.type); + + switch (ins.op) { + case DxbcOpcode::FirstBitLo: dst.id = m_module.opFindILsb(typeId, src.id); break; + case DxbcOpcode::FirstBitHi: dst.id = m_module.opFindUMsb(typeId, src.id); break; + case DxbcOpcode::FirstBitShi: dst.id = m_module.opFindSMsb(typeId, src.id); break; + default: Logger::warn(str::format("DxbcCompiler: Unhandled instruction: ", ins.op)); return; + } + + // The 'Hi' variants are counted from the MSB in DXBC + // rather than the LSB, so we have to invert the number + if (ins.op == DxbcOpcode::FirstBitHi || ins.op == DxbcOpcode::FirstBitShi) { + uint32_t boolTypeId = m_module.defBoolType(); + + if (dst.type.ccount > 1) + boolTypeId = m_module.defVectorType(boolTypeId, dst.type.ccount); + + DxbcRegisterValue const31 = emitBuildConstVecu32(31u, 31u, 31u, 31u, ins.dst[0].mask); + DxbcRegisterValue constff = emitBuildConstVecu32(~0u, ~0u, ~0u, ~0u, ins.dst[0].mask); + + dst.id = m_module.opSelect(typeId, + m_module.opINotEqual(boolTypeId, dst.id, constff.id), + m_module.opISub(typeId, const31.id, dst.id), + constff.id); + } + + // No modifiers are supported + emitRegisterStore(ins.dst[0], dst); + } + + + void DxbcCompiler::emitBufferQuery(const DxbcShaderInstruction& ins) { + // bufinfo takes two arguments + // (dst0) The destination register + // (src0) The buffer register to query + const DxbcBufferInfo bufferInfo = getBufferInfo(ins.src[0]); + bool isSsbo = bufferInfo.isSsbo; + + // We'll store this as a scalar unsigned integer + DxbcRegisterValue result = isSsbo + ? emitQueryBufferSize(ins.src[0]) + : emitQueryTexelBufferSize(ins.src[0]); + + uint32_t typeId = getVectorTypeId(result.type); + + // Adjust returned size if this is a raw or structured + // buffer, as emitQueryTexelBufferSize only returns the + // number of typed elements in the buffer. + if (bufferInfo.type == DxbcResourceType::Raw) { + result.id = m_module.opIMul(typeId, + result.id, m_module.constu32(4)); + } else if (bufferInfo.type == DxbcResourceType::Structured) { + result.id = m_module.opUDiv(typeId, result.id, + m_module.constu32(bufferInfo.stride / 4)); + } + + // Store the result. The scalar will be extended to a + // vector if the write mask consists of more than one + // component, which is the desired behaviour. + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitBufferLoad(const DxbcShaderInstruction& ins) { + // ld_raw takes three arguments: + // (dst0) Destination register + // (src0) Byte offset + // (src1) Source register + // ld_structured takes four arguments: + // (dst0) Destination register + // (src0) Structure index + // (src1) Byte offset + // (src2) Source register + const bool isStructured = ins.op == DxbcOpcode::LdStructured + || ins.op == DxbcOpcode::LdStructuredS; + + // Source register. The exact way we access + // the data depends on the register type. + const DxbcRegister& dstReg = ins.dst[0]; + const DxbcRegister& srcReg = isStructured ? ins.src[2] : ins.src[1]; + + if (dstReg.type == DxbcOperandType::UnorderedAccessView) + emitUavBarrier(uint64_t(1u) << srcReg.idx[0].offset, 0u); + + // Retrieve common info about the buffer + const DxbcBufferInfo bufferInfo = getBufferInfo(srcReg); + + // Shared memory is the only type of buffer that + // is not accessed through a texel buffer view + bool isTgsm = srcReg.type == DxbcOperandType::ThreadGroupSharedMemory; + bool isSsbo = bufferInfo.isSsbo; + + // Common types and IDs used while loading the data + uint32_t bufferId = isTgsm || isSsbo ? 0 : m_module.opLoad(bufferInfo.typeId, bufferInfo.varId); + + uint32_t vectorTypeId = getVectorTypeId({ DxbcScalarType::Uint32, 4 }); + uint32_t scalarTypeId = getVectorTypeId({ DxbcScalarType::Uint32, 1 }); + + // Since all data is represented as a sequence of 32-bit + // integers, we have to load each component individually. + std::array ccomps = { 0, 0, 0, 0 }; + std::array scomps = { 0, 0, 0, 0 }; + uint32_t scount = 0; + + // The sparse feedback ID will be non-zero for sparse + // instructions on input. We need to reset it to 0. + SpirvMemoryOperands memoryOperands; + SpirvImageOperands imageOperands; + imageOperands.sparse = ins.dstCount == 2; + + uint32_t coherence = bufferInfo.coherence; + + if (isTgsm && m_moduleInfo.options.forceVolatileTgsmAccess) { + memoryOperands.flags |= spv::MemoryAccessVolatileMask; + coherence = spv::ScopeWorkgroup; + } + + if (coherence) { + memoryOperands.flags |= spv::MemoryAccessNonPrivatePointerMask; + + if (coherence != spv::ScopeInvocation) { + memoryOperands.flags |= spv::MemoryAccessMakePointerVisibleMask; + memoryOperands.makeVisible = m_module.constu32(coherence); + + imageOperands.flags = spv::ImageOperandsNonPrivateTexelMask + | spv::ImageOperandsMakeTexelVisibleMask; + imageOperands.makeVisible = m_module.constu32(coherence); + } + } + + uint32_t sparseFeedbackId = 0; + + bool useRawAccessChains = m_hasRawAccessChains && isSsbo && !imageOperands.sparse; + + DxbcRegisterValue index = emitRegisterLoad(ins.src[0], DxbcRegMask(true, false, false, false)); + DxbcRegisterValue offset = index; + + if (isStructured) + offset = emitRegisterLoad(ins.src[1], DxbcRegMask(true, false, false, false)); + + DxbcRegisterValue elementIndex = { }; + + uint32_t baseAlignment = sizeof(uint32_t); + + if (useRawAccessChains) { + memoryOperands.flags |= spv::MemoryAccessAlignedMask; + + if (isStructured && ins.src[1].type == DxbcOperandType::Imm32) { + baseAlignment = bufferInfo.stride | ins.src[1].imm.u32_1; + baseAlignment = baseAlignment & -baseAlignment; + baseAlignment = std::min(baseAlignment, uint32_t(m_moduleInfo.options.minSsboAlignment)); + } + } else { + elementIndex = isStructured + ? emitCalcBufferIndexStructured(index, offset, bufferInfo.stride) + : emitCalcBufferIndexRaw(offset); + } + + uint32_t readMask = 0u; + + for (uint32_t i = 0; i < 4; i++) { + if (dstReg.mask[i]) + readMask |= 1u << srcReg.swizzle[i]; + } + + while (readMask) { + uint32_t sindex = bit::tzcnt(readMask); + uint32_t scount = bit::tzcnt(~(readMask >> sindex)); + uint32_t zero = 0; + + if (useRawAccessChains) { + uint32_t alignment = baseAlignment; + uint32_t offsetId = offset.id; + + if (sindex) { + offsetId = m_module.opIAdd(scalarTypeId, + offsetId, m_module.constu32(sizeof(uint32_t) * sindex)); + alignment |= sizeof(uint32_t) * sindex; + } + + DxbcRegisterInfo storeInfo; + storeInfo.type.ctype = DxbcScalarType::Uint32; + storeInfo.type.ccount = scount; + storeInfo.type.alength = 0; + storeInfo.sclass = spv::StorageClassStorageBuffer; + + uint32_t loadTypeId = getArrayTypeId(storeInfo.type); + uint32_t ptrTypeId = getPointerTypeId(storeInfo); + + uint32_t accessChain = isStructured + ? m_module.opRawAccessChain(ptrTypeId, bufferInfo.varId, + m_module.constu32(bufferInfo.stride), index.id, offsetId, + spv::RawAccessChainOperandsRobustnessPerElementNVMask) + : m_module.opRawAccessChain(ptrTypeId, bufferInfo.varId, + m_module.constu32(0), m_module.constu32(0), offsetId, + spv::RawAccessChainOperandsRobustnessPerComponentNVMask); + + memoryOperands.alignment = alignment & -alignment; + + uint32_t vectorId = m_module.opLoad(loadTypeId, accessChain, memoryOperands); + + for (uint32_t i = 0; i < scount; i++) { + ccomps[sindex + i] = vectorId; + + if (scount > 1) { + ccomps[sindex + i] = m_module.opCompositeExtract( + scalarTypeId, vectorId, 1, &i); + } + } + + readMask &= ~(((1u << scount) - 1u) << sindex); + } else { + uint32_t elementIndexAdjusted = m_module.opIAdd( + getVectorTypeId(elementIndex.type), elementIndex.id, + m_module.consti32(sindex)); + + if (isTgsm) { + ccomps[sindex] = m_module.opLoad(scalarTypeId, + m_module.opAccessChain(bufferInfo.typeId, + bufferInfo.varId, 1, &elementIndexAdjusted), + memoryOperands); + } else if (isSsbo) { + uint32_t indices[2] = { m_module.constu32(0), elementIndexAdjusted }; + ccomps[sindex] = m_module.opLoad(scalarTypeId, + m_module.opAccessChain(bufferInfo.typeId, + bufferInfo.varId, 2, indices), + memoryOperands); + } else { + uint32_t resultTypeId = vectorTypeId; + uint32_t resultId = 0; + + if (imageOperands.sparse) + resultTypeId = getSparseResultTypeId(vectorTypeId); + + if (srcReg.type == DxbcOperandType::Resource) { + resultId = m_module.opImageFetch(resultTypeId, + bufferId, elementIndexAdjusted, imageOperands); + } else if (srcReg.type == DxbcOperandType::UnorderedAccessView) { + resultId = m_module.opImageRead(resultTypeId, + bufferId, elementIndexAdjusted, imageOperands); + } else { + throw DxvkError("DxbcCompiler: Invalid operand type for strucured/raw load"); + } + + // Only read sparse feedback once. This may be somewhat inaccurate + // for reads that straddle pages, but we can't easily emulate this. + if (imageOperands.sparse) { + imageOperands.sparse = false; + sparseFeedbackId = resultId; + + resultId = emitExtractSparseTexel(vectorTypeId, resultId); + } + + ccomps[sindex] = m_module.opCompositeExtract(scalarTypeId, resultId, 1, &zero); + } + + readMask &= readMask - 1; + } + } + + for (uint32_t i = 0; i < 4; i++) { + uint32_t sindex = srcReg.swizzle[i]; + + if (dstReg.mask[i]) + scomps[scount++] = ccomps[sindex]; + } + + DxbcRegisterValue result = { }; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = scount; + result.id = scomps[0]; + + if (scount > 1) { + result.id = m_module.opCompositeConstruct( + getVectorTypeId(result.type), + scount, scomps.data()); + } + + emitRegisterStore(dstReg, result); + + if (sparseFeedbackId) + emitStoreSparseFeedback(ins.dst[1], sparseFeedbackId); + } + + + void DxbcCompiler::emitBufferStore(const DxbcShaderInstruction& ins) { + // store_raw takes three arguments: + // (dst0) Destination register + // (src0) Byte offset + // (src1) Source register + // store_structured takes four arguments: + // (dst0) Destination register + // (src0) Structure index + // (src1) Byte offset + // (src2) Source register + const bool isStructured = ins.op == DxbcOpcode::StoreStructured; + + // Source register. The exact way we access + // the data depends on the register type. + const DxbcRegister& dstReg = ins.dst[0]; + const DxbcRegister& srcReg = isStructured ? ins.src[2] : ins.src[1]; + + if (dstReg.type == DxbcOperandType::UnorderedAccessView) + emitUavBarrier(0u, uint64_t(1u) << dstReg.idx[0].offset); + + DxbcRegisterValue value = emitRegisterLoad(srcReg, dstReg.mask); + value = emitRegisterBitcast(value, DxbcScalarType::Uint32); + + // Retrieve common info about the buffer + const DxbcBufferInfo bufferInfo = getBufferInfo(dstReg); + + // Thread Group Shared Memory is not accessed through a texel buffer view + bool isTgsm = dstReg.type == DxbcOperandType::ThreadGroupSharedMemory; + bool isSsbo = bufferInfo.isSsbo; + + uint32_t bufferId = isTgsm || isSsbo ? 0 : m_module.opLoad(bufferInfo.typeId, bufferInfo.varId); + + uint32_t scalarTypeId = getVectorTypeId({ DxbcScalarType::Uint32, 1 }); + uint32_t vectorTypeId = getVectorTypeId({ DxbcScalarType::Uint32, 4 }); + + // Set memory operands according to resource properties + SpirvMemoryOperands memoryOperands; + SpirvImageOperands imageOperands; + + uint32_t coherence = bufferInfo.coherence; + + if (isTgsm && m_moduleInfo.options.forceVolatileTgsmAccess) { + memoryOperands.flags |= spv::MemoryAccessVolatileMask; + coherence = spv::ScopeWorkgroup; + } + + if (coherence) { + memoryOperands.flags |= spv::MemoryAccessNonPrivatePointerMask; + + if (coherence != spv::ScopeInvocation) { + memoryOperands.flags |= spv::MemoryAccessMakePointerAvailableMask; + memoryOperands.makeAvailable = m_module.constu32(coherence); + + imageOperands.flags = spv::ImageOperandsNonPrivateTexelMask + | spv::ImageOperandsMakeTexelAvailableMask; + imageOperands.makeAvailable = m_module.constu32(coherence); + } + } + + // Compute flat element index as necessary + bool useRawAccessChains = isSsbo && m_hasRawAccessChains; + + DxbcRegisterValue index = emitRegisterLoad(ins.src[0], DxbcRegMask(true, false, false, false)); + DxbcRegisterValue offset = index; + + if (isStructured) + offset = emitRegisterLoad(ins.src[1], DxbcRegMask(true, false, false, false)); + + DxbcRegisterValue elementIndex = { }; + + uint32_t baseAlignment = sizeof(uint32_t); + + if (useRawAccessChains) { + memoryOperands.flags |= spv::MemoryAccessAlignedMask; + + if (isStructured && ins.src[1].type == DxbcOperandType::Imm32) { + baseAlignment = bufferInfo.stride | ins.src[1].imm.u32_1; + baseAlignment = baseAlignment & -baseAlignment; + baseAlignment = std::min(baseAlignment, uint32_t(m_moduleInfo.options.minSsboAlignment)); + } + } else { + elementIndex = isStructured + ? emitCalcBufferIndexStructured(index, offset, bufferInfo.stride) + : emitCalcBufferIndexRaw(offset); + } + + uint32_t writeMask = dstReg.mask.raw(); + + while (writeMask) { + uint32_t sindex = bit::tzcnt(writeMask); + uint32_t scount = bit::tzcnt(~(writeMask >> sindex)); + + if (useRawAccessChains) { + uint32_t alignment = baseAlignment; + uint32_t offsetId = offset.id; + + if (sindex) { + offsetId = m_module.opIAdd(scalarTypeId, + offsetId, m_module.constu32(sizeof(uint32_t) * sindex)); + alignment = alignment | (sizeof(uint32_t) * sindex); + } + + DxbcRegisterInfo storeInfo; + storeInfo.type.ctype = DxbcScalarType::Uint32; + storeInfo.type.ccount = scount; + storeInfo.type.alength = 0; + storeInfo.sclass = spv::StorageClassStorageBuffer; + + uint32_t storeTypeId = getArrayTypeId(storeInfo.type); + uint32_t ptrTypeId = getPointerTypeId(storeInfo); + + uint32_t accessChain = isStructured + ? m_module.opRawAccessChain(ptrTypeId, bufferInfo.varId, + m_module.constu32(bufferInfo.stride), index.id, offsetId, + spv::RawAccessChainOperandsRobustnessPerElementNVMask) + : m_module.opRawAccessChain(ptrTypeId, bufferInfo.varId, + m_module.constu32(0), m_module.constu32(0), offsetId, + spv::RawAccessChainOperandsRobustnessPerComponentNVMask); + + uint32_t valueId = value.id; + + if (scount < value.type.ccount) { + if (scount == 1) { + valueId = m_module.opCompositeExtract(storeTypeId, value.id, 1, &sindex); + } else { + std::array indices = { sindex, sindex + 1u, sindex + 2u, sindex + 3u }; + valueId = m_module.opVectorShuffle(storeTypeId, value.id, value.id, scount, indices.data()); + } + } + + memoryOperands.alignment = alignment & -alignment; + m_module.opStore(accessChain, valueId, memoryOperands); + + writeMask &= ~(((1u << scount) - 1u) << sindex); + } else { + uint32_t srcComponentId = value.type.ccount > 1 + ? m_module.opCompositeExtract(scalarTypeId, + value.id, 1, &sindex) + : value.id; + + uint32_t elementIndexAdjusted = sindex != 0 + ? m_module.opIAdd(getVectorTypeId(elementIndex.type), + elementIndex.id, m_module.consti32(sindex)) + : elementIndex.id; + + if (isTgsm) { + m_module.opStore( + m_module.opAccessChain(bufferInfo.typeId, + bufferInfo.varId, 1, &elementIndexAdjusted), + srcComponentId, memoryOperands); + } else if (isSsbo) { + uint32_t indices[2] = { m_module.constu32(0), elementIndexAdjusted }; + m_module.opStore( + m_module.opAccessChain(bufferInfo.typeId, + bufferInfo.varId, 2, indices), + srcComponentId, memoryOperands); + } else if (dstReg.type == DxbcOperandType::UnorderedAccessView) { + const std::array srcVectorIds = { + srcComponentId, srcComponentId, + srcComponentId, srcComponentId, + }; + + m_module.opImageWrite( + bufferId, elementIndexAdjusted, + m_module.opCompositeConstruct(vectorTypeId, + 4, srcVectorIds.data()), + imageOperands); + } else { + throw DxvkError("DxbcCompiler: Invalid operand type for strucured/raw store"); + } + + writeMask &= writeMask - 1u; + } + } + } + + + void DxbcCompiler::emitConvertFloat16(const DxbcShaderInstruction& ins) { + // f32tof16 takes two operands: + // (dst0) Destination register as a uint32 vector + // (src0) Source register as a float32 vector + // f16tof32 takes two operands: + // (dst0) Destination register as a float32 vector + // (src0) Source register as a uint32 vector + const DxbcRegisterValue src = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + + // We handle both packing and unpacking here + const bool isPack = ins.op == DxbcOpcode::F32toF16; + + // The conversion instructions do not map very well to the + // SPIR-V pack instructions, which operate on 2D vectors. + std::array scalarIds = {{ 0, 0, 0, 0 }}; + + const uint32_t componentCount = src.type.ccount; + + // These types are used in both pack and unpack operations + const uint32_t t_u32 = getVectorTypeId({ DxbcScalarType::Uint32, 1 }); + const uint32_t t_f32 = getVectorTypeId({ DxbcScalarType::Float32, 1 }); + const uint32_t t_f32v2 = getVectorTypeId({ DxbcScalarType::Float32, 2 }); + + // Constant zero-bit pattern, used for packing + const uint32_t zerof32 = isPack ? m_module.constf32(0.0f) : 0; + + for (uint32_t i = 0; i < componentCount; i++) { + const DxbcRegisterValue componentValue + = emitRegisterExtract(src, DxbcRegMask::select(i)); + + if (isPack) { // f32tof16 + const std::array packIds = + {{ componentValue.id, zerof32 }}; + + scalarIds[i] = m_module.opPackHalf2x16(t_u32, + m_module.opCompositeConstruct(t_f32v2, packIds.size(), packIds.data())); + } else { // f16tof32 + const uint32_t zeroIndex = 0; + + scalarIds[i] = m_module.opCompositeExtract(t_f32, + m_module.opUnpackHalf2x16(t_f32v2, componentValue.id), + 1, &zeroIndex); + } + } + + DxbcRegisterValue result; + result.type.ctype = ins.dst[0].dataType; + result.type.ccount = componentCount; + + uint32_t typeId = getVectorTypeId(result.type); + result.id = componentCount > 1 + ? m_module.opCompositeConstruct(typeId, + componentCount, scalarIds.data()) + : scalarIds[0]; + + if (isPack) { + // Some drivers return infinity if the input value is above a certain + // threshold, but D3D wants us to return infinity only if the input is + // actually infinite. Fix this up to return the maximum representable + // 16-bit floating point number instead, but preserve input infinity. + uint32_t t_bvec = getVectorTypeId({ DxbcScalarType::Bool, componentCount }); + uint32_t f16Infinity = m_module.constuReplicant(0x7C00, componentCount); + uint32_t f16Unsigned = m_module.constuReplicant(0x7FFF, componentCount); + + uint32_t isInputInf = m_module.opIsInf(t_bvec, src.id); + uint32_t isValueInf = m_module.opIEqual(t_bvec, f16Infinity, + m_module.opBitwiseAnd(typeId, result.id, f16Unsigned)); + + result.id = m_module.opSelect(getVectorTypeId(result.type), + m_module.opLogicalAnd(t_bvec, isValueInf, m_module.opLogicalNot(t_bvec, isInputInf)), + m_module.opISub(typeId, result.id, m_module.constuReplicant(1, componentCount)), + result.id); + } + + // Store result in the destination register + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitConvertFloat64(const DxbcShaderInstruction& ins) { + // ftod and dtof take the following operands: + // (dst0) Destination operand + // (src0) Number to convert + uint32_t dstBits = ins.dst[0].mask.popCount(); + + DxbcRegMask srcMask = isDoubleType(ins.dst[0].dataType) + ? DxbcRegMask(dstBits >= 2, dstBits >= 4, false, false) + : DxbcRegMask(dstBits >= 1, dstBits >= 1, dstBits >= 2, dstBits >= 2); + + // Perform actual conversion, destination modifiers are not applied + DxbcRegisterValue val = emitRegisterLoad(ins.src[0], srcMask); + + DxbcRegisterValue result; + result.type.ctype = ins.dst[0].dataType; + result.type.ccount = val.type.ccount; + + switch (ins.op) { + case DxbcOpcode::DtoF: + case DxbcOpcode::FtoD: + result.id = m_module.opFConvert( + getVectorTypeId(result.type), val.id); + break; + + case DxbcOpcode::DtoI: + result.id = m_module.opConvertFtoS( + getVectorTypeId(result.type), val.id); + break; + + case DxbcOpcode::DtoU: + result.id = m_module.opConvertFtoU( + getVectorTypeId(result.type), val.id); + break; + + case DxbcOpcode::ItoD: + result.id = m_module.opConvertStoF( + getVectorTypeId(result.type), val.id); + break; + + case DxbcOpcode::UtoD: + result.id = m_module.opConvertUtoF( + getVectorTypeId(result.type), val.id); + break; + + default: + Logger::warn(str::format("DxbcCompiler: Unhandled instruction: ", ins.op)); + return; + } + + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitHullShaderInstCnt(const DxbcShaderInstruction& ins) { + this->getCurrentHsForkJoinPhase()->instanceCount = ins.imm[0].u32; + } + + + void DxbcCompiler::emitHullShaderPhase(const DxbcShaderInstruction& ins) { + switch (ins.op) { + case DxbcOpcode::HsDecls: { + if (m_hs.currPhaseType != DxbcCompilerHsPhase::None) + Logger::err("DXBC: HsDecls not the first phase in hull shader"); + + m_hs.currPhaseType = DxbcCompilerHsPhase::Decl; + } break; + + case DxbcOpcode::HsControlPointPhase: { + m_hs.cpPhase = this->emitNewHullShaderControlPointPhase(); + + m_hs.currPhaseType = DxbcCompilerHsPhase::ControlPoint; + m_hs.currPhaseId = 0; + + m_module.setDebugName(m_hs.cpPhase.functionId, "hs_control_point"); + } break; + + case DxbcOpcode::HsForkPhase: { + auto phase = this->emitNewHullShaderForkJoinPhase(); + m_hs.forkPhases.push_back(phase); + + m_hs.currPhaseType = DxbcCompilerHsPhase::Fork; + m_hs.currPhaseId = m_hs.forkPhases.size() - 1; + + m_module.setDebugName(phase.functionId, + str::format("hs_fork_", m_hs.currPhaseId).c_str()); + } break; + + case DxbcOpcode::HsJoinPhase: { + auto phase = this->emitNewHullShaderForkJoinPhase(); + m_hs.joinPhases.push_back(phase); + + m_hs.currPhaseType = DxbcCompilerHsPhase::Join; + m_hs.currPhaseId = m_hs.joinPhases.size() - 1; + + m_module.setDebugName(phase.functionId, + str::format("hs_join_", m_hs.currPhaseId).c_str()); + } break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + } + } + + + void DxbcCompiler::emitInterpolate(const DxbcShaderInstruction& ins) { + m_module.enableCapability(spv::CapabilityInterpolationFunction); + + // The SPIR-V instructions operate on input variable pointers, + // which are all declared as four-component float vectors. + uint32_t registerId = ins.src[0].idx[0].offset; + + DxbcRegisterValue result; + result.type = getInputRegType(registerId); + + switch (ins.op) { + case DxbcOpcode::EvalCentroid: { + result.id = m_module.opInterpolateAtCentroid( + getVectorTypeId(result.type), + m_vRegs.at(registerId).id); + } break; + + case DxbcOpcode::EvalSampleIndex: { + const DxbcRegisterValue sampleIndex = emitRegisterLoad( + ins.src[1], DxbcRegMask(true, false, false, false)); + + result.id = m_module.opInterpolateAtSample( + getVectorTypeId(result.type), + m_vRegs.at(registerId).id, + sampleIndex.id); + } break; + + case DxbcOpcode::EvalSnapped: { + // The offset is encoded as a 4-bit fixed point value + DxbcRegisterValue offset = emitRegisterLoad( + ins.src[1], DxbcRegMask(true, true, false, false)); + offset.id = m_module.opBitFieldSExtract( + getVectorTypeId(offset.type), offset.id, + m_module.consti32(0), m_module.consti32(4)); + + offset.type.ctype = DxbcScalarType::Float32; + offset.id = m_module.opConvertStoF( + getVectorTypeId(offset.type), offset.id); + + offset.id = m_module.opFMul( + getVectorTypeId(offset.type), offset.id, + m_module.constvec2f32(1.0f / 16.0f, 1.0f / 16.0f)); + + result.id = m_module.opInterpolateAtOffset( + getVectorTypeId(result.type), + m_vRegs.at(registerId).id, + offset.id); + } break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + + result = emitRegisterSwizzle(result, + ins.src[0].swizzle, ins.dst[0].mask); + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitSparseCheckAccess( + const DxbcShaderInstruction& ins) { + // check_access_mapped has two operands: + // (dst0) The destination register + // (src0) The residency code + m_module.enableCapability(spv::CapabilitySparseResidency); + + DxbcRegisterValue srcValue = emitRegisterLoad(ins.src[0], ins.dst[0].mask); + + uint32_t boolId = m_module.opImageSparseTexelsResident( + m_module.defBoolType(), srcValue.id); + + DxbcRegisterValue dstValue; + dstValue.type = { DxbcScalarType::Uint32, 1 }; + dstValue.id = m_module.opSelect(getScalarTypeId(DxbcScalarType::Uint32), + boolId, m_module.constu32(~0u), m_module.constu32(0)); + + emitRegisterStore(ins.dst[0], dstValue); + } + + + void DxbcCompiler::emitTextureQuery(const DxbcShaderInstruction& ins) { + // resinfo has three operands: + // (dst0) The destination register + // (src0) Resource LOD to query + // (src1) Resource to query + const DxbcBufferInfo resourceInfo = getBufferInfo(ins.src[1]); + const DxbcResinfoType resinfoType = ins.controls.resinfoType(); + + // Read the exact LOD for the image query + const DxbcRegisterValue mipLod = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, false, false, false)); + + const DxbcScalarType returnType = resinfoType == DxbcResinfoType::Uint + ? DxbcScalarType::Uint32 : DxbcScalarType::Float32; + + // Query the size of the selected mip level, as well as the + // total number of mip levels. We will have to combine the + // result into a four-component vector later. + DxbcRegisterValue imageSize = emitQueryTextureSize(ins.src[1], mipLod); + DxbcRegisterValue imageLevels = emitQueryTextureLods(ins.src[1]); + + // If the mip level is out of bounds, D3D requires us to return + // zero before applying modifiers, whereas SPIR-V is undefined, + // so we need to fix it up manually here. + imageSize.id = m_module.opSelect(getVectorTypeId(imageSize.type), + m_module.opULessThan(m_module.defBoolType(), mipLod.id, imageLevels.id), + imageSize.id, emitBuildZeroVector(imageSize.type).id); + + // Convert intermediates to the requested type + if (returnType == DxbcScalarType::Float32) { + imageSize.type.ctype = DxbcScalarType::Float32; + imageSize.id = m_module.opConvertUtoF( + getVectorTypeId(imageSize.type), + imageSize.id); + + imageLevels.type.ctype = DxbcScalarType::Float32; + imageLevels.id = m_module.opConvertUtoF( + getVectorTypeId(imageLevels.type), + imageLevels.id); + } + + // If the selected return type is rcpFloat, we need + // to compute the reciprocal of the image dimensions, + // but not the array size, so we need to separate it. + const uint32_t imageCoordDim = imageSize.type.ccount; + + DxbcRegisterValue imageLayers; + imageLayers.type = imageSize.type; + imageLayers.id = 0; + + if (resinfoType == DxbcResinfoType::RcpFloat && resourceInfo.image.array) { + imageLayers = emitRegisterExtract(imageSize, DxbcRegMask::select(imageCoordDim - 1)); + imageSize = emitRegisterExtract(imageSize, DxbcRegMask::firstN(imageCoordDim - 1)); + } + + if (resinfoType == DxbcResinfoType::RcpFloat) { + imageSize.id = m_module.opFDiv( + getVectorTypeId(imageSize.type), + emitBuildConstVecf32(1.0f, 1.0f, 1.0f, 1.0f, + DxbcRegMask::firstN(imageSize.type.ccount)).id, + imageSize.id); + } + + // Concatenate result vectors and scalars to form a + // 4D vector. Unused components will be set to zero. + std::array vectorIds = { imageSize.id, 0, 0, 0 }; + uint32_t numVectorIds = 1; + + if (imageLayers.id != 0) + vectorIds[numVectorIds++] = imageLayers.id; + + if (imageCoordDim < 3) { + const uint32_t zero = returnType == DxbcScalarType::Uint32 + ? m_module.constu32(0) + : m_module.constf32(0.0f); + + for (uint32_t i = imageCoordDim; i < 3; i++) + vectorIds[numVectorIds++] = zero; + } + + vectorIds[numVectorIds++] = imageLevels.id; + + // Create the actual result vector + DxbcRegisterValue result; + result.type.ctype = returnType; + result.type.ccount = 4; + result.id = m_module.opCompositeConstruct( + getVectorTypeId(result.type), + numVectorIds, vectorIds.data()); + + // Swizzle components using the resource swizzle + // and the destination operand's write mask + result = emitRegisterSwizzle(result, + ins.src[1].swizzle, ins.dst[0].mask); + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitTextureQueryLod(const DxbcShaderInstruction& ins) { + // All sample instructions have at least these operands: + // (dst0) The destination register + // (src0) Texture coordinates + // (src1) The texture itself + // (src2) The sampler object + const DxbcRegister& texCoordReg = ins.src[0]; + const DxbcRegister& textureReg = ins.src[1]; + const DxbcRegister& samplerReg = ins.src[2]; + + // Texture and sampler register IDs + const auto& texture = m_textures.at(textureReg.idx[0].offset); + const auto& sampler = m_samplers.at(samplerReg.idx[0].offset); + + // Load texture coordinates + const DxbcRegisterValue coord = emitRegisterLoad(texCoordReg, + DxbcRegMask::firstN(getTexLayerDim(texture.imageInfo))); + + // Query the LOD. The result is a two-dimensional float32 + // vector containing the mip level and virtual LOD numbers. + const uint32_t sampledImageId = emitLoadSampledImage(texture, sampler, false); + const uint32_t queriedLodId = m_module.opImageQueryLod( + getVectorTypeId({ DxbcScalarType::Float32, 2 }), + sampledImageId, coord.id); + + // Build the result array vector by filling up + // the remaining two components with zeroes. + const uint32_t zero = m_module.constf32(0.0f); + const std::array resultIds + = {{ queriedLodId, zero, zero }}; + + DxbcRegisterValue result; + result.type = DxbcVectorType { DxbcScalarType::Float32, 4 }; + result.id = m_module.opCompositeConstruct( + getVectorTypeId(result.type), + resultIds.size(), resultIds.data()); + + result = emitRegisterSwizzle(result, ins.src[1].swizzle, ins.dst[0].mask); + emitRegisterStore(ins.dst[0], result); + } + + + void DxbcCompiler::emitTextureQueryMs(const DxbcShaderInstruction& ins) { + // sampleinfo has two operands: + // (dst0) The destination register + // (src0) Resource to query + DxbcRegisterValue sampleCount = emitQueryTextureSamples(ins.src[0]); + + if (ins.controls.returnType() != DxbcInstructionReturnType::Uint) { + sampleCount.type = { DxbcScalarType::Float32, 1 }; + sampleCount.id = m_module.opConvertUtoF( + getVectorTypeId(sampleCount.type), + sampleCount.id); + } + + emitRegisterStore(ins.dst[0], sampleCount); + } + + + void DxbcCompiler::emitTextureQueryMsPos(const DxbcShaderInstruction& ins) { + // samplepos has three operands: + // (dst0) The destination register + // (src0) Resource to query + // (src1) Sample index + if (m_samplePositions == 0) + m_samplePositions = emitSamplePosArray(); + + // The lookup index is qual to the sample count plus the + // sample index, or 0 if the resource cannot be queried. + DxbcRegisterValue sampleCount = emitQueryTextureSamples(ins.src[0]); + DxbcRegisterValue sampleIndex = emitRegisterLoad( + ins.src[1], DxbcRegMask(true, false, false, false)); + + uint32_t lookupIndex = m_module.opIAdd( + getVectorTypeId(sampleCount.type), + sampleCount.id, sampleIndex.id); + + // Validate the parameters + uint32_t sampleCountValid = m_module.opULessThanEqual( + m_module.defBoolType(), + sampleCount.id, + m_module.constu32(16)); + + uint32_t sampleIndexValid = m_module.opULessThan( + m_module.defBoolType(), + sampleIndex.id, + sampleCount.id); + + // If the lookup cannot be performed, set the lookup + // index to zero, which will return a zero vector. + lookupIndex = m_module.opSelect( + getVectorTypeId(sampleCount.type), + m_module.opLogicalAnd( + m_module.defBoolType(), + sampleCountValid, + sampleIndexValid), + lookupIndex, + m_module.constu32(0)); + + // Load sample pos vector and write the masked + // components to the destination register. + DxbcRegisterPointer samplePos; + samplePos.type.ctype = DxbcScalarType::Float32; + samplePos.type.ccount = 2; + samplePos.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(samplePos.type), + spv::StorageClassPrivate), + m_samplePositions, 1, &lookupIndex); + + // Expand to vec4 by appending zeroes + DxbcRegisterValue result = emitValueLoad(samplePos); + + DxbcRegisterValue zero; + zero.type.ctype = DxbcScalarType::Float32; + zero.type.ccount = 2; + zero.id = m_module.constvec2f32(0.0f, 0.0f); + + result = emitRegisterConcat(result, zero); + + emitRegisterStore(ins.dst[0], + emitRegisterSwizzle(result, + ins.src[0].swizzle, + ins.dst[0].mask)); + } + + + void DxbcCompiler::emitTextureFetch(const DxbcShaderInstruction& ins) { + // ld has three operands: + // (dst0) The destination register + // (src0) Source address + // (src1) Source texture + // ld2dms has four operands: + // (dst0) The destination register + // (src0) Source address + // (src1) Source texture + // (src2) Sample number + const auto& texture = m_textures.at(ins.src[1].idx[0].offset); + const uint32_t imageLayerDim = getTexLayerDim(texture.imageInfo); + + bool isMultisampled = ins.op == DxbcOpcode::LdMs + || ins.op == DxbcOpcode::LdMsS; + + // Load the texture coordinates. The last component + // contains the LOD if the resource is an image. + const DxbcRegisterValue address = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, true, true, true)); + + // Additional image operands. This will store + // the LOD and the address offset if present. + SpirvImageOperands imageOperands; + imageOperands.sparse = ins.dstCount == 2; + + if (ins.sampleControls.u != 0 || ins.sampleControls.v != 0 || ins.sampleControls.w != 0) { + const std::array offsetIds = { + imageLayerDim >= 1 ? m_module.consti32(ins.sampleControls.u) : 0, + imageLayerDim >= 2 ? m_module.consti32(ins.sampleControls.v) : 0, + imageLayerDim >= 3 ? m_module.consti32(ins.sampleControls.w) : 0, + }; + + imageOperands.flags |= spv::ImageOperandsConstOffsetMask; + imageOperands.sConstOffset = offsetIds[0]; + + if (imageLayerDim > 1) { + imageOperands.sConstOffset = m_module.constComposite( + getVectorTypeId({ DxbcScalarType::Sint32, imageLayerDim }), + imageLayerDim, offsetIds.data()); + } + } + + // The LOD is not present when reading from + // a buffer or from a multisample texture. + if (texture.imageInfo.dim != spv::DimBuffer && texture.imageInfo.ms == 0) { + DxbcRegisterValue imageLod; + + if (!isMultisampled) { + imageLod = emitRegisterExtract( + address, DxbcRegMask(false, false, false, true)); + } else { + // If we force-disabled MSAA, fetch from LOD 0 + imageLod.type = { DxbcScalarType::Uint32, 1 }; + imageLod.id = m_module.constu32(0); + } + + imageOperands.flags |= spv::ImageOperandsLodMask; + imageOperands.sLod = imageLod.id; + } + + // The ld2dms instruction has a sample index, but we + // are only allowed to set it for multisample views + if (isMultisampled && texture.imageInfo.ms == 1) { + DxbcRegisterValue sampleId = emitRegisterLoad( + ins.src[2], DxbcRegMask(true, false, false, false)); + + imageOperands.flags |= spv::ImageOperandsSampleMask; + imageOperands.sSampleId = sampleId.id; + } + + // Extract coordinates from address + const DxbcRegisterValue coord = emitCalcTexCoord(address, texture.imageInfo); + + // Reading a typed image or buffer view + // always returns a four-component vector. + const uint32_t imageId = m_module.opLoad(texture.imageTypeId, texture.varId); + + DxbcVectorType texelType; + texelType.ctype = texture.sampledType; + texelType.ccount = 4; + + uint32_t texelTypeId = getVectorTypeId(texelType); + uint32_t resultTypeId = texelTypeId; + uint32_t resultId = 0; + + if (imageOperands.sparse) + resultTypeId = getSparseResultTypeId(texelTypeId); + + resultId = m_module.opImageFetch(resultTypeId, + imageId, coord.id, imageOperands); + + DxbcRegisterValue result; + result.type = texelType; + result.id = imageOperands.sparse + ? emitExtractSparseTexel(texelTypeId, resultId) + : resultId; + + // Swizzle components using the texture swizzle + // and the destination operand's write mask + result = emitRegisterSwizzle(result, + ins.src[1].swizzle, ins.dst[0].mask); + + emitRegisterStore(ins.dst[0], result); + + if (imageOperands.sparse) + emitStoreSparseFeedback(ins.dst[1], resultId); + } + + + void DxbcCompiler::emitTextureGather(const DxbcShaderInstruction& ins) { + // Gather4 takes the following operands: + // (dst0) The destination register + // (dst1) The residency code for sparse ops + // (src0) Texture coordinates + // (src1) The texture itself + // (src2) The sampler, with a component selector + // Gather4C takes the following additional operand: + // (src3) The depth reference value + // The Gather4Po variants take an additional operand + // which defines an extended constant offset. + // TODO reduce code duplication by moving some common code + // in both sample() and gather() into separate methods + const bool isExtendedGather = ins.op == DxbcOpcode::Gather4Po + || ins.op == DxbcOpcode::Gather4PoC + || ins.op == DxbcOpcode::Gather4PoS + || ins.op == DxbcOpcode::Gather4PoCS; + + const DxbcRegister& texCoordReg = ins.src[0]; + const DxbcRegister& textureReg = ins.src[1 + isExtendedGather]; + const DxbcRegister& samplerReg = ins.src[2 + isExtendedGather]; + + // Texture and sampler register IDs + const auto& texture = m_textures.at(textureReg.idx[0].offset); + const auto& sampler = m_samplers.at(samplerReg.idx[0].offset); + + // Image type, which stores the image dimensions etc. + const uint32_t imageLayerDim = getTexLayerDim(texture.imageInfo); + + // Load the texture coordinates. SPIR-V allows these + // to be float4 even if not all components are used. + DxbcRegisterValue coord = emitLoadTexCoord(texCoordReg, texture.imageInfo); + + // Load reference value for depth-compare operations + const bool isDepthCompare = ins.op == DxbcOpcode::Gather4C + || ins.op == DxbcOpcode::Gather4PoC + || ins.op == DxbcOpcode::Gather4CS + || ins.op == DxbcOpcode::Gather4PoCS; + + const DxbcRegisterValue referenceValue = isDepthCompare + ? emitRegisterLoad(ins.src[3 + isExtendedGather], + DxbcRegMask(true, false, false, false)) + : DxbcRegisterValue(); + + // Accumulate additional image operands. + SpirvImageOperands imageOperands; + imageOperands.sparse = ins.dstCount == 2; + + if (isExtendedGather) { + m_module.enableCapability(spv::CapabilityImageGatherExtended); + + DxbcRegisterValue gatherOffset = emitRegisterLoad( + ins.src[1], DxbcRegMask::firstN(imageLayerDim)); + + imageOperands.flags |= spv::ImageOperandsOffsetMask; + imageOperands.gOffset = gatherOffset.id; + } else if (ins.sampleControls.u != 0 || ins.sampleControls.v != 0 || ins.sampleControls.w != 0) { + const std::array offsetIds = { + imageLayerDim >= 1 ? m_module.consti32(ins.sampleControls.u) : 0, + imageLayerDim >= 2 ? m_module.consti32(ins.sampleControls.v) : 0, + imageLayerDim >= 3 ? m_module.consti32(ins.sampleControls.w) : 0, + }; + + imageOperands.flags |= spv::ImageOperandsConstOffsetMask; + imageOperands.sConstOffset = offsetIds[0]; + + if (imageLayerDim > 1) { + imageOperands.sConstOffset = m_module.constComposite( + getVectorTypeId({ DxbcScalarType::Sint32, imageLayerDim }), + imageLayerDim, offsetIds.data()); + } + } + + // Gathering texels always returns a four-component + // vector, even for the depth-compare variants. + uint32_t sampledImageId = emitLoadSampledImage(texture, sampler, isDepthCompare); + + DxbcVectorType texelType; + texelType.ctype = texture.sampledType; + texelType.ccount = 4; + + uint32_t texelTypeId = getVectorTypeId(texelType); + uint32_t resultTypeId = texelTypeId; + uint32_t resultId = 0; + + if (imageOperands.sparse) + resultTypeId = getSparseResultTypeId(texelTypeId); + + if (sampledImageId) { + switch (ins.op) { + // Simple image gather operation + case DxbcOpcode::Gather4: + case DxbcOpcode::Gather4S: + case DxbcOpcode::Gather4Po: + case DxbcOpcode::Gather4PoS: { + resultId = m_module.opImageGather( + resultTypeId, sampledImageId, coord.id, + m_module.consti32(samplerReg.swizzle[0]), + imageOperands); + } break; + + // Depth-compare operation + case DxbcOpcode::Gather4C: + case DxbcOpcode::Gather4CS: + case DxbcOpcode::Gather4PoC: + case DxbcOpcode::Gather4PoCS: { + resultId = m_module.opImageDrefGather( + resultTypeId, sampledImageId, coord.id, + referenceValue.id, imageOperands); + } break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + } else { + Logger::warn(str::format("DxbcCompiler: ", ins.op, ": Unsupported image type")); + resultId = m_module.constNull(resultTypeId); + } + + // If necessary, deal with the sparse result + DxbcRegisterValue result; + result.type = texelType; + result.id = imageOperands.sparse + ? emitExtractSparseTexel(texelTypeId, resultId) + : resultId; + + // Swizzle components using the texture swizzle + // and the destination operand's write mask + result = emitRegisterSwizzle(result, + textureReg.swizzle, ins.dst[0].mask); + + emitRegisterStore(ins.dst[0], result); + + if (imageOperands.sparse) + emitStoreSparseFeedback(ins.dst[1], resultId); + } + + + void DxbcCompiler::emitTextureSample(const DxbcShaderInstruction& ins) { + // All sample instructions have at least these operands: + // (dst0) The destination register + // (src0) Texture coordinates + // (src1) The texture itself + // (src2) The sampler object + const DxbcRegister& texCoordReg = ins.src[0]; + const DxbcRegister& textureReg = ins.src[1]; + const DxbcRegister& samplerReg = ins.src[2]; + + // Texture and sampler register IDs + const auto& texture = m_textures.at(textureReg.idx[0].offset); + const auto& sampler = m_samplers.at(samplerReg.idx[0].offset); + const uint32_t imageLayerDim = getTexLayerDim(texture.imageInfo); + + // Load the texture coordinates. SPIR-V allows these + // to be float4 even if not all components are used. + DxbcRegisterValue coord = emitLoadTexCoord(texCoordReg, texture.imageInfo); + + // Load reference value for depth-compare operations + const bool isDepthCompare = ins.op == DxbcOpcode::SampleC + || ins.op == DxbcOpcode::SampleClz + || ins.op == DxbcOpcode::SampleCClampS + || ins.op == DxbcOpcode::SampleClzS; + + const DxbcRegisterValue referenceValue = isDepthCompare + ? emitRegisterLoad(ins.src[3], DxbcRegMask(true, false, false, false)) + : DxbcRegisterValue(); + + // Load explicit gradients for sample operations that require them + const bool hasExplicitGradients = ins.op == DxbcOpcode::SampleD + || ins.op == DxbcOpcode::SampleDClampS; + + const DxbcRegisterValue explicitGradientX = hasExplicitGradients + ? emitRegisterLoad(ins.src[3], DxbcRegMask::firstN(imageLayerDim)) + : DxbcRegisterValue(); + + const DxbcRegisterValue explicitGradientY = hasExplicitGradients + ? emitRegisterLoad(ins.src[4], DxbcRegMask::firstN(imageLayerDim)) + : DxbcRegisterValue(); + + // LOD for certain sample operations + const bool hasLod = ins.op == DxbcOpcode::SampleL + || ins.op == DxbcOpcode::SampleLS + || ins.op == DxbcOpcode::SampleB + || ins.op == DxbcOpcode::SampleBClampS; + + const DxbcRegisterValue lod = hasLod + ? emitRegisterLoad(ins.src[3], DxbcRegMask(true, false, false, false)) + : DxbcRegisterValue(); + + // Min LOD for certain sparse operations + const bool hasMinLod = ins.op == DxbcOpcode::SampleClampS + || ins.op == DxbcOpcode::SampleBClampS + || ins.op == DxbcOpcode::SampleDClampS + || ins.op == DxbcOpcode::SampleCClampS; + + const DxbcRegisterValue minLod = hasMinLod && ins.src[ins.srcCount - 1].type != DxbcOperandType::Null + ? emitRegisterLoad(ins.src[ins.srcCount - 1], DxbcRegMask(true, false, false, false)) + : DxbcRegisterValue(); + + // Accumulate additional image operands. These are + // not part of the actual operand token in SPIR-V. + SpirvImageOperands imageOperands; + imageOperands.sparse = ins.dstCount == 2; + + if (ins.sampleControls.u != 0 || ins.sampleControls.v != 0 || ins.sampleControls.w != 0) { + const std::array offsetIds = { + imageLayerDim >= 1 ? m_module.consti32(ins.sampleControls.u) : 0, + imageLayerDim >= 2 ? m_module.consti32(ins.sampleControls.v) : 0, + imageLayerDim >= 3 ? m_module.consti32(ins.sampleControls.w) : 0, + }; + + imageOperands.flags |= spv::ImageOperandsConstOffsetMask; + imageOperands.sConstOffset = offsetIds[0]; + + if (imageLayerDim > 1) { + imageOperands.sConstOffset = m_module.constComposite( + getVectorTypeId({ DxbcScalarType::Sint32, imageLayerDim }), + imageLayerDim, offsetIds.data()); + } + } + + if (hasMinLod) { + m_module.enableCapability(spv::CapabilityMinLod); + + imageOperands.flags |= spv::ImageOperandsMinLodMask; + imageOperands.sMinLod = minLod.id; + } + + // Combine the texture and the sampler into a sampled image + uint32_t sampledImageId = emitLoadSampledImage(texture, sampler, isDepthCompare); + + // Sampling an image always returns a four-component + // vector, whereas depth-compare ops return a scalar. + DxbcVectorType texelType; + texelType.ctype = texture.sampledType; + texelType.ccount = isDepthCompare ? 1 : 4; + + uint32_t texelTypeId = getVectorTypeId(texelType); + uint32_t resultTypeId = texelTypeId; + uint32_t resultId = 0; + + if (imageOperands.sparse) + resultTypeId = getSparseResultTypeId(texelTypeId); + + if (sampledImageId) { + switch (ins.op) { + // Simple image sample operation + case DxbcOpcode::Sample: + case DxbcOpcode::SampleClampS: { + resultId = m_module.opImageSampleImplicitLod( + resultTypeId, sampledImageId, coord.id, + imageOperands); + } break; + + // Depth-compare operation + case DxbcOpcode::SampleC: + case DxbcOpcode::SampleCClampS: { + resultId = m_module.opImageSampleDrefImplicitLod( + resultTypeId, sampledImageId, coord.id, + referenceValue.id, imageOperands); + } break; + + // Depth-compare operation on mip level zero + case DxbcOpcode::SampleClz: + case DxbcOpcode::SampleClzS: { + imageOperands.flags |= spv::ImageOperandsLodMask; + imageOperands.sLod = m_module.constf32(0.0f); + + resultId = m_module.opImageSampleDrefExplicitLod( + resultTypeId, sampledImageId, coord.id, + referenceValue.id, imageOperands); + } break; + + // Sample operation with explicit gradients + case DxbcOpcode::SampleD: + case DxbcOpcode::SampleDClampS: { + imageOperands.flags |= spv::ImageOperandsGradMask; + imageOperands.sGradX = explicitGradientX.id; + imageOperands.sGradY = explicitGradientY.id; + + resultId = m_module.opImageSampleExplicitLod( + resultTypeId, sampledImageId, coord.id, + imageOperands); + } break; + + // Sample operation with explicit LOD + case DxbcOpcode::SampleL: + case DxbcOpcode::SampleLS: { + imageOperands.flags |= spv::ImageOperandsLodMask; + imageOperands.sLod = lod.id; + + resultId = m_module.opImageSampleExplicitLod( + resultTypeId, sampledImageId, coord.id, + imageOperands); + } break; + + // Sample operation with LOD bias + case DxbcOpcode::SampleB: + case DxbcOpcode::SampleBClampS: { + imageOperands.flags |= spv::ImageOperandsBiasMask; + imageOperands.sLodBias = lod.id; + + resultId = m_module.opImageSampleImplicitLod( + resultTypeId, sampledImageId, coord.id, + imageOperands); + } break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + return; + } + } else { + Logger::warn(str::format("DxbcCompiler: ", ins.op, ": Unsupported image type")); + resultId = m_module.constNull(resultTypeId); + } + + DxbcRegisterValue result; + result.type = texelType; + result.id = imageOperands.sparse + ? emitExtractSparseTexel(texelTypeId, resultId) + : resultId; + + // Swizzle components using the texture swizzle + // and the destination operand's write mask + if (result.type.ccount != 1) { + result = emitRegisterSwizzle(result, + textureReg.swizzle, ins.dst[0].mask); + } + + emitRegisterStore(ins.dst[0], result); + + if (imageOperands.sparse) + emitStoreSparseFeedback(ins.dst[1], resultId); + } + + + void DxbcCompiler::emitTypedUavLoad(const DxbcShaderInstruction& ins) { + // load_uav_typed has three operands: + // (dst0) The destination register + // (src0) The texture or buffer coordinates + // (src1) The UAV to load from + const uint32_t registerId = ins.src[1].idx[0].offset; + const DxbcUav uavInfo = m_uavs.at(registerId); + + emitUavBarrier(uint64_t(1u) << registerId, 0u); + + // Load texture coordinates + DxbcRegisterValue texCoord = emitLoadTexCoord( + ins.src[0], uavInfo.imageInfo); + + SpirvImageOperands imageOperands; + imageOperands.sparse = ins.dstCount == 2; + + if (uavInfo.coherence) { + imageOperands.flags |= spv::ImageOperandsNonPrivateTexelMask + | spv::ImageOperandsMakeTexelVisibleMask; + imageOperands.makeVisible = m_module.constu32(uavInfo.coherence); + } + + DxbcVectorType texelType; + texelType.ctype = uavInfo.sampledType; + texelType.ccount = 4; + + uint32_t texelTypeId = getVectorTypeId(texelType); + uint32_t resultTypeId = texelTypeId; + uint32_t resultId = 0; + + if (imageOperands.sparse) + resultTypeId = getSparseResultTypeId(texelTypeId); + + // Load source value from the UAV + resultId = m_module.opImageRead(resultTypeId, + m_module.opLoad(uavInfo.imageTypeId, uavInfo.varId), + texCoord.id, imageOperands); + + // Apply component swizzle and mask + DxbcRegisterValue uavValue; + uavValue.type = texelType; + uavValue.id = imageOperands.sparse + ? emitExtractSparseTexel(texelTypeId, resultId) + : resultId; + + uavValue = emitRegisterSwizzle(uavValue, + ins.src[1].swizzle, ins.dst[0].mask); + + emitRegisterStore(ins.dst[0], uavValue); + + if (imageOperands.sparse) + emitStoreSparseFeedback(ins.dst[1], resultId); + } + + + void DxbcCompiler::emitTypedUavStore(const DxbcShaderInstruction& ins) { + // store_uav_typed has three operands: + // (dst0) The destination UAV + // (src0) The texture or buffer coordinates + // (src1) The value to store + const DxbcBufferInfo uavInfo = getBufferInfo(ins.dst[0]); + emitUavBarrier(0u, uint64_t(1u) << ins.dst[0].idx[0].offset); + + // Set image operands for coherent access if necessary + SpirvImageOperands imageOperands; + + if (uavInfo.coherence) { + imageOperands.flags |= spv::ImageOperandsNonPrivateTexelMask + | spv::ImageOperandsMakeTexelAvailableMask; + imageOperands.makeAvailable = m_module.constu32(uavInfo.coherence); + } + + // Load texture coordinates + DxbcRegisterValue texCoord = emitLoadTexCoord(ins.src[0], uavInfo.image); + + // Load the value that will be written to the image. We'll + // have to cast it to the component type of the image. + const DxbcRegisterValue texValue = emitRegisterBitcast( + emitRegisterLoad(ins.src[1], DxbcRegMask(true, true, true, true)), + uavInfo.stype); + + // Write the given value to the image + m_module.opImageWrite( + m_module.opLoad(uavInfo.typeId, uavInfo.varId), + texCoord.id, texValue.id, imageOperands); + } + + + void DxbcCompiler::emitControlFlowIf(const DxbcShaderInstruction& ins) { + // Load the first component of the condition + // operand and perform a zero test on it. + const DxbcRegisterValue condition = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, false, false, false)); + + // Declare the 'if' block. We do not know if there + // will be an 'else' block or not, so we'll assume + // that there is one and leave it empty otherwise. + DxbcCfgBlock block; + block.type = DxbcCfgBlockType::If; + block.b_if.ztestId = emitRegisterZeroTest(condition, ins.controls.zeroTest()).id; + block.b_if.labelIf = m_module.allocateId(); + block.b_if.labelElse = 0; + block.b_if.labelEnd = m_module.allocateId(); + block.b_if.headerPtr = m_module.getInsertionPtr(); + m_controlFlowBlocks.push_back(block); + + // We'll insert the branch instruction when closing + // the block, since we don't know whether or not an + // else block is needed right now. + m_module.opLabel(block.b_if.labelIf); + } + + + void DxbcCompiler::emitControlFlowElse(const DxbcShaderInstruction& ins) { + if (m_controlFlowBlocks.size() == 0 + || m_controlFlowBlocks.back().type != DxbcCfgBlockType::If + || m_controlFlowBlocks.back().b_if.labelElse != 0) + throw DxvkError("DxbcCompiler: 'Else' without 'If' found"); + + // Set the 'Else' flag so that we do + // not insert a dummy block on 'EndIf' + DxbcCfgBlock& block = m_controlFlowBlocks.back(); + block.b_if.labelElse = m_module.allocateId(); + + // Close the 'If' block by branching to + // the merge block we declared earlier + m_module.opBranch(block.b_if.labelEnd); + m_module.opLabel (block.b_if.labelElse); + } + + + void DxbcCompiler::emitControlFlowEndIf(const DxbcShaderInstruction& ins) { + if (m_controlFlowBlocks.size() == 0 + || m_controlFlowBlocks.back().type != DxbcCfgBlockType::If) + throw DxvkError("DxbcCompiler: 'EndIf' without 'If' found"); + + // Remove the block from the stack, it's closed + DxbcCfgBlock block = m_controlFlowBlocks.back(); + m_controlFlowBlocks.pop_back(); + + // Write out the 'if' header + m_module.beginInsertion(block.b_if.headerPtr); + + m_module.opSelectionMerge( + block.b_if.labelEnd, + spv::SelectionControlMaskNone); + + m_module.opBranchConditional( + block.b_if.ztestId, + block.b_if.labelIf, + block.b_if.labelElse != 0 + ? block.b_if.labelElse + : block.b_if.labelEnd); + + m_module.endInsertion(); + + // End the active 'if' or 'else' block + m_module.opBranch(block.b_if.labelEnd); + m_module.opLabel (block.b_if.labelEnd); + } + + + void DxbcCompiler::emitControlFlowSwitch(const DxbcShaderInstruction& ins) { + // Load the selector as a scalar unsigned integer + const DxbcRegisterValue selector = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, false, false, false)); + + // Declare switch block. We cannot insert the switch + // instruction itself yet because the number of case + // statements and blocks is unknown at this point. + DxbcCfgBlock block; + block.type = DxbcCfgBlockType::Switch; + block.b_switch.insertPtr = m_module.getInsertionPtr(); + block.b_switch.selectorId = selector.id; + block.b_switch.labelBreak = m_module.allocateId(); + block.b_switch.labelCase = m_module.allocateId(); + block.b_switch.labelDefault = 0; + block.b_switch.labelCases = nullptr; + m_controlFlowBlocks.push_back(block); + + // Define the first 'case' label + m_module.opLabel(block.b_switch.labelCase); + } + + + void DxbcCompiler::emitControlFlowCase(const DxbcShaderInstruction& ins) { + if (m_controlFlowBlocks.size() == 0 + || m_controlFlowBlocks.back().type != DxbcCfgBlockType::Switch) + throw DxvkError("DxbcCompiler: 'Case' without 'Switch' found"); + + // The source operand must be a 32-bit immediate. + if (ins.src[0].type != DxbcOperandType::Imm32) + throw DxvkError("DxbcCompiler: Invalid operand type for 'Case'"); + + // Use the last label allocated for 'case'. + DxbcCfgBlockSwitch* block = &m_controlFlowBlocks.back().b_switch; + + if (caseBlockIsFallthrough()) { + block->labelCase = m_module.allocateId(); + + m_module.opBranch(block->labelCase); + m_module.opLabel (block->labelCase); + } + + DxbcSwitchLabel label; + label.desc.literal = ins.src[0].imm.u32_1; + label.desc.labelId = block->labelCase; + label.next = block->labelCases; + block->labelCases = new DxbcSwitchLabel(label); + } + + + void DxbcCompiler::emitControlFlowDefault(const DxbcShaderInstruction& ins) { + if (m_controlFlowBlocks.size() == 0 + || m_controlFlowBlocks.back().type != DxbcCfgBlockType::Switch) + throw DxvkError("DxbcCompiler: 'Default' without 'Switch' found"); + + DxbcCfgBlockSwitch* block = &m_controlFlowBlocks.back().b_switch; + + if (caseBlockIsFallthrough()) { + block->labelCase = m_module.allocateId(); + + m_module.opBranch(block->labelCase); + m_module.opLabel (block->labelCase); + } + + // Set the last label allocated for 'case' as the default label. + block->labelDefault = block->labelCase; + } + + + void DxbcCompiler::emitControlFlowEndSwitch(const DxbcShaderInstruction& ins) { + if (m_controlFlowBlocks.size() == 0 + || m_controlFlowBlocks.back().type != DxbcCfgBlockType::Switch) + throw DxvkError("DxbcCompiler: 'EndSwitch' without 'Switch' found"); + + // Remove the block from the stack, it's closed + DxbcCfgBlock block = m_controlFlowBlocks.back(); + m_controlFlowBlocks.pop_back(); + + if (!block.b_switch.labelDefault) { + block.b_switch.labelDefault = caseBlockIsFallthrough() + ? block.b_switch.labelBreak + : block.b_switch.labelCase; + } + + // Close the current 'case' block + m_module.opBranch(block.b_switch.labelBreak); + + // Insert the 'switch' statement. For that, we need to + // gather all the literal-label pairs for the construct. + m_module.beginInsertion(block.b_switch.insertPtr); + m_module.opSelectionMerge( + block.b_switch.labelBreak, + spv::SelectionControlMaskNone); + + // We'll restore the original order of the case labels here + std::vector jumpTargets; + for (auto i = block.b_switch.labelCases; i != nullptr; i = i->next) + jumpTargets.insert(jumpTargets.begin(), i->desc); + + m_module.opSwitch( + block.b_switch.selectorId, + block.b_switch.labelDefault, + jumpTargets.size(), + jumpTargets.data()); + m_module.endInsertion(); + + // Destroy the list of case labels + // FIXME we're leaking memory if compilation fails. + DxbcSwitchLabel* caseLabel = block.b_switch.labelCases; + + while (caseLabel != nullptr) + delete std::exchange(caseLabel, caseLabel->next); + + // Begin new block after switch blocks + m_module.opLabel(block.b_switch.labelBreak); + } + + + void DxbcCompiler::emitControlFlowLoop(const DxbcShaderInstruction& ins) { + // Declare the 'loop' block + DxbcCfgBlock block; + block.type = DxbcCfgBlockType::Loop; + block.b_loop.labelHeader = m_module.allocateId(); + block.b_loop.labelBegin = m_module.allocateId(); + block.b_loop.labelContinue = m_module.allocateId(); + block.b_loop.labelBreak = m_module.allocateId(); + m_controlFlowBlocks.push_back(block); + + m_module.opBranch(block.b_loop.labelHeader); + m_module.opLabel (block.b_loop.labelHeader); + + m_module.opLoopMerge( + block.b_loop.labelBreak, + block.b_loop.labelContinue, + spv::LoopControlMaskNone); + + m_module.opBranch(block.b_loop.labelBegin); + m_module.opLabel (block.b_loop.labelBegin); + } + + + void DxbcCompiler::emitControlFlowEndLoop(const DxbcShaderInstruction& ins) { + if (m_controlFlowBlocks.size() == 0 + || m_controlFlowBlocks.back().type != DxbcCfgBlockType::Loop) + throw DxvkError("DxbcCompiler: 'EndLoop' without 'Loop' found"); + + // Remove the block from the stack, it's closed + const DxbcCfgBlock block = m_controlFlowBlocks.back(); + m_controlFlowBlocks.pop_back(); + + // Declare the continue block + m_module.opBranch(block.b_loop.labelContinue); + m_module.opLabel (block.b_loop.labelContinue); + + // Declare the merge block + m_module.opBranch(block.b_loop.labelHeader); + m_module.opLabel (block.b_loop.labelBreak); + } + + + void DxbcCompiler::emitControlFlowBreak(const DxbcShaderInstruction& ins) { + const bool isBreak = ins.op == DxbcOpcode::Break; + + DxbcCfgBlock* cfgBlock = isBreak + ? cfgFindBlock({ DxbcCfgBlockType::Loop, DxbcCfgBlockType::Switch }) + : cfgFindBlock({ DxbcCfgBlockType::Loop }); + + if (cfgBlock == nullptr) + throw DxvkError("DxbcCompiler: 'Break' or 'Continue' outside 'Loop' or 'Switch' found"); + + if (cfgBlock->type == DxbcCfgBlockType::Loop) { + m_module.opBranch(isBreak + ? cfgBlock->b_loop.labelBreak + : cfgBlock->b_loop.labelContinue); + } else /* if (cfgBlock->type == DxbcCfgBlockType::Switch) */ { + m_module.opBranch(cfgBlock->b_switch.labelBreak); + } + + // Subsequent instructions assume that there is an open block + const uint32_t labelId = m_module.allocateId(); + m_module.opLabel(labelId); + + // If this is on the same level as a switch-case construct, + // rather than being nested inside an 'if' statement, close + // the current 'case' block. + if (m_controlFlowBlocks.back().type == DxbcCfgBlockType::Switch) + cfgBlock->b_switch.labelCase = labelId; + } + + + void DxbcCompiler::emitControlFlowBreakc(const DxbcShaderInstruction& ins) { + const bool isBreak = ins.op == DxbcOpcode::Breakc; + + DxbcCfgBlock* cfgBlock = isBreak + ? cfgFindBlock({ DxbcCfgBlockType::Loop, DxbcCfgBlockType::Switch }) + : cfgFindBlock({ DxbcCfgBlockType::Loop }); + + if (cfgBlock == nullptr) + throw DxvkError("DxbcCompiler: 'Breakc' or 'Continuec' outside 'Loop' or 'Switch' found"); + + // Perform zero test on the first component of the condition + const DxbcRegisterValue condition = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, false, false, false)); + + const DxbcRegisterValue zeroTest = emitRegisterZeroTest( + condition, ins.controls.zeroTest()); + + // We basically have to wrap this into an 'if' block + const uint32_t breakBlock = m_module.allocateId(); + const uint32_t mergeBlock = m_module.allocateId(); + + m_module.opSelectionMerge(mergeBlock, + spv::SelectionControlMaskNone); + + m_module.opBranchConditional( + zeroTest.id, breakBlock, mergeBlock); + + m_module.opLabel(breakBlock); + + if (cfgBlock->type == DxbcCfgBlockType::Loop) { + m_module.opBranch(isBreak + ? cfgBlock->b_loop.labelBreak + : cfgBlock->b_loop.labelContinue); + } else /* if (cfgBlock->type == DxbcCfgBlockType::Switch) */ { + m_module.opBranch(cfgBlock->b_switch.labelBreak); + } + + m_module.opLabel(mergeBlock); + } + + + void DxbcCompiler::emitControlFlowRet(const DxbcShaderInstruction& ins) { + if (m_controlFlowBlocks.size() != 0) { + uint32_t labelId = m_module.allocateId(); + + m_module.opReturn(); + m_module.opLabel(labelId); + + // return can be used in place of break to terminate a case block + if (m_controlFlowBlocks.back().type == DxbcCfgBlockType::Switch) + m_controlFlowBlocks.back().b_switch.labelCase = labelId; + + m_topLevelIsUniform = false; + } else { + // Last instruction in the current function + this->emitFunctionEnd(); + } + } + + + void DxbcCompiler::emitControlFlowRetc(const DxbcShaderInstruction& ins) { + // Perform zero test on the first component of the condition + const DxbcRegisterValue condition = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, false, false, false)); + + const DxbcRegisterValue zeroTest = emitRegisterZeroTest( + condition, ins.controls.zeroTest()); + + // We basically have to wrap this into an 'if' block + const uint32_t returnLabel = m_module.allocateId(); + const uint32_t continueLabel = m_module.allocateId(); + + m_module.opSelectionMerge(continueLabel, + spv::SelectionControlMaskNone); + + m_module.opBranchConditional( + zeroTest.id, returnLabel, continueLabel); + + m_module.opLabel(returnLabel); + m_module.opReturn(); + + m_module.opLabel(continueLabel); + + // The return condition may be non-uniform + m_topLevelIsUniform = false; + } + + + void DxbcCompiler::emitControlFlowDiscard(const DxbcShaderInstruction& ins) { + // Discard actually has an operand that determines + // whether or not the fragment should be discarded + const DxbcRegisterValue condition = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, false, false, false)); + + const DxbcRegisterValue zeroTest = emitRegisterZeroTest( + condition, ins.controls.zeroTest()); + + DxbcConditional cond; + cond.labelIf = m_module.allocateId(); + cond.labelEnd = m_module.allocateId(); + + m_module.opSelectionMerge(cond.labelEnd, spv::SelectionControlMaskNone); + m_module.opBranchConditional(zeroTest.id, cond.labelIf, cond.labelEnd); + + m_module.opLabel(cond.labelIf); + m_module.opDemoteToHelperInvocation(); + m_module.opBranch(cond.labelEnd); + + m_module.opLabel(cond.labelEnd); + + m_module.enableCapability(spv::CapabilityDemoteToHelperInvocation); + + // Discard is just retc in a trenchcoat + m_topLevelIsUniform = false; + } + + + void DxbcCompiler::emitControlFlowLabel(const DxbcShaderInstruction& ins) { + uint32_t functionNr = ins.dst[0].idx[0].offset; + uint32_t functionId = getFunctionId(functionNr); + + this->emitFunctionBegin( + functionId, + m_module.defVoidType(), + m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr)); + + m_module.opLabel(m_module.allocateId()); + m_module.setDebugName(functionId, str::format("label", functionNr).c_str()); + + m_insideFunction = true; + + // We have to assume that this function gets + // called from non-uniform control flow + m_topLevelIsUniform = false; + } + + + void DxbcCompiler::emitControlFlowCall(const DxbcShaderInstruction& ins) { + uint32_t functionNr = ins.src[0].idx[0].offset; + uint32_t functionId = getFunctionId(functionNr); + + m_module.opFunctionCall( + m_module.defVoidType(), + functionId, 0, nullptr); + } + + + void DxbcCompiler::emitControlFlowCallc(const DxbcShaderInstruction& ins) { + uint32_t functionNr = ins.src[1].idx[0].offset; + uint32_t functionId = getFunctionId(functionNr); + + // Perform zero test on the first component of the condition + const DxbcRegisterValue condition = emitRegisterLoad( + ins.src[0], DxbcRegMask(true, false, false, false)); + + const DxbcRegisterValue zeroTest = emitRegisterZeroTest( + condition, ins.controls.zeroTest()); + + // We basically have to wrap this into an 'if' block + const uint32_t callLabel = m_module.allocateId(); + const uint32_t skipLabel = m_module.allocateId(); + + m_module.opSelectionMerge(skipLabel, + spv::SelectionControlMaskNone); + + m_module.opBranchConditional( + zeroTest.id, callLabel, skipLabel); + + m_module.opLabel(callLabel); + m_module.opFunctionCall( + m_module.defVoidType(), + functionId, 0, nullptr); + + m_module.opBranch(skipLabel); + m_module.opLabel(skipLabel); + } + + + void DxbcCompiler::emitControlFlow(const DxbcShaderInstruction& ins) { + switch (ins.op) { + case DxbcOpcode::If: + this->emitUavBarrier(0, 0); + this->emitControlFlowIf(ins); + break; + + case DxbcOpcode::Else: + this->emitControlFlowElse(ins); + break; + + case DxbcOpcode::EndIf: + this->emitControlFlowEndIf(ins); + this->emitUavBarrier(0, 0); + break; + + case DxbcOpcode::Switch: + this->emitUavBarrier(0, 0); + this->emitControlFlowSwitch(ins); + break; + + case DxbcOpcode::Case: + this->emitControlFlowCase(ins); + break; + + case DxbcOpcode::Default: + this->emitControlFlowDefault(ins); + break; + + case DxbcOpcode::EndSwitch: + this->emitControlFlowEndSwitch(ins); + this->emitUavBarrier(0, 0); + break; + + case DxbcOpcode::Loop: + this->emitUavBarrier(0, 0); + this->emitControlFlowLoop(ins); + break; + + case DxbcOpcode::EndLoop: + this->emitControlFlowEndLoop(ins); + this->emitUavBarrier(0, 0); + break; + + case DxbcOpcode::Break: + case DxbcOpcode::Continue: + this->emitControlFlowBreak(ins); + break; + + case DxbcOpcode::Breakc: + case DxbcOpcode::Continuec: + this->emitControlFlowBreakc(ins); + break; + + case DxbcOpcode::Ret: + this->emitControlFlowRet(ins); + break; + + case DxbcOpcode::Retc: + this->emitUavBarrier(0, 0); + this->emitControlFlowRetc(ins); + break; + + case DxbcOpcode::Discard: + this->emitControlFlowDiscard(ins); + break; + + case DxbcOpcode::Label: + this->emitControlFlowLabel(ins); + break; + + case DxbcOpcode::Call: + this->emitUavBarrier(0, 0); + this->emitControlFlowCall(ins); + this->emitUavBarrier(-1, -1); + break; + + case DxbcOpcode::Callc: + this->emitUavBarrier(0, 0); + this->emitControlFlowCallc(ins); + this->emitUavBarrier(-1, -1); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled instruction: ", + ins.op)); + } + } + + + DxbcRegisterValue DxbcCompiler::emitBuildConstVecf32( + float x, + float y, + float z, + float w, + const DxbcRegMask& writeMask) { + // TODO refactor these functions into one single template + std::array ids = { 0, 0, 0, 0 }; + uint32_t componentIndex = 0; + + if (writeMask[0]) ids[componentIndex++] = m_module.constf32(x); + if (writeMask[1]) ids[componentIndex++] = m_module.constf32(y); + if (writeMask[2]) ids[componentIndex++] = m_module.constf32(z); + if (writeMask[3]) ids[componentIndex++] = m_module.constf32(w); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Float32; + result.type.ccount = componentIndex; + result.id = componentIndex > 1 + ? m_module.constComposite( + getVectorTypeId(result.type), + componentIndex, ids.data()) + : ids[0]; + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitBuildConstVecu32( + uint32_t x, + uint32_t y, + uint32_t z, + uint32_t w, + const DxbcRegMask& writeMask) { + std::array ids = { 0, 0, 0, 0 }; + uint32_t componentIndex = 0; + + if (writeMask[0]) ids[componentIndex++] = m_module.constu32(x); + if (writeMask[1]) ids[componentIndex++] = m_module.constu32(y); + if (writeMask[2]) ids[componentIndex++] = m_module.constu32(z); + if (writeMask[3]) ids[componentIndex++] = m_module.constu32(w); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = componentIndex; + result.id = componentIndex > 1 + ? m_module.constComposite( + getVectorTypeId(result.type), + componentIndex, ids.data()) + : ids[0]; + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitBuildConstVeci32( + int32_t x, + int32_t y, + int32_t z, + int32_t w, + const DxbcRegMask& writeMask) { + std::array ids = { 0, 0, 0, 0 }; + uint32_t componentIndex = 0; + + if (writeMask[0]) ids[componentIndex++] = m_module.consti32(x); + if (writeMask[1]) ids[componentIndex++] = m_module.consti32(y); + if (writeMask[2]) ids[componentIndex++] = m_module.consti32(z); + if (writeMask[3]) ids[componentIndex++] = m_module.consti32(w); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Sint32; + result.type.ccount = componentIndex; + result.id = componentIndex > 1 + ? m_module.constComposite( + getVectorTypeId(result.type), + componentIndex, ids.data()) + : ids[0]; + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitBuildConstVecf64( + double xy, + double zw, + const DxbcRegMask& writeMask) { + std::array ids = { 0, 0 }; + uint32_t componentIndex = 0; + + if (writeMask[0] && writeMask[1]) ids[componentIndex++] = m_module.constf64(xy); + if (writeMask[2] && writeMask[3]) ids[componentIndex++] = m_module.constf64(zw); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Float64; + result.type.ccount = componentIndex; + result.id = componentIndex > 1 + ? m_module.constComposite( + getVectorTypeId(result.type), + componentIndex, ids.data()) + : ids[0]; + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitBuildVector( + DxbcRegisterValue scalar, + uint32_t count) { + if (count == 1) + return scalar; + + std::array scalarIds = + { scalar.id, scalar.id, scalar.id, scalar.id }; + + DxbcRegisterValue result; + result.type.ctype = scalar.type.ctype; + result.type.ccount = count; + result.id = m_module.constComposite( + getVectorTypeId(result.type), + count, scalarIds.data()); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitBuildZeroVector( + DxbcVectorType type) { + DxbcRegisterValue result; + result.type.ctype = type.ctype; + result.type.ccount = 1; + + switch (type.ctype) { + case DxbcScalarType::Float32: result.id = m_module.constf32(0.0f); break; + case DxbcScalarType::Uint32: result.id = m_module.constu32(0u); break; + case DxbcScalarType::Sint32: result.id = m_module.consti32(0); break; + default: throw DxvkError("DxbcCompiler: Invalid scalar type"); + } + + return emitBuildVector(result, type.ccount); + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterBitcast( + DxbcRegisterValue srcValue, + DxbcScalarType dstType) { + DxbcScalarType srcType = srcValue.type.ctype; + + if (srcType == dstType) + return srcValue; + + DxbcRegisterValue result; + result.type.ctype = dstType; + result.type.ccount = srcValue.type.ccount; + + if (isDoubleType(srcType)) result.type.ccount *= 2; + if (isDoubleType(dstType)) result.type.ccount /= 2; + + result.id = m_module.opBitcast( + getVectorTypeId(result.type), + srcValue.id); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterSwizzle( + DxbcRegisterValue value, + DxbcRegSwizzle swizzle, + DxbcRegMask writeMask) { + if (value.type.ccount == 1) + return emitRegisterExtend(value, writeMask.popCount()); + + std::array indices; + + uint32_t dstIndex = 0; + + for (uint32_t i = 0; i < 4; i++) { + if (writeMask[i]) + indices[dstIndex++] = swizzle[i]; + } + + // If the swizzle combined with the mask can be reduced + // to a no-op, we don't need to insert any instructions. + bool isIdentitySwizzle = dstIndex == value.type.ccount; + + for (uint32_t i = 0; i < dstIndex && isIdentitySwizzle; i++) + isIdentitySwizzle &= indices[i] == i; + + if (isIdentitySwizzle) + return value; + + // Use OpCompositeExtract if the resulting vector contains + // only one component, and OpVectorShuffle if it is a vector. + DxbcRegisterValue result; + result.type.ctype = value.type.ctype; + result.type.ccount = dstIndex; + + const uint32_t typeId = getVectorTypeId(result.type); + + if (dstIndex == 1) { + result.id = m_module.opCompositeExtract( + typeId, value.id, 1, indices.data()); + } else { + result.id = m_module.opVectorShuffle( + typeId, value.id, value.id, + dstIndex, indices.data()); + } + + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterExtract( + DxbcRegisterValue value, + DxbcRegMask mask) { + return emitRegisterSwizzle(value, + DxbcRegSwizzle(0, 1, 2, 3), mask); + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterInsert( + DxbcRegisterValue dstValue, + DxbcRegisterValue srcValue, + DxbcRegMask srcMask) { + DxbcRegisterValue result; + result.type = dstValue.type; + + const uint32_t typeId = getVectorTypeId(result.type); + + if (srcMask.popCount() == 0) { + // Nothing to do if the insertion mask is empty + result.id = dstValue.id; + } else if (dstValue.type.ccount == 1) { + // Both values are scalar, so the first component + // of the write mask decides which one to take. + result.id = srcMask[0] ? srcValue.id : dstValue.id; + } else if (srcValue.type.ccount == 1) { + // The source value is scalar. Since OpVectorShuffle + // requires both arguments to be vectors, we have to + // use OpCompositeInsert to modify the vector instead. + const uint32_t componentId = srcMask.firstSet(); + + result.id = m_module.opCompositeInsert(typeId, + srcValue.id, dstValue.id, 1, &componentId); + } else { + // Both arguments are vectors. We can determine which + // components to take from which vector and use the + // OpVectorShuffle instruction. + std::array components; + uint32_t srcComponentId = dstValue.type.ccount; + + for (uint32_t i = 0; i < dstValue.type.ccount; i++) + components.at(i) = srcMask[i] ? srcComponentId++ : i; + + result.id = m_module.opVectorShuffle( + typeId, dstValue.id, srcValue.id, + dstValue.type.ccount, components.data()); + } + + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterConcat( + DxbcRegisterValue value1, + DxbcRegisterValue value2) { + std::array ids = + {{ value1.id, value2.id }}; + + DxbcRegisterValue result; + result.type.ctype = value1.type.ctype; + result.type.ccount = value1.type.ccount + value2.type.ccount; + result.id = m_module.opCompositeConstruct( + getVectorTypeId(result.type), + ids.size(), ids.data()); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterExtend( + DxbcRegisterValue value, + uint32_t size) { + if (size == 1) + return value; + + std::array ids = {{ + value.id, value.id, + value.id, value.id, + }}; + + DxbcRegisterValue result; + result.type.ctype = value.type.ctype; + result.type.ccount = size; + result.id = m_module.opCompositeConstruct( + getVectorTypeId(result.type), + size, ids.data()); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterAbsolute( + DxbcRegisterValue value) { + const uint32_t typeId = getVectorTypeId(value.type); + + switch (value.type.ctype) { + case DxbcScalarType::Float32: value.id = m_module.opFAbs(typeId, value.id); break; + case DxbcScalarType::Float64: value.id = m_module.opFAbs(typeId, value.id); break; + case DxbcScalarType::Sint32: value.id = m_module.opSAbs(typeId, value.id); break; + case DxbcScalarType::Sint64: value.id = m_module.opSAbs(typeId, value.id); break; + default: Logger::warn("DxbcCompiler: Cannot get absolute value for given type"); + } + + return value; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterNegate( + DxbcRegisterValue value) { + const uint32_t typeId = getVectorTypeId(value.type); + + switch (value.type.ctype) { + case DxbcScalarType::Float32: value.id = m_module.opFNegate(typeId, value.id); break; + case DxbcScalarType::Float64: value.id = m_module.opFNegate(typeId, value.id); break; + case DxbcScalarType::Sint32: value.id = m_module.opSNegate(typeId, value.id); break; + case DxbcScalarType::Sint64: value.id = m_module.opSNegate(typeId, value.id); break; + default: Logger::warn("DxbcCompiler: Cannot negate given type"); + } + + return value; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterZeroTest( + DxbcRegisterValue value, + DxbcZeroTest test) { + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Bool; + result.type.ccount = 1; + + const uint32_t zeroId = m_module.constu32(0u); + const uint32_t typeId = getVectorTypeId(result.type); + + result.id = test == DxbcZeroTest::TestZ + ? m_module.opIEqual (typeId, value.id, zeroId) + : m_module.opINotEqual(typeId, value.id, zeroId); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterMaskBits( + DxbcRegisterValue value, + uint32_t mask) { + DxbcRegisterValue maskVector = emitBuildConstVecu32( + mask, mask, mask, mask, DxbcRegMask::firstN(value.type.ccount)); + + DxbcRegisterValue result; + result.type = value.type; + result.id = m_module.opBitwiseAnd( + getVectorTypeId(result.type), + value.id, maskVector.id); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitSrcOperandModifiers( + DxbcRegisterValue value, + DxbcRegModifiers modifiers) { + if (modifiers.test(DxbcRegModifier::Abs)) + value = emitRegisterAbsolute(value); + + if (modifiers.test(DxbcRegModifier::Neg)) + value = emitRegisterNegate(value); + return value; + } + + + uint32_t DxbcCompiler::emitExtractSparseTexel( + uint32_t texelTypeId, + uint32_t resultId) { + uint32_t index = 1; + + return m_module.opCompositeExtract( + texelTypeId, resultId, 1, &index); + } + + + void DxbcCompiler::emitStoreSparseFeedback( + const DxbcRegister& feedbackRegister, + uint32_t resultId) { + if (feedbackRegister.type != DxbcOperandType::Null) { + uint32_t index = 0; + + DxbcRegisterValue result; + result.type = { DxbcScalarType::Uint32, 1 }; + result.id = m_module.opCompositeExtract( + getScalarTypeId(DxbcScalarType::Uint32), + resultId, 1, &index); + + emitRegisterStore(feedbackRegister, result); + } + } + + + DxbcRegisterValue DxbcCompiler::emitDstOperandModifiers( + DxbcRegisterValue value, + DxbcOpModifiers modifiers) { + const uint32_t typeId = getVectorTypeId(value.type); + + if (modifiers.saturate) { + DxbcRegMask mask; + DxbcRegisterValue vec0, vec1; + + if (value.type.ctype == DxbcScalarType::Float32) { + mask = DxbcRegMask::firstN(value.type.ccount); + vec0 = emitBuildConstVecf32(0.0f, 0.0f, 0.0f, 0.0f, mask); + vec1 = emitBuildConstVecf32(1.0f, 1.0f, 1.0f, 1.0f, mask); + } else if (value.type.ctype == DxbcScalarType::Float64) { + mask = DxbcRegMask::firstN(value.type.ccount * 2); + vec0 = emitBuildConstVecf64(0.0, 0.0, mask); + vec1 = emitBuildConstVecf64(1.0, 1.0, mask); + } + + if (mask) + value.id = m_module.opNClamp(typeId, value.id, vec0.id, vec1.id); + } + + return value; + } + + + DxbcRegisterPointer DxbcCompiler::emitArrayAccess( + DxbcRegisterPointer pointer, + spv::StorageClass sclass, + uint32_t index) { + uint32_t ptrTypeId = m_module.defPointerType( + getVectorTypeId(pointer.type), sclass); + + DxbcRegisterPointer result; + result.type = pointer.type; + result.id = m_module.opAccessChain( + ptrTypeId, pointer.id, 1, &index); + return result; + } + + + uint32_t DxbcCompiler::emitLoadSampledImage( + const DxbcShaderResource& textureResource, + const DxbcSampler& samplerResource, + bool isDepthCompare) { + uint32_t baseId = isDepthCompare + ? textureResource.depthTypeId + : textureResource.colorTypeId; + + if (!baseId) + return 0; + + uint32_t sampledImageType = m_module.defSampledImageType(baseId); + + return m_module.opSampledImage(sampledImageType, + m_module.opLoad(textureResource.imageTypeId, textureResource.varId), + m_module.opLoad(samplerResource.typeId, samplerResource.varId)); + } + + + DxbcRegisterPointer DxbcCompiler::emitGetTempPtr( + const DxbcRegister& operand) { + // r# regs are indexed as follows: + // (0) register index (immediate) + uint32_t regIdx = operand.idx[0].offset; + + if (regIdx >= m_rRegs.size()) + m_rRegs.resize(regIdx + 1, 0u); + + if (!m_rRegs.at(regIdx)) { + DxbcRegisterInfo info; + info.type.ctype = DxbcScalarType::Float32; + info.type.ccount = 4; + info.type.alength = 0; + info.sclass = spv::StorageClassPrivate; + + uint32_t varId = emitNewVariable(info); + m_rRegs.at(regIdx) = varId; + + m_module.setDebugName(varId, + str::format("r", regIdx).c_str()); + } + + DxbcRegisterPointer result; + result.type.ctype = DxbcScalarType::Float32; + result.type.ccount = 4; + result.id = m_rRegs.at(regIdx); + return result; + } + + + DxbcRegisterPointer DxbcCompiler::emitGetIndexableTempPtr( + const DxbcRegister& operand) { + return getIndexableTempPtr(operand, emitIndexLoad(operand.idx[1])); + } + + + DxbcRegisterPointer DxbcCompiler::emitGetInputPtr( + const DxbcRegister& operand) { + // In the vertex and pixel stages, + // v# regs are indexed as follows: + // (0) register index (relative) + // + // In the tessellation and geometry + // stages, the index has two dimensions: + // (0) vertex index (relative) + // (1) register index (relative) + DxbcRegisterPointer result; + result.type.ctype = DxbcScalarType::Float32; + result.type.ccount = 4; + + std::array indices = {{ 0, 0 }}; + + for (uint32_t i = 0; i < operand.idxDim; i++) + indices.at(i) = emitIndexLoad(operand.idx[i]).id; + + // Pick the input array depending on + // the program type and operand type + struct InputArray { + uint32_t id; + spv::StorageClass sclass; + }; + + const InputArray array = [&] () -> InputArray { + switch (operand.type) { + case DxbcOperandType::InputControlPoint: + return m_programInfo.type() == DxbcProgramType::HullShader + ? InputArray { m_vArray, spv::StorageClassPrivate } + : InputArray { m_ds.inputPerVertex, spv::StorageClassInput }; + case DxbcOperandType::InputPatchConstant: + return m_programInfo.type() == DxbcProgramType::HullShader + ? InputArray { m_hs.outputPerPatch, spv::StorageClassPrivate } + : InputArray { m_ds.inputPerPatch, spv::StorageClassInput }; + case DxbcOperandType::OutputControlPoint: + return InputArray { m_hs.outputPerVertex, spv::StorageClassOutput }; + default: + return { m_vArray, spv::StorageClassPrivate }; + } + }(); + + DxbcRegisterInfo info; + info.type.ctype = result.type.ctype; + info.type.ccount = result.type.ccount; + info.type.alength = 0; + info.sclass = array.sclass; + + result.id = m_module.opAccessChain( + getPointerTypeId(info), array.id, + operand.idxDim, indices.data()); + + return result; + } + + + DxbcRegisterPointer DxbcCompiler::emitGetOutputPtr( + const DxbcRegister& operand) { + if (m_programInfo.type() == DxbcProgramType::HullShader) { + // Hull shaders are special in that they have two sets of + // output registers, one for per-patch values and one for + // per-vertex values. + DxbcRegisterPointer result; + result.type.ctype = DxbcScalarType::Float32; + result.type.ccount = 4; + + uint32_t registerId = emitIndexLoad(operand.idx[0]).id; + + if (m_hs.currPhaseType == DxbcCompilerHsPhase::ControlPoint) { + std::array indices = {{ + m_module.opLoad(m_module.defIntType(32, 0), m_hs.builtinInvocationId), + registerId, + }}; + + uint32_t ptrTypeId = m_module.defPointerType( + getVectorTypeId(result.type), + spv::StorageClassOutput); + + result.id = m_module.opAccessChain( + ptrTypeId, m_hs.outputPerVertex, + indices.size(), indices.data()); + } else { + uint32_t ptrTypeId = m_module.defPointerType( + getVectorTypeId(result.type), + spv::StorageClassPrivate); + + result.id = m_module.opAccessChain( + ptrTypeId, m_hs.outputPerPatch, + 1, ®isterId); + } + + return result; + } else { + // Regular shaders have their output + // registers set up at declaration time + return m_oRegs.at(operand.idx[0].offset); + } + } + + + DxbcRegisterPointer DxbcCompiler::emitGetImmConstBufPtr( + const DxbcRegister& operand) { + DxbcRegisterValue constId = emitIndexLoad(operand.idx[0]); + + if (m_icbArray) { + // We pad the icb array with an extra zero vector, so we can + // clamp the index and get correct robustness behaviour. + constId.id = m_module.opUMin(getVectorTypeId(constId.type), + constId.id, m_module.constu32(m_icbSize)); + + DxbcRegisterInfo ptrInfo; + ptrInfo.type.ctype = DxbcScalarType::Uint32; + ptrInfo.type.ccount = m_icbComponents; + ptrInfo.type.alength = 0; + ptrInfo.sclass = spv::StorageClassPrivate; + + DxbcRegisterPointer result; + result.type.ctype = ptrInfo.type.ctype; + result.type.ccount = ptrInfo.type.ccount; + result.id = m_module.opAccessChain( + getPointerTypeId(ptrInfo), + m_icbArray, 1, &constId.id); + return result; + } else if (m_constantBuffers.at(Icb_BindingSlotId).varId != 0) { + const std::array indices = + {{ m_module.consti32(0), constId.id }}; + + DxbcRegisterInfo ptrInfo; + ptrInfo.type.ctype = DxbcScalarType::Float32; + ptrInfo.type.ccount = m_icbComponents; + ptrInfo.type.alength = 0; + ptrInfo.sclass = spv::StorageClassUniform; + + DxbcRegisterPointer result; + result.type.ctype = ptrInfo.type.ctype; + result.type.ccount = ptrInfo.type.ccount; + result.id = m_module.opAccessChain( + getPointerTypeId(ptrInfo), + m_constantBuffers.at(Icb_BindingSlotId).varId, + indices.size(), indices.data()); + return result; + } else { + throw DxvkError("DxbcCompiler: Immediate constant buffer not defined"); + } + } + + + DxbcRegisterPointer DxbcCompiler::emitGetOperandPtr( + const DxbcRegister& operand) { + switch (operand.type) { + case DxbcOperandType::Temp: + return emitGetTempPtr(operand); + + case DxbcOperandType::IndexableTemp: + return emitGetIndexableTempPtr(operand); + + case DxbcOperandType::Input: + case DxbcOperandType::InputControlPoint: + case DxbcOperandType::InputPatchConstant: + case DxbcOperandType::OutputControlPoint: + return emitGetInputPtr(operand); + + case DxbcOperandType::Output: + return emitGetOutputPtr(operand); + + case DxbcOperandType::ImmediateConstantBuffer: + return emitGetImmConstBufPtr(operand); + + case DxbcOperandType::InputThreadId: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 3 }, + m_cs.builtinGlobalInvocationId }; + + case DxbcOperandType::InputThreadGroupId: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 3 }, + m_cs.builtinWorkgroupId }; + + case DxbcOperandType::InputThreadIdInGroup: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 3 }, + m_cs.builtinLocalInvocationId }; + + case DxbcOperandType::InputThreadIndexInGroup: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 1 }, + m_cs.builtinLocalInvocationIndex }; + + case DxbcOperandType::InputCoverageMask: { + const std::array indices + = {{ m_module.constu32(0) }}; + + DxbcRegisterPointer result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(result.type), + spv::StorageClassInput), + m_ps.builtinSampleMaskIn, + indices.size(), indices.data()); + return result; + } + + case DxbcOperandType::OutputCoverageMask: { + const std::array indices + = {{ m_module.constu32(0) }}; + + DxbcRegisterPointer result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(result.type), + spv::StorageClassOutput), + m_ps.builtinSampleMaskOut, + indices.size(), indices.data()); + return result; + } + + case DxbcOperandType::OutputDepth: + case DxbcOperandType::OutputDepthGe: + case DxbcOperandType::OutputDepthLe: + return DxbcRegisterPointer { + { DxbcScalarType::Float32, 1 }, + m_ps.builtinDepth }; + + case DxbcOperandType::OutputStencilRef: + return DxbcRegisterPointer { + { DxbcScalarType::Sint32, 1 }, + m_ps.builtinStencilRef }; + + case DxbcOperandType::InputPrimitiveId: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 1 }, + m_primitiveIdIn }; + + case DxbcOperandType::InputDomainPoint: + return DxbcRegisterPointer { + { DxbcScalarType::Float32, 3 }, + m_ds.builtinTessCoord }; + + case DxbcOperandType::OutputControlPointId: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 1 }, + m_hs.builtinInvocationId }; + + case DxbcOperandType::InputForkInstanceId: + case DxbcOperandType::InputJoinInstanceId: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 1 }, + getCurrentHsForkJoinPhase()->instanceIdPtr }; + + case DxbcOperandType::InputGsInstanceId: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 1 }, + m_gs.builtinInvocationId }; + + case DxbcOperandType::InputInnerCoverage: + return DxbcRegisterPointer { + { DxbcScalarType::Uint32, 1 }, + m_ps.builtinInnerCoverageId }; + + default: + throw DxvkError(str::format( + "DxbcCompiler: Unhandled operand type: ", + operand.type)); + } + } + + + DxbcRegisterPointer DxbcCompiler::emitGetAtomicPointer( + const DxbcRegister& operand, + const DxbcRegister& address) { + // Query information about the resource itself + const uint32_t registerId = operand.idx[0].offset; + const DxbcBufferInfo resourceInfo = getBufferInfo(operand); + + // For UAVs and shared memory, different methods + // of obtaining the final pointer are used. + bool isTgsm = operand.type == DxbcOperandType::ThreadGroupSharedMemory; + bool isSsbo = resourceInfo.isSsbo; + + // Compute the actual address into the resource + const DxbcRegisterValue addressValue = [&] { + switch (resourceInfo.type) { + case DxbcResourceType::Raw: + return emitCalcBufferIndexRaw(emitRegisterLoad( + address, DxbcRegMask(true, false, false, false))); + + case DxbcResourceType::Structured: { + const DxbcRegisterValue addressComponents = emitRegisterLoad( + address, DxbcRegMask(true, true, false, false)); + + return emitCalcBufferIndexStructured( + emitRegisterExtract(addressComponents, DxbcRegMask(true, false, false, false)), + emitRegisterExtract(addressComponents, DxbcRegMask(false, true, false, false)), + resourceInfo.stride); + }; + + case DxbcResourceType::Typed: { + if (isTgsm) + throw DxvkError("DxbcCompiler: TGSM cannot be typed"); + + return emitLoadTexCoord(address, + m_uavs.at(registerId).imageInfo); + } + + default: + throw DxvkError("DxbcCompiler: Unhandled resource type"); + } + }(); + + // Compute the actual pointer + DxbcRegisterPointer result; + result.type.ctype = resourceInfo.stype; + result.type.ccount = 1; + + if (isTgsm) { + result.id = m_module.opAccessChain(resourceInfo.typeId, + resourceInfo.varId, 1, &addressValue.id); + } else if (isSsbo) { + uint32_t indices[2] = { m_module.constu32(0), addressValue.id }; + result.id = m_module.opAccessChain(resourceInfo.typeId, + resourceInfo.varId, 2, indices); + } else { + result.id = m_module.opImageTexelPointer( + m_module.defPointerType(getVectorTypeId(result.type), spv::StorageClassImage), + resourceInfo.varId, addressValue.id, m_module.constu32(0)); + } + + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitQueryBufferSize( + const DxbcRegister& resource) { + const DxbcBufferInfo bufferInfo = getBufferInfo(resource); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opArrayLength( + getVectorTypeId(result.type), + bufferInfo.varId, 0); + + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitQueryTexelBufferSize( + const DxbcRegister& resource) { + // Load the texel buffer object. This cannot be used with + // constant buffers or any other type of resource. + const DxbcBufferInfo bufferInfo = getBufferInfo(resource); + + const uint32_t bufferId = m_module.opLoad( + bufferInfo.typeId, bufferInfo.varId); + + // We'll store this as a scalar unsigned integer + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opImageQuerySize( + getVectorTypeId(result.type), bufferId); + + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitQueryTextureLods( + const DxbcRegister& resource) { + const DxbcBufferInfo info = getBufferInfo(resource); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + + if (info.image.ms == 0 && info.image.sampled == 1) { + result.id = m_module.opImageQueryLevels( + getVectorTypeId(result.type), + m_module.opLoad(info.typeId, info.varId)); + } else { + // Report one LOD in case of UAVs or multisampled images + result.id = m_module.constu32(1); + } + + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitQueryTextureSamples( + const DxbcRegister& resource) { + if (resource.type == DxbcOperandType::Rasterizer) { + // SPIR-V has no gl_NumSamples equivalent, so we + // have to work around it using a push constant + if (!m_ps.pushConstantId) + m_ps.pushConstantId = emitPushConstants(); + + uint32_t uintTypeId = m_module.defIntType(32, 0); + uint32_t ptrTypeId = m_module.defPointerType(uintTypeId, spv::StorageClassPushConstant); + uint32_t index = m_module.constu32(0); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opLoad(uintTypeId, + m_module.opAccessChain(ptrTypeId, m_ps.pushConstantId, 1, &index)); + return result; + } else { + DxbcBufferInfo info = getBufferInfo(resource); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + + if (info.image.ms) { + result.id = m_module.opImageQuerySamples( + getVectorTypeId(result.type), + m_module.opLoad(info.typeId, info.varId)); + } else { + // OpImageQuerySamples requires MSAA images + result.id = m_module.constu32(1); + } + + return result; + } + } + + + DxbcRegisterValue DxbcCompiler::emitQueryTextureSize( + const DxbcRegister& resource, + DxbcRegisterValue lod) { + const DxbcBufferInfo info = getBufferInfo(resource); + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = getTexSizeDim(info.image); + + if (info.image.ms == 0 && info.image.sampled == 1) { + result.id = m_module.opImageQuerySizeLod( + getVectorTypeId(result.type), + m_module.opLoad(info.typeId, info.varId), + lod.id); + } else { + result.id = m_module.opImageQuerySize( + getVectorTypeId(result.type), + m_module.opLoad(info.typeId, info.varId)); + } + + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitCalcBufferIndexStructured( + DxbcRegisterValue structId, + DxbcRegisterValue structOffset, + uint32_t structStride) { + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Sint32; + result.type.ccount = 1; + + uint32_t typeId = getVectorTypeId(result.type); + uint32_t offset = m_module.opShiftRightLogical(typeId, structOffset.id, m_module.consti32(2)); + + result.id = m_module.opIAdd(typeId, + m_module.opIMul(typeId, structId.id, m_module.consti32(structStride / 4)), + offset); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitCalcBufferIndexRaw( + DxbcRegisterValue byteOffset) { + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Sint32; + result.type.ccount = 1; + + uint32_t typeId = getVectorTypeId(result.type); + result.id = m_module.opShiftRightLogical(typeId, byteOffset.id, m_module.consti32(2)); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitCalcTexCoord( + DxbcRegisterValue coordVector, + const DxbcImageInfo& imageInfo) { + const uint32_t dim = getTexCoordDim(imageInfo); + + if (dim != coordVector.type.ccount) { + coordVector = emitRegisterExtract( + coordVector, DxbcRegMask::firstN(dim)); + } + + return coordVector; + } + + + DxbcRegisterValue DxbcCompiler::emitLoadTexCoord( + const DxbcRegister& coordReg, + const DxbcImageInfo& imageInfo) { + return emitCalcTexCoord(emitRegisterLoad(coordReg, + DxbcRegMask(true, true, true, true)), imageInfo); + } + + + DxbcRegisterValue DxbcCompiler::emitIndexLoad( + DxbcRegIndex index) { + if (index.relReg != nullptr) { + DxbcRegisterValue result = emitRegisterLoad( + *index.relReg, DxbcRegMask(true, false, false, false)); + + if (index.offset != 0) { + result.id = m_module.opIAdd( + getVectorTypeId(result.type), result.id, + m_module.consti32(index.offset)); + } + + return result; + } else { + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Sint32; + result.type.ccount = 1; + result.id = m_module.consti32(index.offset); + return result; + } + } + + + DxbcRegisterValue DxbcCompiler::emitValueLoad( + DxbcRegisterPointer ptr) { + DxbcRegisterValue result; + result.type = ptr.type; + result.id = m_module.opLoad( + getVectorTypeId(result.type), + ptr.id); + return result; + } + + + void DxbcCompiler::emitValueStore( + DxbcRegisterPointer ptr, + DxbcRegisterValue value, + DxbcRegMask writeMask) { + // If the component types are not compatible, + // we need to bit-cast the source variable. + if (value.type.ctype != ptr.type.ctype) + value = emitRegisterBitcast(value, ptr.type.ctype); + + // If the source value consists of only one component, + // it is stored in all components of the destination. + if (value.type.ccount == 1) + value = emitRegisterExtend(value, writeMask.popCount()); + + if (ptr.type.ccount == writeMask.popCount()) { + // Simple case: We write to the entire register + m_module.opStore(ptr.id, value.id); + } else { + // We only write to part of the destination + // register, so we need to load and modify it + DxbcRegisterValue tmp = emitValueLoad(ptr); + tmp = emitRegisterInsert(tmp, value, writeMask); + + m_module.opStore(ptr.id, tmp.id); + } + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterLoadRaw( + const DxbcRegister& reg) { + // Try to find index range for the given register + const DxbcIndexRange* indexRange = nullptr; + + if (reg.idxDim && reg.idx[reg.idxDim - 1u].relReg) { + uint32_t offset = reg.idx[reg.idxDim - 1u].offset; + + for (const auto& range : m_indexRanges) { + if (reg.type == range.type && offset >= range.start && offset < range.start + range.length) + indexRange = ⦥ + } + } + + if (reg.type == DxbcOperandType::IndexableTemp || indexRange) { + bool doBoundsCheck = reg.idx[reg.idxDim - 1u].relReg != nullptr; + + if (doBoundsCheck) { + DxbcRegisterValue indexId = emitIndexLoad(reg.idx[reg.idxDim - 1u]); + uint32_t boundsCheck = 0u; + + if (reg.type == DxbcOperandType::IndexableTemp) { + boundsCheck = m_module.opULessThan( + m_module.defBoolType(), indexId.id, + m_module.constu32(m_xRegs.at(reg.idx[0].offset).alength)); + } else { + uint32_t adjustedId = m_module.opISub(getVectorTypeId(indexId.type), + indexId.id, m_module.consti32(indexRange->start)); + + boundsCheck = m_module.opULessThan( + m_module.defBoolType(), adjustedId, + m_module.constu32(indexRange->length)); + } + + // Kind of ugly to have an empty else block here but there's no + // way for us to know the current block ID for the phi below + DxbcConditional cond; + cond.labelIf = m_module.allocateId(); + cond.labelElse = m_module.allocateId(); + cond.labelEnd = m_module.allocateId(); + + m_module.opSelectionMerge(cond.labelEnd, spv::SelectionControlMaskNone); + m_module.opBranchConditional(boundsCheck, cond.labelIf, cond.labelElse); + + m_module.opLabel(cond.labelIf); + + DxbcRegisterValue returnValue = emitValueLoad(emitGetOperandPtr(reg)); + + m_module.opBranch(cond.labelEnd); + m_module.opLabel (cond.labelElse); + + DxbcRegisterValue zeroValue = emitBuildZeroVector(returnValue.type); + + m_module.opBranch(cond.labelEnd); + m_module.opLabel (cond.labelEnd); + + std::array phiLabels = {{ + { returnValue.id, cond.labelIf }, + { zeroValue.id, cond.labelElse }, + }}; + + returnValue.id = m_module.opPhi( + getVectorTypeId(returnValue.type), + phiLabels.size(), phiLabels.data()); + return returnValue; + } + } + + DxbcRegisterValue value = emitValueLoad(emitGetOperandPtr(reg)); + + // Pad icb values to a vec4 since the app may access components that are always 0 + if (reg.type == DxbcOperandType::ImmediateConstantBuffer && value.type.ccount < 4u) { + DxbcVectorType zeroType; + zeroType.ctype = value.type.ctype; + zeroType.ccount = 4u - value.type.ccount; + + uint32_t zeroVector = emitBuildZeroVector(zeroType).id; + + std::array constituents = { value.id, zeroVector }; + + value.type.ccount = 4u; + value.id = m_module.opCompositeConstruct(getVectorTypeId(value.type), + constituents.size(), constituents.data()); + } + + return value; + } + + + DxbcRegisterValue DxbcCompiler::emitConstantBufferLoad( + const DxbcRegister& reg, + DxbcRegMask writeMask) { + // Constant buffers take a two-dimensional index: + // (0) register index (immediate) + // (1) constant offset (relative) + DxbcRegisterInfo info; + info.type.ctype = DxbcScalarType::Float32; + info.type.ccount = 4; + info.type.alength = 0; + info.sclass = spv::StorageClassUniform; + + uint32_t regId = reg.idx[0].offset; + DxbcRegisterValue constId = emitIndexLoad(reg.idx[1]); + + uint32_t ptrTypeId = getPointerTypeId(info); + + const std::array indices = + {{ m_module.consti32(0), constId.id }}; + + DxbcRegisterPointer ptr; + ptr.type.ctype = info.type.ctype; + ptr.type.ccount = info.type.ccount; + ptr.id = m_module.opAccessChain(ptrTypeId, + m_constantBuffers.at(regId).varId, + indices.size(), indices.data()); + + // Load individual components from buffer + std::array ccomps = { 0, 0, 0, 0 }; + std::array scomps = { 0, 0, 0, 0 }; + uint32_t scount = 0; + + for (uint32_t i = 0; i < 4; i++) { + uint32_t sindex = reg.swizzle[i]; + + if (!writeMask[i] || ccomps[sindex]) + continue; + + uint32_t componentId = m_module.constu32(sindex); + uint32_t componentPtr = m_module.opAccessChain( + m_module.defPointerType( + getScalarTypeId(DxbcScalarType::Float32), + spv::StorageClassUniform), + ptr.id, 1, &componentId); + + ccomps[sindex] = m_module.opLoad( + getScalarTypeId(DxbcScalarType::Float32), + componentPtr); + } + + for (uint32_t i = 0; i < 4; i++) { + uint32_t sindex = reg.swizzle[i]; + + if (writeMask[i]) + scomps[scount++] = ccomps[sindex]; + } + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Float32; + result.type.ccount = scount; + result.id = scomps[0]; + + if (scount > 1) { + result.id = m_module.opCompositeConstruct( + getVectorTypeId(result.type), + scount, scomps.data()); + } + + // Apply any post-processing that might be necessary + result = emitRegisterBitcast(result, reg.dataType); + result = emitSrcOperandModifiers(result, reg.modifiers); + return result; + } + + + DxbcRegisterValue DxbcCompiler::emitRegisterLoad( + const DxbcRegister& reg, + DxbcRegMask writeMask) { + if (reg.type == DxbcOperandType::Imm32 + || reg.type == DxbcOperandType::Imm64) { + DxbcRegisterValue result; + + if (reg.componentCount == DxbcComponentCount::Component1) { + // Create one single u32 constant + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.constu32(reg.imm.u32_1); + + result = emitRegisterExtend(result, writeMask.popCount()); + } else if (reg.componentCount == DxbcComponentCount::Component4) { + // Create a u32 vector with as many components as needed + std::array indices = { }; + uint32_t indexId = 0; + + for (uint32_t i = 0; i < indices.size(); i++) { + if (writeMask[i]) { + indices.at(indexId++) = + m_module.constu32(reg.imm.u32_4[i]); + } + } + + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = writeMask.popCount(); + result.id = indices.at(0); + + if (indexId > 1) { + result.id = m_module.constComposite( + getVectorTypeId(result.type), + result.type.ccount, indices.data()); + } + + } else { + // Something went horribly wrong in the decoder or the shader is broken + throw DxvkError("DxbcCompiler: Invalid component count for immediate operand"); + } + + // Cast constants to the requested type + return emitRegisterBitcast(result, reg.dataType); + } else if (reg.type == DxbcOperandType::ConstantBuffer) { + return emitConstantBufferLoad(reg, writeMask); + } else { + // Load operand from the operand pointer + DxbcRegisterValue result = emitRegisterLoadRaw(reg); + + // Apply operand swizzle to the operand value + result = emitRegisterSwizzle(result, reg.swizzle, writeMask); + + // Cast it to the requested type. We need to do + // this after the swizzling for 64-bit types. + result = emitRegisterBitcast(result, reg.dataType); + + // Apply operand modifiers + result = emitSrcOperandModifiers(result, reg.modifiers); + return result; + } + } + + + void DxbcCompiler::emitRegisterStore( + const DxbcRegister& reg, + DxbcRegisterValue value) { + if (reg.type == DxbcOperandType::IndexableTemp) { + bool doBoundsCheck = reg.idx[1].relReg != nullptr; + DxbcRegisterValue vectorId = emitIndexLoad(reg.idx[1]); + + if (doBoundsCheck) { + uint32_t boundsCheck = m_module.opULessThan( + m_module.defBoolType(), vectorId.id, + m_module.constu32(m_xRegs.at(reg.idx[0].offset).alength)); + + DxbcConditional cond; + cond.labelIf = m_module.allocateId(); + cond.labelEnd = m_module.allocateId(); + + m_module.opSelectionMerge(cond.labelEnd, spv::SelectionControlMaskNone); + m_module.opBranchConditional(boundsCheck, cond.labelIf, cond.labelEnd); + + m_module.opLabel(cond.labelIf); + + emitValueStore(getIndexableTempPtr(reg, vectorId), value, reg.mask); + + m_module.opBranch(cond.labelEnd); + m_module.opLabel (cond.labelEnd); + } else { + emitValueStore(getIndexableTempPtr(reg, vectorId), value, reg.mask); + } + } else { + emitValueStore(emitGetOperandPtr(reg), value, reg.mask); + } + } + + + void DxbcCompiler::emitInputSetup() { + m_module.setLateConst(m_vArrayLengthId, &m_vArrayLength); + + // Copy all defined v# registers into the input array + const uint32_t vecTypeId = m_module.defVectorType(m_module.defFloatType(32), 4); + const uint32_t ptrTypeId = m_module.defPointerType(vecTypeId, spv::StorageClassPrivate); + + for (uint32_t i = 0; i < m_vRegs.size(); i++) { + if (m_vRegs.at(i).id != 0) { + const uint32_t registerId = m_module.consti32(i); + + DxbcRegisterPointer srcPtr = m_vRegs.at(i); + DxbcRegisterValue srcValue = emitRegisterBitcast( + emitValueLoad(srcPtr), DxbcScalarType::Float32); + + DxbcRegisterPointer dstPtr; + dstPtr.type = { DxbcScalarType::Float32, 4 }; + dstPtr.id = m_module.opAccessChain( + ptrTypeId, m_vArray, 1, ®isterId); + + emitValueStore(dstPtr, srcValue, DxbcRegMask::firstN(srcValue.type.ccount)); + } + } + + // Copy all system value registers into the array, + // preserving any previously written contents. + for (const DxbcSvMapping& map : m_vMappings) { + const uint32_t registerId = m_module.consti32(map.regId); + + const DxbcRegisterValue value = [&] { + switch (m_programInfo.type()) { + case DxbcProgramType::VertexShader: return emitVsSystemValueLoad(map.sv, map.regMask); + case DxbcProgramType::PixelShader: return emitPsSystemValueLoad(map.sv, map.regMask); + default: throw DxvkError(str::format("DxbcCompiler: Unexpected stage: ", m_programInfo.type())); + } + }(); + + DxbcRegisterPointer inputReg; + inputReg.type.ctype = DxbcScalarType::Float32; + inputReg.type.ccount = 4; + inputReg.id = m_module.opAccessChain( + ptrTypeId, m_vArray, 1, ®isterId); + emitValueStore(inputReg, value, map.regMask); + } + } + + + void DxbcCompiler::emitInputSetup(uint32_t vertexCount) { + m_module.setLateConst(m_vArrayLengthId, &m_vArrayLength); + + // Copy all defined v# registers into the input array. Note + // that the outer index of the array is the vertex index. + const uint32_t vecTypeId = m_module.defVectorType(m_module.defFloatType(32), 4); + const uint32_t dstPtrTypeId = m_module.defPointerType(vecTypeId, spv::StorageClassPrivate); + + for (uint32_t i = 0; i < m_vRegs.size(); i++) { + if (m_vRegs.at(i).id != 0) { + const uint32_t registerId = m_module.consti32(i); + + for (uint32_t v = 0; v < vertexCount; v++) { + std::array indices + = {{ m_module.consti32(v), registerId }}; + + DxbcRegisterPointer srcPtr; + srcPtr.type = m_vRegs.at(i).type; + srcPtr.id = m_module.opAccessChain( + m_module.defPointerType(getVectorTypeId(srcPtr.type), spv::StorageClassInput), + m_vRegs.at(i).id, 1, indices.data()); + + DxbcRegisterValue srcValue = emitRegisterBitcast( + emitValueLoad(srcPtr), DxbcScalarType::Float32); + + DxbcRegisterPointer dstPtr; + dstPtr.type = { DxbcScalarType::Float32, 4 }; + dstPtr.id = m_module.opAccessChain( + dstPtrTypeId, m_vArray, 2, indices.data()); + + emitValueStore(dstPtr, srcValue, DxbcRegMask::firstN(srcValue.type.ccount)); + } + } + } + + // Copy all system value registers into the array, + // preserving any previously written contents. + for (const DxbcSvMapping& map : m_vMappings) { + const uint32_t registerId = m_module.consti32(map.regId); + + for (uint32_t v = 0; v < vertexCount; v++) { + const DxbcRegisterValue value = [&] { + switch (m_programInfo.type()) { + case DxbcProgramType::GeometryShader: return emitGsSystemValueLoad(map.sv, map.regMask, v); + default: throw DxvkError(str::format("DxbcCompiler: Unexpected stage: ", m_programInfo.type())); + } + }(); + + std::array indices = { + m_module.consti32(v), registerId, + }; + + DxbcRegisterPointer inputReg; + inputReg.type.ctype = DxbcScalarType::Float32; + inputReg.type.ccount = 4; + inputReg.id = m_module.opAccessChain(dstPtrTypeId, + m_vArray, indices.size(), indices.data()); + emitValueStore(inputReg, value, map.regMask); + } + } + } + + + void DxbcCompiler::emitOutputSetup() { + for (const DxbcSvMapping& svMapping : m_oMappings) { + DxbcRegisterPointer outputReg = m_oRegs.at(svMapping.regId); + + if (m_programInfo.type() == DxbcProgramType::HullShader) { + uint32_t registerIndex = m_module.constu32(svMapping.regId); + + outputReg.type = { DxbcScalarType::Float32, 4 }; + outputReg.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(outputReg.type), + spv::StorageClassPrivate), + m_hs.outputPerPatch, + 1, ®isterIndex); + } + + auto sv = svMapping.sv; + auto mask = svMapping.regMask; + auto value = emitValueLoad(outputReg); + + switch (m_programInfo.type()) { + case DxbcProgramType::VertexShader: emitVsSystemValueStore(sv, mask, value); break; + case DxbcProgramType::GeometryShader: emitGsSystemValueStore(sv, mask, value); break; + case DxbcProgramType::HullShader: emitHsSystemValueStore(sv, mask, value); break; + case DxbcProgramType::DomainShader: emitDsSystemValueStore(sv, mask, value); break; + case DxbcProgramType::PixelShader: emitPsSystemValueStore(sv, mask, value); break; + default: break; + } + } + } + + + void DxbcCompiler::emitOutputDepthClamp() { + // HACK: Some drivers do not clamp FragDepth to [minDepth..maxDepth] + // before writing to the depth attachment, but we do not have acccess + // to those. Clamp to [0..1] instead. + if (m_ps.builtinDepth) { + DxbcRegisterPointer ptr; + ptr.type = { DxbcScalarType::Float32, 1 }; + ptr.id = m_ps.builtinDepth; + + DxbcRegisterValue value = emitValueLoad(ptr); + + value.id = m_module.opNClamp( + getVectorTypeId(ptr.type), + value.id, + m_module.constf32(0.0f), + m_module.constf32(1.0f)); + + emitValueStore(ptr, value, + DxbcRegMask::firstN(1)); + } + } + + + void DxbcCompiler::emitInitWorkgroupMemory() { + bool hasTgsm = false; + + SpirvMemoryOperands memoryOperands; + memoryOperands.flags = spv::MemoryAccessNonPrivatePointerMask; + + for (uint32_t i = 0; i < m_gRegs.size(); i++) { + if (!m_gRegs[i].varId) + continue; + + if (!m_cs.builtinLocalInvocationIndex) { + m_cs.builtinLocalInvocationIndex = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInLocalInvocationIndex, + "vThreadIndexInGroup"); + } + + uint32_t intTypeId = getScalarTypeId(DxbcScalarType::Uint32); + uint32_t ptrTypeId = m_module.defPointerType( + intTypeId, spv::StorageClassWorkgroup); + + uint32_t numElements = m_gRegs[i].type == DxbcResourceType::Structured + ? m_gRegs[i].elementCount * m_gRegs[i].elementStride / 4 + : m_gRegs[i].elementCount / 4; + + uint32_t numThreads = m_cs.workgroupSizeX * + m_cs.workgroupSizeY * m_cs.workgroupSizeZ; + + uint32_t numElementsPerThread = numElements / numThreads; + uint32_t numElementsRemaining = numElements % numThreads; + + uint32_t threadId = m_module.opLoad( + intTypeId, m_cs.builtinLocalInvocationIndex); + uint32_t zeroId = m_module.constu32(0); + + for (uint32_t e = 0; e < numElementsPerThread; e++) { + uint32_t ofsId = m_module.opIAdd(intTypeId, threadId, + m_module.constu32(numThreads * e)); + + uint32_t ptrId = m_module.opAccessChain( + ptrTypeId, m_gRegs[i].varId, 1, &ofsId); + + m_module.opStore(ptrId, zeroId, memoryOperands); + } + + if (numElementsRemaining) { + uint32_t condition = m_module.opULessThan( + m_module.defBoolType(), threadId, + m_module.constu32(numElementsRemaining)); + + DxbcConditional cond; + cond.labelIf = m_module.allocateId(); + cond.labelEnd = m_module.allocateId(); + + m_module.opSelectionMerge(cond.labelEnd, spv::SelectionControlMaskNone); + m_module.opBranchConditional(condition, cond.labelIf, cond.labelEnd); + + m_module.opLabel(cond.labelIf); + + uint32_t ofsId = m_module.opIAdd(intTypeId, threadId, + m_module.constu32(numThreads * numElementsPerThread)); + + uint32_t ptrId = m_module.opAccessChain( + ptrTypeId, m_gRegs[i].varId, 1, &ofsId); + + m_module.opStore(ptrId, zeroId, memoryOperands); + + m_module.opBranch(cond.labelEnd); + m_module.opLabel (cond.labelEnd); + } + + hasTgsm = true; + } + + if (hasTgsm) { + m_module.opControlBarrier( + m_module.constu32(spv::ScopeWorkgroup), + m_module.constu32(spv::ScopeWorkgroup), + m_module.constu32(spv::MemorySemanticsWorkgroupMemoryMask + | spv::MemorySemanticsAcquireReleaseMask + | spv::MemorySemanticsMakeAvailableMask + | spv::MemorySemanticsMakeVisibleMask)); + } + } + + + DxbcRegisterValue DxbcCompiler::emitVsSystemValueLoad( + DxbcSystemValue sv, + DxbcRegMask mask) { + switch (sv) { + case DxbcSystemValue::VertexId: { + const uint32_t typeId = getScalarTypeId(DxbcScalarType::Uint32); + + if (m_vs.builtinVertexId == 0) { + m_vs.builtinVertexId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInVertexIndex, + "vs_vertex_index"); + } + + if (m_vs.builtinBaseVertex == 0) { + m_vs.builtinBaseVertex = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInBaseVertex, + "vs_base_vertex"); + } + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opISub(typeId, + m_module.opLoad(typeId, m_vs.builtinVertexId), + m_module.opLoad(typeId, m_vs.builtinBaseVertex)); + return result; + } break; + + case DxbcSystemValue::InstanceId: { + const uint32_t typeId = getScalarTypeId(DxbcScalarType::Uint32); + + if (m_vs.builtinInstanceId == 0) { + m_vs.builtinInstanceId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInInstanceIndex, + "vs_instance_index"); + } + + if (m_vs.builtinBaseInstance == 0) { + m_vs.builtinBaseInstance = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInBaseInstance, + "vs_base_instance"); + } + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opISub(typeId, + m_module.opLoad(typeId, m_vs.builtinInstanceId), + m_module.opLoad(typeId, m_vs.builtinBaseInstance)); + return result; + } break; + + default: + throw DxvkError(str::format( + "DxbcCompiler: Unhandled VS SV input: ", sv)); + } + } + + + DxbcRegisterValue DxbcCompiler::emitGsSystemValueLoad( + DxbcSystemValue sv, + DxbcRegMask mask, + uint32_t vertexId) { + switch (sv) { + case DxbcSystemValue::Position: { + uint32_t arrayIndex = m_module.consti32(vertexId); + + if (!m_positionIn) { + m_positionIn = emitNewBuiltinVariable({ + { DxbcScalarType::Float32, 4, primitiveVertexCount(m_gs.inputPrimitive) }, + spv::StorageClassInput }, + spv::BuiltInPosition, + "in_position"); + } + + DxbcRegisterPointer ptrIn; + ptrIn.type.ctype = DxbcScalarType::Float32; + ptrIn.type.ccount = 4; + ptrIn.id = m_module.opAccessChain( + m_module.defPointerType(getVectorTypeId(ptrIn.type), spv::StorageClassInput), + m_positionIn, 1, &arrayIndex); + + return emitRegisterExtract(emitValueLoad(ptrIn), mask); + } break; + + default: + throw DxvkError(str::format( + "DxbcCompiler: Unhandled GS SV input: ", sv)); + } + } + + + DxbcRegisterValue DxbcCompiler::emitPsSystemValueLoad( + DxbcSystemValue sv, + DxbcRegMask mask) { + switch (sv) { + case DxbcSystemValue::Position: { + if (m_ps.builtinFragCoord == 0) { + m_ps.builtinFragCoord = emitNewBuiltinVariable({ + { DxbcScalarType::Float32, 4, 0 }, + spv::StorageClassInput }, + spv::BuiltInFragCoord, + "ps_frag_coord"); + } + + DxbcRegisterPointer ptrIn; + ptrIn.type = { DxbcScalarType::Float32, 4 }; + ptrIn.id = m_ps.builtinFragCoord; + + // The X, Y and Z components of the SV_POSITION semantic + // are identical to Vulkan's FragCoord builtin, but we + // need to compute the reciprocal of the W component. + DxbcRegisterValue fragCoord = emitValueLoad(ptrIn); + + uint32_t componentIndex = 3; + uint32_t t_f32 = m_module.defFloatType(32); + uint32_t v_wComp = m_module.opCompositeExtract(t_f32, fragCoord.id, 1, &componentIndex); + v_wComp = m_module.opFDiv(t_f32, m_module.constf32(1.0f), v_wComp); + + fragCoord.id = m_module.opCompositeInsert( + getVectorTypeId(fragCoord.type), + v_wComp, fragCoord.id, + 1, &componentIndex); + + return emitRegisterExtract(fragCoord, mask); + } break; + + case DxbcSystemValue::IsFrontFace: { + if (m_ps.builtinIsFrontFace == 0) { + m_ps.builtinIsFrontFace = emitNewBuiltinVariable({ + { DxbcScalarType::Bool, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInFrontFacing, + "ps_is_front_face"); + } + + DxbcRegisterValue result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opSelect( + getVectorTypeId(result.type), + m_module.opLoad( + m_module.defBoolType(), + m_ps.builtinIsFrontFace), + m_module.constu32(0xFFFFFFFF), + m_module.constu32(0x00000000)); + return result; + } break; + + case DxbcSystemValue::PrimitiveId: { + if (m_primitiveIdIn == 0) { + m_module.enableCapability(spv::CapabilityGeometry); + + m_primitiveIdIn = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInPrimitiveId, + "ps_primitive_id"); + } + + DxbcRegisterPointer ptrIn; + ptrIn.type = { DxbcScalarType::Uint32, 1 }; + ptrIn.id = m_primitiveIdIn; + + return emitValueLoad(ptrIn); + } break; + + case DxbcSystemValue::SampleIndex: { + if (m_ps.builtinSampleId == 0) { + m_module.enableCapability(spv::CapabilitySampleRateShading); + + m_ps.builtinSampleId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInSampleId, + "ps_sample_id"); + } + + DxbcRegisterPointer ptrIn; + ptrIn.type.ctype = DxbcScalarType::Uint32; + ptrIn.type.ccount = 1; + ptrIn.id = m_ps.builtinSampleId; + + return emitValueLoad(ptrIn); + } break; + + case DxbcSystemValue::RenderTargetId: { + if (m_ps.builtinLayer == 0) { + m_module.enableCapability(spv::CapabilityGeometry); + + m_ps.builtinLayer = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInLayer, + "v_layer"); + } + + DxbcRegisterPointer ptr; + ptr.type.ctype = DxbcScalarType::Uint32; + ptr.type.ccount = 1; + ptr.id = m_ps.builtinLayer; + + return emitValueLoad(ptr); + } break; + + case DxbcSystemValue::ViewportId: { + if (m_ps.builtinViewportId == 0) { + m_module.enableCapability(spv::CapabilityMultiViewport); + + m_ps.builtinViewportId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInViewportIndex, + "v_viewport"); + } + + DxbcRegisterPointer ptr; + ptr.type.ctype = DxbcScalarType::Uint32; + ptr.type.ccount = 1; + ptr.id = m_ps.builtinViewportId; + + return emitValueLoad(ptr); + } break; + + default: + throw DxvkError(str::format( + "DxbcCompiler: Unhandled PS SV input: ", sv)); + } + } + + + void DxbcCompiler::emitVsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value) { + switch (sv) { + case DxbcSystemValue::Position: { + if (!m_positionOut) { + m_positionOut = emitNewBuiltinVariable({ + { DxbcScalarType::Float32, 4, 0 }, + spv::StorageClassOutput }, + spv::BuiltInPosition, + "out_position"); + } + + DxbcRegisterPointer ptr; + ptr.type.ctype = DxbcScalarType::Float32; + ptr.type.ccount = 4; + ptr.id = m_positionOut; + + emitValueStore(ptr, value, mask); + } break; + + case DxbcSystemValue::RenderTargetId: { + if (m_programInfo.type() != DxbcProgramType::GeometryShader) + m_module.enableCapability(spv::CapabilityShaderLayer); + + if (m_gs.builtinLayer == 0) { + m_module.enableCapability(spv::CapabilityGeometry); + + m_gs.builtinLayer = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInLayer, + "o_layer"); + } + + DxbcRegisterPointer ptr; + ptr.type = { DxbcScalarType::Uint32, 1 }; + ptr.id = m_gs.builtinLayer; + + emitValueStore( + ptr, emitRegisterExtract(value, mask), + DxbcRegMask(true, false, false, false)); + } break; + + case DxbcSystemValue::ViewportId: { + if (m_programInfo.type() != DxbcProgramType::GeometryShader) + m_module.enableCapability(spv::CapabilityShaderViewportIndex); + + if (m_gs.builtinViewportId == 0) { + m_module.enableCapability(spv::CapabilityMultiViewport); + + m_gs.builtinViewportId = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInViewportIndex, + "o_viewport"); + } + + DxbcRegisterPointer ptr; + ptr.type = { DxbcScalarType::Uint32, 1}; + ptr.id = m_gs.builtinViewportId; + + emitValueStore( + ptr, emitRegisterExtract(value, mask), + DxbcRegMask(true, false, false, false)); + } break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled VS SV output: ", sv)); + } + } + + + void DxbcCompiler::emitHsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value) { + if (sv >= DxbcSystemValue::FinalQuadUeq0EdgeTessFactor + && sv <= DxbcSystemValue::FinalLineDensityTessFactor) { + struct TessFactor { + uint32_t array = 0; + uint32_t index = 0; + }; + + static const std::array s_tessFactors = {{ + { m_hs.builtinTessLevelOuter, 0 }, // FinalQuadUeq0EdgeTessFactor + { m_hs.builtinTessLevelOuter, 1 }, // FinalQuadVeq0EdgeTessFactor + { m_hs.builtinTessLevelOuter, 2 }, // FinalQuadUeq1EdgeTessFactor + { m_hs.builtinTessLevelOuter, 3 }, // FinalQuadVeq1EdgeTessFactor + { m_hs.builtinTessLevelInner, 0 }, // FinalQuadUInsideTessFactor + { m_hs.builtinTessLevelInner, 1 }, // FinalQuadVInsideTessFactor + { m_hs.builtinTessLevelOuter, 0 }, // FinalTriUeq0EdgeTessFactor + { m_hs.builtinTessLevelOuter, 1 }, // FinalTriVeq0EdgeTessFactor + { m_hs.builtinTessLevelOuter, 2 }, // FinalTriWeq0EdgeTessFactor + { m_hs.builtinTessLevelInner, 0 }, // FinalTriInsideTessFactor + { m_hs.builtinTessLevelOuter, 0 }, // FinalLineDensityTessFactor + { m_hs.builtinTessLevelOuter, 1 }, // FinalLineDetailTessFactor + }}; + + const TessFactor tessFactor = s_tessFactors.at(uint32_t(sv) + - uint32_t(DxbcSystemValue::FinalQuadUeq0EdgeTessFactor)); + + const uint32_t tessFactorArrayIndex + = m_module.constu32(tessFactor.index); + + // Apply global tess factor limit + float maxTessFactor = m_hs.maxTessFactor; + + if (m_moduleInfo.tess != nullptr) { + if (m_moduleInfo.tess->maxTessFactor < maxTessFactor) + maxTessFactor = m_moduleInfo.tess->maxTessFactor; + } + + DxbcRegisterValue tessValue = emitRegisterExtract(value, mask); + tessValue.id = m_module.opNClamp(getVectorTypeId(tessValue.type), + tessValue.id, m_module.constf32(0.0f), + m_module.constf32(maxTessFactor)); + + DxbcRegisterPointer ptr; + ptr.type.ctype = DxbcScalarType::Float32; + ptr.type.ccount = 1; + ptr.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(ptr.type), + spv::StorageClassOutput), + tessFactor.array, 1, + &tessFactorArrayIndex); + + emitValueStore(ptr, tessValue, + DxbcRegMask(true, false, false, false)); + } else { + Logger::warn(str::format( + "DxbcCompiler: Unhandled HS SV output: ", sv)); + } + } + + + void DxbcCompiler::emitGsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value) { + switch (sv) { + case DxbcSystemValue::Position: + case DxbcSystemValue::CullDistance: + case DxbcSystemValue::ClipDistance: + case DxbcSystemValue::RenderTargetId: + case DxbcSystemValue::ViewportId: + emitVsSystemValueStore(sv, mask, value); + break; + + case DxbcSystemValue::PrimitiveId: { + if (m_primitiveIdOut == 0) { + m_primitiveIdOut = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInPrimitiveId, + "gs_primitive_id"); + } + + DxbcRegisterPointer ptr; + ptr.type = { DxbcScalarType::Uint32, 1}; + ptr.id = m_primitiveIdOut; + + emitValueStore( + ptr, emitRegisterExtract(value, mask), + DxbcRegMask(true, false, false, false)); + } break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled GS SV output: ", sv)); + } + } + + + void DxbcCompiler::emitPsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value) { + Logger::warn(str::format( + "DxbcCompiler: Unhandled PS SV output: ", sv)); + } + + + void DxbcCompiler::emitDsSystemValueStore( + DxbcSystemValue sv, + DxbcRegMask mask, + const DxbcRegisterValue& value) { + switch (sv) { + case DxbcSystemValue::Position: + case DxbcSystemValue::CullDistance: + case DxbcSystemValue::ClipDistance: + case DxbcSystemValue::RenderTargetId: + case DxbcSystemValue::ViewportId: + emitVsSystemValueStore(sv, mask, value); + break; + + default: + Logger::warn(str::format( + "DxbcCompiler: Unhandled DS SV output: ", sv)); + } + } + + + void DxbcCompiler::emitClipCullStore( + DxbcSystemValue sv, + uint32_t dstArray) { + uint32_t offset = 0; + + if (dstArray == 0) + return; + + for (auto e = m_osgn->begin(); e != m_osgn->end(); e++) { + if (e->systemValue == sv) { + DxbcRegisterPointer srcPtr = m_oRegs.at(e->registerId); + DxbcRegisterValue srcValue = emitValueLoad(srcPtr); + + for (uint32_t i = 0; i < 4; i++) { + if (e->componentMask[i]) { + uint32_t offsetId = m_module.consti32(offset++); + + DxbcRegisterValue component = emitRegisterExtract( + srcValue, DxbcRegMask::select(i)); + + DxbcRegisterPointer dstPtr; + dstPtr.type = { DxbcScalarType::Float32, 1 }; + dstPtr.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(dstPtr.type), + spv::StorageClassOutput), + dstArray, 1, &offsetId); + + emitValueStore(dstPtr, component, + DxbcRegMask(true, false, false, false)); + } + } + } + } + } + + + void DxbcCompiler::emitClipCullLoad( + DxbcSystemValue sv, + uint32_t srcArray) { + uint32_t offset = 0; + + if (srcArray == 0) + return; + + for (auto e = m_isgn->begin(); e != m_isgn->end(); e++) { + if (e->systemValue == sv) { + // Load individual components from the source array + uint32_t componentIndex = 0; + std::array componentIds = {{ 0, 0, 0, 0 }}; + + for (uint32_t i = 0; i < 4; i++) { + if (e->componentMask[i]) { + uint32_t offsetId = m_module.consti32(offset++); + + DxbcRegisterPointer srcPtr; + srcPtr.type = { DxbcScalarType::Float32, 1 }; + srcPtr.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(srcPtr.type), + spv::StorageClassInput), + srcArray, 1, &offsetId); + + componentIds[componentIndex++] + = emitValueLoad(srcPtr).id; + } + } + + // Put everything into one vector + DxbcRegisterValue dstValue; + dstValue.type = { DxbcScalarType::Float32, componentIndex }; + dstValue.id = componentIds[0]; + + if (componentIndex > 1) { + dstValue.id = m_module.opCompositeConstruct( + getVectorTypeId(dstValue.type), + componentIndex, componentIds.data()); + } + + // Store vector to the input array + uint32_t registerId = m_module.consti32(e->registerId); + + DxbcRegisterPointer dstInput; + dstInput.type = { DxbcScalarType::Float32, 4 }; + dstInput.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(dstInput.type), + spv::StorageClassPrivate), + m_vArray, 1, ®isterId); + + emitValueStore(dstInput, dstValue, e->componentMask); + } + } + } + + + void DxbcCompiler::emitPointSizeStore() { + if (m_moduleInfo.options.needsPointSizeExport) { + uint32_t pointSizeId = emitNewBuiltinVariable(DxbcRegisterInfo { + { DxbcScalarType::Float32, 1, 0 }, + spv::StorageClassOutput }, + spv::BuiltInPointSize, + "point_size"); + + m_module.opStore(pointSizeId, m_module.constf32(1.0f)); + } + } + + + void DxbcCompiler::emitInit() { + // Set up common capabilities for all shaders + m_module.enableCapability(spv::CapabilityShader); + m_module.enableCapability(spv::CapabilityImageQuery); + + // Initialize the shader module with capabilities + // etc. Each shader type has its own peculiarities. + switch (m_programInfo.type()) { + case DxbcProgramType::VertexShader: emitVsInit(); break; + case DxbcProgramType::HullShader: emitHsInit(); break; + case DxbcProgramType::DomainShader: emitDsInit(); break; + case DxbcProgramType::GeometryShader: emitGsInit(); break; + case DxbcProgramType::PixelShader: emitPsInit(); break; + case DxbcProgramType::ComputeShader: emitCsInit(); break; + default: throw DxvkError("Invalid shader stage"); + } + } + + + void DxbcCompiler::emitFunctionBegin( + uint32_t entryPoint, + uint32_t returnType, + uint32_t funcType) { + this->emitFunctionEnd(); + + m_module.functionBegin( + returnType, entryPoint, funcType, + spv::FunctionControlMaskNone); + + m_insideFunction = true; + } + + + void DxbcCompiler::emitFunctionEnd() { + if (m_insideFunction) { + m_module.opReturn(); + m_module.functionEnd(); + } + + m_insideFunction = false; + } + + + void DxbcCompiler::emitFunctionLabel() { + m_module.opLabel(m_module.allocateId()); + } + + + void DxbcCompiler::emitMainFunctionBegin() { + this->emitFunctionBegin( + m_entryPointId, + m_module.defVoidType(), + m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr)); + this->emitFunctionLabel(); + } + + + void DxbcCompiler::emitVsInit() { + m_module.enableCapability(spv::CapabilityClipDistance); + m_module.enableCapability(spv::CapabilityCullDistance); + m_module.enableCapability(spv::CapabilityDrawParameters); + + // Standard input array + emitDclInputArray(0); + + // Cull/clip distances as outputs + m_clipDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullOut.numClipPlanes, + spv::BuiltInClipDistance, + spv::StorageClassOutput); + + m_cullDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullOut.numCullPlanes, + spv::BuiltInCullDistance, + spv::StorageClassOutput); + + // Main function of the vertex shader + m_vs.functionId = m_module.allocateId(); + m_module.setDebugName(m_vs.functionId, "vs_main"); + + this->emitFunctionBegin( + m_vs.functionId, + m_module.defVoidType(), + m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr)); + this->emitFunctionLabel(); + } + + + void DxbcCompiler::emitHsInit() { + m_module.enableCapability(spv::CapabilityTessellation); + m_module.enableCapability(spv::CapabilityClipDistance); + m_module.enableCapability(spv::CapabilityCullDistance); + + m_hs.builtinInvocationId = emitNewBuiltinVariable( + DxbcRegisterInfo { + { DxbcScalarType::Uint32, 1, 0 }, + spv::StorageClassInput }, + spv::BuiltInInvocationId, + "vOutputControlPointId"); + + m_hs.builtinTessLevelOuter = emitBuiltinTessLevelOuter(spv::StorageClassOutput); + m_hs.builtinTessLevelInner = emitBuiltinTessLevelInner(spv::StorageClassOutput); + } + + + void DxbcCompiler::emitDsInit() { + m_module.enableCapability(spv::CapabilityTessellation); + m_module.enableCapability(spv::CapabilityClipDistance); + m_module.enableCapability(spv::CapabilityCullDistance); + + m_ds.builtinTessLevelOuter = emitBuiltinTessLevelOuter(spv::StorageClassInput); + m_ds.builtinTessLevelInner = emitBuiltinTessLevelInner(spv::StorageClassInput); + + // Cull/clip distances as outputs + m_clipDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullOut.numClipPlanes, + spv::BuiltInClipDistance, + spv::StorageClassOutput); + + m_cullDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullOut.numCullPlanes, + spv::BuiltInCullDistance, + spv::StorageClassOutput); + + // Main function of the domain shader + m_ds.functionId = m_module.allocateId(); + m_module.setDebugName(m_ds.functionId, "ds_main"); + + this->emitFunctionBegin( + m_ds.functionId, + m_module.defVoidType(), + m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr)); + this->emitFunctionLabel(); + } + + + void DxbcCompiler::emitGsInit() { + m_module.enableCapability(spv::CapabilityGeometry); + m_module.enableCapability(spv::CapabilityClipDistance); + m_module.enableCapability(spv::CapabilityCullDistance); + + // Enable capabilities for xfb mode if necessary + if (m_moduleInfo.xfb) { + m_module.enableCapability(spv::CapabilityGeometryStreams); + m_module.enableCapability(spv::CapabilityTransformFeedback); + + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeXfb); + } + + // We only need outputs if rasterization is enabled + m_gs.needsOutputSetup = !m_moduleInfo.xfb + || m_moduleInfo.xfb->rasterizedStream >= 0; + + // Cull/clip distances as outputs + m_clipDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullOut.numClipPlanes, + spv::BuiltInClipDistance, + spv::StorageClassOutput); + + m_cullDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullOut.numCullPlanes, + spv::BuiltInCullDistance, + spv::StorageClassOutput); + + // Emit Xfb variables if necessary + if (m_moduleInfo.xfb) + emitXfbOutputDeclarations(); + + // Main function of the vertex shader + m_gs.functionId = m_module.allocateId(); + m_module.setDebugName(m_gs.functionId, "gs_main"); + + this->emitFunctionBegin( + m_gs.functionId, + m_module.defVoidType(), + m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr)); + this->emitFunctionLabel(); + } + + + void DxbcCompiler::emitPsInit() { + m_module.enableCapability(spv::CapabilityDerivativeControl); + + m_module.setExecutionMode(m_entryPointId, + spv::ExecutionModeOriginUpperLeft); + + // Standard input array + emitDclInputArray(0); + + // Cull/clip distances as inputs + m_clipDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullIn.numClipPlanes, + spv::BuiltInClipDistance, + spv::StorageClassInput); + + m_cullDistances = emitDclClipCullDistanceArray( + m_analysis->clipCullIn.numCullPlanes, + spv::BuiltInCullDistance, + spv::StorageClassInput); + + // Main function of the pixel shader + m_ps.functionId = m_module.allocateId(); + m_module.setDebugName(m_ps.functionId, "ps_main"); + + this->emitFunctionBegin( + m_ps.functionId, + m_module.defVoidType(), + m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr)); + this->emitFunctionLabel(); + } + + + void DxbcCompiler::emitCsInit() { + // Main function of the compute shader + m_cs.functionId = m_module.allocateId(); + m_module.setDebugName(m_cs.functionId, "cs_main"); + + this->emitFunctionBegin( + m_cs.functionId, + m_module.defVoidType(), + m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr)); + this->emitFunctionLabel(); + } + + + void DxbcCompiler::emitVsFinalize() { + this->emitMainFunctionBegin(); + this->emitInputSetup(); + m_module.opFunctionCall( + m_module.defVoidType(), + m_vs.functionId, 0, nullptr); + this->emitOutputSetup(); + this->emitClipCullStore(DxbcSystemValue::ClipDistance, m_clipDistances); + this->emitClipCullStore(DxbcSystemValue::CullDistance, m_cullDistances); + this->emitPointSizeStore(); + this->emitFunctionEnd(); + } + + + void DxbcCompiler::emitHsFinalize() { + if (m_hs.cpPhase.functionId == 0) + m_hs.cpPhase = this->emitNewHullShaderPassthroughPhase(); + + // Control point phase + this->emitMainFunctionBegin(); + this->emitInputSetup(m_hs.vertexCountIn); + this->emitHsControlPointPhase(m_hs.cpPhase); + this->emitHsPhaseBarrier(); + + // Fork-join phases and output setup + this->emitHsInvocationBlockBegin(1); + + for (const auto& phase : m_hs.forkPhases) + this->emitHsForkJoinPhase(phase); + + for (const auto& phase : m_hs.joinPhases) + this->emitHsForkJoinPhase(phase); + + this->emitOutputSetup(); + this->emitHsOutputSetup(); + this->emitHsInvocationBlockEnd(); + this->emitFunctionEnd(); + } + + + void DxbcCompiler::emitDsFinalize() { + this->emitMainFunctionBegin(); + m_module.opFunctionCall( + m_module.defVoidType(), + m_ds.functionId, 0, nullptr); + this->emitOutputSetup(); + this->emitClipCullStore(DxbcSystemValue::ClipDistance, m_clipDistances); + this->emitClipCullStore(DxbcSystemValue::CullDistance, m_cullDistances); + this->emitFunctionEnd(); + } + + + void DxbcCompiler::emitGsFinalize() { + if (!m_gs.invocationCount) + m_module.setInvocations(m_entryPointId, 1); + + this->emitMainFunctionBegin(); + this->emitInputSetup( + primitiveVertexCount(m_gs.inputPrimitive)); + m_module.opFunctionCall( + m_module.defVoidType(), + m_gs.functionId, 0, nullptr); + // No output setup at this point as that was + // already done during the EmitVertex step + this->emitFunctionEnd(); + } + + + void DxbcCompiler::emitPsFinalize() { + this->emitMainFunctionBegin(); + this->emitInputSetup(); + this->emitClipCullLoad(DxbcSystemValue::ClipDistance, m_clipDistances); + this->emitClipCullLoad(DxbcSystemValue::CullDistance, m_cullDistances); + + if (m_hasRasterizerOrderedUav) { + // For simplicity, just lock the entire fragment shader + // if there are any rasterizer ordered views. + m_module.enableExtension("SPV_EXT_fragment_shader_interlock"); + + if (m_module.hasCapability(spv::CapabilitySampleRateShading) + && m_moduleInfo.options.enableSampleShadingInterlock) { + m_module.enableCapability(spv::CapabilityFragmentShaderSampleInterlockEXT); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeSampleInterlockOrderedEXT); + } else { + m_module.enableCapability(spv::CapabilityFragmentShaderPixelInterlockEXT); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModePixelInterlockOrderedEXT); + } + + m_module.opBeginInvocationInterlock(); + } + + m_module.opFunctionCall( + m_module.defVoidType(), + m_ps.functionId, 0, nullptr); + + if (m_hasRasterizerOrderedUav) + m_module.opEndInvocationInterlock(); + + this->emitOutputSetup(); + + if (m_moduleInfo.options.useDepthClipWorkaround) + this->emitOutputDepthClamp(); + + this->emitFunctionEnd(); + } + + + void DxbcCompiler::emitCsFinalize() { + this->emitMainFunctionBegin(); + + if (m_moduleInfo.options.zeroInitWorkgroupMemory) + this->emitInitWorkgroupMemory(); + + m_module.opFunctionCall( + m_module.defVoidType(), + m_cs.functionId, 0, nullptr); + + this->emitFunctionEnd(); + } + + + void DxbcCompiler::emitXfbOutputDeclarations() { + for (uint32_t i = 0; i < m_moduleInfo.xfb->entryCount; i++) { + const DxbcXfbEntry* xfbEntry = m_moduleInfo.xfb->entries + i; + const DxbcSgnEntry* sigEntry = m_osgn->find( + xfbEntry->semanticName, + xfbEntry->semanticIndex, + xfbEntry->streamId); + + if (sigEntry == nullptr) + continue; + + DxbcRegisterInfo varInfo; + varInfo.type.ctype = DxbcScalarType::Float32; + varInfo.type.ccount = xfbEntry->componentCount; + varInfo.type.alength = 0; + varInfo.sclass = spv::StorageClassOutput; + + uint32_t dstComponentMask = (1 << xfbEntry->componentCount) - 1; + uint32_t srcComponentMask = dstComponentMask + << sigEntry->componentMask.firstSet() + << xfbEntry->componentIndex; + + DxbcXfbVar xfbVar; + xfbVar.varId = emitNewVariable(varInfo); + xfbVar.streamId = xfbEntry->streamId; + xfbVar.outputId = sigEntry->registerId; + xfbVar.srcMask = DxbcRegMask(srcComponentMask); + xfbVar.dstMask = DxbcRegMask(dstComponentMask); + m_xfbVars.push_back(xfbVar); + + m_module.setDebugName(xfbVar.varId, + str::format("xfb", i).c_str()); + + m_module.decorateXfb(xfbVar.varId, + xfbEntry->streamId, xfbEntry->bufferId, xfbEntry->offset, + m_moduleInfo.xfb->strides[xfbEntry->bufferId]); + } + + // TODO Compact location/component assignment + for (uint32_t i = 0; i < m_xfbVars.size(); i++) { + m_xfbVars[i].location = i; + m_xfbVars[i].component = 0; + } + + for (uint32_t i = 0; i < m_xfbVars.size(); i++) { + const DxbcXfbVar* var = &m_xfbVars[i]; + + m_module.decorateLocation (var->varId, var->location); + m_module.decorateComponent(var->varId, var->component); + } + } + + + void DxbcCompiler::emitXfbOutputSetup( + uint32_t streamId, + bool passthrough) { + for (size_t i = 0; i < m_xfbVars.size(); i++) { + if (m_xfbVars[i].streamId == streamId) { + DxbcRegisterPointer srcPtr = passthrough + ? m_vRegs[m_xfbVars[i].outputId] + : m_oRegs[m_xfbVars[i].outputId]; + + if (passthrough) { + srcPtr = emitArrayAccess(srcPtr, + spv::StorageClassInput, + m_module.constu32(0)); + } + + DxbcRegisterPointer dstPtr; + dstPtr.type.ctype = DxbcScalarType::Float32; + dstPtr.type.ccount = m_xfbVars[i].dstMask.popCount(); + dstPtr.id = m_xfbVars[i].varId; + + DxbcRegisterValue value = emitRegisterExtract( + emitValueLoad(srcPtr), m_xfbVars[i].srcMask); + emitValueStore(dstPtr, value, m_xfbVars[i].dstMask); + } + } + } + + + void DxbcCompiler::emitHsControlPointPhase( + const DxbcCompilerHsControlPointPhase& phase) { + m_module.opFunctionCall( + m_module.defVoidType(), + phase.functionId, 0, nullptr); + } + + + void DxbcCompiler::emitHsForkJoinPhase( + const DxbcCompilerHsForkJoinPhase& phase) { + for (uint32_t i = 0; i < phase.instanceCount; i++) { + uint32_t invocationId = m_module.constu32(i); + + m_module.opFunctionCall( + m_module.defVoidType(), + phase.functionId, 1, + &invocationId); + } + } + + + void DxbcCompiler::emitDclInputArray(uint32_t vertexCount) { + DxbcVectorType info; + info.ctype = DxbcScalarType::Float32; + info.ccount = 4; + + // Define the array type. This will be two-dimensional + // in some shaders, with the outer index representing + // the vertex ID within an invocation. + m_vArrayLength = m_isgn != nullptr ? std::max(1u, m_isgn->maxRegisterCount()) : 1; + m_vArrayLengthId = m_module.lateConst32(getScalarTypeId(DxbcScalarType::Uint32)); + + uint32_t vectorTypeId = getVectorTypeId(info); + uint32_t arrayTypeId = m_module.defArrayType(vectorTypeId, m_vArrayLengthId); + + if (vertexCount != 0) { + arrayTypeId = m_module.defArrayType( + arrayTypeId, m_module.constu32(vertexCount)); + } + + // Define the actual variable. Note that this is private + // because we will copy input registers and some system + // variables to the array during the setup phase. + const uint32_t ptrTypeId = m_module.defPointerType( + arrayTypeId, spv::StorageClassPrivate); + + const uint32_t varId = m_module.newVar( + ptrTypeId, spv::StorageClassPrivate); + + m_module.setDebugName(varId, "shader_in"); + m_vArray = varId; + } + + + uint32_t DxbcCompiler::emitDclClipCullDistanceArray( + uint32_t length, + spv::BuiltIn builtIn, + spv::StorageClass storageClass) { + if (length == 0) + return 0; + + uint32_t t_f32 = m_module.defFloatType(32); + uint32_t t_arr = m_module.defArrayType(t_f32, m_module.constu32(length)); + uint32_t t_ptr = m_module.defPointerType(t_arr, storageClass); + uint32_t varId = m_module.newVar(t_ptr, storageClass); + + m_module.decorateBuiltIn(varId, builtIn); + m_module.setDebugName(varId, + builtIn == spv::BuiltInClipDistance + ? "clip_distances" + : "cull_distances"); + + return varId; + } + + + DxbcCompilerHsControlPointPhase DxbcCompiler::emitNewHullShaderControlPointPhase() { + uint32_t funTypeId = m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr); + + uint32_t funId = m_module.allocateId(); + + this->emitFunctionBegin(funId, + m_module.defVoidType(), + funTypeId); + this->emitFunctionLabel(); + + DxbcCompilerHsControlPointPhase result; + result.functionId = funId; + return result; + } + + + DxbcCompilerHsControlPointPhase DxbcCompiler::emitNewHullShaderPassthroughPhase() { + uint32_t funTypeId = m_module.defFunctionType( + m_module.defVoidType(), 0, nullptr); + + // Begin passthrough function + uint32_t funId = m_module.allocateId(); + m_module.setDebugName(funId, "hs_passthrough"); + + this->emitFunctionBegin(funId, + m_module.defVoidType(), + funTypeId); + this->emitFunctionLabel(); + + // We'll basically copy each input variable to the corresponding + // output, using the shader's invocation ID as the array index. + const uint32_t invocationId = m_module.opLoad( + getScalarTypeId(DxbcScalarType::Uint32), + m_hs.builtinInvocationId); + + for (auto i = m_isgn->begin(); i != m_isgn->end(); i++) { + this->emitDclInput( + i->registerId, m_hs.vertexCountIn, + i->componentMask, + DxbcSystemValue::None, + DxbcInterpolationMode::Undefined); + + // Vector type index + const std::array dstIndices + = {{ invocationId, m_module.constu32(i->registerId) }}; + + DxbcRegisterPointer srcPtr; + srcPtr.type = m_vRegs.at(i->registerId).type; + srcPtr.id = m_module.opAccessChain( + m_module.defPointerType(getVectorTypeId(srcPtr.type), spv::StorageClassInput), + m_vRegs.at(i->registerId).id, 1, &invocationId); + + DxbcRegisterValue srcValue = emitRegisterBitcast( + emitValueLoad(srcPtr), DxbcScalarType::Float32); + + DxbcRegisterPointer dstPtr; + dstPtr.type = { DxbcScalarType::Float32, 4 }; + dstPtr.id = m_module.opAccessChain( + m_module.defPointerType(getVectorTypeId(dstPtr.type), spv::StorageClassOutput), + m_hs.outputPerVertex, dstIndices.size(), dstIndices.data()); + + emitValueStore(dstPtr, srcValue, DxbcRegMask::firstN(srcValue.type.ccount)); + } + + // End function + this->emitFunctionEnd(); + + DxbcCompilerHsControlPointPhase result; + result.functionId = funId; + return result; + } + + + DxbcCompilerHsForkJoinPhase DxbcCompiler::emitNewHullShaderForkJoinPhase() { + uint32_t argTypeId = m_module.defIntType(32, 0); + uint32_t funTypeId = m_module.defFunctionType( + m_module.defVoidType(), 1, &argTypeId); + + uint32_t funId = m_module.allocateId(); + + this->emitFunctionBegin(funId, + m_module.defVoidType(), + funTypeId); + + uint32_t argId = m_module.functionParameter(argTypeId); + this->emitFunctionLabel(); + + DxbcCompilerHsForkJoinPhase result; + result.functionId = funId; + result.instanceId = argId; + return result; + } + + + void DxbcCompiler::emitHsPhaseBarrier() { + uint32_t exeScopeId = m_module.constu32(spv::ScopeWorkgroup); + uint32_t memScopeId = m_module.constu32(spv::ScopeWorkgroup); + uint32_t semanticId = m_module.constu32( + spv::MemorySemanticsOutputMemoryMask | + spv::MemorySemanticsAcquireReleaseMask | + spv::MemorySemanticsMakeAvailableMask | + spv::MemorySemanticsMakeVisibleMask); + + m_module.opControlBarrier(exeScopeId, memScopeId, semanticId); + } + + + void DxbcCompiler::emitHsInvocationBlockBegin(uint32_t count) { + uint32_t invocationId = m_module.opLoad( + getScalarTypeId(DxbcScalarType::Uint32), + m_hs.builtinInvocationId); + + uint32_t condition = m_module.opULessThan( + m_module.defBoolType(), invocationId, + m_module.constu32(count)); + + m_hs.invocationBlockBegin = m_module.allocateId(); + m_hs.invocationBlockEnd = m_module.allocateId(); + + m_module.opSelectionMerge( + m_hs.invocationBlockEnd, + spv::SelectionControlMaskNone); + + m_module.opBranchConditional( + condition, + m_hs.invocationBlockBegin, + m_hs.invocationBlockEnd); + + m_module.opLabel( + m_hs.invocationBlockBegin); + } + + + void DxbcCompiler::emitHsInvocationBlockEnd() { + m_module.opBranch (m_hs.invocationBlockEnd); + m_module.opLabel (m_hs.invocationBlockEnd); + + m_hs.invocationBlockBegin = 0; + m_hs.invocationBlockEnd = 0; + } + + + void DxbcCompiler::emitHsOutputSetup() { + uint32_t outputPerPatch = emitTessInterfacePerPatch(spv::StorageClassOutput); + + if (!outputPerPatch) + return; + + uint32_t vecType = getVectorTypeId({ DxbcScalarType::Float32, 4 }); + + uint32_t srcPtrType = m_module.defPointerType(vecType, spv::StorageClassPrivate); + uint32_t dstPtrType = m_module.defPointerType(vecType, spv::StorageClassOutput); + + for (uint32_t i = 0; i < 32; i++) { + if (m_hs.outputPerPatchMask & (1 << i)) { + uint32_t index = m_module.constu32(i); + + uint32_t srcPtr = m_module.opAccessChain(srcPtrType, m_hs.outputPerPatch, 1, &index); + uint32_t dstPtr = m_module.opAccessChain(dstPtrType, outputPerPatch, 1, &index); + + m_module.opStore(dstPtr, m_module.opLoad(vecType, srcPtr)); + } + } + } + + + uint32_t DxbcCompiler::emitTessInterfacePerPatch(spv::StorageClass storageClass) { + const char* name = "vPatch"; + + if (storageClass == spv::StorageClassPrivate) + name = "rPatch"; + if (storageClass == spv::StorageClassOutput) + name = "oPatch"; + + uint32_t arrLen = m_psgn != nullptr ? m_psgn->maxRegisterCount() : 0; + + if (!arrLen) + return 0; + + uint32_t vecType = m_module.defVectorType (m_module.defFloatType(32), 4); + uint32_t arrType = m_module.defArrayType (vecType, m_module.constu32(arrLen)); + uint32_t ptrType = m_module.defPointerType(arrType, storageClass); + uint32_t varId = m_module.newVar (ptrType, storageClass); + + m_module.setDebugName (varId, name); + + if (storageClass != spv::StorageClassPrivate) { + m_module.decorate (varId, spv::DecorationPatch); + m_module.decorateLocation (varId, 0); + } + + return varId; + } + + + uint32_t DxbcCompiler::emitTessInterfacePerVertex(spv::StorageClass storageClass, uint32_t vertexCount) { + const bool isInput = storageClass == spv::StorageClassInput; + + uint32_t arrLen = isInput + ? (m_isgn != nullptr ? m_isgn->maxRegisterCount() : 0) + : (m_osgn != nullptr ? m_osgn->maxRegisterCount() : 0); + + if (!arrLen) + return 0; + + uint32_t locIdx = m_psgn != nullptr + ? m_psgn->maxRegisterCount() + : 0; + + uint32_t vecType = m_module.defVectorType (m_module.defFloatType(32), 4); + uint32_t arrTypeInner = m_module.defArrayType (vecType, m_module.constu32(arrLen)); + uint32_t arrTypeOuter = m_module.defArrayType (arrTypeInner, m_module.constu32(vertexCount)); + uint32_t ptrType = m_module.defPointerType(arrTypeOuter, storageClass); + uint32_t varId = m_module.newVar (ptrType, storageClass); + + m_module.setDebugName (varId, isInput ? "vVertex" : "oVertex"); + m_module.decorateLocation (varId, locIdx); + return varId; + } + + + uint32_t DxbcCompiler::emitSamplePosArray() { + const std::array samplePosVectors = {{ + // Invalid sample count / unbound resource + m_module.constvec2f32( 0.0f, 0.0f), + // VK_SAMPLE_COUNT_1_BIT + m_module.constvec2f32( 0.0f, 0.0f), + // VK_SAMPLE_COUNT_2_BIT + m_module.constvec2f32( 0.25f, 0.25f), + m_module.constvec2f32(-0.25f,-0.25f), + // VK_SAMPLE_COUNT_4_BIT + m_module.constvec2f32(-0.125f,-0.375f), + m_module.constvec2f32( 0.375f,-0.125f), + m_module.constvec2f32(-0.375f, 0.125f), + m_module.constvec2f32( 0.125f, 0.375f), + // VK_SAMPLE_COUNT_8_BIT + m_module.constvec2f32( 0.0625f,-0.1875f), + m_module.constvec2f32(-0.0625f, 0.1875f), + m_module.constvec2f32( 0.3125f, 0.0625f), + m_module.constvec2f32(-0.1875f,-0.3125f), + m_module.constvec2f32(-0.3125f, 0.3125f), + m_module.constvec2f32(-0.4375f,-0.0625f), + m_module.constvec2f32( 0.1875f, 0.4375f), + m_module.constvec2f32( 0.4375f,-0.4375f), + // VK_SAMPLE_COUNT_16_BIT + m_module.constvec2f32( 0.0625f, 0.0625f), + m_module.constvec2f32(-0.0625f,-0.1875f), + m_module.constvec2f32(-0.1875f, 0.1250f), + m_module.constvec2f32( 0.2500f,-0.0625f), + m_module.constvec2f32(-0.3125f,-0.1250f), + m_module.constvec2f32( 0.1250f, 0.3125f), + m_module.constvec2f32( 0.3125f, 0.1875f), + m_module.constvec2f32( 0.1875f,-0.3125f), + m_module.constvec2f32(-0.1250f, 0.3750f), + m_module.constvec2f32( 0.0000f,-0.4375f), + m_module.constvec2f32(-0.2500f,-0.3750f), + m_module.constvec2f32(-0.3750f, 0.2500f), + m_module.constvec2f32(-0.5000f, 0.0000f), + m_module.constvec2f32( 0.4375f,-0.2500f), + m_module.constvec2f32( 0.3750f, 0.4375f), + m_module.constvec2f32(-0.4375f,-0.5000f), + }}; + + uint32_t arrayTypeId = getArrayTypeId({ + DxbcScalarType::Float32, 2, + static_cast(samplePosVectors.size()) }); + + uint32_t samplePosArray = m_module.constComposite( + arrayTypeId, + samplePosVectors.size(), + samplePosVectors.data()); + + uint32_t varId = m_module.newVarInit( + m_module.defPointerType(arrayTypeId, spv::StorageClassPrivate), + spv::StorageClassPrivate, samplePosArray); + + m_module.setDebugName(varId, "g_sample_pos"); + m_module.decorate(varId, spv::DecorationNonWritable); + return varId; + } + + + void DxbcCompiler::emitFloatControl() { + DxbcFloatControlFlags flags = m_moduleInfo.options.floatControl; + + if (flags.isClear()) + return; + + const uint32_t width32 = 32; + const uint32_t width64 = 64; + + if (flags.test(DxbcFloatControlFlag::DenormFlushToZero32)) { + m_module.enableCapability(spv::CapabilityDenormFlushToZero); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeDenormFlushToZero, 1, &width32); + } + + if (flags.test(DxbcFloatControlFlag::PreserveNan32)) { + m_module.enableCapability(spv::CapabilitySignedZeroInfNanPreserve); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeSignedZeroInfNanPreserve, 1, &width32); + } + + if (m_module.hasCapability(spv::CapabilityFloat64)) { + if (flags.test(DxbcFloatControlFlag::DenormPreserve64)) { + m_module.enableCapability(spv::CapabilityDenormPreserve); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeDenormPreserve, 1, &width64); + } + + if (flags.test(DxbcFloatControlFlag::PreserveNan64)) { + m_module.enableCapability(spv::CapabilitySignedZeroInfNanPreserve); + m_module.setExecutionMode(m_entryPointId, spv::ExecutionModeSignedZeroInfNanPreserve, 1, &width64); + } + } + } + + + uint32_t DxbcCompiler::emitNewVariable(const DxbcRegisterInfo& info) { + const uint32_t ptrTypeId = this->getPointerTypeId(info); + return m_module.newVar(ptrTypeId, info.sclass); + } + + + uint32_t DxbcCompiler::emitNewBuiltinVariable( + const DxbcRegisterInfo& info, + spv::BuiltIn builtIn, + const char* name) { + const uint32_t varId = emitNewVariable(info); + + if (name) + m_module.setDebugName(varId, name); + + m_module.decorateBuiltIn(varId, builtIn); + + if (m_programInfo.type() == DxbcProgramType::PixelShader + && info.type.ctype != DxbcScalarType::Float32 + && info.type.ctype != DxbcScalarType::Bool + && info.sclass == spv::StorageClassInput) + m_module.decorate(varId, spv::DecorationFlat); + + return varId; + } + + + uint32_t DxbcCompiler::emitBuiltinTessLevelOuter(spv::StorageClass storageClass) { + uint32_t id = emitNewBuiltinVariable( + DxbcRegisterInfo { + { DxbcScalarType::Float32, 0, 4 }, + storageClass }, + spv::BuiltInTessLevelOuter, + "bTessLevelOuter"); + + m_module.decorate(id, spv::DecorationPatch); + return id; + } + + + uint32_t DxbcCompiler::emitBuiltinTessLevelInner(spv::StorageClass storageClass) { + uint32_t id = emitNewBuiltinVariable( + DxbcRegisterInfo { + { DxbcScalarType::Float32, 0, 2 }, + storageClass }, + spv::BuiltInTessLevelInner, + "bTessLevelInner"); + + m_module.decorate(id, spv::DecorationPatch); + return id; + } + + + uint32_t DxbcCompiler::emitPushConstants() { + uint32_t uintTypeId = m_module.defIntType(32, 0); + uint32_t structTypeId = m_module.defStructTypeUnique(1, &uintTypeId); + + m_module.setDebugName(structTypeId, "pc_t"); + m_module.setDebugMemberName(structTypeId, 0, "RasterizerSampleCount"); + m_module.memberDecorateOffset(structTypeId, 0, 0); + + uint32_t ptrTypeId = m_module.defPointerType(structTypeId, spv::StorageClassPushConstant); + uint32_t varId = m_module.newVar(ptrTypeId, spv::StorageClassPushConstant); + + m_module.setDebugName(varId, "pc"); + return varId; + } + + + DxbcCfgBlock* DxbcCompiler::cfgFindBlock( + const std::initializer_list& types) { + for (auto cur = m_controlFlowBlocks.rbegin(); + cur != m_controlFlowBlocks.rend(); cur++) { + for (auto type : types) { + if (cur->type == type) + return &(*cur); + } + } + + return nullptr; + } + + + DxbcBufferInfo DxbcCompiler::getBufferInfo(const DxbcRegister& reg) { + const uint32_t registerId = reg.idx[0].offset; + + switch (reg.type) { + case DxbcOperandType::Resource: { + const auto& texture = m_textures.at(registerId); + + DxbcBufferInfo result; + result.image = texture.imageInfo; + result.stype = texture.sampledType; + result.type = texture.type; + result.typeId = texture.imageTypeId; + result.varId = texture.varId; + result.stride = texture.structStride; + result.coherence = 0; + result.isSsbo = texture.isRawSsbo; + return result; + } break; + + case DxbcOperandType::UnorderedAccessView: { + const auto& uav = m_uavs.at(registerId); + + DxbcBufferInfo result; + result.image = uav.imageInfo; + result.stype = uav.sampledType; + result.type = uav.type; + result.typeId = uav.imageTypeId; + result.varId = uav.varId; + result.stride = uav.structStride; + result.coherence = uav.coherence; + result.isSsbo = uav.isRawSsbo; + return result; + } break; + + case DxbcOperandType::ThreadGroupSharedMemory: { + DxbcBufferInfo result; + result.image = { spv::DimBuffer, 0, 0, 0 }; + result.stype = DxbcScalarType::Uint32; + result.type = m_gRegs.at(registerId).type; + result.typeId = m_module.defPointerType( + getScalarTypeId(DxbcScalarType::Uint32), + spv::StorageClassWorkgroup); + result.varId = m_gRegs.at(registerId).varId; + result.stride = m_gRegs.at(registerId).elementStride; + result.coherence = spv::ScopeInvocation; + result.isSsbo = false; + return result; + } break; + + default: + throw DxvkError(str::format("DxbcCompiler: Invalid operand type for buffer: ", reg.type)); + } + } + + + uint32_t DxbcCompiler::getTexSizeDim(const DxbcImageInfo& imageType) const { + switch (imageType.dim) { + case spv::DimBuffer: return 1 + imageType.array; + case spv::Dim1D: return 1 + imageType.array; + case spv::Dim2D: return 2 + imageType.array; + case spv::Dim3D: return 3 + imageType.array; + case spv::DimCube: return 2 + imageType.array; + default: throw DxvkError("DxbcCompiler: getTexLayerDim: Unsupported image dimension"); + } + } + + + uint32_t DxbcCompiler::getTexLayerDim(const DxbcImageInfo& imageType) const { + switch (imageType.dim) { + case spv::DimBuffer: return 1; + case spv::Dim1D: return 1; + case spv::Dim2D: return 2; + case spv::Dim3D: return 3; + case spv::DimCube: return 3; + default: throw DxvkError("DxbcCompiler: getTexLayerDim: Unsupported image dimension"); + } + } + + + uint32_t DxbcCompiler::getTexCoordDim(const DxbcImageInfo& imageType) const { + return getTexLayerDim(imageType) + imageType.array; + } + + + DxbcRegMask DxbcCompiler::getTexCoordMask(const DxbcImageInfo& imageType) const { + return DxbcRegMask::firstN(getTexCoordDim(imageType)); + } + + + bool DxbcCompiler::ignoreInputSystemValue(DxbcSystemValue sv) const { + switch (sv) { + case DxbcSystemValue::Position: + case DxbcSystemValue::IsFrontFace: + case DxbcSystemValue::SampleIndex: + case DxbcSystemValue::PrimitiveId: + case DxbcSystemValue::Coverage: + return m_programInfo.type() == DxbcProgramType::PixelShader; + + default: + return false; + } + } + + + void DxbcCompiler::emitUavBarrier(uint64_t readMask, uint64_t writeMask) { + if (!m_moduleInfo.options.forceComputeUavBarriers + || m_programInfo.type() != DxbcProgramType::ComputeShader) + return; + + // If both masks are 0, emit a barrier in case at least one read-write UAV + // has a pending unsynchronized access. Only consider read-after-write and + // write-after-read hazards, assume that back-to-back stores are safe and + // do not overlap in memory. Atomics are also completely ignored here. + uint64_t rdMask = m_uavRdMask; + uint64_t wrMask = m_uavWrMask; + + bool insertBarrier = bool(rdMask & wrMask); + + if (readMask || writeMask) { + rdMask &= m_uavWrMask; + wrMask &= m_uavRdMask; + } + + for (auto uav : bit::BitMask(rdMask | wrMask)) { + constexpr VkAccessFlags rwAccess = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + insertBarrier |= (m_analysis->uavInfos[uav].accessFlags & rwAccess) == rwAccess; + } + + // Need to be in uniform top-level control flow, or otherwise + // it is not safe to insert control barriers. + if (insertBarrier && m_controlFlowBlocks.empty() && m_topLevelIsUniform) { + m_module.opControlBarrier( + m_module.constu32(spv::ScopeWorkgroup), + m_module.constu32(m_hasGloballyCoherentUav ? spv::ScopeQueueFamily : spv::ScopeWorkgroup), + m_module.constu32(spv::MemorySemanticsWorkgroupMemoryMask + | spv::MemorySemanticsImageMemoryMask + | spv::MemorySemanticsUniformMemoryMask + | spv::MemorySemanticsAcquireReleaseMask + | spv::MemorySemanticsMakeAvailableMask + | spv::MemorySemanticsMakeVisibleMask)); + + m_uavWrMask = 0u; + m_uavRdMask = 0u; + } + + // Mark pending accesses + m_uavWrMask |= writeMask; + m_uavRdMask |= readMask; + } + + + DxbcVectorType DxbcCompiler::getInputRegType(uint32_t regIdx) const { + switch (m_programInfo.type()) { + case DxbcProgramType::VertexShader: { + const DxbcSgnEntry* entry = m_isgn->findByRegister(regIdx); + + DxbcVectorType result; + result.ctype = DxbcScalarType::Float32; + result.ccount = 4; + + if (entry != nullptr) { + result.ctype = entry->componentType; + result.ccount = entry->componentMask.popCount(); + } + + return result; + } + + case DxbcProgramType::DomainShader: { + DxbcVectorType result; + result.ctype = DxbcScalarType::Float32; + result.ccount = 4; + return result; + } + + default: { + DxbcVectorType result; + result.ctype = DxbcScalarType::Float32; + result.ccount = 4; + + if (m_isgn == nullptr || !m_isgn->findByRegister(regIdx)) + return result; + + DxbcRegMask mask(0u); + DxbcRegMask used(0u); + + for (const auto& e : *m_isgn) { + if (e.registerId == regIdx && !ignoreInputSystemValue(e.systemValue)) { + mask |= e.componentMask; + used |= e.componentUsed; + } + } + + if (m_programInfo.type() == DxbcProgramType::PixelShader) { + if ((used.raw() & mask.raw()) == used.raw()) + mask = used; + } + + result.ccount = mask.minComponents(); + return result; + } + } + } + + + DxbcVectorType DxbcCompiler::getOutputRegType(uint32_t regIdx) const { + switch (m_programInfo.type()) { + case DxbcProgramType::PixelShader: { + const DxbcSgnEntry* entry = m_osgn->findByRegister(regIdx); + + DxbcVectorType result; + result.ctype = DxbcScalarType::Float32; + result.ccount = 4; + + if (entry != nullptr) { + result.ctype = entry->componentType; + result.ccount = entry->componentMask.popCount(); + } + + return result; + } + + case DxbcProgramType::HullShader: { + DxbcVectorType result; + result.ctype = DxbcScalarType::Float32; + result.ccount = 4; + return result; + } + + default: { + DxbcVectorType result; + result.ctype = DxbcScalarType::Float32; + result.ccount = 4; + + if (m_osgn->findByRegister(regIdx)) + result.ccount = m_osgn->regMask(regIdx).minComponents(); + return result; + } + } + } + + + DxbcImageInfo DxbcCompiler::getResourceType( + DxbcResourceDim resourceType, + bool isUav) const { + uint32_t ms = m_moduleInfo.options.disableMsaa ? 0 : 1; + + switch (resourceType) { + case DxbcResourceDim::Buffer: return { spv::DimBuffer, 0, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_MAX_ENUM }; + case DxbcResourceDim::Texture1D: return { spv::Dim1D, 0, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_1D }; + case DxbcResourceDim::Texture1DArr: return { spv::Dim1D, 1, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_1D_ARRAY }; + case DxbcResourceDim::Texture2D: return { spv::Dim2D, 0, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_2D }; + case DxbcResourceDim::Texture2DArr: return { spv::Dim2D, 1, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_2D_ARRAY }; + case DxbcResourceDim::Texture2DMs: return { spv::Dim2D, 0, ms,isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_2D }; + case DxbcResourceDim::Texture2DMsArr: return { spv::Dim2D, 1, ms,isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_2D_ARRAY }; + case DxbcResourceDim::Texture3D: return { spv::Dim3D, 0, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_3D }; + case DxbcResourceDim::TextureCube: return { spv::DimCube, 0, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_CUBE }; + case DxbcResourceDim::TextureCubeArr: return { spv::DimCube, 1, 0, isUav ? 2u : 1u, VK_IMAGE_VIEW_TYPE_CUBE_ARRAY }; + default: throw DxvkError(str::format("DxbcCompiler: Unsupported resource type: ", resourceType)); + } + } + + + spv::ImageFormat DxbcCompiler::getScalarImageFormat(DxbcScalarType type) const { + switch (type) { + case DxbcScalarType::Float32: return spv::ImageFormatR32f; + case DxbcScalarType::Sint32: return spv::ImageFormatR32i; + case DxbcScalarType::Uint32: return spv::ImageFormatR32ui; + default: throw DxvkError("DxbcCompiler: Unhandled scalar resource type"); + } + } + + + bool DxbcCompiler::isDoubleType(DxbcScalarType type) const { + return type == DxbcScalarType::Sint64 + || type == DxbcScalarType::Uint64 + || type == DxbcScalarType::Float64; + } + + DxbcRegisterPointer DxbcCompiler::getIndexableTempPtr( + const DxbcRegister& operand, + DxbcRegisterValue vectorId) { + // x# regs are indexed as follows: + // (0) register index (immediate) + // (1) element index (relative) + const uint32_t regId = operand.idx[0].offset; + + DxbcRegisterInfo info; + info.type.ctype = DxbcScalarType::Float32; + info.type.ccount = m_xRegs[regId].ccount; + info.type.alength = 0; + info.sclass = spv::StorageClassPrivate; + + DxbcRegisterPointer result; + result.type.ctype = info.type.ctype; + result.type.ccount = info.type.ccount; + result.id = m_module.opAccessChain( + getPointerTypeId(info), + m_xRegs.at(regId).varId, + 1, &vectorId.id); + + return result; + } + + bool DxbcCompiler::caseBlockIsFallthrough() const { + return m_lastOp != DxbcOpcode::Case + && m_lastOp != DxbcOpcode::Default + && m_lastOp != DxbcOpcode::Break + && m_lastOp != DxbcOpcode::Ret; + } + + + uint32_t DxbcCompiler::getUavCoherence(uint32_t registerId, DxbcUavFlags flags) { + // For any ROV with write access, we must ensure that + // availability operations happen within the locked scope. + if (flags.test(DxbcUavFlag::RasterizerOrdered) + && (m_analysis->uavInfos[registerId].accessFlags & VK_ACCESS_SHADER_WRITE_BIT)) { + m_hasGloballyCoherentUav = true; + m_hasRasterizerOrderedUav = true; + return spv::ScopeQueueFamily; + } + + // Ignore any resources that can't both be read and written in + // the current shader, explicit availability/visibility operands + // are not useful in that case. + if (m_analysis->uavInfos[registerId].accessFlags != (VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT)) + return 0; + + // If the globally coherent flag is set, the resource must be + // coherent across multiple workgroups of the same dispatch + if (flags.test(DxbcUavFlag::GloballyCoherent)) { + m_hasGloballyCoherentUav = true; + return spv::ScopeQueueFamily; + } + + // In compute shaders, UAVs are implicitly workgroup coherent, + // but we can rely on memory barrier instructions to make any + // access available and visible to the entire workgroup. + if (m_programInfo.type() == DxbcProgramType::ComputeShader) + return spv::ScopeInvocation; + + return 0; + } + + + uint32_t DxbcCompiler::getScalarTypeId(DxbcScalarType type) { + if (type == DxbcScalarType::Float64) + m_module.enableCapability(spv::CapabilityFloat64); + + if (type == DxbcScalarType::Sint64 || type == DxbcScalarType::Uint64) + m_module.enableCapability(spv::CapabilityInt64); + + switch (type) { + case DxbcScalarType::Uint32: return m_module.defIntType(32, 0); + case DxbcScalarType::Uint64: return m_module.defIntType(64, 0); + case DxbcScalarType::Sint32: return m_module.defIntType(32, 1); + case DxbcScalarType::Sint64: return m_module.defIntType(64, 1); + case DxbcScalarType::Float32: return m_module.defFloatType(32); + case DxbcScalarType::Float64: return m_module.defFloatType(64); + case DxbcScalarType::Bool: return m_module.defBoolType(); + } + + throw DxvkError("DxbcCompiler: Invalid scalar type"); + } + + + uint32_t DxbcCompiler::getVectorTypeId(const DxbcVectorType& type) { + uint32_t typeId = this->getScalarTypeId(type.ctype); + + if (type.ccount > 1) + typeId = m_module.defVectorType(typeId, type.ccount); + + return typeId; + } + + + uint32_t DxbcCompiler::getArrayTypeId(const DxbcArrayType& type) { + DxbcVectorType vtype; + vtype.ctype = type.ctype; + vtype.ccount = type.ccount; + + uint32_t typeId = this->getVectorTypeId(vtype); + + if (type.alength != 0) { + typeId = m_module.defArrayType(typeId, + m_module.constu32(type.alength)); + } + + return typeId; + } + + + uint32_t DxbcCompiler::getPointerTypeId(const DxbcRegisterInfo& type) { + return m_module.defPointerType( + this->getArrayTypeId(type.type), + type.sclass); + } + + + uint32_t DxbcCompiler::getSparseResultTypeId(uint32_t baseType) { + m_module.enableCapability(spv::CapabilitySparseResidency); + + uint32_t uintType = getScalarTypeId(DxbcScalarType::Uint32); + std::array typeIds = { uintType, baseType }; + return m_module.defStructType(typeIds.size(), typeIds.data()); + } + + + uint32_t DxbcCompiler::getFunctionId( + uint32_t functionNr) { + auto entry = m_subroutines.find(functionNr); + if (entry != m_subroutines.end()) + return entry->second; + + uint32_t functionId = m_module.allocateId(); + m_subroutines.insert({ functionNr, functionId }); + return functionId; + } + + + DxbcCompilerHsForkJoinPhase* DxbcCompiler::getCurrentHsForkJoinPhase() { + switch (m_hs.currPhaseType) { + case DxbcCompilerHsPhase::Fork: return &m_hs.forkPhases.at(m_hs.currPhaseId); + case DxbcCompilerHsPhase::Join: return &m_hs.joinPhases.at(m_hs.currPhaseId); + default: return nullptr; + } + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_decoder.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_decoder.cpp new file mode 100644 index 0000000000..0de7ddad17 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_decoder.cpp @@ -0,0 +1,360 @@ +#include "dxbc_decoder.h" + +namespace dxvk { + + const uint32_t* DxbcCodeSlice::ptrAt(uint32_t id) const { + if (m_ptr + id >= m_end) + throw DxvkError("DxbcCodeSlice: End of stream"); + return m_ptr + id; + } + + + uint32_t DxbcCodeSlice::at(uint32_t id) const { + if (m_ptr + id >= m_end) + throw DxvkError("DxbcCodeSlice: End of stream"); + return m_ptr[id]; + } + + + uint32_t DxbcCodeSlice::read() { + if (m_ptr >= m_end) + throw DxvkError("DxbcCodeSlice: End of stream"); + return *(m_ptr++); + } + + + DxbcCodeSlice DxbcCodeSlice::take(uint32_t n) const { + if (m_ptr + n > m_end) + throw DxvkError("DxbcCodeSlice: End of stream"); + return DxbcCodeSlice(m_ptr, m_ptr + n); + } + + + DxbcCodeSlice DxbcCodeSlice::skip(uint32_t n) const { + if (m_ptr + n > m_end) + throw DxvkError("DxbcCodeSlice: End of stream"); + return DxbcCodeSlice(m_ptr + n, m_end); + } + + + + void DxbcDecodeContext::decodeInstruction(DxbcCodeSlice& code) { + const uint32_t token0 = code.at(0); + + // Initialize the instruction structure. Some of these values + // may not get written otherwise while decoding the instruction. + m_instruction.op = static_cast(bit::extract(token0, 0, 10)); + m_instruction.opClass = DxbcInstClass::Undefined; + m_instruction.sampleControls = { 0, 0, 0 }; + m_instruction.dstCount = 0; + m_instruction.srcCount = 0; + m_instruction.immCount = 0; + m_instruction.dst = m_dstOperands.data(); + m_instruction.src = m_srcOperands.data(); + m_instruction.imm = m_immOperands.data(); + m_instruction.customDataType = DxbcCustomDataClass::Comment; + m_instruction.customDataSize = 0; + m_instruction.customData = nullptr; + + // Reset the index pointer, which may still contain + // a non-zero value from the previous iteration + m_indexId = 0; + + // Instruction length, in DWORDs. This includes the token + // itself and any other prefix that an instruction may have. + uint32_t length = 0; + + if (m_instruction.op == DxbcOpcode::CustomData) { + length = code.at(1); + this->decodeCustomData(code.take(length)); + } else { + length = bit::extract(token0, 24, 30); + this->decodeOperation(code.take(length)); + } + + // Advance the caller's slice to the next token so that + // they can make consecutive calls to decodeInstruction() + code = code.skip(length); + } + + + void DxbcDecodeContext::decodeCustomData(DxbcCodeSlice code) { + const uint32_t blockLength = code.at(1); + + if (blockLength < 2) { + Logger::err("DxbcDecodeContext: Invalid custom data block"); + return; + } + + // Custom data blocks have their own instruction class + m_instruction.op = DxbcOpcode::CustomData; + m_instruction.opClass = DxbcInstClass::CustomData; + + // We'll point into the code buffer rather than making a copy + m_instruction.customDataType = static_cast( + bit::extract(code.at(0), 11, 31)); + m_instruction.customDataSize = blockLength - 2; + m_instruction.customData = code.ptrAt(2); + } + + + void DxbcDecodeContext::decodeOperation(DxbcCodeSlice code) { + uint32_t token = code.read(); + + // Result modifiers, which are applied to common ALU ops + m_instruction.modifiers.saturate = !!bit::extract(token, 13, 13); + m_instruction.modifiers.precise = !!bit::extract(token, 19, 22); + + // Opcode controls. It will depend on the + // opcode itself which ones are valid. + m_instruction.controls = DxbcShaderOpcodeControls(token); + + // Process extended opcode tokens + while (bit::extract(token, 31, 31)) { + token = code.read(); + + const DxbcExtOpcode extOpcode + = static_cast(bit::extract(token, 0, 5)); + + switch (extOpcode) { + case DxbcExtOpcode::SampleControls: { + struct { + int u : 4; + int v : 4; + int w : 4; + } aoffimmi; + + aoffimmi.u = bit::extract(token, 9, 12); + aoffimmi.v = bit::extract(token, 13, 16); + aoffimmi.w = bit::extract(token, 17, 20); + + // Four-bit signed numbers, sign-extend them + m_instruction.sampleControls.u = aoffimmi.u; + m_instruction.sampleControls.v = aoffimmi.v; + m_instruction.sampleControls.w = aoffimmi.w; + } break; + + case DxbcExtOpcode::ResourceDim: + case DxbcExtOpcode::ResourceReturnType: + break; // part of resource description + + default: + Logger::warn(str::format( + "DxbcDecodeContext: Unhandled extended opcode: ", + extOpcode)); + } + } + + // Retrieve the instruction format in order to parse the + // operands. Doing this mostly automatically means that + // the compiler can rely on the operands being valid. + const DxbcInstFormat format = dxbcInstructionFormat(m_instruction.op); + m_instruction.opClass = format.instructionClass; + + for (uint32_t i = 0; i < format.operandCount; i++) + this->decodeOperand(code, format.operands[i]); + } + + + void DxbcDecodeContext::decodeComponentSelection(DxbcRegister& reg, uint32_t token) { + // Pick the correct component selection mode based on the + // component count. We'll simplify this here so that the + // compiler can assume that everything is a 4D vector. + reg.componentCount = static_cast(bit::extract(token, 0, 1)); + + switch (reg.componentCount) { + // No components - used for samplers etc. + case DxbcComponentCount::Component0: + reg.mask = DxbcRegMask(false, false, false, false); + reg.swizzle = DxbcRegSwizzle(0, 0, 0, 0); + break; + + // One component - used for immediates + // and a few built-in registers. + case DxbcComponentCount::Component1: + reg.mask = DxbcRegMask(true, false, false, false); + reg.swizzle = DxbcRegSwizzle(0, 0, 0, 0); + break; + + // Four components - everything else. This requires us + // to actually parse the component selection mode. + case DxbcComponentCount::Component4: { + const DxbcRegMode componentMode = + static_cast(bit::extract(token, 2, 3)); + + switch (componentMode) { + // Write mask for destination operands + case DxbcRegMode::Mask: + reg.mask = bit::extract(token, 4, 7); + reg.swizzle = DxbcRegSwizzle(0, 1, 2, 3); + break; + + // Swizzle for source operands (including resources) + case DxbcRegMode::Swizzle: + reg.mask = DxbcRegMask(true, true, true, true); + reg.swizzle = DxbcRegSwizzle( + bit::extract(token, 4, 5), + bit::extract(token, 6, 7), + bit::extract(token, 8, 9), + bit::extract(token, 10, 11)); + break; + + // Selection of one component. We can generate both a + // mask and a swizzle for this so that the compiler + // won't have to deal with this case specifically. + case DxbcRegMode::Select1: { + const uint32_t n = bit::extract(token, 4, 5); + reg.mask = DxbcRegMask(n == 0, n == 1, n == 2, n == 3); + reg.swizzle = DxbcRegSwizzle(n, n, n, n); + } break; + + default: + Logger::warn("DxbcDecodeContext: Invalid component selection mode"); + } + } break; + + default: + Logger::warn("DxbcDecodeContext: Invalid component count"); + } + } + + + void DxbcDecodeContext::decodeOperandExtensions(DxbcCodeSlice& code, DxbcRegister& reg, uint32_t token) { + while (bit::extract(token, 31, 31)) { + token = code.read(); + + // Type of the extended operand token + const DxbcOperandExt extTokenType = + static_cast(bit::extract(token, 0, 5)); + + switch (extTokenType) { + // Operand modifiers, which are used to manipulate the + // value of a source operand during the load operation + case DxbcOperandExt::OperandModifier: + reg.modifiers = bit::extract(token, 6, 13); + break; + + default: + Logger::warn(str::format( + "DxbcDecodeContext: Unhandled extended operand token: ", + extTokenType)); + } + } + } + + + void DxbcDecodeContext::decodeOperandImmediates(DxbcCodeSlice& code, DxbcRegister& reg) { + if (reg.type == DxbcOperandType::Imm32 + || reg.type == DxbcOperandType::Imm64) { + switch (reg.componentCount) { + // This is commonly used if only one vector + // component is involved in an operation + case DxbcComponentCount::Component1: { + reg.imm.u32_1 = code.read(); + } break; + + // Typical four-component vector + case DxbcComponentCount::Component4: { + reg.imm.u32_4[0] = code.read(); + reg.imm.u32_4[1] = code.read(); + reg.imm.u32_4[2] = code.read(); + reg.imm.u32_4[3] = code.read(); + } break; + + default: + Logger::warn("DxbcDecodeContext: Invalid component count for immediate operand"); + } + } + } + + + void DxbcDecodeContext::decodeOperandIndex(DxbcCodeSlice& code, DxbcRegister& reg, uint32_t token) { + reg.idxDim = bit::extract(token, 20, 21); + + for (uint32_t i = 0; i < reg.idxDim; i++) { + // An index can be encoded in various different ways + const DxbcOperandIndexRepresentation repr = + static_cast( + bit::extract(token, 22 + 3 * i, 24 + 3 * i)); + + switch (repr) { + case DxbcOperandIndexRepresentation::Imm32: + reg.idx[i].offset = static_cast(code.read()); + reg.idx[i].relReg = nullptr; + break; + + case DxbcOperandIndexRepresentation::Relative: + reg.idx[i].offset = 0; + reg.idx[i].relReg = &m_indices.at(m_indexId); + + this->decodeRegister(code, + m_indices.at(m_indexId++), + DxbcScalarType::Sint32); + break; + + case DxbcOperandIndexRepresentation::Imm32Relative: + reg.idx[i].offset = static_cast(code.read()); + reg.idx[i].relReg = &m_indices.at(m_indexId); + + this->decodeRegister(code, + m_indices.at(m_indexId++), + DxbcScalarType::Sint32); + break; + + default: + Logger::warn(str::format( + "DxbcDecodeContext: Unhandled index representation: ", + repr)); + } + } + } + + + void DxbcDecodeContext::decodeRegister(DxbcCodeSlice& code, DxbcRegister& reg, DxbcScalarType type) { + const uint32_t token = code.read(); + + reg.type = static_cast(bit::extract(token, 12, 19)); + reg.dataType = type; + reg.modifiers = 0; + reg.idxDim = 0; + + for (uint32_t i = 0; i < DxbcMaxRegIndexDim; i++) { + reg.idx[i].relReg = nullptr; + reg.idx[i].offset = 0; + } + + this->decodeComponentSelection(reg, token); + this->decodeOperandExtensions(code, reg, token); + this->decodeOperandImmediates(code, reg); + this->decodeOperandIndex(code, reg, token); + } + + + void DxbcDecodeContext::decodeImm32(DxbcCodeSlice& code, DxbcImmediate& imm, DxbcScalarType type) { + imm.u32 = code.read(); + } + + + void DxbcDecodeContext::decodeOperand(DxbcCodeSlice& code, const DxbcInstOperandFormat& format) { + switch (format.kind) { + case DxbcOperandKind::DstReg: { + const uint32_t operandId = m_instruction.dstCount++; + this->decodeRegister(code, m_dstOperands.at(operandId), format.type); + } break; + + case DxbcOperandKind::SrcReg: { + const uint32_t operandId = m_instruction.srcCount++; + this->decodeRegister(code, m_srcOperands.at(operandId), format.type); + } break; + + case DxbcOperandKind::Imm32: { + const uint32_t operandId = m_instruction.immCount++; + this->decodeImm32(code, m_immOperands.at(operandId), format.type); + } break; + + default: + throw DxvkError("DxbcDecodeContext: Invalid operand format"); + } + } + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_defs.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_defs.cpp new file mode 100644 index 0000000000..0d193ada97 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_defs.cpp @@ -0,0 +1,1255 @@ +#include "dxbc_defs.h" + +namespace dxvk { + + const std::array g_instructionFormats = {{ + /* Add */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* And */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Break */ + { 0, DxbcInstClass::ControlFlow }, + /* Breakc */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Call */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Callc */ + { 2, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Case */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Continue */ + { 0, DxbcInstClass::ControlFlow }, + /* Continuec */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Cut */ + { 0, DxbcInstClass::GeometryEmit }, + /* Default */ + { 0, DxbcInstClass::ControlFlow }, + /* DerivRtx */ + { 2, DxbcInstClass::VectorDeriv, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* DerivRty */ + { 2, DxbcInstClass::VectorDeriv, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Discard */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Div */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Dp2 */ + { 3, DxbcInstClass::VectorDot, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Dp3 */ + { 3, DxbcInstClass::VectorDot, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Dp4 */ + { 3, DxbcInstClass::VectorDot, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Else */ + { 0, DxbcInstClass::ControlFlow }, + /* Emit */ + { 0, DxbcInstClass::GeometryEmit }, + /* EmitThenCut */ + { 0, DxbcInstClass::GeometryEmit }, + /* EndIf */ + { 0, DxbcInstClass::ControlFlow }, + /* EndLoop */ + { 0, DxbcInstClass::ControlFlow }, + /* EndSwitch */ + { 0, DxbcInstClass::ControlFlow }, + /* Eq */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Exp */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Frc */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* FtoI */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* FtoU */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Ge */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* IAdd */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* If */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* IEq */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* IGe */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* ILt */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* IMad */ + { 4, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* IMax */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* IMin */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* IMul */ + { 4, DxbcInstClass::VectorImul, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* INe */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* INeg */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* IShl */ + { 3, DxbcInstClass::VectorShift, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* IShr */ + { 3, DxbcInstClass::VectorShift, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ItoF */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* Label */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + } }, + /* Ld */ + { 3, DxbcInstClass::TextureFetch, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* LdMs */ + { 4, DxbcInstClass::TextureFetch, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* Log */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Loop */ + { 0, DxbcInstClass::ControlFlow }, + /* Lt */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Mad */ + { 4, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Min */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Max */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* CustomData */ + { 0, DxbcInstClass::CustomData }, + /* Mov */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Movc */ + { 4, DxbcInstClass::VectorCmov, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Mul */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Ne */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Nop */ + { 0, DxbcInstClass::NoOperation }, + /* Not */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Or */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ResInfo */ + { 3, DxbcInstClass::TextureQuery, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Ret */ + { 0, DxbcInstClass::ControlFlow }, + /* Retc */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* RoundNe */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* RoundNi */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* RoundPi */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* RoundZ */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Rsq */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Sample */ + { 4, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleC */ + { 5, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleClz */ + { 5, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleL */ + { 5, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleD */ + { 6, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleB */ + { 5, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Sqrt */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Switch */ + { 1, DxbcInstClass::ControlFlow, { + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* SinCos */ + { 3, DxbcInstClass::VectorSinCos, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* UDiv */ + { 4, DxbcInstClass::VectorIdiv, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ULt */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UGe */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UMul */ + { 4, DxbcInstClass::VectorImul, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UMad */ + { 4, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UMax */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UMin */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UShr */ + { 3, DxbcInstClass::VectorShift, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UtoF */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Xor */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* DclResource */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclConstantBuffer */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + } }, + /* DclSampler */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + } }, + /* DclIndexRange */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclGsOutputPrimitiveTopology */ + { 0, DxbcInstClass::Declaration }, + /* DclGsInputPrimitive */ + { 0, DxbcInstClass::Declaration }, + /* DclMaxOutputVertexCount */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclInput */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + } }, + /* DclInputSgv */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclInputSiv */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclInputPs */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + } }, + /* DclInputPsSgv */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclInputPsSiv */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclOutput */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + } }, + /* DclOutputSgv */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclOutputSiv */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclTemps */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclIndexableTemp */ + { 3, DxbcInstClass::Declaration, { + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclGlobalFlags */ + { 0, DxbcInstClass::Declaration }, + /* Reserved0 */ + { 0, DxbcInstClass::Undefined }, + /* Lod */ + { 4, DxbcInstClass::TextureQueryLod, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Gather4 */ + { 4, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SamplePos */ + { 3, DxbcInstClass::TextureQueryMsPos, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* SampleInfo */ + { 2, DxbcInstClass::TextureQueryMs, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Reserved1 */ + { }, + /* HsDecls */ + { 0, DxbcInstClass::HullShaderPhase }, + /* HsControlPointPhase */ + { 0, DxbcInstClass::HullShaderPhase }, + /* HsForkPhase */ + { 0, DxbcInstClass::HullShaderPhase }, + /* HsJoinPhase */ + { 0, DxbcInstClass::HullShaderPhase }, + /* EmitStream */ + { 1, DxbcInstClass::GeometryEmit, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + } }, + /* CutStream */ + { 1, DxbcInstClass::GeometryEmit, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + } }, + /* EmitThenCutStream */ + { 1, DxbcInstClass::GeometryEmit, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + } }, + /* InterfaceCall */ + { }, + /* BufInfo */ + { 2, DxbcInstClass::BufferQuery, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* DerivRtxCoarse */ + { 2, DxbcInstClass::VectorDeriv, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* DerivRtxFine */ + { 2, DxbcInstClass::VectorDeriv, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* DerivRtyCoarse */ + { 2, DxbcInstClass::VectorDeriv, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* DerivRtyFine */ + { 2, DxbcInstClass::VectorDeriv, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Gather4C */ + { 5, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Gather4Po */ + { 5, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Gather4PoC */ + { 6, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Rcp */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* F32toF16 */ + { 2, DxbcInstClass::ConvertFloat16, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* F16toF32 */ + { 2, DxbcInstClass::ConvertFloat16, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UAddc */ + { }, + /* USubb */ + { }, + /* CountBits */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* FirstBitHi */ + { 2, DxbcInstClass::BitScan, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* FirstBitLo */ + { 2, DxbcInstClass::BitScan, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* FirstBitShi */ + { 2, DxbcInstClass::BitScan, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* UBfe */ + { 4, DxbcInstClass::BitExtract, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* IBfe */ + { 4, DxbcInstClass::BitExtract, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* Bfi */ + { 5, DxbcInstClass::BitInsert, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* BfRev */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Swapc */ + { 5, DxbcInstClass::VectorCmov, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* DclStream */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + } }, + /* DclFunctionBody */ + { }, + /* DclFunctionTable */ + { }, + /* DclInterface */ + { }, + /* DclInputControlPointCount */ + { 0, DxbcInstClass::Declaration }, + /* DclOutputControlPointCount */ + { 0, DxbcInstClass::Declaration }, + /* DclTessDomain */ + { 0, DxbcInstClass::Declaration }, + /* DclTessPartitioning */ + { 0, DxbcInstClass::Declaration }, + /* DclTessOutputPrimitive */ + { 0, DxbcInstClass::Declaration }, + /* DclHsMaxTessFactor */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::Imm32, DxbcScalarType::Float32 }, + } }, + /* DclHsForkPhaseInstanceCount */ + { 1, DxbcInstClass::HullShaderInstCnt, { + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclHsJoinPhaseInstanceCount */ + { 1, DxbcInstClass::HullShaderInstCnt, { + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclThreadGroup */ + { 3, DxbcInstClass::Declaration, { + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclUavTyped */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclUavRaw */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + } }, + /* DclUavStructured */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclThreadGroupSharedMemoryRaw */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclThreadGroupSharedMemoryStructured */ + { 3, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* DclResourceRaw */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + } }, + /* DclResourceStructured */ + { 2, DxbcInstClass::Declaration, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* LdUavTyped */ + { 3, DxbcInstClass::TypedUavLoad, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* StoreUavTyped */ + { 3, DxbcInstClass::TypedUavStore, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* LdRaw */ + { 3, DxbcInstClass::BufferLoad, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* StoreRaw */ + { 3, DxbcInstClass::BufferStore, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* LdStructured */ + { 4, DxbcInstClass::BufferLoad, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* StoreStructured */ + { 4, DxbcInstClass::BufferStore, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* AtomicAnd */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* AtomicOr */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* AtomicXor */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* AtomicCmpStore */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* AtomicIAdd */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* AtomicIMax */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* AtomicIMin */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* AtomicUMax */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* AtomicUMin */ + { 3, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicAlloc */ + { 2, DxbcInstClass::AtomicCounter, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicConsume */ + { 2, DxbcInstClass::AtomicCounter, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicIAdd */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicAnd */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicOr */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicXor */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicExch */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicCmpExch */ + { 5, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicIMax */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* ImmAtomicIMin */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* ImmAtomicUMax */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ImmAtomicUMin */ + { 4, DxbcInstClass::Atomic, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* Sync */ + { 0, DxbcInstClass::Barrier }, + /* DAdd */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DMax */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DMin */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DMul */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DEq */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DGe */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DLt */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DNe */ + { 3, DxbcInstClass::VectorCmp, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DMov */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DMovc */ + { 4, DxbcInstClass::VectorCmov, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DtoF */ + { 2, DxbcInstClass::ConvertFloat64, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* FtoD */ + { 2, DxbcInstClass::ConvertFloat64, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* EvalSnapped */ + { 3, DxbcInstClass::Interpolate, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* EvalSampleIndex */ + { 3, DxbcInstClass::Interpolate, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* EvalCentroid */ + { 2, DxbcInstClass::Interpolate, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* DclGsInstanceCount */ + { 1, DxbcInstClass::Declaration, { + { DxbcOperandKind::Imm32, DxbcScalarType::Uint32 }, + } }, + /* Abort */ + { }, + /* DebugBreak */ + { }, + /* ReservedBegin11_1 */ + { }, + /* DDiv */ + { 3, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DFma */ + { 4, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DRcp */ + { 2, DxbcInstClass::VectorAlu, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* Msad */ + { 4, DxbcInstClass::VectorMsad, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* DtoI */ + { 2, DxbcInstClass::ConvertFloat64, { + { DxbcOperandKind::DstReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* DtoU */ + { 2, DxbcInstClass::ConvertFloat64, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float64 }, + } }, + /* ItoD */ + { 2, DxbcInstClass::ConvertFloat64, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* UtoD */ + { 2, DxbcInstClass::ConvertFloat64, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float64 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* ReservedBegin11_2 */ + { }, + /* Gather4S */ + { 5, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Gather4CS */ + { 6, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Gather4PoS */ + { 6, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* Gather4PoCS */ + { 7, DxbcInstClass::TextureGather, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* LdS */ + { 4, DxbcInstClass::TextureFetch, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* LdMsS */ + { 5, DxbcInstClass::TextureFetch, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + } }, + /* LdUavTypedS */ + { 4, DxbcInstClass::TypedUavLoad, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* LdRawS */ + { 4, DxbcInstClass::BufferLoad, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* LdStructuredS */ + { 5, DxbcInstClass::BufferLoad, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Sint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + /* SampleLS */ + { 6, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleClzS */ + { 6, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleClampS */ + { 6, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleBClampS */ + { 7, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleDClampS */ + { 8, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* SampleCClampS */ + { 7, DxbcInstClass::TextureSample, { + { DxbcOperandKind::DstReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Float32 }, + } }, + /* CheckAccessFullyMapped */ + { 2, DxbcInstClass::SparseCheckAccess, { + { DxbcOperandKind::DstReg, DxbcScalarType::Uint32 }, + { DxbcOperandKind::SrcReg, DxbcScalarType::Uint32 }, + } }, + }}; + + + DxbcInstFormat dxbcInstructionFormat(DxbcOpcode opcode) { + const uint32_t idx = static_cast(opcode); + + return (idx < g_instructionFormats.size()) + ? g_instructionFormats.at(idx) + : DxbcInstFormat(); + } + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_header.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_header.cpp new file mode 100644 index 0000000000..9b5f698957 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_header.cpp @@ -0,0 +1,30 @@ +#include "dxbc_header.h" + +namespace dxvk { + + DxbcHeader::DxbcHeader(DxbcReader& reader) { + // FourCC at the start of the file, must be 'DXBC' + DxbcTag fourcc = reader.readTag(); + + if (fourcc != "DXBC") + throw DxvkError("DxbcHeader::DxbcHeader: Invalid fourcc, expected 'DXBC'"); + + // Stuff we don't actually need to store + reader.skip(4 * sizeof(uint32_t)); // Check sum + reader.skip(1 * sizeof(uint32_t)); // Constant 1 + reader.skip(1 * sizeof(uint32_t)); // Bytecode length + + // Number of chunks in the file + uint32_t chunkCount = reader.readu32(); + + // Chunk offsets are stored immediately after + for (uint32_t i = 0; i < chunkCount; i++) + m_chunkOffsets.push_back(reader.readu32()); + } + + + DxbcHeader::~DxbcHeader() { + + } + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_module.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_module.cpp new file mode 100644 index 0000000000..573d503b04 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_module.cpp @@ -0,0 +1,120 @@ +#include "dxbc_analysis.h" +#include "dxbc_compiler.h" +#include "dxbc_module.h" + +namespace dxvk { + + DxbcModule::DxbcModule(DxbcReader& reader) + : m_header(reader) { + for (uint32_t i = 0; i < m_header.numChunks(); i++) { + + // The chunk tag is stored at the beginning of each chunk + auto chunkReader = reader.clone(m_header.chunkOffset(i)); + auto tag = chunkReader.readTag(); + + // The chunk size follows right after the four-character + // code. This does not include the eight bytes that are + // consumed by the FourCC and chunk length entry. + auto chunkLength = chunkReader.readu32(); + + chunkReader = chunkReader.clone(8); + chunkReader = chunkReader.resize(chunkLength); + + if ((tag == "SHDR") || (tag == "SHEX")) + m_shexChunk = new DxbcShex(chunkReader); + + if ((tag == "ISGN") || (tag == "ISG1")) + m_isgnChunk = new DxbcIsgn(chunkReader, tag); + + if ((tag == "OSGN") || (tag == "OSG5") || (tag == "OSG1")) + m_osgnChunk = new DxbcIsgn(chunkReader, tag); + + if ((tag == "PCSG") || (tag == "PSG1")) + m_psgnChunk = new DxbcIsgn(chunkReader, tag); + } + } + + + DxbcModule::~DxbcModule() { + + } + + + SpirvCodeBuffer DxbcModule::compile( + const DxbcModuleInfo& moduleInfo, + const std::string& fileName) { + if (m_shexChunk == nullptr) + throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk"); + + DxbcAnalysisInfo analysisInfo; + + DxbcAnalyzer analyzer(moduleInfo, + m_shexChunk->programInfo(), + m_isgnChunk, m_osgnChunk, + m_psgnChunk, analysisInfo); + + this->runAnalyzer(analyzer, m_shexChunk->slice()); + + m_bindings = std::make_optional(analysisInfo.bindings); + + DxbcCompiler compiler( + fileName, moduleInfo, + m_shexChunk->programInfo(), + m_isgnChunk, m_osgnChunk, + m_psgnChunk, analysisInfo); + + this->runCompiler(compiler, m_shexChunk->slice()); + + m_icb = compiler.getIcbData(); + + return compiler.finalize(); + } + + + SpirvCodeBuffer DxbcModule::compilePassthroughShader( + const DxbcModuleInfo& moduleInfo, + const std::string& fileName) const { + if (m_shexChunk == nullptr) + throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk"); + + DxbcAnalysisInfo analysisInfo; + + DxbcCompiler compiler( + fileName, moduleInfo, + DxbcProgramType::GeometryShader, + m_osgnChunk, m_osgnChunk, + m_psgnChunk, analysisInfo); + + compiler.processXfbPassthrough(); + return compiler.finalize(); + } + + + void DxbcModule::runAnalyzer( + DxbcAnalyzer& analyzer, + DxbcCodeSlice slice) const { + DxbcDecodeContext decoder; + + while (!slice.atEnd()) { + decoder.decodeInstruction(slice); + + analyzer.processInstruction( + decoder.getInstruction()); + } + } + + + void DxbcModule::runCompiler( + DxbcCompiler& compiler, + DxbcCodeSlice slice) const { + DxbcDecodeContext decoder; + + while (!slice.atEnd()) { + decoder.decodeInstruction(slice); + + compiler.processInstruction( + decoder.getInstruction()); + } + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_names.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_names.cpp new file mode 100644 index 0000000000..c6a00eccca --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_names.cpp @@ -0,0 +1,445 @@ +#include "dxbc_names.h" + +namespace dxvk { + + std::ostream& operator << (std::ostream& os, DxbcOpcode e) { + switch (e) { + ENUM_NAME(DxbcOpcode::Add); + ENUM_NAME(DxbcOpcode::And); + ENUM_NAME(DxbcOpcode::Break); + ENUM_NAME(DxbcOpcode::Breakc); + ENUM_NAME(DxbcOpcode::Call); + ENUM_NAME(DxbcOpcode::Callc); + ENUM_NAME(DxbcOpcode::Case); + ENUM_NAME(DxbcOpcode::Continue); + ENUM_NAME(DxbcOpcode::Continuec); + ENUM_NAME(DxbcOpcode::Cut); + ENUM_NAME(DxbcOpcode::Default); + ENUM_NAME(DxbcOpcode::DerivRtx); + ENUM_NAME(DxbcOpcode::DerivRty); + ENUM_NAME(DxbcOpcode::Discard); + ENUM_NAME(DxbcOpcode::Div); + ENUM_NAME(DxbcOpcode::Dp2); + ENUM_NAME(DxbcOpcode::Dp3); + ENUM_NAME(DxbcOpcode::Dp4); + ENUM_NAME(DxbcOpcode::Else); + ENUM_NAME(DxbcOpcode::Emit); + ENUM_NAME(DxbcOpcode::EmitThenCut); + ENUM_NAME(DxbcOpcode::EndIf); + ENUM_NAME(DxbcOpcode::EndLoop); + ENUM_NAME(DxbcOpcode::EndSwitch); + ENUM_NAME(DxbcOpcode::Eq); + ENUM_NAME(DxbcOpcode::Exp); + ENUM_NAME(DxbcOpcode::Frc); + ENUM_NAME(DxbcOpcode::FtoI); + ENUM_NAME(DxbcOpcode::FtoU); + ENUM_NAME(DxbcOpcode::Ge); + ENUM_NAME(DxbcOpcode::IAdd); + ENUM_NAME(DxbcOpcode::If); + ENUM_NAME(DxbcOpcode::IEq); + ENUM_NAME(DxbcOpcode::IGe); + ENUM_NAME(DxbcOpcode::ILt); + ENUM_NAME(DxbcOpcode::IMad); + ENUM_NAME(DxbcOpcode::IMax); + ENUM_NAME(DxbcOpcode::IMin); + ENUM_NAME(DxbcOpcode::IMul); + ENUM_NAME(DxbcOpcode::INe); + ENUM_NAME(DxbcOpcode::INeg); + ENUM_NAME(DxbcOpcode::IShl); + ENUM_NAME(DxbcOpcode::IShr); + ENUM_NAME(DxbcOpcode::ItoF); + ENUM_NAME(DxbcOpcode::Label); + ENUM_NAME(DxbcOpcode::Ld); + ENUM_NAME(DxbcOpcode::LdMs); + ENUM_NAME(DxbcOpcode::Log); + ENUM_NAME(DxbcOpcode::Loop); + ENUM_NAME(DxbcOpcode::Lt); + ENUM_NAME(DxbcOpcode::Mad); + ENUM_NAME(DxbcOpcode::Min); + ENUM_NAME(DxbcOpcode::Max); + ENUM_NAME(DxbcOpcode::CustomData); + ENUM_NAME(DxbcOpcode::Mov); + ENUM_NAME(DxbcOpcode::Movc); + ENUM_NAME(DxbcOpcode::Mul); + ENUM_NAME(DxbcOpcode::Ne); + ENUM_NAME(DxbcOpcode::Nop); + ENUM_NAME(DxbcOpcode::Not); + ENUM_NAME(DxbcOpcode::Or); + ENUM_NAME(DxbcOpcode::ResInfo); + ENUM_NAME(DxbcOpcode::Ret); + ENUM_NAME(DxbcOpcode::Retc); + ENUM_NAME(DxbcOpcode::RoundNe); + ENUM_NAME(DxbcOpcode::RoundNi); + ENUM_NAME(DxbcOpcode::RoundPi); + ENUM_NAME(DxbcOpcode::RoundZ); + ENUM_NAME(DxbcOpcode::Rsq); + ENUM_NAME(DxbcOpcode::Sample); + ENUM_NAME(DxbcOpcode::SampleC); + ENUM_NAME(DxbcOpcode::SampleClz); + ENUM_NAME(DxbcOpcode::SampleL); + ENUM_NAME(DxbcOpcode::SampleD); + ENUM_NAME(DxbcOpcode::SampleB); + ENUM_NAME(DxbcOpcode::Sqrt); + ENUM_NAME(DxbcOpcode::Switch); + ENUM_NAME(DxbcOpcode::SinCos); + ENUM_NAME(DxbcOpcode::UDiv); + ENUM_NAME(DxbcOpcode::ULt); + ENUM_NAME(DxbcOpcode::UGe); + ENUM_NAME(DxbcOpcode::UMul); + ENUM_NAME(DxbcOpcode::UMad); + ENUM_NAME(DxbcOpcode::UMax); + ENUM_NAME(DxbcOpcode::UMin); + ENUM_NAME(DxbcOpcode::UShr); + ENUM_NAME(DxbcOpcode::UtoF); + ENUM_NAME(DxbcOpcode::Xor); + ENUM_NAME(DxbcOpcode::DclResource); + ENUM_NAME(DxbcOpcode::DclConstantBuffer); + ENUM_NAME(DxbcOpcode::DclSampler); + ENUM_NAME(DxbcOpcode::DclIndexRange); + ENUM_NAME(DxbcOpcode::DclGsOutputPrimitiveTopology); + ENUM_NAME(DxbcOpcode::DclGsInputPrimitive); + ENUM_NAME(DxbcOpcode::DclMaxOutputVertexCount); + ENUM_NAME(DxbcOpcode::DclInput); + ENUM_NAME(DxbcOpcode::DclInputSgv); + ENUM_NAME(DxbcOpcode::DclInputSiv); + ENUM_NAME(DxbcOpcode::DclInputPs); + ENUM_NAME(DxbcOpcode::DclInputPsSgv); + ENUM_NAME(DxbcOpcode::DclInputPsSiv); + ENUM_NAME(DxbcOpcode::DclOutput); + ENUM_NAME(DxbcOpcode::DclOutputSgv); + ENUM_NAME(DxbcOpcode::DclOutputSiv); + ENUM_NAME(DxbcOpcode::DclTemps); + ENUM_NAME(DxbcOpcode::DclIndexableTemp); + ENUM_NAME(DxbcOpcode::DclGlobalFlags); + ENUM_NAME(DxbcOpcode::Reserved0); + ENUM_NAME(DxbcOpcode::Lod); + ENUM_NAME(DxbcOpcode::Gather4); + ENUM_NAME(DxbcOpcode::SamplePos); + ENUM_NAME(DxbcOpcode::SampleInfo); + ENUM_NAME(DxbcOpcode::Reserved1); + ENUM_NAME(DxbcOpcode::HsDecls); + ENUM_NAME(DxbcOpcode::HsControlPointPhase); + ENUM_NAME(DxbcOpcode::HsForkPhase); + ENUM_NAME(DxbcOpcode::HsJoinPhase); + ENUM_NAME(DxbcOpcode::EmitStream); + ENUM_NAME(DxbcOpcode::CutStream); + ENUM_NAME(DxbcOpcode::EmitThenCutStream); + ENUM_NAME(DxbcOpcode::InterfaceCall); + ENUM_NAME(DxbcOpcode::BufInfo); + ENUM_NAME(DxbcOpcode::DerivRtxCoarse); + ENUM_NAME(DxbcOpcode::DerivRtxFine); + ENUM_NAME(DxbcOpcode::DerivRtyCoarse); + ENUM_NAME(DxbcOpcode::DerivRtyFine); + ENUM_NAME(DxbcOpcode::Gather4C); + ENUM_NAME(DxbcOpcode::Gather4Po); + ENUM_NAME(DxbcOpcode::Gather4PoC); + ENUM_NAME(DxbcOpcode::Rcp); + ENUM_NAME(DxbcOpcode::F32toF16); + ENUM_NAME(DxbcOpcode::F16toF32); + ENUM_NAME(DxbcOpcode::UAddc); + ENUM_NAME(DxbcOpcode::USubb); + ENUM_NAME(DxbcOpcode::CountBits); + ENUM_NAME(DxbcOpcode::FirstBitHi); + ENUM_NAME(DxbcOpcode::FirstBitLo); + ENUM_NAME(DxbcOpcode::FirstBitShi); + ENUM_NAME(DxbcOpcode::UBfe); + ENUM_NAME(DxbcOpcode::IBfe); + ENUM_NAME(DxbcOpcode::Bfi); + ENUM_NAME(DxbcOpcode::BfRev); + ENUM_NAME(DxbcOpcode::Swapc); + ENUM_NAME(DxbcOpcode::DclStream); + ENUM_NAME(DxbcOpcode::DclFunctionBody); + ENUM_NAME(DxbcOpcode::DclFunctionTable); + ENUM_NAME(DxbcOpcode::DclInterface); + ENUM_NAME(DxbcOpcode::DclInputControlPointCount); + ENUM_NAME(DxbcOpcode::DclOutputControlPointCount); + ENUM_NAME(DxbcOpcode::DclTessDomain); + ENUM_NAME(DxbcOpcode::DclTessPartitioning); + ENUM_NAME(DxbcOpcode::DclTessOutputPrimitive); + ENUM_NAME(DxbcOpcode::DclHsMaxTessFactor); + ENUM_NAME(DxbcOpcode::DclHsForkPhaseInstanceCount); + ENUM_NAME(DxbcOpcode::DclHsJoinPhaseInstanceCount); + ENUM_NAME(DxbcOpcode::DclThreadGroup); + ENUM_NAME(DxbcOpcode::DclUavTyped); + ENUM_NAME(DxbcOpcode::DclUavRaw); + ENUM_NAME(DxbcOpcode::DclUavStructured); + ENUM_NAME(DxbcOpcode::DclThreadGroupSharedMemoryRaw); + ENUM_NAME(DxbcOpcode::DclThreadGroupSharedMemoryStructured); + ENUM_NAME(DxbcOpcode::DclResourceRaw); + ENUM_NAME(DxbcOpcode::DclResourceStructured); + ENUM_NAME(DxbcOpcode::LdUavTyped); + ENUM_NAME(DxbcOpcode::StoreUavTyped); + ENUM_NAME(DxbcOpcode::LdRaw); + ENUM_NAME(DxbcOpcode::StoreRaw); + ENUM_NAME(DxbcOpcode::LdStructured); + ENUM_NAME(DxbcOpcode::StoreStructured); + ENUM_NAME(DxbcOpcode::AtomicAnd); + ENUM_NAME(DxbcOpcode::AtomicOr); + ENUM_NAME(DxbcOpcode::AtomicXor); + ENUM_NAME(DxbcOpcode::AtomicCmpStore); + ENUM_NAME(DxbcOpcode::AtomicIAdd); + ENUM_NAME(DxbcOpcode::AtomicIMax); + ENUM_NAME(DxbcOpcode::AtomicIMin); + ENUM_NAME(DxbcOpcode::AtomicUMax); + ENUM_NAME(DxbcOpcode::AtomicUMin); + ENUM_NAME(DxbcOpcode::ImmAtomicAlloc); + ENUM_NAME(DxbcOpcode::ImmAtomicConsume); + ENUM_NAME(DxbcOpcode::ImmAtomicIAdd); + ENUM_NAME(DxbcOpcode::ImmAtomicAnd); + ENUM_NAME(DxbcOpcode::ImmAtomicOr); + ENUM_NAME(DxbcOpcode::ImmAtomicXor); + ENUM_NAME(DxbcOpcode::ImmAtomicExch); + ENUM_NAME(DxbcOpcode::ImmAtomicCmpExch); + ENUM_NAME(DxbcOpcode::ImmAtomicIMax); + ENUM_NAME(DxbcOpcode::ImmAtomicIMin); + ENUM_NAME(DxbcOpcode::ImmAtomicUMax); + ENUM_NAME(DxbcOpcode::ImmAtomicUMin); + ENUM_NAME(DxbcOpcode::Sync); + ENUM_NAME(DxbcOpcode::DAdd); + ENUM_NAME(DxbcOpcode::DMax); + ENUM_NAME(DxbcOpcode::DMin); + ENUM_NAME(DxbcOpcode::DMul); + ENUM_NAME(DxbcOpcode::DEq); + ENUM_NAME(DxbcOpcode::DGe); + ENUM_NAME(DxbcOpcode::DLt); + ENUM_NAME(DxbcOpcode::DNe); + ENUM_NAME(DxbcOpcode::DMov); + ENUM_NAME(DxbcOpcode::DMovc); + ENUM_NAME(DxbcOpcode::DtoF); + ENUM_NAME(DxbcOpcode::FtoD); + ENUM_NAME(DxbcOpcode::EvalSnapped); + ENUM_NAME(DxbcOpcode::EvalSampleIndex); + ENUM_NAME(DxbcOpcode::EvalCentroid); + ENUM_NAME(DxbcOpcode::DclGsInstanceCount); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcExtOpcode e) { + switch (e) { + ENUM_NAME(DxbcExtOpcode::Empty); + ENUM_NAME(DxbcExtOpcode::SampleControls); + ENUM_NAME(DxbcExtOpcode::ResourceDim); + ENUM_NAME(DxbcExtOpcode::ResourceReturnType); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcOperandType e) { + switch (e) { + ENUM_NAME(DxbcOperandType::Temp); + ENUM_NAME(DxbcOperandType::Input); + ENUM_NAME(DxbcOperandType::Output); + ENUM_NAME(DxbcOperandType::IndexableTemp); + ENUM_NAME(DxbcOperandType::Imm32); + ENUM_NAME(DxbcOperandType::Imm64); + ENUM_NAME(DxbcOperandType::Sampler); + ENUM_NAME(DxbcOperandType::Resource); + ENUM_NAME(DxbcOperandType::ConstantBuffer); + ENUM_NAME(DxbcOperandType::ImmediateConstantBuffer); + ENUM_NAME(DxbcOperandType::Label); + ENUM_NAME(DxbcOperandType::InputPrimitiveId); + ENUM_NAME(DxbcOperandType::OutputDepth); + ENUM_NAME(DxbcOperandType::Null); + ENUM_NAME(DxbcOperandType::Rasterizer); + ENUM_NAME(DxbcOperandType::OutputCoverageMask); + ENUM_NAME(DxbcOperandType::Stream); + ENUM_NAME(DxbcOperandType::FunctionBody); + ENUM_NAME(DxbcOperandType::FunctionTable); + ENUM_NAME(DxbcOperandType::Interface); + ENUM_NAME(DxbcOperandType::FunctionInput); + ENUM_NAME(DxbcOperandType::FunctionOutput); + ENUM_NAME(DxbcOperandType::OutputControlPointId); + ENUM_NAME(DxbcOperandType::InputForkInstanceId); + ENUM_NAME(DxbcOperandType::InputJoinInstanceId); + ENUM_NAME(DxbcOperandType::InputControlPoint); + ENUM_NAME(DxbcOperandType::OutputControlPoint); + ENUM_NAME(DxbcOperandType::InputPatchConstant); + ENUM_NAME(DxbcOperandType::InputDomainPoint); + ENUM_NAME(DxbcOperandType::ThisPointer); + ENUM_NAME(DxbcOperandType::UnorderedAccessView); + ENUM_NAME(DxbcOperandType::ThreadGroupSharedMemory); + ENUM_NAME(DxbcOperandType::InputThreadId); + ENUM_NAME(DxbcOperandType::InputThreadGroupId); + ENUM_NAME(DxbcOperandType::InputThreadIdInGroup); + ENUM_NAME(DxbcOperandType::InputCoverageMask); + ENUM_NAME(DxbcOperandType::InputThreadIndexInGroup); + ENUM_NAME(DxbcOperandType::InputGsInstanceId); + ENUM_NAME(DxbcOperandType::OutputDepthGe); + ENUM_NAME(DxbcOperandType::OutputDepthLe); + ENUM_NAME(DxbcOperandType::CycleCounter); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, dxvk::DxbcOperandExt e) { + switch (e) { + ENUM_NAME(DxbcOperandExt::OperandModifier); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcComponentCount e) { + switch (e) { + ENUM_NAME(DxbcComponentCount::Component0); + ENUM_NAME(DxbcComponentCount::Component1); + ENUM_NAME(DxbcComponentCount::Component4); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcRegMode e) { + switch (e) { + ENUM_NAME(DxbcRegMode::Mask); + ENUM_NAME(DxbcRegMode::Swizzle); + ENUM_NAME(DxbcRegMode::Select1); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcOperandIndexRepresentation e) { + switch (e) { + ENUM_NAME(DxbcOperandIndexRepresentation::Imm32); + ENUM_NAME(DxbcOperandIndexRepresentation::Imm64); + ENUM_NAME(DxbcOperandIndexRepresentation::Relative); + ENUM_NAME(DxbcOperandIndexRepresentation::Imm32Relative); + ENUM_NAME(DxbcOperandIndexRepresentation::Imm64Relative); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcResourceDim e) { + switch (e) { + ENUM_NAME(DxbcResourceDim::Unknown); + ENUM_NAME(DxbcResourceDim::Buffer); + ENUM_NAME(DxbcResourceDim::Texture1D); + ENUM_NAME(DxbcResourceDim::Texture2D); + ENUM_NAME(DxbcResourceDim::Texture2DMs); + ENUM_NAME(DxbcResourceDim::Texture3D); + ENUM_NAME(DxbcResourceDim::TextureCube); + ENUM_NAME(DxbcResourceDim::Texture1DArr); + ENUM_NAME(DxbcResourceDim::Texture2DArr); + ENUM_NAME(DxbcResourceDim::Texture2DMsArr); + ENUM_NAME(DxbcResourceDim::TextureCubeArr); + ENUM_NAME(DxbcResourceDim::RawBuffer); + ENUM_NAME(DxbcResourceDim::StructuredBuffer); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcResourceReturnType e) { + switch (e) { + ENUM_NAME(DxbcResourceReturnType::Unorm); + ENUM_NAME(DxbcResourceReturnType::Snorm); + ENUM_NAME(DxbcResourceReturnType::Sint); + ENUM_NAME(DxbcResourceReturnType::Uint); + ENUM_NAME(DxbcResourceReturnType::Float); + ENUM_NAME(DxbcResourceReturnType::Mixed); + ENUM_NAME(DxbcResourceReturnType::Double); + ENUM_NAME(DxbcResourceReturnType::Continued); + ENUM_NAME(DxbcResourceReturnType::Unused); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcRegisterComponentType e) { + switch (e) { + ENUM_NAME(DxbcRegisterComponentType::Unknown); + ENUM_NAME(DxbcRegisterComponentType::Uint32); + ENUM_NAME(DxbcRegisterComponentType::Sint32); + ENUM_NAME(DxbcRegisterComponentType::Float32); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcInstructionReturnType e) { + switch (e) { + ENUM_NAME(DxbcInstructionReturnType::Float); + ENUM_NAME(DxbcInstructionReturnType::Uint); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, DxbcSystemValue e) { + switch (e) { + ENUM_NAME(DxbcSystemValue::None); + ENUM_NAME(DxbcSystemValue::Position); + ENUM_NAME(DxbcSystemValue::ClipDistance); + ENUM_NAME(DxbcSystemValue::CullDistance); + ENUM_NAME(DxbcSystemValue::RenderTargetId); + ENUM_NAME(DxbcSystemValue::ViewportId); + ENUM_NAME(DxbcSystemValue::VertexId); + ENUM_NAME(DxbcSystemValue::PrimitiveId); + ENUM_NAME(DxbcSystemValue::InstanceId); + ENUM_NAME(DxbcSystemValue::IsFrontFace); + ENUM_NAME(DxbcSystemValue::SampleIndex); + ENUM_NAME(DxbcSystemValue::FinalQuadUeq0EdgeTessFactor); + ENUM_NAME(DxbcSystemValue::FinalQuadVeq0EdgeTessFactor); + ENUM_NAME(DxbcSystemValue::FinalQuadUeq1EdgeTessFactor); + ENUM_NAME(DxbcSystemValue::FinalQuadVeq1EdgeTessFactor); + ENUM_NAME(DxbcSystemValue::FinalQuadUInsideTessFactor); + ENUM_NAME(DxbcSystemValue::FinalQuadVInsideTessFactor); + ENUM_NAME(DxbcSystemValue::FinalTriUeq0EdgeTessFactor); + ENUM_NAME(DxbcSystemValue::FinalTriVeq0EdgeTessFactor); + ENUM_NAME(DxbcSystemValue::FinalTriWeq0EdgeTessFactor); + ENUM_NAME(DxbcSystemValue::FinalTriInsideTessFactor); + ENUM_NAME(DxbcSystemValue::FinalLineDetailTessFactor); + ENUM_NAME(DxbcSystemValue::FinalLineDensityTessFactor); + ENUM_NAME(DxbcSystemValue::Target); + ENUM_NAME(DxbcSystemValue::Depth); + ENUM_NAME(DxbcSystemValue::Coverage); + ENUM_NAME(DxbcSystemValue::DepthGe); + ENUM_NAME(DxbcSystemValue::DepthLe); + ENUM_DEFAULT(e); + } + } + + + std::ostream& operator << (std::ostream& os, dxvk::DxbcProgramType e) { + switch (e) { + ENUM_NAME(DxbcProgramType::PixelShader); + ENUM_NAME(DxbcProgramType::VertexShader); + ENUM_NAME(DxbcProgramType::GeometryShader); + ENUM_NAME(DxbcProgramType::HullShader); + ENUM_NAME(DxbcProgramType::DomainShader); + ENUM_NAME(DxbcProgramType::ComputeShader); + ENUM_DEFAULT(e); + } + } + + std::ostream& operator << (std::ostream& os, dxvk::DxbcCustomDataClass e) { + switch (e) { + ENUM_NAME(DxbcCustomDataClass::Comment); + ENUM_NAME(DxbcCustomDataClass::DebugInfo); + ENUM_NAME(DxbcCustomDataClass::Opaque); + ENUM_NAME(DxbcCustomDataClass::ImmConstBuf); + ENUM_DEFAULT(e); + } + } + + std::ostream& operator << (std::ostream& os, dxvk::DxbcScalarType e) { + switch (e) { + ENUM_NAME(DxbcScalarType::Uint32); + ENUM_NAME(DxbcScalarType::Uint64); + ENUM_NAME(DxbcScalarType::Sint32); + ENUM_NAME(DxbcScalarType::Sint64); + ENUM_NAME(DxbcScalarType::Float32); + ENUM_NAME(DxbcScalarType::Float64); + ENUM_NAME(DxbcScalarType::Bool); + ENUM_DEFAULT(e); + } + } + + +} //namespace dxvk diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_reader.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_reader.cpp new file mode 100644 index 0000000000..9b9a340a38 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_reader.cpp @@ -0,0 +1,58 @@ +#include + +#include "dxbc_reader.h" + +namespace dxvk { + + DxbcTag DxbcReader::readTag() { + DxbcTag tag; + this->read(&tag, 4); + return tag; + } + + + std::string DxbcReader::readString() { + std::string result; + + while (m_data[m_pos] != '\0') + result.push_back(m_data[m_pos++]); + + m_pos++; + return result; + } + + + void DxbcReader::read(void* dst, size_t n) { + if (m_pos + n > m_size) + throw DxvkError("DxbcReader::read: Unexpected end of file"); + std::memcpy(dst, m_data + m_pos, n); + m_pos += n; + } + + + void DxbcReader::skip(size_t n) { + if (m_pos + n > m_size) + throw DxvkError("DxbcReader::skip: Unexpected end of file"); + m_pos += n; + } + + + DxbcReader DxbcReader::clone(size_t pos) const { + if (pos > m_size) + throw DxvkError("DxbcReader::clone: Invalid offset"); + return DxbcReader(m_data + pos, m_size - pos); + } + + + DxbcReader DxbcReader::resize(size_t size) const { + if (size > m_size) + throw DxvkError("DxbcReader::resize: Invalid size"); + return DxbcReader(m_data, size, m_pos); + } + + + void DxbcReader::store(std::ostream&& stream) const { + stream.write(m_data, m_size); + } + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_util.cpp b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_util.cpp new file mode 100644 index 0000000000..3d885fc9c5 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/dxbc/dxbc_util.cpp @@ -0,0 +1,26 @@ +#include "dxbc_util.h" + +namespace dxvk { + + uint32_t primitiveVertexCount(DxbcPrimitive primitive) { + static const std::array s_vertexCounts = { + 0, // Undefined + 1, // Point + 2, // Line + 3, // Triangle + 0, // Undefined + 0, // Undefined + 4, // Line with adjacency + 6, // Triangle with adjacency + }; + + if (primitive >= DxbcPrimitive::Patch1) { + return uint32_t(primitive) + - uint32_t(DxbcPrimitive::Patch1) + + 1u; + } else { + return s_vertexCounts.at(uint32_t(primitive)); + } + } + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/src/spirv/spirv_code_buffer.cpp b/app/src/main/cpp/thirdparty/dxbc/src/spirv/spirv_code_buffer.cpp new file mode 100644 index 0000000000..f8166df51c --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/spirv/spirv_code_buffer.cpp @@ -0,0 +1,166 @@ +#include +#include + +#include "spirv_code_buffer.h" + +namespace dxvk { + + SpirvCodeBuffer:: SpirvCodeBuffer() { } + SpirvCodeBuffer::~SpirvCodeBuffer() { } + + + SpirvCodeBuffer::SpirvCodeBuffer(uint32_t size) + : m_ptr(size) { + m_code.resize(size); + } + + + SpirvCodeBuffer::SpirvCodeBuffer(uint32_t size, const uint32_t* data) + : m_ptr(size) { + m_code.resize(size); + std::memcpy(m_code.data(), data, size * sizeof(uint32_t)); + } + + + SpirvCodeBuffer::SpirvCodeBuffer(std::istream& stream) { + stream.ignore(std::numeric_limits::max()); + std::streamsize length = stream.gcount(); + stream.clear(); + stream.seekg(0, std::ios_base::beg); + + std::vector buffer(length); + stream.read(buffer.data(), length); + buffer.resize(stream.gcount()); + + m_code.resize(buffer.size() / sizeof(uint32_t)); + std::memcpy(reinterpret_cast(m_code.data()), + buffer.data(), m_code.size() * sizeof(uint32_t)); + + m_ptr = m_code.size(); + } + + + uint32_t SpirvCodeBuffer::allocId() { + constexpr size_t BoundIdsOffset = 3; + + if (m_code.size() <= BoundIdsOffset) + return 0; + + return m_code[BoundIdsOffset]++; + } + + + void SpirvCodeBuffer::append(const SpirvInstruction& ins) { + const size_t size = m_code.size(); + + m_code.resize(size + ins.length()); + + for (uint32_t i = 0; i < ins.length(); i++) + m_code[size + i] = ins.arg(i); + + m_ptr += ins.length(); + } + + + void SpirvCodeBuffer::append(const SpirvCodeBuffer& other) { + if (other.size() != 0) { + const size_t size = m_code.size(); + m_code.resize(size + other.m_code.size()); + + uint32_t* dst = this->m_code.data(); + const uint32_t* src = other.m_code.data(); + + std::memcpy(dst + size, src, other.size()); + m_ptr += other.m_code.size(); + } + } + + + void SpirvCodeBuffer::putWord(uint32_t word) { + m_code.insert(m_code.begin() + m_ptr, word); + m_ptr += 1; + } + + + void SpirvCodeBuffer::putIns(spv::Op opCode, uint16_t wordCount) { + this->putWord( + (static_cast(opCode) << 0) + | (static_cast(wordCount) << 16)); + } + + + void SpirvCodeBuffer::putInt32(uint32_t word) { + this->putWord(word); + } + + + void SpirvCodeBuffer::putInt64(uint64_t value) { + this->putWord(value >> 0); + this->putWord(value >> 32); + } + + + void SpirvCodeBuffer::putFloat32(float value) { + uint32_t tmp; + static_assert(sizeof(tmp) == sizeof(value)); + std::memcpy(&tmp, &value, sizeof(value)); + this->putInt32(tmp); + } + + + void SpirvCodeBuffer::putFloat64(double value) { + uint64_t tmp; + static_assert(sizeof(tmp) == sizeof(value)); + std::memcpy(&tmp, &value, sizeof(value)); + this->putInt64(tmp); + } + + + void SpirvCodeBuffer::putStr(const char* str) { + uint32_t word = 0; + uint32_t nbit = 0; + + for (uint32_t i = 0; str[i] != '\0'; str++) { + word |= (static_cast(str[i]) & 0xFF) << nbit; + + if ((nbit += 8) == 32) { + this->putWord(word); + word = 0; + nbit = 0; + } + } + + // Commit current word + this->putWord(word); + } + + + void SpirvCodeBuffer::putHeader(uint32_t version, uint32_t boundIds) { + this->putWord(spv::MagicNumber); + this->putWord(version); + this->putWord(0); // Generator + this->putWord(boundIds); + this->putWord(0); // Schema + } + + + void SpirvCodeBuffer::erase(size_t size) { + m_code.erase( + m_code.begin() + m_ptr, + m_code.begin() + m_ptr + size); + } + + + uint32_t SpirvCodeBuffer::strLen(const char* str) { + // Null-termination plus padding + return (std::strlen(str) + 4) / 4; + } + + + void SpirvCodeBuffer::store(std::ostream& stream) const { + stream.write( + reinterpret_cast(m_code.data()), + sizeof(uint32_t) * m_code.size()); + } + +} \ No newline at end of file diff --git a/app/src/main/cpp/thirdparty/dxbc/src/spirv/spirv_module.cpp b/app/src/main/cpp/thirdparty/dxbc/src/spirv/spirv_module.cpp new file mode 100644 index 0000000000..aad1b39ec3 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/spirv/spirv_module.cpp @@ -0,0 +1,4085 @@ +#include + +#include "spirv_module.h" + +namespace dxvk { + + SpirvModule::SpirvModule(uint32_t version) + : m_version(version) { + this->instImportGlsl450(); + } + + + SpirvModule::~SpirvModule() { + + } + + + SpirvCodeBuffer SpirvModule::compile() { + SpirvCodeBuffer result; + result.putHeader(m_version, m_id); + result.append(m_capabilities); + result.append(m_extensions); + result.append(m_instExt); + result.append(m_memoryModel); + result.append(m_entryPoints); + result.append(m_execModeInfo); + result.append(m_debugNames); + result.append(m_annotations); + result.append(m_typeConstDefs); + result.append(m_variables); + + // Perform some crude dead code elimination. In some cases, our compilers + // may emit invalid code, such as an unreachable block branching to a loop's + // continue block, but those cases cannot be reasonably detected up-front. + std::unordered_set reachableBlocks; + std::unordered_set mergeBlocks; + + classifyBlocks(reachableBlocks, mergeBlocks); + + bool reachable = true; + + for (auto ins : m_code) { + if (ins.opCode() == spv::OpFunctionEnd) { + reachable = true; + result.append(ins); + } else if (ins.opCode() == spv::OpLabel) { + uint32_t labelId = ins.arg(1); + + if ((reachable = reachableBlocks.find(labelId) != reachableBlocks.end())) { + result.append(ins); + } else if (mergeBlocks.find(labelId) != mergeBlocks.end()) { + result.append(ins); + result.putIns(spv::OpUnreachable, 1); + } + } else if (reachable) { + result.append(ins); + } + } + + return result; + } + + + uint32_t SpirvModule::allocateId() { + return m_id++; + } + + + bool SpirvModule::hasCapability( + spv::Capability capability) { + for (auto ins : m_capabilities) { + if (ins.opCode() == spv::OpCapability && ins.arg(1) == capability) + return true; + } + + return false; + } + + void SpirvModule::enableCapability( + spv::Capability capability) { + // Scan the generated instructions to check + // whether we already enabled the capability. + if (!hasCapability(capability)) { + m_capabilities.putIns (spv::OpCapability, 2); + m_capabilities.putWord(capability); + } + } + + + void SpirvModule::enableExtension( + const char* extensionName) { + m_extensions.putIns (spv::OpExtension, 1 + m_extensions.strLen(extensionName)); + m_extensions.putStr (extensionName); + } + + + void SpirvModule::addEntryPoint( + uint32_t entryPointId, + spv::ExecutionModel executionModel, + const char* name) { + m_entryPoints.putIns (spv::OpEntryPoint, 3 + m_entryPoints.strLen(name) + m_interfaceVars.size()); + m_entryPoints.putWord (executionModel); + m_entryPoints.putWord (entryPointId); + m_entryPoints.putStr (name); + + for (uint32_t varId : m_interfaceVars) + m_entryPoints.putWord(varId); + } + + + void SpirvModule::setMemoryModel( + spv::AddressingModel addressModel, + spv::MemoryModel memoryModel) { + m_memoryModel.putIns (spv::OpMemoryModel, 3); + m_memoryModel.putWord (addressModel); + m_memoryModel.putWord (memoryModel); + } + + + void SpirvModule::setExecutionMode( + uint32_t entryPointId, + spv::ExecutionMode executionMode) { + m_execModeInfo.putIns (spv::OpExecutionMode, 3); + m_execModeInfo.putWord(entryPointId); + m_execModeInfo.putWord(executionMode); + } + + + void SpirvModule::setExecutionMode( + uint32_t entryPointId, + spv::ExecutionMode executionMode, + uint32_t argCount, + const uint32_t* args) { + m_execModeInfo.putIns (spv::OpExecutionMode, 3 + argCount); + m_execModeInfo.putWord(entryPointId); + m_execModeInfo.putWord(executionMode); + + for (uint32_t i = 0; i < argCount; i++) + m_execModeInfo.putWord(args[i]); + } + + + void SpirvModule::setInvocations( + uint32_t entryPointId, + uint32_t invocations) { + m_execModeInfo.putIns (spv::OpExecutionMode, 4); + m_execModeInfo.putWord (entryPointId); + m_execModeInfo.putWord (spv::ExecutionModeInvocations); + m_execModeInfo.putInt32(invocations); + } + + + void SpirvModule::setLocalSize( + uint32_t entryPointId, + uint32_t x, + uint32_t y, + uint32_t z) { + m_execModeInfo.putIns (spv::OpExecutionMode, 6); + m_execModeInfo.putWord (entryPointId); + m_execModeInfo.putWord (spv::ExecutionModeLocalSize); + m_execModeInfo.putInt32(x); + m_execModeInfo.putInt32(y); + m_execModeInfo.putInt32(z); + } + + + void SpirvModule::setOutputVertices( + uint32_t entryPointId, + uint32_t vertexCount) { + m_execModeInfo.putIns (spv::OpExecutionMode, 4); + m_execModeInfo.putWord(entryPointId); + m_execModeInfo.putWord(spv::ExecutionModeOutputVertices); + m_execModeInfo.putWord(vertexCount); + } + + + uint32_t SpirvModule::addDebugString( + const char* string) { + uint32_t resultId = this->allocateId(); + + m_debugNames.putIns (spv::OpString, + 2 + m_debugNames.strLen(string)); + m_debugNames.putWord(resultId); + m_debugNames.putStr (string); + return resultId; + } + + + void SpirvModule::setDebugSource( + spv::SourceLanguage language, + uint32_t version, + uint32_t file, + const char* source) { + uint32_t strLen = source != nullptr + ? m_debugNames.strLen(source) : 0; + + m_debugNames.putIns (spv::OpSource, 4 + strLen); + m_debugNames.putWord(language); + m_debugNames.putWord(version); + m_debugNames.putWord(file); + + if (source != nullptr) + m_debugNames.putStr(source); + } + + void SpirvModule::setDebugName( + uint32_t expressionId, + const char* debugName) { + m_debugNames.putIns (spv::OpName, 2 + m_debugNames.strLen(debugName)); + m_debugNames.putWord(expressionId); + m_debugNames.putStr (debugName); + } + + + void SpirvModule::setDebugMemberName( + uint32_t structId, + uint32_t memberId, + const char* debugName) { + m_debugNames.putIns (spv::OpMemberName, 3 + m_debugNames.strLen(debugName)); + m_debugNames.putWord(structId); + m_debugNames.putWord(memberId); + m_debugNames.putStr (debugName); + } + + + uint32_t SpirvModule::constBool( + bool v) { + return this->defConst(v + ? spv::OpConstantTrue + : spv::OpConstantFalse, + this->defBoolType(), + 0, nullptr); + } + + + uint32_t SpirvModule::consti32( + int32_t v) { + std::array data; + std::memcpy(data.data(), &v, sizeof(v)); + + return this->defConst( + spv::OpConstant, + this->defIntType(32, 1), + data.size(), + data.data()); + } + + + uint32_t SpirvModule::consti64( + int64_t v) { + std::array data; + std::memcpy(data.data(), &v, sizeof(v)); + + return this->defConst( + spv::OpConstant, + this->defIntType(64, 1), + data.size(), + data.data()); + } + + + uint32_t SpirvModule::constu32( + uint32_t v) { + std::array data; + std::memcpy(data.data(), &v, sizeof(v)); + + return this->defConst( + spv::OpConstant, + this->defIntType(32, 0), + data.size(), + data.data()); + } + + + uint32_t SpirvModule::constu64( + uint64_t v) { + std::array data; + std::memcpy(data.data(), &v, sizeof(v)); + + return this->defConst( + spv::OpConstant, + this->defIntType(64, 0), + data.size(), + data.data()); + } + + + uint32_t SpirvModule::constf32( + float v) { + std::array data; + std::memcpy(data.data(), &v, sizeof(v)); + + return this->defConst( + spv::OpConstant, + this->defFloatType(32), + data.size(), + data.data()); + } + + + uint32_t SpirvModule::constf64( + double v) { + std::array data; + std::memcpy(data.data(), &v, sizeof(v)); + + return this->defConst( + spv::OpConstant, + this->defFloatType(64), + data.size(), + data.data()); + } + + + uint32_t SpirvModule::constvec4i32( + int32_t x, + int32_t y, + int32_t z, + int32_t w) { + std::array args = {{ + this->consti32(x), this->consti32(y), + this->consti32(z), this->consti32(w), + }}; + + uint32_t scalarTypeId = this->defIntType(32, 1); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, 4); + + return this->constComposite(vectorTypeId, args.size(), args.data()); + } + + + uint32_t SpirvModule::constvec4b32( + bool x, + bool y, + bool z, + bool w) { + std::array args = {{ + this->constBool(x), this->constBool(y), + this->constBool(z), this->constBool(w), + }}; + + uint32_t scalarTypeId = this->defBoolType(); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, 4); + + return this->constComposite(vectorTypeId, args.size(), args.data()); + } + + + uint32_t SpirvModule::constvec4u32( + uint32_t x, + uint32_t y, + uint32_t z, + uint32_t w) { + std::array args = {{ + this->constu32(x), this->constu32(y), + this->constu32(z), this->constu32(w), + }}; + + uint32_t scalarTypeId = this->defIntType(32, 0); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, 4); + + return this->constComposite(vectorTypeId, args.size(), args.data()); + } + + + uint32_t SpirvModule::constvec2f32( + float x, + float y) { + std::array args = {{ + this->constf32(x), this->constf32(y), + }}; + + uint32_t scalarTypeId = this->defFloatType(32); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, 2); + + return this->constComposite(vectorTypeId, args.size(), args.data()); + } + + + uint32_t SpirvModule::constvec3f32( + float x, + float y, + float z) { + std::array args = {{ + this->constf32(x), this->constf32(y), + this->constf32(z), + }}; + + uint32_t scalarTypeId = this->defFloatType(32); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, 3); + + return this->constComposite(vectorTypeId, args.size(), args.data()); + } + + + uint32_t SpirvModule::constvec4f32( + float x, + float y, + float z, + float w) { + std::array args = {{ + this->constf32(x), this->constf32(y), + this->constf32(z), this->constf32(w), + }}; + + uint32_t scalarTypeId = this->defFloatType(32); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, 4); + + return this->constComposite(vectorTypeId, args.size(), args.data()); + } + + + uint32_t SpirvModule::constfReplicant( + float replicant, + uint32_t count) { + uint32_t value = this->constf32(replicant); + + std::array args = { value, value, value, value }; + + // Can't make a scalar composite. + if (count == 1) + return args[0]; + + uint32_t scalarTypeId = this->defFloatType(32); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, count); + + return this->constComposite(vectorTypeId, count, args.data()); + } + + + uint32_t SpirvModule::constbReplicant( + bool replicant, + uint32_t count) { + uint32_t value = this->constBool(replicant); + + std::array args = { value, value, value, value }; + + // Can't make a scalar composite. + if (count == 1) + return args[0]; + + uint32_t scalarTypeId = this->defBoolType(); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, count); + + return this->constComposite(vectorTypeId, count, args.data()); + } + + + uint32_t SpirvModule::constiReplicant( + int32_t replicant, + uint32_t count) { + uint32_t value = this->consti32(replicant); + + std::array args = { value, value, value, value }; + + // Can't make a scalar composite. + if (count == 1) + return args[0]; + + uint32_t scalarTypeId = this->defIntType(32, 1); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, count); + + return this->constComposite(vectorTypeId, count, args.data()); + } + + + uint32_t SpirvModule::constuReplicant( + int32_t replicant, + uint32_t count) { + uint32_t value = this->constu32(replicant); + + std::array args = { value, value, value, value }; + + // Can't make a scalar composite. + if (count == 1) + return args[0]; + + uint32_t scalarTypeId = this->defIntType(32, 0); + uint32_t vectorTypeId = this->defVectorType(scalarTypeId, count); + + return this->constComposite(vectorTypeId, count, args.data()); + } + + + uint32_t SpirvModule::constComposite( + uint32_t typeId, + uint32_t constCount, + const uint32_t* constIds) { + return this->defConst( + spv::OpConstantComposite, + typeId, constCount, constIds); + } + + + uint32_t SpirvModule::constUndef( + uint32_t typeId) { + return this->defConst(spv::OpUndef, + typeId, 0, nullptr); + } + + + uint32_t SpirvModule::constNull( + uint32_t typeId) { + return this->defConst(spv::OpConstantNull, + typeId, 0, nullptr); + } + + + uint32_t SpirvModule::lateConst32( + uint32_t typeId) { + uint32_t resultId = this->allocateId(); + m_lateConsts.insert(resultId); + + m_typeConstDefs.putIns (spv::OpConstant, 4); + m_typeConstDefs.putWord(typeId); + m_typeConstDefs.putWord(resultId); + m_typeConstDefs.putWord(0); + return resultId; + } + + + void SpirvModule::setLateConst( + uint32_t constId, + const uint32_t* argIds) { + for (auto ins : m_typeConstDefs) { + if (ins.opCode() != spv::OpConstant + && ins.opCode() != spv::OpConstantComposite) + continue; + + if (ins.arg(2) != constId) + continue; + + for (uint32_t i = 3; i < ins.length(); i++) + ins.setArg(i, argIds[i - 3]); + + return; + } + } + + + uint32_t SpirvModule::specConstBool( + bool v) { + uint32_t typeId = this->defBoolType(); + uint32_t resultId = this->allocateId(); + + const spv::Op op = v + ? spv::OpSpecConstantTrue + : spv::OpSpecConstantFalse; + + m_typeConstDefs.putIns (op, 3); + m_typeConstDefs.putWord (typeId); + m_typeConstDefs.putWord (resultId); + return resultId; + } + + + uint32_t SpirvModule::specConst32( + uint32_t typeId, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_typeConstDefs.putIns (spv::OpSpecConstant, 4); + m_typeConstDefs.putWord (typeId); + m_typeConstDefs.putWord (resultId); + m_typeConstDefs.putWord (value); + return resultId; + } + + + void SpirvModule::decorate( + uint32_t object, + spv::Decoration decoration) { + m_annotations.putIns (spv::OpDecorate, 3); + m_annotations.putWord (object); + m_annotations.putWord (decoration); + } + + + void SpirvModule::decorateArrayStride( + uint32_t object, + uint32_t stride) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationArrayStride); + m_annotations.putInt32(stride); + } + + + void SpirvModule::decorateBinding( + uint32_t object, + uint32_t binding) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationBinding); + m_annotations.putInt32(binding); + } + + + void SpirvModule::decorateBlock(uint32_t object) { + m_annotations.putIns (spv::OpDecorate, 3); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationBlock); + } + + + void SpirvModule::decorateBuiltIn( + uint32_t object, + spv::BuiltIn builtIn) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationBuiltIn); + m_annotations.putWord (builtIn); + } + + + void SpirvModule::decorateComponent( + uint32_t object, + uint32_t location) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationComponent); + m_annotations.putInt32(location); + } + + + void SpirvModule::decorateDescriptorSet( + uint32_t object, + uint32_t set) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationDescriptorSet); + m_annotations.putInt32(set); + } + + + void SpirvModule::decorateIndex( + uint32_t object, + uint32_t index) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationIndex); + m_annotations.putInt32(index); + } + + + void SpirvModule::decorateLocation( + uint32_t object, + uint32_t location) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationLocation); + m_annotations.putInt32(location); + } + + + void SpirvModule::decorateSpecId( + uint32_t object, + uint32_t specId) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationSpecId); + m_annotations.putInt32(specId); + } + + + void SpirvModule::decorateXfb( + uint32_t object, + uint32_t streamId, + uint32_t bufferId, + uint32_t offset, + uint32_t stride) { + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationStream); + m_annotations.putInt32(streamId); + + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationXfbBuffer); + m_annotations.putInt32(bufferId); + + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationXfbStride); + m_annotations.putInt32(stride); + + m_annotations.putIns (spv::OpDecorate, 4); + m_annotations.putWord (object); + m_annotations.putWord (spv::DecorationOffset); + m_annotations.putInt32(offset); + } + + + void SpirvModule::memberDecorateBuiltIn( + uint32_t structId, + uint32_t memberId, + spv::BuiltIn builtIn) { + m_annotations.putIns (spv::OpMemberDecorate, 5); + m_annotations.putWord (structId); + m_annotations.putWord (memberId); + m_annotations.putWord (spv::DecorationBuiltIn); + m_annotations.putWord (builtIn); + } + + + void SpirvModule::memberDecorate( + uint32_t structId, + uint32_t memberId, + spv::Decoration decoration) { + m_annotations.putIns (spv::OpMemberDecorate, 4); + m_annotations.putWord (structId); + m_annotations.putWord (memberId); + m_annotations.putWord (decoration); + } + + + void SpirvModule::memberDecorateMatrixStride( + uint32_t structId, + uint32_t memberId, + uint32_t stride) { + m_annotations.putIns (spv::OpMemberDecorate, 5); + m_annotations.putWord (structId); + m_annotations.putWord (memberId); + m_annotations.putWord (spv::DecorationMatrixStride); + m_annotations.putWord (stride); + } + + + void SpirvModule::memberDecorateOffset( + uint32_t structId, + uint32_t memberId, + uint32_t offset) { + m_annotations.putIns (spv::OpMemberDecorate, 5); + m_annotations.putWord (structId); + m_annotations.putWord (memberId); + m_annotations.putWord (spv::DecorationOffset); + m_annotations.putWord (offset); + } + + + uint32_t SpirvModule::defVoidType() { + return this->defType(spv::OpTypeVoid, 0, nullptr); + } + + + uint32_t SpirvModule::defBoolType() { + return this->defType(spv::OpTypeBool, 0, nullptr); + } + + + uint32_t SpirvModule::defIntType( + uint32_t width, + uint32_t isSigned) { + std::array args = {{ width, isSigned }}; + return this->defType(spv::OpTypeInt, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defFloatType( + uint32_t width) { + std::array args = {{ width }}; + return this->defType(spv::OpTypeFloat, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defVectorType( + uint32_t elementType, + uint32_t elementCount) { + std::array args = + {{ elementType, elementCount }}; + + return this->defType(spv::OpTypeVector, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defMatrixType( + uint32_t columnType, + uint32_t columnCount) { + std::array args = + {{ columnType, columnCount }}; + + return this->defType(spv::OpTypeMatrix, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defArrayType( + uint32_t typeId, + uint32_t length) { + std::array args = {{ typeId, length }}; + + return this->defType(spv::OpTypeArray, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defArrayTypeUnique( + uint32_t typeId, + uint32_t length) { + uint32_t resultId = this->allocateId(); + + m_typeConstDefs.putIns (spv::OpTypeArray, 4); + m_typeConstDefs.putWord(resultId); + m_typeConstDefs.putWord(typeId); + m_typeConstDefs.putWord(length); + return resultId; + } + + + uint32_t SpirvModule::defRuntimeArrayType( + uint32_t typeId) { + std::array args = { typeId }; + + return this->defType(spv::OpTypeRuntimeArray, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defRuntimeArrayTypeUnique( + uint32_t typeId) { + uint32_t resultId = this->allocateId(); + + m_typeConstDefs.putIns (spv::OpTypeRuntimeArray, 3); + m_typeConstDefs.putWord(resultId); + m_typeConstDefs.putWord(typeId); + return resultId; + } + + + uint32_t SpirvModule::defFunctionType( + uint32_t returnType, + uint32_t argCount, + const uint32_t* argTypes) { + std::vector args; + args.push_back(returnType); + + for (uint32_t i = 0; i < argCount; i++) + args.push_back(argTypes[i]); + + return this->defType(spv::OpTypeFunction, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defStructType( + uint32_t memberCount, + const uint32_t* memberTypes) { + return this->defType(spv::OpTypeStruct, + memberCount, memberTypes); + } + + + uint32_t SpirvModule::defStructTypeUnique( + uint32_t memberCount, + const uint32_t* memberTypes) { + uint32_t resultId = this->allocateId(); + + m_typeConstDefs.putIns (spv::OpTypeStruct, 2 + memberCount); + m_typeConstDefs.putWord(resultId); + + for (uint32_t i = 0; i < memberCount; i++) + m_typeConstDefs.putWord(memberTypes[i]); + return resultId; + } + + + uint32_t SpirvModule::defPointerType( + uint32_t variableType, + spv::StorageClass storageClass) { + std::array args = {{ + static_cast(storageClass), + variableType, + }}; + + return this->defType(spv::OpTypePointer, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defSamplerType() { + return this->defType(spv::OpTypeSampler, 0, nullptr); + } + + + uint32_t SpirvModule::defImageType( + uint32_t sampledType, + spv::Dim dimensionality, + uint32_t depth, + uint32_t arrayed, + uint32_t multisample, + uint32_t sampled, + spv::ImageFormat format) { + std::array args = {{ + sampledType, + static_cast(dimensionality), + depth, arrayed, + multisample, + sampled, + static_cast(format) + }}; + + return this->defType(spv::OpTypeImage, + args.size(), args.data()); + } + + + uint32_t SpirvModule::defSampledImageType( + uint32_t imageType) { + return this->defType(spv::OpTypeSampledImage, 1, &imageType); + } + + + uint32_t SpirvModule::newVar( + uint32_t pointerType, + spv::StorageClass storageClass) { + uint32_t resultId = this->allocateId(); + + if (isInterfaceVar(storageClass)) + m_interfaceVars.push_back(resultId); + + auto& code = storageClass != spv::StorageClassFunction + ? m_variables : m_code; + + code.putIns (spv::OpVariable, 4); + code.putWord (pointerType); + code.putWord (resultId); + code.putWord (storageClass); + return resultId; + } + + + uint32_t SpirvModule::newVarInit( + uint32_t pointerType, + spv::StorageClass storageClass, + uint32_t initialValue) { + uint32_t resultId = this->allocateId(); + + if (isInterfaceVar(storageClass)) + m_interfaceVars.push_back(resultId); + + auto& code = storageClass != spv::StorageClassFunction + ? m_variables : m_code; + + code.putIns (spv::OpVariable, 5); + code.putWord (pointerType); + code.putWord (resultId); + code.putWord (storageClass); + code.putWord (initialValue); + return resultId; + } + + + void SpirvModule::functionBegin( + uint32_t returnType, + uint32_t functionId, + uint32_t functionType, + spv::FunctionControlMask functionControl) { + m_code.putIns (spv::OpFunction, 5); + m_code.putWord(returnType); + m_code.putWord(functionId); + m_code.putWord(functionControl); + m_code.putWord(functionType); + } + + + uint32_t SpirvModule::functionParameter( + uint32_t parameterType) { + uint32_t parameterId = this->allocateId(); + + m_code.putIns (spv::OpFunctionParameter, 3); + m_code.putWord(parameterType); + m_code.putWord(parameterId); + return parameterId; + } + + + void SpirvModule::functionEnd() { + m_code.putIns (spv::OpFunctionEnd, 1); + } + + + uint32_t SpirvModule::opAccessChain( + uint32_t resultType, + uint32_t composite, + uint32_t indexCount, + const uint32_t* indexArray) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAccessChain, 4 + indexCount); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(composite); + + for (uint32_t i = 0; i < indexCount; i++) + m_code.putInt32(indexArray[i]); + return resultId; + } + + + uint32_t SpirvModule::opArrayLength( + uint32_t resultType, + uint32_t structure, + uint32_t memberId) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpArrayLength, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(structure); + m_code.putWord(memberId); + return resultId; + } + + + uint32_t SpirvModule::opAny( + uint32_t resultType, + uint32_t vector) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAny, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector); + return resultId; + } + + + uint32_t SpirvModule::opAll( + uint32_t resultType, + uint32_t vector) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAll, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector); + return resultId; + } + + + uint32_t SpirvModule::opAtomicLoad( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicLoad, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + return resultId; + } + + + void SpirvModule::opAtomicStore( + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + m_code.putIns (spv::OpAtomicStore, 5); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + } + + + uint32_t SpirvModule::opAtomicExchange( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicExchange, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicCompareExchange( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t equal, + uint32_t unequal, + uint32_t value, + uint32_t comparator) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicCompareExchange, 9); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(equal); + m_code.putWord(unequal); + m_code.putWord(value); + m_code.putWord(comparator); + return resultId; + } + + + uint32_t SpirvModule::opAtomicIIncrement( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicIIncrement, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + return resultId; + } + + + uint32_t SpirvModule::opAtomicIDecrement( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicIDecrement, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + return resultId; + } + + + uint32_t SpirvModule::opAtomicIAdd( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicIAdd, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicISub( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicISub, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicSMin( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicSMin, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicSMax( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicSMax, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicUMin( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicUMin, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicUMax( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicUMax, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicAnd( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicAnd, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicOr( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicOr, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opAtomicXor( + uint32_t resultType, + uint32_t pointer, + uint32_t scope, + uint32_t semantics, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpAtomicXor, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(pointer); + m_code.putWord(scope); + m_code.putWord(semantics); + m_code.putWord(value); + return resultId; + } + + + uint32_t SpirvModule::opBitcast( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitcast, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opBitCount( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitCount, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opBitReverse( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitReverse, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFindILsb( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FindILsb); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFindUMsb( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FindUMsb); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFindSMsb( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FindSMsb); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opBitFieldInsert( + uint32_t resultType, + uint32_t base, + uint32_t insert, + uint32_t offset, + uint32_t count) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitFieldInsert, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(base); + m_code.putWord(insert); + m_code.putWord(offset); + m_code.putWord(count); + return resultId; + } + + + uint32_t SpirvModule::opBitFieldSExtract( + uint32_t resultType, + uint32_t base, + uint32_t offset, + uint32_t count) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitFieldSExtract, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(base); + m_code.putWord(offset); + m_code.putWord(count); + return resultId; + } + + + uint32_t SpirvModule::opBitFieldUExtract( + uint32_t resultType, + uint32_t base, + uint32_t offset, + uint32_t count) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitFieldUExtract, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(base); + m_code.putWord(offset); + m_code.putWord(count); + return resultId; + } + + + uint32_t SpirvModule::opBitwiseAnd( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitwiseAnd, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opBitwiseOr( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitwiseOr, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opBitwiseXor( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpBitwiseXor, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opNot( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpNot, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opShiftLeftLogical( + uint32_t resultType, + uint32_t base, + uint32_t shift) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpShiftLeftLogical, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(base); + m_code.putWord(shift); + return resultId; + } + + + uint32_t SpirvModule::opShiftRightArithmetic( + uint32_t resultType, + uint32_t base, + uint32_t shift) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpShiftRightArithmetic, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(base); + m_code.putWord(shift); + return resultId; + } + + + uint32_t SpirvModule::opShiftRightLogical( + uint32_t resultType, + uint32_t base, + uint32_t shift) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpShiftRightLogical, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(base); + m_code.putWord(shift); + return resultId; + } + + + uint32_t SpirvModule::opConvertFtoS( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpConvertFToS, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opConvertFtoU( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpConvertFToU, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opConvertStoF( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpConvertSToF, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opConvertUtoF( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpConvertUToF, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opCompositeConstruct( + uint32_t resultType, + uint32_t valueCount, + const uint32_t* valueArray) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpCompositeConstruct, 3 + valueCount); + m_code.putWord(resultType); + m_code.putWord(resultId); + + for (uint32_t i = 0; i < valueCount; i++) + m_code.putWord(valueArray[i]); + return resultId; + } + + + uint32_t SpirvModule::opCompositeExtract( + uint32_t resultType, + uint32_t composite, + uint32_t indexCount, + const uint32_t* indexArray) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpCompositeExtract, 4 + indexCount); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(composite); + + for (uint32_t i = 0; i < indexCount; i++) + m_code.putInt32(indexArray[i]); + return resultId; + } + + + uint32_t SpirvModule::opCompositeInsert( + uint32_t resultType, + uint32_t object, + uint32_t composite, + uint32_t indexCount, + const uint32_t* indexArray) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpCompositeInsert, 5 + indexCount); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(object); + m_code.putWord(composite); + + for (uint32_t i = 0; i < indexCount; i++) + m_code.putInt32(indexArray[i]); + return resultId; + } + + + uint32_t SpirvModule::opDpdx( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpDPdx, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opDpdy( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpDPdy, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opDpdxCoarse( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpDPdxCoarse, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opDpdyCoarse( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpDPdyCoarse, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opDpdxFine( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpDPdxFine, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opDpdyFine( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpDPdyFine, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opVectorExtractDynamic( + uint32_t resultType, + uint32_t vector, + uint32_t index) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpVectorExtractDynamic, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector); + m_code.putWord(index); + return resultId; + } + + + uint32_t SpirvModule::opVectorShuffle( + uint32_t resultType, + uint32_t vectorLeft, + uint32_t vectorRight, + uint32_t indexCount, + const uint32_t* indexArray) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpVectorShuffle, 5 + indexCount); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vectorLeft); + m_code.putWord(vectorRight); + + for (uint32_t i = 0; i < indexCount; i++) + m_code.putInt32(indexArray[i]); + return resultId; + } + + + uint32_t SpirvModule::opSNegate( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSNegate, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFNegate( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFNegate, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opSAbs( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450SAbs); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFAbs( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FAbs); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFSign( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FSign); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFMix( + uint32_t resultType, + uint32_t x, + uint32_t y, + uint32_t a) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 8); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FMix); + m_code.putWord(x); + m_code.putWord(y); + m_code.putWord(a); + return resultId; + } + + + uint32_t SpirvModule::opCross( + uint32_t resultType, + uint32_t x, + uint32_t y) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Cross); + m_code.putWord(x); + m_code.putWord(y); + return resultId; + } + + + uint32_t SpirvModule::opIAdd( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpIAdd, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opISub( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpISub, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opFAdd( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFAdd, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opFSub( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFSub, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opSDiv( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSDiv, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opUDiv( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpUDiv, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opSRem( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSRem, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opUMod( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpUMod, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opFDiv( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFDiv, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opIMul( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpIMul, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opFMul( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFMul, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opVectorTimesScalar( + uint32_t resultType, + uint32_t vector, + uint32_t scalar) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpVectorTimesScalar, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector); + m_code.putWord(scalar); + return resultId; + } + + + uint32_t SpirvModule::opMatrixTimesMatrix( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpMatrixTimesMatrix, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opMatrixTimesVector( + uint32_t resultType, + uint32_t matrix, + uint32_t vector) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpMatrixTimesVector, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(matrix); + m_code.putWord(vector); + return resultId; + } + + + uint32_t SpirvModule::opVectorTimesMatrix( + uint32_t resultType, + uint32_t vector, + uint32_t matrix) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpVectorTimesMatrix, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector); + m_code.putWord(matrix); + return resultId; + } + + + uint32_t SpirvModule::opTranspose( + uint32_t resultType, + uint32_t matrix) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpTranspose, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(matrix); + return resultId; + } + + + uint32_t SpirvModule::opInverse( + uint32_t resultType, + uint32_t matrix) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450MatrixInverse); + m_code.putWord(matrix); + return resultId; + } + + + uint32_t SpirvModule::opFFma( + uint32_t resultType, + uint32_t a, + uint32_t b, + uint32_t c) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 8); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Fma); + m_code.putWord(a); + m_code.putWord(b); + m_code.putWord(c); + return resultId; + } + + + uint32_t SpirvModule::opFMax( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FMax); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opFMin( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FMin); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opNMax( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450NMax); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opNMin( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450NMin); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opSMax( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450SMax); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opSMin( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450SMin); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opUMax( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450UMax); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opUMin( + uint32_t resultType, + uint32_t a, + uint32_t b) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450UMin); + m_code.putWord(a); + m_code.putWord(b); + return resultId; + } + + + uint32_t SpirvModule::opFClamp( + uint32_t resultType, + uint32_t x, + uint32_t minVal, + uint32_t maxVal) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 8); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450FClamp); + m_code.putWord(x); + m_code.putWord(minVal); + m_code.putWord(maxVal); + return resultId; + } + + + uint32_t SpirvModule::opNClamp( + uint32_t resultType, + uint32_t x, + uint32_t minVal, + uint32_t maxVal) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 8); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450NClamp); + m_code.putWord(x); + m_code.putWord(minVal); + m_code.putWord(maxVal); + return resultId; + } + + + uint32_t SpirvModule::opIEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpIEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opINotEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpINotEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opSLessThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSLessThan, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opSLessThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSLessThanEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opSGreaterThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSGreaterThan, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opSGreaterThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSGreaterThanEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opULessThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpULessThan, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opULessThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpULessThanEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opUGreaterThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpUGreaterThan, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opUGreaterThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpUGreaterThanEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opFOrdEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFOrdEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opFUnordNotEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFUnordNotEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opFOrdLessThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFOrdLessThan, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opFOrdLessThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFOrdLessThanEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opFOrdGreaterThan( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFOrdGreaterThan, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opFOrdGreaterThanEqual( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFOrdGreaterThanEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opLogicalEqual( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpLogicalEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opLogicalNotEqual( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpLogicalNotEqual, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opLogicalAnd( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpLogicalAnd, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opLogicalOr( + uint32_t resultType, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpLogicalOr, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opLogicalNot( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpLogicalNot, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opDot( + uint32_t resultType, + uint32_t vector1, + uint32_t vector2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpDot, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(vector1); + m_code.putWord(vector2); + return resultId; + } + + + uint32_t SpirvModule::opSin( + uint32_t resultType, + uint32_t vector) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Sin); + m_code.putWord(vector); + return resultId; + } + + + uint32_t SpirvModule::opCos( + uint32_t resultType, + uint32_t vector) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Cos); + m_code.putWord(vector); + return resultId; + } + + + uint32_t SpirvModule::opSqrt( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Sqrt); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opInverseSqrt( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450InverseSqrt); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opNormalize( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Normalize); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opRawAccessChain( + uint32_t resultType, + uint32_t base, + uint32_t stride, + uint32_t index, + uint32_t offset, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpRawAccessChainNV, operand ? 8 : 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(base); + m_code.putWord(stride); + m_code.putWord(index); + m_code.putWord(offset); + + if (operand) + m_code.putWord(operand); + + return resultId; + } + + + uint32_t SpirvModule::opReflect( + uint32_t resultType, + uint32_t incident, + uint32_t normal) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Reflect); + m_code.putWord(incident); + m_code.putWord(normal); + return resultId; + } + + + uint32_t SpirvModule::opLength( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Length); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opExp2( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Exp2); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opExp( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Exp); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opLog2( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Log2); + m_code.putWord(operand); + return resultId; + } + + uint32_t SpirvModule::opPow( + uint32_t resultType, + uint32_t base, + uint32_t exponent) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Pow); + m_code.putWord(base); + m_code.putWord(exponent); + return resultId; + } + + uint32_t SpirvModule::opFract( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Fract); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opCeil( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Ceil); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFloor( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Floor); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opRound( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Round); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opRoundEven( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450RoundEven); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opTrunc( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450Trunc); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFConvert( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFConvert, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opPackHalf2x16( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450PackHalf2x16); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opUnpackHalf2x16( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450UnpackHalf2x16); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opSelect( + uint32_t resultType, + uint32_t condition, + uint32_t operand1, + uint32_t operand2) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSelect, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(condition); + m_code.putWord(operand1); + m_code.putWord(operand2); + return resultId; + } + + + uint32_t SpirvModule::opIsNan( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpIsNan, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opIsInf( + uint32_t resultType, + uint32_t operand) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpIsInf, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(operand); + return resultId; + } + + + uint32_t SpirvModule::opFunctionCall( + uint32_t resultType, + uint32_t functionId, + uint32_t argCount, + const uint32_t* argIds) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpFunctionCall, 4 + argCount); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(functionId); + + for (uint32_t i = 0; i < argCount; i++) + m_code.putWord(argIds[i]); + return resultId; + } + + + void SpirvModule::opLabel(uint32_t labelId) { + m_code.putIns (spv::OpLabel, 2); + m_code.putWord(labelId); + + m_blockId = labelId; + } + + + uint32_t SpirvModule::opLoad( + uint32_t typeId, + uint32_t pointerId) { + return opLoad(typeId, pointerId, SpirvMemoryOperands()); + } + + + uint32_t SpirvModule::opLoad( + uint32_t typeId, + uint32_t pointerId, + const SpirvMemoryOperands& operands) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpLoad, 4 + getMemoryOperandWordCount(operands)); + m_code.putWord(typeId); + m_code.putWord(resultId); + m_code.putWord(pointerId); + + putMemoryOperands(operands); + return resultId; + } + + + void SpirvModule::opStore( + uint32_t pointerId, + uint32_t valueId) { + opStore(pointerId, valueId, SpirvMemoryOperands()); + } + + + void SpirvModule::opStore( + uint32_t pointerId, + uint32_t valueId, + const SpirvMemoryOperands& operands) { + m_code.putIns (spv::OpStore, 3 + getMemoryOperandWordCount(operands)); + m_code.putWord(pointerId); + m_code.putWord(valueId); + + putMemoryOperands(operands); + } + + + uint32_t SpirvModule::opInterpolateAtCentroid( + uint32_t resultType, + uint32_t interpolant) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450InterpolateAtCentroid); + m_code.putWord(interpolant); + return resultId; + } + + + uint32_t SpirvModule::opInterpolateAtSample( + uint32_t resultType, + uint32_t interpolant, + uint32_t sample) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450InterpolateAtSample); + m_code.putWord(interpolant); + m_code.putWord(sample); + return resultId; + } + + + uint32_t SpirvModule::opInterpolateAtOffset( + uint32_t resultType, + uint32_t interpolant, + uint32_t offset) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpExtInst, 7); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(m_instExtGlsl450); + m_code.putWord(GLSLstd450InterpolateAtOffset); + m_code.putWord(interpolant); + m_code.putWord(offset); + return resultId; + } + + + uint32_t SpirvModule::opImage( + uint32_t resultType, + uint32_t sampledImage) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpImage, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + return resultId; + } + + + uint32_t SpirvModule::opImageRead( + uint32_t resultType, + uint32_t image, + uint32_t coordinates, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseRead + : spv::OpImageRead; + + m_code.putIns(op, 5 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + m_code.putWord(coordinates); + + putImageOperands(operands); + return resultId; + } + + + void SpirvModule::opImageWrite( + uint32_t image, + uint32_t coordinates, + uint32_t texel, + const SpirvImageOperands& operands) { + m_code.putIns (spv::OpImageWrite, + 4 + getImageOperandWordCount(operands)); + m_code.putWord(image); + m_code.putWord(coordinates); + m_code.putWord(texel); + + putImageOperands(operands); + } + + + uint32_t SpirvModule::opImageSparseTexelsResident( + uint32_t resultType, + uint32_t residentCode) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpImageSparseTexelsResident, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(residentCode); + + return resultId; + } + + + uint32_t SpirvModule::opSampledImage( + uint32_t resultType, + uint32_t image, + uint32_t sampler) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpSampledImage, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + m_code.putWord(sampler); + return resultId; + } + + + uint32_t SpirvModule::opImageTexelPointer( + uint32_t resultType, + uint32_t image, + uint32_t coordinates, + uint32_t sample) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpImageTexelPointer, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + m_code.putWord(coordinates); + m_code.putWord(sample); + return resultId; + } + + + uint32_t SpirvModule::opImageQuerySizeLod( + uint32_t resultType, + uint32_t image, + uint32_t lod) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpImageQuerySizeLod, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + m_code.putWord(lod); + return resultId; + } + + + uint32_t SpirvModule::opImageQuerySize( + uint32_t resultType, + uint32_t image) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpImageQuerySize, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + return resultId; + } + + + uint32_t SpirvModule::opImageQueryLevels( + uint32_t resultType, + uint32_t image) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpImageQueryLevels, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + return resultId; + } + + + uint32_t SpirvModule::opImageQueryLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpImageQueryLod, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + return resultId; + } + + + uint32_t SpirvModule::opImageQuerySamples( + uint32_t resultType, + uint32_t image) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpImageQuerySamples, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + return resultId; + } + + + uint32_t SpirvModule::opImageFetch( + uint32_t resultType, + uint32_t image, + uint32_t coordinates, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseFetch + : spv::OpImageFetch; + + m_code.putIns(op, 5 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(image); + m_code.putWord(coordinates); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageGather( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t component, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseGather + : spv::OpImageGather; + + m_code.putIns(op, 6 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + m_code.putWord(component); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageDrefGather( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseDrefGather + : spv::OpImageDrefGather; + + m_code.putIns(op, 6 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + m_code.putWord(reference); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleImplicitLod + : spv::OpImageSampleImplicitLod; + + m_code.putIns(op, 5 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleExplicitLod + : spv::OpImageSampleExplicitLod; + + m_code.putIns(op, 5 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleProjImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleProjImplicitLod + : spv::OpImageSampleProjImplicitLod; + + m_code.putIns(op, 5 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleProjExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleProjExplicitLod + : spv::OpImageSampleProjExplicitLod; + + m_code.putIns(op, 5 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleDrefImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleDrefImplicitLod + : spv::OpImageSampleDrefImplicitLod; + + m_code.putIns(op, 6 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + m_code.putWord(reference); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleDrefExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleDrefExplicitLod + : spv::OpImageSampleDrefExplicitLod; + + m_code.putIns(op, 6 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + m_code.putWord(reference); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleProjDrefImplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleProjDrefImplicitLod + : spv::OpImageSampleProjDrefImplicitLod; + + m_code.putIns(op, 6 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + m_code.putWord(reference); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opImageSampleProjDrefExplicitLod( + uint32_t resultType, + uint32_t sampledImage, + uint32_t coordinates, + uint32_t reference, + const SpirvImageOperands& operands) { + uint32_t resultId = this->allocateId(); + + spv::Op op = operands.sparse + ? spv::OpImageSparseSampleProjDrefExplicitLod + : spv::OpImageSampleProjDrefExplicitLod; + + m_code.putIns(op, 6 + getImageOperandWordCount(operands)); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(sampledImage); + m_code.putWord(coordinates); + m_code.putWord(reference); + + putImageOperands(operands); + return resultId; + } + + + uint32_t SpirvModule::opGroupNonUniformBallot( + uint32_t resultType, + uint32_t execution, + uint32_t predicate) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpGroupNonUniformBallot, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(execution); + m_code.putWord(predicate); + return resultId; + } + + + uint32_t SpirvModule::opGroupNonUniformBallotBitCount( + uint32_t resultType, + uint32_t execution, + uint32_t operation, + uint32_t ballot) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpGroupNonUniformBallotBitCount, 6); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(execution); + m_code.putWord(operation); + m_code.putWord(ballot); + return resultId; + } + + + uint32_t SpirvModule::opGroupNonUniformElect( + uint32_t resultType, + uint32_t execution) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpGroupNonUniformElect, 4); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(execution); + return resultId; + } + + + uint32_t SpirvModule::opGroupNonUniformBroadcastFirst( + uint32_t resultType, + uint32_t execution, + uint32_t value) { + uint32_t resultId = this->allocateId(); + + m_code.putIns(spv::OpGroupNonUniformBroadcastFirst, 5); + m_code.putWord(resultType); + m_code.putWord(resultId); + m_code.putWord(execution); + m_code.putWord(value); + return resultId; + } + + + void SpirvModule::opControlBarrier( + uint32_t execution, + uint32_t memory, + uint32_t semantics) { + m_code.putIns (spv::OpControlBarrier, 4); + m_code.putWord(execution); + m_code.putWord(memory); + m_code.putWord(semantics); + } + + + void SpirvModule::opMemoryBarrier( + uint32_t memory, + uint32_t semantics) { + m_code.putIns (spv::OpMemoryBarrier, 3); + m_code.putWord(memory); + m_code.putWord(semantics); + } + + + void SpirvModule::opLoopMerge( + uint32_t mergeBlock, + uint32_t continueTarget, + uint32_t loopControl) { + m_code.putIns (spv::OpLoopMerge, 4); + m_code.putWord(mergeBlock); + m_code.putWord(continueTarget); + m_code.putWord(loopControl); + } + + + void SpirvModule::opSelectionMerge( + uint32_t mergeBlock, + uint32_t selectionControl) { + m_code.putIns (spv::OpSelectionMerge, 3); + m_code.putWord(mergeBlock); + m_code.putWord(selectionControl); + } + + + void SpirvModule::opBranch( + uint32_t label) { + m_code.putIns (spv::OpBranch, 2); + m_code.putWord(label); + + m_blockId = 0; + } + + + void SpirvModule::opBranchConditional( + uint32_t condition, + uint32_t trueLabel, + uint32_t falseLabel) { + m_code.putIns (spv::OpBranchConditional, 4); + m_code.putWord(condition); + m_code.putWord(trueLabel); + m_code.putWord(falseLabel); + + m_blockId = 0; + } + + + void SpirvModule::opSwitch( + uint32_t selector, + uint32_t jumpDefault, + uint32_t caseCount, + const SpirvSwitchCaseLabel* caseLabels) { + m_code.putIns (spv::OpSwitch, 3 + 2 * caseCount); + m_code.putWord(selector); + m_code.putWord(jumpDefault); + + for (uint32_t i = 0; i < caseCount; i++) { + m_code.putWord(caseLabels[i].literal); + m_code.putWord(caseLabels[i].labelId); + } + + m_blockId = 0; + } + + + uint32_t SpirvModule::opPhi( + uint32_t resultType, + uint32_t sourceCount, + const SpirvPhiLabel* sourceLabels) { + uint32_t resultId = this->allocateId(); + + m_code.putIns (spv::OpPhi, 3 + 2 * sourceCount); + m_code.putWord(resultType); + m_code.putWord(resultId); + + for (uint32_t i = 0; i < sourceCount; i++) { + m_code.putWord(sourceLabels[i].varId); + m_code.putWord(sourceLabels[i].labelId); + } + + return resultId; + } + + + void SpirvModule::opReturn() { + m_code.putIns (spv::OpReturn, 1); + m_blockId = 0; + } + + + void SpirvModule::opDemoteToHelperInvocation() { + m_code.putIns (spv::OpDemoteToHelperInvocation, 1); + } + + + void SpirvModule::opEmitVertex( + uint32_t streamId) { + if (streamId == 0) { + m_code.putIns (spv::OpEmitVertex, 1); + } else { + m_code.putIns (spv::OpEmitStreamVertex, 2); + m_code.putWord(streamId); + } + } + + + void SpirvModule::opEndPrimitive( + uint32_t streamId) { + if (streamId == 0) { + m_code.putIns (spv::OpEndPrimitive, 1); + } else { + m_code.putIns (spv::OpEndStreamPrimitive, 2); + m_code.putWord(streamId); + } + } + + + void SpirvModule::opBeginInvocationInterlock() { + m_code.putIns(spv::OpBeginInvocationInterlockEXT, 1); + } + + + void SpirvModule::opEndInvocationInterlock() { + m_code.putIns(spv::OpEndInvocationInterlockEXT, 1); + } + + + uint32_t SpirvModule::opSinCos( + uint32_t x, + bool useBuiltIn) { + // We only operate on 32-bit floats here + uint32_t floatType = defFloatType(32); + uint32_t resultType = defVectorType(floatType, 2u); + + if (useBuiltIn) { + std::array members = { opSin(floatType, x), opCos(floatType, x) }; + return opCompositeConstruct(resultType, members.size(), members.data()); + } else { + uint32_t uintType = defIntType(32, false); + uint32_t sintType = defIntType(32, true); + uint32_t boolType = defBoolType(); + + // Normalize input to multiple of pi/4 + uint32_t xNorm = opFMul(floatType, opFAbs(floatType, x), constf32(4.0 / pi)); + + uint32_t xTrunc = opTrunc(floatType, xNorm); + uint32_t xFract = opFSub(floatType, xNorm, xTrunc); + + uint32_t xInt = opConvertFtoU(uintType, xTrunc); + + // Mirror input along x axis as necessary + uint32_t mirror = opINotEqual(boolType, opBitwiseAnd(uintType, xInt, constu32(1u)), constu32(0u)); + xFract = opSelect(floatType, mirror, opFSub(floatType, constf32(1.0f), xFract), xFract); + + // Compute taylor series for fractional part + uint32_t xFract_2 = opFMul(floatType, xFract, xFract); + uint32_t xFract_4 = opFMul(floatType, xFract_2, xFract_2); + uint32_t xFract_6 = opFMul(floatType, xFract_4, xFract_2); + + uint32_t taylor = opFMul(floatType, xFract_6, constf32(-sincosTaylorFactor(7))); + decorate(taylor, spv::DecorationNoContraction); + + taylor = opFFma(floatType, xFract_4, constf32(sincosTaylorFactor(5)), taylor); + decorate(taylor, spv::DecorationNoContraction); + + taylor = opFFma(floatType, xFract_2, constf32(-sincosTaylorFactor(3)), taylor); + decorate(taylor, spv::DecorationNoContraction); + + taylor = opFAdd(floatType, constf32(sincosTaylorFactor(1)), taylor); + decorate(taylor, spv::DecorationNoContraction); + + taylor = opFMul(floatType, taylor, xFract); + decorate(taylor, spv::DecorationNoContraction); + + // Compute co-function based on sin^2 + cos^2 = 1 + uint32_t coFunc = opSqrt(floatType, opFSub(floatType, constf32(1.0f), opFMul(floatType, taylor, taylor))); + + // Determine whether the taylor series was used for sine or cosine and assign the correct result + uint32_t funcIsSin = opIEqual(boolType, opBitwiseAnd(uintType, opIAdd(uintType, xInt, constu32(1u)), constu32(2u)), constu32(0u)); + + uint32_t sin = opSelect(floatType, funcIsSin, taylor, coFunc); + uint32_t cos = opSelect(floatType, funcIsSin, coFunc, taylor); + + // Determine whether sine is negative. Interpret the input as a + // signed integer in order to propagate signed zeroes properly. + uint32_t inputNeg = opSLessThan(boolType, opBitcast(sintType, x), consti32(0)); + + uint32_t sinNeg = opINotEqual(boolType, opBitwiseAnd(uintType, xInt, constu32(4u)), constu32(0u)); + sinNeg = opLogicalNotEqual(boolType, sinNeg, inputNeg); + + // Determine whether cosine is negative + uint32_t cosNeg = opINotEqual(boolType, opBitwiseAnd(uintType, opIAdd(uintType, xInt, constu32(2u)), constu32(4u)), constu32(0u)); + + sin = opSelect(floatType, sinNeg, opFNegate(floatType, sin), sin); + cos = opSelect(floatType, cosNeg, opFNegate(floatType, cos), cos); + + std::array members = { sin, cos }; + return opCompositeConstruct(resultType, members.size(), members.data()); + } + } + + + uint32_t SpirvModule::defType( + spv::Op op, + uint32_t argCount, + const uint32_t* argIds) { + // Since the type info is stored in the code buffer, + // we can use the code buffer to look up type IDs as + // well. Result IDs are always stored as argument 1. + for (auto ins : m_typeConstDefs) { + bool match = ins.opCode() == op + && ins.length() == 2 + argCount; + + for (uint32_t i = 0; i < argCount && match; i++) + match &= ins.arg(2 + i) == argIds[i]; + + if (match) + return ins.arg(1); + } + + // Type not yet declared, create a new one. + uint32_t resultId = this->allocateId(); + m_typeConstDefs.putIns (op, 2 + argCount); + m_typeConstDefs.putWord(resultId); + + for (uint32_t i = 0; i < argCount; i++) + m_typeConstDefs.putWord(argIds[i]); + return resultId; + } + + + uint32_t SpirvModule::defConst( + spv::Op op, + uint32_t typeId, + uint32_t argCount, + const uint32_t* argIds) { + // Avoid declaring constants multiple times + for (auto ins : m_typeConstDefs) { + bool match = ins.opCode() == op + && ins.length() == 3 + argCount + && ins.arg(1) == typeId; + + for (uint32_t i = 0; i < argCount && match; i++) + match &= ins.arg(3 + i) == argIds[i]; + + if (!match) + continue; + + uint32_t id = ins.arg(2); + + if (m_lateConsts.find(id) == m_lateConsts.end()) + return id; + } + + // Constant not yet declared, make a new one + uint32_t resultId = this->allocateId(); + m_typeConstDefs.putIns (op, 3 + argCount); + m_typeConstDefs.putWord(typeId); + m_typeConstDefs.putWord(resultId); + + for (uint32_t i = 0; i < argCount; i++) + m_typeConstDefs.putWord(argIds[i]); + return resultId; + } + + + void SpirvModule::instImportGlsl450() { + m_instExtGlsl450 = this->allocateId(); + const char* name = "GLSL.std.450"; + + m_instExt.putIns (spv::OpExtInstImport, 2 + m_instExt.strLen(name)); + m_instExt.putWord(m_instExtGlsl450); + m_instExt.putStr (name); + } + + + uint32_t SpirvModule::getMemoryOperandWordCount( + const SpirvMemoryOperands& op) const { + const uint32_t result + = ((op.flags & spv::MemoryAccessAlignedMask) ? 1 : 0) + + ((op.flags & spv::MemoryAccessMakePointerAvailableMask) ? 1 : 0) + + ((op.flags & spv::MemoryAccessMakePointerVisibleMask) ? 1 : 0); + + return op.flags ? result + 1 : 0; + } + + + void SpirvModule::putMemoryOperands( + const SpirvMemoryOperands& op) { + if (op.flags) { + m_code.putWord(op.flags); + + if (op.flags & spv::MemoryAccessAlignedMask) + m_code.putWord(op.alignment); + + if (op.flags & spv::MemoryAccessMakePointerAvailableMask) + m_code.putWord(op.makeAvailable); + + if (op.flags & spv::MemoryAccessMakePointerVisibleMask) + m_code.putWord(op.makeVisible); + } + } + + + uint32_t SpirvModule::getImageOperandWordCount(const SpirvImageOperands& op) const { + // Each flag may add one or more operands + const uint32_t result + = ((op.flags & spv::ImageOperandsBiasMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsLodMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsConstOffsetMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsGradMask) ? 2 : 0) + + ((op.flags & spv::ImageOperandsOffsetMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsConstOffsetsMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsSampleMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsMinLodMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsMakeTexelAvailableMask) ? 1 : 0) + + ((op.flags & spv::ImageOperandsMakeTexelVisibleMask) ? 1 : 0); + + // Add a DWORD for the operand mask if it is non-zero + return op.flags ? result + 1 : 0; + } + + + void SpirvModule::putImageOperands(const SpirvImageOperands& op) { + if (op.flags) { + m_code.putWord(op.flags); + + if (op.flags & spv::ImageOperandsBiasMask) + m_code.putWord(op.sLodBias); + + if (op.flags & spv::ImageOperandsLodMask) + m_code.putWord(op.sLod); + + if (op.flags & spv::ImageOperandsGradMask) { + m_code.putWord(op.sGradX); + m_code.putWord(op.sGradY); + } + + if (op.flags & spv::ImageOperandsConstOffsetMask) + m_code.putWord(op.sConstOffset); + + if (op.flags & spv::ImageOperandsOffsetMask) + m_code.putWord(op.gOffset); + + if (op.flags & spv::ImageOperandsConstOffsetsMask) + m_code.putWord(op.gConstOffsets); + + if (op.flags & spv::ImageOperandsSampleMask) + m_code.putWord(op.sSampleId); + + if (op.flags & spv::ImageOperandsMinLodMask) + m_code.putWord(op.sMinLod); + + if (op.flags & spv::ImageOperandsMakeTexelAvailableMask) + m_code.putWord(op.makeAvailable); + + if (op.flags & spv::ImageOperandsMakeTexelVisibleMask) + m_code.putWord(op.makeVisible); + } + } + + + bool SpirvModule::isInterfaceVar( + spv::StorageClass sclass) const { + if (m_version < spvVersion(1, 4)) { + return sclass == spv::StorageClassInput + || sclass == spv::StorageClassOutput; + } else { + // All global variables need to be declared + return sclass != spv::StorageClassFunction; + } + } + + + void SpirvModule::classifyBlocks( + std::unordered_set& reachableBlocks, + std::unordered_set& mergeBlocks) { + std::unordered_multimap branches; + std::queue blockQueue; + + uint32_t blockId = 0; + + for (auto ins : m_code) { + switch (ins.opCode()) { + case spv::OpLabel: { + uint32_t id = ins.arg(1); + + if (!blockId) + branches.insert({ 0u, id }); + + blockId = id; + } break; + + case spv::OpFunction: { + blockId = 0u; + } break; + + case spv::OpBranch: { + branches.insert({ blockId, ins.arg(1) }); + } break; + + case spv::OpBranchConditional: { + branches.insert({ blockId, ins.arg(2) }); + branches.insert({ blockId, ins.arg(3) }); + } break; + + case spv::OpSwitch: { + branches.insert({ blockId, ins.arg(2) }); + + for (uint32_t i = 4; i < ins.length(); i += 2) + branches.insert({ blockId, ins.arg(i) }); + } break; + + case spv::OpSelectionMerge: { + mergeBlocks.insert(ins.arg(1)); + } break; + + case spv::OpLoopMerge: { + mergeBlocks.insert(ins.arg(1)); + + // It is possible for the continue block to be unreachable in + // practice, but we still need to emit it if we are not going + // to eliminate this loop. Since the current block dominates + // the loop, use it to keep the continue block intact. + branches.insert({ blockId, ins.arg(2) }); + } break; + + default:; + } + } + + blockQueue.push(0); + + while (!blockQueue.empty()) { + uint32_t id = blockQueue.front(); + + auto range = branches.equal_range(id); + + for (auto i = range.first; i != range.second; i++) { + if (reachableBlocks.insert(i->second).second) + blockQueue.push(i->second); + } + + blockQueue.pop(); + } + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/util/util_log.cpp b/app/src/main/cpp/thirdparty/dxbc/src/util/util_log.cpp new file mode 100644 index 0000000000..e2dcfb803f --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/util/util_log.cpp @@ -0,0 +1,11 @@ +#include "log/log_debug.h" + +namespace dxvk::debug { + + std::string methodName(const std::string& prettyName) { + size_t end = prettyName.find("("); + size_t begin = prettyName.substr(0, end).rfind(" ") + 1; + return prettyName.substr(begin,end - begin); + } + +} diff --git a/app/src/main/cpp/thirdparty/dxbc/src/util/util_string.cpp b/app/src/main/cpp/thirdparty/dxbc/src/util/util_string.cpp new file mode 100644 index 0000000000..9bb4b61149 --- /dev/null +++ b/app/src/main/cpp/thirdparty/dxbc/src/util/util_string.cpp @@ -0,0 +1,234 @@ +#include "util_string.h" + +namespace dxvk::str { + + const uint8_t* decodeTypedChar( + const uint8_t* begin, + const uint8_t* end, + uint32_t& ch) { + uint32_t first = begin[0]; + + if (likely(first < 0x80)) { + // Basic ASCII character + ch = uint32_t(first); + return begin + 1; + } else if (unlikely(first < 0xC0)) { + // Character starts with a continuation byte, + // just skip until we find the next valid prefix + while ((begin < end) && (((*begin) & 0xC0) == 0x80)) + begin += 1; + + ch = uint32_t('?'); + return begin; + } else { + // The number of leading 1 bits in the first byte + // determines the length of this character + size_t length = bit::lzcnt((~first) << 24); + + if (unlikely(begin + length > end)) { + ch = uint32_t('?'); + return end; + } + + if (first < 0xE0) { + ch = ((uint32_t(begin[0]) & 0x1F) << 6) + | ((uint32_t(begin[1]) & 0x3F)); + } else if (first < 0xF0) { + ch = ((uint32_t(begin[0]) & 0x0F) << 12) + | ((uint32_t(begin[1]) & 0x3F) << 6) + | ((uint32_t(begin[2]) & 0x3F)); + } else if (first < 0xF8) { + ch = ((uint32_t(begin[0]) & 0x07) << 18) + | ((uint32_t(begin[1]) & 0x3F) << 12) + | ((uint32_t(begin[2]) & 0x3F) << 6) + | ((uint32_t(begin[3]) & 0x3F)); + } else { + // Invalid prefix + ch = uint32_t('?'); + } + + return begin + length; + } + } + + const uint16_t* decodeTypedChar( + const uint16_t* begin, + const uint16_t* end, + uint32_t& ch) { + uint32_t first = begin[0]; + + if (likely(first < 0xD800)) { + ch = first; + return begin + 1; + } else if (first < 0xDC00) { + if (unlikely(begin + 2 > end)) { + ch = uint32_t('?'); + return end; + } + + ch = 0x10000 + + ((uint32_t(begin[0]) & 0x3FF) << 10) + + ((uint32_t(begin[1]) & 0x3FF)); + return begin + 2; + } else if (unlikely(first < 0xE000)) { + // Stray low surrogate + ch = uint32_t('?'); + return begin + 1; + } else { + ch = first; + return begin + 1; + } + } + + + const uint32_t* decodeTypedChar( + const uint32_t* begin, + const uint32_t* end, + uint32_t& ch) { + ch = begin[0]; + return begin + 1; + } + + + size_t encodeTypedChar( + uint8_t* begin, + uint8_t* end, + uint32_t ch) { + if (likely(ch < 0x80)) { + if (begin) { + if (unlikely(begin + 1 > end)) + return 0; + + begin[0] = uint8_t(ch); + } + + return 1; + } else if (ch < 0x800) { + if (begin) { + if (unlikely(begin + 2 > end)) + return 0; + + begin[0] = uint8_t(0xC0 | (ch >> 6)); + begin[1] = uint8_t(0x80 | (ch & 0x3F)); + } + + return 2; + } else if (ch < 0x10000) { + if (begin) { + if (unlikely(begin + 3 > end)) + return 0; + + begin[0] = uint8_t(0xE0 | ((ch >> 12))); + begin[1] = uint8_t(0x80 | ((ch >> 6) & 0x3F)); + begin[2] = uint8_t(0x80 | ((ch >> 0) & 0x3F)); + } + + return 3; + } else if (ch < 0x200000) { + if (begin) { + if (unlikely(begin + 4 > end)) + return 0; + + begin[0] = uint8_t(0xF0 | ((ch >> 18))); + begin[1] = uint8_t(0x80 | ((ch >> 12) & 0x3F)); + begin[2] = uint8_t(0x80 | ((ch >> 6) & 0x3F)); + begin[3] = uint8_t(0x80 | ((ch >> 0) & 0x3F)); + } + + return 4; + } else { + // Invalid code point for UTF-8 + return 0; + } + } + + + size_t encodeTypedChar( + uint16_t* begin, + uint16_t* end, + uint32_t ch) { + if (likely(ch < 0xD800)) { + if (begin) { + if (unlikely(begin + 1 > end)) + return 0; + + begin[0] = ch; + } + + return 1; + } else if (ch < 0xE000) { + // Private use code points, + // we can't encode these + return 0; + } else if (ch < 0x10000) { + if (begin) { + if (unlikely(begin + 1 > end)) + return 0; + + begin[0] = ch; + } + + return 1; + } else if (ch < 0x110000) { + if (begin) { + if (unlikely(begin + 2 > end)) + return 0; + + ch -= 0x10000; + begin[0] = uint16_t(0xD800 + (ch >> 10)); + begin[1] = uint16_t(0xDC00 + (ch & 0x3FF)); + } + + return 2; + } else { + // Invalid code point + return 0; + } + } + + + size_t encodeTypedChar( + uint32_t* begin, + uint32_t* end, + uint32_t ch) { + if (begin) { + if (unlikely(begin + 1 > end)) + return 0; + + begin[0] = ch; + } + + return 1; + } + + + std::string fromws(const wchar_t* ws) { + size_t srcLen = length(ws); + size_t dstLen = transcodeString( + nullptr, 0, ws, srcLen); + + std::string result; + result.resize(dstLen); + + transcodeString(result.data(), + dstLen, ws, srcLen); + + return result; + } + + + std::wstring tows(const char* mbs) { + size_t srcLen = length(mbs); + size_t dstLen = transcodeString( + nullptr, 0, mbs, srcLen); + + std::wstring result; + result.resize(dstLen); + + transcodeString(result.data(), + dstLen, mbs, srcLen); + + return result; + } + +} diff --git a/app/src/main/cpp/waylandcomp/CMakeLists.txt b/app/src/main/cpp/waylandcomp/CMakeLists.txt index 1f20d2c11e..b861762c55 100644 --- a/app/src/main/cpp/waylandcomp/CMakeLists.txt +++ b/app/src/main/cpp/waylandcomp/CMakeLists.txt @@ -72,6 +72,8 @@ if (TARGET dxbc AND EXISTS ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_pacer.cpp ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_governor.cpp + # The Lossless.dll import (validate / extract / cache) for the app's LsfgNative. + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_jni.cpp ${BANNER_FRAMEGEN_WINFG_DIR}/framegen.cpp ${BANNER_FRAMEGEN_WINFG_DIR}/winfg_vkd.cpp ${BANNER_FRAMEGEN_WINFG_DIR}/winfg_engine.cpp diff --git a/app/src/main/cpp/winlator/VulkanRendererContext.h b/app/src/main/cpp/winlator/VulkanRendererContext.h new file mode 100644 index 0000000000..22871f317c --- /dev/null +++ b/app/src/main/cpp/winlator/VulkanRendererContext.h @@ -0,0 +1,846 @@ +#pragma once +#include +#include +#include +struct VkTable { + + PFN_vkCreateInstance CreateInstance; + + PFN_vkDestroyInstance DestroyInstance; + PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; + PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties; + PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties; + PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR; + PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR; + PFN_vkGetPhysicalDeviceSurfacePresentModesKHR GetPhysicalDeviceSurfacePresentModesKHR; + PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties; + PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR; + PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties; + PFN_vkGetPhysicalDeviceFeatures2 GetPhysicalDeviceFeatures2; + PFN_vkCreateDevice CreateDevice; + PFN_vkDestroySurfaceKHR DestroySurfaceKHR; + PFN_vkCreateAndroidSurfaceKHR CreateAndroidSurfaceKHR; + + PFN_vkGetDeviceProcAddr GetDeviceProcAddr; + PFN_vkDestroyDevice DestroyDevice; + PFN_vkGetDeviceQueue GetDeviceQueue; + PFN_vkDeviceWaitIdle DeviceWaitIdle; + PFN_vkCreateSwapchainKHR CreateSwapchainKHR; + PFN_vkDestroySwapchainKHR DestroySwapchainKHR; + PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR; + PFN_vkAcquireNextImageKHR AcquireNextImageKHR; + PFN_vkQueuePresentKHR QueuePresentKHR; + PFN_vkQueueSubmit QueueSubmit; + PFN_vkCreateQueryPool CreateQueryPool; + PFN_vkDestroyQueryPool DestroyQueryPool; + PFN_vkCmdResetQueryPool CmdResetQueryPool; + PFN_vkCmdWriteTimestamp CmdWriteTimestamp; + PFN_vkGetQueryPoolResults GetQueryPoolResults; + PFN_vkCreateRenderPass CreateRenderPass; + PFN_vkDestroyRenderPass DestroyRenderPass; + PFN_vkCreateFramebuffer CreateFramebuffer; + PFN_vkDestroyFramebuffer DestroyFramebuffer; + PFN_vkCreateImageView CreateImageView; + PFN_vkDestroyImageView DestroyImageView; + PFN_vkCreateImage CreateImage; + PFN_vkDestroyImage DestroyImage; + PFN_vkCreateBuffer CreateBuffer; + PFN_vkDestroyBuffer DestroyBuffer; + PFN_vkAllocateMemory AllocateMemory; + PFN_vkFreeMemory FreeMemory; + PFN_vkMapMemory MapMemory; + PFN_vkFlushMappedMemoryRanges FlushMappedMemoryRanges; + PFN_vkBindBufferMemory BindBufferMemory; + PFN_vkBindImageMemory BindImageMemory; + PFN_vkGetBufferMemoryRequirements GetBufferMemoryRequirements; + PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements; + PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout; + PFN_vkDestroyDescriptorSetLayout DestroyDescriptorSetLayout; + PFN_vkCreateDescriptorPool CreateDescriptorPool; + PFN_vkDestroyDescriptorPool DestroyDescriptorPool; + PFN_vkAllocateDescriptorSets AllocateDescriptorSets; + PFN_vkFreeDescriptorSets FreeDescriptorSets; + PFN_vkUpdateDescriptorSets UpdateDescriptorSets; + PFN_vkCreatePipelineLayout CreatePipelineLayout; + PFN_vkDestroyPipelineLayout DestroyPipelineLayout; + PFN_vkCreateShaderModule CreateShaderModule; + PFN_vkDestroyShaderModule DestroyShaderModule; + PFN_vkCreateGraphicsPipelines CreateGraphicsPipelines; + PFN_vkDestroyPipeline DestroyPipeline; + PFN_vkCreateCommandPool CreateCommandPool; + PFN_vkDestroyCommandPool DestroyCommandPool; + PFN_vkAllocateCommandBuffers AllocateCommandBuffers; + PFN_vkFreeCommandBuffers FreeCommandBuffers; + PFN_vkBeginCommandBuffer BeginCommandBuffer; + PFN_vkEndCommandBuffer EndCommandBuffer; + PFN_vkResetCommandBuffer ResetCommandBuffer; + PFN_vkCmdBeginRenderPass CmdBeginRenderPass; + PFN_vkCmdEndRenderPass CmdEndRenderPass; + PFN_vkCmdBindPipeline CmdBindPipeline; + PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets; + PFN_vkCmdDraw CmdDraw; + PFN_vkCmdPushConstants CmdPushConstants; + PFN_vkCmdSetViewport CmdSetViewport; + PFN_vkCmdSetScissor CmdSetScissor; + PFN_vkCmdPipelineBarrier CmdPipelineBarrier; + PFN_vkCmdCopyImage CmdCopyImage; + PFN_vkCmdBlitImage CmdBlitImage; // frame-gen capture resolution: composite -> swapchain upscale + // Compute: the native LSFG chain is 25 compute dispatches. + PFN_vkCmdDispatch CmdDispatch; + PFN_vkCreateComputePipelines CreateComputePipelines; + PFN_vkUnmapMemory UnmapMemory; + // win-fg native: clears its flow scratch, resets its scratch pool on resize. + PFN_vkCmdClearColorImage CmdClearColorImage; + PFN_vkResetDescriptorPool ResetDescriptorPool; + PFN_vkCmdCopyBufferToImage CmdCopyBufferToImage; + PFN_vkCreateSampler CreateSampler; + PFN_vkDestroySampler DestroySampler; + PFN_vkCreateSemaphore CreateSemaphore; + PFN_vkDestroySemaphore DestroySemaphore; + PFN_vkCreateFence CreateFence; + PFN_vkDestroyFence DestroyFence; + PFN_vkWaitForFences WaitForFences; + PFN_vkResetFences ResetFences; + PFN_vkGetFenceStatus GetFenceStatus; + + PFN_vkGetAndroidHardwareBufferPropertiesANDROID GetAndroidHardwareBufferPropertiesANDROID; +}; + +#include +#include +#define WLOG_TAG "Winlator_Renderer" +#define RLOG(...) if(verboseLog) __android_log_print(ANDROID_LOG_DEBUG,WLOG_TAG,__VA_ARGS__) +#define RLOG_E(...) __android_log_print(ANDROID_LOG_ERROR,WLOG_TAG,__VA_ARGS__) +#define SCANOUT_LOG(...) __android_log_print(ANDROID_LOG_DEBUG,"Winlator_Scanout",__VA_ARGS__) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Renderer-neutral direct-scanout impl (owns the SurfaceControl/AHB state). +// Included after SCANOUT_LOG is defined above; its own definition is guarded. +#include "../scanout/ScanoutContext.h" + +// Native (compositor-side) LSFG frame generation — capability gate. +#include "lsfg/lsfg_probe.h" +#include +#include + +namespace lsfg { class Engine; } +namespace winfg { class Engine; } + +static constexpr uint32_t MAX_FRAMES_IN_FLIGHT = 2; + +struct WindowPushConstants { float ndcX0, ndcY0, ndcX1, ndcY1; int useTexAlpha; }; + +// Push-constant layouts for the spatial-upscaler post passes. The leading vec4 +// `ndc` matches upscale.vert; the remaining members are read only by the +// fragment stage. std430 offsets line up with these C structs. +struct SgsrPushConstants { // 36 bytes + float ndc[4]; + float viewportInfo[4]; // xy = 1/inputSize, zw = inputSize px + float edgeSharpness; // SGSR EdgeSharpness, from the slider +}; +struct NisPushConstants { // 36 bytes + float ndc[4]; + float viewportInfo[4]; // xy = 1/inputSize, zw = inputSize px + float sharpness; // NIS sharpness [0..1], from the slider +}; +struct EasuPushConstants { // 88 bytes + float ndc[4]; + uint32_t con0[4], con1[4], con2[4], con3[4]; + float outW, outH; +}; +struct RcasPushConstants { // 40 bytes + float ndc[4]; + uint32_t con[4]; // con.x = bit-packed sharpness + float outW, outH; +}; +struct DownscalePushConstants { // 32 bytes + float ndc[4]; + float srcW, srcH; // render (source) resolution + float dstW, dstH; // display (output) resolution +}; +// Composable post effects (AMD CAS sharpen + fake-HDR). Both lead with vec4 ndc +// (offset 0) like the upscaler PCs and stay well under the 88-byte PC range. +struct CasPushConstants { // 32 bytes + float ndc[4]; + float resolution[2]; // input texture size in px + float sharpness; // CAS SHARPNESS term [0..1] + float _pad; +}; +struct HdrPushConstants { // 24 bytes + float ndc[4]; + float resolution[2]; // input texture size in px +}; +// Phase 2 screen effects ported from the GL EffectComposer. Each leads with vec4 +// ndc (offset 0) like the upscaler PCs and stays well under the 88-byte PC range. +struct FxaaPushConstants { // 24 bytes + float ndc[4]; + float resolution[2]; // input texture size in px +}; +struct ToonPushConstants { // 24 bytes + float ndc[4]; + float resolution[2]; // input texture size in px +}; +struct ColorPushConstants { // 32 bytes + float ndc[4]; + float brightness; // additive [-1,1] + float contrast; // [0,2] + float gamma; // [0.1,5] + float saturation; // [0,2]; 1 = unchanged, 0 = greyscale. + // APPENDED last so the three offsets above + // stay where color.frag already had them. +}; +struct NtscPushConstants { // 28 bytes + float ndc[4]; + float resolution[2]; // screen size in px (TextureSize/resolution) + float frameCount; // animated chroma-phase counter +}; +struct CrtPushConstants { // 24 bytes + float ndc[4]; + float resolution[2]; // input texture size in px (unused by shader) +}; +struct DebandPushConstants { // 28 bytes + float ndc[4]; + float resolution[2]; // input texture size in px (layout parity) + float strength; // dither amplitude in LSBs (1.0 = +/-1/255) +}; + +class VulkanRendererContext { +public: + // `lsfgVk11Compat` (experimental) lets the LSFG capability probe accept a + // Vulkan 1.1/1.2 device that offers the extensions the chain needs; it has + // to be known before vkCreateDevice, hence a constructor argument. + VulkanRendererContext(ANativeWindow* window, int cWidth, int cHeight, void* adrenotoolsHandle = nullptr, + bool lsfgVk11Compat = false); + ~VulkanRendererContext(); + + void onSurfaceResized(int width, int height); + void setTransform(float ox, float oy, float sx, float sy); + // #413: game-region clip rect (surface px). Stored and applied as the swapchain scissor in + // recordCmdBuf so a FILL/STRETCH game confined to a half (TOP/BOTTOM alignment) can't bleed into + // the on-screen-controls half. A full-surface (or w<=0) rect means "no clip" (CENTER). + void setClipRegion(int x, int y, int w, int h); + void updatePointerPosition(short x, short y); + void updateWindowContent(int64_t id, void* pixels, short w, short h, short stride, int x, int y); + void updateWindowContentAHB(int64_t id, AHardwareBuffer* ahb, short w, short h, int x, int y); + void updateCursorImage(void* pixels, short w, short h, short hotX, short hotY); + void setCursorVisible(bool visible); + void setRenderList(const int64_t* ids, const int* xs, const int* ys, int count); + void removeWindow(int64_t id); + void clearBackbuffer() {} + void beginBatch() {} + void endBatch() {} + void initScanout(); + void destroyScanout(); + void applyScanoutBuffer(); + void initScanoutFromWindows(ANativeWindow* gameWin, ANativeWindow* cursorWin); + void scanoutSetDst(int x, int y, int w, int h); + void scanoutSetBuffer(AHardwareBuffer* ahb, int x, int y, int w, int h, int fenceFd = -1); + void scanoutSetCursorImage(void* pixels, short w, short h, short stride); + void scanoutSetCursorPos(short x, short y, short hotX, short hotY); + // The renderer-neutral scanout implementation. The scanout methods above are + // thin forwarders to this (see VulkanRendererScanout.cpp); the cursor render- + // thread signalling stays in the forwarders, not in ScanoutContext. + ScanoutContext scanout; + // Bound to scanout's atomics so the existing JNI ABI (r->scanoutActive / + // r->gameFrameDelivered direct member access) keeps compiling against a + // single source of truth. Must be declared after `scanout`. + std::atomic& scanoutActive = scanout.scanoutActive; + std::atomic& gameFrameDelivered = scanout.gameFrameDelivered; + std::atomic surfaceDetached{false}; + + void detachSurface(); + bool reattachSurface(ANativeWindow* newWindow); + + bool verboseLog = true; + void setVerboseLog(bool v) { verboseLog = v; scanout.setVerboseLog(v); } + void dumpRendererInfo(); + + std::string adrenoDriverPath; + std::string adrenoDriverName; + std::string adrenoNativeLibDir; + void* vulkanHandle = nullptr; + std::atomic scanoutBlackFrameDone{false}; + PFN_vkGetInstanceProcAddr gipa = nullptr; + VkTable vk_ = {}; + void loadCustomDriver(); + void loadInstanceDispatch(); + void loadDeviceDispatch(); + + void setFilterMode(int mode); + void setUpscaler(int mode); + void setHqDownscale(bool enabled); + void setCas(bool enabled, int sharpness); + void setHdr(bool enabled); + void setDeband(bool enabled, int strength); + void setUpscaleSharpness(int sharpness); + void setFxaa(bool enabled); + void setToon(bool enabled); + void setCrt(bool enabled); + void setNtsc(bool enabled); + void setColorGrade(float brightness, float contrast, float gamma, float saturation); + void setSwapRB(bool enabled); + void setPresentMode(VkPresentModeKHR mode); + std::vector getSupportedPresentModes() const; + + // --- Native LSFG frame generation ------------------------------------- + // Capability verdict for the compositor-side LSFG engine. Filled at device + // creation and completed once the swapchain format is known; read by the + // UI (through JNI) to grey the engine out with a reason. + const lsfg::Caps& lsfgCaps() const { return lsfgCaps_; } + + // Arm/disarm native LSFG frame generation for this session. Changing the + // armed state recreates the swapchain, because the composite path needs + // TRANSFER_DST usage and a deeper image queue that a normal session does + // not pay for. + void setFrameGenArmed(bool armed, int multiplier); + bool frameGenArmed() const { return fgArmed_.load(std::memory_order_relaxed); } + // Live frame-gen telemetry for the in-game readout: + // [0] generations the governor currently trusts + // [1] generations actually planned for the last source frame + // [2] measured source (real) frames per second + // [3] measured presented frames per second + // [4] thermal status, -1 when the device gives no signal + // [5] GPU milliseconds the chain spends per generated frame, -1 unknown + void frameGenStats(float out[6]) const; + // Why the selected native frame-gen engine cannot run here, for the UI: + // -1 not known yet (caps not probed), 0 fine, 1 this driver lacks what the + // engine needs (lsfgCaps().reason says which gate), 2 the engine failed to start. + int frameGenProblem() const; + // Path to the SPIR-V cache built from the user's Lossless.dll. Setting it + // drops any existing engine so the next armed frame rebuilds from it. + void setLsfgCachePath(const char* path); + // Flow scale (0.25-1.0) and the panel's real refresh rate. The pacer never + // generates above the refresh rate. + // Experimental: `captureHeight` sizes the composite ring the chain runs on, + // the width following the swapchain's aspect, so a phone GPU generates at + // game-like resolution and the result is blitted up. 0 = panel; + // kFgCaptureGame = the X screen's height (containerHeight), which already + // carries the per-game override and render scale; otherwise a pixel height. + static constexpr int32_t kFgCaptureGame = -1; + void setFrameGenTuning(float flowScale, float refreshHz, int32_t captureHeight = 0); + // Which native engine generates: 0 = LSFG (needs the cache built from the + // user's Lossless.dll), 1 = win-fg (our own chain, embedded, needs nothing). + // Switching drops the other engine so only one ever holds GPU resources. + void setFrameGenEngine(int kind); + // win-fg only: interpolation model (3/4) and performance preset (0..2). + void setWinFgTuning(int model, int perfPreset); + +private: + struct WinTex { + VkImage img = VK_NULL_HANDLE; + VkDeviceMemory mem = VK_NULL_HANDLE; + VkImageView view = VK_NULL_HANDLE; + VkDescriptorSet ds = VK_NULL_HANDLE; + VkBuffer stg = VK_NULL_HANDLE; + VkDeviceMemory stgMem = VK_NULL_HANDLE; + void* mapped = nullptr; + VkDeviceSize cap = 0; + int w = 0; + int h = 0; + bool dirty = false; + bool isAHB = false; + bool needsTransition = false; + AHardwareBuffer* ahb = nullptr; + }; + + struct RenderEntry { int64_t id; int x, y; }; + struct DrawEntry { + VkImage img = VK_NULL_HANDLE; + VkDescriptorSet ds = VK_NULL_HANDLE; + VkBuffer upload = VK_NULL_HANDLE; + int x=0, y=0, w=0, h=0; + bool needsTransition = false; + bool isAHB = false; + }; + + ANativeWindow* window; + int surfaceWidth, surfaceHeight, containerWidth, containerHeight; + // #413 compositor clip rect (surface px). clipRegionW<=0 => disabled (whole swapchain). Written from + // the renderer thread (setClipRegion), read from the render thread (recordCmdBuf) -> atomic. + std::atomic clipRegionX{0}, clipRegionY{0}, clipRegionW{0}, clipRegionH{0}; + void* adrenotoolsHandle = nullptr; + bool lsfgVk11Compat_ = false; // see the constructor + int filterMode = 0; + bool swapRB = false; + float maxAnisotropy = 1.0f; + bool cubicSupported = false; + VkPhysicalDeviceMemoryProperties memProperties{}; + VkPresentModeKHR requestedPresentMode = VK_PRESENT_MODE_FIFO_KHR; + uint32_t graphicsQueueFamilyIndex = 0; + std::vector availablePresentModes; + + std::unordered_map texMap; + + std::unordered_map ahbImportCache; + std::unordered_map> windowAhbs; + + std::vector deleteQueue; + std::vector renderList; + + std::vector frameDraws; + std::vector frameAhbTransitions; + std::vector framePreUpload; + std::vector framePostUpload; + + // [P0] All SurfaceControl / AHardwareBuffer scanout state moved to + // ScanoutContext (member `scanout` above). Dead members (lastDst*, + // ScanoutPending/scanoutPending*, fnSTSetBackPressure) were dropped. + + std::atomic pointerX{0}, pointerY{0}; + float sceneOffsetX=0.f, sceneOffsetY=0.f, sceneScaleX=1.f, sceneScaleY=1.f; + + std::atomic cursorVisible{false}; + short cursorHotX=0, cursorHotY=0, cursorTexW=0, cursorTexH=0; + std::vector cursorPixels; + std::atomic isCursorImageDirty{false}; + std::atomic cursorMoved{false}; + + VkImage cursorImg = VK_NULL_HANDLE; + VkDeviceMemory cursorMem = VK_NULL_HANDLE; + VkImageView cursorView = VK_NULL_HANDLE; + VkDescriptorSet cursorDS = VK_NULL_HANDLE; + VkBuffer cursorStg = VK_NULL_HANDLE; + VkDeviceMemory cursorStgM = VK_NULL_HANDLE; + void* cursorStgP = nullptr; + VkDeviceSize cursorStgC = 0; + VkDeviceSize cursorUploadSize = 0; + + VkInstance instance; + VkSurfaceKHR surface; + VkPhysicalDevice physicalDevice; + VkDevice device; + VkQueue graphicsQueue; + VkSwapchainKHR swapchain = VK_NULL_HANDLE; + VkFormat swapchainFmt; + VkExtent2D swapchainExt; + + std::vector swapchainImages; + std::vector swapchainViews; + std::vector swapchainFBs; + + VkRenderPass renderPass = VK_NULL_HANDLE; + VkDescriptorSetLayout dsLayout = VK_NULL_HANDLE; + VkPipelineLayout pipeLayout = VK_NULL_HANDLE; + + VkPipeline pipeline = VK_NULL_HANDLE; + + // ---- Spatial upscaler (SGSR / FSR1) ---- + // upscalerMode enum (mirrored by JNI nativeSetUpscaler): + // 0 = none (passthrough; current sampler governs scaling) + // 1 = linear (rebuild base sampler LINEAR; no shader pass) + // 2 = nearest (rebuild base sampler NEAREST; no shader pass) + // 3 = sgsr (Snapdragon GSR 1.0; single pass; aspect-fit / letterbox) + // 4 = fsr (AMD FSR1 EASU+RCAS; two passes; fill / stretch) + // 5 = fsr_fit (AMD FSR1 EASU+RCAS; two passes; aspect-fit / letterbox) + // 6 = sharpen (RCAS-only; any resolution; aspect-fit / letterbox) + // 7 = nis (NVIDIA Image Scaling NVScaler; single pass; aspect-fit) + // 8 = sgsr_quality (SGSR 1 edge-direction variant; single pass; aspect-fit) + // Shader upscaling only engages for modes 3-8 AND when the game render + // resolution (container) is smaller than the swapchain. Otherwise the + // existing direct-to-swapchain path is used unchanged. + int upscalerMode = 0; + // Independent of upscalerMode: high-quality Lanczos downscale for the + // supersampling case (game render res > display res). When enabled and the + // render res exceeds the swapchain, replaces the bilinear minify with a + // proper downscale pass. Supersampling and the upscale modes are mutually + // exclusive in practice (one is render>display, the other render CAS SHARPNESS + bool hdrEnabled = false; + float upscaleSharpness01 = 0.75f; // slider/100; RCAS lobe scale, SGSR edge derived + // Debanding: terminal TPDF/IGN dither pass before the 8-bit swapchain quantize. + bool debandEnabled = false; + int debandStrength = 100; // slider 0..200 -> strength/100 LSBs + + // Phase 2 screen effects (GL EffectComposer parity). FXAA/Toon/CRT/NTSC are + // binary; Color is the brightness/contrast/gamma grade (always-applied via the + // sliders, no toggle) and is "enabled" only when not at neutral (0,0,1). + bool fxaaEnabled = false; + bool toonEnabled = false; + bool crtEnabled = false; + bool ntscEnabled = false; + bool colorEnabled = false; // derived: !neutral grade + float colorBrightness = 0.0f; // [-1,1] (slider/100, clamped) + float colorContrast = 0.0f; // [0,2] (slider/100, clamped) + float colorGamma = 1.0f; // [0.1,5] + float colorSaturation = 1.0f; // [0,2] (slider/100, clamped) + uint32_t ntscFrameCounter = 0; // animates NTSC chroma phase + + VkSampler upscaleSampler = VK_NULL_HANDLE; // linear clamp; offscreen/mid input + + // === Native LSFG: composite target ring =================================== + // Frame generation cannot composite straight into a swapchain image: the + // finished frame has to be READABLE (it becomes the next frame's LSFG + // input) and generated frames have to be STORAGE-WRITABLE by a compute + // dispatch. Android swapchain images are COLOR_ATTACHMENT only, and + // storage support on a swapchain format is not something a driver owes us. + // + // So when frame gen is armed the whole existing recording is redirected at + // a composite image we own — format-identical to the swapchain, so every + // existing pipeline stays render-pass compatible — and a copy moves it into + // the acquired swapchain image at the end. With frame gen off, not one of + // these objects is created and the direct-to-swapchain path is untouched. + struct CompositeTarget { + VkImage img = VK_NULL_HANDLE; + VkDeviceMemory mem = VK_NULL_HANDLE; + VkImageView view = VK_NULL_HANDLE; // colour attachment + sampled + VkImageView storageView = VK_NULL_HANDLE; // compute writes (generate) + VkFramebuffer fb = VK_NULL_HANDLE; + VkDescriptorSet ds = VK_NULL_HANDLE; // sampled, for later passes + }; + // Hard ceiling: (max generations + 1) presentable frames per source frame, + // times a queue depth of 2, capped so the footprint stays bounded. + static constexpr uint32_t kMaxCompositeTargets = 7; + + std::vector compositeTargets; + VkRenderPass compositeRenderPass = VK_NULL_HANDLE; // CLEAR -> GENERAL + uint32_t compositeW = 0, compositeH = 0; + uint32_t compositeIndex = 0; // rotates per composite; gives history for free + bool compositeArmed = false; // targets exist AND this frame uses them + bool swapchainTransferDst = false; // swapchain was created with TRANSFER_DST + + // Set from the app when the native LSFG engine is selected for this + // session. Read on the render thread; false keeps every path as it was. + std::atomic fgArmed_{false}; + std::atomic fgMultiplier_{0}; + // Tuning is written by the UI thread and consumed by the render thread, so + // it is published through atomics and applied to the engine at the top of + // the frame-gen block. The UI thread never touches the engine itself. + std::atomic fgFlowScale_{1.0f}; + std::atomic fgRefreshHz_{0.0f}; + std::atomic fgConfigDirty_{true}; + // Experimental (see setFrameGenTuning): capture height of the composite + // ring. 0 = panel resolution, kFgCaptureGame = the X screen's height. + std::atomic fgCaptureHeight_{0}; + // Extent the composite ring should have for the current swapchain and + // capture height (width follows the swapchain aspect, both even). + void compositeExtentFor(uint32_t& w, uint32_t& h) const; + // The extent the scene is rendered at this frame: the composite ring while + // frame gen runs on a ring smaller than the swapchain (experimental capture + // resolution), otherwise the swapchain. Every full-target pass (the effect + // chain, the spatial upscalers, the render-scale downscale) sizes itself by + // this, so those keep working below panel resolution and their + // intermediates shrink with the ring. + VkExtent2D renderExtent() const { + if (compositeActive() && (compositeW != swapchainExt.width || compositeH != swapchainExt.height)) + return VkExtent2D{compositeW, compositeH}; + return swapchainExt; + } + // Copy (same extent) or blit (composite smaller than the swapchain) a + // composite-ring image, already in TRANSFER_SRC, into a swapchain image + // already in TRANSFER_DST. + void recordCompositeToSwapchainTransfer(VkCommandBuffer cb, VkImage src, uint32_t imgIdx); + + bool createCompositeRenderPass(); + bool ensureCompositeTargets(uint32_t w, uint32_t h, uint32_t count); + void destroyCompositeTargets(); + // True when this frame should composite off-swapchain. Call on the render + // thread; every gate must hold or we fall back to the untouched path. + bool compositeActive() const; + // Render pass / framebuffer this frame draws its FINAL pass into. + VkRenderPass targetRenderPass() const; + VkFramebuffer targetFramebuffer(uint32_t imgIdx) const; + // Copy the finished composite into the acquired swapchain image and leave + // it in PRESENT_SRC. No-op when the composite path is not active. + void copyCompositeToSwapchain(VkCommandBuffer cb, uint32_t imgIdx); + + // === Native LSFG: the software cursor ==================================== + // LSFG interpolates whatever it is given, so a cursor composited into the + // frame gets warped along the flow field and smears. It is therefore + // excluded from the composite while frame gen is armed and drawn once into + // EVERY presented image instead - real and generated alike - through a + // load-op render pass that leaves the image ready to present. + VkRenderPass cursorOverlayRenderPass = VK_NULL_HANDLE; + struct CursorOverlay { + bool draw = false; + float ox = 0, oy = 0, sx = 0, sy = 0, cw = 0, ch = 0; + short ptrX = 0, ptrY = 0, hotX = 0, hotY = 0, w = 0, h = 0; + }; + CursorOverlay cursorOverlay_{}; + + bool createCursorOverlayRenderPass(); + // Draw the cursor into an already-copied swapchain image and leave it in + // PRESENT_SRC. Takes over the final transition from the copy helpers. + void recordCursorOverlay(VkCommandBuffer cb, uint32_t imgIdx); + // True when the cursor is being drawn per present rather than composited. + bool cursorDrawnPerPresent() const; + + // === Native LSFG: the per-source-frame present plan ======================= + // Interpolation produces frames that belong BETWEEN N-1 and N, so the + // generated frames are presented FIRST and real frame N is held back one + // slot. All presents for one source frame are queued together: with FIFO + // the driver then shows them on consecutive vblanks, so the pacing falls + // out of the present mode for free - no sleeps, no render-mode change. + static constexpr uint32_t kMaxPresentsPerFrame = 4; // 1 real + up to 3 generated + struct FrameGenPlan { + uint32_t generations = 0; + uint32_t presents = 1; + uint32_t imgIdx[kMaxPresentsPerFrame] = {}; + }; + FrameGenPlan fgPlan_{}; + std::unique_ptr lsfgEngine_; + uint64_t fgSourceFrames_ = 0; + std::string lsfgCachePath_; + bool lsfgEngineTried_ = false; + std::unique_ptr winfgEngine_; + bool winfgEngineTried_ = false; + std::atomic fgEngineKind_{0}; // 0 = lsfg, 1 = win-fg + std::atomic fgModel_{4}; + std::atomic fgPerfPreset_{1}; + bool ensureWinFgEngine(); + // Capability gate for the SELECTED engine. win-fg's shaders need only a + // storage-capable swapchain format; the LSFG chain also needs the fp16 / + // memory-model feature set, which some otherwise capable GPUs lack. + bool fgCapsOk() const; + + // Sync objects are indexed per PRESENT, not per composite: each pending + // present needs its own image-available and render-finished semaphore. + uint32_t syncSlot(uint32_t k) const { return currentFrame * kMaxPresentsPerFrame + k; } + // Destroy and rebuild every acquire/present semaphore. Called with the + // swapchain, so no stale pending signal can survive into the new one. + void recreateSyncObjects(); + uint32_t fgAcquireFailLog_ = 0; + + // Measured PRESENTS per second - the rate that actually reaches the panel, + // counting generated frames. The pacer's own "loop rate" cannot serve this + // purpose: it is sampled once per SOURCE frame, so it always equals the + // guest rate and contains no evidence that generation happened at all. + float fgPresentedRate_ = 0.0f; + // Measured SOURCE frames per second over the same window, for engines that + // do not measure it themselves (win-fg). + float fgSourceRate_ = 0.0f; + uint32_t fgSourceAccum_ = 0; + uint32_t fgPresentAccum_ = 0; + std::chrono::steady_clock::time_point fgRateWindowStart_{}; + bool fgRateWindowOpen_ = false; + void trackPresentedRate(uint32_t presents); + + bool ensureLsfgEngine(); + // One command buffer per pending present: slot 0 carries the composite, + // the chain's shared passes and generated frame 0; each later generated + // frame and the real frame are recorded and submitted on their own, so a + // finished frame reaches the presentation engine without waiting for the + // rest of the chain. + uint32_t cmdSlot(uint32_t k) const { return currentFrame * kMaxPresentsPerFrame + k; } + // Shared chain passes (the 24 shaders every generated frame depends on). + void recordFrameGenProcess(VkCommandBuffer cb); + // Generated frame g: synthesise into a spare composite target and copy it + // into the swapchain image reserved for it. + void recordFrameGenGeneration(VkCommandBuffer cb, uint32_t g); + + // Chain cost: a timestamp pair per frame slot, start before the shared + // passes, end after the last generation's compute (before its copy, so a + // vblank wait on the swapchain image is not counted). Read back after the + // slot's fence wait, one frame later. + VkQueryPool fgQueryPool_ = VK_NULL_HANDLE; + bool fgTimestampsOk_ = false; + float fgTimestampPeriodNs_ = 0.0f; + bool fgQueryPending_[MAX_FRAMES_IN_FLIGHT] = {}; + uint32_t fgQueryGens_[MAX_FRAMES_IN_FLIGHT] = {}; + float fgChainMsPerGen_ = -1.0f; + uint32_t fgChainLogCount_ = 0; + void ensureFgQueryPool(); + void destroyFgQueryPool(); + void readFgQueryResult(); + + VkFormat offscreenFmt = VK_FORMAT_R8G8B8A8_UNORM; + VkRenderPass offscreenRenderPass = VK_NULL_HANDLE; // CLEAR -> SHADER_READ_ONLY + VkPipelineLayout postPipeLayout = VK_NULL_HANDLE; + VkPipeline sgsrPipeline = VK_NULL_HANDLE; + VkPipeline nisPipeline = VK_NULL_HANDLE; // NVIDIA Image Scaling (mode 7) + VkPipeline sgsrQualityPipeline = VK_NULL_HANDLE; // SGSR 1 edge-direction (mode 8) + VkPipeline easuPipeline = VK_NULL_HANDLE; + VkPipeline rcasPipeline = VK_NULL_HANDLE; + VkPipeline downscalePipeline = VK_NULL_HANDLE; + // CAS/HDR can be either a non-final pass (writes an fx target via + // offscreenRenderPass) or the final pass (writes the swapchain via renderPass); + // a pipeline is render-pass-specific, so keep one variant of each. + VkPipeline casPipelineOff = VK_NULL_HANDLE; // -> fx target (offscreenRenderPass) + VkPipeline casPipelineSwap = VK_NULL_HANDLE; // -> swapchain (renderPass) + VkPipeline hdrPipelineOff = VK_NULL_HANDLE; + VkPipeline hdrPipelineSwap = VK_NULL_HANDLE; + // Phase 2 effects: same Off (-> fx target) / Swap (-> swapchain) variant pair. + VkPipeline fxaaPipelineOff = VK_NULL_HANDLE; + VkPipeline fxaaPipelineSwap = VK_NULL_HANDLE; + VkPipeline toonPipelineOff = VK_NULL_HANDLE; + VkPipeline toonPipelineSwap = VK_NULL_HANDLE; + VkPipeline colorPipelineOff = VK_NULL_HANDLE; + VkPipeline colorPipelineSwap = VK_NULL_HANDLE; + VkPipeline ntscPipelineOff = VK_NULL_HANDLE; + VkPipeline ntscPipelineSwap = VK_NULL_HANDLE; + VkPipeline crtPipelineOff = VK_NULL_HANDLE; + VkPipeline crtPipelineSwap = VK_NULL_HANDLE; + // Debanding is always the LAST effect (terminal) -> only a swapchain variant. + VkPipeline debandPipelineSwap = VK_NULL_HANDLE; + + // offscreen composite target @ game/container resolution + VkImage offscreenImg = VK_NULL_HANDLE; + VkDeviceMemory offscreenMem = VK_NULL_HANDLE; + VkImageView offscreenView = VK_NULL_HANDLE; + VkFramebuffer offscreenFB = VK_NULL_HANDLE; + VkDescriptorSet offscreenDS = VK_NULL_HANDLE; + int offscreenW = 0, offscreenH = 0; + + // FSR intermediate (EASU output) @ upscale output resolution + VkImage midImg = VK_NULL_HANDLE; + VkDeviceMemory midMem = VK_NULL_HANDLE; + VkImageView midView = VK_NULL_HANDLE; + VkFramebuffer midFB = VK_NULL_HANDLE; + VkDescriptorSet midDS = VK_NULL_HANDLE; + int midW = 0, midH = 0; + + // Effect-chain intermediates @ swapchain resolution. fx1 holds the scaled (or + // composited) image fed into CAS/HDR; fx2 ping-pongs when both effects run. + VkImage fx1Img = VK_NULL_HANDLE; + VkDeviceMemory fx1Mem = VK_NULL_HANDLE; + VkImageView fx1View = VK_NULL_HANDLE; + VkFramebuffer fx1FB = VK_NULL_HANDLE; + VkDescriptorSet fx1DS = VK_NULL_HANDLE; + int fx1W = 0, fx1H = 0; + + VkImage fx2Img = VK_NULL_HANDLE; + VkDeviceMemory fx2Mem = VK_NULL_HANDLE; + VkImageView fx2View = VK_NULL_HANDLE; + VkFramebuffer fx2FB = VK_NULL_HANDLE; + VkDescriptorSet fx2DS = VK_NULL_HANDLE; + int fx2W = 0, fx2H = 0; + + // Per-frame upscale plan, computed in renderFrame, consumed by recordCmdBuf. + // upFrame.mode reuses the upscalerMode enum (3=sgsr,4=fsr,5=fsr_fit,6=sharpen,7=nis,8=sgsr_quality) + // plus an internal sentinel (UPMODE_DOWNSCALE) for the supersampling path. + struct UpscaleFrame { + bool active = false; + int mode = 0; + int outX = 0, outY = 0, outW = 0, outH = 0; + bool cas = false; // run CAS this frame (snapshot of casEnabled) + bool hdr = false; // run HDR this frame (snapshot of hdrEnabled) + bool fxaa = false; // snapshot of fxaaEnabled + bool toon = false; // snapshot of toonEnabled + bool color = false; // snapshot of colorEnabled (non-neutral grade) + bool ntsc = false; // snapshot of ntscEnabled + bool crt = false; // snapshot of crtEnabled + bool deband = false;// snapshot of debandEnabled (terminal dither) + SgsrPushConstants sgsrPC{}; + NisPushConstants nisPC{}; + EasuPushConstants easuPC{}; + RcasPushConstants rcasPC{}; + DownscalePushConstants dsPC{}; + CasPushConstants casPC{}; + HdrPushConstants hdrPC{}; + FxaaPushConstants fxaaPC{}; + ToonPushConstants toonPC{}; + ColorPushConstants colorPC{}; + NtscPushConstants ntscPC{}; + CrtPushConstants crtPC{}; + DebandPushConstants debandPC{}; + } upFrame; + + VkCommandPool cmdPool = VK_NULL_HANDLE; + std::vector cmdBufs; + + std::vector imgAvailSems; + std::vector renderDoneSems; + std::vector inFlightFences; + std::vector imgInFlight; + uint32_t currentFrame = 0; + + VkSampler sampler = VK_NULL_HANDLE; + VkDescriptorPool winTexPool = VK_NULL_HANDLE; + + std::atomic needsRender{false}; + std::thread renderThread; + std::atomic isRunning{false}; + std::atomic fbResized{false}; + std::mutex renderMutex; + std::mutex dirtyMutex; + std::condition_variable dirtyCV; + std::shared_mutex frameMutex; + + void createInstance(); + void createSurface(); + void pickPhysicalDevice(); + lsfg::Caps lsfgCaps_{}; + + void createLogicalDevice(); + void createSwapchain(); + void createRenderPass(); + void createDSLayout(); + void createPipeline(bool blend, VkPipeline& out); + void createFramebuffers(); + void createCmdPool(); + void createSampler(); + void createUpscaleSampler(); + void createOffscreenRenderPass(); + void createPostPipelines(); + VkPipeline createPostPipeline(const uint32_t* fragCode, size_t fragSz, VkRenderPass rp); + bool createColorTarget(int w, int h, VkImage& img, VkDeviceMemory& mem, + VkImageView& view, VkFramebuffer& fb, VkDescriptorSet& ds); + void destroyColorTarget(VkImage& img, VkDeviceMemory& mem, VkImageView& view, + VkFramebuffer& fb, VkDescriptorSet& ds); + bool ensureOffscreen(int w, int h); + bool ensureMid(int w, int h); + bool ensureFx1(int w, int h); + bool ensureFx2(int w, int h); + void recordUpscalePasses(VkCommandBuffer cb, uint32_t imgIdx, + const std::vector& draws, bool cursorDrawn, + short ptrX, short ptrY, short curHotX, short curHotY, + short curW, short curH, + float ox, float oy, float sx, float sy, + float cw, float ch); + void planUpscaleFrame(); + void createWinTexPool(); + void createCursorPipeline(); + void createCursorDS(); + void createCmdBufs(); + void createSyncObjects(); + void cleanupSwapchain(); + + bool createWinTexResources(WinTex& wt, int w, int h); + bool importAHBToWinTex(WinTex& wt, AHardwareBuffer* ahb); + void cleanupAllAHBCache(); + void flushDeleteQueue(); + void destroyWinTex(WinTex& wt); + void ensureCursorTex(short w, short h); + void cleanupCursorTex(); + void ensureCursorStaging(VkDeviceSize sz); + + void recordCmdBuf(VkCommandBuffer cb, uint32_t imgIdx, + const std::vector& draws, + std::vector& ahbTransitions, + std::vector& preUpload, + std::vector& postUpload, + VkBuffer cursorUpload, bool hasCursorUpload, + float ox, float oy, float sx, float sy, float cw, float ch, + short ptrX, short ptrY, short curHotX, short curHotY, + short curW, short curH, bool curVis); + void renderLoop(); + void renderFrame(); + + uint32_t findMemType(uint32_t filter, VkMemoryPropertyFlags props); + void createBuffer(VkDeviceSize sz, VkBufferUsageFlags usage, + VkMemoryPropertyFlags props, VkBuffer& buf, VkDeviceMemory& mem); + VkCommandBuffer beginOneTime(); + void endOneTime(VkCommandBuffer cmd); + void transition(VkCommandBuffer cmd, VkImage img, + VkImageLayout oldL, VkImageLayout newL, + VkAccessFlags srcA, VkAccessFlags dstA, + VkPipelineStageFlags srcS, VkPipelineStageFlags dstS); + VkShaderModule makeShader(const uint32_t* code, size_t sz); +}; diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_alpha.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_alpha.cpp new file mode 100644 index 0000000000..73be35b59c --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_alpha.cpp @@ -0,0 +1,157 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_alpha.hpp" +#include "lsfg_shaders.hpp" + +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t DISPATCH_TILE_SHIFT = 3; + +[[nodiscard]] uint32_t GroupCount(uint32_t size) { + return (size + (1u << DISPATCH_TILE_SHIFT) - 1) >> DISPATCH_TILE_SHIFT; +} + +[[nodiscard]] VkExtent2D HalveExtent(VkExtent2D extent) { + return VkExtent2D{ + (extent.width + 1) >> 1, + (extent.height + 1) >> 1, + }; +} + +} + +LsfgAlphaPasses::LsfgAlphaPasses(const Device& device, const LsfgShaders& shaders) { + passes[0] = LsfgPass(device, shaders, LSFG_ALPHA_SHADERS[0], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[1] = LsfgPass(device, shaders, LSFG_ALPHA_SHADERS[1], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[2] = LsfgPass(device, shaders, LSFG_ALPHA_SHADERS[2], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[3] = LsfgPass(device, shaders, LSFG_ALPHA_SHADERS[3], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); +} + +bool LsfgAlphaPasses::Valid() const { + for (const auto& pass : passes) { + if (!pass.Valid()) return false; + } + return true; +} + +LsfgAlpha::LsfgAlpha(const Device& device, const LsfgAlphaPasses& passes_, + LsfgResources& resources, VkDescriptorPool descriptor_pool, LsfgImage& input_) + : passes{&passes_}, input{&input_} { + if (!passes->Valid()) return; + + const VkExtent2D half_extent = HalveExtent(input->Extent()); + const VkExtent2D quarter_extent = HalveExtent(half_extent); + + temp1 = LsfgImage(device, half_extent); + temp2 = LsfgImage(device, half_extent); + if (!temp1.Valid() || !temp2.Valid()) return; + + for (size_t i = 0; i < temp3.size(); ++i) { + temp3[i] = LsfgImage(device, quarter_extent); + if (!temp3[i].Valid()) return; + + for (size_t j = 0; j < LSFG_HISTORY_SLOTS; ++j) { + out_images[j][i] = LsfgImage(device, quarter_extent); + if (!out_images[j][i].Valid()) return; + } + } + + std::vector layouts; + for (size_t i = 0; i < LSFG_ALPHA_STAGES - 1; ++i) { + layouts.push_back(passes->Get(i).SetLayout()); + } + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + layouts.push_back(passes->Get(3).SetLayout()); + } + + const std::vector sets = + AllocateLsfgDescriptorSets(device, descriptor_pool, layouts); + if (sets.size() != layouts.size()) return; + + for (size_t i = 0; i < LSFG_ALPHA_STAGES - 1; ++i) { + descriptor_sets[i] = sets[i]; + } + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + last_descriptor_sets[i] = sets[LSFG_ALPHA_STAGES - 1 + i]; + } + + const VkSampler sampler = resources.GetSampler(); + + LsfgDescriptorWriter(descriptor_sets[0]) + .AddSampler(sampler) + .AddSampledImage(*input) + .AddStorageImage(temp1) + .Build(device); + LsfgDescriptorWriter(descriptor_sets[1]) + .AddSampler(sampler) + .AddSampledImage(temp1) + .AddStorageImage(temp2) + .Build(device); + LsfgDescriptorWriter(descriptor_sets[2]) + .AddSampler(sampler) + .AddSampledImage(temp2) + .AddStorageImages(temp3) + .Build(device); + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + LsfgDescriptorWriter(last_descriptor_sets[i]) + .AddSampler(sampler) + .AddSampledImages(temp3) + .AddStorageImages(out_images[i]) + .Build(device); + } + allocated = true; +} + +void LsfgAlpha::PushBarriers(LsfgBarriers& barriers, uint64_t frame_count, size_t stage) { + switch (stage) { + case 0: + barriers.WriteToRead(*input).ReadToWrite(temp1); + break; + case 1: + barriers.WriteToRead(temp1).ReadToWrite(temp2); + break; + case 2: + barriers.WriteToRead(temp2).ReadToWriteAll(temp3); + break; + default: + barriers.WriteToReadAll(temp3).ReadToWriteAll(out_images[frame_count % LSFG_HISTORY_SLOTS]); + break; + } +} + +void LsfgAlpha::DispatchStage(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t stage) { + const VkExtent2D extent = stage < 2 ? temp1.Extent() : temp3[0].Extent(); + const VkDescriptorSet set = stage < LSFG_ALPHA_STAGES - 1 + ? descriptor_sets[stage] + : last_descriptor_sets[frame_count % LSFG_HISTORY_SLOTS]; + + passes->Get(stage).BindSet(cmdbuf, set); + vkd.CmdDispatch(cmdbuf, GroupCount(extent.width), GroupCount(extent.height), 1); +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_alpha.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_alpha.hpp new file mode 100644 index 0000000000..6c233c16ca --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_alpha.hpp @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include + +#include "lsfg_common.hpp" + +namespace lsfg { + +class LsfgShaders; + +constexpr size_t LSFG_ALPHA_STAGES = 4; + +class LsfgAlphaPasses { +public: + LsfgAlphaPasses() = default; + LsfgAlphaPasses(const Device& device, const LsfgShaders& shaders); + + [[nodiscard]] const LsfgPass& Get(size_t stage) const { + return passes[stage]; + } + + [[nodiscard]] bool Valid() const; + +private: + std::array passes; +}; + +class LsfgAlpha { +public: + LsfgAlpha() = default; + LsfgAlpha(const Device& device, const LsfgAlphaPasses& passes, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImage& input); + + void PushBarriers(LsfgBarriers& barriers, uint64_t frame_count, size_t stage); + void DispatchStage(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t stage); + + [[nodiscard]] LsfgImageHistory& Outputs() { + return out_images; + } + + [[nodiscard]] bool Valid() const { + return allocated; + } + +private: + const LsfgAlphaPasses* passes{}; + LsfgImage* input{}; + + std::array descriptor_sets{}; + std::array last_descriptor_sets{}; + + LsfgImage temp1; + LsfgImage temp2; + LsfgImagePair temp3; + LsfgImageHistory out_images; + bool allocated{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_beta.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_beta.cpp new file mode 100644 index 0000000000..299e22cf72 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_beta.cpp @@ -0,0 +1,155 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_beta.hpp" +#include "lsfg_shaders.hpp" + +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t DISPATCH_TILE_SHIFT = 3; +constexpr uint32_t OUTPUT_TILE_SHIFT = 5; + +[[nodiscard]] uint32_t GroupCount(uint32_t size, uint32_t shift) { + return (size + (1u << shift) - 1) >> shift; +} + +} + +LsfgBeta::LsfgBeta(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImageHistory& inputs_) + : inputs{&inputs_} { + passes[0] = LsfgPass(device, shaders, LSFG_BETA_SHADERS[0], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {6, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + for (size_t i = 1; i < LSFG_BETA_STAGES - 1; ++i) { + passes[i] = LsfgPass(device, shaders, LSFG_BETA_SHADERS[i], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + } + passes[4] = LsfgPass(device, shaders, LSFG_BETA_SHADERS[4], + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {6, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + for (const auto& pass : passes) { + if (!pass.Valid()) return; + } + + const VkExtent2D extent = (*inputs)[0][0].Extent(); + for (size_t i = 0; i < temp1.size(); ++i) { + temp1[i] = LsfgImage(device, extent); + temp2[i] = LsfgImage(device, extent); + if (!temp1[i].Valid() || !temp2[i].Valid()) return; + } + for (size_t i = 0; i < LSFG_BETA_OUTPUTS; ++i) { + const VkExtent2D level_extent{ + extent.width >> i, + extent.height >> i, + }; + out_images[i] = LsfgImage(device, level_extent, LSFG_FLOW_FORMAT); + if (!out_images[i].Valid()) return; + } + + std::vector layouts; + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + layouts.push_back(passes[0].SetLayout()); + } + for (size_t i = 1; i < LSFG_BETA_STAGES; ++i) { + layouts.push_back(passes[i].SetLayout()); + } + + const std::vector sets = + AllocateLsfgDescriptorSets(device, descriptor_pool, layouts); + if (sets.size() != layouts.size()) return; + + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + first_descriptor_sets[i] = sets[i]; + } + for (size_t i = 0; i < LSFG_BETA_STAGES - 1; ++i) { + descriptor_sets[i] = sets[LSFG_HISTORY_SLOTS + i]; + } + + const VkSampler sampler = resources.GetSampler(); + const VkSampler border_sampler = + resources.GetSampler(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_COMPARE_OP_NEVER, true); + + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + LsfgDescriptorWriter(first_descriptor_sets[i]) + .AddSampler(border_sampler) + .AddSampledImages((*inputs)[(i + 1) % LSFG_HISTORY_SLOTS]) + .AddSampledImages((*inputs)[(i + 2) % LSFG_HISTORY_SLOTS]) + .AddSampledImages((*inputs)[i % LSFG_HISTORY_SLOTS]) + .AddStorageImages(temp1) + .Build(device); + } + LsfgDescriptorWriter(descriptor_sets[0]) + .AddSampler(sampler) + .AddSampledImages(temp1) + .AddStorageImages(temp2) + .Build(device); + LsfgDescriptorWriter(descriptor_sets[1]) + .AddSampler(sampler) + .AddSampledImages(temp2) + .AddStorageImages(temp1) + .Build(device); + LsfgDescriptorWriter(descriptor_sets[2]) + .AddSampler(sampler) + .AddSampledImages(temp1) + .AddStorageImages(temp2) + .Build(device); + LsfgDescriptorWriter(descriptor_sets[3]) + .AddUniformBuffer(resources.GetBuffer(0.5f), LsfgResources::BufferSize()) + .AddSampler(sampler) + .AddSampledImages(temp2) + .AddStorageImages(out_images) + .Build(device); + allocated = true; +} + +void LsfgBeta::Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count) { + const VkExtent2D extent = temp1[0].Extent(); + const uint32_t groups_x = GroupCount(extent.width, DISPATCH_TILE_SHIFT); + const uint32_t groups_y = GroupCount(extent.height, DISPATCH_TILE_SHIFT); + + LsfgBarriers barriers(cmdbuf); + for (auto& slot : *inputs) { + barriers.WriteToReadAll(slot); + } + barriers.ReadToWriteAll(temp1).Build(); + + passes[0].Bind(cmdbuf, first_descriptor_sets[frame_count % LSFG_HISTORY_SLOTS]); + vkd.CmdDispatch(cmdbuf, groups_x, groups_y, 1); + + LsfgBarriers(cmdbuf).WriteToReadAll(temp1).ReadToWriteAll(temp2).Build(); + passes[1].Bind(cmdbuf, descriptor_sets[0]); + vkd.CmdDispatch(cmdbuf, groups_x, groups_y, 1); + + LsfgBarriers(cmdbuf).WriteToReadAll(temp2).ReadToWriteAll(temp1).Build(); + passes[2].Bind(cmdbuf, descriptor_sets[1]); + vkd.CmdDispatch(cmdbuf, groups_x, groups_y, 1); + + LsfgBarriers(cmdbuf).WriteToReadAll(temp1).ReadToWriteAll(temp2).Build(); + passes[3].Bind(cmdbuf, descriptor_sets[2]); + vkd.CmdDispatch(cmdbuf, groups_x, groups_y, 1); + + LsfgBarriers(cmdbuf).WriteToReadAll(temp2).ReadToWriteAll(out_images).Build(); + passes[4].Bind(cmdbuf, descriptor_sets[3]); + vkd.CmdDispatch(cmdbuf, GroupCount(extent.width, OUTPUT_TILE_SHIFT), + GroupCount(extent.height, OUTPUT_TILE_SHIFT), 1); +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_beta.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_beta.hpp new file mode 100644 index 0000000000..1d1e77a56c --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_beta.hpp @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include + +#include "lsfg_common.hpp" + +namespace lsfg { + +class LsfgShaders; + +constexpr size_t LSFG_BETA_STAGES = 5; +constexpr size_t LSFG_BETA_OUTPUTS = 6; + +class LsfgBeta { +public: + LsfgBeta() = default; + LsfgBeta(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImageHistory& inputs); + + void Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count); + + [[nodiscard]] LsfgImage& Output(size_t level) { + return out_images[level]; + } + + [[nodiscard]] bool Valid() const { + return allocated; + } + +private: + LsfgImageHistory* inputs{}; + + std::array passes; + std::array first_descriptor_sets{}; + std::array descriptor_sets{}; + + LsfgImagePair temp1; + LsfgImagePair temp2; + std::array out_images; + bool allocated{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_chain.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_chain.cpp new file mode 100644 index 0000000000..f9ff4b4f86 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_chain.cpp @@ -0,0 +1,149 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_chain.hpp" +#include "lsfg_shaders.hpp" + +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t FIXED_DESCRIPTOR_SETS = 64; +constexpr uint32_t DESCRIPTOR_SETS_PER_SLOT = 112; +[[nodiscard]] constexpr bool HasDelta(size_t i) { + return i >= LSFG_FIRST_DELTA_LEVEL && i <= LSFG_LAST_DELTA_LEVEL; +} + +} + +LsfgChain::LsfgChain(const Device& device, const LsfgShaders& shaders, VkExtent2D extent, + VkFormat format, float flow_scale) + : resources{device, flow_scale}, owner{device.Handle()} { + descriptor_pool = CreateLsfgDescriptorPool( + device, FIXED_DESCRIPTOR_SETS + + DESCRIPTOR_SETS_PER_SLOT * static_cast(LSFG_GENERATION_SLOTS)); + if (descriptor_pool == VK_NULL_HANDLE) return; + + for (auto& image : frames) { + image = LsfgImage(device, extent, format); + if (!image.Valid()) return; + } + + mipmaps = LsfgMipmaps(device, shaders, resources, descriptor_pool, frames, flow_scale); + if (!mipmaps.Valid()) return; + + alpha_passes = LsfgAlphaPasses(device, shaders); + if (!alpha_passes.Valid()) return; + + for (size_t i = 0; i < LSFG_MIP_LEVELS; ++i) { + alpha[i] = LsfgAlpha(device, alpha_passes, resources, descriptor_pool, mipmaps.Output(i)); + if (!alpha[i].Valid()) return; + } + + beta = LsfgBeta(device, shaders, resources, descriptor_pool, alpha[0].Outputs()); + if (!beta.Valid()) return; + + for (size_t i = 0; i < LSFG_MIP_LEVELS; ++i) { + const size_t level = LSFG_MIP_LEVELS - 1 - i; + gamma[i] = LsfgGamma(device, shaders, resources, descriptor_pool, alpha[level].Outputs(), + beta.Output(std::min(level, LSFG_BETA_OUTPUTS - 1)), + i == 0 ? nullptr : &gamma[i - 1].Output()); + if (!gamma[i].Valid()) return; + + if (!HasDelta(i)) { + continue; + } + + const size_t index = i - LSFG_FIRST_DELTA_LEVEL; + const bool first = i == LSFG_FIRST_DELTA_LEVEL; + delta[index] = LsfgDelta(device, shaders, resources, descriptor_pool, + alpha[level].Outputs(), beta.Output(level), + first ? nullptr : &gamma[i - 1].Output(), + first ? nullptr : &delta[index - 1].Output1(), + first ? nullptr : &delta[index - 1].Output2()); + if (!delta[index].Valid()) return; + } + + generate = LsfgGenerate(device, shaders, resources, descriptor_pool, frames, + gamma[LSFG_MIP_LEVELS - 1].Output(), + delta[LSFG_DELTA_INSTANCES - 1].Output1(), + delta[LSFG_DELTA_INSTANCES - 1].Output2()); + if (!generate.Valid()) return; + + valid = true; +} + +LsfgChain::~LsfgChain() { + if (descriptor_pool != VK_NULL_HANDLE) { + vkd.DestroyDescriptorPool(owner, descriptor_pool, nullptr); + descriptor_pool = VK_NULL_HANDLE; + } +} + +void LsfgChain::DispatchShared(VkCommandBuffer cmdbuf, uint64_t frame_count) { + resources.PrepareDummies(cmdbuf); + + mipmaps.Dispatch(cmdbuf, frame_count); + + for (size_t stage = 0; stage < LSFG_ALPHA_STAGES; ++stage) { + LsfgBarriers barriers(cmdbuf); + for (auto& level : alpha) { + level.PushBarriers(barriers, frame_count, stage); + } + barriers.Build(); + + alpha_passes.Get(stage).BindPipeline(cmdbuf); + for (auto& level : alpha) { + level.DispatchStage(cmdbuf, frame_count, stage); + } + } + + beta.Dispatch(cmdbuf, frame_count); +} + +void LsfgChain::DispatchGeneration(VkCommandBuffer cmdbuf, uint64_t frame_count, + size_t generation_count, size_t generation, uint32_t target, + VkImage image, VkExtent2D extent) { + const size_t slot = LsfgGenerationSlot(generation_count, generation); + constexpr size_t PAIRED_STEPS = + LSFG_GAMMA_STAGES > LSFG_DELTA_STAGES ? LSFG_GAMMA_STAGES : LSFG_DELTA_STAGES; + + for (size_t i = 0; i < LSFG_MIP_LEVELS; ++i) { + if (!HasDelta(i)) { + gamma[i].Dispatch(cmdbuf, frame_count, slot); + continue; + } + + LsfgDelta& paired = delta[i - LSFG_FIRST_DELTA_LEVEL]; + for (size_t step = 0; step < PAIRED_STEPS; ++step) { + LsfgBarriers barriers(cmdbuf); + if (step < LSFG_GAMMA_STAGES) { + gamma[i].PushStepBarriers(barriers, frame_count, step); + } + if (step < LSFG_DELTA_STAGES) { + paired.PushStepBarriers(barriers, frame_count, step); + } + barriers.Build(); + + if (step < LSFG_GAMMA_STAGES) { + gamma[i].DispatchStep(cmdbuf, frame_count, slot, step); + } + if (step < LSFG_DELTA_STAGES) { + paired.DispatchStep(cmdbuf, frame_count, slot, step); + } + } + } + generate.Dispatch(cmdbuf, frame_count, slot, target, image, extent); +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_chain.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_chain.hpp new file mode 100644 index 0000000000..4324c80bc2 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_chain.hpp @@ -0,0 +1,83 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include + +#include "lsfg_alpha.hpp" +#include "lsfg_beta.hpp" +#include "lsfg_common.hpp" +#include "lsfg_delta.hpp" +#include "lsfg_gamma.hpp" +#include "lsfg_generate.hpp" +#include "lsfg_mipmaps.hpp" + +namespace lsfg { + +class LsfgShaders; + +constexpr size_t LSFG_FIRST_DELTA_LEVEL = 4; +constexpr size_t LSFG_LAST_DELTA_LEVEL = LSFG_MIP_LEVELS - 1; +constexpr size_t LSFG_DELTA_INSTANCES = LSFG_LAST_DELTA_LEVEL + 1 - LSFG_FIRST_DELTA_LEVEL; + +class LsfgChain { +public: + LsfgChain(const Device& device, const LsfgShaders& shaders, VkExtent2D extent, VkFormat format, + float flow_scale); + ~LsfgChain(); + + LsfgChain(const LsfgChain&) = delete; + LsfgChain& operator=(const LsfgChain&) = delete; + + void DispatchShared(VkCommandBuffer cmdbuf, uint64_t frame_count); + + void DispatchGeneration(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t generation_count, + size_t generation, uint32_t target, VkImage image, VkExtent2D extent); + + void SetTarget(const Device& device, size_t generation_count, size_t generation, + uint32_t target, VkImageView view) { + generate.SetTarget(device, LsfgGenerationSlot(generation_count, generation), target, view); + } + + void ForgetTargets() { + generate.ForgetTargets(); + } + + [[nodiscard]] LsfgImage& Input(uint64_t frame_count) { + return frames[frame_count % frames.size()]; + } + + [[nodiscard]] LsfgImage& FlowLevel(size_t level) { + return mipmaps.Output(level); + } + + [[nodiscard]] bool Valid() const { + return valid; + } + +private: + LsfgResources resources; + VkDevice owner{VK_NULL_HANDLE}; + VkDescriptorPool descriptor_pool{VK_NULL_HANDLE}; + + LsfgImagePair frames; + LsfgMipmaps mipmaps; + LsfgAlphaPasses alpha_passes; + std::array alpha; + LsfgBeta beta; + std::array gamma; + std::array delta; + LsfgGenerate generate; + bool valid{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_common.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_common.cpp new file mode 100644 index 0000000000..b72eb22873 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_common.cpp @@ -0,0 +1,653 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_common.hpp" +#include "lsfg_shaders.hpp" + +#include +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t DESCRIPTORS_PER_TYPE = 4096; + +struct LsfgConstants { + std::array input_offset; + uint32_t first_iter; + uint32_t first_iter_s; + uint32_t advanced_color_kind; + uint32_t hdr_support; + float resolution_inv_scale; + float timestamp; + float ui_threshold; + std::array padding; +}; +static_assert(sizeof(LsfgConstants) == 48); + +VkImageMemoryBarrier MakeBarrier(const LsfgImage& image, VkAccessFlags src_access, + VkAccessFlags dst_access) { + VkImageMemoryBarrier barrier{}; + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.srcAccessMask = src_access; + barrier.dstAccessMask = dst_access; + barrier.oldLayout = image.Layout(); + barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = image.Handle(); + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.levelCount = 1; + barrier.subresourceRange.layerCount = 1; + return barrier; +} + +} + +Device::Device(VkDevice device_, VkPhysicalDevice physical_device_) + : device{device_}, physical_device{physical_device_} { + vkd.GetPhysicalDeviceMemoryProperties(physical_device, &memory_properties); +} + +uint32_t Device::FindMemoryType(uint32_t bits, VkMemoryPropertyFlags properties) const { + for (uint32_t i = 0; i < memory_properties.memoryTypeCount; i++) { + if ((bits & (1u << i)) == 0) continue; + if ((memory_properties.memoryTypes[i].propertyFlags & properties) == properties) return i; + } + return UINT32_MAX; +} + +Buffer::Buffer(const Device& device_, VkDeviceSize size) : device{device_.Handle()} { + VkBufferCreateInfo buffer_ci{}; + buffer_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_ci.size = size; + buffer_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; + buffer_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + if (vkd.CreateBuffer(device, &buffer_ci, nullptr, &buffer) != VK_SUCCESS) { + buffer = VK_NULL_HANDLE; + return; + } + + VkMemoryRequirements requirements; + vkd.GetBufferMemoryRequirements(device, buffer, &requirements); + + VkMemoryAllocateInfo allocate_info{}; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = requirements.size; + allocate_info.memoryTypeIndex = device_.FindMemoryType( + requirements.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + if (allocate_info.memoryTypeIndex == UINT32_MAX || + vkd.AllocateMemory(device, &allocate_info, nullptr, &memory) != VK_SUCCESS) { + Release(); + return; + } + + vkd.BindBufferMemory(device, buffer, memory, 0); + if (vkd.MapMemory(device, memory, 0, VK_WHOLE_SIZE, 0, &mapped) != VK_SUCCESS) { + mapped = nullptr; + Release(); + } +} + +Buffer::~Buffer() { + Release(); +} + +Buffer::Buffer(Buffer&& other) noexcept + : device{other.device}, buffer{other.buffer}, memory{other.memory}, mapped{other.mapped} { + other.device = VK_NULL_HANDLE; + other.buffer = VK_NULL_HANDLE; + other.memory = VK_NULL_HANDLE; + other.mapped = nullptr; +} + +Buffer& Buffer::operator=(Buffer&& other) noexcept { + if (this != &other) { + Release(); + device = other.device; + buffer = other.buffer; + memory = other.memory; + mapped = other.mapped; + other.device = VK_NULL_HANDLE; + other.buffer = VK_NULL_HANDLE; + other.memory = VK_NULL_HANDLE; + other.mapped = nullptr; + } + return *this; +} + +void Buffer::Upload(const void* data, size_t size) { + if (mapped) std::memcpy(mapped, data, size); +} + +void Buffer::Release() { + if (device == VK_NULL_HANDLE) return; + if (mapped) { + vkd.UnmapMemory(device, memory); + mapped = nullptr; + } + if (buffer) vkd.DestroyBuffer(device, buffer, nullptr); + if (memory) vkd.FreeMemory(device, memory, nullptr); + buffer = VK_NULL_HANDLE; + memory = VK_NULL_HANDLE; +} + +LsfgImage::LsfgImage(const Device& device_, VkExtent2D extent_, VkFormat format_) + : device{device_.Handle()}, + extent{std::max(1u, extent_.width), std::max(1u, extent_.height)}, format{format_} { + VkImageCreateInfo image_ci{}; + image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + image_ci.imageType = VK_IMAGE_TYPE_2D; + image_ci.format = format; + image_ci.extent = {extent.width, extent.height, 1}; + image_ci.mipLevels = 1; + image_ci.arrayLayers = 1; + image_ci.samples = VK_SAMPLE_COUNT_1_BIT; + image_ci.tiling = VK_IMAGE_TILING_OPTIMAL; + image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | + VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + if (vkd.CreateImage(device, &image_ci, nullptr, &image) != VK_SUCCESS) { + image = VK_NULL_HANDLE; + return; + } + + VkMemoryRequirements requirements; + vkd.GetImageMemoryRequirements(device, image, &requirements); + + VkMemoryAllocateInfo allocate_info{}; + allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocate_info.allocationSize = requirements.size; + allocate_info.memoryTypeIndex = + device_.FindMemoryType(requirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (allocate_info.memoryTypeIndex == UINT32_MAX || + vkd.AllocateMemory(device, &allocate_info, nullptr, &memory) != VK_SUCCESS) { + Release(); + return; + } + vkd.BindImageMemory(device, image, memory, 0); + + VkImageViewCreateInfo view_ci{}; + view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + view_ci.image = image; + view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; + view_ci.format = format; + view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + view_ci.subresourceRange.levelCount = 1; + view_ci.subresourceRange.layerCount = 1; + if (vkd.CreateImageView(device, &view_ci, nullptr, &view) != VK_SUCCESS) { + view = VK_NULL_HANDLE; + Release(); + } +} + +LsfgImage::~LsfgImage() { + Release(); +} + +LsfgImage::LsfgImage(LsfgImage&& other) noexcept + : device{other.device}, image{other.image}, view{other.view}, memory{other.memory}, + extent{other.extent}, format{other.format}, layout{other.layout} { + other.device = VK_NULL_HANDLE; + other.image = VK_NULL_HANDLE; + other.view = VK_NULL_HANDLE; + other.memory = VK_NULL_HANDLE; +} + +LsfgImage& LsfgImage::operator=(LsfgImage&& other) noexcept { + if (this != &other) { + Release(); + device = other.device; + image = other.image; + view = other.view; + memory = other.memory; + extent = other.extent; + format = other.format; + layout = other.layout; + other.device = VK_NULL_HANDLE; + other.image = VK_NULL_HANDLE; + other.view = VK_NULL_HANDLE; + other.memory = VK_NULL_HANDLE; + } + return *this; +} + +void LsfgImage::Release() { + if (device == VK_NULL_HANDLE) return; + if (view) vkd.DestroyImageView(device, view, nullptr); + if (image) vkd.DestroyImage(device, image, nullptr); + if (memory) vkd.FreeMemory(device, memory, nullptr); + view = VK_NULL_HANDLE; + image = VK_NULL_HANDLE; + memory = VK_NULL_HANDLE; +} + +LsfgResources::~LsfgResources() { + if (!device) return; + for (auto& [key, sampler] : samplers) { + vkd.DestroySampler(device->Handle(), sampler, nullptr); + } + samplers.clear(); +} + +VkDeviceSize LsfgResources::BufferSize() { + return sizeof(LsfgConstants); +} + +VkSampler LsfgResources::GetSampler(VkSamplerAddressMode address_mode, VkCompareOp compare_op, + bool white_border) { + const uint64_t key = static_cast(address_mode) | + (static_cast(compare_op) << 8) | + (static_cast(white_border) << 16); + + const auto it = samplers.find(key); + if (it != samplers.end()) return it->second; + + VkSampler sampler = CreateLsfgSampler(*device, address_mode, compare_op, white_border); + samplers.emplace(key, sampler); + return sampler; +} + +VkBuffer LsfgResources::GetBuffer(float timestamp, bool first_iter, bool first_iter_s) { + uint32_t timestamp_bits{}; + std::memcpy(×tamp_bits, ×tamp, sizeof(timestamp_bits)); + const uint64_t key = static_cast(timestamp_bits) | + (static_cast(first_iter) << 32) | + (static_cast(first_iter_s) << 33); + + const auto it = buffers.find(key); + if (it != buffers.end()) return it->second.Handle(); + + Buffer buffer{*device, sizeof(LsfgConstants)}; + if (!buffer.Valid()) return VK_NULL_HANDLE; + + LsfgConstants constants{}; + constants.first_iter = first_iter ? 1u : 0u; + constants.first_iter_s = first_iter_s ? 1u : 0u; + constants.resolution_inv_scale = 1.0f / flow_scale; + constants.timestamp = timestamp; + constants.ui_threshold = 0.5f; + buffer.Upload(&constants, sizeof(constants)); + + const auto [entry, inserted] = buffers.emplace(key, std::move(buffer)); + return entry->second.Handle(); +} + +const LsfgImage& LsfgResources::GetDummy(VkFormat format) { + const uint32_t key = static_cast(format); + + const auto it = dummies.find(key); + if (it != dummies.end()) return it->second; + + LsfgImage image{*device, VkExtent2D{1, 1}, format}; + const auto [entry, inserted] = dummies.emplace(key, std::move(image)); + dummies_ready = false; + return entry->second; +} + +void LsfgResources::PrepareDummies(VkCommandBuffer cmdbuf) { + if (dummies_ready || dummies.empty()) return; + + std::vector barriers; + for (auto& [key, image] : dummies) { + if (!image.Valid()) continue; + + VkImageMemoryBarrier barrier{}; + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.srcAccessMask = 0; + barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = image.Handle(); + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.levelCount = 1; + barrier.subresourceRange.layerCount = 1; + barriers.push_back(barrier); + image.SetLayout(VK_IMAGE_LAYOUT_GENERAL); + } + + if (!barriers.empty()) { + vkd.CmdPipelineBarrier(cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, + static_cast(barriers.size()), barriers.data()); + } + dummies_ready = true; +} + +LsfgBarriers& LsfgBarriers::Push(LsfgImage& image, VkAccessFlags src_access, + VkAccessFlags dst_access) { + barriers.push_back(MakeBarrier(image, src_access, dst_access)); + image.SetLayout(VK_IMAGE_LAYOUT_GENERAL); + return *this; +} + +LsfgBarriers& LsfgBarriers::WriteToRead(LsfgImage& image) { + return Push(image, VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT); +} + +LsfgBarriers& LsfgBarriers::ReadToWrite(LsfgImage& image) { + return Push(image, VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_SHADER_WRITE_BIT); +} + +LsfgBarriers& LsfgBarriers::WriteToRead(LsfgImage* image) { + return image == nullptr ? *this : WriteToRead(*image); +} + +LsfgBarriers& LsfgBarriers::ReadToWrite(LsfgImage* image) { + return image == nullptr ? *this : ReadToWrite(*image); +} + +LsfgBarriers& LsfgBarriers::DiscardToWrite(VkImage image) { + VkImageMemoryBarrier barrier{}; + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.srcAccessMask = 0; + barrier.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT; + barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; + barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = image; + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.levelCount = 1; + barrier.subresourceRange.layerCount = 1; + barriers.push_back(barrier); + return *this; +} + +void LsfgBarriers::Build() { + if (barriers.empty()) return; + vkd.CmdPipelineBarrier(cmdbuf, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, + static_cast(barriers.size()), barriers.data()); + barriers.clear(); +} + +LsfgDescriptorWriter& LsfgDescriptorWriter::PushImage(VkDescriptorType type, VkSampler sampler, + VkImageView view) { + VkDescriptorImageInfo info{}; + info.sampler = sampler; + info.imageView = view; + info.imageLayout = + view == VK_NULL_HANDLE ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_GENERAL; + image_infos.push_back(info); + + VkWriteDescriptorSet write{}; + write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write.dstSet = set; + write.dstBinding = binding++; + write.descriptorCount = 1; + write.descriptorType = type; + write.pImageInfo = &image_infos.back(); + writes.push_back(write); + return *this; +} + +LsfgDescriptorWriter& LsfgDescriptorWriter::AddSampler(VkSampler sampler) { + return PushImage(VK_DESCRIPTOR_TYPE_SAMPLER, sampler, VK_NULL_HANDLE); +} + +LsfgDescriptorWriter& LsfgDescriptorWriter::AddSampledImage(const LsfgImage& image) { + return PushImage(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_NULL_HANDLE, image.View()); +} + +LsfgDescriptorWriter& LsfgDescriptorWriter::AddSampledImage(const LsfgImage* image) { + return PushImage(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_NULL_HANDLE, + image == nullptr ? VK_NULL_HANDLE : image->View()); +} + +LsfgDescriptorWriter& LsfgDescriptorWriter::AddStorageImage(const LsfgImage& image) { + return PushImage(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_NULL_HANDLE, image.View()); +} + +LsfgDescriptorWriter& LsfgDescriptorWriter::AddStorageView(VkImageView view) { + return PushImage(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_NULL_HANDLE, view); +} + +LsfgDescriptorWriter& LsfgDescriptorWriter::AddUniformBuffer(VkBuffer buffer, VkDeviceSize size) { + VkDescriptorBufferInfo info{}; + info.buffer = buffer; + info.offset = 0; + info.range = size; + buffer_infos.push_back(info); + + VkWriteDescriptorSet write{}; + write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write.dstSet = set; + write.dstBinding = binding++; + write.descriptorCount = 1; + write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + write.pBufferInfo = &buffer_infos.back(); + writes.push_back(write); + return *this; +} + +void LsfgDescriptorWriter::Build(const Device& device) { + if (writes.empty()) return; + vkd.UpdateDescriptorSets(device.Handle(), static_cast(writes.size()), writes.data(), 0, + nullptr); + writes.clear(); +} + +LsfgPass::LsfgPass(const Device& device_, const LsfgShaders& shaders, uint32_t shader_id, + LsfgBindings bindings) + : device{device_.Handle()} { + std::vector layout_bindings; + uint32_t index = 0; + for (const auto& [count, type] : bindings) { + for (uint32_t i = 0; i < count; i++) { + VkDescriptorSetLayoutBinding entry{}; + entry.binding = index++; + entry.descriptorType = type; + entry.descriptorCount = 1; + entry.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + layout_bindings.push_back(entry); + } + } + descriptor_count = index; + + VkDescriptorSetLayoutCreateInfo layout_ci{}; + layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout_ci.bindingCount = static_cast(layout_bindings.size()); + layout_ci.pBindings = layout_bindings.data(); + if (vkd.CreateDescriptorSetLayout(device, &layout_ci, nullptr, &descriptor_set_layout) != + VK_SUCCESS) { + Release(); + return; + } + + VkPipelineLayoutCreateInfo pipeline_layout_ci{}; + pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_ci.setLayoutCount = 1; + pipeline_layout_ci.pSetLayouts = &descriptor_set_layout; + if (vkd.CreatePipelineLayout(device, &pipeline_layout_ci, nullptr, &pipeline_layout) != + VK_SUCCESS) { + Release(); + return; + } + + const VkShaderModule module = shaders.Get(shader_id); + if (module == VK_NULL_HANDLE) { + Release(); + return; + } + + VkPipelineShaderStageCreateInfo stage{}; + stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; + stage.module = module; + stage.pName = "main"; + + VkComputePipelineCreateInfo pipeline_ci{}; + pipeline_ci.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + pipeline_ci.stage = stage; + pipeline_ci.layout = pipeline_layout; + if (vkd.CreateComputePipelines(device, VK_NULL_HANDLE, 1, &pipeline_ci, nullptr, &pipeline) != + VK_SUCCESS) { + pipeline = VK_NULL_HANDLE; + Release(); + } +} + +LsfgPass::~LsfgPass() { + Release(); +} + +LsfgPass::LsfgPass(LsfgPass&& other) noexcept + : device{other.device}, descriptor_set_layout{other.descriptor_set_layout}, + pipeline_layout{other.pipeline_layout}, pipeline{other.pipeline}, + descriptor_count{other.descriptor_count} { + other.device = VK_NULL_HANDLE; + other.descriptor_set_layout = VK_NULL_HANDLE; + other.pipeline_layout = VK_NULL_HANDLE; + other.pipeline = VK_NULL_HANDLE; +} + +LsfgPass& LsfgPass::operator=(LsfgPass&& other) noexcept { + if (this != &other) { + Release(); + device = other.device; + descriptor_set_layout = other.descriptor_set_layout; + pipeline_layout = other.pipeline_layout; + pipeline = other.pipeline; + descriptor_count = other.descriptor_count; + other.device = VK_NULL_HANDLE; + other.descriptor_set_layout = VK_NULL_HANDLE; + other.pipeline_layout = VK_NULL_HANDLE; + other.pipeline = VK_NULL_HANDLE; + } + return *this; +} + +void LsfgPass::Release() { + if (device == VK_NULL_HANDLE) return; + if (pipeline) vkd.DestroyPipeline(device, pipeline, nullptr); + if (pipeline_layout) vkd.DestroyPipelineLayout(device, pipeline_layout, nullptr); + if (descriptor_set_layout) vkd.DestroyDescriptorSetLayout(device, descriptor_set_layout, nullptr); + pipeline = VK_NULL_HANDLE; + pipeline_layout = VK_NULL_HANDLE; + descriptor_set_layout = VK_NULL_HANDLE; +} + +void LsfgPass::Bind(VkCommandBuffer cmdbuf, VkDescriptorSet set) const { + BindPipeline(cmdbuf); + BindSet(cmdbuf, set); +} + +void LsfgPass::BindPipeline(VkCommandBuffer cmdbuf) const { + vkd.CmdBindPipeline(cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); +} + +void LsfgPass::BindSet(VkCommandBuffer cmdbuf, VkDescriptorSet set) const { + vkd.CmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &set, 0, + nullptr); +} + +VkDescriptorPool CreateLsfgDescriptorPool(const Device& device, uint32_t max_sets) { + const VkDescriptorType types[] = { + VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + VK_DESCRIPTOR_TYPE_SAMPLER, + VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + }; + + std::vector sizes; + for (const VkDescriptorType type : types) { + VkDescriptorPoolSize size{}; + size.type = type; + size.descriptorCount = DESCRIPTORS_PER_TYPE; + sizes.push_back(size); + } + + VkDescriptorPoolCreateInfo pool_ci{}; + pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_ci.maxSets = max_sets; + pool_ci.poolSizeCount = static_cast(sizes.size()); + pool_ci.pPoolSizes = sizes.data(); + + VkDescriptorPool pool = VK_NULL_HANDLE; + if (vkd.CreateDescriptorPool(device.Handle(), &pool_ci, nullptr, &pool) != VK_SUCCESS) { + return VK_NULL_HANDLE; + } + return pool; +} + +std::vector AllocateLsfgDescriptorSets(const Device& device, + VkDescriptorPool pool, + VkDescriptorSetLayout layout, + uint32_t count) { + if (pool == VK_NULL_HANDLE || layout == VK_NULL_HANDLE || count == 0) return {}; + + const std::vector layouts(count, layout); + VkDescriptorSetAllocateInfo allocate_info{}; + allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + allocate_info.descriptorPool = pool; + allocate_info.descriptorSetCount = count; + allocate_info.pSetLayouts = layouts.data(); + + std::vector sets(count, VK_NULL_HANDLE); + if (vkd.AllocateDescriptorSets(device.Handle(), &allocate_info, sets.data()) != VK_SUCCESS) { + return {}; + } + return sets; +} + +std::vector AllocateLsfgDescriptorSets( + const Device& device, VkDescriptorPool pool, + const std::vector& layouts) { + if (pool == VK_NULL_HANDLE || layouts.empty()) return {}; + for (const VkDescriptorSetLayout layout : layouts) { + if (layout == VK_NULL_HANDLE) return {}; + } + + VkDescriptorSetAllocateInfo allocate_info{}; + allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + allocate_info.descriptorPool = pool; + allocate_info.descriptorSetCount = static_cast(layouts.size()); + allocate_info.pSetLayouts = layouts.data(); + + std::vector sets(layouts.size(), VK_NULL_HANDLE); + if (vkd.AllocateDescriptorSets(device.Handle(), &allocate_info, sets.data()) != VK_SUCCESS) { + return {}; + } + return sets; +} + +VkSampler CreateLsfgSampler(const Device& device, VkSamplerAddressMode address_mode, + VkCompareOp compare_op, bool white_border) { + VkSamplerCreateInfo sampler_ci{}; + sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_ci.magFilter = VK_FILTER_LINEAR; + sampler_ci.minFilter = VK_FILTER_LINEAR; + sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + sampler_ci.addressModeU = address_mode; + sampler_ci.addressModeV = address_mode; + sampler_ci.addressModeW = address_mode; + sampler_ci.anisotropyEnable = VK_FALSE; + sampler_ci.compareEnable = VK_FALSE; + sampler_ci.compareOp = compare_op; + sampler_ci.maxLod = VK_LOD_CLAMP_NONE; + sampler_ci.borderColor = white_border ? VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE + : VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; + sampler_ci.unnormalizedCoordinates = VK_FALSE; + + VkSampler sampler = VK_NULL_HANDLE; + if (vkd.CreateSampler(device.Handle(), &sampler_ci, nullptr, &sampler) != VK_SUCCESS) { + return VK_NULL_HANDLE; + } + return sampler; +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_common.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_common.hpp new file mode 100644 index 0000000000..1f6b209833 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_common.hpp @@ -0,0 +1,331 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "lsfg_vkd.h" + +namespace lsfg { + +constexpr VkFormat LSFG_DEFAULT_FORMAT = VK_FORMAT_R8G8B8A8_UNORM; +constexpr VkFormat LSFG_FLOW_FORMAT = VK_FORMAT_R8_UNORM; +constexpr VkFormat LSFG_MOTION_FORMAT = VK_FORMAT_R16G16B16A16_SFLOAT; + +constexpr size_t LSFG_HISTORY_SLOTS = 3; +constexpr size_t LSFG_MAX_TARGETS = 7; +constexpr size_t LSFG_MAX_GENERATIONS = 3; +constexpr size_t LSFG_MIP_LEVELS = 7; + +constexpr size_t LSFG_GENERATION_SLOTS = LSFG_MAX_GENERATIONS * (LSFG_MAX_GENERATIONS + 1) / 2; +constexpr size_t LSFG_BARRIER_CAPACITY = 32; + +constexpr std::array LSFG_ALPHA_SHADERS{290, 291, 292, 293}; +constexpr std::array LSFG_BETA_SHADERS{298, 299, 300, 301, 302}; +constexpr std::array LSFG_GAMMA_SHADERS{280, 282, 283, 284, 285}; +constexpr std::array LSFG_DELTA_SHADERS{280, 286, 287, 288, 289, + 281, 294, 295, 296, 297}; + +[[nodiscard]] constexpr size_t LsfgGenerationSlot(size_t generation_count, size_t generation) { + return (generation_count - 1) * generation_count / 2 + generation; +} + +[[nodiscard]] constexpr float LsfgTimestamp(size_t generation, size_t generation_count) { + return static_cast(generation + 1) / + static_cast(generation_count + 1); +} + +[[nodiscard]] constexpr size_t LsfgSlotCount(size_t slot) { + size_t count = 1; + while (LsfgGenerationSlot(count + 1, 0) <= slot) { + ++count; + } + return count; +} + +[[nodiscard]] constexpr float LsfgSlotTimestamp(size_t slot) { + const size_t count = LsfgSlotCount(slot); + return LsfgTimestamp(slot - LsfgGenerationSlot(count, 0), count); +} + +class Device { +public: + Device() = default; + Device(VkDevice device_, VkPhysicalDevice physical_device_); + + [[nodiscard]] VkDevice Handle() const { + return device; + } + + [[nodiscard]] uint32_t FindMemoryType(uint32_t bits, VkMemoryPropertyFlags properties) const; + +private: + VkDevice device{VK_NULL_HANDLE}; + VkPhysicalDevice physical_device{VK_NULL_HANDLE}; + VkPhysicalDeviceMemoryProperties memory_properties{}; +}; + +class Buffer { +public: + Buffer() = default; + Buffer(const Device& device, VkDeviceSize size); + ~Buffer(); + + Buffer(const Buffer&) = delete; + Buffer& operator=(const Buffer&) = delete; + Buffer(Buffer&& other) noexcept; + Buffer& operator=(Buffer&& other) noexcept; + + [[nodiscard]] VkBuffer Handle() const { + return buffer; + } + + [[nodiscard]] bool Valid() const { + return buffer != VK_NULL_HANDLE; + } + + void Upload(const void* data, size_t size); + +private: + void Release(); + + VkDevice device{VK_NULL_HANDLE}; + VkBuffer buffer{VK_NULL_HANDLE}; + VkDeviceMemory memory{VK_NULL_HANDLE}; + void* mapped{nullptr}; +}; + +class LsfgImage { +public: + LsfgImage() = default; + LsfgImage(const Device& device, VkExtent2D extent, VkFormat format = LSFG_DEFAULT_FORMAT); + ~LsfgImage(); + + LsfgImage(const LsfgImage&) = delete; + LsfgImage& operator=(const LsfgImage&) = delete; + LsfgImage(LsfgImage&& other) noexcept; + LsfgImage& operator=(LsfgImage&& other) noexcept; + + [[nodiscard]] VkImage Handle() const { + return image; + } + + [[nodiscard]] VkImageView View() const { + return view; + } + + [[nodiscard]] VkExtent2D Extent() const { + return extent; + } + + [[nodiscard]] VkFormat Format() const { + return format; + } + + [[nodiscard]] VkImageLayout Layout() const { + return layout; + } + + [[nodiscard]] bool Valid() const { + return image != VK_NULL_HANDLE; + } + + void SetLayout(VkImageLayout new_layout) { + layout = new_layout; + } + +private: + void Release(); + + VkDevice device{VK_NULL_HANDLE}; + VkImage image{VK_NULL_HANDLE}; + VkImageView view{VK_NULL_HANDLE}; + VkDeviceMemory memory{VK_NULL_HANDLE}; + VkExtent2D extent{}; + VkFormat format{VK_FORMAT_UNDEFINED}; + VkImageLayout layout{VK_IMAGE_LAYOUT_UNDEFINED}; +}; + +using LsfgImagePair = std::array; +using LsfgImageHistory = std::array; + +class LsfgResources { +public: + LsfgResources() = default; + LsfgResources(const Device& device_, float flow_scale_) + : device{&device_}, flow_scale{flow_scale_} {} + + ~LsfgResources(); + + LsfgResources(const LsfgResources&) = delete; + LsfgResources& operator=(const LsfgResources&) = delete; + + [[nodiscard]] VkSampler GetSampler( + VkSamplerAddressMode address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, + VkCompareOp compare_op = VK_COMPARE_OP_NEVER, bool white_border = false); + + [[nodiscard]] VkBuffer GetBuffer(float timestamp = 0.0f, bool first_iter = false, + bool first_iter_s = false); + + [[nodiscard]] const LsfgImage& GetDummy(VkFormat format = LSFG_MOTION_FORMAT); + + void PrepareDummies(VkCommandBuffer cmdbuf); + + [[nodiscard]] static VkDeviceSize BufferSize(); + +private: + const Device* device{}; + float flow_scale{1.0f}; + + std::map samplers; + std::map buffers; + std::map dummies; + bool dummies_ready{}; +}; + +class LsfgBarriers { +public: + explicit LsfgBarriers(VkCommandBuffer cmdbuf_) : cmdbuf{cmdbuf_} { + barriers.reserve(LSFG_BARRIER_CAPACITY); + } + + LsfgBarriers& WriteToRead(LsfgImage& image); + LsfgBarriers& ReadToWrite(LsfgImage& image); + LsfgBarriers& WriteToRead(LsfgImage* image); + LsfgBarriers& ReadToWrite(LsfgImage* image); + LsfgBarriers& DiscardToWrite(VkImage image); + + template + LsfgBarriers& WriteToReadAll(Range& images) { + for (auto& image : images) { + WriteToRead(image); + } + return *this; + } + + template + LsfgBarriers& ReadToWriteAll(Range& images) { + for (auto& image : images) { + ReadToWrite(image); + } + return *this; + } + + void Build(); + +private: + LsfgBarriers& Push(LsfgImage& image, VkAccessFlags src_access, VkAccessFlags dst_access); + + VkCommandBuffer cmdbuf; + std::vector barriers; +}; + +class LsfgDescriptorWriter { +public: + explicit LsfgDescriptorWriter(VkDescriptorSet set_) : set{set_} {} + + LsfgDescriptorWriter& AddSampler(VkSampler sampler); + LsfgDescriptorWriter& AddSampledImage(const LsfgImage& image); + LsfgDescriptorWriter& AddSampledImage(const LsfgImage* image); + LsfgDescriptorWriter& AddStorageImage(const LsfgImage& image); + LsfgDescriptorWriter& AddStorageView(VkImageView view); + LsfgDescriptorWriter& AddUniformBuffer(VkBuffer buffer, VkDeviceSize size); + + template + LsfgDescriptorWriter& AddSampledImages(const Range& images) { + for (const auto& image : images) { + AddSampledImage(image); + } + return *this; + } + + template + LsfgDescriptorWriter& AddStorageImages(const Range& images) { + for (const auto& image : images) { + AddStorageImage(image); + } + return *this; + } + + void Build(const Device& device); + +private: + LsfgDescriptorWriter& PushImage(VkDescriptorType type, VkSampler sampler, VkImageView view); + + VkDescriptorSet set; + uint32_t binding{}; + std::deque image_infos; + std::deque buffer_infos; + std::vector writes; +}; + +using LsfgBindings = std::initializer_list>; + +class LsfgShaders; + +class LsfgPass { +public: + LsfgPass() = default; + LsfgPass(const Device& device, const LsfgShaders& shaders, uint32_t shader_id, + LsfgBindings bindings); + ~LsfgPass(); + + LsfgPass(const LsfgPass&) = delete; + LsfgPass& operator=(const LsfgPass&) = delete; + LsfgPass(LsfgPass&& other) noexcept; + LsfgPass& operator=(LsfgPass&& other) noexcept; + + [[nodiscard]] VkDescriptorSetLayout SetLayout() const { + return descriptor_set_layout; + } + + [[nodiscard]] uint32_t DescriptorCount() const { + return descriptor_count; + } + + [[nodiscard]] bool Valid() const { + return pipeline != VK_NULL_HANDLE; + } + + void Bind(VkCommandBuffer cmdbuf, VkDescriptorSet set) const; + void BindPipeline(VkCommandBuffer cmdbuf) const; + void BindSet(VkCommandBuffer cmdbuf, VkDescriptorSet set) const; + +private: + void Release(); + + VkDevice device{VK_NULL_HANDLE}; + VkDescriptorSetLayout descriptor_set_layout{VK_NULL_HANDLE}; + VkPipelineLayout pipeline_layout{VK_NULL_HANDLE}; + VkPipeline pipeline{VK_NULL_HANDLE}; + uint32_t descriptor_count{}; +}; + +[[nodiscard]] VkDescriptorPool CreateLsfgDescriptorPool(const Device& device, uint32_t max_sets); + +[[nodiscard]] std::vector AllocateLsfgDescriptorSets( + const Device& device, VkDescriptorPool pool, VkDescriptorSetLayout layout, uint32_t count); + +[[nodiscard]] std::vector AllocateLsfgDescriptorSets( + const Device& device, VkDescriptorPool pool, + const std::vector& layouts); + +[[nodiscard]] VkSampler CreateLsfgSampler(const Device& device, VkSamplerAddressMode address_mode, + VkCompareOp compare_op, bool white_border); + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_delta.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_delta.cpp new file mode 100644 index 0000000000..ddba102d5c --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_delta.cpp @@ -0,0 +1,293 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_delta.hpp" +#include "lsfg_shaders.hpp" + +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t DISPATCH_TILE_SHIFT = 3; + +[[nodiscard]] uint32_t GroupCount(uint32_t size) { + return (size + (1u << DISPATCH_TILE_SHIFT) - 1) >> DISPATCH_TILE_SHIFT; +} + +} + +LsfgDelta::LsfgDelta(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImageHistory& inputs_, + LsfgImage& flow_input_, LsfgImage* previous_gamma_, LsfgImage* previous1_, + LsfgImage* previous2_) + : inputs{&inputs_}, flow_input{&flow_input_}, previous_gamma{previous_gamma_}, + previous1{previous1_}, previous2{previous2_} { + passes[0] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[0], + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLER}, + {5, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {3, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[1] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[1], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {3, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[2] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[2], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[3] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[3], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[4] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[4], + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLER}, + {4, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[5] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[5], + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLER}, + {6, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + for (size_t i = 6; i < LSFG_DELTA_STAGES - 1; ++i) { + passes[i] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[i], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + } + passes[9] = LsfgPass(device, shaders, LSFG_DELTA_SHADERS[9], + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + for (const auto& pass : passes) { + if (!pass.Valid()) return; + } + + const VkExtent2D extent = (*inputs)[0][0].Extent(); + for (auto& image : temp1) { + image = LsfgImage(device, extent); + if (!image.Valid()) return; + } + for (auto& image : temp2) { + image = LsfgImage(device, extent); + if (!image.Valid()) return; + } + out_image1 = LsfgImage(device, extent, LSFG_MOTION_FORMAT); + out_image2 = LsfgImage(device, extent, LSFG_MOTION_FORMAT); + if (!out_image1.Valid() || !out_image2.Valid()) return; + + std::vector layouts; + for (size_t slot = 0; slot < LSFG_GENERATION_SLOTS; ++slot) { + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + layouts.push_back(passes[0].SetLayout()); + } + for (size_t i = 1; i <= 4; ++i) { + layouts.push_back(passes[i].SetLayout()); + } + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + layouts.push_back(passes[5].SetLayout()); + } + for (size_t i = 6; i < LSFG_DELTA_STAGES; ++i) { + layouts.push_back(passes[i].SetLayout()); + } + } + + const std::vector sets = + AllocateLsfgDescriptorSets(device, descriptor_pool, layouts); + if (sets.size() != layouts.size()) return; + + const LsfgImage& dummy = resources.GetDummy(LSFG_MOTION_FORMAT); + const LsfgImage& previous_gamma_image = previous_gamma != nullptr ? *previous_gamma : dummy; + const LsfgImage& previous1_image = previous1 != nullptr ? *previous1 : dummy; + const LsfgImage& previous2_image = previous2 != nullptr ? *previous2 : dummy; + if (!dummy.Valid()) return; + + const VkSampler sampler = resources.GetSampler(); + const VkSampler border_sampler = + resources.GetSampler(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_COMPARE_OP_NEVER, true); + const VkSampler edge_sampler = + resources.GetSampler(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_COMPARE_OP_ALWAYS, false); + + size_t next = 0; + for (size_t slot = 0; slot < LSFG_GENERATION_SLOTS; ++slot) { + Generation& pass = generations[slot]; + const VkBuffer buffer = + resources.GetBuffer(LsfgSlotTimestamp(slot), false, previous_gamma == nullptr); + + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + pass.first_descriptor_sets[i] = sets[next++]; + } + for (size_t i = 0; i < 4; ++i) { + pass.descriptor_sets[i] = sets[next++]; + } + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + pass.sixth_descriptor_sets[i] = sets[next++]; + } + for (size_t i = 4; i < LSFG_DELTA_STAGES - 2; ++i) { + pass.descriptor_sets[i] = sets[next++]; + } + + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + LsfgDescriptorWriter(pass.first_descriptor_sets[i]) + .AddUniformBuffer(buffer, LsfgResources::BufferSize()) + .AddSampler(border_sampler) + .AddSampler(edge_sampler) + .AddSampledImages((*inputs)[(i + 2) % LSFG_HISTORY_SLOTS]) + .AddSampledImages((*inputs)[i % LSFG_HISTORY_SLOTS]) + .AddSampledImage(previous_gamma_image) + .AddStorageImages(temp1) + .Build(device); + LsfgDescriptorWriter(pass.sixth_descriptor_sets[i]) + .AddUniformBuffer(buffer, LsfgResources::BufferSize()) + .AddSampler(border_sampler) + .AddSampler(edge_sampler) + .AddSampledImages((*inputs)[(i + 2) % LSFG_HISTORY_SLOTS]) + .AddSampledImages((*inputs)[i % LSFG_HISTORY_SLOTS]) + .AddSampledImage(previous_gamma_image) + .AddSampledImage(previous1_image) + .AddStorageImage(temp2[0]) + .Build(device); + } + LsfgDescriptorWriter(pass.descriptor_sets[0]) + .AddSampler(sampler) + .AddSampledImages(temp1) + .AddStorageImages(temp2) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[1]) + .AddSampler(sampler) + .AddSampledImages(temp2) + .AddStorageImage(temp1[0]) + .AddStorageImage(temp1[1]) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[2]) + .AddSampler(sampler) + .AddSampledImage(temp1[0]) + .AddSampledImage(temp1[1]) + .AddStorageImages(temp2) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[3]) + .AddUniformBuffer(buffer, LsfgResources::BufferSize()) + .AddSampler(sampler) + .AddSampler(edge_sampler) + .AddSampledImages(temp2) + .AddSampledImage(previous_gamma_image) + .AddSampledImage(*flow_input) + .AddStorageImage(out_image1) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[4]) + .AddSampler(sampler) + .AddSampledImage(temp2[0]) + .AddStorageImage(temp1[0]) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[5]) + .AddSampler(sampler) + .AddSampledImage(temp1[0]) + .AddStorageImage(temp2[0]) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[6]) + .AddSampler(sampler) + .AddSampledImage(temp2[0]) + .AddStorageImage(temp1[0]) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[7]) + .AddUniformBuffer(buffer, LsfgResources::BufferSize()) + .AddSampler(sampler) + .AddSampler(edge_sampler) + .AddSampledImage(temp1[0]) + .AddSampledImage(previous2_image) + .AddStorageImage(out_image2) + .Build(device); + } + allocated = true; +} + +void LsfgDelta::PushStepBarriers(LsfgBarriers& barriers, uint64_t frame_count, size_t step) { + const size_t history = frame_count % LSFG_HISTORY_SLOTS; + const size_t previous_history = (frame_count + 2) % LSFG_HISTORY_SLOTS; + + switch (step) { + case 0: + barriers.WriteToReadAll((*inputs)[previous_history]) + .WriteToReadAll((*inputs)[history]) + .WriteToRead(previous_gamma) + .ReadToWriteAll(temp1); + break; + case 1: + barriers.WriteToReadAll(temp1).ReadToWriteAll(temp2); + break; + case 2: + barriers.WriteToReadAll(temp2).ReadToWriteAll(temp1); + break; + case 3: + barriers.WriteToReadAll(temp1).ReadToWriteAll(temp2); + break; + case 4: + barriers.WriteToReadAll(temp2) + .WriteToRead(previous_gamma) + .WriteToRead(*flow_input) + .ReadToWrite(out_image1); + break; + case 5: + barriers.WriteToReadAll((*inputs)[previous_history]) + .WriteToReadAll((*inputs)[history]) + .WriteToRead(previous_gamma) + .WriteToRead(previous1) + .ReadToWriteAll(temp2); + break; + case 6: + barriers.WriteToReadAll(temp2).ReadToWrite(temp1[0]).ReadToWrite(temp1[1]); + break; + case 7: + barriers.WriteToRead(temp1[0]).WriteToRead(temp1[1]).ReadToWriteAll(temp2); + break; + case 8: + barriers.WriteToReadAll(temp2).ReadToWrite(temp1[0]).ReadToWrite(temp1[1]); + break; + default: + barriers.WriteToRead(temp1[0]) + .WriteToRead(temp1[1]) + .WriteToRead(previous2) + .ReadToWrite(out_image2); + break; + } +} + +void LsfgDelta::DispatchStep(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot, + size_t step) { + const Generation& pass = generations[slot]; + const VkExtent2D extent = temp1[0].Extent(); + const size_t history = frame_count % LSFG_HISTORY_SLOTS; + + if (step == 0) { + passes[0].Bind(cmdbuf, pass.first_descriptor_sets[history]); + } else if (step == 5) { + passes[5].Bind(cmdbuf, pass.sixth_descriptor_sets[history]); + } else if (step < 5) { + passes[step].Bind(cmdbuf, pass.descriptor_sets[step - 1]); + } else { + passes[step].Bind(cmdbuf, pass.descriptor_sets[step - 2]); + } + vkd.CmdDispatch(cmdbuf, GroupCount(extent.width), GroupCount(extent.height), 1); +} + +void LsfgDelta::Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot) { + for (size_t step = 0; step < LSFG_DELTA_STAGES; ++step) { + LsfgBarriers barriers(cmdbuf); + PushStepBarriers(barriers, frame_count, step); + barriers.Build(); + DispatchStep(cmdbuf, frame_count, slot, step); + } +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_delta.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_delta.hpp new file mode 100644 index 0000000000..8d82326752 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_delta.hpp @@ -0,0 +1,74 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include + +#include "lsfg_common.hpp" + +namespace lsfg { + +class LsfgShaders; + +constexpr size_t LSFG_DELTA_STAGES = 10; +constexpr size_t LSFG_DELTA_TEMPS = 3; + +class LsfgDelta { +public: + LsfgDelta() = default; + LsfgDelta(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImageHistory& inputs, LsfgImage& flow_input, + LsfgImage* previous_gamma, LsfgImage* previous1, LsfgImage* previous2); + + void Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot); + + void PushStepBarriers(LsfgBarriers& barriers, uint64_t frame_count, size_t step); + + void DispatchStep(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot, + size_t step); + + [[nodiscard]] LsfgImage& Output1() { + return out_image1; + } + + [[nodiscard]] LsfgImage& Output2() { + return out_image2; + } + + [[nodiscard]] bool Valid() const { + return allocated; + } + +private: + struct Generation { + std::array first_descriptor_sets{}; + std::array sixth_descriptor_sets{}; + std::array descriptor_sets{}; + }; + + LsfgImageHistory* inputs{}; + LsfgImage* flow_input{}; + LsfgImage* previous_gamma{}; + LsfgImage* previous1{}; + LsfgImage* previous2{}; + + std::array passes; + std::array generations{}; + + std::array temp1; + LsfgImagePair temp2; + LsfgImage out_image1; + LsfgImage out_image2; + bool allocated{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_dll.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_dll.cpp new file mode 100644 index 0000000000..764a567f86 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_dll.cpp @@ -0,0 +1,702 @@ +// See lsfg_dll.h. PE resource walk + on-device SPIR-V cache for the Lossless +// Scaling frame-generation chain. +// +// Derived from WinNative's lsfg_dll.c (GPL-3.0-or-later), LSFG port credited to +// Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk +// (PancakeTAS). Bannerlator is GPL-3.0. + +#include "lsfg_dll.h" +#include "lsfg_dxbc.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define LOG_TAG "LsfgDll" +#define LSFG_LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define LSFG_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) + +namespace lsfg { +namespace { + +// ---- PE constants --------------------------------------------------------- +constexpr uint16_t kDosMagic = 0x5A4Du; // "MZ" +constexpr uint32_t kPeSignature = 0x00004550u; // "PE\0\0" +constexpr uint16_t kPe32Magic = 0x010Bu; +constexpr uint16_t kPe32PlusMagic = 0x020Bu; + +constexpr size_t kDosLfanewOffset = 0x3Cu; +constexpr size_t kCoffHeaderSize = 20u; +constexpr size_t kOptionalHeaderSizeOff = 16u; +constexpr size_t kDataDirectoryEntrySize = 8u; +constexpr size_t kDataDirectoryOffPe32 = 96u; +constexpr size_t kDataDirectoryOffPe32P = 112u; +constexpr size_t kResourceDirectoryIndex = 2u; +constexpr size_t kSectionHeaderSize = 40u; + +constexpr size_t kResourceDirectorySize = 16u; +constexpr size_t kResourceNamedCountOff = 12u; +constexpr size_t kResourceIdCountOff = 14u; +constexpr size_t kResourceEntrySize = 8u; +constexpr uint32_t kResourceSubdirectoryBit = 0x80000000u; +constexpr uint32_t kResourceTypeRcData = 10u; + +// ---- SPIR-V constants ----------------------------------------------------- +constexpr uint32_t kSpirvMagic = 0x07230203u; +constexpr size_t kSpirvHeaderWords = 5u; +constexpr uint32_t kSpirvWordCountShift = 16u; +constexpr uint32_t kSpirvOpcodeMask = 0xFFFFu; +constexpr uint32_t kSpirvOpFunction = 54u; +constexpr uint32_t kSpirvOpDecorate = 71u; +constexpr uint32_t kDecorationBinding = 33u; +constexpr uint32_t kDecorationDescriptorSet = 34u; +constexpr size_t kDecorationLiteralWord = 3u; + +constexpr uint32_t kVariantFp16Offset = 49u; +constexpr uint32_t kVariantFp32Offset = 98u; + +constexpr uint32_t kMaxResourceId = 512u; +constexpr size_t kMaxSpirvWords = 16u * 1024u * 1024u; + +constexpr uint32_t kCacheMagic = 0x4C534642u; // "BFSL" little-endian +constexpr uint32_t kCacheVersion = 1u; + +struct CacheHeader { + uint32_t magic; + uint32_t version; + uint64_t sourceSize; + uint64_t sourceHash; + uint32_t moduleCount; + uint32_t variant; +}; + +struct PeSection { + uint32_t virtualAddress = 0; + uint32_t virtualSize = 0; + uint32_t rawAddress = 0; + uint32_t rawSize = 0; +}; + +// Read-only mapping of the DLL. Closes itself; the DLL is never executed. +class PeImage { +public: + ~PeImage() { close(); } + + bool open(const std::string& path) { + fd_ = ::open(path.c_str(), O_RDONLY | O_CLOEXEC); + if (fd_ < 0) return false; + struct stat info{}; + if (fstat(fd_, &info) != 0 || info.st_size <= 0) { close(); return false; } + size_ = (size_t)info.st_size; + void* m = mmap(nullptr, size_, PROT_READ, MAP_PRIVATE, fd_, 0); + if (m == MAP_FAILED) { close(); return false; } + data_ = (const uint8_t*)m; + return true; + } + + void close() { + if (data_) { munmap((void*)data_, size_); data_ = nullptr; } + if (fd_ >= 0) { ::close(fd_); fd_ = -1; } + size_ = 0; + sections_.clear(); + } + + const uint8_t* data() const { return data_; } + size_t size() const { return size_; } + + bool readU16(size_t off, uint16_t& out) const { + if (off > size_ || size_ - off < sizeof(uint16_t)) return false; + memcpy(&out, data_ + off, sizeof(uint16_t)); + return true; + } + bool readU32(size_t off, uint32_t& out) const { + if (off > size_ || size_ - off < sizeof(uint32_t)) return false; + memcpy(&out, data_ + off, sizeof(uint32_t)); + return true; + } + + bool findPeHeader(size_t& outOffset) const { + uint16_t dos = 0; + if (!readU16(0, dos) || dos != kDosMagic) return false; + uint32_t peOff = 0; + if (!readU32(kDosLfanewOffset, peOff)) return false; + uint32_t sig = 0; + if (!readU32(peOff, sig) || sig != kPeSignature) return false; + outOffset = (size_t)peOff; + return true; + } + + bool readSections(size_t peOffset) { + uint16_t count = 0, optSize = 0; + if (!readU16(peOffset + 4 + 2, count) || + !readU16(peOffset + 4 + kOptionalHeaderSizeOff, optSize)) return false; + if (count == 0) return false; + + sections_.assign(count, PeSection{}); + const size_t table = peOffset + 4 + kCoffHeaderSize + optSize; + for (uint16_t i = 0; i < count; i++) { + const size_t off = table + (size_t)i * kSectionHeaderSize; + PeSection& s = sections_[i]; + if (!readU32(off + 8, s.virtualSize) || + !readU32(off + 12, s.virtualAddress) || + !readU32(off + 16, s.rawSize) || + !readU32(off + 20, s.rawAddress)) { sections_.clear(); return false; } + } + return true; + } + + bool rvaToOffset(uint32_t rva, size_t& outOffset) const { + for (const PeSection& s : sections_) { + const uint32_t span = s.virtualSize > s.rawSize ? s.virtualSize : s.rawSize; + if (span == 0 || rva < s.virtualAddress) continue; + const uint32_t rel = rva - s.virtualAddress; + if (rel < span) { outOffset = (size_t)s.rawAddress + rel; return true; } + } + return false; + } + +private: + int fd_ = -1; + const uint8_t* data_ = nullptr; + size_t size_ = 0; + std::vector sections_; +}; + +// RCDATA id -> blob, for the ids we care about. +struct ResourceTable { + const uint8_t* data[kMaxResourceId] = {}; + uint32_t size[kMaxResourceId] = {}; +}; + +uint64_t fnv1a64(const uint8_t* data, size_t size) { + uint64_t hash = 1469598103934665603ULL; + for (size_t i = 0; i < size; i++) { + hash ^= (uint64_t)data[i]; + hash *= 1099511628211ULL; + } + return hash; +} + +bool resourceEntryCount(const PeImage& img, size_t dirOffset, size_t& outTotal) { + uint16_t named = 0, ids = 0; + if (!img.readU16(dirOffset + kResourceNamedCountOff, named) || + !img.readU16(dirOffset + kResourceIdCountOff, ids)) return false; + outTotal = (size_t)named + (size_t)ids; + return true; +} + +bool resourceEntryAt(const PeImage& img, size_t dirOffset, size_t index, + uint32_t& outId, uint32_t& outOffset, + bool& outIsDirectory, bool& outIsNamed) { + const size_t off = dirOffset + kResourceDirectorySize + index * kResourceEntrySize; + uint32_t name = 0, data = 0; + if (!img.readU32(off, name) || !img.readU32(off + 4, data)) return false; + outId = name & ~kResourceSubdirectoryBit; + outOffset = data & ~kResourceSubdirectoryBit; + outIsDirectory = (data & kResourceSubdirectoryBit) != 0; + outIsNamed = (name & kResourceSubdirectoryBit) != 0; + return true; +} + +bool resourceReadLeaf(const PeImage& img, size_t leafOffset, + const uint8_t*& outData, uint32_t& outSize) { + uint32_t rva = 0, size = 0; + if (!img.readU32(leafOffset, rva) || !img.readU32(leafOffset + 4, size) || size == 0) + return false; + size_t dataOffset = 0; + if (!img.rvaToOffset(rva, dataOffset)) return false; + if (dataOffset > img.size() || img.size() - dataOffset < size) return false; + outData = img.data() + dataOffset; + outSize = size; + return true; +} + +// Walk type -> name -> language and keep the first language of every RCDATA id. +bool collectRcData(const PeImage& img, size_t resourceBase, ResourceTable& out) { + size_t typeTotal = 0; + if (!resourceEntryCount(img, resourceBase, typeTotal)) return false; + + for (size_t t = 0; t < typeTotal; t++) { + uint32_t typeId = 0, typeOffset = 0; + bool typeIsDir = false, typeIsNamed = false; + if (!resourceEntryAt(img, resourceBase, t, typeId, typeOffset, typeIsDir, typeIsNamed)) + return false; + if (typeIsNamed || typeId != kResourceTypeRcData || !typeIsDir) continue; + + const size_t nameBase = resourceBase + typeOffset; + size_t nameTotal = 0; + if (!resourceEntryCount(img, nameBase, nameTotal)) return false; + + for (size_t n = 0; n < nameTotal; n++) { + uint32_t nameId = 0, nameOffset = 0; + bool nameIsDir = false, nameIsNamed = false; + if (!resourceEntryAt(img, nameBase, n, nameId, nameOffset, nameIsDir, nameIsNamed)) + return false; + if (nameIsNamed || !nameIsDir || nameId >= kMaxResourceId) continue; + + const size_t langBase = resourceBase + nameOffset; + size_t langTotal = 0; + if (!resourceEntryCount(img, langBase, langTotal)) return false; + + for (size_t l = 0; l < langTotal; l++) { + uint32_t langId = 0, langOffset = 0; + bool langIsDir = false, langIsNamed = false; + if (!resourceEntryAt(img, langBase, l, langId, langOffset, langIsDir, langIsNamed)) + return false; + if (langIsDir) continue; + + const uint8_t* blob = nullptr; + uint32_t blobSize = 0; + if (!resourceReadLeaf(img, resourceBase + langOffset, blob, blobSize)) continue; + out.data[nameId] = blob; + out.size[nameId] = blobSize; + break; // first language wins + } + } + } + return true; +} + +DllStatus parseResources(PeImage& img, ResourceTable& table) { + size_t peOffset = 0; + if (!img.findPeHeader(peOffset)) return DllStatus::NotPortableExecutable; + if (!img.readSections(peOffset)) return DllStatus::NotPortableExecutable; + + uint16_t optionalMagic = 0; + const size_t optionalHeaderOffset = peOffset + 4 + kCoffHeaderSize; + if (!img.readU16(optionalHeaderOffset, optionalMagic)) return DllStatus::NotPortableExecutable; + + size_t dataDirectory = 0; + if (optionalMagic == kPe32Magic) dataDirectory = optionalHeaderOffset + kDataDirectoryOffPe32; + else if (optionalMagic == kPe32PlusMagic) dataDirectory = optionalHeaderOffset + kDataDirectoryOffPe32P; + else return DllStatus::NotPortableExecutable; + + uint32_t resourceRva = 0; + if (!img.readU32(dataDirectory + kResourceDirectoryIndex * kDataDirectoryEntrySize, resourceRva) + || resourceRva == 0) { + return DllStatus::MissingShaders; + } + + size_t resourceBase = 0; + if (!img.rvaToOffset(resourceRva, resourceBase)) return DllStatus::MissingShaders; + if (!collectRcData(img, resourceBase, table)) return DllStatus::MissingShaders; + return DllStatus::Ok; +} + +// ---- SPIR-V adoption (precompiled-variant path) --------------------------- + +bool isSpirvModule(const uint8_t* blob, uint32_t size) { + if (!blob || size < kSpirvHeaderWords * sizeof(uint32_t)) return false; + if (size % sizeof(uint32_t) != 0) return false; + uint32_t magic = 0; + memcpy(&magic, blob, sizeof(magic)); + return magic == kSpirvMagic; +} + +uint32_t lookupDescriptorSet(const std::vector& w, uint32_t targetId) { + size_t off = kSpirvHeaderWords; + while (off < w.size()) { + const uint32_t length = w[off] >> kSpirvWordCountShift; + const uint32_t opcode = w[off] & kSpirvOpcodeMask; + if (length == 0 || off + length > w.size()) break; + if (opcode == kSpirvOpFunction) break; + if (opcode == kSpirvOpDecorate && length >= 4 && + w[off + 2] == kDecorationDescriptorSet && w[off + 1] == targetId) { + return w[off + 3]; + } + off += length; + } + return 0; +} + +// Precompiled blobs are renumbered into set/binding order — that is the +// convention they were built with. The DXBC path uses encounter order instead +// (see lsfg_dxbc), which is what DXVK's output pairs with. Do not merge them. +bool renumberBindingsSetOrder(std::vector& w) { + struct Slot { uint32_t set; uint32_t binding; size_t literalOffset; }; + std::vector slots; + + size_t off = kSpirvHeaderWords; + while (off < w.size()) { + const uint32_t length = w[off] >> kSpirvWordCountShift; + const uint32_t opcode = w[off] & kSpirvOpcodeMask; + if (length == 0 || off + length > w.size()) return false; + if (opcode == kSpirvOpFunction) break; + if (opcode == kSpirvOpDecorate && length >= 4 && w[off + 2] == kDecorationBinding) { + slots.push_back(Slot{ lookupDescriptorSet(w, w[off + 1]), + w[off + 3], + off + kDecorationLiteralWord }); + } + off += length; + } + if (slots.empty()) return true; + + std::sort(slots.begin(), slots.end(), [](const Slot& a, const Slot& b) { + return a.set != b.set ? a.set < b.set : a.binding < b.binding; + }); + for (size_t i = 0; i < slots.size(); i++) w[slots[i].literalOffset] = (uint32_t)i; + return true; +} + +bool adoptSpirv(const uint8_t* blob, uint32_t size, std::vector& outWords) { + if (!isSpirvModule(blob, size)) return false; + const size_t wordCount = size / sizeof(uint32_t); + if (wordCount > kMaxSpirvWords) return false; + + outWords.resize(wordCount); + memcpy(outWords.data(), blob, wordCount * sizeof(uint32_t)); + if (!renumberBindingsSetOrder(outWords)) { outWords.clear(); return false; } + return true; +} + +bool hasNativeVariant(const ResourceTable& t, uint32_t variantOffset) { + for (uint32_t id : shaderIds()) { + const uint32_t vid = id + variantOffset; + if (vid >= kMaxResourceId) return false; + if (!isSpirvModule(t.data[vid], t.size[vid])) return false; + } + return true; +} + +bool hasBaseChain(const ResourceTable& t) { + for (uint32_t id : shaderIds()) { + if (id >= kMaxResourceId || t.data[id] == nullptr) return false; + } + return true; +} + +Variant selectVariant(const ResourceTable& t, bool preferFp16) { + if (preferFp16 && hasNativeVariant(t, kVariantFp16Offset)) return Variant::SpirvFp16; + if (hasNativeVariant(t, kVariantFp32Offset)) return Variant::SpirvFp32; + if (hasNativeVariant(t, kVariantFp16Offset)) return Variant::SpirvFp16; + return Variant::None; +} + +uint32_t variantOffset(Variant v) { + return v == Variant::SpirvFp16 ? kVariantFp16Offset : kVariantFp32Offset; +} + +bool writeCache(const std::string& cachePath, const CacheHeader& header, const ModuleSet& set) { + const std::string tempPath = cachePath + ".tmp"; + FILE* f = fopen(tempPath.c_str(), "wb"); + if (!f) return false; + + bool ok = fwrite(&header, sizeof(header), 1, f) == 1; + for (size_t i = 0; ok && i < set.modules.size(); i++) { + const Module& m = set.modules[i]; + const uint32_t wordCount = (uint32_t)m.words.size(); + ok = fwrite(&m.id, sizeof(m.id), 1, f) == 1 + && fwrite(&wordCount, sizeof(wordCount), 1, f) == 1 + && fwrite(m.words.data(), sizeof(uint32_t), wordCount, f) == wordCount; + } + if (ok) ok = fflush(f) == 0; + if (ok) ok = fsync(fileno(f)) == 0; + fclose(f); + + // Temp file + rename, so a failed or interrupted build can never leave a + // half-written cache that would later be loaded as if it were complete. + if (!ok || rename(tempPath.c_str(), cachePath.c_str()) != 0) { + unlink(tempPath.c_str()); + return false; + } + return true; +} + +bool readCacheHeader(const std::string& cachePath, CacheHeader& out) { + FILE* f = fopen(cachePath.c_str(), "rb"); + if (!f) return false; + const bool ok = fread(&out, sizeof(out), 1, f) == 1; + fclose(f); + return ok && out.magic == kCacheMagic && out.version == kCacheVersion; +} + +} // namespace + +// ---- public API ----------------------------------------------------------- + +const std::vector& shaderIds() { + static const std::vector ids = [] { + std::vector v; + v.reserve(kShaderCount); + v.push_back(kShaderMipmaps); + v.push_back(kShaderGenerate); + for (uint32_t id = kShaderChainFirst; id <= kShaderChainLast; id++) v.push_back(id); + return v; + }(); + return ids; +} + +const std::vector* ModuleSet::find(uint32_t id) const { + for (const Module& m : modules) if (m.id == id) return &m.words; + return nullptr; +} + +bool ModuleSet::complete() const { + if (modules.size() != kShaderCount) return false; + for (uint32_t id : shaderIds()) if (!find(id)) return false; + return true; +} + +const char* statusName(DllStatus s) { + switch (s) { + case DllStatus::Ok: return "ok"; + case DllStatus::NotInstalled: return "not installed"; + case DllStatus::UnreadableFile: return "unreadable file"; + case DllStatus::NotPortableExecutable: return "not a PE file"; + case DllStatus::MissingShaders: return "missing shaders"; + case DllStatus::TranslationFailed: return "shader translation failed"; + case DllStatus::CacheUnusable: return "cache unusable"; + } + return "unknown"; +} + +const char* variantName(Variant v) { + switch (v) { + case Variant::SpirvFp16: return "spirv-fp16"; + case Variant::SpirvFp32: return "spirv-fp32"; + case Variant::DxbcTranslated: return "dxbc-translated"; + case Variant::None: return "none"; + } + return "none"; +} + +DllStatus validateDll(const std::string& dllPath) { + if (dllPath.empty()) return DllStatus::NotInstalled; + + PeImage img; + if (!img.open(dllPath)) return DllStatus::NotInstalled; + + ResourceTable table; + DllStatus status = parseResources(img, table); + if (status == DllStatus::Ok && !hasBaseChain(table)) status = DllStatus::MissingShaders; + return status; +} + +Variant dllVariant(const std::string& dllPath, bool preferFp16) { + if (dllPath.empty()) return Variant::None; + + PeImage img; + if (!img.open(dllPath)) return Variant::None; + + ResourceTable table; + if (parseResources(img, table) != DllStatus::Ok) return Variant::None; + + Variant v = selectVariant(table, preferFp16); + if (v == Variant::None && hasBaseChain(table)) v = Variant::DxbcTranslated; + return v; +} + +DllStatus buildCache(const std::string& dllPath, const std::string& cachePath, bool preferFp16) { + if (dllPath.empty() || cachePath.empty()) return DllStatus::NotInstalled; + + PeImage img; + if (!img.open(dllPath)) return DllStatus::NotInstalled; + + ResourceTable table; + DllStatus status = parseResources(img, table); + if (status != DllStatus::Ok) return status; + + const Variant precompiled = selectVariant(table, preferFp16); + const bool translate = precompiled == Variant::None; + if (translate && !hasBaseChain(table)) return DllStatus::MissingShaders; + + ModuleSet set; + set.variant = translate ? Variant::DxbcTranslated : precompiled; + set.modules.reserve(kShaderCount); + + const uint32_t offset = translate ? 0u : variantOffset(precompiled); + for (uint32_t id : shaderIds()) { + const uint32_t resourceId = id + offset; + if (resourceId >= kMaxResourceId) return DllStatus::MissingShaders; + + Module m; + m.id = id; + const bool ok = translate + ? translateDxbc(table.data[resourceId], table.size[resourceId], m.words) + : adoptSpirv(table.data[resourceId], table.size[resourceId], m.words); + if (!ok || m.words.empty()) { + LSFG_LOGE("shader %u (%s) failed", id, translate ? "dxbc" : "spirv"); + return DllStatus::TranslationFailed; + } + set.modules.push_back(std::move(m)); + } + + CacheHeader header{}; + header.magic = kCacheMagic; + header.version = kCacheVersion; + header.sourceSize = (uint64_t)img.size(); + header.sourceHash = fnv1a64(img.data(), img.size()); + header.moduleCount = (uint32_t)set.modules.size(); + header.variant = (uint32_t)set.variant; + + if (!writeCache(cachePath, header, set)) { + LSFG_LOGE("cache write failed: %s", cachePath.c_str()); + return DllStatus::CacheUnusable; + } + + size_t totalWords = 0; + for (const Module& m : set.modules) totalWords += m.words.size(); + LSFG_LOGI("cached %zu LSFG modules, %zu SPIR-V words (%s)", + set.modules.size(), totalWords, variantName(set.variant)); + return DllStatus::Ok; +} + +DllStatus cacheMatchesSource(const std::string& cachePath, const std::string& dllPath, + bool& outMatches) { + outMatches = false; + if (cachePath.empty() || dllPath.empty()) return DllStatus::CacheUnusable; + + CacheHeader header{}; + if (!readCacheHeader(cachePath, header)) return DllStatus::CacheUnusable; + + PeImage img; + if (!img.open(dllPath)) return DllStatus::NotInstalled; + + outMatches = header.sourceSize == (uint64_t)img.size() + && header.sourceHash == fnv1a64(img.data(), img.size()); + return DllStatus::Ok; +} + +DllStatus cacheVariant(const std::string& cachePath, Variant& outVariant) { + outVariant = Variant::None; + CacheHeader header{}; + if (!readCacheHeader(cachePath, header)) return DllStatus::CacheUnusable; + if (header.variant > (uint32_t)Variant::DxbcTranslated) return DllStatus::CacheUnusable; + outVariant = (Variant)header.variant; + return DllStatus::Ok; +} + +DllStatus loadModules(const std::string& cachePath, ModuleSet& outSet) { + outSet.modules.clear(); + outSet.variant = Variant::None; + if (cachePath.empty()) return DllStatus::CacheUnusable; + + FILE* f = fopen(cachePath.c_str(), "rb"); + if (!f) return DllStatus::NotInstalled; + + CacheHeader header{}; + if (fread(&header, sizeof(header), 1, f) != 1 || header.magic != kCacheMagic || + header.version != kCacheVersion || header.moduleCount != kShaderCount) { + fclose(f); + return DllStatus::CacheUnusable; + } + outSet.variant = (Variant)header.variant; + outSet.modules.reserve(header.moduleCount); + + DllStatus status = DllStatus::Ok; + for (uint32_t i = 0; i < header.moduleCount; i++) { + uint32_t id = 0, wordCount = 0; + if (fread(&id, sizeof(id), 1, f) != 1 || + fread(&wordCount, sizeof(wordCount), 1, f) != 1 || + wordCount == 0 || wordCount > kMaxSpirvWords) { + status = DllStatus::CacheUnusable; + break; + } + Module m; + m.id = id; + m.words.resize(wordCount); + if (fread(m.words.data(), sizeof(uint32_t), wordCount, f) != wordCount) { + status = DllStatus::CacheUnusable; + break; + } + outSet.modules.push_back(std::move(m)); + } + fclose(f); + + if (status == DllStatus::Ok && !outSet.complete()) status = DllStatus::MissingShaders; + if (status != DllStatus::Ok) { outSet.modules.clear(); outSet.variant = Variant::None; } + return status; +} + +// ---- SPIR-V version lowering (Vulkan 1.1/1.2 compat) ---------------------- + +namespace { + +constexpr uint32_t kSpirvOpExtension = 10u; +constexpr uint32_t kSpirvOpExtInstImport= 11u; +constexpr uint32_t kSpirvOpMemoryModel = 14u; +constexpr uint32_t kSpirvOpCapability = 17u; + +// Capabilities that are core in the version the translator emits but not in +// the versions we lower to. +constexpr uint32_t kCapVulkanMemoryModel = 5345u; // core from 1.5 +constexpr uint32_t kCapVulkanMemoryModelDeviceScope = 5346u; // core from 1.5 +constexpr uint32_t kCapDemoteToHelperInvocation = 5379u; // core from 1.6 + +std::vector encodeOpExtension(const char* name) { + const size_t len = strlen(name) + 1; // incl. NUL + const size_t strWords = (len + 3) / 4; + std::vector ins(1 + strWords, 0u); + ins[0] = ((uint32_t)(1 + strWords) << kSpirvWordCountShift) | kSpirvOpExtension; + memcpy(&ins[1], name, len); + return ins; +} + +bool hasOpExtension(const std::vector& w, const char* name) { + size_t off = kSpirvHeaderWords; + while (off < w.size()) { + const uint32_t length = w[off] >> kSpirvWordCountShift; + const uint32_t opcode = w[off] & kSpirvOpcodeMask; + if (length == 0 || off + length > w.size()) return false; + if (opcode == kSpirvOpFunction || opcode == kSpirvOpMemoryModel) break; + if (opcode == kSpirvOpExtension && length >= 2) { + const char* s = reinterpret_cast(&w[off + 1]); + if (strncmp(s, name, (length - 1) * 4) == 0) return true; + } + off += length; + } + return false; +} + +} // namespace + +bool downgradeSpirv(std::vector& w, uint32_t targetVersion) { + if (w.size() < kSpirvHeaderWords || w[0] != kSpirvMagic) return false; + if (targetVersion < kSpirv14) return false; + if (w[1] <= targetVersion) return true; // already low enough + + // Walk the preamble first and only touch the module once it is known to + // be lowerable: note which extension-gated capabilities are declared and + // where the capability block ends (OpExtension must follow every + // OpCapability and precede OpExtInstImport / OpMemoryModel). + bool needMemoryModel = false; + size_t insertAt = kSpirvHeaderWords; + size_t off = kSpirvHeaderWords; + while (off < w.size()) { + const uint32_t length = w[off] >> kSpirvWordCountShift; + const uint32_t opcode = w[off] & kSpirvOpcodeMask; + if (length == 0 || off + length > w.size()) return false; + if (opcode == kSpirvOpCapability && length >= 2) { + const uint32_t cap = w[off + 1]; + if (cap == kCapVulkanMemoryModel || cap == kCapVulkanMemoryModelDeviceScope) needMemoryModel = true; + // Core only in 1.6, and VK_EXT_shader_demote_to_helper_invocation + // is never enabled on the compat path: refuse rather than hand the + // driver a module that is not legal at the lowered version. + if (cap == kCapDemoteToHelperInvocation) return false; + insertAt = off + length; + } else if (opcode == kSpirvOpExtension) { + insertAt = off + length; + } else if (opcode == kSpirvOpExtInstImport || opcode == kSpirvOpMemoryModel + || opcode == kSpirvOpFunction) { + break; + } + off += length; + } + + // 1.5 has the memory model as core; only 1.4 needs it declared. + if (targetVersion < kSpirv15 && needMemoryModel + && !hasOpExtension(w, "SPV_KHR_vulkan_memory_model")) { + const auto e = encodeOpExtension("SPV_KHR_vulkan_memory_model"); + w.insert(w.begin() + (std::ptrdiff_t)insertAt, e.begin(), e.end()); + } + w[1] = targetVersion; + return true; +} + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_dll.h b/app/src/main/cpp/winlator/lsfg/lsfg_dll.h new file mode 100644 index 0000000000..fc46dd2606 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_dll.h @@ -0,0 +1,134 @@ +#pragma once +// ============================================================================ +// lsfg_dll — extract the Lossless Scaling frame-generation shader chain from +// the user's own Lossless.dll, and cache it on device as SPIR-V. +// +// The 25 compute shaders that make up LSFG 3.1 are NOT redistributable. They +// ship as RCDATA resources inside Lossless.dll from the user's own paid copy +// of Lossless Scaling (Steam app 993090). Every implementation — upstream +// lsfg-vk, LSFG-Android, eden, WinNative — requires the user to supply their +// own DLL and extracts the resources on device. Bannerlator does the same, and +// bundles nothing. +// +// The DLL is mmap'd READ-ONLY and parsed as data. It is never loaded as a +// library and never executed. +// +// Resource layout, measured against real installs: +// * The base chain lives at RCDATA ids 255, 256 and 280-302 (25 modules), +// and is DXBC. It has always been DXBC. +// * Lossless Scaling MAY additionally carry precompiled SPIR-V copies at +// base+49 (native fp16) and base+98 (native fp32). No build currently +// downloadable from Steam carries them — public buildId 19655272 was +// measured with zero SPIR-V anywhere in the 311 MB install — so the DXBC +// path is the normal path and the translator is not optional. The SPIR-V +// path is kept because it costs nothing and a future build may ship them. +// +// Both producers fill the same shader-id -> SPIR-V words map, so everything +// downstream of this file is source-agnostic. +// +// Derived from WinNative's lsfg_dll.c (GPL-3.0-or-later), whose LSFG port is +// credited to Camille LaVey / the Eden Emulator Project, and which follows +// upstream lsfg-vk (PancakeTAS). Bannerlator is GPL-3.0; see THIRD-PARTY-LICENSES.md. +// ============================================================================ + +#include +#include +#include + +namespace lsfg { + +enum class DllStatus { + Ok = 0, + NotInstalled, // no such file / cannot open + UnreadableFile, // opens but cannot be mapped or is empty + NotPortableExecutable, + MissingShaders, // parses, but the base chain is not all there + TranslationFailed, // a shader failed DXBC->SPIR-V or SPIR-V adoption + CacheUnusable // cache could not be written or read back +}; + +// SPIR-V version words. The translator emits 1.6; a Vulkan 1.1 device takes +// 1.4 (via VK_KHR_spirv_1_4) and a 1.2 device 1.5. One definition for the +// probe, the engine and the shader loader. +constexpr uint32_t kSpirv14 = 0x00010400u; +constexpr uint32_t kSpirv15 = 0x00010500u; +constexpr uint32_t kSpirv16 = 0x00010600u; + +enum class Variant { + None = 0, + SpirvFp16, // precompiled fp16 blobs at base+49 + SpirvFp32, // precompiled fp32 blobs at base+98 + DxbcTranslated // base chain, translated on device (the normal case) +}; + +// The 25 shader ids that make up the chain. +constexpr uint32_t kShaderMipmaps = 255u; +constexpr uint32_t kShaderGenerate = 256u; +constexpr uint32_t kShaderChainFirst= 280u; +constexpr uint32_t kShaderChainLast = 302u; +constexpr uint32_t kShaderCount = 25u; + +// Upstream spelling for the two ids the ported chain files refer to by name. +// Kept so those files stay byte-close to their upstream form; these alias the +// constants above rather than being a second source of truth. +constexpr uint32_t LSFG_SHADER_MIPMAPS = kShaderMipmaps; +constexpr uint32_t LSFG_SHADER_GENERATE = kShaderGenerate; + +struct Module { + uint32_t id = 0; + std::vector words; // SPIR-V +}; + +struct ModuleSet { + std::vector modules; + Variant variant = Variant::None; + + const std::vector* find(uint32_t id) const; + bool complete() const; +}; + +// The canonical shader-id list, in dispatch-independent order. +const std::vector& shaderIds(); + +const char* statusName(DllStatus s); +const char* variantName(Variant v); + +// Does this file look like a usable Lossless.dll? Checks the base chain only, +// so a DLL without the SPIR-V variants (i.e. every build on Steam today) is +// reported as valid — the translator handles it. +DllStatus validateDll(const std::string& dllPath); + +// Which producer would be used for this DLL. +Variant dllVariant(const std::string& dllPath, bool preferFp16); + +// Parse the DLL, produce all 25 SPIR-V modules, and write them to cachePath +// (via temp file + rename, so a failed build cannot leave a half-written +// cache behind). Records which producer ran in the cache header. +DllStatus buildCache(const std::string& dllPath, const std::string& cachePath, bool preferFp16); + +// Is the cache current for this DLL? Compares source size + content hash. +DllStatus cacheMatchesSource(const std::string& cachePath, const std::string& dllPath, + bool& outMatches); + +// Load a previously built cache. +DllStatus loadModules(const std::string& cachePath, ModuleSet& outSet); + +// Which producer built an existing cache, without loading the modules. +DllStatus cacheVariant(const std::string& cachePath, Variant& outVariant); + +// Experimental Vulkan 1.1 / 1.2 compat: lower a DXBC-translated module's +// declared SPIR-V version to `targetVersion` (kSpirv14 or kSpirv15). Below 1.5 +// the Vulkan memory model is not core, so SPV_KHR_vulkan_memory_model is +// declared for it (the device side enables VK_KHR_vulkan_memory_model). The +// cache is built without a device in hand, always at the translator's native +// 1.6, so this runs at load time against whatever the device can take. A +// module already at or below the target is left untouched. Returns false, +// leaving the module untouched, for a malformed module, a target below 1.4, or +// a module declaring DemoteToHelperInvocation: that capability is core only in +// 1.6 and its extension is never enabled on the compat path, so such a module +// cannot be made legal here (DXVK emits it for pixel-shader discard only, so +// the 25 compute shaders never carry it). Whether the device then accepts the +// result is vkCreateShaderModule's / vkCreateComputePipelines' verdict. +bool downgradeSpirv(std::vector& words, uint32_t targetVersion); + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_dxbc.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_dxbc.cpp new file mode 100644 index 0000000000..db23e36864 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_dxbc.cpp @@ -0,0 +1,84 @@ +// See lsfg_dxbc.h. DXBC -> SPIR-V via DXVK's vendored translator. +// +// Follows upstream lsfg-vk's src/extract/trans.cpp, including its +// encounter-order binding renumber. Derived from WinNative's lsfg_dxbc.cpp +// (GPL-3.0-or-later); the translator itself is DXVK's, zlib licensed, vendored +// under cpp/thirdparty/dxbc. + +#include "lsfg_dxbc.h" + +#include +#include + +#include +#include +#include +#include + +namespace lsfg { +namespace { + +struct BindingSlot { + uint32_t bindingIndex = 0; + uint32_t bindingOffset = 0; // word offset of the Binding literal + uint32_t setIndex = 0; + uint32_t setOffset = 0; +}; + +} // namespace + +bool translateDxbc(const uint8_t* bytecode, uint32_t size, std::vector& outWords) { + outWords.clear(); + if (!bytecode || size < 4) return false; + + try { + dxvk::DxbcReader reader(reinterpret_cast(bytecode), size); + dxvk::DxbcModule module(reader); + const dxvk::DxbcModuleInfo info{}; + auto code = module.compile(info, "CS"); + + // Collect the descriptor decorations in the order the Binding + // decorations appear. Everything before the first OpFunction is the + // decoration block, so the scan stops there. + std::vector slotsByVarId; + std::vector varIdsInOrder; + for (auto ins : code) { + if (ins.opCode() == spv::OpDecorate) { + const uint32_t varId = ins.arg(1); + if (ins.arg(2) == spv::DecorationBinding) { + slotsByVarId.resize(std::max(slotsByVarId.size(), (size_t)varId + 1)); + slotsByVarId[varId].bindingIndex = ins.arg(3); + slotsByVarId[varId].bindingOffset = ins.offset() + 3; + varIdsInOrder.push_back(varId); + } else if (ins.arg(2) == spv::DecorationDescriptorSet) { + slotsByVarId.resize(std::max(slotsByVarId.size(), (size_t)varId + 1)); + slotsByVarId[varId].setIndex = ins.arg(3); + slotsByVarId[varId].setOffset = ins.offset() + 3; + } + } + if (ins.opCode() == spv::OpFunction) break; + } + + // Renumber to a dense 0..n range, in encounter order. + uint32_t next = 0; + for (const uint32_t varId : varIdsInOrder) { + const BindingSlot& slot = slotsByVarId[varId]; + if (slot.bindingOffset == 0) continue; + code.data()[slot.bindingOffset] = next++; + } + + const size_t byteSize = code.size(); + if (byteSize == 0 || byteSize % sizeof(uint32_t) != 0) return false; + + outWords.resize(byteSize / sizeof(uint32_t)); + std::memcpy(outWords.data(), code.data(), byteSize); + return true; + } catch (...) { + // DXVK's compiler signals malformed bytecode by throwing. A bad + // resource must degrade to "this DLL is unusable", never to a crash. + outWords.clear(); + return false; + } +} + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_dxbc.h b/app/src/main/cpp/winlator/lsfg/lsfg_dxbc.h new file mode 100644 index 0000000000..52ba00d65a --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_dxbc.h @@ -0,0 +1,39 @@ +#pragma once +// ============================================================================ +// lsfg_dxbc — DXBC -> SPIR-V for the Lossless Scaling shader chain. +// +// Why this exists at all: the base chain inside Lossless.dll is DXBC, and has +// always been DXBC. Lossless Scaling 3.2.2's release note ("Added shaders +// intended for use by the lsfg-vk project") describes precompiled SPIR-V +// copies at RCDATA base+49 / base+98 — but no build downloadable from Steam +// carries them. Measured against the current public build (buildId 19655272, +// 2025-08-19; linux_testing byte-identical on depot 993091): the whole 311 MB +// install contains zero occurrences of the SPIR-V magic word, and the DLL's +// 202 RCDATA entries are all DXBC. +// +// So a translator is required, not optional. Upstream lsfg-vk reaches the same +// conclusion and links DXVK's `dxbc` in src/extract/trans.cpp; we vendor the +// same subset (zlib licence) under cpp/thirdparty/dxbc and follow its +// trans.cpp step for step. +// +// The binding renumber here is ENCOUNTER ORDER — the order in which Binding +// decorations appear in DXVK's output — which is what DXVK's own layout pairs +// with. The precompiled-SPIR-V path in lsfg_dll.cpp uses a set/binding sort +// instead, because those blobs were built with that convention. The two must +// not be merged. +// ============================================================================ + +#include +#include + +namespace lsfg { + +// Translate one DXBC compute shader to SPIR-V, renumbering descriptor bindings +// into a dense 0..n range in encounter order. Returns false (leaving outWords +// empty) on any malformed input — DXVK's compiler throws, and everything is +// caught here. +// Emits DXVK's native SPIR-V 1.6; lowering for a Vulkan 1.1/1.2 device happens +// at load time (lsfg_dll.h downgradeSpirv). +bool translateDxbc(const uint8_t* bytecode, uint32_t size, std::vector& outWords); + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_engine.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_engine.cpp new file mode 100644 index 0000000000..4f1482eb77 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_engine.cpp @@ -0,0 +1,320 @@ +// See lsfg_engine.h. +// +// Ported from WinNative's vkr_lsfg.cpp (GPL-3.0-or-later), LSFG port credited +// to Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk. + +#include "lsfg_engine.h" + +#include "lsfg_chain.hpp" +#include "lsfg_shaders.hpp" +#include "lsfg_vkd.h" + +#include +#include + +#include + +#define LSFG_LOGI(...) __android_log_print(ANDROID_LOG_INFO, "LsfgEngine", __VA_ARGS__) +#define LSFG_LOGW(...) __android_log_print(ANDROID_LOG_WARN, "LsfgEngine", __VA_ARGS__) + +namespace lsfg { +namespace { + +// The chain needs two real frames in its history before anything it produces +// is meaningful, and we require the plan to stay warm for a couple of frames +// so a single settled sample cannot start generation from garbage. +constexpr uint64_t kRequiredFrames = 2; +constexpr uint32_t kRecurrenceFrames = 2; +constexpr uint64_t kTelemetryInterval = 120; + +constexpr float kFlowScaleMin = 0.25f; +constexpr float kFlowScaleMax = 1.0f; +constexpr float kFlowScaleSteps = 20.0f; + +VkImageMemoryBarrier makeTransition(VkImage image, VkAccessFlags srcAccess, + VkAccessFlags dstAccess, VkImageLayout oldLayout, + VkImageLayout newLayout) { + VkImageMemoryBarrier b{}; + b.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + b.srcAccessMask = srcAccess; + b.dstAccessMask = dstAccess; + b.oldLayout = oldLayout; + b.newLayout = newLayout; + b.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + b.image = image; + b.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + b.subresourceRange.levelCount = 1; + b.subresourceRange.layerCount = 1; + return b; +} + +// Copy the just-composited frame into the chain's input ring. `source` is the +// composite target, which the composite render pass leaves in GENERAL. +void copyPresentedFrame(VkCommandBuffer cmd, VkImage source, LsfgImage& destination, + VkExtent2D extent) { + const VkImageMemoryBarrier before[] = { + makeTransition(source, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, + VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL), + makeTransition(destination.Handle(), VK_ACCESS_SHADER_READ_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, destination.Layout(), + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL), + }; + vkd.CmdPipelineBarrier(cmd, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 2, before); + + VkImageCopy region{}; + region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + region.srcSubresource.layerCount = 1; + region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + region.dstSubresource.layerCount = 1; + region.extent = {extent.width, extent.height, 1}; + vkd.CmdCopyImage(cmd, source, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destination.Handle(), + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + + const VkImageMemoryBarrier after[] = { + makeTransition(source, VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL), + makeTransition(destination.Handle(), VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_LAYOUT_GENERAL), + }; + vkd.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + 0, 0, nullptr, 0, nullptr, 2, after); + + destination.SetLayout(VK_IMAGE_LAYOUT_GENERAL); +} + +} // namespace + +Engine::Engine() = default; + +Engine::~Engine() { + chain_.reset(); + shaders_.reset(); +} + +bool Engine::init(VkDevice device, VkPhysicalDevice physicalDevice, const std::string& cachePath, + uint32_t spirvTarget) { + if (device == VK_NULL_HANDLE || physicalDevice == VK_NULL_HANDLE || cachePath.empty()) + return false; + if (!lsfgVkdReady()) { + LSFG_LOGW("dispatch not initialised; frame generation unavailable"); + return false; + } + + device_ = Device(device, physicalDevice); + cachePath_ = cachePath; + + shaders_ = std::make_unique(device_, cachePath_, spirvTarget); + if (!shaders_->IsValid()) { + LSFG_LOGW("shader cache at %s did not yield all modules", cachePath.c_str()); + shaders_.reset(); + return false; + } + LSFG_LOGI("frame generation shaders ready"); + return true; +} + +void Engine::configure(uint32_t multiplier, uint32_t targetRate, float flowScale, + float refreshRate) { + LsfgPacerConfig config = pacer_.Config(); + config.multiplier = multiplier; + config.target_rate = targetRate; + config.refresh_rate = refreshRate; + pacer_.SetConfig(config); + flowScale_ = std::clamp(flowScale, kFlowScaleMin, kFlowScaleMax); +} + +void Engine::setRefreshRate(float refreshRate) { + LsfgPacerConfig config = pacer_.Config(); + if (config.refresh_rate == refreshRate) return; + config.refresh_rate = refreshRate; + pacer_.SetConfig(config); +} + +void Engine::setGuestExtent(uint32_t width, uint32_t height) { + if (width == 0 || height == 0) return; + peakGuestExtent_.width = std::max(peakGuestExtent_.width, width); + peakGuestExtent_.height = std::max(peakGuestExtent_.height, height); +} + +// The flow pyramid is the expensive part, so its resolution is scaled relative +// to the largest guest surface seen: a game running well below panel +// resolution does not need a panel-resolution flow field. +float Engine::effectiveFlowScale(uint32_t width) const { + if (width == 0 || peakGuestExtent_.width == 0) return flowScale_; + const float ratio = (float)peakGuestExtent_.width / (float)width; + const float stepped = std::ceil(ratio * kFlowScaleSteps) / kFlowScaleSteps; + return std::clamp(std::min(stepped, flowScale_), kFlowScaleMin, kFlowScaleMax); +} + +bool Engine::needsRebuild(uint32_t width, uint32_t height, VkFormat format) const { + if (unavailable_) return false; + return !chain_ + || builtExtent_.width != width || builtExtent_.height != height + || builtFormat_ != format + || builtFlowScale_ != effectiveFlowScale(width); +} + +bool Engine::prepare(uint32_t width, uint32_t height, VkFormat format) { + if (unavailable_ || !shaders_) return false; + if (width == 0 || height == 0 || format == VK_FORMAT_UNDEFINED) return false; + if (!needsRebuild(width, height, format)) return chain_ && chain_->Valid(); + + const float scale = effectiveFlowScale(width); + + chain_.reset(); + chain_ = std::make_unique(device_, *shaders_, VkExtent2D{width, height}, format, + scale); + if (!chain_->Valid()) { + // A device that cannot build the chain reports unsupported once and + // stops trying, rather than thrashing allocations every frame. + LSFG_LOGW("chain build failed at %ux%u; frame generation unavailable", width, height); + chain_.reset(); + unavailable_ = true; + return false; + } + + builtExtent_ = VkExtent2D{width, height}; + builtFormat_ = format; + builtFlowScale_ = scale; + frameCount_ = 0; + lastCopiedCount_ = 0; + haveCopied_ = false; + primeHistory_ = false; + planCalls_ = 0; + warmStreak_ = 0; + warm_ = false; + generating_ = false; + pacer_.Reset(); + governor_.reset(); + LSFG_LOGI("chain built at %ux%u, flow %ux%u scale %.2f (preset %.2f, guest %ux%u)", + width, height, (unsigned)(width * scale), (unsigned)(height * scale), + (double)scale, (double)flowScale_, + peakGuestExtent_.width, peakGuestExtent_.height); + return true; +} + +uint32_t Engine::plan(uint32_t capacity, uint64_t sourceFrames) { + if (unavailable_ || !chain_) return 0; + + plan_ = pacer_.Plan(std::min(capacity, kMaxGenerations), sourceFrames); + + // The pacer says how many frames FIT in the panel's budget. The governor + // says how many this device can actually afford right now - on a handheld + // the chain competes with the game for one GPU, so an extra generation has + // to prove it improves total output without collapsing the real frame rate. + if (governorEnabled_) { + const LsfgPacerStats s = pacer_.Stats(); + governor_.configure((uint32_t)std::min(pacer_.MaxGenerations(), kMaxGenerations)); + // presentedRate_, NOT the pacer's loop rate. The pacer samples its loop + // once per SOURCE frame, so its "loop rate" is the guest rate by + // construction and can never show that generation added anything - the + // governor could not accept a probe on any hardware. + plan_.generations = governor_.cap((uint32_t)plan_.generations, s.source_rate, + presentedRate_); + } + + warm_ = plan_.warm && frameCount_ + 1 >= kRequiredFrames; + warmStreak_ = warm_ ? warmStreak_ + 1 : 0; + generating_ = warm_ && warmStreak_ >= kRecurrenceFrames && plan_.generations > 0; + + // The ring is only seeded while generating, so the first frame after any + // gap - arming, or a pacer discontinuity after a hitch - would interpolate + // between this frame and whatever the other slot held when generation last + // stopped. That is a visible warp, and it happens every time the engine + // starts. Spend this frame filling the ring instead and generate from the + // next one, when both slots are genuinely consecutive. + primeHistory_ = false; + if (generating_ && !historyFresh()) { + primeHistory_ = true; + generating_ = false; + if ((primeLogCount_++ % 60) == 0) + LSFG_LOGI("priming the input ring (last copied frame %llu, now at %llu)", + (unsigned long long)(haveCopied_ ? lastCopiedCount_ : 0), + (unsigned long long)frameCount_); + } + + if ((planCalls_++ % kTelemetryInterval) == 0) { + const LsfgPacerStats stats = pacer_.Stats(); + const float wanted = stats.source_rate * (float)(plan_.generations + 1); + LSFG_LOGI("presented=%.1f fps (measured at the swapchain)", (double)presentedRate_); + LSFG_LOGI("pace gen=%zu max=%zu cap=%u guest=%.1f loop=%.1f refresh=%.1f target=%.0f " + "slots=%.2f drawn=%llu needs=%.1fHz%s%s", + plan_.generations, pacer_.MaxGenerations(), capacity, + (double)stats.source_rate, (double)stats.loop_rate, (double)stats.refresh_rate, + (double)stats.target_rate, (double)stats.slots, + (unsigned long long)stats.last_drawn, (double)wanted, + (stats.refresh_rate > 0.0f && wanted > stats.refresh_rate + 1.0f) + ? " PANEL-BOUND" : "", + stats.rates_settled ? (warm_ ? "" : " cold") : " sampling"); + } + + return generating_ ? (uint32_t)plan_.generations : 0; +} + +void Engine::process(VkCommandBuffer cmd, VkImage source, uint32_t width, uint32_t height, + uint32_t generations) { + if (!chain_ || !chain_->Valid()) return; + + const uint64_t count = frameCount_++; + lastCount_ = count; + lastGenerations_ = generations; + + // Seeding the input ring is a full-resolution image copy every frame, so it + // is NOT free at 100 fps - it was costing real frame rate while producing + // nothing. Copy only when generating, on the one priming frame that + // precedes generation, or while the governor is warming up towards a + // probe - so the ring is populated by the time it is needed. + const bool needHistory = generations > 0 || primeHistory_ + || (governorEnabled_ && governor_.wantsHistory()); + if (needHistory) { + copyPresentedFrame(cmd, source, chain_->Input(count), VkExtent2D{width, height}); + lastCopiedCount_ = count; + haveCopied_ = true; + } + + // The SHARED chain is 24 of the 25 shaders - the whole flow pyramid - and + // only `generate` runs per generated frame. Running it while producing + // nothing spends almost the entire cost of frame generation for no frames + // at all, every frame. That is what pinned the GPU at 100% on device + // regardless of the game's own settings, and it fed straight back into the + // governor: the chain made the source rate collapse, the governor saw the + // collapse and refused to generate, and refusing did not stop the chain. + if (warm_ && generations > 0) chain_->DispatchShared(cmd, count); +} + +void Engine::generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t targetIndex, + VkImage targetImage, VkImageView targetView, + uint32_t width, uint32_t height) { + if (!chain_ || !chain_->Valid()) return; + if (targetIndex >= LSFG_MAX_TARGETS) return; + + chain_->SetTarget(device_, lastGenerations_, generation, targetIndex, targetView); + chain_->DispatchGeneration(cmd, lastCount_, lastGenerations_, generation, targetIndex, + targetImage, VkExtent2D{width, height}); +} + +float Engine::sourceRate() const { return pacer_.Stats().source_rate; } + +void Engine::forgetTargets() { + if (chain_) chain_->ForgetTargets(); +} + +void Engine::reset() { + pacer_.Reset(); + governor_.reset(); + peakGuestExtent_ = VkExtent2D{}; + lastCopiedCount_ = 0; + haveCopied_ = false; + primeHistory_ = false; + warmStreak_ = 0; + warm_ = false; + generating_ = false; + plan_ = {}; +} + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_engine.h b/app/src/main/cpp/winlator/lsfg/lsfg_engine.h new file mode 100644 index 0000000000..51cc4e69bc --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_engine.h @@ -0,0 +1,149 @@ +#pragma once +// ============================================================================ +// lsfg_engine — the compositor's handle on native LSFG frame generation. +// +// Owns the shader modules, the interpolation chain and the pacer, and exposes +// the small contract the render loop needs: +// +// prepare(w, h, format) build/rebuild the chain for this size +// plan(capacity, sourceFrames) how many frames to generate this time +// process(cmd, source, w, h, gens) take frame N in, run the shared chain +// generateInto(cmd, g, i, img, view) synthesise generated frame g +// +// Ordering matters and is not obvious: interpolation produces frames that +// belong BETWEEN N-1 and N, so the generated frames are presented FIRST and +// the real frame N is held back one slot. That one output interval is the +// unavoidable cost of interpolating rather than extrapolating; no placement of +// this code changes it. +// +// Ported from WinNative's vkr_lsfg.cpp (GPL-3.0-or-later), LSFG port credited +// to Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk. +// ============================================================================ + +#include +#include +#include + +#include + +#include "lsfg_common.hpp" +#include "lsfg_dll.h" // kSpirv16 +#include "lsfg_governor.h" +#include "lsfg_pacer.hpp" + +namespace lsfg { + +class LsfgShaders; +class LsfgChain; + +// Hard ceiling on generated frames per source frame (2x..4x -> 1..3). +constexpr uint32_t kMaxGenerations = 3; + +class Engine { +public: + // Both the constructor and destructor are out-of-line ON PURPOSE. The + // shader set and the chain are held by unique_ptr to forward-declared + // types, and an inline constructor would make the compiler emit the + // exception-cleanup path for those members at every construction site - + // which needs the complete types there. Keeping both here confines that to + // lsfg_engine.cpp, where the types are complete. + Engine(); + ~Engine(); + + Engine(const Engine&) = delete; + Engine& operator=(const Engine&) = delete; + + // Build the shader modules from a cache produced by lsfg_dll::buildCache. + // Returns false if the cache does not yield all 25 modules. `spirvTarget` + // is the highest SPIR-V version the device accepts (lsfg_probe.h); the + // cached 1.6 modules are lowered to it when it is below that. + bool init(VkDevice device, VkPhysicalDevice physicalDevice, const std::string& cachePath, + uint32_t spirvTarget = kSpirv16); + + bool valid() const { return shaders_ != nullptr && !unavailable_; } + bool unavailable() const { return unavailable_; } + + void configure(uint32_t multiplier, uint32_t targetRate, float flowScale, float refreshRate); + void setRefreshRate(float refreshRate); + void setGuestExtent(uint32_t width, uint32_t height); + + bool needsRebuild(uint32_t width, uint32_t height, VkFormat format) const; + bool prepare(uint32_t width, uint32_t height, VkFormat format); + + // How many frames to generate for this source frame. Returns 0 until the + // history slots are valid and the rates have settled, so the first frames + // after a start or a resize are never interpolated from garbage. + uint32_t plan(uint32_t capacity, uint64_t sourceFrames); + + // Take the just-composited frame as LSFG input and run the shared part of + // the chain (everything except `generate`). `source` must be in GENERAL. + void process(VkCommandBuffer cmd, VkImage source, uint32_t width, uint32_t height, + uint32_t generations); + + // Synthesise generated frame `generation` into the given storage image. + void generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t targetIndex, + VkImage targetImage, VkImageView targetView, + uint32_t width, uint32_t height); + + // What the probe governor currently trusts, and the latest thermal + // reading (-1 = no signal). Surfaced for the HUD and diagnostics. + uint32_t acceptedGenerations() const { return governor_.accepted(); } + int thermalStatus() const { return governor_.thermalStatus(); } + float sourceRate() const; + // The rate that actually reaches the panel, generated frames included. + // Supplied by the renderer, which is the only thing that counts presents. + float loopRate() const { return presentedRate_; } + void setPresentedRate(float fps) { presentedRate_ = fps; } + + void forgetTargets(); + void reset(); + +private: + float effectiveFlowScale(uint32_t width) const; + + // A generated frame is a blend of the last two REAL frames, so the input + // ring - which is two images deep - only holds usable history when the + // other slot was filled by the frame immediately before this one. It is + // not, every time generation resumes after a pause: the ring is seeded + // only while generating, so the slot still carries whatever was there when + // generation last stopped. + bool historyFresh() const { return haveCopied_ && lastCopiedCount_ + 1 == frameCount_; } + + Device device_{}; + std::string cachePath_; + std::unique_ptr shaders_; + std::unique_ptr chain_; + LsfgPacer pacer_; + ProbeGovernor governor_; + // The governor is OFF by default: the device's own thermal management is + // the authority, and a probe loop that can veto the user's setting is not + // wanted here. The multiplier is then what was asked for, still clamped by + // what the panel can show. Kept behind a flag rather than deleted because + // the probe/backoff logic is the right answer for a device WITHOUT decent + // native throttling, and this is the only thing that would have to change. + bool governorEnabled_ = false; + LsfgPlan plan_{}; + + VkExtent2D builtExtent_{}; + VkExtent2D peakGuestExtent_{}; + VkFormat builtFormat_{VK_FORMAT_UNDEFINED}; + float builtFlowScale_{}; + float flowScale_{1.0f}; + + float presentedRate_{}; + + uint64_t frameCount_{}; + uint64_t lastCopiedCount_{}; + bool haveCopied_{}; + bool primeHistory_{}; + uint64_t primeLogCount_{}; + uint64_t lastCount_{}; + size_t lastGenerations_{}; + uint64_t planCalls_{}; + uint32_t warmStreak_{}; + bool warm_{}; + bool generating_{}; + bool unavailable_{}; +}; + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_gamma.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_gamma.cpp new file mode 100644 index 0000000000..392930b615 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_gamma.cpp @@ -0,0 +1,200 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_gamma.hpp" +#include "lsfg_shaders.hpp" + +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t DISPATCH_TILE_SHIFT = 3; + +[[nodiscard]] uint32_t GroupCount(uint32_t size) { + return (size + (1u << DISPATCH_TILE_SHIFT) - 1) >> DISPATCH_TILE_SHIFT; +} + +} + +LsfgGamma::LsfgGamma(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImageHistory& inputs_, + LsfgImage& flow_input_, LsfgImage* previous_) + : inputs{&inputs_}, flow_input{&flow_input_}, previous{previous_} { + passes[0] = LsfgPass(device, shaders, LSFG_GAMMA_SHADERS[0], + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLER}, + {5, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {3, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[1] = LsfgPass(device, shaders, LSFG_GAMMA_SHADERS[1], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {3, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[2] = LsfgPass(device, shaders, LSFG_GAMMA_SHADERS[2], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[3] = LsfgPass(device, shaders, LSFG_GAMMA_SHADERS[3], + {{1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + passes[4] = LsfgPass(device, shaders, LSFG_GAMMA_SHADERS[4], + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLER}, + {4, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + for (const auto& pass : passes) { + if (!pass.Valid()) return; + } + + const VkExtent2D extent = (*inputs)[0][0].Extent(); + for (auto& image : temp1) { + image = LsfgImage(device, extent); + if (!image.Valid()) return; + } + for (auto& image : temp2) { + image = LsfgImage(device, extent); + if (!image.Valid()) return; + } + out_image = LsfgImage(device, extent, LSFG_MOTION_FORMAT); + if (!out_image.Valid()) return; + + std::vector layouts; + for (size_t slot = 0; slot < LSFG_GENERATION_SLOTS; ++slot) { + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + layouts.push_back(passes[0].SetLayout()); + } + for (size_t i = 1; i < LSFG_GAMMA_STAGES; ++i) { + layouts.push_back(passes[i].SetLayout()); + } + } + + const std::vector sets = + AllocateLsfgDescriptorSets(device, descriptor_pool, layouts); + if (sets.size() != layouts.size()) return; + + const LsfgImage& previous_image = + previous != nullptr ? *previous : resources.GetDummy(LSFG_MOTION_FORMAT); + if (!previous_image.Valid()) return; + + const VkSampler sampler = resources.GetSampler(); + const VkSampler border_sampler = + resources.GetSampler(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_COMPARE_OP_NEVER, true); + const VkSampler edge_sampler = + resources.GetSampler(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_COMPARE_OP_ALWAYS, false); + + size_t next = 0; + for (size_t slot = 0; slot < LSFG_GENERATION_SLOTS; ++slot) { + Generation& pass = generations[slot]; + const VkBuffer buffer = resources.GetBuffer(LsfgSlotTimestamp(slot), previous == nullptr); + + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + pass.first_descriptor_sets[i] = sets[next++]; + } + for (size_t i = 0; i < LSFG_GAMMA_STAGES - 1; ++i) { + pass.descriptor_sets[i] = sets[next++]; + } + + for (size_t i = 0; i < LSFG_HISTORY_SLOTS; ++i) { + LsfgDescriptorWriter(pass.first_descriptor_sets[i]) + .AddUniformBuffer(buffer, LsfgResources::BufferSize()) + .AddSampler(border_sampler) + .AddSampler(edge_sampler) + .AddSampledImages((*inputs)[(i + 2) % LSFG_HISTORY_SLOTS]) + .AddSampledImages((*inputs)[i % LSFG_HISTORY_SLOTS]) + .AddSampledImage(previous_image) + .AddStorageImages(temp1) + .Build(device); + } + LsfgDescriptorWriter(pass.descriptor_sets[0]) + .AddSampler(sampler) + .AddSampledImages(temp1) + .AddStorageImages(temp2) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[1]) + .AddSampler(sampler) + .AddSampledImages(temp2) + .AddStorageImage(temp1[0]) + .AddStorageImage(temp1[1]) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[2]) + .AddSampler(sampler) + .AddSampledImage(temp1[0]) + .AddSampledImage(temp1[1]) + .AddStorageImages(temp2) + .Build(device); + LsfgDescriptorWriter(pass.descriptor_sets[3]) + .AddUniformBuffer(buffer, LsfgResources::BufferSize()) + .AddSampler(sampler) + .AddSampler(edge_sampler) + .AddSampledImages(temp2) + .AddSampledImage(previous_image) + .AddSampledImage(*flow_input) + .AddStorageImage(out_image) + .Build(device); + } + allocated = true; +} + +void LsfgGamma::PushStepBarriers(LsfgBarriers& barriers, uint64_t frame_count, size_t step) { + const size_t history = frame_count % LSFG_HISTORY_SLOTS; + const size_t previous_history = (frame_count + 2) % LSFG_HISTORY_SLOTS; + + switch (step) { + case 0: + barriers.WriteToReadAll((*inputs)[previous_history]) + .WriteToReadAll((*inputs)[history]) + .WriteToRead(previous) + .ReadToWriteAll(temp1); + break; + case 1: + barriers.WriteToReadAll(temp1).ReadToWriteAll(temp2); + break; + case 2: + barriers.WriteToReadAll(temp2).ReadToWrite(temp1[0]).ReadToWrite(temp1[1]); + break; + case 3: + barriers.WriteToRead(temp1[0]).WriteToRead(temp1[1]).ReadToWriteAll(temp2); + break; + default: + barriers.WriteToReadAll(temp2) + .WriteToRead(previous) + .WriteToRead(*flow_input) + .ReadToWrite(out_image); + break; + } +} + +void LsfgGamma::DispatchStep(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot, + size_t step) { + const Generation& pass = generations[slot]; + const VkExtent2D extent = temp1[0].Extent(); + const size_t history = frame_count % LSFG_HISTORY_SLOTS; + + if (step == 0) { + passes[0].Bind(cmdbuf, pass.first_descriptor_sets[history]); + } else { + passes[step].Bind(cmdbuf, pass.descriptor_sets[step - 1]); + } + vkd.CmdDispatch(cmdbuf, GroupCount(extent.width), GroupCount(extent.height), 1); +} + +void LsfgGamma::Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot) { + for (size_t step = 0; step < LSFG_GAMMA_STAGES; ++step) { + LsfgBarriers barriers(cmdbuf); + PushStepBarriers(barriers, frame_count, step); + barriers.Build(); + DispatchStep(cmdbuf, frame_count, slot, step); + } +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_gamma.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_gamma.hpp new file mode 100644 index 0000000000..8210dd2590 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_gamma.hpp @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include + +#include "lsfg_common.hpp" + +namespace lsfg { + +class LsfgShaders; + +constexpr size_t LSFG_GAMMA_STAGES = 5; +constexpr size_t LSFG_GAMMA_TEMPS = 3; + +class LsfgGamma { +public: + LsfgGamma() = default; + LsfgGamma(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImageHistory& inputs, LsfgImage& flow_input, + LsfgImage* previous); + + void Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot); + + void PushStepBarriers(LsfgBarriers& barriers, uint64_t frame_count, size_t step); + + void DispatchStep(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot, + size_t step); + + [[nodiscard]] LsfgImage& Output() { + return out_image; + } + + [[nodiscard]] bool Valid() const { + return allocated; + } + +private: + struct Generation { + std::array first_descriptor_sets{}; + std::array descriptor_sets{}; + }; + + LsfgImageHistory* inputs{}; + LsfgImage* flow_input{}; + LsfgImage* previous{}; + + std::array passes; + std::array generations{}; + + std::array temp1; + LsfgImagePair temp2; + LsfgImage out_image; + bool allocated{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_generate.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_generate.cpp new file mode 100644 index 0000000000..1c84cb1866 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_generate.cpp @@ -0,0 +1,137 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_generate.hpp" +#include "lsfg_dll.h" +#include "lsfg_shaders.hpp" + +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t DISPATCH_TILE_SHIFT = 4; + +[[nodiscard]] uint32_t GroupCount(uint32_t size) { + return (size + (1u << DISPATCH_TILE_SHIFT) - 1) >> DISPATCH_TILE_SHIFT; +} + +VkImageMemoryBarrier MakeTargetBarrier(VkImage image, VkAccessFlags src_access, + VkAccessFlags dst_access, VkImageLayout old_layout) { + VkImageMemoryBarrier barrier{}; + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.srcAccessMask = src_access; + barrier.dstAccessMask = dst_access; + barrier.oldLayout = old_layout; + barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = image; + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.levelCount = 1; + barrier.subresourceRange.layerCount = 1; + return barrier; +} + +} + +LsfgGenerate::LsfgGenerate(const Device& device, const LsfgShaders& shaders, + LsfgResources& resources, VkDescriptorPool descriptor_pool, + LsfgImagePair& frames_, LsfgImage& motion_, LsfgImage& detail1_, + LsfgImage& detail2_) + : frames{&frames_}, motion{&motion_}, detail1{&detail1_}, detail2{&detail2_} { + pass = LsfgPass(device, shaders, LSFG_SHADER_GENERATE, + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {2, VK_DESCRIPTOR_TYPE_SAMPLER}, + {5, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + if (!pass.Valid()) return; + + sampler = resources.GetSampler(); + edge_sampler = + resources.GetSampler(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_COMPARE_OP_ALWAYS, false); + + const uint32_t total = + static_cast(LSFG_GENERATION_SLOTS * LSFG_MAX_TARGETS * 2); + const std::vector sets = + AllocateLsfgDescriptorSets(device, descriptor_pool, pass.SetLayout(), total); + if (sets.size() != total) return; + + size_t next = 0; + for (size_t slot = 0; slot < LSFG_GENERATION_SLOTS; ++slot) { + Generation& target = generations[slot]; + target.buffer = resources.GetBuffer(LsfgSlotTimestamp(slot)); + + for (auto& entry : target.targets) { + for (auto& set : entry.descriptor_sets) { + set = sets[next++]; + } + } + } + allocated = true; +} + +void LsfgGenerate::SetTarget(const Device& device, size_t slot, uint32_t target, + VkImageView view) { + Target& entry = generations[slot].targets[target]; + if (entry.view == view) return; + entry.view = view; + + for (size_t i = 0; i < entry.descriptor_sets.size(); ++i) { + LsfgDescriptorWriter(entry.descriptor_sets[i]) + .AddUniformBuffer(generations[slot].buffer, LsfgResources::BufferSize()) + .AddSampler(sampler) + .AddSampler(edge_sampler) + .AddSampledImage((*frames)[1 - i]) + .AddSampledImage((*frames)[i]) + .AddSampledImage(*motion) + .AddSampledImage(*detail1) + .AddSampledImage(*detail2) + .AddStorageView(view) + .Build(device); + } +} + +void LsfgGenerate::ForgetTargets() { + for (auto& generation : generations) { + for (auto& entry : generation.targets) { + entry.view = VK_NULL_HANDLE; + } + } +} + +void LsfgGenerate::Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot, + uint32_t target, VkImage image, VkExtent2D extent) { + const Target& entry = generations[slot].targets[target]; + + LsfgBarriers(cmdbuf) + .WriteToReadAll(*frames) + .WriteToRead(*motion) + .WriteToRead(*detail1) + .WriteToRead(*detail2) + .DiscardToWrite(image) + .Build(); + + pass.Bind(cmdbuf, entry.descriptor_sets[frame_count % entry.descriptor_sets.size()]); + vkd.CmdDispatch(cmdbuf, GroupCount(extent.width), GroupCount(extent.height), 1); + + const VkImageMemoryBarrier after = MakeTargetBarrier( + image, VK_ACCESS_SHADER_WRITE_BIT, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT, + VK_IMAGE_LAYOUT_GENERAL); + vkd.CmdPipelineBarrier(cmdbuf, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | + VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, nullptr, 0, nullptr, 1, &after); +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_generate.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_generate.hpp new file mode 100644 index 0000000000..68e23967b7 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_generate.hpp @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include + +#include "lsfg_common.hpp" + +namespace lsfg { + +class LsfgShaders; + +class LsfgGenerate { +public: + LsfgGenerate() = default; + LsfgGenerate(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImagePair& frames, LsfgImage& motion, + LsfgImage& detail1, LsfgImage& detail2); + + void SetTarget(const Device& device, size_t slot, uint32_t target, VkImageView view); + + void ForgetTargets(); + + void Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count, size_t slot, uint32_t target, + VkImage image, VkExtent2D extent); + + [[nodiscard]] bool Valid() const { + return pass.Valid() && allocated; + } + +private: + struct Target { + std::array descriptor_sets{}; + VkImageView view{VK_NULL_HANDLE}; + }; + + struct Generation { + std::array targets{}; + VkBuffer buffer{VK_NULL_HANDLE}; + }; + + LsfgImagePair* frames{}; + LsfgImage* motion{}; + LsfgImage* detail1{}; + LsfgImage* detail2{}; + VkSampler sampler{VK_NULL_HANDLE}; + VkSampler edge_sampler{VK_NULL_HANDLE}; + + LsfgPass pass; + std::array generations{}; + bool allocated{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_governor.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_governor.cpp new file mode 100644 index 0000000000..828b5be6bf --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_governor.cpp @@ -0,0 +1,237 @@ +// See lsfg_governor.h. + +#include "lsfg_governor.h" + +#include + +#include +#include + +#define GOV_LOGI(...) __android_log_print(ANDROID_LOG_INFO, "LsfgGovernor", __VA_ARGS__) + +namespace lsfg { +namespace { + +// A probe has to run long enough to survive a single unlucky frame, and the +// baseline long enough to be a fair comparison. +constexpr float kBaselineSeconds = 2.0f; +constexpr float kProbeSeconds = 2.0f; +constexpr uint32_t kMinSamples = 30; + +// Keep the extra generation only if it actually paid off. +constexpr float kOutputGainRequired = 1.15f; +constexpr float kSourceFloor = 0.70f; + +constexpr float kBackoffSeconds[] = {5.0f, 15.0f, 30.0f, 60.0f}; +constexpr uint32_t kBackoffSteps = 4; + +constexpr float kThermalPollSeconds = 2.0f; +constexpr float kThermalDecaySeconds = 1.0f; + +// ADEVICE_THERMAL_STATUS_* from , which is API 30. Resolved +// by dlsym so the build keeps working below that and on devices that do not +// ship the service; -1 simply means "no thermal signal", never "hot". +// Android reports a STATUS, not a temperature - NONE 0, LIGHT 1, MODERATE 2, +// SEVERE 3, CRITICAL 4, EMERGENCY 5, SHUTDOWN 6 - so there is no degree value +// here to raise. The equivalent of "let it run hotter" is to act on a higher +// status, which is what these now do. +// +// A handheld under a real 3D load sits at SEVERE routinely; blocking there +// made the governor refuse on a device that was working exactly as intended. +// It now only stops GROWING at SEVERE and only gives frames back at CRITICAL, +// leaving the device's own thermal management as the authority. +constexpr int kThermalBlock = 4; // CRITICAL: give generations back +constexpr int kThermalNoGrowth = 3; // SEVERE: keep what we have, stop probing + +using PFN_AThermal_acquireManager = void* (*)(); +using PFN_AThermal_getCurrentThermalStatus = int (*)(void*); + +void* thermalManager() { + static void* manager = [] () -> void* { + void* lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL); + if (!lib) return nullptr; + auto acquire = (PFN_AThermal_acquireManager)dlsym(lib, "AThermal_acquireManager"); + return acquire ? acquire() : nullptr; + }(); + return manager; +} + +int readThermalStatus() { + void* manager = thermalManager(); + if (!manager) return -1; + static auto get = [] () -> PFN_AThermal_getCurrentThermalStatus { + void* lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL); + return lib ? (PFN_AThermal_getCurrentThermalStatus) + dlsym(lib, "AThermal_getCurrentThermalStatus") : nullptr; + }(); + return get ? get(manager) : -1; +} + +float phaseSeconds(std::chrono::steady_clock::time_point a, + std::chrono::steady_clock::time_point b) { + return std::chrono::duration(b - a).count(); +} + +} // namespace + +void ProbeGovernor::configure(uint32_t maxGenerations) { + if (maxGenerations_ == maxGenerations) return; + // Raising the ceiling must NOT throw away what we already know works - + // going 2x -> 4x used to reset the accepted level to zero and restart the + // whole baseline/probe cycle, so a user raising the multiplier got FEWER + // frames. Only clamp down to a ceiling that has actually been lowered. + maxGenerations_ = maxGenerations; + if (accepted_ > maxGenerations_) accepted_ = maxGenerations_; + // Re-measure against the new ceiling, but keep the accepted level. + phase_ = Phase::Baseline; + havePhaseStart_ = false; + sourceAccum_ = loopAccum_ = 0.0f; + samples_ = 0; + haveBaseline_ = false; +} + +void ProbeGovernor::reset() { + accepted_ = 0; + phase_ = Phase::Baseline; + havePhaseStart_ = false; + sourceAccum_ = loopAccum_ = 0.0f; + samples_ = 0; + baselineSource_ = baselineLoop_ = 0.0f; + haveBaseline_ = false; + backoffStep_ = 0; +} + +void ProbeGovernor::enterBaseline(Clock::time_point now) { + phase_ = Phase::Baseline; + phaseStart_ = now; + havePhaseStart_ = true; + sourceAccum_ = loopAccum_ = 0.0f; + samples_ = 0; +} + +void ProbeGovernor::enterBackoff(Clock::time_point now) { + phase_ = Phase::Backoff; + phaseStart_ = now; + havePhaseStart_ = true; + sourceAccum_ = loopAccum_ = 0.0f; + samples_ = 0; + if (backoffStep_ < kBackoffSteps - 1) backoffStep_++; +} + +void ProbeGovernor::pollThermal(Clock::time_point now) { + if (haveThermalPoll_ && phaseSeconds(lastThermalPoll_, now) < kThermalPollSeconds) return; + lastThermalPoll_ = now; + haveThermalPoll_ = true; + thermal_ = readThermalStatus(); +} + +uint32_t ProbeGovernor::cap(uint32_t requested, float sourceRate, float loopRate) { + if (maxGenerations_ == 0 || requested == 0) return 0; + + const Clock::time_point now = Clock::now(); + if (!havePhaseStart_) enterBaseline(now); + pollThermal(now); + + // Thermal override: at SEVERE and above we stop asking for more and give + // generations back, but SLOWLY. + // + // This runs once per source frame - about forty times a second - so the + // previous version's unconditional accepted_-- was not "give one back", it + // was "slam to zero in three frames", and its unconditional enterBackoff() + // reset the backoff clock every single call, so the backoff could never + // expire and the governor could never measure or recover. One decay per + // second, and no churn at all once there is nothing left to give back. + thermalBlocked_ = thermal_ >= kThermalBlock; + if (thermal_ >= kThermalBlock) { + // Logged, sparingly. This is a REFUSAL TO EVEN MEASURE, and it was + // silent: on device it looked identical to "measured and declined". + if ((refusalLog_++ % 600u) == 0u) + GOV_LOGI("thermal status %d - not probing (accepted=%u)", thermal_, accepted_); + const bool decayDue = !haveThermalDecay_ + || phaseSeconds(lastThermalDecay_, now) >= kThermalDecaySeconds; + if (accepted_ > 0 && decayDue) { + GOV_LOGI("thermal status %d - dropping to %u generations", thermal_, accepted_ - 1); + accepted_--; + lastThermalDecay_ = now; + haveThermalDecay_ = true; + enterBackoff(now); + } + return std::min(requested, accepted_); + } + haveThermalDecay_ = false; + + if (sourceRate > 0.0f && loopRate > 0.0f) { + sourceAccum_ += sourceRate; + loopAccum_ += loopRate; + samples_++; + } + + const float elapsed = phaseSeconds(phaseStart_, now); + + switch (phase_) { + case Phase::Baseline: + if (elapsed >= kBaselineSeconds && samples_ >= kMinSamples) { + baselineSource_ = sourceAccum_ / (float)samples_; + baselineLoop_ = loopAccum_ / (float)samples_; + haveBaseline_ = true; + + const bool roomToGrow = accepted_ < maxGenerations_ && requested > accepted_; + const bool thermallyFree = thermal_ < kThermalNoGrowth || thermal_ < 0; + if (roomToGrow && thermallyFree) { + phase_ = Phase::Probing; + phaseStart_ = now; + sourceAccum_ = loopAccum_ = 0.0f; + samples_ = 0; + } else { + // Also previously silent. "Baseline completed but we did not + // probe" is a decision worth seeing in a log. + if ((refusalLog_++ % 600u) == 0u) + GOV_LOGI("not probing: accepted=%u max=%u requested=%u thermal=%d", + accepted_, maxGenerations_, requested, thermal_); + enterBaseline(now); // nothing to try; measure again later + } + } + break; + + case Phase::Probing: + if (elapsed >= kProbeSeconds && samples_ >= kMinSamples && haveBaseline_) { + const float probeSource = sourceAccum_ / (float)samples_; + const float probeLoop = loopAccum_ / (float)samples_; + + const bool outputImproved = + baselineLoop_ > 0.0f && probeLoop >= baselineLoop_ * kOutputGainRequired; + const bool sourceHeld = + baselineSource_ <= 0.0f || probeSource >= baselineSource_ * kSourceFloor; + + if (outputImproved && sourceHeld) { + accepted_ = std::min(accepted_ + 1, maxGenerations_); + backoffStep_ = 0; + GOV_LOGI("probe kept: %u generations (output %.1f -> %.1f, source %.1f -> %.1f)", + accepted_, (double)baselineLoop_, (double)probeLoop, + (double)baselineSource_, (double)probeSource); + enterBaseline(now); + } else { + GOV_LOGI("probe rejected at %u+1 (output %.1f -> %.1f, source %.1f -> %.1f) - " + "backing off %.0fs", accepted_, + (double)baselineLoop_, (double)probeLoop, + (double)baselineSource_, (double)probeSource, + (double)kBackoffSeconds[backoffStep_]); + enterBackoff(now); + } + } + break; + + case Phase::Backoff: + if (elapsed >= kBackoffSeconds[backoffStep_]) enterBaseline(now); + break; + } + + // While probing we allow one more than is currently accepted; otherwise the + // accepted level is the ceiling, and the pacer's own answer still applies. + const uint32_t allowed = phase_ == Phase::Probing + ? std::min(accepted_ + 1, maxGenerations_) + : accepted_; + return std::min(requested, allowed); +} + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_governor.h b/app/src/main/cpp/winlator/lsfg/lsfg_governor.h new file mode 100644 index 0000000000..effe8a964b --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_governor.h @@ -0,0 +1,90 @@ +#pragma once +// ============================================================================ +// lsfg_governor — decides whether an extra generated frame is actually WORTH +// it on this device, right now. +// +// The ported pacer answers "how many frames fit in the panel's budget". That +// is necessary but not sufficient on a handheld: the LSFG chain competes with +// the game for the same GPU, so a naive fixed 3x on a GPU-bound title lowers +// the real frame rate by more than the generated frames add. The user sees a +// higher HUD number and a worse-looking game. +// +// So the multiplier is treated as a ceiling to earn, not a setting to obey. +// The governor starts at 0 generations, periodically PROBES one more, and +// keeps it only if the probe measurably paid off: +// +// * total output rate must improve by at least 1.15x, and +// * the real (source) frame rate must not collapse below 0.70x baseline. +// +// A failed probe reverts immediately and backs off 5s, 15s, 30s, then 60s, so +// a device that cannot afford another generation stops being asked. +// +// Thermals are the second input a phone needs and a desktop does not. +// Sustained frame generation is a thermal decision as much as a performance +// one, so the governor gives back generations as the device heats and refuses +// to probe while it is throttling. +// ============================================================================ + +#include +#include + +namespace lsfg { + +class ProbeGovernor { +public: + void configure(uint32_t maxGenerations); + + // Cap the pacer's answer. Called once per source frame with the measured + // rates; returns the number of generations actually permitted. + uint32_t cap(uint32_t requested, float sourceRate, float loopRate); + + void reset(); + + uint32_t accepted() const { return accepted_; } + bool probing() const { return phase_ == Phase::Probing; } + // Whether the chain's input ring needs to be kept fed. Seeding it is a + // full-resolution copy every frame, so it is skipped during the long idle + // stretches - a backoff, or a thermal block - and resumed during Baseline, + // which gives it a couple of seconds to fill before a probe can start. + bool wantsHistory() const { + return !thermalBlocked_ && phase_ != Phase::Backoff; + } + // Latest thermal reading, 0 (none) .. 6 (shutdown); -1 when unavailable. + int thermalStatus() const { return thermal_; } + +private: + using Clock = std::chrono::steady_clock; + + enum class Phase { Baseline, Probing, Backoff }; + + void enterBaseline(Clock::time_point now); + void enterBackoff(Clock::time_point now); + void pollThermal(Clock::time_point now); + + uint32_t maxGenerations_ = 0; + uint32_t accepted_ = 0; + Phase phase_ = Phase::Baseline; + + Clock::time_point phaseStart_{}; + bool havePhaseStart_ = false; + + // Rolling means over the current phase window. + float sourceAccum_ = 0.0f, loopAccum_ = 0.0f; + uint32_t samples_ = 0; + + // What the accepted level achieves, measured during Baseline. + float baselineSource_ = 0.0f, baselineLoop_ = 0.0f; + bool haveBaseline_ = false; + + uint32_t backoffStep_ = 0; + + int thermal_ = -1; + Clock::time_point lastThermalDecay_{}; + bool haveThermalDecay_ = false; + bool thermalBlocked_ = false; + uint32_t refusalLog_ = 0; + Clock::time_point lastThermalPoll_{}; + bool haveThermalPoll_ = false; +}; + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_jni.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_jni.cpp new file mode 100644 index 0000000000..f4a1a4e73a --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_jni.cpp @@ -0,0 +1,69 @@ +// JNI surface for native LSFG shader-cache management. +// +// Deliberately free of any renderer handle: extracting the shader chain from +// Lossless.dll and caching it is a slow, once-per-DLL operation that the app +// runs off the render thread, long before a game launches. + +#include "lsfg_dll.h" + +#include +#include + +namespace { + +std::string toStdString(JNIEnv* env, jstring s) { + if (!s) return {}; + const char* chars = env->GetStringUTFChars(s, nullptr); + if (!chars) return {}; + std::string out(chars); + env->ReleaseStringUTFChars(s, chars); + return out; +} + +} // namespace + +extern "C" JNIEXPORT jint JNICALL +Java_com_steamdeck_launcher_gpu_LsfgNative_nativeValidateDll(JNIEnv* env, jclass, jstring dllPath) { + return (jint)lsfg::validateDll(toStdString(env, dllPath)); +} + +extern "C" JNIEXPORT jint JNICALL +Java_com_steamdeck_launcher_gpu_LsfgNative_nativeDllVariant(JNIEnv* env, jclass, jstring dllPath, + jboolean preferFp16) { + return (jint)lsfg::dllVariant(toStdString(env, dllPath), preferFp16 == JNI_TRUE); +} + +extern "C" JNIEXPORT jint JNICALL +Java_com_steamdeck_launcher_gpu_LsfgNative_nativeBuildCache(JNIEnv* env, jclass, jstring dllPath, + jstring cachePath, jboolean preferFp16) { + return (jint)lsfg::buildCache(toStdString(env, dllPath), toStdString(env, cachePath), + preferFp16 == JNI_TRUE); +} + +extern "C" JNIEXPORT jboolean JNICALL +Java_com_steamdeck_launcher_gpu_LsfgNative_nativeCacheMatchesSource(JNIEnv* env, jclass, + jstring cachePath, + jstring dllPath) { + bool matches = false; + const lsfg::DllStatus status = lsfg::cacheMatchesSource(toStdString(env, cachePath), + toStdString(env, dllPath), matches); + return (jboolean)(status == lsfg::DllStatus::Ok && matches); +} + +extern "C" JNIEXPORT jint JNICALL +Java_com_steamdeck_launcher_gpu_LsfgNative_nativeCacheVariant(JNIEnv* env, jclass, jstring cachePath) { + lsfg::Variant variant = lsfg::Variant::None; + if (lsfg::cacheVariant(toStdString(env, cachePath), variant) != lsfg::DllStatus::Ok) + return (jint)lsfg::Variant::None; + return (jint)variant; +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_steamdeck_launcher_gpu_LsfgNative_nativeStatusName(JNIEnv* env, jclass, jint status) { + return env->NewStringUTF(lsfg::statusName((lsfg::DllStatus)status)); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_steamdeck_launcher_gpu_LsfgNative_nativeVariantName(JNIEnv* env, jclass, jint variant) { + return env->NewStringUTF(lsfg::variantName((lsfg::Variant)variant)); +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_mipmaps.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_mipmaps.cpp new file mode 100644 index 0000000000..4d17625554 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_mipmaps.cpp @@ -0,0 +1,85 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_mipmaps.hpp" +#include "lsfg_dll.h" +#include "lsfg_shaders.hpp" + +#include +#include + +namespace lsfg { + +namespace { + +constexpr uint32_t DISPATCH_TILE_SHIFT = 6; + +[[nodiscard]] uint32_t GroupCount(uint32_t size) { + return (size + (1u << DISPATCH_TILE_SHIFT) - 1) >> DISPATCH_TILE_SHIFT; +} + +} + +LsfgMipmaps::LsfgMipmaps(const Device& device, const LsfgShaders& shaders, + LsfgResources& resources, VkDescriptorPool descriptor_pool, + LsfgImagePair& frames_, float flow_scale) + : frames{&frames_} { + pass = LsfgPass(device, shaders, LSFG_SHADER_MIPMAPS, + {{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}, + {1, VK_DESCRIPTOR_TYPE_SAMPLER}, + {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE}, + {LSFG_MIP_LEVELS, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE}}); + if (!pass.Valid()) return; + + const VkExtent2D input_extent = (*frames)[0].Extent(); + flow_extent = VkExtent2D{ + std::max(1u, static_cast(static_cast(input_extent.width) * flow_scale)), + std::max(1u, static_cast(static_cast(input_extent.height) * flow_scale)), + }; + + for (size_t i = 0; i < LSFG_MIP_LEVELS; ++i) { + const VkExtent2D level_extent{ + std::max(1u, flow_extent.width >> i), + std::max(1u, flow_extent.height >> i), + }; + out_images[i] = LsfgImage(device, level_extent, LSFG_FLOW_FORMAT); + if (!out_images[i].Valid()) return; + } + + const std::vector sets = AllocateLsfgDescriptorSets( + device, descriptor_pool, pass.SetLayout(), + static_cast(descriptor_sets.size())); + if (sets.size() != descriptor_sets.size()) return; + + const VkSampler sampler = resources.GetSampler(); + const VkBuffer buffer = resources.GetBuffer(); + + for (size_t i = 0; i < descriptor_sets.size(); ++i) { + descriptor_sets[i] = sets[i]; + LsfgDescriptorWriter(descriptor_sets[i]) + .AddUniformBuffer(buffer, LsfgResources::BufferSize()) + .AddSampler(sampler) + .AddSampledImage((*frames)[i]) + .AddStorageImages(out_images) + .Build(device); + } +} + +void LsfgMipmaps::Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count) { + const size_t slot = frame_count % descriptor_sets.size(); + + LsfgBarriers(cmdbuf).WriteToRead((*frames)[slot]).ReadToWriteAll(out_images).Build(); + + pass.Bind(cmdbuf, descriptor_sets[slot]); + vkd.CmdDispatch(cmdbuf, GroupCount(flow_extent.width), GroupCount(flow_extent.height), 1); +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_mipmaps.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_mipmaps.hpp new file mode 100644 index 0000000000..4ce06b0f5e --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_mipmaps.hpp @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include + +#include "lsfg_common.hpp" + +namespace lsfg { + +class LsfgShaders; + +class LsfgMipmaps { +public: + LsfgMipmaps() = default; + LsfgMipmaps(const Device& device, const LsfgShaders& shaders, LsfgResources& resources, + VkDescriptorPool descriptor_pool, LsfgImagePair& frames, float flow_scale); + + void Dispatch(VkCommandBuffer cmdbuf, uint64_t frame_count); + + [[nodiscard]] LsfgImage& Output(size_t level) { + return out_images[level]; + } + + [[nodiscard]] VkExtent2D FlowExtent() const { + return flow_extent; + } + + [[nodiscard]] bool Valid() const { + return pass.Valid() && descriptor_sets[0] != VK_NULL_HANDLE; + } + +private: + LsfgImagePair* frames{}; + + LsfgPass pass; + std::array descriptor_sets{}; + + VkExtent2D flow_extent{}; + std::array out_images; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_pacer.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_pacer.cpp new file mode 100644 index 0000000000..29da8729d0 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_pacer.cpp @@ -0,0 +1,193 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_pacer.hpp" + +#include +#include + +namespace lsfg { + +namespace { + +using Clock = std::chrono::steady_clock; + +constexpr float INTERVAL_SMOOTHING = 0.25f; +constexpr float SOURCE_SMOOTHING = 0.15f; +constexpr float SOURCE_STALE_SECONDS = 0.5f; +constexpr float DISCONTINUITY_SECONDS = 0.25f; +constexpr float HEADROOM_EPSILON = 0.02f; +constexpr float CREDIT_EPSILON = 1.0e-4f; +constexpr float SOURCE_ACCUM_FLOOR = 0.01f; +constexpr uint32_t MIN_RATE_SAMPLES = 12; + +} + +size_t LsfgPacer::MaxGenerations() const { + if (config.multiplier < 2) return 0; + if (config.target_rate != 0) return LSFG_MAX_MULTIPLIER - 1; + return std::min(config.multiplier, LSFG_MAX_MULTIPLIER) - 1; +} + +void LsfgPacer::TrackSourceRate(Clock::time_point now, uint64_t source_frames) { + if (!last_source_sample) { + last_source_sample = now; + last_source_frames = source_frames; + return; + } + + const float elapsed = std::chrono::duration(now - *last_source_sample).count(); + if (elapsed <= 0.0f) { + return; + } + + last_source_sample = now; + const uint64_t drawn = + source_frames > last_source_frames ? source_frames - last_source_frames : 0; + last_source_frames = source_frames; + + if (elapsed > SOURCE_STALE_SECONDS) { + source_frame_accum = 0.0f; + source_time_accum = 0.0f; + source_interval = 0.0f; + source_samples = 0; + return; + } + + last_drawn = drawn; + last_elapsed = elapsed; + source_frame_accum += (static_cast(drawn) - source_frame_accum) * SOURCE_SMOOTHING; + source_time_accum += (elapsed - source_time_accum) * SOURCE_SMOOTHING; + source_interval = + source_frame_accum > SOURCE_ACCUM_FLOOR ? source_time_accum / source_frame_accum : 0.0f; + if (source_samples < MIN_RATE_SAMPLES) ++source_samples; +} + +void LsfgPacer::TrackLoopRate(float interval_seconds) { + loop_interval = loop_interval > 0.0f + ? loop_interval + (interval_seconds - loop_interval) * INTERVAL_SMOOTHING + : interval_seconds; + if (loop_samples < MIN_RATE_SAMPLES) ++loop_samples; +} + +bool LsfgPacer::RatesSettled() const { + return source_samples >= MIN_RATE_SAMPLES && loop_samples >= MIN_RATE_SAMPLES; +} + +size_t LsfgPacer::HeadroomLimit() const { + if (config.refresh_rate <= 0.0f || source_interval <= 0.0f || + source_samples < MIN_RATE_SAMPLES) { + return LSFG_MAX_MULTIPLIER - 1; + } + + const float budget = std::ceil(config.refresh_rate * source_interval - HEADROOM_EPSILON); + return budget < 2.0f ? 0 : static_cast(budget) - 1; +} + +LsfgPlan LsfgPacer::Plan(size_t capacity, uint64_t source_frames) { + const size_t ceiling = std::min(capacity, MaxGenerations()); + if (ceiling == 0) { + Reset(); + return {}; + } + + const Clock::time_point now = Clock::now(); + TrackSourceRate(now, source_frames); + if (!last_frame) { + last_frame = now; + return {}; + } + + const float interval_seconds = std::chrono::duration(now - *last_frame).count(); + last_frame = now; + + if (interval_seconds <= 0.0f || interval_seconds > DISCONTINUITY_SECONDS) { + output_credit = 0.0f; + return LsfgPlan{0, true}; + } + + TrackLoopRate(interval_seconds); + + float target_rate = static_cast(config.target_rate); + if (target_rate > 0.0f && config.refresh_rate > 0.0f) { + target_rate = std::min(target_rate, config.refresh_rate); + } + + if (target_rate == 0.0f) { + // No explicit target rate: the multiplier is the multiplier, full stop. + // The panel-headroom clamp was here briefly and was removed at the + // user's decision; this is also upstream's behaviour on this branch. + // + // What that means above the panel's refresh rate, for the record: the + // display cannot show more frames than it refreshes, so under FIFO the + // surplus presents queue and the render thread waits on acquire. Nothing + // is displayed faster, and the compositor falls behind on guest + // deliveries instead. Below the refresh rate - every source at or under + // panel/4 - this branch behaves identically with or without the clamp. + // To restore it: limit = std::min(ceiling, HeadroomLimit()). + output_credit = 0.0f; + limit = ceiling; + return LsfgPlan{limit, true}; + } + + const size_t allowed = std::min(ceiling, HeadroomLimit()); + const float desired_outputs = loop_interval * target_rate; + if (allowed == 0 || desired_outputs <= 1.0f) { + output_credit = 0.0f; + limit = 0; + return {}; + } + + output_credit += desired_outputs; + const size_t outputs = + std::max(1, static_cast(std::floor(output_credit + CREDIT_EPSILON))); + const size_t generations = std::min(outputs - 1, allowed); + + output_credit -= static_cast(generations + 1); + if (output_credit < 0.0f) { + output_credit = 0.0f; + } else if (generations == allowed && output_credit >= 1.0f) { + output_credit = std::fmod(output_credit, 1.0f); + } + + limit = generations; + return LsfgPlan{generations, true}; +} + +LsfgPacerStats LsfgPacer::Stats() const { + LsfgPacerStats stats; + stats.source_rate = source_interval > 0.0f ? 1.0f / source_interval : 0.0f; + stats.loop_rate = loop_interval > 0.0f ? 1.0f / loop_interval : 0.0f; + stats.refresh_rate = config.refresh_rate; + stats.target_rate = static_cast(config.target_rate); + stats.slots = config.refresh_rate * source_interval; + stats.limit = limit; + stats.rates_settled = RatesSettled(); + stats.last_drawn = last_drawn; + stats.last_elapsed = last_elapsed; + stats.source_frames = last_source_frames; + return stats; +} + +void LsfgPacer::Reset() { + last_frame.reset(); + last_source_sample.reset(); + last_source_frames = 0; + source_interval = 0.0f; + source_frame_accum = 0.0f; + source_time_accum = 0.0f; + loop_interval = 0.0f; + source_samples = 0; + loop_samples = 0; + last_drawn = 0; + last_elapsed = 0.0f; + output_credit = 0.0f; + limit = 0; +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_pacer.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_pacer.hpp new file mode 100644 index 0000000000..5613c4c306 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_pacer.hpp @@ -0,0 +1,87 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include +#include +#include +#include + +namespace lsfg { + +constexpr size_t LSFG_MAX_MULTIPLIER = 4; + +struct LsfgPacerConfig { + uint32_t multiplier{2}; + uint32_t target_rate{}; + float refresh_rate{}; +}; + +struct LsfgPlan { + size_t generations{}; + bool warm{}; +}; + +struct LsfgPacerStats { + float source_rate{}; + float loop_rate{}; + float refresh_rate{}; + float target_rate{}; + float slots{}; + size_t limit{}; + bool rates_settled{}; + uint64_t last_drawn{}; + float last_elapsed{}; + uint64_t source_frames{}; +}; + +class LsfgPacer { +public: + void SetConfig(const LsfgPacerConfig& config_) { + config = config_; + } + + [[nodiscard]] const LsfgPacerConfig& Config() const { + return config; + } + + [[nodiscard]] size_t MaxGenerations() const; + + [[nodiscard]] LsfgPlan Plan(size_t capacity, uint64_t source_frames); + + [[nodiscard]] LsfgPacerStats Stats() const; + + void Reset(); + +private: + using Clock = std::chrono::steady_clock; + + void TrackSourceRate(Clock::time_point now, uint64_t source_frames); + void TrackLoopRate(float interval_seconds); + [[nodiscard]] bool RatesSettled() const; + [[nodiscard]] size_t HeadroomLimit() const; + + LsfgPacerConfig config; + + std::optional last_frame; + std::optional last_source_sample; + uint64_t last_source_frames{}; + float source_interval{}; + float source_frame_accum{}; + float source_time_accum{}; + float loop_interval{}; + uint32_t source_samples{}; + uint32_t loop_samples{}; + uint64_t last_drawn{}; + float last_elapsed{}; + float output_credit{}; + size_t limit{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_probe.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_probe.cpp new file mode 100644 index 0000000000..38a7ae27ff --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_probe.cpp @@ -0,0 +1,166 @@ +// See lsfg_probe.h. Capability gate for native compositor-side LSFG. + +#include "lsfg_probe.h" +#include "../VulkanRendererContext.h" + +#include +#include + +namespace lsfg { + +namespace { + +bool hasExtension(const std::vector& exts, const char* name) { + for (const auto& e : exts) + if (strcmp(e.extensionName, name) == 0) return true; + return false; +} + +} // namespace + +FeatureSupport queryFeatures(const VkTable& vk, VkPhysicalDevice pd, + const std::vector& deviceExtensions, + bool allowVk11) { + FeatureSupport fs{}; + if (pd == VK_NULL_HANDLE || !vk.GetPhysicalDeviceProperties) return fs; + + VkPhysicalDeviceProperties props{}; + vk.GetPhysicalDeviceProperties(pd, &props); + fs.deviceApiVersion = props.apiVersion; + fs.apiAtLeast13 = props.apiVersion >= VK_API_VERSION_1_3; + + if (!vk.GetPhysicalDeviceFeatures2) return fs; + + const bool below12 = props.apiVersion < VK_API_VERSION_1_2; + if (below12) { + // Below 1.2 there is no VkPhysicalDeviceVulkan12Features to chain, and + // the SPIR-V 1.6 modules will not load anyway. Unless the experimental + // compat path is on AND the driver offers the extensions that make the + // chain loadable as SPIR-V 1.4, don't touch the device further: + // device creation stays exactly as it is today. + if (!allowVk11) return fs; + fs.hasSpirv14 = hasExtension(deviceExtensions, VK_KHR_SPIRV_1_4_EXTENSION_NAME); + fs.hasFloatControls = hasExtension(deviceExtensions, VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME); + fs.hasMemoryModelExt = hasExtension(deviceExtensions, VK_KHR_VULKAN_MEMORY_MODEL_EXTENSION_NAME); + if (!fs.hasSpirv14 || !fs.hasFloatControls || !fs.hasMemoryModelExt) { + // Report what was looked at so explain() can name the gap. + fs.queried = true; + return fs; + } + fs.extensionPath = true; + fs.spirvTarget = kSpirv14; + } else if (!fs.apiAtLeast13 && allowVk11) { + // 1.2: SPIR-V 1.5 is core, VulkanMemoryModel is core. Nothing to + // enable beyond the features; the modules only need their header + // lowered from 1.6 to 1.5. Same experimental gate as the 1.1 path so + // a production build keeps rejecting 1.2 exactly as before. + fs.extensionPath = true; + fs.spirvTarget = kSpirv15; + } + + // On 1.2+ the Vulkan12Features struct carries the memory model; below + // that the KHR struct does (same sType value, same layout). + VkPhysicalDeviceVulkan12Features v12{}; + v12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; + VkPhysicalDeviceVulkanMemoryModelFeaturesKHR mm{}; + mm.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES_KHR; + + VkPhysicalDeviceFeatures2 f2{}; + f2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + f2.pNext = below12 ? (void*)&mm : (void*)&v12; + + vk.GetPhysicalDeviceFeatures2(pd, &f2); + + fs.queried = true; + if (below12) { + fs.vulkanMemoryModel = mm.vulkanMemoryModel == VK_TRUE; + fs.vulkanMemoryModelDeviceScope = mm.vulkanMemoryModelDeviceScope == VK_TRUE; + } else { + fs.vulkanMemoryModel = v12.vulkanMemoryModel == VK_TRUE; + fs.vulkanMemoryModelDeviceScope = v12.vulkanMemoryModelDeviceScope == VK_TRUE; + } + fs.storageImageWriteWithoutFormat = f2.features.shaderStorageImageWriteWithoutFormat == VK_TRUE; + fs.storageImageExtendedFormats = f2.features.shaderStorageImageExtendedFormats == VK_TRUE; + return fs; +} + +std::vector extensionNames(const FeatureSupport& f) { + std::vector out; + if (!f.extensionPath || f.deviceApiVersion >= VK_API_VERSION_1_2) return out; + out.push_back(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME); // dependency of spirv_1_4 + out.push_back(VK_KHR_SPIRV_1_4_EXTENSION_NAME); + out.push_back(VK_KHR_VULKAN_MEMORY_MODEL_EXTENSION_NAME); + return out; +} + +bool probeLinearBlit(const VkTable& vk, VkPhysicalDevice pd, VkFormat fmt) { + if (pd == VK_NULL_HANDLE || fmt == VK_FORMAT_UNDEFINED + || !vk.GetPhysicalDeviceFormatProperties) return false; + VkFormatProperties fp{}; + vk.GetPhysicalDeviceFormatProperties(pd, fmt, &fp); + return (fp.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) != 0; +} + +bool probeStorageFormat(const VkTable& vk, VkPhysicalDevice pd, VkFormat fmt) { + if (pd == VK_NULL_HANDLE || fmt == VK_FORMAT_UNDEFINED + || !vk.GetPhysicalDeviceFormatProperties) return false; + + VkFormatProperties fp{}; + vk.GetPhysicalDeviceFormatProperties(pd, fmt, &fp); + + // The composite target is COLOR_ATTACHMENT (effect chain writes it), + // SAMPLED (next frame's LSFG input reads it), STORAGE (generate writes it) + // and both blit ends (it is copied — or, below panel resolution, blitted — + // into the swapchain image). + const VkFormatFeatureFlags need = + VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT + | VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT + | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT + | VK_FORMAT_FEATURE_BLIT_SRC_BIT + | VK_FORMAT_FEATURE_BLIT_DST_BIT; + + return (fp.optimalTilingFeatures & need) == need; +} + +void explain(Caps& caps) { + const FeatureSupport& f = caps.features; + const char* why = nullptr; + + if (!f.queried) { + why = f.deviceApiVersion < VK_API_VERSION_1_2 + ? "device Vulkan version below 1.2" + : "vkGetPhysicalDeviceFeatures2 unavailable"; + } else if (!f.apiAtLeast13 && !f.extensionPath) { + if (f.deviceApiVersion < VK_API_VERSION_1_2) { + why = !f.hasSpirv14 ? "Vulkan 1.1 driver lacks VK_KHR_spirv_1_4" + : !f.hasFloatControls ? "Vulkan 1.1 driver lacks VK_KHR_shader_float_controls" + : "Vulkan 1.1 driver lacks VK_KHR_vulkan_memory_model"; + } else { + why = "device Vulkan version below 1.3 (SPIR-V 1.6 will not load)"; + } + } else if (!f.vulkanMemoryModel) { + why = "driver lacks vulkanMemoryModel"; + } else if (!f.storageImageWriteWithoutFormat) { + why = "driver lacks shaderStorageImageWriteWithoutFormat"; + } else if (!f.storageImageExtendedFormats) { + why = "driver lacks shaderStorageImageExtendedFormats"; + } else if (!caps.featuresEnabled) { + why = "required features not enabled at device creation"; + } else if (!caps.storageOnSwapchainFormat) { + why = "swapchain format is not storage-image capable"; + } + + if (why) { + snprintf(caps.reason, sizeof(caps.reason), "unsupported: %s", why); + } else { + snprintf(caps.reason, sizeof(caps.reason), + "supported (device Vulkan %u.%u.%u%s, fmt %d)", + VK_VERSION_MAJOR(f.deviceApiVersion), + VK_VERSION_MINOR(f.deviceApiVersion), + VK_VERSION_PATCH(f.deviceApiVersion), + f.extensionPath ? " via extensions, SPIR-V lowered" : "", + (int)caps.probedFormat); + } +} + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_probe.h b/app/src/main/cpp/winlator/lsfg/lsfg_probe.h new file mode 100644 index 0000000000..0892fc5f50 --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_probe.h @@ -0,0 +1,111 @@ +#pragma once +// ============================================================================ +// lsfg_probe — capability gate for native (compositor-side) LSFG frame +// generation. +// +// The Lossless Scaling chain is 25 compute shaders that DXVK's DXBC translator +// emits as SPIR-V 1.6 with OpCapability VulkanMemoryModel and +// StorageImageWriteWithoutFormat. Three consequences, all checked here: +// +// * SPIR-V 1.6 will not load on a Vulkan 1.1 device, so the DEVICE (not just +// the instance) must report 1.3+ ... OR, on the experimental Vulkan 1.1 +// compat path, offer VK_KHR_spirv_1_4 + VK_KHR_vulkan_memory_model so the +// same modules can be handed over as SPIR-V 1.4 (see downgradeSpirv in +// lsfg_dll.h). The stock Qualcomm driver on Adreno 7xx phones reports +// 1.1.128 yet carries every one of those extensions (measured on an +// Adreno 710 / HyperOS device with `cmd gpu vkjson`). +// * vulkanMemoryModel, shaderStorageImageWriteWithoutFormat and +// shaderStorageImageExtendedFormats must be ENABLED at device creation. +// Today the renderer enables no features at all, so all three are off. +// * `generate` writes into a storage image, and Android swapchain formats +// are frequently not storage-capable — so the format is probed separately +// once the swapchain has picked one. +// +// A device failing any gate reports unsupported UP FRONT, with a reason, so +// the UI can grey the engine out instead of failing later inside +// vkCreateShaderModule or vkCreateComputePipelines. +// ============================================================================ + +#include +#include +#include + +#include "lsfg_dll.h" // kSpirv14/15/16 + +struct VkTable; + +namespace lsfg { + +// Which of the three required features the physical device OFFERS. Queried +// before vkCreateDevice; what we actually enable is recorded in Caps below. +struct FeatureSupport { + bool queried = false; // vkGetPhysicalDeviceFeatures2 resolved + bool apiAtLeast13 = false; + bool vulkanMemoryModel = false; + bool vulkanMemoryModelDeviceScope= false; + bool storageImageWriteWithoutFormat = false; + bool storageImageExtendedFormats = false; + uint32_t deviceApiVersion = 0; + + // Experimental Vulkan 1.1 compat: the device is below 1.3 but offers the + // extensions that make the chain loadable. When set, the renderer must + // enable those extensions at device creation (see extensionNames) and the + // modules are downgraded to `spirvTarget` at load. + bool extensionPath = false; + bool hasSpirv14 = false; // VK_KHR_spirv_1_4 + bool hasFloatControls = false; // VK_KHR_shader_float_controls (spirv_1_4 depends on it) + bool hasMemoryModelExt = false; // VK_KHR_vulkan_memory_model + uint32_t spirvTarget = kSpirv16; + + // Every hard device-level gate passes (format is checked separately). + bool deviceGatesPass() const { + return queried && (apiAtLeast13 || extensionPath) && vulkanMemoryModel + && storageImageWriteWithoutFormat && storageImageExtendedFormats; + } +}; + +// What was actually enabled + the running verdict. Owned by the renderer. +struct Caps { + FeatureSupport features; + bool featuresEnabled = false; // the chain was passed to vkCreateDevice + bool storageOnSwapchainFormat = false; + // The swapchain format blits with VK_FILTER_LINEAR (needs + // SAMPLED_IMAGE_FILTER_LINEAR on the source). Not a gate: without it the + // capture-resolution upscale falls back to NEAREST. + bool linearBlitOnSwapchainFormat = false; + VkFormat probedFormat = VK_FORMAT_UNDEFINED; + char reason[160] = "not probed"; + + // The single question the UI and the render path ask. + bool supported() const { + return featuresEnabled && features.deviceGatesPass() && storageOnSwapchainFormat; + } +}; + +// Ask the physical device which of the required features it offers. +// Safe on any driver: if vkGetPhysicalDeviceFeatures2 cannot be resolved, or +// the device reports below Vulkan 1.2 and `allowVk11` is false, nothing is +// chained and `queried` is left false — the caller then creates the device +// exactly as it always has. With `allowVk11`, a 1.1 device is accepted when +// `deviceExtensions` lists VK_KHR_spirv_1_4, VK_KHR_shader_float_controls and +// VK_KHR_vulkan_memory_model, and the memory-model features are queried +// through the KHR struct instead of VkPhysicalDeviceVulkan12Features. +FeatureSupport queryFeatures(const VkTable& vk, VkPhysicalDevice pd, + const std::vector& deviceExtensions, + bool allowVk11); + +// The device extensions the extension path needs enabled, in the order they +// should be pushed onto VkDeviceCreateInfo. Empty unless extensionPath. +std::vector extensionNames(const FeatureSupport& f); + +// Probe VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT on the live swapchain format. +// `generate` writes into an image of this format via a compute dispatch. +bool probeStorageFormat(const VkTable& vk, VkPhysicalDevice pd, VkFormat fmt); + +// Whether the format may be the source of a VK_FILTER_LINEAR blit. +bool probeLinearBlit(const VkTable& vk, VkPhysicalDevice pd, VkFormat fmt); + +// Fill caps.reason with the FIRST gate that failed (or "supported"). +void explain(Caps& caps); + +} // namespace lsfg diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_shaders.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_shaders.cpp new file mode 100644 index 0000000000..96fb7bfdca --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_shaders.cpp @@ -0,0 +1,100 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#include "lsfg_shaders.hpp" +#include "lsfg_common.hpp" +#include "lsfg_dll.h" + +#include + +#define LOG_TAG "LsfgShaders" +#define SHADER_LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define SHADER_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) + +namespace lsfg { + +LsfgShaders::LsfgShaders(const Device& device_, const std::string& cache_path, + uint32_t spirv_target) + : device{device_.Handle()} { + ModuleSet set; + const DllStatus status = loadModules(cache_path, set); + if (status != DllStatus::Ok) { + SHADER_LOGE("Shader cache unusable (%s)", statusName(status)); + return; + } + + // Vulkan 1.1/1.2 compat: the cache is always built at the translator's + // native SPIR-V 1.6 (no device exists at import time), so lower each module + // to what THIS device accepts. A no-op on 1.3+ devices. Only the + // DXBC-translated chain is lowered: downgradeSpirv knows the capabilities + // DXVK emits, not whatever a precompiled vendor SPIR-V variant may carry, + // and relabelling one of those could hand the driver invalid SPIR-V. + uint32_t lowered = 0; + for (Module& module : set.modules) { + if (module.words.size() > 1 && module.words[1] > spirv_target) { + if (set.variant != Variant::DxbcTranslated) { + SHADER_LOGE("shader %u: precompiled SPIR-V 0x%x is above this device's 0x%x; not lowering", + module.id, module.words[1], spirv_target); + return; + } + if (!downgradeSpirv(module.words, spirv_target)) { + SHADER_LOGE("shader %u: could not lower SPIR-V 0x%x to 0x%x", + module.id, module.words[1], spirv_target); + return; + } + lowered++; + } + } + if (lowered) + SHADER_LOGI("Lowered %u modules to SPIR-V 0x%x for this device", lowered, spirv_target); + + for (const Module& module : set.modules) { + VkShaderModuleCreateInfo module_ci{}; + module_ci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + module_ci.codeSize = module.words.size() * sizeof(uint32_t); + module_ci.pCode = module.words.data(); + + VkShaderModule handle = VK_NULL_HANDLE; + if (vkd.CreateShaderModule(device, &module_ci, nullptr, &handle) != VK_SUCCESS) { + SHADER_LOGE("vkCreateShaderModule failed for shader %u", module.id); + Release(); + return; + } + modules.emplace(module.id, handle); + } + + valid = modules.size() == kShaderCount; + if (valid) { + SHADER_LOGI("Created %zu LSFG shader modules, variant=%s", modules.size(), + variantName(set.variant)); + } else { + SHADER_LOGE("Expected %u shader modules, got %zu", kShaderCount, modules.size()); + Release(); + } +} + +LsfgShaders::~LsfgShaders() { + Release(); +} + +void LsfgShaders::Release() { + if (device != VK_NULL_HANDLE) { + for (auto& [id, module] : modules) { + vkd.DestroyShaderModule(device, module, nullptr); + } + } + modules.clear(); + valid = false; +} + +VkShaderModule LsfgShaders::Get(uint32_t shader_id) const { + const auto it = modules.find(shader_id); + return it == modules.end() ? VK_NULL_HANDLE : it->second; +} + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_shaders.hpp b/app/src/main/cpp/winlator/lsfg/lsfg_shaders.hpp new file mode 100644 index 0000000000..ba7854da4f --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_shaders.hpp @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Ported into Bannerlator's compositor from WinNative (GPL-3.0-or-later), +// whose LSFG port is credited to Camille LaVey / the Eden Emulator Project and +// follows upstream lsfg-vk. Only the Vulkan dispatch differs: Bannerlator +// resolves entry points through the renderer's own table (see lsfg_vkd.h). + +#pragma once + +#include +#include +#include +#include "lsfg_dll.h" +#include "lsfg_vkd.h" + +namespace lsfg { + +class Device; + +class LsfgShaders { +public: + LsfgShaders() = default; + // `spirv_target` is the highest SPIR-V version the device accepts (see + // lsfg_probe.h); cached modules above it are lowered before creation. + LsfgShaders(const Device& device, const std::string& cache_path, + uint32_t spirv_target = kSpirv16); + ~LsfgShaders(); + + LsfgShaders(const LsfgShaders&) = delete; + LsfgShaders& operator=(const LsfgShaders&) = delete; + + [[nodiscard]] bool IsValid() const { + return valid; + } + + [[nodiscard]] VkShaderModule Get(uint32_t shader_id) const; + +private: + void Release(); + + VkDevice device{VK_NULL_HANDLE}; + std::map modules; + bool valid{}; +}; + +} diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_vkd.cpp b/app/src/main/cpp/winlator/lsfg/lsfg_vkd.cpp new file mode 100644 index 0000000000..1e7877e92f --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_vkd.cpp @@ -0,0 +1,66 @@ +// See lsfg_vkd.h. Fills the chain's dispatch from the renderer's own table. + +#include "lsfg_vkd.h" +#include "../VulkanRendererContext.h" + +#include + +LsfgVkDispatch vkd; + +namespace { +bool g_ready = false; +} + +bool lsfgVkdInit(const VkTable& table) { + bool ok = true; +#define COPY(fn) \ + do { \ + vkd.fn = table.fn; \ + if (!vkd.fn) { \ + __android_log_print(ANDROID_LOG_ERROR, "LsfgVkd", \ + "entry point vk" #fn " did not resolve"); \ + ok = false; \ + } \ + } while (0) + + COPY(AllocateDescriptorSets); + COPY(AllocateMemory); + COPY(BindBufferMemory); + COPY(BindImageMemory); + COPY(CmdBindDescriptorSets); + COPY(CmdBindPipeline); + COPY(CmdCopyImage); + COPY(CmdDispatch); + COPY(CmdPipelineBarrier); + COPY(CreateBuffer); + COPY(CreateComputePipelines); + COPY(CreateDescriptorPool); + COPY(CreateDescriptorSetLayout); + COPY(CreateImage); + COPY(CreateImageView); + COPY(CreatePipelineLayout); + COPY(CreateSampler); + COPY(CreateShaderModule); + COPY(DestroyBuffer); + COPY(DestroyDescriptorPool); + COPY(DestroyDescriptorSetLayout); + COPY(DestroyImage); + COPY(DestroyImageView); + COPY(DestroyPipeline); + COPY(DestroyPipelineLayout); + COPY(DestroySampler); + COPY(DestroyShaderModule); + COPY(FreeMemory); + COPY(GetBufferMemoryRequirements); + COPY(GetImageMemoryRequirements); + COPY(GetPhysicalDeviceMemoryProperties); + COPY(MapMemory); + COPY(UnmapMemory); + COPY(UpdateDescriptorSets); +#undef COPY + + g_ready = ok; + return ok; +} + +bool lsfgVkdReady() { return g_ready; } diff --git a/app/src/main/cpp/winlator/lsfg/lsfg_vkd.h b/app/src/main/cpp/winlator/lsfg/lsfg_vkd.h new file mode 100644 index 0000000000..768588dccf --- /dev/null +++ b/app/src/main/cpp/winlator/lsfg/lsfg_vkd.h @@ -0,0 +1,70 @@ +#pragma once +// ============================================================================ +// lsfg_vkd — the Vulkan entry points the LSFG chain calls, as a single global. +// +// Two dispatch styles meet here. Bannerlator's compositor resolves Vulkan +// through a per-context VkTable (`vk_`), because an adrenotools-loaded driver +// lives in an isolated linker namespace and shares no global symbols with the +// system loader. The LSFG chain, ported from eden by way of WinNative, calls +// through a file-scope `vkd`. Rather than rewrite ~2,300 lines of proven chain +// code to thread a table through every call, this shim exposes exactly the 34 +// entry points the chain uses and is filled from the renderer's own table when +// the chain is created. +// +// That keeps the ported files close to their upstream form, which matters: +// they are the part of this feature that is hardest to review by eye and +// easiest to break with a well-meaning edit. +// +// Single-renderer assumption: there is one Vulkan compositor per process, so +// one global table is correct. lsfgVkdInit() is idempotent and simply +// overwrites; lsfgVkdReady() reports whether every pointer resolved. +// ============================================================================ + +#include + +struct VkTable; + +struct LsfgVkDispatch { + PFN_vkAllocateDescriptorSets AllocateDescriptorSets = nullptr; + PFN_vkAllocateMemory AllocateMemory = nullptr; + PFN_vkBindBufferMemory BindBufferMemory = nullptr; + PFN_vkBindImageMemory BindImageMemory = nullptr; + PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets = nullptr; + PFN_vkCmdBindPipeline CmdBindPipeline = nullptr; + PFN_vkCmdCopyImage CmdCopyImage = nullptr; + PFN_vkCmdDispatch CmdDispatch = nullptr; + PFN_vkCmdPipelineBarrier CmdPipelineBarrier = nullptr; + PFN_vkCreateBuffer CreateBuffer = nullptr; + PFN_vkCreateComputePipelines CreateComputePipelines = nullptr; + PFN_vkCreateDescriptorPool CreateDescriptorPool = nullptr; + PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout = nullptr; + PFN_vkCreateImage CreateImage = nullptr; + PFN_vkCreateImageView CreateImageView = nullptr; + PFN_vkCreatePipelineLayout CreatePipelineLayout = nullptr; + PFN_vkCreateSampler CreateSampler = nullptr; + PFN_vkCreateShaderModule CreateShaderModule = nullptr; + PFN_vkDestroyBuffer DestroyBuffer = nullptr; + PFN_vkDestroyDescriptorPool DestroyDescriptorPool = nullptr; + PFN_vkDestroyDescriptorSetLayout DestroyDescriptorSetLayout = nullptr; + PFN_vkDestroyImage DestroyImage = nullptr; + PFN_vkDestroyImageView DestroyImageView = nullptr; + PFN_vkDestroyPipeline DestroyPipeline = nullptr; + PFN_vkDestroyPipelineLayout DestroyPipelineLayout = nullptr; + PFN_vkDestroySampler DestroySampler = nullptr; + PFN_vkDestroyShaderModule DestroyShaderModule = nullptr; + PFN_vkFreeMemory FreeMemory = nullptr; + PFN_vkGetBufferMemoryRequirements GetBufferMemoryRequirements = nullptr; + PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements = nullptr; + PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties = nullptr; + PFN_vkMapMemory MapMemory = nullptr; + PFN_vkUnmapMemory UnmapMemory = nullptr; + PFN_vkUpdateDescriptorSets UpdateDescriptorSets = nullptr; +}; + +extern LsfgVkDispatch vkd; + +// Fill `vkd` from the renderer's table. Returns false (and leaves the chain +// unusable) if any entry point failed to resolve — better to report the engine +// unsupported than to call through a null pointer mid-frame. +bool lsfgVkdInit(const VkTable& table); +bool lsfgVkdReady(); diff --git a/app/src/main/cpp/winlator/winfg/LICENSE.win-fg b/app/src/main/cpp/winlator/winfg/LICENSE.win-fg new file mode 100644 index 0000000000..1fb0c75624 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/LICENSE.win-fg @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 The412Banner + +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. diff --git a/app/src/main/cpp/winlator/winfg/NOTICE_FIDELITYFX_OPTICALFLOW.md b/app/src/main/cpp/winlator/winfg/NOTICE_FIDELITYFX_OPTICALFLOW.md new file mode 100644 index 0000000000..4b618fe4ee --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/NOTICE_FIDELITYFX_OPTICALFLOW.md @@ -0,0 +1,47 @@ +# NOTICE — FidelityFX Optical Flow (model 3) + +win-fg "model 3" (FSR3 Optical Flow) embeds compute shaders that are an +adaptation of the **AMD FidelityFX SDK FSR3 Optical Flow** algorithm. + +Source passes adapted (FidelityFX-SDK, branch `main`): + +- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_prepare_luma.h` + → `of3_luma.comp` (Rec.709 LDR luminance extraction) +- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_compute_luminance_pyramid.h` + → `of3_downsample.comp` (4-tap box / SPD-equivalent mip reduce) +- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_compute_optical_flow_v5.h` + → `of3_flow.comp` (SAD block-match search with coarse-level prediction) +- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_scale_optical_flow_advanced_v5.h` + → `of3_expand.comp` (bilinear upscale of coarse flow to display resolution) + +The GLSL adaptations are subgroup-free / SPD-library-free re-implementations so +they compile with `glslangValidator` for Vulkan 1.1 (Adreno/Turnip-safe). They +intentionally drop the SDK's HDR transfer-function handling, wave intrinsics +(`ffxWaveSum`), `msad4`, packed-uint luma and groupshared SAD maps, none of +which are portable to bare GLSL on this stack. See per-shader DEVIATION comments. + +FidelityFX SDK is distributed under the MIT License: + +``` +This file is part of the FidelityFX SDK. + +Copyright (C) Advanced Micro Devices, Inc. + +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. +``` diff --git a/app/src/main/cpp/winlator/winfg/config.hpp b/app/src/main/cpp/winlator/winfg/config.hpp new file mode 100644 index 0000000000..eb186382e4 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/config.hpp @@ -0,0 +1,357 @@ +// win-fg — runtime config: enable gate, model, multiplier, and the synthesis +// tuning parameters. Sourced from environment variables and an optional +// conf.toml (a config file, when present, wins over the env defaults). +#pragma once +#include +#include +#include +#include +#include +#include + +namespace winfg { + +struct Config { + bool enabled = false; // gate; loader also honours the manifest enable var + // GRANULAR PRESENT-PATH DEBUG TRACE. Default OFF. When ON, winfg_QueuePresentKHR + // emits a per-frame, step-by-step trail (logcat tag "win-fg") so a freeze/ + // crash-on-enable leaves an obvious LAST line at the exact stage that hung or + // faulted (acquire-spare, compute-submit, present-generated/real, fence wait, + // fallback). Zero behaviour change and effectively zero cost when off — one + // predicted-not-taken bool test per step, no logcat writes. + // WIN_FG_DEBUG=1|0 / conf.toml debug=on|off. + bool debug = false; + // ── EVEN-CADENCE FRAME PACING ───────────────────────────────────────────── + // Default ON. The 2x insert path presents the GENERATED frame then the REAL + // frame back-to-back in one vkQueuePresentKHR hook call, so on Mailbox/ + // Immediate both land in ~one instant followed by a full frame-interval gap + // until the next pair — uneven in time → judder ("slows down to catch up"). + // With pacing on, the layer measures the real-frame interval (EMA of a + // monotonic clock) and holds the REAL present to its scheduled beat so the + // generated frame lands near the temporal MIDPOINT between consecutive real + // frames (even gen,real,gen,real cadence). Pure bounded CPU sleep — no GPU + // wait added; if a frame is already behind schedule the wait is SKIPPED + // (present immediately) so worst case is one un-paced pair, never a hitch. + // FIFO self-paces so the waits collapse to ~0 there. Off ⇒ byte-identical + // back-to-back behaviour. WIN_FG_PACING=on|off / conf.toml pacing=on|off. + // ISOLATION BUILD: default flipped to OFF to A/B the AYANEO-750 post-setting-change + // flicker regression against the pacing feature (everything else byte-identical). + bool pacing = false; + int model = 4; // 3 = symmetric flow, 4 = bidir + occlusion gate + int multiplier = 2; // generated presents per real present + 1 + // EXTRA SWAPCHAIN IMAGE HEADROOM (device-freeze fix). On top of the +1 spare the + // insert path needs, request this many ADDITIONAL images at swapchain creation: + // requested minImageCount = app_min + 1 (spare) + extra_images, + // clamped to surfaceCaps.maxImageCount (0 = unlimited -> no clamp), never below + // app_min+1. The extra headroom stops the guest's NEXT vkAcquireNextImageKHR from + // starving while win-fg holds a spare + a real frame in flight to the AHB-backed + // host compositor. Some SoCs (Adreno 840 / Turnip) recycle displayed AHBs too + // slowly to tolerate the extra present with only the +1 spare and freeze on the + // first inserted frame; the AYANEO (Adreno 750) recycles fast enough to tolerate + // it. Default 2 (a few MB VRAM), applied on all devices. On a device that already + // works this only grows the pool — no FPS/quality change; the pool-headroom guard + // in QueuePresentKHR stays a no-op when headroom is adequate. + // WIN_FG_EXTRA_IMAGES / conf.toml extra_images. + int extraImages = 2; + // ── FLOW-RESOLUTION PERFORMANCE PRESET ──────────────────────────────────── + // Trades base-FPS-drop against optical-flow quality by selecting the FINEST + // pyramid level the dense flow is solved at (FrameGen::kFlowFinest): + // 0 = Quality -> kFlowFinest = 1 (~1/2-res flow; best motion, biggest FG cost) + // 1 = Balanced -> kFlowFinest = 2 (~1/4-res; TODAY's behaviour) [DEFAULT] + // 2 = Performance -> kFlowFinest = 3 (~1/8-res; cheapest -> smallest base-FPS drop) + // Out-of-range clamps to Balanced (1), so an unset/older conf.toml is byte- + // identical to today. Changing this LIVE rebuilds the affected per-size flow + // images (like a resize) inside the layer and resets the flow predictor, so a + // preset change is fully hot — no FG toggle needed. See FrameGen::configure / + // FrameGen::flowFinestForPreset. WIN_FG_PERF_PRESET / conf.toml perf_preset. + int perfPreset = 1; // 0 quality, 1 balanced (default), 2 performance + float flowScale = 1.0f; // scales solved flow magnitude + // C1 GLOBAL-MOTION PRE-WARP. Estimate the per-frame camera affine (LK) and + // remove it before the dense SAD flow search so the search only sees coherent + // object-only residual motion (kills fast-pan "melt"). 0 = auto (engage only + // when the LK solve is stable), 1 = on (force-engage once a solve exists), + // 2 = off (never pre-warp; identity affine → pipeline == pre-C1 exactly). + // WIN_FG_GM=auto|on|off / conf.toml global_motion=auto|on|off. + int gmMode = 0; // 0 auto, 1 on, 2 off + // C2 FLOW REGULARIZATION (TV-L1 smoothness prior). After C1 removes the camera + // motion, the dense flow (flowLvl_ at kFlowFinest, 1/4-res) is the OBJECT-only + // residual; it still carries spurious per-block vectors. C2 runs N semi-implicit + // TV-L1 denoising iterations on that field — an L1 data term + edge-aware Total- + // Variation regularizer — to kill incoherent vectors while KEEPING true motion + // discontinuities (object edges) sharp. Solved in-place; expand's median + C1 + // add-back consume the cleaned field unchanged. 0 iterations ⇒ byte-identical to + // pre-C2. See shaders/of3_flowreg.comp. + // WIN_FG_FLOWREG=auto|on|off / conf.toml flow_reg=auto|on|off. + int frMode = 0; // 0 auto (engaged), 1 on (engaged), 2 off + int frIters = 4; // TV-L1 iterations at kFlowFinest (0 ⇒ off) + float frLambda = 2.0f; // L1 data-fidelity weight (higher ⇒ trust SAD flow) + float frDt = 0.25f; // semi-implicit smoothing step (higher ⇒ smoother) + float frEdge = 8.0f; // luma-gradient edge sensitivity for the TV weight g + float frEps = 0.05f; // Charbonnier epsilon (px) for the TV diffusivity + // synthesis (wfg_synth) tuning + float beta = 8.0f; // softmax sharpness on importance Z + float lambda = 0.6f; // FB-consistency vs photometric weight + // Tightened 2026-08-17 to prioritise "no ghost" over max sharpness — the + // remaining single-frame ghosts came from pixels that the previous defaults + // still trusted with warp when they should have cross-faded. Raising both + // pushes borderline pixels toward the safe cross-fade path (softer, but no + // smear). Prewarp will lift the ceiling further; this is the "safety net" + // knob change until then. + // Walked back from (0.10, 9.0) tighten after user reported softening. The + // real fix for the residual ghosts is the 3a-fallback path change in + // layer.cpp (present real curr on fallback instead of blitting synth over); + // the gate can stay closer to the original values now. + float epsilon = 0.07f; // disocclusion floor (0.05 -> 0.10 -> 0.07) + float photoScale = 7.5f; // photometric residual scale into Z (6.0 -> 9.0 -> 7.5) + // HUD exclusion rect in pixel coords (x0,y0,x1,y1). Fragments inside are + // passed through as the real current frame (no warp, no synth) so text / + // overlays don't ghost. Disabled when x0 >= x1 or y0 >= y1 (the default). + // Sourced from WIN_FG_HUD_RECT="x0,y0,x1,y1" env var or conf.toml + // (hudRect="x0,y0,x1,y1"). Pattern is Isygold's Vegas DXVK framegen — + // host knows where the HUD is, tell the shader to skip it. + float hudX0 = 0.0f; + float hudY0 = 0.0f; + float hudX1 = 0.0f; + float hudY1 = 0.0f; + + // ── TRAINING-DATA CAPTURE MODE (Route-B VFI dataset collection) ─────────── + // A dev-only gate. When OFF (default) the present path is byte-identical to a + // build without this feature — a single bool test and nothing else. When ON, + // every real present is downscaled on the GPU, read back async, and written to + // disk as lossless QOI (motion-rich 256² triplet patches by default, or full + // downscaled frames) plus a JSONL manifest, for offline (i-1,i+1)->i training. + // NEVER captures win-fg's generated frames — capture reads the real swapchain + // image at the TOP of QueuePresentKHR, before any interpolation. + // WIN_FG_CAPTURE=on|off / conf.toml capture=on|off. + bool capture = false; + // Downscale target box (aspect-preserving, never upscales). WIN_FG_CAPTURE_W/H, + // conf capture_width/capture_height. + int captureW = 1280; + int captureH = 720; + // 0 = patch (self-contained aligned triplets, DEFAULT), 1 = frame (full + // downscaled frames in order). WIN_FG_CAPTURE_MODE=patch|frame. + int capMode = 0; + int capPatches = 3; // patches per triplet in patch mode (WIN_FG_CAPTURE_PATCHES) + int capPatchSize = 256; // patch edge in downscaled px (WIN_FG_CAPTURE_PATCH) + // Skip a unit whose inter-frame motion (mean per-pixel luma abs-diff, 0..255) + // is below this. WIN_FG_CAPTURE_MOTION / conf capture_motion. + float capMotion = 2.0f; + // Output dir; empty => $HOME/.cache/winfg-capture. WIN_FG_CAPTURE_DIR / + // conf capture_dir. A per-run session subdir is created under it. + std::string capDir; + // Rolling-shard size cap (MiB). Output is a small number of large packed + // .wfgcap containers, not thousands of loose files; a new shard opens when the + // current one passes this. WIN_FG_CAPTURE_SHARD_MB / conf capture_shard_mb. + int capShardMB = 1024; + + void sanitize() { + if (model < 3) model = 3; if (model > 4) model = 4; + if (multiplier < 2) multiplier = 2; if (multiplier > 4) multiplier = 4; + if (extraImages < 0) extraImages = 0; if (extraImages > 8) extraImages = 8; + if (perfPreset < 0 || perfPreset > 2) perfPreset = 1; // clamp out-of-range -> Balanced + if (gmMode < 0) gmMode = 0; if (gmMode > 2) gmMode = 2; + if (frMode < 0) frMode = 0; if (frMode > 2) frMode = 2; + if (frIters < 0) frIters = 0; if (frIters > 16) frIters = 16; + if (frLambda < 0.0f) frLambda = 0.0f; + if (frDt < 0.01f) frDt = 0.01f; if (frDt > 4.0f) frDt = 4.0f; + if (frEdge < 0.0f) frEdge = 0.0f; + if (frEps < 1e-3f) frEps = 1e-3f; + if (flowScale < 0.05f) flowScale = 0.05f; if (flowScale > 4.0f) flowScale = 4.0f; + if (beta < 0.0f) beta = 0.0f; if (lambda < 0.0f) lambda = 0.0f; + // capture knobs + if (captureW < 16) captureW = 16; if (captureW > 7680) captureW = 7680; + if (captureH < 16) captureH = 16; if (captureH > 4320) captureH = 4320; + if (capMode < 0) capMode = 0; if (capMode > 1) capMode = 1; + if (capPatches < 1) capPatches = 1; if (capPatches > 16) capPatches = 16; + if (capPatchSize < 16) capPatchSize = 16; if (capPatchSize > 1024) capPatchSize = 1024; + if (capMotion < 0.0f) capMotion = 0.0f; + if (capShardMB < 16) capShardMB = 16; if (capShardMB > 65536) capShardMB = 65536; + } +}; + +static inline float envf(const char* k, float d) { + const char* v = std::getenv(k); return v ? std::strtof(v, nullptr) : d; +} +static inline int envi(const char* k, int d) { + const char* v = std::getenv(k); return v ? std::atoi(v) : d; +} + +// "auto"/"on"/"off" (also true/false/on/off numerics) -> {0 auto, 1 on, 2 off}. +static inline int parse_tristate(const std::string& v, int dflt) { + if (v.empty()) return dflt; + if (v == "auto") return 0; + if (v == "on" || v == "1" || v == "force" || v == "true" || v == "yes") return 1; + if (v == "off" || v == "0" || v == "false" || v == "no") return 2; + return dflt; +} + +// "on"/"off"/"1"/"true"/... -> bool. +static inline bool parse_bool(const std::string& v, bool dflt) { + int t = parse_tristate(v, dflt ? 1 : 2); + return t == 1; +} +// "patch"|"frame" -> {0 patch, 1 frame}. +static inline int parse_capmode(const std::string& v, int dflt) { + if (v == "patch" || v == "patches" || v == "0") return 0; + if (v == "frame" || v == "frames" || v == "1") return 1; + return dflt; +} + +// key=value TOML-lite reader (flat keys, '#' comments) — enough for our knobs. +static inline void apply_toml(Config& c, const std::string& path) { + std::ifstream f(path); + if (!f) return; + std::string line; + while (std::getline(f, line)) { + auto h = line.find('#'); if (h != std::string::npos) line = line.substr(0, h); + auto eq = line.find('='); if (eq == std::string::npos) continue; + auto trim = [](std::string s){ + size_t a = s.find_first_not_of(" \t\r\n"); size_t b = s.find_last_not_of(" \t\r\n"); + return (a == std::string::npos) ? std::string() : s.substr(a, b - a + 1); }; + std::string k = trim(line.substr(0, eq)), v = trim(line.substr(eq + 1)); + if (k.empty() || v.empty()) continue; + if (k == "enabled") c.enabled = (v == "1" || v == "true"); + else if (k == "debug") c.debug = parse_bool(v, c.debug); + else if (k == "pacing") c.pacing = parse_bool(v, c.pacing); + else if (k == "model") c.model = std::atoi(v.c_str()); + else if (k == "multiplier") c.multiplier = std::atoi(v.c_str()); + else if (k == "extra_images") c.extraImages = std::atoi(v.c_str()); + else if (k == "perf_preset") c.perfPreset = std::atoi(v.c_str()); + else if (k == "global_motion") c.gmMode = parse_tristate(v, c.gmMode); + else if (k == "flow_reg") c.frMode = parse_tristate(v, c.frMode); + else if (k == "fr_iters") c.frIters = std::atoi(v.c_str()); + else if (k == "fr_lambda") c.frLambda = std::strtof(v.c_str(), nullptr); + else if (k == "fr_dt") c.frDt = std::strtof(v.c_str(), nullptr); + else if (k == "fr_edge") c.frEdge = std::strtof(v.c_str(), nullptr); + else if (k == "fr_eps") c.frEps = std::strtof(v.c_str(), nullptr); + else if (k == "flowScale") c.flowScale = std::strtof(v.c_str(), nullptr); + else if (k == "beta") c.beta = std::strtof(v.c_str(), nullptr); + else if (k == "lambda") c.lambda = std::strtof(v.c_str(), nullptr); + else if (k == "epsilon") c.epsilon = std::strtof(v.c_str(), nullptr); + else if (k == "photoScale") c.photoScale = std::strtof(v.c_str(), nullptr); + // ── capture-mode knobs ──────────────────────────────────────────────── + else if (k == "capture") c.capture = parse_bool(v, c.capture); + else if (k == "capture_dir") c.capDir = v; + else if (k == "capture_width") c.captureW = std::atoi(v.c_str()); + else if (k == "capture_height") c.captureH = std::atoi(v.c_str()); + else if (k == "capture_mode") c.capMode = parse_capmode(v, c.capMode); + else if (k == "capture_patches") c.capPatches = std::atoi(v.c_str()); + else if (k == "capture_patch_size") c.capPatchSize = std::atoi(v.c_str()); + else if (k == "capture_motion") c.capMotion = std::strtof(v.c_str(), nullptr); + else if (k == "capture_shard_mb") c.capShardMB = std::atoi(v.c_str()); + else if (k == "hudRect") { + // "x0,y0,x1,y1" in pixel coords + float r[4] = {0,0,0,0}; int n = 0; + size_t start = 0; std::string s = v; + for (; n < 4; ++n) { + size_t comma = s.find(',', start); + std::string tok = s.substr(start, comma == std::string::npos ? std::string::npos : comma - start); + r[n] = std::strtof(tok.c_str(), nullptr); + if (comma == std::string::npos) break; + start = comma + 1; + } + c.hudX0 = r[0]; c.hudY0 = r[1]; c.hudX1 = r[2]; c.hudY1 = r[3]; + } + } +} + +// Path of the conf.toml the app writes (used for hot-reload mtime checks). +static inline std::string conf_path() { + if (const char* p = std::getenv("WIN_FG_CONF")) return p; + const char* home = std::getenv("HOME"); + return home ? std::string(home) + "/.config/win-fg/conf.toml" : std::string(); +} + +// Resolve the capture output root: explicit override, else $HOME/.cache/winfg-capture, +// else a /tmp fallback so a HOME-less prefix still writes somewhere pullable. +static inline std::string capture_root(const Config& c) { + if (!c.capDir.empty()) return c.capDir; + if (const char* home = std::getenv("HOME")) return std::string(home) + "/.cache/winfg-capture"; + return std::string("/tmp/winfg-capture"); +} + +// env defaults first, then conf.toml overrides (file wins when present). +static inline Config load_config() { + Config c; + c.enabled = envi("WIN_FG_ENABLE", 0) != 0; + if (const char* d = std::getenv("WIN_FG_DEBUG")) c.debug = parse_bool(d, c.debug); + if (const char* pc = std::getenv("WIN_FG_PACING")) c.pacing = parse_bool(pc, c.pacing); + c.model = envi("WIN_FG_MODEL", c.model); + c.multiplier = envi("WIN_FG_MULT", c.multiplier); + c.extraImages = envi("WIN_FG_EXTRA_IMAGES", c.extraImages); + c.perfPreset = envi("WIN_FG_PERF_PRESET", c.perfPreset); + if (const char* g = std::getenv("WIN_FG_GM")) c.gmMode = parse_tristate(g, c.gmMode); + if (const char* r = std::getenv("WIN_FG_FLOWREG")) c.frMode = parse_tristate(r, c.frMode); + c.frIters = envi("WIN_FG_FR_ITERS", c.frIters); + c.frLambda = envf("WIN_FG_FR_LAMBDA", c.frLambda); + c.frDt = envf("WIN_FG_FR_DT", c.frDt); + c.frEdge = envf("WIN_FG_FR_EDGE", c.frEdge); + c.frEps = envf("WIN_FG_FR_EPS", c.frEps); + c.flowScale = envf("WIN_FG_FLOWSCALE", c.flowScale); + c.beta = envf("WIN_FG_BETA", c.beta); + c.lambda = envf("WIN_FG_LAMBDA", c.lambda); + c.epsilon = envf("WIN_FG_EPSILON", c.epsilon); + c.photoScale = envf("WIN_FG_PHOTOSCALE", c.photoScale); + // ── capture-mode env (conf.toml still wins below) ───────────────────────── + if (const char* cc = std::getenv("WIN_FG_CAPTURE")) c.capture = parse_bool(cc, c.capture); + c.captureW = envi("WIN_FG_CAPTURE_W", c.captureW); + c.captureH = envi("WIN_FG_CAPTURE_H", c.captureH); + if (const char* cm = std::getenv("WIN_FG_CAPTURE_MODE")) c.capMode = parse_capmode(cm, c.capMode); + c.capPatches = envi("WIN_FG_CAPTURE_PATCHES", c.capPatches); + c.capPatchSize = envi("WIN_FG_CAPTURE_PATCH", c.capPatchSize); + c.capMotion = envf("WIN_FG_CAPTURE_MOTION", c.capMotion); + c.capShardMB = envi("WIN_FG_CAPTURE_SHARD_MB", c.capShardMB); + if (const char* cd = std::getenv("WIN_FG_CAPTURE_DIR")) c.capDir = cd; + if (const char* h = std::getenv("WIN_FG_HUD_RECT")) { + // "x0,y0,x1,y1" — pixel coords; disabled when x0>=x1 or y0>=y1 + float r[4] = {0,0,0,0}; int n = 0; + std::string s = h; size_t start = 0; + for (; n < 4; ++n) { + size_t comma = s.find(',', start); + r[n] = std::strtof(s.substr(start, comma == std::string::npos ? std::string::npos : comma - start).c_str(), nullptr); + if (comma == std::string::npos) break; + start = comma + 1; + } + c.hudX0 = r[0]; c.hudY0 = r[1]; c.hudX1 = r[2]; c.hudY1 = r[3]; + } + const char* home = std::getenv("HOME"); + if (home) apply_toml(c, std::string(home) + "/.config/win-fg/conf.toml"); + if (const char* p = std::getenv("WIN_FG_CONF")) apply_toml(c, p); + c.sanitize(); + return c; +} + +// UBO layout — MUST match wfg_synth.comp binding 0. +// The vec4 hudRect is 16-byte aligned in std140, sits at offset 32 (after the +// 8 leading floats which naturally occupy 32B). Disabled when hudX0>=hudX1. +struct SynthUBO { + float flowScale, alpha, beta, lambda, epsilon, photoScale, pad0, pad1; + float hudX0, hudY0, hudX1, hudY1; +}; +// UBO layout — MUST match of3_flow / of3_expand_m4 binding 0 (Model3UBO). +struct FlowUBO { float flowScale; uint32_t level; float occlLo; float occlHi; }; + +// C1 global-motion UBO — MUST match binding 1 in of3_gm_reduce / of3_gm_prewarp / +// of3_expand(_m4). std140: four vec4 = 64 bytes. The affine is in centered-UV +// space: P = [[p1,p3],[p2,p4]], translation (tx,ty); warp uvSrc = uv + P*(uv-0.5) +// + t maps a prev(template) coord to the curr(image) coord it samples (prev→curr). +// lin[] = running LK estimate (linearization point fed to of3_gm_reduce) +// app[] = APPLIED affine (of3_gm_prewarp + expand add-back); identity when +// disengaged so the pipeline is byte-identical to pre-C1. +struct GMUBO { + float lin[4]; // p1,p2,p3,p4 + float linT[4]; // tx,ty, engaged, pad + float app[4]; // p1,p2,p3,p4 + float appT[4]; // tx,ty, pad, pad +}; + +// C2 flow-regularization UBO — MUST match binding 0 (vec4 params) in +// of3_flowreg.comp. std140: one vec4 = 16 bytes. See Config::fr* fields. +struct FlowRegUBO { + float dt; // params.x — semi-implicit smoothing step + float lambda; // params.y — L1 data-fidelity weight (θ = dt·lambda) + float edgeAlpha; // params.z — luma-gradient edge sensitivity for g + float epsTV; // params.w — Charbonnier epsilon (px) for the TV diffusivity +}; + +} // namespace winfg diff --git a/app/src/main/cpp/winlator/winfg/embedded_shaders.hpp b/app/src/main/cpp/winlator/winfg/embedded_shaders.hpp new file mode 100644 index 0000000000..7d858d6318 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/embedded_shaders.hpp @@ -0,0 +1,44 @@ +// GENERATED by tools/embed_spv.py — do not edit by hand. +// win-fg embedded SPIR-V: our optical-flow front end + synthesis only. +#pragma once +#include +#include +namespace winfg { namespace embedded { +static const uint32_t OF3_LUMA_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000054u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00030005u,0x00000030u,0x00007675u,0x00030005u,0x0000003bu,0x00626772u,0x00040005u,0x0000003fu,0x63725375u,0x00000000u,0x00030005u,0x00000047u,0x00005966u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00040047u,0x0000003fu,0x00000021u,0x00000020u,0x00040047u,0x0000003fu,0x00000022u,0x00000000u,0x00040047u,0x00000053u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000033u,0x3f000000u,0x00040017u,0x00000039u,0x00000013u,0x00000003u,0x00040020u,0x0000003au,0x00000007u,0x00000039u,0x00090019u,0x0000003cu,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000003du,0x0000003cu,0x00040020u,0x0000003eu,0x00000000u,0x0000003du,0x0004003bu,0x0000003eu,0x0000003fu,0x00000000u,0x0004002bu,0x00000013u,0x00000042u,0x00000000u,0x00040017u,0x00000043u,0x00000013u,0x00000004u,0x00040020u,0x00000046u,0x00000007u,0x00000013u,0x0004002bu,0x00000013u,0x00000049u,0x3e59b3d0u,0x0004002bu,0x00000013u,0x0000004au,0x3f371759u,0x0004002bu,0x00000013u,0x0000004bu,0x3d93dd98u,0x0006002cu,0x00000039u,0x0000004cu,0x00000049u,0x0000004au,0x0000004bu,0x0004002bu,0x0000000au,0x00000052u,0x00000010u,0x0006002cu,0x0000000bu,0x00000053u,0x00000052u,0x00000052u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000003au,0x0000003bu,0x00000007u,0x0004003bu,0x00000046u,0x00000047u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000007u,0x00000031u,0x00000009u,0x0004006fu,0x0000002eu,0x00000032u,0x00000031u,0x00050050u,0x0000002eu,0x00000034u,0x00000033u,0x00000033u,0x00050081u,0x0000002eu,0x00000035u,0x00000032u,0x00000034u,0x0004003du,0x00000007u,0x00000036u,0x00000012u,0x0004006fu,0x0000002eu,0x00000037u,0x00000036u,0x00050088u,0x0000002eu,0x00000038u,0x00000035u,0x00000037u,0x0003003eu,0x00000030u,0x00000038u,0x0004003du,0x0000003du,0x00000040u,0x0000003fu,0x0004003du,0x0000002eu,0x00000041u,0x00000030u,0x00070058u,0x00000043u,0x00000044u,0x00000040u,0x00000041u,0x00000002u,0x00000042u,0x0008004fu,0x00000039u,0x00000045u,0x00000044u,0x00000044u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x0000003bu,0x00000045u,0x0004003du,0x00000039u,0x00000048u,0x0000003bu,0x00050094u,0x00000013u,0x0000004du,0x00000048u,0x0000004cu,0x0003003eu,0x00000047u,0x0000004du,0x0004003du,0x00000014u,0x0000004eu,0x00000016u,0x0004003du,0x00000007u,0x0000004fu,0x00000009u,0x0004003du,0x00000013u,0x00000050u,0x00000047u,0x00070050u,0x00000043u,0x00000051u,0x00000050u,0x00000042u,0x00000042u,0x00000042u,0x00040063u,0x0000004eu,0x0000004fu,0x00000051u,0x000100fdu,0x00010038u}; +static const size_t OF3_LUMA_LEN = 481; +static const uint32_t OF3_DOWNSAMPLE_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x0000008au,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00040005u,0x00000030u,0x44637273u,0x00006d69u,0x00040005u,0x00000034u,0x63725375u,0x00000000u,0x00040005u,0x0000003au,0x65736162u,0x00000000u,0x00030005u,0x00000044u,0x00000068u,0x00030005u,0x0000004au,0x00000061u,0x00030005u,0x00000059u,0x00000062u,0x00030005u,0x00000065u,0x00000063u,0x00030005u,0x00000071u,0x00000064u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00040047u,0x00000034u,0x00000021u,0x00000020u,0x00040047u,0x00000034u,0x00000022u,0x00000000u,0x00040047u,0x00000089u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x00090019u,0x00000031u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000032u,0x00000031u,0x00040020u,0x00000033u,0x00000000u,0x00000032u,0x0004003bu,0x00000033u,0x00000034u,0x00000000u,0x0004002bu,0x00000006u,0x00000036u,0x00000000u,0x0004002bu,0x00000013u,0x0000003du,0x40000000u,0x0004002bu,0x00000013u,0x0000003fu,0x3f800000u,0x0004002bu,0x00000013u,0x00000045u,0x3f000000u,0x00040020u,0x00000049u,0x00000007u,0x00000013u,0x0004002bu,0x00000013u,0x00000055u,0x00000000u,0x00040017u,0x00000056u,0x00000013u,0x00000004u,0x0004002bu,0x00000013u,0x00000085u,0x3e800000u,0x0004002bu,0x0000000au,0x00000088u,0x00000010u,0x0006002cu,0x0000000bu,0x00000089u,0x00000088u,0x00000088u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x0000003au,0x00000007u,0x0004003bu,0x0000002fu,0x00000044u,0x00000007u,0x0004003bu,0x00000049u,0x0000004au,0x00000007u,0x0004003bu,0x00000049u,0x00000059u,0x00000007u,0x0004003bu,0x00000049u,0x00000065u,0x00000007u,0x0004003bu,0x00000049u,0x00000071u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000032u,0x00000035u,0x00000034u,0x00040064u,0x00000031u,0x00000037u,0x00000035u,0x00050067u,0x00000007u,0x00000038u,0x00000037u,0x00000036u,0x0004006fu,0x0000002eu,0x00000039u,0x00000038u,0x0003003eu,0x00000030u,0x00000039u,0x0004003du,0x00000007u,0x0000003bu,0x00000009u,0x0004006fu,0x0000002eu,0x0000003cu,0x0000003bu,0x0005008eu,0x0000002eu,0x0000003eu,0x0000003cu,0x0000003du,0x00050050u,0x0000002eu,0x00000040u,0x0000003fu,0x0000003fu,0x00050081u,0x0000002eu,0x00000041u,0x0000003eu,0x00000040u,0x0004003du,0x0000002eu,0x00000042u,0x00000030u,0x00050088u,0x0000002eu,0x00000043u,0x00000041u,0x00000042u,0x0003003eu,0x0000003au,0x00000043u,0x0004003du,0x0000002eu,0x00000046u,0x00000030u,0x00050050u,0x0000002eu,0x00000047u,0x00000045u,0x00000045u,0x00050088u,0x0000002eu,0x00000048u,0x00000047u,0x00000046u,0x0003003eu,0x00000044u,0x00000048u,0x0004003du,0x00000032u,0x0000004bu,0x00000034u,0x0004003du,0x0000002eu,0x0000004cu,0x0000003au,0x00050041u,0x00000049u,0x0000004du,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x0000004eu,0x0000004du,0x0004007fu,0x00000013u,0x0000004fu,0x0000004eu,0x00050041u,0x00000049u,0x00000050u,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x00000051u,0x00000050u,0x0004007fu,0x00000013u,0x00000052u,0x00000051u,0x00050050u,0x0000002eu,0x00000053u,0x0000004fu,0x00000052u,0x00050081u,0x0000002eu,0x00000054u,0x0000004cu,0x00000053u,0x00070058u,0x00000056u,0x00000057u,0x0000004bu,0x00000054u,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x00000058u,0x00000057u,0x00000000u,0x0003003eu,0x0000004au,0x00000058u,0x0004003du,0x00000032u,0x0000005au,0x00000034u,0x0004003du,0x0000002eu,0x0000005bu,0x0000003au,0x00050041u,0x00000049u,0x0000005cu,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x0000005du,0x0000005cu,0x00050041u,0x00000049u,0x0000005eu,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x0000005fu,0x0000005eu,0x0004007fu,0x00000013u,0x00000060u,0x0000005fu,0x00050050u,0x0000002eu,0x00000061u,0x0000005du,0x00000060u,0x00050081u,0x0000002eu,0x00000062u,0x0000005bu,0x00000061u,0x00070058u,0x00000056u,0x00000063u,0x0000005au,0x00000062u,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x00000064u,0x00000063u,0x00000000u,0x0003003eu,0x00000059u,0x00000064u,0x0004003du,0x00000032u,0x00000066u,0x00000034u,0x0004003du,0x0000002eu,0x00000067u,0x0000003au,0x00050041u,0x00000049u,0x00000068u,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x00000069u,0x00000068u,0x0004007fu,0x00000013u,0x0000006au,0x00000069u,0x00050041u,0x00000049u,0x0000006bu,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x0000006cu,0x0000006bu,0x00050050u,0x0000002eu,0x0000006du,0x0000006au,0x0000006cu,0x00050081u,0x0000002eu,0x0000006eu,0x00000067u,0x0000006du,0x00070058u,0x00000056u,0x0000006fu,0x00000066u,0x0000006eu,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x00000070u,0x0000006fu,0x00000000u,0x0003003eu,0x00000065u,0x00000070u,0x0004003du,0x00000032u,0x00000072u,0x00000034u,0x0004003du,0x0000002eu,0x00000073u,0x0000003au,0x00050041u,0x00000049u,0x00000074u,0x00000044u,0x0000001au,0x0004003du,0x00000013u,0x00000075u,0x00000074u,0x00050041u,0x00000049u,0x00000076u,0x00000044u,0x00000024u,0x0004003du,0x00000013u,0x00000077u,0x00000076u,0x00050050u,0x0000002eu,0x00000078u,0x00000075u,0x00000077u,0x00050081u,0x0000002eu,0x00000079u,0x00000073u,0x00000078u,0x00070058u,0x00000056u,0x0000007au,0x00000072u,0x00000079u,0x00000002u,0x00000055u,0x00050051u,0x00000013u,0x0000007bu,0x0000007au,0x00000000u,0x0003003eu,0x00000071u,0x0000007bu,0x0004003du,0x00000014u,0x0000007cu,0x00000016u,0x0004003du,0x00000007u,0x0000007du,0x00000009u,0x0004003du,0x00000013u,0x0000007eu,0x0000004au,0x0004003du,0x00000013u,0x0000007fu,0x00000059u,0x00050081u,0x00000013u,0x00000080u,0x0000007eu,0x0000007fu,0x0004003du,0x00000013u,0x00000081u,0x00000065u,0x00050081u,0x00000013u,0x00000082u,0x00000080u,0x00000081u,0x0004003du,0x00000013u,0x00000083u,0x00000071u,0x00050081u,0x00000013u,0x00000084u,0x00000082u,0x00000083u,0x00050085u,0x00000013u,0x00000086u,0x00000084u,0x00000085u,0x00070050u,0x00000056u,0x00000087u,0x00000086u,0x00000055u,0x00000055u,0x00000055u,0x00040063u,0x0000007cu,0x0000007du,0x00000087u,0x000100fdu,0x00010038u}; +static const size_t OF3_DOWNSAMPLE_LEN = 753; +static const uint32_t OF3_FLOW_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000185u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x6f6c4675u,0x00000077u,0x00040005u,0x00000030u,0x44766e69u,0x00006d69u,0x00030005u,0x00000036u,0x00007675u,0x00040005u,0x0000003fu,0x654c6f74u,0x006c6576u,0x00030005u,0x00000040u,0x00000055u,0x00060006u,0x00000040u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000040u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000040u,0x00000002u,0x30646170u,0x00000000u,0x00050006u,0x00000040u,0x00000003u,0x31646170u,0x00000000u,0x00030005u,0x00000042u,0x00000000u,0x00050005u,0x0000004au,0x64657270u,0x6c6c7546u,0x00000000u,0x00050005u,0x0000004eu,0x65725075u,0x74636964u,0x0000726fu,0x00050005u,0x00000055u,0x64657270u,0x6576654cu,0x0000006cu,0x00040005u,0x00000059u,0x74736562u,0x00646153u,0x00050005u,0x0000005bu,0x74736562u,0x70736944u,0x00000000u,0x00030005u,0x0000005du,0x00007973u,0x00030005u,0x00000067u,0x00007873u,0x00040005u,0x0000006fu,0x646e6163u,0x00000000u,0x00030005u,0x00000077u,0x00646173u,0x00030005u,0x00000078u,0x00007962u,0x00030005u,0x00000081u,0x00007862u,0x00030005u,0x00000089u,0x00006f62u,0x00030005u,0x0000008fu,0x00000070u,0x00050005u,0x00000090u,0x6d754c75u,0x65725061u,0x00000076u,0x00030005u,0x00000099u,0x00000063u,0x00050005u,0x0000009au,0x6d754c75u,0x72754361u,0x00000072u,0x00040005u,0x000000cau,0x43646173u,0x00000000u,0x00040005u,0x000000ccu,0x58646173u,0x0000006du,0x00040005u,0x000000cdu,0x58646173u,0x00000070u,0x00040005u,0x000000ceu,0x59646173u,0x0000006du,0x00040005u,0x000000cfu,0x59646173u,0x00000070u,0x00030005u,0x000000d0u,0x00007962u,0x00030005u,0x000000d8u,0x00007862u,0x00030005u,0x000000e0u,0x00006f62u,0x00030005u,0x000000e6u,0x00000070u,0x00040005u,0x000000efu,0x646e6163u,0x00006d58u,0x00040005u,0x000000f4u,0x646e6163u,0x00007058u,0x00040005u,0x000000f8u,0x646e6163u,0x00006d59u,0x00040005u,0x000000fcu,0x646e6163u,0x00007059u,0x00030005u,0x00000148u,0x00007864u,0x00030005u,0x00000149u,0x00007964u,0x00040005u,0x0000014au,0x6f6e6564u,0x0000586du,0x00040005u,0x00000152u,0x6f6e6564u,0x0000596du,0x00050005u,0x00000176u,0x776f6c66u,0x6c6c7546u,0x00000000u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00030047u,0x00000040u,0x00000002u,0x00050048u,0x00000040u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000040u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000040u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000040u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000042u,0x00000021u,0x00000000u,0x00040047u,0x00000042u,0x00000022u,0x00000000u,0x00040047u,0x0000004eu,0x00000021u,0x00000022u,0x00040047u,0x0000004eu,0x00000022u,0x00000000u,0x00040047u,0x00000090u,0x00000021u,0x00000020u,0x00040047u,0x00000090u,0x00000022u,0x00000000u,0x00040047u,0x0000009au,0x00000021u,0x00000021u,0x00040047u,0x0000009au,0x00000022u,0x00000000u,0x00040047u,0x00000184u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000031u,0x3f800000u,0x0004002bu,0x00000013u,0x00000039u,0x3f000000u,0x00040020u,0x0000003eu,0x00000007u,0x00000013u,0x0006001eu,0x00000040u,0x00000013u,0x0000000au,0x0000000au,0x0000000au,0x00040020u,0x00000041u,0x00000002u,0x00000040u,0x0004003bu,0x00000041u,0x00000042u,0x00000002u,0x0004002bu,0x00000006u,0x00000043u,0x00000001u,0x00040020u,0x00000044u,0x00000002u,0x0000000au,0x00090019u,0x0000004bu,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000004cu,0x0000004bu,0x00040020u,0x0000004du,0x00000000u,0x0000004cu,0x0004003bu,0x0000004du,0x0000004eu,0x00000000u,0x0004002bu,0x00000013u,0x00000051u,0x00000000u,0x00040017u,0x00000052u,0x00000013u,0x00000004u,0x0004002bu,0x00000013u,0x0000005au,0x7f7fffffu,0x0004002bu,0x00000006u,0x0000005eu,0xfffffffdu,0x0004002bu,0x00000006u,0x00000065u,0x00000003u,0x0004002bu,0x00000006u,0x00000079u,0xffffffffu,0x0004003bu,0x0000004du,0x00000090u,0x00000000u,0x0004003bu,0x0000004du,0x0000009au,0x00000000u,0x0004002bu,0x00000013u,0x000000afu,0x3bc49ba6u,0x0004002bu,0x00000013u,0x000000f1u,0xbf800000u,0x0005002cu,0x0000002eu,0x000000f2u,0x000000f1u,0x00000051u,0x0005002cu,0x0000002eu,0x000000f6u,0x00000031u,0x00000051u,0x0005002cu,0x0000002eu,0x000000fau,0x00000051u,0x000000f1u,0x0005002cu,0x0000002eu,0x000000feu,0x00000051u,0x00000031u,0x0004002bu,0x00000013u,0x0000014cu,0x40000000u,0x0004002bu,0x00000013u,0x0000015au,0x358637bdu,0x0004002bu,0x00000013u,0x00000164u,0xbf000000u,0x0004002bu,0x0000000au,0x00000183u,0x00000010u,0x0006002cu,0x0000000bu,0x00000184u,0x00000183u,0x00000183u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x00000036u,0x00000007u,0x0004003bu,0x0000003eu,0x0000003fu,0x00000007u,0x0004003bu,0x0000002fu,0x0000004au,0x00000007u,0x0004003bu,0x0000002fu,0x00000055u,0x00000007u,0x0004003bu,0x0000003eu,0x00000059u,0x00000007u,0x0004003bu,0x0000002fu,0x0000005bu,0x00000007u,0x0004003bu,0x0000001bu,0x0000005du,0x00000007u,0x0004003bu,0x0000001bu,0x00000067u,0x00000007u,0x0004003bu,0x0000002fu,0x0000006fu,0x00000007u,0x0004003bu,0x0000003eu,0x00000077u,0x00000007u,0x0004003bu,0x0000001bu,0x00000078u,0x00000007u,0x0004003bu,0x0000001bu,0x00000081u,0x00000007u,0x0004003bu,0x0000002fu,0x00000089u,0x00000007u,0x0004003bu,0x0000003eu,0x0000008fu,0x00000007u,0x0004003bu,0x0000003eu,0x00000099u,0x00000007u,0x0004003bu,0x0000003eu,0x000000cau,0x00000007u,0x0004003bu,0x0000003eu,0x000000ccu,0x00000007u,0x0004003bu,0x0000003eu,0x000000cdu,0x00000007u,0x0004003bu,0x0000003eu,0x000000ceu,0x00000007u,0x0004003bu,0x0000003eu,0x000000cfu,0x00000007u,0x0004003bu,0x0000001bu,0x000000d0u,0x00000007u,0x0004003bu,0x0000001bu,0x000000d8u,0x00000007u,0x0004003bu,0x0000002fu,0x000000e0u,0x00000007u,0x0004003bu,0x0000003eu,0x000000e6u,0x00000007u,0x0004003bu,0x0000002fu,0x000000efu,0x00000007u,0x0004003bu,0x0000002fu,0x000000f4u,0x00000007u,0x0004003bu,0x0000002fu,0x000000f8u,0x00000007u,0x0004003bu,0x0000002fu,0x000000fcu,0x00000007u,0x0004003bu,0x0000003eu,0x00000148u,0x00000007u,0x0004003bu,0x0000003eu,0x00000149u,0x00000007u,0x0004003bu,0x0000003eu,0x0000014au,0x00000007u,0x0004003bu,0x0000003eu,0x00000152u,0x00000007u,0x0004003bu,0x0000002fu,0x00000176u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000007u,0x00000032u,0x00000012u,0x0004006fu,0x0000002eu,0x00000033u,0x00000032u,0x00050050u,0x0000002eu,0x00000034u,0x00000031u,0x00000031u,0x00050088u,0x0000002eu,0x00000035u,0x00000034u,0x00000033u,0x0003003eu,0x00000030u,0x00000035u,0x0004003du,0x00000007u,0x00000037u,0x00000009u,0x0004006fu,0x0000002eu,0x00000038u,0x00000037u,0x00050050u,0x0000002eu,0x0000003au,0x00000039u,0x00000039u,0x00050081u,0x0000002eu,0x0000003bu,0x00000038u,0x0000003au,0x0004003du,0x0000002eu,0x0000003cu,0x00000030u,0x00050085u,0x0000002eu,0x0000003du,0x0000003bu,0x0000003cu,0x0003003eu,0x00000036u,0x0000003du,0x00050041u,0x00000044u,0x00000045u,0x00000042u,0x00000043u,0x0004003du,0x0000000au,0x00000046u,0x00000045u,0x00040070u,0x00000013u,0x00000047u,0x00000046u,0x0004007fu,0x00000013u,0x00000048u,0x00000047u,0x0006000cu,0x00000013u,0x00000049u,0x00000001u,0x0000001du,0x00000048u,0x0003003eu,0x0000003fu,0x00000049u,0x0004003du,0x0000004cu,0x0000004fu,0x0000004eu,0x0004003du,0x0000002eu,0x00000050u,0x00000036u,0x00070058u,0x00000052u,0x00000053u,0x0000004fu,0x00000050u,0x00000002u,0x00000051u,0x0007004fu,0x0000002eu,0x00000054u,0x00000053u,0x00000053u,0x00000000u,0x00000001u,0x0003003eu,0x0000004au,0x00000054u,0x0004003du,0x0000002eu,0x00000056u,0x0000004au,0x0004003du,0x00000013u,0x00000057u,0x0000003fu,0x0005008eu,0x0000002eu,0x00000058u,0x00000056u,0x00000057u,0x0003003eu,0x00000055u,0x00000058u,0x0003003eu,0x00000059u,0x0000005au,0x0004003du,0x0000002eu,0x0000005cu,0x00000055u,0x0003003eu,0x0000005bu,0x0000005cu,0x0003003eu,0x0000005du,0x0000005eu,0x000200f9u,0x0000005fu,0x000200f8u,0x0000005fu,0x000400f6u,0x00000061u,0x00000062u,0x00000000u,0x000200f9u,0x00000063u,0x000200f8u,0x00000063u,0x0004003du,0x00000006u,0x00000064u,0x0000005du,0x000500b3u,0x00000019u,0x00000066u,0x00000064u,0x00000065u,0x000400fau,0x00000066u,0x00000060u,0x00000061u,0x000200f8u,0x00000060u,0x0003003eu,0x00000067u,0x0000005eu,0x000200f9u,0x00000068u,0x000200f8u,0x00000068u,0x000400f6u,0x0000006au,0x0000006bu,0x00000000u,0x000200f9u,0x0000006cu,0x000200f8u,0x0000006cu,0x0004003du,0x00000006u,0x0000006du,0x00000067u,0x000500b3u,0x00000019u,0x0000006eu,0x0000006du,0x00000065u,0x000400fau,0x0000006eu,0x00000069u,0x0000006au,0x000200f8u,0x00000069u,0x0004003du,0x0000002eu,0x00000070u,0x00000055u,0x0004003du,0x00000006u,0x00000071u,0x00000067u,0x0004006fu,0x00000013u,0x00000072u,0x00000071u,0x0004003du,0x00000006u,0x00000073u,0x0000005du,0x0004006fu,0x00000013u,0x00000074u,0x00000073u,0x00050050u,0x0000002eu,0x00000075u,0x00000072u,0x00000074u,0x00050081u,0x0000002eu,0x00000076u,0x00000070u,0x00000075u,0x0003003eu,0x0000006fu,0x00000076u,0x0003003eu,0x00000077u,0x00000051u,0x0003003eu,0x00000078u,0x00000079u,0x000200f9u,0x0000007au,0x000200f8u,0x0000007au,0x000400f6u,0x0000007cu,0x0000007du,0x00000000u,0x000200f9u,0x0000007eu,0x000200f8u,0x0000007eu,0x0004003du,0x00000006u,0x0000007fu,0x00000078u,0x000500b3u,0x00000019u,0x00000080u,0x0000007fu,0x00000043u,0x000400fau,0x00000080u,0x0000007bu,0x0000007cu,0x000200f8u,0x0000007bu,0x0003003eu,0x00000081u,0x00000079u,0x000200f9u,0x00000082u,0x000200f8u,0x00000082u,0x000400f6u,0x00000084u,0x00000085u,0x00000000u,0x000200f9u,0x00000086u,0x000200f8u,0x00000086u,0x0004003du,0x00000006u,0x00000087u,0x00000081u,0x000500b3u,0x00000019u,0x00000088u,0x00000087u,0x00000043u,0x000400fau,0x00000088u,0x00000083u,0x00000084u,0x000200f8u,0x00000083u,0x0004003du,0x00000006u,0x0000008au,0x00000081u,0x0004006fu,0x00000013u,0x0000008bu,0x0000008au,0x0004003du,0x00000006u,0x0000008cu,0x00000078u,0x0004006fu,0x00000013u,0x0000008du,0x0000008cu,0x00050050u,0x0000002eu,0x0000008eu,0x0000008bu,0x0000008du,0x0003003eu,0x00000089u,0x0000008eu,0x0004003du,0x0000004cu,0x00000091u,0x00000090u,0x0004003du,0x0000002eu,0x00000092u,0x00000036u,0x0004003du,0x0000002eu,0x00000093u,0x00000089u,0x0004003du,0x0000002eu,0x00000094u,0x00000030u,0x00050085u,0x0000002eu,0x00000095u,0x00000093u,0x00000094u,0x00050081u,0x0000002eu,0x00000096u,0x00000092u,0x00000095u,0x00070058u,0x00000052u,0x00000097u,0x00000091u,0x00000096u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000098u,0x00000097u,0x00000000u,0x0003003eu,0x0000008fu,0x00000098u,0x0004003du,0x0000004cu,0x0000009bu,0x0000009au,0x0004003du,0x0000002eu,0x0000009cu,0x00000036u,0x0004003du,0x0000002eu,0x0000009du,0x00000089u,0x0004003du,0x0000002eu,0x0000009eu,0x0000006fu,0x00050081u,0x0000002eu,0x0000009fu,0x0000009du,0x0000009eu,0x0004003du,0x0000002eu,0x000000a0u,0x00000030u,0x00050085u,0x0000002eu,0x000000a1u,0x0000009fu,0x000000a0u,0x00050081u,0x0000002eu,0x000000a2u,0x0000009cu,0x000000a1u,0x00070058u,0x00000052u,0x000000a3u,0x0000009bu,0x000000a2u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x000000a4u,0x000000a3u,0x00000000u,0x0003003eu,0x00000099u,0x000000a4u,0x0004003du,0x00000013u,0x000000a5u,0x0000008fu,0x0004003du,0x00000013u,0x000000a6u,0x00000099u,0x00050083u,0x00000013u,0x000000a7u,0x000000a5u,0x000000a6u,0x0006000cu,0x00000013u,0x000000a8u,0x00000001u,0x00000004u,0x000000a7u,0x0004003du,0x00000013u,0x000000a9u,0x00000077u,0x00050081u,0x00000013u,0x000000aau,0x000000a9u,0x000000a8u,0x0003003eu,0x00000077u,0x000000aau,0x000200f9u,0x00000085u,0x000200f8u,0x00000085u,0x0004003du,0x00000006u,0x000000abu,0x00000081u,0x00050080u,0x00000006u,0x000000acu,0x000000abu,0x00000043u,0x0003003eu,0x00000081u,0x000000acu,0x000200f9u,0x00000082u,0x000200f8u,0x00000084u,0x000200f9u,0x0000007du,0x000200f8u,0x0000007du,0x0004003du,0x00000006u,0x000000adu,0x00000078u,0x00050080u,0x00000006u,0x000000aeu,0x000000adu,0x00000043u,0x0003003eu,0x00000078u,0x000000aeu,0x000200f9u,0x0000007au,0x000200f8u,0x0000007cu,0x0004003du,0x00000006u,0x000000b0u,0x00000067u,0x0004006fu,0x00000013u,0x000000b1u,0x000000b0u,0x0006000cu,0x00000013u,0x000000b2u,0x00000001u,0x00000004u,0x000000b1u,0x0004003du,0x00000006u,0x000000b3u,0x0000005du,0x0004006fu,0x00000013u,0x000000b4u,0x000000b3u,0x0006000cu,0x00000013u,0x000000b5u,0x00000001u,0x00000004u,0x000000b4u,0x00050081u,0x00000013u,0x000000b6u,0x000000b2u,0x000000b5u,0x00050085u,0x00000013u,0x000000b7u,0x000000afu,0x000000b6u,0x0004003du,0x00000013u,0x000000b8u,0x00000077u,0x00050081u,0x00000013u,0x000000b9u,0x000000b8u,0x000000b7u,0x0003003eu,0x00000077u,0x000000b9u,0x0004003du,0x00000013u,0x000000bau,0x00000077u,0x0004003du,0x00000013u,0x000000bbu,0x00000059u,0x000500b8u,0x00000019u,0x000000bcu,0x000000bau,0x000000bbu,0x000300f7u,0x000000beu,0x00000000u,0x000400fau,0x000000bcu,0x000000bdu,0x000000beu,0x000200f8u,0x000000bdu,0x0004003du,0x00000013u,0x000000bfu,0x00000077u,0x0003003eu,0x00000059u,0x000000bfu,0x0004003du,0x0000002eu,0x000000c0u,0x0000006fu,0x0003003eu,0x0000005bu,0x000000c0u,0x000200f9u,0x000000beu,0x000200f8u,0x000000beu,0x000200f9u,0x0000006bu,0x000200f8u,0x0000006bu,0x0004003du,0x00000006u,0x000000c1u,0x00000067u,0x00050080u,0x00000006u,0x000000c2u,0x000000c1u,0x00000043u,0x0003003eu,0x00000067u,0x000000c2u,0x000200f9u,0x00000068u,0x000200f8u,0x0000006au,0x000200f9u,0x00000062u,0x000200f8u,0x00000062u,0x0004003du,0x00000006u,0x000000c3u,0x0000005du,0x00050080u,0x00000006u,0x000000c4u,0x000000c3u,0x00000043u,0x0003003eu,0x0000005du,0x000000c4u,0x000200f9u,0x0000005fu,0x000200f8u,0x00000061u,0x00050041u,0x00000044u,0x000000c5u,0x00000042u,0x00000043u,0x0004003du,0x0000000au,0x000000c6u,0x000000c5u,0x000500aau,0x00000019u,0x000000c7u,0x000000c6u,0x0000001au,0x000300f7u,0x000000c9u,0x00000000u,0x000400fau,0x000000c7u,0x000000c8u,0x000000c9u,0x000200f8u,0x000000c8u,0x0004003du,0x00000013u,0x000000cbu,0x00000059u,0x0003003eu,0x000000cau,0x000000cbu,0x0003003eu,0x000000ccu,0x00000051u,0x0003003eu,0x000000cdu,0x00000051u,0x0003003eu,0x000000ceu,0x00000051u,0x0003003eu,0x000000cfu,0x00000051u,0x0003003eu,0x000000d0u,0x00000079u,0x000200f9u,0x000000d1u,0x000200f8u,0x000000d1u,0x000400f6u,0x000000d3u,0x000000d4u,0x00000000u,0x000200f9u,0x000000d5u,0x000200f8u,0x000000d5u,0x0004003du,0x00000006u,0x000000d6u,0x000000d0u,0x000500b3u,0x00000019u,0x000000d7u,0x000000d6u,0x00000043u,0x000400fau,0x000000d7u,0x000000d2u,0x000000d3u,0x000200f8u,0x000000d2u,0x0003003eu,0x000000d8u,0x00000079u,0x000200f9u,0x000000d9u,0x000200f8u,0x000000d9u,0x000400f6u,0x000000dbu,0x000000dcu,0x00000000u,0x000200f9u,0x000000ddu,0x000200f8u,0x000000ddu,0x0004003du,0x00000006u,0x000000deu,0x000000d8u,0x000500b3u,0x00000019u,0x000000dfu,0x000000deu,0x00000043u,0x000400fau,0x000000dfu,0x000000dau,0x000000dbu,0x000200f8u,0x000000dau,0x0004003du,0x00000006u,0x000000e1u,0x000000d8u,0x0004006fu,0x00000013u,0x000000e2u,0x000000e1u,0x0004003du,0x00000006u,0x000000e3u,0x000000d0u,0x0004006fu,0x00000013u,0x000000e4u,0x000000e3u,0x00050050u,0x0000002eu,0x000000e5u,0x000000e2u,0x000000e4u,0x0003003eu,0x000000e0u,0x000000e5u,0x0004003du,0x0000004cu,0x000000e7u,0x00000090u,0x0004003du,0x0000002eu,0x000000e8u,0x00000036u,0x0004003du,0x0000002eu,0x000000e9u,0x000000e0u,0x0004003du,0x0000002eu,0x000000eau,0x00000030u,0x00050085u,0x0000002eu,0x000000ebu,0x000000e9u,0x000000eau,0x00050081u,0x0000002eu,0x000000ecu,0x000000e8u,0x000000ebu,0x00070058u,0x00000052u,0x000000edu,0x000000e7u,0x000000ecu,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x000000eeu,0x000000edu,0x00000000u,0x0003003eu,0x000000e6u,0x000000eeu,0x0004003du,0x0000002eu,0x000000f0u,0x0000005bu,0x00050081u,0x0000002eu,0x000000f3u,0x000000f0u,0x000000f2u,0x0003003eu,0x000000efu,0x000000f3u,0x0004003du,0x0000002eu,0x000000f5u,0x0000005bu,0x00050081u,0x0000002eu,0x000000f7u,0x000000f5u,0x000000f6u,0x0003003eu,0x000000f4u,0x000000f7u,0x0004003du,0x0000002eu,0x000000f9u,0x0000005bu,0x00050081u,0x0000002eu,0x000000fbu,0x000000f9u,0x000000fau,0x0003003eu,0x000000f8u,0x000000fbu,0x0004003du,0x0000002eu,0x000000fdu,0x0000005bu,0x00050081u,0x0000002eu,0x000000ffu,0x000000fdu,0x000000feu,0x0003003eu,0x000000fcu,0x000000ffu,0x0004003du,0x00000013u,0x00000100u,0x000000e6u,0x0004003du,0x0000004cu,0x00000101u,0x0000009au,0x0004003du,0x0000002eu,0x00000102u,0x00000036u,0x0004003du,0x0000002eu,0x00000103u,0x000000e0u,0x0004003du,0x0000002eu,0x00000104u,0x000000efu,0x00050081u,0x0000002eu,0x00000105u,0x00000103u,0x00000104u,0x0004003du,0x0000002eu,0x00000106u,0x00000030u,0x00050085u,0x0000002eu,0x00000107u,0x00000105u,0x00000106u,0x00050081u,0x0000002eu,0x00000108u,0x00000102u,0x00000107u,0x00070058u,0x00000052u,0x00000109u,0x00000101u,0x00000108u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x0000010au,0x00000109u,0x00000000u,0x00050083u,0x00000013u,0x0000010bu,0x00000100u,0x0000010au,0x0006000cu,0x00000013u,0x0000010cu,0x00000001u,0x00000004u,0x0000010bu,0x0004003du,0x00000013u,0x0000010du,0x000000ccu,0x00050081u,0x00000013u,0x0000010eu,0x0000010du,0x0000010cu,0x0003003eu,0x000000ccu,0x0000010eu,0x0004003du,0x00000013u,0x0000010fu,0x000000e6u,0x0004003du,0x0000004cu,0x00000110u,0x0000009au,0x0004003du,0x0000002eu,0x00000111u,0x00000036u,0x0004003du,0x0000002eu,0x00000112u,0x000000e0u,0x0004003du,0x0000002eu,0x00000113u,0x000000f4u,0x00050081u,0x0000002eu,0x00000114u,0x00000112u,0x00000113u,0x0004003du,0x0000002eu,0x00000115u,0x00000030u,0x00050085u,0x0000002eu,0x00000116u,0x00000114u,0x00000115u,0x00050081u,0x0000002eu,0x00000117u,0x00000111u,0x00000116u,0x00070058u,0x00000052u,0x00000118u,0x00000110u,0x00000117u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000119u,0x00000118u,0x00000000u,0x00050083u,0x00000013u,0x0000011au,0x0000010fu,0x00000119u,0x0006000cu,0x00000013u,0x0000011bu,0x00000001u,0x00000004u,0x0000011au,0x0004003du,0x00000013u,0x0000011cu,0x000000cdu,0x00050081u,0x00000013u,0x0000011du,0x0000011cu,0x0000011bu,0x0003003eu,0x000000cdu,0x0000011du,0x0004003du,0x00000013u,0x0000011eu,0x000000e6u,0x0004003du,0x0000004cu,0x0000011fu,0x0000009au,0x0004003du,0x0000002eu,0x00000120u,0x00000036u,0x0004003du,0x0000002eu,0x00000121u,0x000000e0u,0x0004003du,0x0000002eu,0x00000122u,0x000000f8u,0x00050081u,0x0000002eu,0x00000123u,0x00000121u,0x00000122u,0x0004003du,0x0000002eu,0x00000124u,0x00000030u,0x00050085u,0x0000002eu,0x00000125u,0x00000123u,0x00000124u,0x00050081u,0x0000002eu,0x00000126u,0x00000120u,0x00000125u,0x00070058u,0x00000052u,0x00000127u,0x0000011fu,0x00000126u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000128u,0x00000127u,0x00000000u,0x00050083u,0x00000013u,0x00000129u,0x0000011eu,0x00000128u,0x0006000cu,0x00000013u,0x0000012au,0x00000001u,0x00000004u,0x00000129u,0x0004003du,0x00000013u,0x0000012bu,0x000000ceu,0x00050081u,0x00000013u,0x0000012cu,0x0000012bu,0x0000012au,0x0003003eu,0x000000ceu,0x0000012cu,0x0004003du,0x00000013u,0x0000012du,0x000000e6u,0x0004003du,0x0000004cu,0x0000012eu,0x0000009au,0x0004003du,0x0000002eu,0x0000012fu,0x00000036u,0x0004003du,0x0000002eu,0x00000130u,0x000000e0u,0x0004003du,0x0000002eu,0x00000131u,0x000000fcu,0x00050081u,0x0000002eu,0x00000132u,0x00000130u,0x00000131u,0x0004003du,0x0000002eu,0x00000133u,0x00000030u,0x00050085u,0x0000002eu,0x00000134u,0x00000132u,0x00000133u,0x00050081u,0x0000002eu,0x00000135u,0x0000012fu,0x00000134u,0x00070058u,0x00000052u,0x00000136u,0x0000012eu,0x00000135u,0x00000002u,0x00000051u,0x00050051u,0x00000013u,0x00000137u,0x00000136u,0x00000000u,0x00050083u,0x00000013u,0x00000138u,0x0000012du,0x00000137u,0x0006000cu,0x00000013u,0x00000139u,0x00000001u,0x00000004u,0x00000138u,0x0004003du,0x00000013u,0x0000013au,0x000000cfu,0x00050081u,0x00000013u,0x0000013bu,0x0000013au,0x00000139u,0x0003003eu,0x000000cfu,0x0000013bu,0x000200f9u,0x000000dcu,0x000200f8u,0x000000dcu,0x0004003du,0x00000006u,0x0000013cu,0x000000d8u,0x00050080u,0x00000006u,0x0000013du,0x0000013cu,0x00000043u,0x0003003eu,0x000000d8u,0x0000013du,0x000200f9u,0x000000d9u,0x000200f8u,0x000000dbu,0x000200f9u,0x000000d4u,0x000200f8u,0x000000d4u,0x0004003du,0x00000006u,0x0000013eu,0x000000d0u,0x00050080u,0x00000006u,0x0000013fu,0x0000013eu,0x00000043u,0x0003003eu,0x000000d0u,0x0000013fu,0x000200f9u,0x000000d1u,0x000200f8u,0x000000d3u,0x0004003du,0x00000013u,0x00000140u,0x000000ccu,0x00050081u,0x00000013u,0x00000141u,0x00000140u,0x000000afu,0x0003003eu,0x000000ccu,0x00000141u,0x0004003du,0x00000013u,0x00000142u,0x000000cdu,0x00050081u,0x00000013u,0x00000143u,0x00000142u,0x000000afu,0x0003003eu,0x000000cdu,0x00000143u,0x0004003du,0x00000013u,0x00000144u,0x000000ceu,0x00050081u,0x00000013u,0x00000145u,0x00000144u,0x000000afu,0x0003003eu,0x000000ceu,0x00000145u,0x0004003du,0x00000013u,0x00000146u,0x000000cfu,0x00050081u,0x00000013u,0x00000147u,0x00000146u,0x000000afu,0x0003003eu,0x000000cfu,0x00000147u,0x0003003eu,0x00000148u,0x00000051u,0x0003003eu,0x00000149u,0x00000051u,0x0004003du,0x00000013u,0x0000014bu,0x000000ccu,0x0004003du,0x00000013u,0x0000014du,0x000000cau,0x00050085u,0x00000013u,0x0000014eu,0x0000014cu,0x0000014du,0x00050083u,0x00000013u,0x0000014fu,0x0000014bu,0x0000014eu,0x0004003du,0x00000013u,0x00000150u,0x000000cdu,0x00050081u,0x00000013u,0x00000151u,0x0000014fu,0x00000150u,0x0003003eu,0x0000014au,0x00000151u,0x0004003du,0x00000013u,0x00000153u,0x000000ceu,0x0004003du,0x00000013u,0x00000154u,0x000000cau,0x00050085u,0x00000013u,0x00000155u,0x0000014cu,0x00000154u,0x00050083u,0x00000013u,0x00000156u,0x00000153u,0x00000155u,0x0004003du,0x00000013u,0x00000157u,0x000000cfu,0x00050081u,0x00000013u,0x00000158u,0x00000156u,0x00000157u,0x0003003eu,0x00000152u,0x00000158u,0x0004003du,0x00000013u,0x00000159u,0x0000014au,0x000500bau,0x00000019u,0x0000015bu,0x00000159u,0x0000015au,0x000300f7u,0x0000015du,0x00000000u,0x000400fau,0x0000015bu,0x0000015cu,0x0000015du,0x000200f8u,0x0000015cu,0x0004003du,0x00000013u,0x0000015eu,0x000000ccu,0x0004003du,0x00000013u,0x0000015fu,0x000000cdu,0x00050083u,0x00000013u,0x00000160u,0x0000015eu,0x0000015fu,0x00050085u,0x00000013u,0x00000161u,0x00000039u,0x00000160u,0x0004003du,0x00000013u,0x00000162u,0x0000014au,0x00050088u,0x00000013u,0x00000163u,0x00000161u,0x00000162u,0x0008000cu,0x00000013u,0x00000165u,0x00000001u,0x0000002bu,0x00000163u,0x00000164u,0x00000039u,0x0003003eu,0x00000148u,0x00000165u,0x000200f9u,0x0000015du,0x000200f8u,0x0000015du,0x0004003du,0x00000013u,0x00000166u,0x00000152u,0x000500bau,0x00000019u,0x00000167u,0x00000166u,0x0000015au,0x000300f7u,0x00000169u,0x00000000u,0x000400fau,0x00000167u,0x00000168u,0x00000169u,0x000200f8u,0x00000168u,0x0004003du,0x00000013u,0x0000016au,0x000000ceu,0x0004003du,0x00000013u,0x0000016bu,0x000000cfu,0x00050083u,0x00000013u,0x0000016cu,0x0000016au,0x0000016bu,0x00050085u,0x00000013u,0x0000016du,0x00000039u,0x0000016cu,0x0004003du,0x00000013u,0x0000016eu,0x00000152u,0x00050088u,0x00000013u,0x0000016fu,0x0000016du,0x0000016eu,0x0008000cu,0x00000013u,0x00000170u,0x00000001u,0x0000002bu,0x0000016fu,0x00000164u,0x00000039u,0x0003003eu,0x00000149u,0x00000170u,0x000200f9u,0x00000169u,0x000200f8u,0x00000169u,0x0004003du,0x00000013u,0x00000171u,0x00000148u,0x0004003du,0x00000013u,0x00000172u,0x00000149u,0x00050050u,0x0000002eu,0x00000173u,0x00000171u,0x00000172u,0x0004003du,0x0000002eu,0x00000174u,0x0000005bu,0x00050081u,0x0000002eu,0x00000175u,0x00000174u,0x00000173u,0x0003003eu,0x0000005bu,0x00000175u,0x000200f9u,0x000000c9u,0x000200f8u,0x000000c9u,0x0004003du,0x0000002eu,0x00000177u,0x0000005bu,0x00050041u,0x00000044u,0x00000178u,0x00000042u,0x00000043u,0x0004003du,0x0000000au,0x00000179u,0x00000178u,0x00040070u,0x00000013u,0x0000017au,0x00000179u,0x0006000cu,0x00000013u,0x0000017bu,0x00000001u,0x0000001du,0x0000017au,0x0005008eu,0x0000002eu,0x0000017cu,0x00000177u,0x0000017bu,0x0003003eu,0x00000176u,0x0000017cu,0x0004003du,0x00000014u,0x0000017du,0x00000016u,0x0004003du,0x00000007u,0x0000017eu,0x00000009u,0x0004003du,0x0000002eu,0x0000017fu,0x00000176u,0x00050051u,0x00000013u,0x00000180u,0x0000017fu,0x00000000u,0x00050051u,0x00000013u,0x00000181u,0x0000017fu,0x00000001u,0x00070050u,0x00000052u,0x00000182u,0x00000180u,0x00000181u,0x00000051u,0x00000051u,0x00040063u,0x0000017du,0x0000017eu,0x00000182u,0x000100fdu,0x00010038u}; +static const size_t OF3_FLOW_LEN = 2253; +static const uint32_t OF3_EXPAND_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000124u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000049u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x0000000eu,0x3564656du,0x3b316628u,0x663b3166u,0x31663b31u,0x3b31663bu,0x00000000u,0x00030005u,0x00000009u,0x00000061u,0x00030005u,0x0000000au,0x00000062u,0x00030005u,0x0000000bu,0x00000063u,0x00030005u,0x0000000cu,0x00000064u,0x00030005u,0x0000000du,0x00000065u,0x00030005u,0x00000010u,0x00000078u,0x00030005u,0x00000034u,0x00000079u,0x00030005u,0x00000045u,0x00646967u,0x00080005u,0x00000049u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000004eu,0x006d6964u,0x00040005u,0x00000051u,0x64774675u,0x00000000u,0x00030005u,0x0000006bu,0x00007675u,0x00030005u,0x00000074u,0x00007366u,0x00050005u,0x00000079u,0x6f6c4675u,0x6e694677u,0x00000065u,0x00030005u,0x00000081u,0x00000063u,0x00030005u,0x00000088u,0x00006d78u,0x00030005u,0x00000091u,0x00007078u,0x00030005u,0x0000009au,0x00006d79u,0x00030005u,0x000000a3u,0x00007079u,0x00030005u,0x000000acu,0x00000064u,0x00040005u,0x000000adu,0x61726170u,0x0000006du,0x00040005u,0x000000b0u,0x61726170u,0x0000006du,0x00040005u,0x000000b3u,0x61726170u,0x0000006du,0x00040005u,0x000000b6u,0x61726170u,0x0000006du,0x00040005u,0x000000b9u,0x61726170u,0x0000006du,0x00040005u,0x000000bdu,0x61726170u,0x0000006du,0x00040005u,0x000000c0u,0x61726170u,0x0000006du,0x00040005u,0x000000c3u,0x61726170u,0x0000006du,0x00040005u,0x000000c6u,0x61726170u,0x0000006du,0x00040005u,0x000000c9u,0x61726170u,0x0000006du,0x00030005u,0x000000ceu,0x00000071u,0x00030005u,0x000000d2u,0x00787067u,0x00030005u,0x000000d3u,0x00004d47u,0x00050006u,0x000000d3u,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x000000d3u,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x000000d3u,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x000000d3u,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x000000d5u,0x00000000u,0x00030005u,0x000000fdu,0x00003241u,0x00040005u,0x0000010bu,0x6c6c7566u,0x00000000u,0x00040005u,0x00000117u,0x64774275u,0x00000000u,0x00030005u,0x00000121u,0x00000055u,0x00060006u,0x00000121u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000121u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000121u,0x00000002u,0x30646170u,0x00000000u,0x00050006u,0x00000121u,0x00000003u,0x31646170u,0x00000000u,0x00030005u,0x00000123u,0x00000000u,0x00040047u,0x00000049u,0x0000000bu,0x0000001cu,0x00030047u,0x00000051u,0x00000019u,0x00040047u,0x00000051u,0x00000021u,0x00000030u,0x00040047u,0x00000051u,0x00000022u,0x00000000u,0x00040047u,0x00000079u,0x00000021u,0x00000020u,0x00040047u,0x00000079u,0x00000022u,0x00000000u,0x00030047u,0x000000d3u,0x00000002u,0x00050048u,0x000000d3u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x000000d3u,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x000000d3u,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x000000d3u,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x000000d5u,0x00000021u,0x00000001u,0x00040047u,0x000000d5u,0x00000022u,0x00000000u,0x00030047u,0x00000117u,0x00000019u,0x00040047u,0x00000117u,0x00000021u,0x00000031u,0x00040047u,0x00000117u,0x00000022u,0x00000000u,0x00040047u,0x00000120u,0x0000000bu,0x00000019u,0x00030047u,0x00000121u,0x00000002u,0x00050048u,0x00000121u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000121u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000121u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000121u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000123u,0x00000021u,0x00000000u,0x00040047u,0x00000123u,0x00000022u,0x00000000u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00040020u,0x00000007u,0x00000007u,0x00000006u,0x00080021u,0x00000008u,0x00000006u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00040015u,0x00000042u,0x00000020u,0x00000001u,0x00040017u,0x00000043u,0x00000042u,0x00000002u,0x00040020u,0x00000044u,0x00000007u,0x00000043u,0x00040015u,0x00000046u,0x00000020u,0x00000000u,0x00040017u,0x00000047u,0x00000046u,0x00000003u,0x00040020u,0x00000048u,0x00000001u,0x00000047u,0x0004003bu,0x00000048u,0x00000049u,0x00000001u,0x00040017u,0x0000004au,0x00000046u,0x00000002u,0x00090019u,0x0000004fu,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000050u,0x00000000u,0x0000004fu,0x0004003bu,0x00000050u,0x00000051u,0x00000000u,0x00020014u,0x00000054u,0x0004002bu,0x00000046u,0x00000055u,0x00000000u,0x00040020u,0x00000056u,0x00000007u,0x00000042u,0x0004002bu,0x00000046u,0x0000005fu,0x00000001u,0x00040017u,0x00000069u,0x00000006u,0x00000002u,0x00040020u,0x0000006au,0x00000007u,0x00000069u,0x0004002bu,0x00000006u,0x0000006eu,0x3f000000u,0x0004002bu,0x00000006u,0x00000075u,0x3f800000u,0x00090019u,0x00000076u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000077u,0x00000076u,0x00040020u,0x00000078u,0x00000000u,0x00000077u,0x0004003bu,0x00000078u,0x00000079u,0x00000000u,0x0004002bu,0x00000042u,0x0000007bu,0x00000000u,0x0004002bu,0x00000006u,0x00000084u,0x00000000u,0x00040017u,0x00000085u,0x00000006u,0x00000004u,0x0006001eu,0x000000d3u,0x00000085u,0x00000085u,0x00000085u,0x00000085u,0x00040020u,0x000000d4u,0x00000002u,0x000000d3u,0x0004003bu,0x000000d4u,0x000000d5u,0x00000002u,0x0004002bu,0x00000042u,0x000000d6u,0x00000002u,0x00040020u,0x000000d7u,0x00000002u,0x00000006u,0x0004002bu,0x00000046u,0x000000ddu,0x00000002u,0x0004002bu,0x00000042u,0x000000e4u,0x00000003u,0x0004002bu,0x00000046u,0x000000edu,0x00000003u,0x00040018u,0x000000fbu,0x00000069u,0x00000002u,0x00040020u,0x000000fcu,0x00000007u,0x000000fbu,0x0004003bu,0x00000050u,0x00000117u,0x00000000u,0x0004002bu,0x00000046u,0x0000011fu,0x00000010u,0x0006002cu,0x00000047u,0x00000120u,0x0000011fu,0x0000011fu,0x0000005fu,0x0006001eu,0x00000121u,0x00000006u,0x00000046u,0x00000046u,0x00000046u,0x00040020u,0x00000122u,0x00000002u,0x00000121u,0x0004003bu,0x00000122u,0x00000123u,0x00000002u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000044u,0x00000045u,0x00000007u,0x0004003bu,0x00000044u,0x0000004eu,0x00000007u,0x0004003bu,0x0000006au,0x0000006bu,0x00000007u,0x0004003bu,0x0000006au,0x00000074u,0x00000007u,0x0004003bu,0x0000006au,0x00000081u,0x00000007u,0x0004003bu,0x0000006au,0x00000088u,0x00000007u,0x0004003bu,0x0000006au,0x00000091u,0x00000007u,0x0004003bu,0x0000006au,0x0000009au,0x00000007u,0x0004003bu,0x0000006au,0x000000a3u,0x00000007u,0x0004003bu,0x0000006au,0x000000acu,0x00000007u,0x0004003bu,0x00000007u,0x000000adu,0x00000007u,0x0004003bu,0x00000007u,0x000000b0u,0x00000007u,0x0004003bu,0x00000007u,0x000000b3u,0x00000007u,0x0004003bu,0x00000007u,0x000000b6u,0x00000007u,0x0004003bu,0x00000007u,0x000000b9u,0x00000007u,0x0004003bu,0x00000007u,0x000000bdu,0x00000007u,0x0004003bu,0x00000007u,0x000000c0u,0x00000007u,0x0004003bu,0x00000007u,0x000000c3u,0x00000007u,0x0004003bu,0x00000007u,0x000000c6u,0x00000007u,0x0004003bu,0x00000007u,0x000000c9u,0x00000007u,0x0004003bu,0x0000006au,0x000000ceu,0x00000007u,0x0004003bu,0x0000006au,0x000000d2u,0x00000007u,0x0004003bu,0x000000fcu,0x000000fdu,0x00000007u,0x0004003bu,0x0000006au,0x0000010bu,0x00000007u,0x0004003du,0x00000047u,0x0000004bu,0x00000049u,0x0007004fu,0x0000004au,0x0000004cu,0x0000004bu,0x0000004bu,0x00000000u,0x00000001u,0x0004007cu,0x00000043u,0x0000004du,0x0000004cu,0x0003003eu,0x00000045u,0x0000004du,0x0004003du,0x0000004fu,0x00000052u,0x00000051u,0x00040068u,0x00000043u,0x00000053u,0x00000052u,0x0003003eu,0x0000004eu,0x00000053u,0x00050041u,0x00000056u,0x00000057u,0x00000045u,0x00000055u,0x0004003du,0x00000042u,0x00000058u,0x00000057u,0x00050041u,0x00000056u,0x00000059u,0x0000004eu,0x00000055u,0x0004003du,0x00000042u,0x0000005au,0x00000059u,0x000500afu,0x00000054u,0x0000005bu,0x00000058u,0x0000005au,0x000400a8u,0x00000054u,0x0000005cu,0x0000005bu,0x000300f7u,0x0000005eu,0x00000000u,0x000400fau,0x0000005cu,0x0000005du,0x0000005eu,0x000200f8u,0x0000005du,0x00050041u,0x00000056u,0x00000060u,0x00000045u,0x0000005fu,0x0004003du,0x00000042u,0x00000061u,0x00000060u,0x00050041u,0x00000056u,0x00000062u,0x0000004eu,0x0000005fu,0x0004003du,0x00000042u,0x00000063u,0x00000062u,0x000500afu,0x00000054u,0x00000064u,0x00000061u,0x00000063u,0x000200f9u,0x0000005eu,0x000200f8u,0x0000005eu,0x000700f5u,0x00000054u,0x00000065u,0x0000005bu,0x00000005u,0x00000064u,0x0000005du,0x000300f7u,0x00000067u,0x00000000u,0x000400fau,0x00000065u,0x00000066u,0x00000067u,0x000200f8u,0x00000066u,0x000100fdu,0x000200f8u,0x00000067u,0x0004003du,0x00000043u,0x0000006cu,0x00000045u,0x0004006fu,0x00000069u,0x0000006du,0x0000006cu,0x00050050u,0x00000069u,0x0000006fu,0x0000006eu,0x0000006eu,0x00050081u,0x00000069u,0x00000070u,0x0000006du,0x0000006fu,0x0004003du,0x00000043u,0x00000071u,0x0000004eu,0x0004006fu,0x00000069u,0x00000072u,0x00000071u,0x00050088u,0x00000069u,0x00000073u,0x00000070u,0x00000072u,0x0003003eu,0x0000006bu,0x00000073u,0x0004003du,0x00000077u,0x0000007au,0x00000079u,0x00040064u,0x00000076u,0x0000007cu,0x0000007au,0x00050067u,0x00000043u,0x0000007du,0x0000007cu,0x0000007bu,0x0004006fu,0x00000069u,0x0000007eu,0x0000007du,0x00050050u,0x00000069u,0x0000007fu,0x00000075u,0x00000075u,0x00050088u,0x00000069u,0x00000080u,0x0000007fu,0x0000007eu,0x0003003eu,0x00000074u,0x00000080u,0x0004003du,0x00000077u,0x00000082u,0x00000079u,0x0004003du,0x00000069u,0x00000083u,0x0000006bu,0x00070058u,0x00000085u,0x00000086u,0x00000082u,0x00000083u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x00000087u,0x00000086u,0x00000086u,0x00000000u,0x00000001u,0x0003003eu,0x00000081u,0x00000087u,0x0004003du,0x00000077u,0x00000089u,0x00000079u,0x0004003du,0x00000069u,0x0000008au,0x0000006bu,0x00050041u,0x00000007u,0x0000008bu,0x00000074u,0x00000055u,0x0004003du,0x00000006u,0x0000008cu,0x0000008bu,0x00050050u,0x00000069u,0x0000008du,0x0000008cu,0x00000084u,0x00050083u,0x00000069u,0x0000008eu,0x0000008au,0x0000008du,0x00070058u,0x00000085u,0x0000008fu,0x00000089u,0x0000008eu,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x00000090u,0x0000008fu,0x0000008fu,0x00000000u,0x00000001u,0x0003003eu,0x00000088u,0x00000090u,0x0004003du,0x00000077u,0x00000092u,0x00000079u,0x0004003du,0x00000069u,0x00000093u,0x0000006bu,0x00050041u,0x00000007u,0x00000094u,0x00000074u,0x00000055u,0x0004003du,0x00000006u,0x00000095u,0x00000094u,0x00050050u,0x00000069u,0x00000096u,0x00000095u,0x00000084u,0x00050081u,0x00000069u,0x00000097u,0x00000093u,0x00000096u,0x00070058u,0x00000085u,0x00000098u,0x00000092u,0x00000097u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x00000099u,0x00000098u,0x00000098u,0x00000000u,0x00000001u,0x0003003eu,0x00000091u,0x00000099u,0x0004003du,0x00000077u,0x0000009bu,0x00000079u,0x0004003du,0x00000069u,0x0000009cu,0x0000006bu,0x00050041u,0x00000007u,0x0000009du,0x00000074u,0x0000005fu,0x0004003du,0x00000006u,0x0000009eu,0x0000009du,0x00050050u,0x00000069u,0x0000009fu,0x00000084u,0x0000009eu,0x00050083u,0x00000069u,0x000000a0u,0x0000009cu,0x0000009fu,0x00070058u,0x00000085u,0x000000a1u,0x0000009bu,0x000000a0u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x000000a2u,0x000000a1u,0x000000a1u,0x00000000u,0x00000001u,0x0003003eu,0x0000009au,0x000000a2u,0x0004003du,0x00000077u,0x000000a4u,0x00000079u,0x0004003du,0x00000069u,0x000000a5u,0x0000006bu,0x00050041u,0x00000007u,0x000000a6u,0x00000074u,0x0000005fu,0x0004003du,0x00000006u,0x000000a7u,0x000000a6u,0x00050050u,0x00000069u,0x000000a8u,0x00000084u,0x000000a7u,0x00050081u,0x00000069u,0x000000a9u,0x000000a5u,0x000000a8u,0x00070058u,0x00000085u,0x000000aau,0x000000a4u,0x000000a9u,0x00000002u,0x00000084u,0x0007004fu,0x00000069u,0x000000abu,0x000000aau,0x000000aau,0x00000000u,0x00000001u,0x0003003eu,0x000000a3u,0x000000abu,0x00050041u,0x00000007u,0x000000aeu,0x00000081u,0x00000055u,0x0004003du,0x00000006u,0x000000afu,0x000000aeu,0x0003003eu,0x000000adu,0x000000afu,0x00050041u,0x00000007u,0x000000b1u,0x00000088u,0x00000055u,0x0004003du,0x00000006u,0x000000b2u,0x000000b1u,0x0003003eu,0x000000b0u,0x000000b2u,0x00050041u,0x00000007u,0x000000b4u,0x00000091u,0x00000055u,0x0004003du,0x00000006u,0x000000b5u,0x000000b4u,0x0003003eu,0x000000b3u,0x000000b5u,0x00050041u,0x00000007u,0x000000b7u,0x0000009au,0x00000055u,0x0004003du,0x00000006u,0x000000b8u,0x000000b7u,0x0003003eu,0x000000b6u,0x000000b8u,0x00050041u,0x00000007u,0x000000bau,0x000000a3u,0x00000055u,0x0004003du,0x00000006u,0x000000bbu,0x000000bau,0x0003003eu,0x000000b9u,0x000000bbu,0x00090039u,0x00000006u,0x000000bcu,0x0000000eu,0x000000adu,0x000000b0u,0x000000b3u,0x000000b6u,0x000000b9u,0x00050041u,0x00000007u,0x000000beu,0x00000081u,0x0000005fu,0x0004003du,0x00000006u,0x000000bfu,0x000000beu,0x0003003eu,0x000000bdu,0x000000bfu,0x00050041u,0x00000007u,0x000000c1u,0x00000088u,0x0000005fu,0x0004003du,0x00000006u,0x000000c2u,0x000000c1u,0x0003003eu,0x000000c0u,0x000000c2u,0x00050041u,0x00000007u,0x000000c4u,0x00000091u,0x0000005fu,0x0004003du,0x00000006u,0x000000c5u,0x000000c4u,0x0003003eu,0x000000c3u,0x000000c5u,0x00050041u,0x00000007u,0x000000c7u,0x0000009au,0x0000005fu,0x0004003du,0x00000006u,0x000000c8u,0x000000c7u,0x0003003eu,0x000000c6u,0x000000c8u,0x00050041u,0x00000007u,0x000000cau,0x000000a3u,0x0000005fu,0x0004003du,0x00000006u,0x000000cbu,0x000000cau,0x0003003eu,0x000000c9u,0x000000cbu,0x00090039u,0x00000006u,0x000000ccu,0x0000000eu,0x000000bdu,0x000000c0u,0x000000c3u,0x000000c6u,0x000000c9u,0x00050050u,0x00000069u,0x000000cdu,0x000000bcu,0x000000ccu,0x0003003eu,0x000000acu,0x000000cdu,0x0004003du,0x00000069u,0x000000cfu,0x0000006bu,0x00050050u,0x00000069u,0x000000d0u,0x0000006eu,0x0000006eu,0x00050083u,0x00000069u,0x000000d1u,0x000000cfu,0x000000d0u,0x0003003eu,0x000000ceu,0x000000d1u,0x00060041u,0x000000d7u,0x000000d8u,0x000000d5u,0x000000d6u,0x00000055u,0x0004003du,0x00000006u,0x000000d9u,0x000000d8u,0x00050041u,0x00000007u,0x000000dau,0x000000ceu,0x00000055u,0x0004003du,0x00000006u,0x000000dbu,0x000000dau,0x00050085u,0x00000006u,0x000000dcu,0x000000d9u,0x000000dbu,0x00060041u,0x000000d7u,0x000000deu,0x000000d5u,0x000000d6u,0x000000ddu,0x0004003du,0x00000006u,0x000000dfu,0x000000deu,0x00050041u,0x00000007u,0x000000e0u,0x000000ceu,0x0000005fu,0x0004003du,0x00000006u,0x000000e1u,0x000000e0u,0x00050085u,0x00000006u,0x000000e2u,0x000000dfu,0x000000e1u,0x00050081u,0x00000006u,0x000000e3u,0x000000dcu,0x000000e2u,0x00060041u,0x000000d7u,0x000000e5u,0x000000d5u,0x000000e4u,0x00000055u,0x0004003du,0x00000006u,0x000000e6u,0x000000e5u,0x00050081u,0x00000006u,0x000000e7u,0x000000e3u,0x000000e6u,0x00060041u,0x000000d7u,0x000000e8u,0x000000d5u,0x000000d6u,0x0000005fu,0x0004003du,0x00000006u,0x000000e9u,0x000000e8u,0x00050041u,0x00000007u,0x000000eau,0x000000ceu,0x00000055u,0x0004003du,0x00000006u,0x000000ebu,0x000000eau,0x00050085u,0x00000006u,0x000000ecu,0x000000e9u,0x000000ebu,0x00060041u,0x000000d7u,0x000000eeu,0x000000d5u,0x000000d6u,0x000000edu,0x0004003du,0x00000006u,0x000000efu,0x000000eeu,0x00050041u,0x00000007u,0x000000f0u,0x000000ceu,0x0000005fu,0x0004003du,0x00000006u,0x000000f1u,0x000000f0u,0x00050085u,0x00000006u,0x000000f2u,0x000000efu,0x000000f1u,0x00050081u,0x00000006u,0x000000f3u,0x000000ecu,0x000000f2u,0x00060041u,0x000000d7u,0x000000f4u,0x000000d5u,0x000000e4u,0x0000005fu,0x0004003du,0x00000006u,0x000000f5u,0x000000f4u,0x00050081u,0x00000006u,0x000000f6u,0x000000f3u,0x000000f5u,0x00050050u,0x00000069u,0x000000f7u,0x000000e7u,0x000000f6u,0x0004003du,0x00000043u,0x000000f8u,0x0000004eu,0x0004006fu,0x00000069u,0x000000f9u,0x000000f8u,0x00050085u,0x00000069u,0x000000fau,0x000000f7u,0x000000f9u,0x0003003eu,0x000000d2u,0x000000fau,0x00060041u,0x000000d7u,0x000000feu,0x000000d5u,0x000000d6u,0x00000055u,0x0004003du,0x00000006u,0x000000ffu,0x000000feu,0x00050081u,0x00000006u,0x00000100u,0x00000075u,0x000000ffu,0x00060041u,0x000000d7u,0x00000101u,0x000000d5u,0x000000d6u,0x0000005fu,0x0004003du,0x00000006u,0x00000102u,0x00000101u,0x00060041u,0x000000d7u,0x00000103u,0x000000d5u,0x000000d6u,0x000000ddu,0x0004003du,0x00000006u,0x00000104u,0x00000103u,0x00060041u,0x000000d7u,0x00000105u,0x000000d5u,0x000000d6u,0x000000edu,0x0004003du,0x00000006u,0x00000106u,0x00000105u,0x00050081u,0x00000006u,0x00000107u,0x00000075u,0x00000106u,0x00050050u,0x00000069u,0x00000108u,0x00000100u,0x00000102u,0x00050050u,0x00000069u,0x00000109u,0x00000104u,0x00000107u,0x00050050u,0x000000fbu,0x0000010au,0x00000108u,0x00000109u,0x0003003eu,0x000000fdu,0x0000010au,0x0004003du,0x00000069u,0x0000010cu,0x000000d2u,0x0004003du,0x000000fbu,0x0000010du,0x000000fdu,0x0004003du,0x00000069u,0x0000010eu,0x000000acu,0x00050091u,0x00000069u,0x0000010fu,0x0000010du,0x0000010eu,0x00050081u,0x00000069u,0x00000110u,0x0000010cu,0x0000010fu,0x0003003eu,0x0000010bu,0x00000110u,0x0004003du,0x0000004fu,0x00000111u,0x00000051u,0x0004003du,0x00000043u,0x00000112u,0x00000045u,0x0004003du,0x00000069u,0x00000113u,0x0000010bu,0x00050051u,0x00000006u,0x00000114u,0x00000113u,0x00000000u,0x00050051u,0x00000006u,0x00000115u,0x00000113u,0x00000001u,0x00070050u,0x00000085u,0x00000116u,0x00000114u,0x00000115u,0x00000084u,0x00000075u,0x00040063u,0x00000111u,0x00000112u,0x00000116u,0x0004003du,0x0000004fu,0x00000118u,0x00000117u,0x0004003du,0x00000043u,0x00000119u,0x00000045u,0x0004003du,0x00000069u,0x0000011au,0x0000010bu,0x0004007fu,0x00000069u,0x0000011bu,0x0000011au,0x00050051u,0x00000006u,0x0000011cu,0x0000011bu,0x00000000u,0x00050051u,0x00000006u,0x0000011du,0x0000011bu,0x00000001u,0x00070050u,0x00000085u,0x0000011eu,0x0000011cu,0x0000011du,0x00000084u,0x00000075u,0x00040063u,0x00000118u,0x00000119u,0x0000011eu,0x000100fdu,0x00010038u,0x00050036u,0x00000006u,0x0000000eu,0x00000000u,0x00000008u,0x00030037u,0x00000007u,0x00000009u,0x00030037u,0x00000007u,0x0000000au,0x00030037u,0x00000007u,0x0000000bu,0x00030037u,0x00000007u,0x0000000cu,0x00030037u,0x00000007u,0x0000000du,0x000200f8u,0x0000000fu,0x0004003bu,0x00000007u,0x00000010u,0x00000007u,0x0004003bu,0x00000007u,0x00000034u,0x00000007u,0x0004003du,0x00000006u,0x00000011u,0x00000009u,0x0004003du,0x00000006u,0x00000012u,0x0000000au,0x0007000cu,0x00000006u,0x00000013u,0x00000001u,0x00000025u,0x00000011u,0x00000012u,0x0003003eu,0x00000010u,0x00000013u,0x0004003du,0x00000006u,0x00000014u,0x00000009u,0x0004003du,0x00000006u,0x00000015u,0x0000000au,0x0007000cu,0x00000006u,0x00000016u,0x00000001u,0x00000028u,0x00000014u,0x00000015u,0x0003003eu,0x00000009u,0x00000016u,0x0004003du,0x00000006u,0x00000017u,0x00000010u,0x0003003eu,0x0000000au,0x00000017u,0x0004003du,0x00000006u,0x00000018u,0x0000000bu,0x0004003du,0x00000006u,0x00000019u,0x0000000cu,0x0007000cu,0x00000006u,0x0000001au,0x00000001u,0x00000025u,0x00000018u,0x00000019u,0x0003003eu,0x00000010u,0x0000001au,0x0004003du,0x00000006u,0x0000001bu,0x0000000bu,0x0004003du,0x00000006u,0x0000001cu,0x0000000cu,0x0007000cu,0x00000006u,0x0000001du,0x00000001u,0x00000028u,0x0000001bu,0x0000001cu,0x0003003eu,0x0000000bu,0x0000001du,0x0004003du,0x00000006u,0x0000001eu,0x00000010u,0x0003003eu,0x0000000cu,0x0000001eu,0x0004003du,0x00000006u,0x0000001fu,0x00000009u,0x0004003du,0x00000006u,0x00000020u,0x0000000bu,0x0007000cu,0x00000006u,0x00000021u,0x00000001u,0x00000025u,0x0000001fu,0x00000020u,0x0003003eu,0x00000010u,0x00000021u,0x0004003du,0x00000006u,0x00000022u,0x00000009u,0x0004003du,0x00000006u,0x00000023u,0x0000000bu,0x0007000cu,0x00000006u,0x00000024u,0x00000001u,0x00000028u,0x00000022u,0x00000023u,0x0003003eu,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000025u,0x00000010u,0x0003003eu,0x0000000bu,0x00000025u,0x0004003du,0x00000006u,0x00000026u,0x0000000au,0x0004003du,0x00000006u,0x00000027u,0x0000000cu,0x0007000cu,0x00000006u,0x00000028u,0x00000001u,0x00000025u,0x00000026u,0x00000027u,0x0003003eu,0x00000010u,0x00000028u,0x0004003du,0x00000006u,0x00000029u,0x0000000au,0x0004003du,0x00000006u,0x0000002au,0x0000000cu,0x0007000cu,0x00000006u,0x0000002bu,0x00000001u,0x00000028u,0x00000029u,0x0000002au,0x0003003eu,0x0000000au,0x0000002bu,0x0004003du,0x00000006u,0x0000002cu,0x00000010u,0x0003003eu,0x0000000cu,0x0000002cu,0x0004003du,0x00000006u,0x0000002du,0x0000000au,0x0004003du,0x00000006u,0x0000002eu,0x0000000bu,0x0007000cu,0x00000006u,0x0000002fu,0x00000001u,0x00000025u,0x0000002du,0x0000002eu,0x0003003eu,0x00000010u,0x0000002fu,0x0004003du,0x00000006u,0x00000030u,0x0000000au,0x0004003du,0x00000006u,0x00000031u,0x0000000bu,0x0007000cu,0x00000006u,0x00000032u,0x00000001u,0x00000028u,0x00000030u,0x00000031u,0x0003003eu,0x0000000au,0x00000032u,0x0004003du,0x00000006u,0x00000033u,0x00000010u,0x0003003eu,0x0000000bu,0x00000033u,0x0004003du,0x00000006u,0x00000035u,0x0000000au,0x0004003du,0x00000006u,0x00000036u,0x0000000du,0x0007000cu,0x00000006u,0x00000037u,0x00000001u,0x00000025u,0x00000035u,0x00000036u,0x0003003eu,0x00000034u,0x00000037u,0x0004003du,0x00000006u,0x00000038u,0x0000000au,0x0004003du,0x00000006u,0x00000039u,0x0000000du,0x0007000cu,0x00000006u,0x0000003au,0x00000001u,0x00000028u,0x00000038u,0x00000039u,0x0003003eu,0x00000010u,0x0000003au,0x0004003du,0x00000006u,0x0000003bu,0x00000034u,0x0004003du,0x00000006u,0x0000003cu,0x0000000bu,0x0007000cu,0x00000006u,0x0000003du,0x00000001u,0x00000028u,0x0000003bu,0x0000003cu,0x0004003du,0x00000006u,0x0000003eu,0x00000010u,0x0007000cu,0x00000006u,0x0000003fu,0x00000001u,0x00000025u,0x0000003du,0x0000003eu,0x000200feu,0x0000003fu,0x00010038u}; +static const size_t OF3_EXPAND_LEN = 1798; +static const uint32_t OF3_FLOW_M4_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000151u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x000000f6u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x00000010u,0x636f6c62u,0x6461536bu,0x31327328u,0x3132733bu,0x3266763bu,0x0000003bu,0x00030005u,0x0000000du,0x00000061u,0x00030005u,0x0000000eu,0x00000062u,0x00040005u,0x0000000fu,0x646e6163u,0x00000000u,0x00070005u,0x00000016u,0x766c6f73u,0x32732865u,0x32733b31u,0x66763b31u,0x00003b32u,0x00030005u,0x00000013u,0x00000061u,0x00030005u,0x00000014u,0x00000062u,0x00040005u,0x00000015u,0x64657270u,0x00000000u,0x00030005u,0x00000019u,0x00646173u,0x00030005u,0x0000001du,0x00007962u,0x00030005u,0x00000028u,0x00007862u,0x00030005u,0x00000030u,0x00006f62u,0x00030005u,0x00000036u,0x00006170u,0x00030005u,0x00000039u,0x00765567u,0x00050005u,0x0000003cu,0x766e4967u,0x616d754cu,0x00000000u,0x00030005u,0x00000045u,0x00006270u,0x00040005u,0x0000005du,0x74736562u,0x00646153u,0x00050005u,0x0000005fu,0x74736562u,0x70736944u,0x00000000u,0x00030005u,0x00000061u,0x00007973u,0x00030005u,0x0000006bu,0x00007873u,0x00040005u,0x00000073u,0x646e6163u,0x00000000u,0x00030005u,0x0000007bu,0x00646173u,0x00040005u,0x0000007cu,0x61726170u,0x0000006du,0x00030005u,0x00000095u,0x00000055u,0x00060006u,0x00000095u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000095u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000095u,0x00000002u,0x6c63636fu,0x00006f4cu,0x00050006u,0x00000095u,0x00000003u,0x6c63636fu,0x00006948u,0x00030005u,0x00000097u,0x00000000u,0x00040005u,0x0000009eu,0x43646173u,0x00000000u,0x00040005u,0x000000a1u,0x58646173u,0x0000006du,0x00040005u,0x000000a6u,0x61726170u,0x0000006du,0x00040005u,0x000000a9u,0x58646173u,0x00000070u,0x00040005u,0x000000aeu,0x61726170u,0x0000006du,0x00040005u,0x000000b1u,0x59646173u,0x0000006du,0x00040005u,0x000000b5u,0x61726170u,0x0000006du,0x00040005u,0x000000b8u,0x59646173u,0x00000070u,0x00040005u,0x000000bcu,0x61726170u,0x0000006du,0x00030005u,0x000000bfu,0x00007864u,0x00030005u,0x000000c0u,0x00007964u,0x00040005u,0x000000c1u,0x6f6e6564u,0x0000586du,0x00040005u,0x000000c9u,0x6f6e6564u,0x0000596du,0x00030005u,0x000000f3u,0x00646967u,0x00080005u,0x000000f6u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x000000fbu,0x006d6964u,0x00040005u,0x000000feu,0x6f6c4675u,0x00000077u,0x00050005u,0x0000011au,0x6d754c75u,0x72754361u,0x00000072u,0x00040005u,0x00000122u,0x654c6f74u,0x006c6576u,0x00040005u,0x00000129u,0x64657270u,0x00000000u,0x00050005u,0x0000012au,0x65725075u,0x74636964u,0x0000726fu,0x00030005u,0x0000012eu,0x00647766u,0x00050005u,0x0000012fu,0x6d754c75u,0x65725061u,0x00000076u,0x00040005u,0x00000134u,0x61726170u,0x0000006du,0x00030005u,0x00000136u,0x00647762u,0x00040005u,0x0000013bu,0x61726170u,0x0000006du,0x00040005u,0x0000013du,0x75466f74u,0x00006c6cu,0x00030047u,0x00000095u,0x00000002u,0x00050048u,0x00000095u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000095u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000095u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000095u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000097u,0x00000021u,0x00000000u,0x00040047u,0x00000097u,0x00000022u,0x00000000u,0x00040047u,0x000000f6u,0x0000000bu,0x0000001cu,0x00030047u,0x000000feu,0x00000019u,0x00040047u,0x000000feu,0x00000021u,0x00000030u,0x00040047u,0x000000feu,0x00000022u,0x00000000u,0x00040047u,0x0000011au,0x00000021u,0x00000021u,0x00040047u,0x0000011au,0x00000022u,0x00000000u,0x00040047u,0x0000012au,0x00000021u,0x00000022u,0x00040047u,0x0000012au,0x00000022u,0x00000000u,0x00040047u,0x0000012fu,0x00000021u,0x00000020u,0x00040047u,0x0000012fu,0x00000022u,0x00000000u,0x00040047u,0x00000150u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00090019u,0x00000007u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000008u,0x00000007u,0x00040020u,0x00000009u,0x00000000u,0x00000008u,0x00040017u,0x0000000au,0x00000006u,0x00000002u,0x00040020u,0x0000000bu,0x00000007u,0x0000000au,0x00060021u,0x0000000cu,0x00000006u,0x00000009u,0x00000009u,0x0000000bu,0x00060021u,0x00000012u,0x0000000au,0x00000009u,0x00000009u,0x0000000bu,0x00040020u,0x00000018u,0x00000007u,0x00000006u,0x0004002bu,0x00000006u,0x0000001au,0x00000000u,0x00040015u,0x0000001bu,0x00000020u,0x00000001u,0x00040020u,0x0000001cu,0x00000007u,0x0000001bu,0x0004002bu,0x0000001bu,0x0000001eu,0xffffffffu,0x0004002bu,0x0000001bu,0x00000025u,0x00000001u,0x00020014u,0x00000026u,0x00040020u,0x00000038u,0x00000006u,0x0000000au,0x0004003bu,0x00000038u,0x00000039u,0x00000006u,0x0004003bu,0x00000038u,0x0000003cu,0x00000006u,0x00040017u,0x00000040u,0x00000006u,0x00000004u,0x00040015u,0x00000042u,0x00000020u,0x00000000u,0x0004002bu,0x00000042u,0x00000043u,0x00000000u,0x0004002bu,0x00000006u,0x0000005eu,0x7f7fffffu,0x0004002bu,0x0000001bu,0x00000062u,0xfffffffdu,0x0004002bu,0x0000001bu,0x00000069u,0x00000003u,0x0004002bu,0x00000006u,0x0000007fu,0x3b03126fu,0x0006001eu,0x00000095u,0x00000006u,0x00000042u,0x00000006u,0x00000006u,0x00040020u,0x00000096u,0x00000002u,0x00000095u,0x0004003bu,0x00000096u,0x00000097u,0x00000002u,0x00040020u,0x00000098u,0x00000002u,0x00000042u,0x0004002bu,0x00000006u,0x000000a3u,0xbf800000u,0x0005002cu,0x0000000au,0x000000a4u,0x000000a3u,0x0000001au,0x0004002bu,0x00000006u,0x000000abu,0x3f800000u,0x0005002cu,0x0000000au,0x000000acu,0x000000abu,0x0000001au,0x0005002cu,0x0000000au,0x000000b3u,0x0000001au,0x000000a3u,0x0005002cu,0x0000000au,0x000000bau,0x0000001au,0x000000abu,0x0004002bu,0x00000006u,0x000000c3u,0x40000000u,0x0004002bu,0x00000006u,0x000000d1u,0x358637bdu,0x0004002bu,0x00000006u,0x000000d5u,0x3f000000u,0x0004002bu,0x00000006u,0x000000dcu,0xbf000000u,0x00040017u,0x000000f1u,0x0000001bu,0x00000002u,0x00040020u,0x000000f2u,0x00000007u,0x000000f1u,0x00040017u,0x000000f4u,0x00000042u,0x00000003u,0x00040020u,0x000000f5u,0x00000001u,0x000000f4u,0x0004003bu,0x000000f5u,0x000000f6u,0x00000001u,0x00040017u,0x000000f7u,0x00000042u,0x00000002u,0x00090019u,0x000000fcu,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x000000fdu,0x00000000u,0x000000fcu,0x0004003bu,0x000000fdu,0x000000feu,0x00000000u,0x0004002bu,0x00000042u,0x00000109u,0x00000001u,0x0004003bu,0x00000009u,0x0000011au,0x00000000u,0x0004002bu,0x0000001bu,0x0000011cu,0x00000000u,0x00040020u,0x00000128u,0x00000007u,0x00000040u,0x0004003bu,0x00000009u,0x0000012au,0x00000000u,0x0004003bu,0x00000009u,0x0000012fu,0x00000000u,0x0004002bu,0x00000042u,0x0000014fu,0x00000010u,0x0006002cu,0x000000f4u,0x00000150u,0x0000014fu,0x0000014fu,0x00000109u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x000000f2u,0x000000f3u,0x00000007u,0x0004003bu,0x000000f2u,0x000000fbu,0x00000007u,0x0004003bu,0x00000018u,0x00000122u,0x00000007u,0x0004003bu,0x00000128u,0x00000129u,0x00000007u,0x0004003bu,0x0000000bu,0x0000012eu,0x00000007u,0x0004003bu,0x0000000bu,0x00000134u,0x00000007u,0x0004003bu,0x0000000bu,0x00000136u,0x00000007u,0x0004003bu,0x0000000bu,0x0000013bu,0x00000007u,0x0004003bu,0x00000018u,0x0000013du,0x00000007u,0x0004003du,0x000000f4u,0x000000f8u,0x000000f6u,0x0007004fu,0x000000f7u,0x000000f9u,0x000000f8u,0x000000f8u,0x00000000u,0x00000001u,0x0004007cu,0x000000f1u,0x000000fau,0x000000f9u,0x0003003eu,0x000000f3u,0x000000fau,0x0004003du,0x000000fcu,0x000000ffu,0x000000feu,0x00040068u,0x000000f1u,0x00000100u,0x000000ffu,0x0003003eu,0x000000fbu,0x00000100u,0x00050041u,0x0000001cu,0x00000101u,0x000000f3u,0x00000043u,0x0004003du,0x0000001bu,0x00000102u,0x00000101u,0x00050041u,0x0000001cu,0x00000103u,0x000000fbu,0x00000043u,0x0004003du,0x0000001bu,0x00000104u,0x00000103u,0x000500afu,0x00000026u,0x00000105u,0x00000102u,0x00000104u,0x000400a8u,0x00000026u,0x00000106u,0x00000105u,0x000300f7u,0x00000108u,0x00000000u,0x000400fau,0x00000106u,0x00000107u,0x00000108u,0x000200f8u,0x00000107u,0x00050041u,0x0000001cu,0x0000010au,0x000000f3u,0x00000109u,0x0004003du,0x0000001bu,0x0000010bu,0x0000010au,0x00050041u,0x0000001cu,0x0000010cu,0x000000fbu,0x00000109u,0x0004003du,0x0000001bu,0x0000010du,0x0000010cu,0x000500afu,0x00000026u,0x0000010eu,0x0000010bu,0x0000010du,0x000200f9u,0x00000108u,0x000200f8u,0x00000108u,0x000700f5u,0x00000026u,0x0000010fu,0x00000105u,0x00000005u,0x0000010eu,0x00000107u,0x000300f7u,0x00000111u,0x00000000u,0x000400fau,0x0000010fu,0x00000110u,0x00000111u,0x000200f8u,0x00000110u,0x000100fdu,0x000200f8u,0x00000111u,0x0004003du,0x000000f1u,0x00000113u,0x000000f3u,0x0004006fu,0x0000000au,0x00000114u,0x00000113u,0x00050050u,0x0000000au,0x00000115u,0x000000d5u,0x000000d5u,0x00050081u,0x0000000au,0x00000116u,0x00000114u,0x00000115u,0x0004003du,0x000000f1u,0x00000117u,0x000000fbu,0x0004006fu,0x0000000au,0x00000118u,0x00000117u,0x00050088u,0x0000000au,0x00000119u,0x00000116u,0x00000118u,0x0003003eu,0x00000039u,0x00000119u,0x0004003du,0x00000008u,0x0000011bu,0x0000011au,0x00040064u,0x00000007u,0x0000011du,0x0000011bu,0x00050067u,0x000000f1u,0x0000011eu,0x0000011du,0x0000011cu,0x0004006fu,0x0000000au,0x0000011fu,0x0000011eu,0x00050050u,0x0000000au,0x00000120u,0x000000abu,0x000000abu,0x00050088u,0x0000000au,0x00000121u,0x00000120u,0x0000011fu,0x0003003eu,0x0000003cu,0x00000121u,0x00050041u,0x00000098u,0x00000123u,0x00000097u,0x00000025u,0x0004003du,0x00000042u,0x00000124u,0x00000123u,0x00040070u,0x00000006u,0x00000125u,0x00000124u,0x0004007fu,0x00000006u,0x00000126u,0x00000125u,0x0006000cu,0x00000006u,0x00000127u,0x00000001u,0x0000001du,0x00000126u,0x0003003eu,0x00000122u,0x00000127u,0x0004003du,0x00000008u,0x0000012bu,0x0000012au,0x0004003du,0x0000000au,0x0000012cu,0x00000039u,0x00070058u,0x00000040u,0x0000012du,0x0000012bu,0x0000012cu,0x00000002u,0x0000001au,0x0003003eu,0x00000129u,0x0000012du,0x0004003du,0x00000040u,0x00000130u,0x00000129u,0x0007004fu,0x0000000au,0x00000131u,0x00000130u,0x00000130u,0x00000000u,0x00000001u,0x0004003du,0x00000006u,0x00000132u,0x00000122u,0x0005008eu,0x0000000au,0x00000133u,0x00000131u,0x00000132u,0x0003003eu,0x00000134u,0x00000133u,0x00070039u,0x0000000au,0x00000135u,0x00000016u,0x0000012fu,0x0000011au,0x00000134u,0x0003003eu,0x0000012eu,0x00000135u,0x0004003du,0x00000040u,0x00000137u,0x00000129u,0x0007004fu,0x0000000au,0x00000138u,0x00000137u,0x00000137u,0x00000002u,0x00000003u,0x0004003du,0x00000006u,0x00000139u,0x00000122u,0x0005008eu,0x0000000au,0x0000013au,0x00000138u,0x00000139u,0x0003003eu,0x0000013bu,0x0000013au,0x00070039u,0x0000000au,0x0000013cu,0x00000016u,0x0000011au,0x0000012fu,0x0000013bu,0x0003003eu,0x00000136u,0x0000013cu,0x00050041u,0x00000098u,0x0000013eu,0x00000097u,0x00000025u,0x0004003du,0x00000042u,0x0000013fu,0x0000013eu,0x00040070u,0x00000006u,0x00000140u,0x0000013fu,0x0006000cu,0x00000006u,0x00000141u,0x00000001u,0x0000001du,0x00000140u,0x0003003eu,0x0000013du,0x00000141u,0x0004003du,0x000000fcu,0x00000142u,0x000000feu,0x0004003du,0x000000f1u,0x00000143u,0x000000f3u,0x0004003du,0x0000000au,0x00000144u,0x0000012eu,0x0004003du,0x00000006u,0x00000145u,0x0000013du,0x0005008eu,0x0000000au,0x00000146u,0x00000144u,0x00000145u,0x0004003du,0x0000000au,0x00000147u,0x00000136u,0x0004003du,0x00000006u,0x00000148u,0x0000013du,0x0005008eu,0x0000000au,0x00000149u,0x00000147u,0x00000148u,0x00050051u,0x00000006u,0x0000014au,0x00000146u,0x00000000u,0x00050051u,0x00000006u,0x0000014bu,0x00000146u,0x00000001u,0x00050051u,0x00000006u,0x0000014cu,0x00000149u,0x00000000u,0x00050051u,0x00000006u,0x0000014du,0x00000149u,0x00000001u,0x00070050u,0x00000040u,0x0000014eu,0x0000014au,0x0000014bu,0x0000014cu,0x0000014du,0x00040063u,0x00000142u,0x00000143u,0x0000014eu,0x000100fdu,0x00010038u,0x00050036u,0x00000006u,0x00000010u,0x00000000u,0x0000000cu,0x00030037u,0x00000009u,0x0000000du,0x00030037u,0x00000009u,0x0000000eu,0x00030037u,0x0000000bu,0x0000000fu,0x000200f8u,0x00000011u,0x0004003bu,0x00000018u,0x00000019u,0x00000007u,0x0004003bu,0x0000001cu,0x0000001du,0x00000007u,0x0004003bu,0x0000001cu,0x00000028u,0x00000007u,0x0004003bu,0x0000000bu,0x00000030u,0x00000007u,0x0004003bu,0x00000018u,0x00000036u,0x00000007u,0x0004003bu,0x00000018u,0x00000045u,0x00000007u,0x0003003eu,0x00000019u,0x0000001au,0x0003003eu,0x0000001du,0x0000001eu,0x000200f9u,0x0000001fu,0x000200f8u,0x0000001fu,0x000400f6u,0x00000021u,0x00000022u,0x00000000u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x0004003du,0x0000001bu,0x00000024u,0x0000001du,0x000500b3u,0x00000026u,0x00000027u,0x00000024u,0x00000025u,0x000400fau,0x00000027u,0x00000020u,0x00000021u,0x000200f8u,0x00000020u,0x0003003eu,0x00000028u,0x0000001eu,0x000200f9u,0x00000029u,0x000200f8u,0x00000029u,0x000400f6u,0x0000002bu,0x0000002cu,0x00000000u,0x000200f9u,0x0000002du,0x000200f8u,0x0000002du,0x0004003du,0x0000001bu,0x0000002eu,0x00000028u,0x000500b3u,0x00000026u,0x0000002fu,0x0000002eu,0x00000025u,0x000400fau,0x0000002fu,0x0000002au,0x0000002bu,0x000200f8u,0x0000002au,0x0004003du,0x0000001bu,0x00000031u,0x00000028u,0x0004006fu,0x00000006u,0x00000032u,0x00000031u,0x0004003du,0x0000001bu,0x00000033u,0x0000001du,0x0004006fu,0x00000006u,0x00000034u,0x00000033u,0x00050050u,0x0000000au,0x00000035u,0x00000032u,0x00000034u,0x0003003eu,0x00000030u,0x00000035u,0x0004003du,0x00000008u,0x00000037u,0x0000000du,0x0004003du,0x0000000au,0x0000003au,0x00000039u,0x0004003du,0x0000000au,0x0000003bu,0x00000030u,0x0004003du,0x0000000au,0x0000003du,0x0000003cu,0x00050085u,0x0000000au,0x0000003eu,0x0000003bu,0x0000003du,0x00050081u,0x0000000au,0x0000003fu,0x0000003au,0x0000003eu,0x00070058u,0x00000040u,0x00000041u,0x00000037u,0x0000003fu,0x00000002u,0x0000001au,0x00050051u,0x00000006u,0x00000044u,0x00000041u,0x00000000u,0x0003003eu,0x00000036u,0x00000044u,0x0004003du,0x00000008u,0x00000046u,0x0000000eu,0x0004003du,0x0000000au,0x00000047u,0x00000039u,0x0004003du,0x0000000au,0x00000048u,0x00000030u,0x0004003du,0x0000000au,0x00000049u,0x0000000fu,0x00050081u,0x0000000au,0x0000004au,0x00000048u,0x00000049u,0x0004003du,0x0000000au,0x0000004bu,0x0000003cu,0x00050085u,0x0000000au,0x0000004cu,0x0000004au,0x0000004bu,0x00050081u,0x0000000au,0x0000004du,0x00000047u,0x0000004cu,0x00070058u,0x00000040u,0x0000004eu,0x00000046u,0x0000004du,0x00000002u,0x0000001au,0x00050051u,0x00000006u,0x0000004fu,0x0000004eu,0x00000000u,0x0003003eu,0x00000045u,0x0000004fu,0x0004003du,0x00000006u,0x00000050u,0x00000036u,0x0004003du,0x00000006u,0x00000051u,0x00000045u,0x00050083u,0x00000006u,0x00000052u,0x00000050u,0x00000051u,0x0006000cu,0x00000006u,0x00000053u,0x00000001u,0x00000004u,0x00000052u,0x0004003du,0x00000006u,0x00000054u,0x00000019u,0x00050081u,0x00000006u,0x00000055u,0x00000054u,0x00000053u,0x0003003eu,0x00000019u,0x00000055u,0x000200f9u,0x0000002cu,0x000200f8u,0x0000002cu,0x0004003du,0x0000001bu,0x00000056u,0x00000028u,0x00050080u,0x0000001bu,0x00000057u,0x00000056u,0x00000025u,0x0003003eu,0x00000028u,0x00000057u,0x000200f9u,0x00000029u,0x000200f8u,0x0000002bu,0x000200f9u,0x00000022u,0x000200f8u,0x00000022u,0x0004003du,0x0000001bu,0x00000058u,0x0000001du,0x00050080u,0x0000001bu,0x00000059u,0x00000058u,0x00000025u,0x0003003eu,0x0000001du,0x00000059u,0x000200f9u,0x0000001fu,0x000200f8u,0x00000021u,0x0004003du,0x00000006u,0x0000005au,0x00000019u,0x000200feu,0x0000005au,0x00010038u,0x00050036u,0x0000000au,0x00000016u,0x00000000u,0x00000012u,0x00030037u,0x00000009u,0x00000013u,0x00030037u,0x00000009u,0x00000014u,0x00030037u,0x0000000bu,0x00000015u,0x000200f8u,0x00000017u,0x0004003bu,0x00000018u,0x0000005du,0x00000007u,0x0004003bu,0x0000000bu,0x0000005fu,0x00000007u,0x0004003bu,0x0000001cu,0x00000061u,0x00000007u,0x0004003bu,0x0000001cu,0x0000006bu,0x00000007u,0x0004003bu,0x0000000bu,0x00000073u,0x00000007u,0x0004003bu,0x00000018u,0x0000007bu,0x00000007u,0x0004003bu,0x0000000bu,0x0000007cu,0x00000007u,0x0004003bu,0x00000018u,0x0000009eu,0x00000007u,0x0004003bu,0x00000018u,0x000000a1u,0x00000007u,0x0004003bu,0x0000000bu,0x000000a6u,0x00000007u,0x0004003bu,0x00000018u,0x000000a9u,0x00000007u,0x0004003bu,0x0000000bu,0x000000aeu,0x00000007u,0x0004003bu,0x00000018u,0x000000b1u,0x00000007u,0x0004003bu,0x0000000bu,0x000000b5u,0x00000007u,0x0004003bu,0x00000018u,0x000000b8u,0x00000007u,0x0004003bu,0x0000000bu,0x000000bcu,0x00000007u,0x0004003bu,0x00000018u,0x000000bfu,0x00000007u,0x0004003bu,0x00000018u,0x000000c0u,0x00000007u,0x0004003bu,0x00000018u,0x000000c1u,0x00000007u,0x0004003bu,0x00000018u,0x000000c9u,0x00000007u,0x0003003eu,0x0000005du,0x0000005eu,0x0004003du,0x0000000au,0x00000060u,0x00000015u,0x0003003eu,0x0000005fu,0x00000060u,0x0003003eu,0x00000061u,0x00000062u,0x000200f9u,0x00000063u,0x000200f8u,0x00000063u,0x000400f6u,0x00000065u,0x00000066u,0x00000000u,0x000200f9u,0x00000067u,0x000200f8u,0x00000067u,0x0004003du,0x0000001bu,0x00000068u,0x00000061u,0x000500b3u,0x00000026u,0x0000006au,0x00000068u,0x00000069u,0x000400fau,0x0000006au,0x00000064u,0x00000065u,0x000200f8u,0x00000064u,0x0003003eu,0x0000006bu,0x00000062u,0x000200f9u,0x0000006cu,0x000200f8u,0x0000006cu,0x000400f6u,0x0000006eu,0x0000006fu,0x00000000u,0x000200f9u,0x00000070u,0x000200f8u,0x00000070u,0x0004003du,0x0000001bu,0x00000071u,0x0000006bu,0x000500b3u,0x00000026u,0x00000072u,0x00000071u,0x00000069u,0x000400fau,0x00000072u,0x0000006du,0x0000006eu,0x000200f8u,0x0000006du,0x0004003du,0x0000000au,0x00000074u,0x00000015u,0x0004003du,0x0000001bu,0x00000075u,0x0000006bu,0x0004006fu,0x00000006u,0x00000076u,0x00000075u,0x0004003du,0x0000001bu,0x00000077u,0x00000061u,0x0004006fu,0x00000006u,0x00000078u,0x00000077u,0x00050050u,0x0000000au,0x00000079u,0x00000076u,0x00000078u,0x00050081u,0x0000000au,0x0000007au,0x00000074u,0x00000079u,0x0003003eu,0x00000073u,0x0000007au,0x0004003du,0x0000000au,0x0000007du,0x00000073u,0x0003003eu,0x0000007cu,0x0000007du,0x00070039u,0x00000006u,0x0000007eu,0x00000010u,0x00000013u,0x00000014u,0x0000007cu,0x0003003eu,0x0000007bu,0x0000007eu,0x0004003du,0x0000001bu,0x00000080u,0x0000006bu,0x0004006fu,0x00000006u,0x00000081u,0x00000080u,0x0006000cu,0x00000006u,0x00000082u,0x00000001u,0x00000004u,0x00000081u,0x0004003du,0x0000001bu,0x00000083u,0x00000061u,0x0004006fu,0x00000006u,0x00000084u,0x00000083u,0x0006000cu,0x00000006u,0x00000085u,0x00000001u,0x00000004u,0x00000084u,0x00050081u,0x00000006u,0x00000086u,0x00000082u,0x00000085u,0x00050085u,0x00000006u,0x00000087u,0x0000007fu,0x00000086u,0x0004003du,0x00000006u,0x00000088u,0x0000007bu,0x00050081u,0x00000006u,0x00000089u,0x00000088u,0x00000087u,0x0003003eu,0x0000007bu,0x00000089u,0x0004003du,0x00000006u,0x0000008au,0x0000007bu,0x0004003du,0x00000006u,0x0000008bu,0x0000005du,0x000500b8u,0x00000026u,0x0000008cu,0x0000008au,0x0000008bu,0x000300f7u,0x0000008eu,0x00000000u,0x000400fau,0x0000008cu,0x0000008du,0x0000008eu,0x000200f8u,0x0000008du,0x0004003du,0x00000006u,0x0000008fu,0x0000007bu,0x0003003eu,0x0000005du,0x0000008fu,0x0004003du,0x0000000au,0x00000090u,0x00000073u,0x0003003eu,0x0000005fu,0x00000090u,0x000200f9u,0x0000008eu,0x000200f8u,0x0000008eu,0x000200f9u,0x0000006fu,0x000200f8u,0x0000006fu,0x0004003du,0x0000001bu,0x00000091u,0x0000006bu,0x00050080u,0x0000001bu,0x00000092u,0x00000091u,0x00000025u,0x0003003eu,0x0000006bu,0x00000092u,0x000200f9u,0x0000006cu,0x000200f8u,0x0000006eu,0x000200f9u,0x00000066u,0x000200f8u,0x00000066u,0x0004003du,0x0000001bu,0x00000093u,0x00000061u,0x00050080u,0x0000001bu,0x00000094u,0x00000093u,0x00000025u,0x0003003eu,0x00000061u,0x00000094u,0x000200f9u,0x00000063u,0x000200f8u,0x00000065u,0x00050041u,0x00000098u,0x00000099u,0x00000097u,0x00000025u,0x0004003du,0x00000042u,0x0000009au,0x00000099u,0x000500aau,0x00000026u,0x0000009bu,0x0000009au,0x00000043u,0x000300f7u,0x0000009du,0x00000000u,0x000400fau,0x0000009bu,0x0000009cu,0x0000009du,0x000200f8u,0x0000009cu,0x0004003du,0x00000006u,0x0000009fu,0x0000005du,0x00050083u,0x00000006u,0x000000a0u,0x0000009fu,0x0000001au,0x0003003eu,0x0000009eu,0x000000a0u,0x0004003du,0x0000000au,0x000000a2u,0x0000005fu,0x00050081u,0x0000000au,0x000000a5u,0x000000a2u,0x000000a4u,0x0003003eu,0x000000a6u,0x000000a5u,0x00070039u,0x00000006u,0x000000a7u,0x00000010u,0x00000013u,0x00000014u,0x000000a6u,0x00050081u,0x00000006u,0x000000a8u,0x000000a7u,0x0000007fu,0x0003003eu,0x000000a1u,0x000000a8u,0x0004003du,0x0000000au,0x000000aau,0x0000005fu,0x00050081u,0x0000000au,0x000000adu,0x000000aau,0x000000acu,0x0003003eu,0x000000aeu,0x000000adu,0x00070039u,0x00000006u,0x000000afu,0x00000010u,0x00000013u,0x00000014u,0x000000aeu,0x00050081u,0x00000006u,0x000000b0u,0x000000afu,0x0000007fu,0x0003003eu,0x000000a9u,0x000000b0u,0x0004003du,0x0000000au,0x000000b2u,0x0000005fu,0x00050081u,0x0000000au,0x000000b4u,0x000000b2u,0x000000b3u,0x0003003eu,0x000000b5u,0x000000b4u,0x00070039u,0x00000006u,0x000000b6u,0x00000010u,0x00000013u,0x00000014u,0x000000b5u,0x00050081u,0x00000006u,0x000000b7u,0x000000b6u,0x0000007fu,0x0003003eu,0x000000b1u,0x000000b7u,0x0004003du,0x0000000au,0x000000b9u,0x0000005fu,0x00050081u,0x0000000au,0x000000bbu,0x000000b9u,0x000000bau,0x0003003eu,0x000000bcu,0x000000bbu,0x00070039u,0x00000006u,0x000000bdu,0x00000010u,0x00000013u,0x00000014u,0x000000bcu,0x00050081u,0x00000006u,0x000000beu,0x000000bdu,0x0000007fu,0x0003003eu,0x000000b8u,0x000000beu,0x0003003eu,0x000000bfu,0x0000001au,0x0003003eu,0x000000c0u,0x0000001au,0x0004003du,0x00000006u,0x000000c2u,0x000000a1u,0x0004003du,0x00000006u,0x000000c4u,0x0000009eu,0x00050085u,0x00000006u,0x000000c5u,0x000000c3u,0x000000c4u,0x00050083u,0x00000006u,0x000000c6u,0x000000c2u,0x000000c5u,0x0004003du,0x00000006u,0x000000c7u,0x000000a9u,0x00050081u,0x00000006u,0x000000c8u,0x000000c6u,0x000000c7u,0x0003003eu,0x000000c1u,0x000000c8u,0x0004003du,0x00000006u,0x000000cau,0x000000b1u,0x0004003du,0x00000006u,0x000000cbu,0x0000009eu,0x00050085u,0x00000006u,0x000000ccu,0x000000c3u,0x000000cbu,0x00050083u,0x00000006u,0x000000cdu,0x000000cau,0x000000ccu,0x0004003du,0x00000006u,0x000000ceu,0x000000b8u,0x00050081u,0x00000006u,0x000000cfu,0x000000cdu,0x000000ceu,0x0003003eu,0x000000c9u,0x000000cfu,0x0004003du,0x00000006u,0x000000d0u,0x000000c1u,0x000500bau,0x00000026u,0x000000d2u,0x000000d0u,0x000000d1u,0x000300f7u,0x000000d4u,0x00000000u,0x000400fau,0x000000d2u,0x000000d3u,0x000000d4u,0x000200f8u,0x000000d3u,0x0004003du,0x00000006u,0x000000d6u,0x000000a1u,0x0004003du,0x00000006u,0x000000d7u,0x000000a9u,0x00050083u,0x00000006u,0x000000d8u,0x000000d6u,0x000000d7u,0x00050085u,0x00000006u,0x000000d9u,0x000000d5u,0x000000d8u,0x0004003du,0x00000006u,0x000000dau,0x000000c1u,0x00050088u,0x00000006u,0x000000dbu,0x000000d9u,0x000000dau,0x0008000cu,0x00000006u,0x000000ddu,0x00000001u,0x0000002bu,0x000000dbu,0x000000dcu,0x000000d5u,0x0003003eu,0x000000bfu,0x000000ddu,0x000200f9u,0x000000d4u,0x000200f8u,0x000000d4u,0x0004003du,0x00000006u,0x000000deu,0x000000c9u,0x000500bau,0x00000026u,0x000000dfu,0x000000deu,0x000000d1u,0x000300f7u,0x000000e1u,0x00000000u,0x000400fau,0x000000dfu,0x000000e0u,0x000000e1u,0x000200f8u,0x000000e0u,0x0004003du,0x00000006u,0x000000e2u,0x000000b1u,0x0004003du,0x00000006u,0x000000e3u,0x000000b8u,0x00050083u,0x00000006u,0x000000e4u,0x000000e2u,0x000000e3u,0x00050085u,0x00000006u,0x000000e5u,0x000000d5u,0x000000e4u,0x0004003du,0x00000006u,0x000000e6u,0x000000c9u,0x00050088u,0x00000006u,0x000000e7u,0x000000e5u,0x000000e6u,0x0008000cu,0x00000006u,0x000000e8u,0x00000001u,0x0000002bu,0x000000e7u,0x000000dcu,0x000000d5u,0x0003003eu,0x000000c0u,0x000000e8u,0x000200f9u,0x000000e1u,0x000200f8u,0x000000e1u,0x0004003du,0x00000006u,0x000000e9u,0x000000bfu,0x0004003du,0x00000006u,0x000000eau,0x000000c0u,0x00050050u,0x0000000au,0x000000ebu,0x000000e9u,0x000000eau,0x0004003du,0x0000000au,0x000000ecu,0x0000005fu,0x00050081u,0x0000000au,0x000000edu,0x000000ecu,0x000000ebu,0x0003003eu,0x0000005fu,0x000000edu,0x000200f9u,0x0000009du,0x000200f8u,0x0000009du,0x0004003du,0x0000000au,0x000000eeu,0x0000005fu,0x000200feu,0x000000eeu,0x00010038u}; +static const size_t OF3_FLOW_M4_LEN = 2005; +static const uint32_t OF3_EXPAND_M4_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000169u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000049u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x0000000eu,0x3564656du,0x3b316628u,0x663b3166u,0x31663b31u,0x3b31663bu,0x00000000u,0x00030005u,0x00000009u,0x00000061u,0x00030005u,0x0000000au,0x00000062u,0x00030005u,0x0000000bu,0x00000063u,0x00030005u,0x0000000cu,0x00000064u,0x00030005u,0x0000000du,0x00000065u,0x00030005u,0x00000010u,0x00000078u,0x00030005u,0x00000034u,0x00000079u,0x00030005u,0x00000045u,0x00646967u,0x00080005u,0x00000049u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000004eu,0x006d6964u,0x00040005u,0x00000051u,0x64774675u,0x00000000u,0x00030005u,0x0000006bu,0x00007675u,0x00030005u,0x00000074u,0x00007366u,0x00050005u,0x00000079u,0x6f6c4675u,0x6e694677u,0x00000065u,0x00030005u,0x00000083u,0x00003463u,0x00030005u,0x00000088u,0x00006d78u,0x00030005u,0x00000090u,0x00007078u,0x00030005u,0x00000098u,0x00006d79u,0x00030005u,0x000000a0u,0x00007079u,0x00030005u,0x000000a8u,0x00000066u,0x00040005u,0x000000a9u,0x61726170u,0x0000006du,0x00040005u,0x000000acu,0x61726170u,0x0000006du,0x00040005u,0x000000afu,0x61726170u,0x0000006du,0x00040005u,0x000000b2u,0x61726170u,0x0000006du,0x00040005u,0x000000b5u,0x61726170u,0x0000006du,0x00040005u,0x000000b9u,0x61726170u,0x0000006du,0x00040005u,0x000000bcu,0x61726170u,0x0000006du,0x00040005u,0x000000bfu,0x61726170u,0x0000006du,0x00040005u,0x000000c2u,0x61726170u,0x0000006du,0x00040005u,0x000000c5u,0x61726170u,0x0000006du,0x00040005u,0x000000c9u,0x61726170u,0x0000006du,0x00040005u,0x000000cdu,0x61726170u,0x0000006du,0x00040005u,0x000000d0u,0x61726170u,0x0000006du,0x00040005u,0x000000d3u,0x61726170u,0x0000006du,0x00040005u,0x000000d6u,0x61726170u,0x0000006du,0x00040005u,0x000000dau,0x61726170u,0x0000006du,0x00040005u,0x000000deu,0x61726170u,0x0000006du,0x00040005u,0x000000e1u,0x61726170u,0x0000006du,0x00040005u,0x000000e4u,0x61726170u,0x0000006du,0x00040005u,0x000000e7u,0x61726170u,0x0000006du,0x00030005u,0x000000ecu,0x00647766u,0x00030005u,0x000000efu,0x00647762u,0x00030005u,0x000000f2u,0x0067616du,0x00030005u,0x000000fau,0x006c6572u,0x00040005u,0x00000101u,0x666e6f63u,0x00000000u,0x00030005u,0x00000102u,0x00000055u,0x00060006u,0x00000102u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000102u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000102u,0x00000002u,0x6c63636fu,0x00006f4cu,0x00050006u,0x00000102u,0x00000003u,0x6c63636fu,0x00006948u,0x00030005u,0x00000104u,0x00000000u,0x00030005u,0x0000010fu,0x00000071u,0x00030005u,0x00000113u,0x00787067u,0x00030005u,0x00000114u,0x00004d47u,0x00050006u,0x00000114u,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x00000114u,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x00000114u,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x00000114u,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x00000116u,0x00000000u,0x00030005u,0x00000139u,0x00003241u,0x00040005u,0x00000147u,0x6c6c7566u,0x00647746u,0x00040005u,0x0000014fu,0x6c6c7566u,0x00647742u,0x00040005u,0x0000015fu,0x64774275u,0x00000000u,0x00040047u,0x00000049u,0x0000000bu,0x0000001cu,0x00030047u,0x00000051u,0x00000019u,0x00040047u,0x00000051u,0x00000021u,0x00000030u,0x00040047u,0x00000051u,0x00000022u,0x00000000u,0x00040047u,0x00000079u,0x00000021u,0x00000020u,0x00040047u,0x00000079u,0x00000022u,0x00000000u,0x00030047u,0x00000102u,0x00000002u,0x00050048u,0x00000102u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000102u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000102u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000102u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000104u,0x00000021u,0x00000000u,0x00040047u,0x00000104u,0x00000022u,0x00000000u,0x00030047u,0x00000114u,0x00000002u,0x00050048u,0x00000114u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000114u,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x00000114u,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x00000114u,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x00000116u,0x00000021u,0x00000001u,0x00040047u,0x00000116u,0x00000022u,0x00000000u,0x00030047u,0x0000015fu,0x00000019u,0x00040047u,0x0000015fu,0x00000021u,0x00000031u,0x00040047u,0x0000015fu,0x00000022u,0x00000000u,0x00040047u,0x00000168u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00040020u,0x00000007u,0x00000007u,0x00000006u,0x00080021u,0x00000008u,0x00000006u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00040015u,0x00000042u,0x00000020u,0x00000001u,0x00040017u,0x00000043u,0x00000042u,0x00000002u,0x00040020u,0x00000044u,0x00000007u,0x00000043u,0x00040015u,0x00000046u,0x00000020u,0x00000000u,0x00040017u,0x00000047u,0x00000046u,0x00000003u,0x00040020u,0x00000048u,0x00000001u,0x00000047u,0x0004003bu,0x00000048u,0x00000049u,0x00000001u,0x00040017u,0x0000004au,0x00000046u,0x00000002u,0x00090019u,0x0000004fu,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000050u,0x00000000u,0x0000004fu,0x0004003bu,0x00000050u,0x00000051u,0x00000000u,0x00020014u,0x00000054u,0x0004002bu,0x00000046u,0x00000055u,0x00000000u,0x00040020u,0x00000056u,0x00000007u,0x00000042u,0x0004002bu,0x00000046u,0x0000005fu,0x00000001u,0x00040017u,0x00000069u,0x00000006u,0x00000002u,0x00040020u,0x0000006au,0x00000007u,0x00000069u,0x0004002bu,0x00000006u,0x0000006eu,0x3f000000u,0x0004002bu,0x00000006u,0x00000075u,0x3f800000u,0x00090019u,0x00000076u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000077u,0x00000076u,0x00040020u,0x00000078u,0x00000000u,0x00000077u,0x0004003bu,0x00000078u,0x00000079u,0x00000000u,0x0004002bu,0x00000042u,0x0000007bu,0x00000000u,0x00040017u,0x00000081u,0x00000006u,0x00000004u,0x00040020u,0x00000082u,0x00000007u,0x00000081u,0x0004002bu,0x00000006u,0x00000086u,0x00000000u,0x0004002bu,0x00000046u,0x000000cau,0x00000002u,0x0004002bu,0x00000046u,0x000000dbu,0x00000003u,0x0006001eu,0x00000102u,0x00000006u,0x00000046u,0x00000006u,0x00000006u,0x00040020u,0x00000103u,0x00000002u,0x00000102u,0x0004003bu,0x00000103u,0x00000104u,0x00000002u,0x0004002bu,0x00000042u,0x00000105u,0x00000002u,0x00040020u,0x00000106u,0x00000002u,0x00000006u,0x0004002bu,0x00000042u,0x00000109u,0x00000003u,0x0006001eu,0x00000114u,0x00000081u,0x00000081u,0x00000081u,0x00000081u,0x00040020u,0x00000115u,0x00000002u,0x00000114u,0x0004003bu,0x00000115u,0x00000116u,0x00000002u,0x00040018u,0x00000137u,0x00000069u,0x00000002u,0x00040020u,0x00000138u,0x00000007u,0x00000137u,0x0004003bu,0x00000050u,0x0000015fu,0x00000000u,0x0004002bu,0x00000046u,0x00000167u,0x00000010u,0x0006002cu,0x00000047u,0x00000168u,0x00000167u,0x00000167u,0x0000005fu,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000044u,0x00000045u,0x00000007u,0x0004003bu,0x00000044u,0x0000004eu,0x00000007u,0x0004003bu,0x0000006au,0x0000006bu,0x00000007u,0x0004003bu,0x0000006au,0x00000074u,0x00000007u,0x0004003bu,0x00000082u,0x00000083u,0x00000007u,0x0004003bu,0x00000082u,0x00000088u,0x00000007u,0x0004003bu,0x00000082u,0x00000090u,0x00000007u,0x0004003bu,0x00000082u,0x00000098u,0x00000007u,0x0004003bu,0x00000082u,0x000000a0u,0x00000007u,0x0004003bu,0x00000082u,0x000000a8u,0x00000007u,0x0004003bu,0x00000007u,0x000000a9u,0x00000007u,0x0004003bu,0x00000007u,0x000000acu,0x00000007u,0x0004003bu,0x00000007u,0x000000afu,0x00000007u,0x0004003bu,0x00000007u,0x000000b2u,0x00000007u,0x0004003bu,0x00000007u,0x000000b5u,0x00000007u,0x0004003bu,0x00000007u,0x000000b9u,0x00000007u,0x0004003bu,0x00000007u,0x000000bcu,0x00000007u,0x0004003bu,0x00000007u,0x000000bfu,0x00000007u,0x0004003bu,0x00000007u,0x000000c2u,0x00000007u,0x0004003bu,0x00000007u,0x000000c5u,0x00000007u,0x0004003bu,0x00000007u,0x000000c9u,0x00000007u,0x0004003bu,0x00000007u,0x000000cdu,0x00000007u,0x0004003bu,0x00000007u,0x000000d0u,0x00000007u,0x0004003bu,0x00000007u,0x000000d3u,0x00000007u,0x0004003bu,0x00000007u,0x000000d6u,0x00000007u,0x0004003bu,0x00000007u,0x000000dau,0x00000007u,0x0004003bu,0x00000007u,0x000000deu,0x00000007u,0x0004003bu,0x00000007u,0x000000e1u,0x00000007u,0x0004003bu,0x00000007u,0x000000e4u,0x00000007u,0x0004003bu,0x00000007u,0x000000e7u,0x00000007u,0x0004003bu,0x0000006au,0x000000ecu,0x00000007u,0x0004003bu,0x0000006au,0x000000efu,0x00000007u,0x0004003bu,0x00000007u,0x000000f2u,0x00000007u,0x0004003bu,0x00000007u,0x000000fau,0x00000007u,0x0004003bu,0x00000007u,0x00000101u,0x00000007u,0x0004003bu,0x0000006au,0x0000010fu,0x00000007u,0x0004003bu,0x0000006au,0x00000113u,0x00000007u,0x0004003bu,0x00000138u,0x00000139u,0x00000007u,0x0004003bu,0x0000006au,0x00000147u,0x00000007u,0x0004003bu,0x0000006au,0x0000014fu,0x00000007u,0x0004003du,0x00000047u,0x0000004bu,0x00000049u,0x0007004fu,0x0000004au,0x0000004cu,0x0000004bu,0x0000004bu,0x00000000u,0x00000001u,0x0004007cu,0x00000043u,0x0000004du,0x0000004cu,0x0003003eu,0x00000045u,0x0000004du,0x0004003du,0x0000004fu,0x00000052u,0x00000051u,0x00040068u,0x00000043u,0x00000053u,0x00000052u,0x0003003eu,0x0000004eu,0x00000053u,0x00050041u,0x00000056u,0x00000057u,0x00000045u,0x00000055u,0x0004003du,0x00000042u,0x00000058u,0x00000057u,0x00050041u,0x00000056u,0x00000059u,0x0000004eu,0x00000055u,0x0004003du,0x00000042u,0x0000005au,0x00000059u,0x000500afu,0x00000054u,0x0000005bu,0x00000058u,0x0000005au,0x000400a8u,0x00000054u,0x0000005cu,0x0000005bu,0x000300f7u,0x0000005eu,0x00000000u,0x000400fau,0x0000005cu,0x0000005du,0x0000005eu,0x000200f8u,0x0000005du,0x00050041u,0x00000056u,0x00000060u,0x00000045u,0x0000005fu,0x0004003du,0x00000042u,0x00000061u,0x00000060u,0x00050041u,0x00000056u,0x00000062u,0x0000004eu,0x0000005fu,0x0004003du,0x00000042u,0x00000063u,0x00000062u,0x000500afu,0x00000054u,0x00000064u,0x00000061u,0x00000063u,0x000200f9u,0x0000005eu,0x000200f8u,0x0000005eu,0x000700f5u,0x00000054u,0x00000065u,0x0000005bu,0x00000005u,0x00000064u,0x0000005du,0x000300f7u,0x00000067u,0x00000000u,0x000400fau,0x00000065u,0x00000066u,0x00000067u,0x000200f8u,0x00000066u,0x000100fdu,0x000200f8u,0x00000067u,0x0004003du,0x00000043u,0x0000006cu,0x00000045u,0x0004006fu,0x00000069u,0x0000006du,0x0000006cu,0x00050050u,0x00000069u,0x0000006fu,0x0000006eu,0x0000006eu,0x00050081u,0x00000069u,0x00000070u,0x0000006du,0x0000006fu,0x0004003du,0x00000043u,0x00000071u,0x0000004eu,0x0004006fu,0x00000069u,0x00000072u,0x00000071u,0x00050088u,0x00000069u,0x00000073u,0x00000070u,0x00000072u,0x0003003eu,0x0000006bu,0x00000073u,0x0004003du,0x00000077u,0x0000007au,0x00000079u,0x00040064u,0x00000076u,0x0000007cu,0x0000007au,0x00050067u,0x00000043u,0x0000007du,0x0000007cu,0x0000007bu,0x0004006fu,0x00000069u,0x0000007eu,0x0000007du,0x00050050u,0x00000069u,0x0000007fu,0x00000075u,0x00000075u,0x00050088u,0x00000069u,0x00000080u,0x0000007fu,0x0000007eu,0x0003003eu,0x00000074u,0x00000080u,0x0004003du,0x00000077u,0x00000084u,0x00000079u,0x0004003du,0x00000069u,0x00000085u,0x0000006bu,0x00070058u,0x00000081u,0x00000087u,0x00000084u,0x00000085u,0x00000002u,0x00000086u,0x0003003eu,0x00000083u,0x00000087u,0x0004003du,0x00000077u,0x00000089u,0x00000079u,0x0004003du,0x00000069u,0x0000008au,0x0000006bu,0x00050041u,0x00000007u,0x0000008bu,0x00000074u,0x00000055u,0x0004003du,0x00000006u,0x0000008cu,0x0000008bu,0x00050050u,0x00000069u,0x0000008du,0x0000008cu,0x00000086u,0x00050083u,0x00000069u,0x0000008eu,0x0000008au,0x0000008du,0x00070058u,0x00000081u,0x0000008fu,0x00000089u,0x0000008eu,0x00000002u,0x00000086u,0x0003003eu,0x00000088u,0x0000008fu,0x0004003du,0x00000077u,0x00000091u,0x00000079u,0x0004003du,0x00000069u,0x00000092u,0x0000006bu,0x00050041u,0x00000007u,0x00000093u,0x00000074u,0x00000055u,0x0004003du,0x00000006u,0x00000094u,0x00000093u,0x00050050u,0x00000069u,0x00000095u,0x00000094u,0x00000086u,0x00050081u,0x00000069u,0x00000096u,0x00000092u,0x00000095u,0x00070058u,0x00000081u,0x00000097u,0x00000091u,0x00000096u,0x00000002u,0x00000086u,0x0003003eu,0x00000090u,0x00000097u,0x0004003du,0x00000077u,0x00000099u,0x00000079u,0x0004003du,0x00000069u,0x0000009au,0x0000006bu,0x00050041u,0x00000007u,0x0000009bu,0x00000074u,0x0000005fu,0x0004003du,0x00000006u,0x0000009cu,0x0000009bu,0x00050050u,0x00000069u,0x0000009du,0x00000086u,0x0000009cu,0x00050083u,0x00000069u,0x0000009eu,0x0000009au,0x0000009du,0x00070058u,0x00000081u,0x0000009fu,0x00000099u,0x0000009eu,0x00000002u,0x00000086u,0x0003003eu,0x00000098u,0x0000009fu,0x0004003du,0x00000077u,0x000000a1u,0x00000079u,0x0004003du,0x00000069u,0x000000a2u,0x0000006bu,0x00050041u,0x00000007u,0x000000a3u,0x00000074u,0x0000005fu,0x0004003du,0x00000006u,0x000000a4u,0x000000a3u,0x00050050u,0x00000069u,0x000000a5u,0x00000086u,0x000000a4u,0x00050081u,0x00000069u,0x000000a6u,0x000000a2u,0x000000a5u,0x00070058u,0x00000081u,0x000000a7u,0x000000a1u,0x000000a6u,0x00000002u,0x00000086u,0x0003003eu,0x000000a0u,0x000000a7u,0x00050041u,0x00000007u,0x000000aau,0x00000083u,0x00000055u,0x0004003du,0x00000006u,0x000000abu,0x000000aau,0x0003003eu,0x000000a9u,0x000000abu,0x00050041u,0x00000007u,0x000000adu,0x00000088u,0x00000055u,0x0004003du,0x00000006u,0x000000aeu,0x000000adu,0x0003003eu,0x000000acu,0x000000aeu,0x00050041u,0x00000007u,0x000000b0u,0x00000090u,0x00000055u,0x0004003du,0x00000006u,0x000000b1u,0x000000b0u,0x0003003eu,0x000000afu,0x000000b1u,0x00050041u,0x00000007u,0x000000b3u,0x00000098u,0x00000055u,0x0004003du,0x00000006u,0x000000b4u,0x000000b3u,0x0003003eu,0x000000b2u,0x000000b4u,0x00050041u,0x00000007u,0x000000b6u,0x000000a0u,0x00000055u,0x0004003du,0x00000006u,0x000000b7u,0x000000b6u,0x0003003eu,0x000000b5u,0x000000b7u,0x00090039u,0x00000006u,0x000000b8u,0x0000000eu,0x000000a9u,0x000000acu,0x000000afu,0x000000b2u,0x000000b5u,0x00050041u,0x00000007u,0x000000bau,0x00000083u,0x0000005fu,0x0004003du,0x00000006u,0x000000bbu,0x000000bau,0x0003003eu,0x000000b9u,0x000000bbu,0x00050041u,0x00000007u,0x000000bdu,0x00000088u,0x0000005fu,0x0004003du,0x00000006u,0x000000beu,0x000000bdu,0x0003003eu,0x000000bcu,0x000000beu,0x00050041u,0x00000007u,0x000000c0u,0x00000090u,0x0000005fu,0x0004003du,0x00000006u,0x000000c1u,0x000000c0u,0x0003003eu,0x000000bfu,0x000000c1u,0x00050041u,0x00000007u,0x000000c3u,0x00000098u,0x0000005fu,0x0004003du,0x00000006u,0x000000c4u,0x000000c3u,0x0003003eu,0x000000c2u,0x000000c4u,0x00050041u,0x00000007u,0x000000c6u,0x000000a0u,0x0000005fu,0x0004003du,0x00000006u,0x000000c7u,0x000000c6u,0x0003003eu,0x000000c5u,0x000000c7u,0x00090039u,0x00000006u,0x000000c8u,0x0000000eu,0x000000b9u,0x000000bcu,0x000000bfu,0x000000c2u,0x000000c5u,0x00050041u,0x00000007u,0x000000cbu,0x00000083u,0x000000cau,0x0004003du,0x00000006u,0x000000ccu,0x000000cbu,0x0003003eu,0x000000c9u,0x000000ccu,0x00050041u,0x00000007u,0x000000ceu,0x00000088u,0x000000cau,0x0004003du,0x00000006u,0x000000cfu,0x000000ceu,0x0003003eu,0x000000cdu,0x000000cfu,0x00050041u,0x00000007u,0x000000d1u,0x00000090u,0x000000cau,0x0004003du,0x00000006u,0x000000d2u,0x000000d1u,0x0003003eu,0x000000d0u,0x000000d2u,0x00050041u,0x00000007u,0x000000d4u,0x00000098u,0x000000cau,0x0004003du,0x00000006u,0x000000d5u,0x000000d4u,0x0003003eu,0x000000d3u,0x000000d5u,0x00050041u,0x00000007u,0x000000d7u,0x000000a0u,0x000000cau,0x0004003du,0x00000006u,0x000000d8u,0x000000d7u,0x0003003eu,0x000000d6u,0x000000d8u,0x00090039u,0x00000006u,0x000000d9u,0x0000000eu,0x000000c9u,0x000000cdu,0x000000d0u,0x000000d3u,0x000000d6u,0x00050041u,0x00000007u,0x000000dcu,0x00000083u,0x000000dbu,0x0004003du,0x00000006u,0x000000ddu,0x000000dcu,0x0003003eu,0x000000dau,0x000000ddu,0x00050041u,0x00000007u,0x000000dfu,0x00000088u,0x000000dbu,0x0004003du,0x00000006u,0x000000e0u,0x000000dfu,0x0003003eu,0x000000deu,0x000000e0u,0x00050041u,0x00000007u,0x000000e2u,0x00000090u,0x000000dbu,0x0004003du,0x00000006u,0x000000e3u,0x000000e2u,0x0003003eu,0x000000e1u,0x000000e3u,0x00050041u,0x00000007u,0x000000e5u,0x00000098u,0x000000dbu,0x0004003du,0x00000006u,0x000000e6u,0x000000e5u,0x0003003eu,0x000000e4u,0x000000e6u,0x00050041u,0x00000007u,0x000000e8u,0x000000a0u,0x000000dbu,0x0004003du,0x00000006u,0x000000e9u,0x000000e8u,0x0003003eu,0x000000e7u,0x000000e9u,0x00090039u,0x00000006u,0x000000eau,0x0000000eu,0x000000dau,0x000000deu,0x000000e1u,0x000000e4u,0x000000e7u,0x00070050u,0x00000081u,0x000000ebu,0x000000b8u,0x000000c8u,0x000000d9u,0x000000eau,0x0003003eu,0x000000a8u,0x000000ebu,0x0004003du,0x00000081u,0x000000edu,0x000000a8u,0x0007004fu,0x00000069u,0x000000eeu,0x000000edu,0x000000edu,0x00000000u,0x00000001u,0x0003003eu,0x000000ecu,0x000000eeu,0x0004003du,0x00000081u,0x000000f0u,0x000000a8u,0x0007004fu,0x00000069u,0x000000f1u,0x000000f0u,0x000000f0u,0x00000002u,0x00000003u,0x0003003eu,0x000000efu,0x000000f1u,0x0004003du,0x00000069u,0x000000f3u,0x000000ecu,0x0006000cu,0x00000006u,0x000000f4u,0x00000001u,0x00000042u,0x000000f3u,0x0004003du,0x00000069u,0x000000f5u,0x000000efu,0x0006000cu,0x00000006u,0x000000f6u,0x00000001u,0x00000042u,0x000000f5u,0x00050081u,0x00000006u,0x000000f7u,0x000000f4u,0x000000f6u,0x00050085u,0x00000006u,0x000000f8u,0x0000006eu,0x000000f7u,0x00050081u,0x00000006u,0x000000f9u,0x000000f8u,0x0000006eu,0x0003003eu,0x000000f2u,0x000000f9u,0x0004003du,0x00000069u,0x000000fbu,0x000000ecu,0x0004003du,0x00000069u,0x000000fcu,0x000000efu,0x00050081u,0x00000069u,0x000000fdu,0x000000fbu,0x000000fcu,0x0006000cu,0x00000006u,0x000000feu,0x00000001u,0x00000042u,0x000000fdu,0x0004003du,0x00000006u,0x000000ffu,0x000000f2u,0x00050088u,0x00000006u,0x00000100u,0x000000feu,0x000000ffu,0x0003003eu,0x000000fau,0x00000100u,0x00050041u,0x00000106u,0x00000107u,0x00000104u,0x00000105u,0x0004003du,0x00000006u,0x00000108u,0x00000107u,0x00050041u,0x00000106u,0x0000010au,0x00000104u,0x00000109u,0x0004003du,0x00000006u,0x0000010bu,0x0000010au,0x0004003du,0x00000006u,0x0000010cu,0x000000fau,0x0008000cu,0x00000006u,0x0000010du,0x00000001u,0x00000031u,0x00000108u,0x0000010bu,0x0000010cu,0x00050083u,0x00000006u,0x0000010eu,0x00000075u,0x0000010du,0x0003003eu,0x00000101u,0x0000010eu,0x0004003du,0x00000069u,0x00000110u,0x0000006bu,0x00050050u,0x00000069u,0x00000111u,0x0000006eu,0x0000006eu,0x00050083u,0x00000069u,0x00000112u,0x00000110u,0x00000111u,0x0003003eu,0x0000010fu,0x00000112u,0x00060041u,0x00000106u,0x00000117u,0x00000116u,0x00000105u,0x00000055u,0x0004003du,0x00000006u,0x00000118u,0x00000117u,0x00050041u,0x00000007u,0x00000119u,0x0000010fu,0x00000055u,0x0004003du,0x00000006u,0x0000011au,0x00000119u,0x00050085u,0x00000006u,0x0000011bu,0x00000118u,0x0000011au,0x00060041u,0x00000106u,0x0000011cu,0x00000116u,0x00000105u,0x000000cau,0x0004003du,0x00000006u,0x0000011du,0x0000011cu,0x00050041u,0x00000007u,0x0000011eu,0x0000010fu,0x0000005fu,0x0004003du,0x00000006u,0x0000011fu,0x0000011eu,0x00050085u,0x00000006u,0x00000120u,0x0000011du,0x0000011fu,0x00050081u,0x00000006u,0x00000121u,0x0000011bu,0x00000120u,0x00060041u,0x00000106u,0x00000122u,0x00000116u,0x00000109u,0x00000055u,0x0004003du,0x00000006u,0x00000123u,0x00000122u,0x00050081u,0x00000006u,0x00000124u,0x00000121u,0x00000123u,0x00060041u,0x00000106u,0x00000125u,0x00000116u,0x00000105u,0x0000005fu,0x0004003du,0x00000006u,0x00000126u,0x00000125u,0x00050041u,0x00000007u,0x00000127u,0x0000010fu,0x00000055u,0x0004003du,0x00000006u,0x00000128u,0x00000127u,0x00050085u,0x00000006u,0x00000129u,0x00000126u,0x00000128u,0x00060041u,0x00000106u,0x0000012au,0x00000116u,0x00000105u,0x000000dbu,0x0004003du,0x00000006u,0x0000012bu,0x0000012au,0x00050041u,0x00000007u,0x0000012cu,0x0000010fu,0x0000005fu,0x0004003du,0x00000006u,0x0000012du,0x0000012cu,0x00050085u,0x00000006u,0x0000012eu,0x0000012bu,0x0000012du,0x00050081u,0x00000006u,0x0000012fu,0x00000129u,0x0000012eu,0x00060041u,0x00000106u,0x00000130u,0x00000116u,0x00000109u,0x0000005fu,0x0004003du,0x00000006u,0x00000131u,0x00000130u,0x00050081u,0x00000006u,0x00000132u,0x0000012fu,0x00000131u,0x00050050u,0x00000069u,0x00000133u,0x00000124u,0x00000132u,0x0004003du,0x00000043u,0x00000134u,0x0000004eu,0x0004006fu,0x00000069u,0x00000135u,0x00000134u,0x00050085u,0x00000069u,0x00000136u,0x00000133u,0x00000135u,0x0003003eu,0x00000113u,0x00000136u,0x00060041u,0x00000106u,0x0000013au,0x00000116u,0x00000105u,0x00000055u,0x0004003du,0x00000006u,0x0000013bu,0x0000013au,0x00050081u,0x00000006u,0x0000013cu,0x00000075u,0x0000013bu,0x00060041u,0x00000106u,0x0000013du,0x00000116u,0x00000105u,0x0000005fu,0x0004003du,0x00000006u,0x0000013eu,0x0000013du,0x00060041u,0x00000106u,0x0000013fu,0x00000116u,0x00000105u,0x000000cau,0x0004003du,0x00000006u,0x00000140u,0x0000013fu,0x00060041u,0x00000106u,0x00000141u,0x00000116u,0x00000105u,0x000000dbu,0x0004003du,0x00000006u,0x00000142u,0x00000141u,0x00050081u,0x00000006u,0x00000143u,0x00000075u,0x00000142u,0x00050050u,0x00000069u,0x00000144u,0x0000013cu,0x0000013eu,0x00050050u,0x00000069u,0x00000145u,0x00000140u,0x00000143u,0x00050050u,0x00000137u,0x00000146u,0x00000144u,0x00000145u,0x0003003eu,0x00000139u,0x00000146u,0x0004003du,0x00000069u,0x00000148u,0x00000113u,0x0004003du,0x00000006u,0x00000149u,0x00000101u,0x0004003du,0x00000137u,0x0000014au,0x00000139u,0x0004003du,0x00000069u,0x0000014bu,0x000000ecu,0x00050091u,0x00000069u,0x0000014cu,0x0000014au,0x0000014bu,0x0005008eu,0x00000069u,0x0000014du,0x0000014cu,0x00000149u,0x00050081u,0x00000069u,0x0000014eu,0x00000148u,0x0000014du,0x0003003eu,0x00000147u,0x0000014eu,0x0004003du,0x00000069u,0x00000150u,0x00000113u,0x0004007fu,0x00000069u,0x00000151u,0x00000150u,0x0004003du,0x00000006u,0x00000152u,0x00000101u,0x0004003du,0x00000137u,0x00000153u,0x00000139u,0x0004003du,0x00000069u,0x00000154u,0x000000efu,0x00050091u,0x00000069u,0x00000155u,0x00000153u,0x00000154u,0x0005008eu,0x00000069u,0x00000156u,0x00000155u,0x00000152u,0x00050081u,0x00000069u,0x00000157u,0x00000151u,0x00000156u,0x0003003eu,0x0000014fu,0x00000157u,0x0004003du,0x0000004fu,0x00000158u,0x00000051u,0x0004003du,0x00000043u,0x00000159u,0x00000045u,0x0004003du,0x00000069u,0x0000015au,0x00000147u,0x0004003du,0x00000006u,0x0000015bu,0x00000101u,0x00050051u,0x00000006u,0x0000015cu,0x0000015au,0x00000000u,0x00050051u,0x00000006u,0x0000015du,0x0000015au,0x00000001u,0x00070050u,0x00000081u,0x0000015eu,0x0000015cu,0x0000015du,0x00000086u,0x0000015bu,0x00040063u,0x00000158u,0x00000159u,0x0000015eu,0x0004003du,0x0000004fu,0x00000160u,0x0000015fu,0x0004003du,0x00000043u,0x00000161u,0x00000045u,0x0004003du,0x00000069u,0x00000162u,0x0000014fu,0x0004003du,0x00000006u,0x00000163u,0x00000101u,0x00050051u,0x00000006u,0x00000164u,0x00000162u,0x00000000u,0x00050051u,0x00000006u,0x00000165u,0x00000162u,0x00000001u,0x00070050u,0x00000081u,0x00000166u,0x00000164u,0x00000165u,0x00000086u,0x00000163u,0x00040063u,0x00000160u,0x00000161u,0x00000166u,0x000100fdu,0x00010038u,0x00050036u,0x00000006u,0x0000000eu,0x00000000u,0x00000008u,0x00030037u,0x00000007u,0x00000009u,0x00030037u,0x00000007u,0x0000000au,0x00030037u,0x00000007u,0x0000000bu,0x00030037u,0x00000007u,0x0000000cu,0x00030037u,0x00000007u,0x0000000du,0x000200f8u,0x0000000fu,0x0004003bu,0x00000007u,0x00000010u,0x00000007u,0x0004003bu,0x00000007u,0x00000034u,0x00000007u,0x0004003du,0x00000006u,0x00000011u,0x00000009u,0x0004003du,0x00000006u,0x00000012u,0x0000000au,0x0007000cu,0x00000006u,0x00000013u,0x00000001u,0x00000025u,0x00000011u,0x00000012u,0x0003003eu,0x00000010u,0x00000013u,0x0004003du,0x00000006u,0x00000014u,0x00000009u,0x0004003du,0x00000006u,0x00000015u,0x0000000au,0x0007000cu,0x00000006u,0x00000016u,0x00000001u,0x00000028u,0x00000014u,0x00000015u,0x0003003eu,0x00000009u,0x00000016u,0x0004003du,0x00000006u,0x00000017u,0x00000010u,0x0003003eu,0x0000000au,0x00000017u,0x0004003du,0x00000006u,0x00000018u,0x0000000bu,0x0004003du,0x00000006u,0x00000019u,0x0000000cu,0x0007000cu,0x00000006u,0x0000001au,0x00000001u,0x00000025u,0x00000018u,0x00000019u,0x0003003eu,0x00000010u,0x0000001au,0x0004003du,0x00000006u,0x0000001bu,0x0000000bu,0x0004003du,0x00000006u,0x0000001cu,0x0000000cu,0x0007000cu,0x00000006u,0x0000001du,0x00000001u,0x00000028u,0x0000001bu,0x0000001cu,0x0003003eu,0x0000000bu,0x0000001du,0x0004003du,0x00000006u,0x0000001eu,0x00000010u,0x0003003eu,0x0000000cu,0x0000001eu,0x0004003du,0x00000006u,0x0000001fu,0x00000009u,0x0004003du,0x00000006u,0x00000020u,0x0000000bu,0x0007000cu,0x00000006u,0x00000021u,0x00000001u,0x00000025u,0x0000001fu,0x00000020u,0x0003003eu,0x00000010u,0x00000021u,0x0004003du,0x00000006u,0x00000022u,0x00000009u,0x0004003du,0x00000006u,0x00000023u,0x0000000bu,0x0007000cu,0x00000006u,0x00000024u,0x00000001u,0x00000028u,0x00000022u,0x00000023u,0x0003003eu,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000025u,0x00000010u,0x0003003eu,0x0000000bu,0x00000025u,0x0004003du,0x00000006u,0x00000026u,0x0000000au,0x0004003du,0x00000006u,0x00000027u,0x0000000cu,0x0007000cu,0x00000006u,0x00000028u,0x00000001u,0x00000025u,0x00000026u,0x00000027u,0x0003003eu,0x00000010u,0x00000028u,0x0004003du,0x00000006u,0x00000029u,0x0000000au,0x0004003du,0x00000006u,0x0000002au,0x0000000cu,0x0007000cu,0x00000006u,0x0000002bu,0x00000001u,0x00000028u,0x00000029u,0x0000002au,0x0003003eu,0x0000000au,0x0000002bu,0x0004003du,0x00000006u,0x0000002cu,0x00000010u,0x0003003eu,0x0000000cu,0x0000002cu,0x0004003du,0x00000006u,0x0000002du,0x0000000au,0x0004003du,0x00000006u,0x0000002eu,0x0000000bu,0x0007000cu,0x00000006u,0x0000002fu,0x00000001u,0x00000025u,0x0000002du,0x0000002eu,0x0003003eu,0x00000010u,0x0000002fu,0x0004003du,0x00000006u,0x00000030u,0x0000000au,0x0004003du,0x00000006u,0x00000031u,0x0000000bu,0x0007000cu,0x00000006u,0x00000032u,0x00000001u,0x00000028u,0x00000030u,0x00000031u,0x0003003eu,0x0000000au,0x00000032u,0x0004003du,0x00000006u,0x00000033u,0x00000010u,0x0003003eu,0x0000000bu,0x00000033u,0x0004003du,0x00000006u,0x00000035u,0x0000000au,0x0004003du,0x00000006u,0x00000036u,0x0000000du,0x0007000cu,0x00000006u,0x00000037u,0x00000001u,0x00000025u,0x00000035u,0x00000036u,0x0003003eu,0x00000034u,0x00000037u,0x0004003du,0x00000006u,0x00000038u,0x0000000au,0x0004003du,0x00000006u,0x00000039u,0x0000000du,0x0007000cu,0x00000006u,0x0000003au,0x00000001u,0x00000028u,0x00000038u,0x00000039u,0x0003003eu,0x00000010u,0x0000003au,0x0004003du,0x00000006u,0x0000003bu,0x00000034u,0x0004003du,0x00000006u,0x0000003cu,0x0000000bu,0x0007000cu,0x00000006u,0x0000003du,0x00000001u,0x00000028u,0x0000003bu,0x0000003cu,0x0004003du,0x00000006u,0x0000003eu,0x00000010u,0x0007000cu,0x00000006u,0x0000003fu,0x00000001u,0x00000025u,0x0000003du,0x0000003eu,0x000200feu,0x0000003fu,0x00010038u}; +static const size_t OF3_EXPAND_M4_LEN = 2217; +static const uint32_t OF3_GM_REDUCE_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x000001d7u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000bu,0x00060010u,0x00000004u,0x00000011u,0x00000040u,0x00000001u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00040005u,0x00000008u,0x64697467u,0x00000000u,0x00080005u,0x0000000bu,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000001au,0x006d6964u,0x00040005u,0x0000001fu,0x65725075u,0x00000076u,0x00040005u,0x00000024u,0x61746f74u,0x0000006cu,0x00040005u,0x00000030u,0x44766e69u,0x00006d69u,0x00040005u,0x00000036u,0x6c6f6370u,0x00000030u,0x00030005u,0x00000038u,0x00004d47u,0x00050006u,0x00000038u,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x00000038u,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x00000038u,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x00000038u,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x0000003au,0x00000000u,0x00040005u,0x00000041u,0x6c6f6370u,0x00000031u,0x00030005u,0x00000049u,0x00000074u,0x00030005u,0x0000004fu,0x0000006bu,0x00030005u,0x0000005au,0x00636361u,0x00030005u,0x00000061u,0x00000069u,0x00030005u,0x0000006bu,0x00007870u,0x00030005u,0x0000009au,0x00007675u,0x00030005u,0x000000a2u,0x00000071u,0x00040005u,0x000000a6u,0x72537675u,0x00000063u,0x00030005u,0x000000cfu,0x00000054u,0x00030005u,0x000000d4u,0x00000049u,0x00040005u,0x000000d5u,0x72754375u,0x00000072u,0x00030005u,0x000000dau,0x00000065u,0x00030005u,0x000000deu,0x006d7854u,0x00030005u,0x000000e7u,0x00707854u,0x00030005u,0x000000f0u,0x006d7954u,0x00030005u,0x000000f9u,0x00707954u,0x00030005u,0x00000102u,0x00007854u,0x00030005u,0x0000010au,0x00007954u,0x00030005u,0x00000112u,0x00006561u,0x00030005u,0x00000115u,0x00000077u,0x00030005u,0x00000125u,0x00006473u,0x00030005u,0x00000142u,0x00786469u,0x00030005u,0x00000143u,0x00000072u,0x00030005u,0x0000014bu,0x00000063u,0x00040005u,0x000001bcu,0x65736162u,0x00000000u,0x00030005u,0x000001bfu,0x0000006bu,0x00050005u,0x000001c8u,0x74726150u,0x736c6169u,0x00000000u,0x00050006u,0x000001c8u,0x00000000u,0x74726170u,0x00000000u,0x00030005u,0x000001cau,0x00000000u,0x00040047u,0x0000000bu,0x0000000bu,0x0000001cu,0x00040047u,0x0000001fu,0x00000021u,0x00000020u,0x00040047u,0x0000001fu,0x00000022u,0x00000000u,0x00030047u,0x00000038u,0x00000002u,0x00050048u,0x00000038u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000038u,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x00000038u,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x00000038u,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x0000003au,0x00000021u,0x00000001u,0x00040047u,0x0000003au,0x00000022u,0x00000000u,0x00040047u,0x000000d5u,0x00000021u,0x00000021u,0x00040047u,0x000000d5u,0x00000022u,0x00000000u,0x00040047u,0x000001c7u,0x00000006u,0x00000004u,0x00030047u,0x000001c8u,0x00000002u,0x00050048u,0x000001c8u,0x00000000u,0x00000023u,0x00000000u,0x00040047u,0x000001cau,0x00000021u,0x00000010u,0x00040047u,0x000001cau,0x00000022u,0x00000000u,0x00040047u,0x000001d6u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000000u,0x00040020u,0x00000007u,0x00000007u,0x00000006u,0x00040017u,0x00000009u,0x00000006u,0x00000003u,0x00040020u,0x0000000au,0x00000001u,0x00000009u,0x0004003bu,0x0000000au,0x0000000bu,0x00000001u,0x0004002bu,0x00000006u,0x0000000cu,0x00000000u,0x00040020u,0x0000000du,0x00000001u,0x00000006u,0x0004002bu,0x00000006u,0x00000011u,0x00000200u,0x00020014u,0x00000012u,0x00040015u,0x00000017u,0x00000020u,0x00000001u,0x00040017u,0x00000018u,0x00000017u,0x00000002u,0x00040020u,0x00000019u,0x00000007u,0x00000018u,0x00030016u,0x0000001bu,0x00000020u,0x00090019u,0x0000001cu,0x0000001bu,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000001du,0x0000001cu,0x00040020u,0x0000001eu,0x00000000u,0x0000001du,0x0004003bu,0x0000001eu,0x0000001fu,0x00000000u,0x0004002bu,0x00000017u,0x00000021u,0x00000000u,0x00040020u,0x00000025u,0x00000007u,0x00000017u,0x0004002bu,0x00000006u,0x00000029u,0x00000001u,0x00040017u,0x0000002eu,0x0000001bu,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x0000001bu,0x00000031u,0x3f800000u,0x00040017u,0x00000037u,0x0000001bu,0x00000004u,0x0006001eu,0x00000038u,0x00000037u,0x00000037u,0x00000037u,0x00000037u,0x00040020u,0x00000039u,0x00000002u,0x00000038u,0x0004003bu,0x00000039u,0x0000003au,0x00000002u,0x00040020u,0x0000003bu,0x00000002u,0x0000001bu,0x0004002bu,0x00000006u,0x00000042u,0x00000002u,0x0004002bu,0x00000006u,0x00000045u,0x00000003u,0x0004002bu,0x00000017u,0x0000004au,0x00000001u,0x00040020u,0x0000004bu,0x00000002u,0x00000037u,0x0004002bu,0x00000006u,0x00000056u,0x00000020u,0x0004001cu,0x00000058u,0x0000001bu,0x00000056u,0x00040020u,0x00000059u,0x00000007u,0x00000058u,0x0004002bu,0x0000001bu,0x0000005cu,0x00000000u,0x00040020u,0x0000005du,0x00000007u,0x0000001bu,0x0004002bu,0x0000001bu,0x0000009du,0x3f000000u,0x0004003bu,0x0000001eu,0x000000d5u,0x00000000u,0x0004002bu,0x0000001bu,0x00000117u,0x3d75c28fu,0x0004002bu,0x0000001bu,0x0000011eu,0x358637bdu,0x0004002bu,0x00000006u,0x00000122u,0x00000006u,0x0004001cu,0x00000123u,0x0000001bu,0x00000122u,0x00040020u,0x00000124u,0x00000007u,0x00000123u,0x0004002bu,0x00000017u,0x00000130u,0x00000002u,0x0004002bu,0x00000017u,0x00000136u,0x00000003u,0x0004002bu,0x00000017u,0x0000013cu,0x00000004u,0x0004002bu,0x00000017u,0x0000013fu,0x00000005u,0x0004002bu,0x00000017u,0x00000168u,0x00000015u,0x0004002bu,0x00000017u,0x00000173u,0x00000016u,0x0004002bu,0x00000017u,0x0000017eu,0x00000017u,0x0004002bu,0x00000017u,0x00000189u,0x00000018u,0x0004002bu,0x00000017u,0x00000194u,0x00000019u,0x0004002bu,0x00000017u,0x0000019fu,0x0000001au,0x0004002bu,0x00000017u,0x000001aau,0x0000001bu,0x0004002bu,0x00000017u,0x000001b0u,0x0000001cu,0x0003001du,0x000001c7u,0x0000001bu,0x0003001eu,0x000001c8u,0x000001c7u,0x00040020u,0x000001c9u,0x0000000cu,0x000001c8u,0x0004003bu,0x000001c9u,0x000001cau,0x0000000cu,0x00040020u,0x000001d1u,0x0000000cu,0x0000001bu,0x0004002bu,0x00000006u,0x000001d5u,0x00000040u,0x0006002cu,0x00000009u,0x000001d6u,0x000001d5u,0x00000029u,0x00000029u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000007u,0x00000008u,0x00000007u,0x0004003bu,0x00000019u,0x0000001au,0x00000007u,0x0004003bu,0x00000007u,0x00000024u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x00000036u,0x00000007u,0x0004003bu,0x0000002fu,0x00000041u,0x00000007u,0x0004003bu,0x0000002fu,0x00000049u,0x00000007u,0x0004003bu,0x00000007u,0x0000004fu,0x00000007u,0x0004003bu,0x00000059u,0x0000005au,0x00000007u,0x0004003bu,0x00000007u,0x00000061u,0x00000007u,0x0004003bu,0x00000019u,0x0000006bu,0x00000007u,0x0004003bu,0x0000002fu,0x0000009au,0x00000007u,0x0004003bu,0x0000002fu,0x000000a2u,0x00000007u,0x0004003bu,0x0000002fu,0x000000a6u,0x00000007u,0x0004003bu,0x0000005du,0x000000cfu,0x00000007u,0x0004003bu,0x0000005du,0x000000d4u,0x00000007u,0x0004003bu,0x0000005du,0x000000dau,0x00000007u,0x0004003bu,0x0000005du,0x000000deu,0x00000007u,0x0004003bu,0x0000005du,0x000000e7u,0x00000007u,0x0004003bu,0x0000005du,0x000000f0u,0x00000007u,0x0004003bu,0x0000005du,0x000000f9u,0x00000007u,0x0004003bu,0x0000005du,0x00000102u,0x00000007u,0x0004003bu,0x0000005du,0x0000010au,0x00000007u,0x0004003bu,0x0000005du,0x00000112u,0x00000007u,0x0004003bu,0x0000005du,0x00000115u,0x00000007u,0x0004003bu,0x0000005du,0x00000119u,0x00000007u,0x0004003bu,0x00000124u,0x00000125u,0x00000007u,0x0004003bu,0x00000007u,0x00000142u,0x00000007u,0x0004003bu,0x00000007u,0x00000143u,0x00000007u,0x0004003bu,0x00000007u,0x0000014bu,0x00000007u,0x0004003bu,0x00000007u,0x000001bcu,0x00000007u,0x0004003bu,0x00000007u,0x000001bfu,0x00000007u,0x00050041u,0x0000000du,0x0000000eu,0x0000000bu,0x0000000cu,0x0004003du,0x00000006u,0x0000000fu,0x0000000eu,0x0003003eu,0x00000008u,0x0000000fu,0x0004003du,0x00000006u,0x00000010u,0x00000008u,0x000500aeu,0x00000012u,0x00000013u,0x00000010u,0x00000011u,0x000300f7u,0x00000015u,0x00000000u,0x000400fau,0x00000013u,0x00000014u,0x00000015u,0x000200f8u,0x00000014u,0x000100fdu,0x000200f8u,0x00000015u,0x0004003du,0x0000001du,0x00000020u,0x0000001fu,0x00040064u,0x0000001cu,0x00000022u,0x00000020u,0x00050067u,0x00000018u,0x00000023u,0x00000022u,0x00000021u,0x0003003eu,0x0000001au,0x00000023u,0x00050041u,0x00000025u,0x00000026u,0x0000001au,0x0000000cu,0x0004003du,0x00000017u,0x00000027u,0x00000026u,0x0004007cu,0x00000006u,0x00000028u,0x00000027u,0x00050041u,0x00000025u,0x0000002au,0x0000001au,0x00000029u,0x0004003du,0x00000017u,0x0000002bu,0x0000002au,0x0004007cu,0x00000006u,0x0000002cu,0x0000002bu,0x00050084u,0x00000006u,0x0000002du,0x00000028u,0x0000002cu,0x0003003eu,0x00000024u,0x0000002du,0x0004003du,0x00000018u,0x00000032u,0x0000001au,0x0004006fu,0x0000002eu,0x00000033u,0x00000032u,0x00050050u,0x0000002eu,0x00000034u,0x00000031u,0x00000031u,0x00050088u,0x0000002eu,0x00000035u,0x00000034u,0x00000033u,0x0003003eu,0x00000030u,0x00000035u,0x00060041u,0x0000003bu,0x0000003cu,0x0000003au,0x00000021u,0x0000000cu,0x0004003du,0x0000001bu,0x0000003du,0x0000003cu,0x00060041u,0x0000003bu,0x0000003eu,0x0000003au,0x00000021u,0x00000029u,0x0004003du,0x0000001bu,0x0000003fu,0x0000003eu,0x00050050u,0x0000002eu,0x00000040u,0x0000003du,0x0000003fu,0x0003003eu,0x00000036u,0x00000040u,0x00060041u,0x0000003bu,0x00000043u,0x0000003au,0x00000021u,0x00000042u,0x0004003du,0x0000001bu,0x00000044u,0x00000043u,0x00060041u,0x0000003bu,0x00000046u,0x0000003au,0x00000021u,0x00000045u,0x0004003du,0x0000001bu,0x00000047u,0x00000046u,0x00050050u,0x0000002eu,0x00000048u,0x00000044u,0x00000047u,0x0003003eu,0x00000041u,0x00000048u,0x00050041u,0x0000004bu,0x0000004cu,0x0000003au,0x0000004au,0x0004003du,0x00000037u,0x0000004du,0x0000004cu,0x0007004fu,0x0000002eu,0x0000004eu,0x0000004du,0x0000004du,0x00000000u,0x00000001u,0x0003003eu,0x00000049u,0x0000004eu,0x0003003eu,0x0000004fu,0x0000000cu,0x000200f9u,0x00000050u,0x000200f8u,0x00000050u,0x000400f6u,0x00000052u,0x00000053u,0x00000000u,0x000200f9u,0x00000054u,0x000200f8u,0x00000054u,0x0004003du,0x00000006u,0x00000055u,0x0000004fu,0x000500b0u,0x00000012u,0x00000057u,0x00000055u,0x00000056u,0x000400fau,0x00000057u,0x00000051u,0x00000052u,0x000200f8u,0x00000051u,0x0004003du,0x00000006u,0x0000005bu,0x0000004fu,0x00050041u,0x0000005du,0x0000005eu,0x0000005au,0x0000005bu,0x0003003eu,0x0000005eu,0x0000005cu,0x000200f9u,0x00000053u,0x000200f8u,0x00000053u,0x0004003du,0x00000006u,0x0000005fu,0x0000004fu,0x00050080u,0x00000006u,0x00000060u,0x0000005fu,0x0000004au,0x0003003eu,0x0000004fu,0x00000060u,0x000200f9u,0x00000050u,0x000200f8u,0x00000052u,0x0004003du,0x00000006u,0x00000062u,0x00000008u,0x0003003eu,0x00000061u,0x00000062u,0x000200f9u,0x00000063u,0x000200f8u,0x00000063u,0x000400f6u,0x00000065u,0x00000066u,0x00000000u,0x000200f9u,0x00000067u,0x000200f8u,0x00000067u,0x0004003du,0x00000006u,0x00000068u,0x00000061u,0x0004003du,0x00000006u,0x00000069u,0x00000024u,0x000500b0u,0x00000012u,0x0000006au,0x00000068u,0x00000069u,0x000400fau,0x0000006au,0x00000064u,0x00000065u,0x000200f8u,0x00000064u,0x0004003du,0x00000006u,0x0000006cu,0x00000061u,0x00050041u,0x00000025u,0x0000006du,0x0000001au,0x0000000cu,0x0004003du,0x00000017u,0x0000006eu,0x0000006du,0x0004007cu,0x00000006u,0x0000006fu,0x0000006eu,0x00050089u,0x00000006u,0x00000070u,0x0000006cu,0x0000006fu,0x0004007cu,0x00000017u,0x00000071u,0x00000070u,0x0004003du,0x00000006u,0x00000072u,0x00000061u,0x00050041u,0x00000025u,0x00000073u,0x0000001au,0x0000000cu,0x0004003du,0x00000017u,0x00000074u,0x00000073u,0x0004007cu,0x00000006u,0x00000075u,0x00000074u,0x00050086u,0x00000006u,0x00000076u,0x00000072u,0x00000075u,0x0004007cu,0x00000017u,0x00000077u,0x00000076u,0x00050050u,0x00000018u,0x00000078u,0x00000071u,0x00000077u,0x0003003eu,0x0000006bu,0x00000078u,0x00050041u,0x00000025u,0x00000079u,0x0000006bu,0x0000000cu,0x0004003du,0x00000017u,0x0000007au,0x00000079u,0x000500b1u,0x00000012u,0x0000007bu,0x0000007au,0x0000004au,0x000400a8u,0x00000012u,0x0000007cu,0x0000007bu,0x000300f7u,0x0000007eu,0x00000000u,0x000400fau,0x0000007cu,0x0000007du,0x0000007eu,0x000200f8u,0x0000007du,0x00050041u,0x00000025u,0x0000007fu,0x0000006bu,0x00000029u,0x0004003du,0x00000017u,0x00000080u,0x0000007fu,0x000500b1u,0x00000012u,0x00000081u,0x00000080u,0x0000004au,0x000200f9u,0x0000007eu,0x000200f8u,0x0000007eu,0x000700f5u,0x00000012u,0x00000082u,0x0000007bu,0x00000064u,0x00000081u,0x0000007du,0x000400a8u,0x00000012u,0x00000083u,0x00000082u,0x000300f7u,0x00000085u,0x00000000u,0x000400fau,0x00000083u,0x00000084u,0x00000085u,0x000200f8u,0x00000084u,0x00050041u,0x00000025u,0x00000086u,0x0000006bu,0x0000000cu,0x0004003du,0x00000017u,0x00000087u,0x00000086u,0x00050041u,0x00000025u,0x00000088u,0x0000001au,0x0000000cu,0x0004003du,0x00000017u,0x00000089u,0x00000088u,0x00050082u,0x00000017u,0x0000008au,0x00000089u,0x0000004au,0x000500afu,0x00000012u,0x0000008bu,0x00000087u,0x0000008au,0x000200f9u,0x00000085u,0x000200f8u,0x00000085u,0x000700f5u,0x00000012u,0x0000008cu,0x00000082u,0x0000007eu,0x0000008bu,0x00000084u,0x000400a8u,0x00000012u,0x0000008du,0x0000008cu,0x000300f7u,0x0000008fu,0x00000000u,0x000400fau,0x0000008du,0x0000008eu,0x0000008fu,0x000200f8u,0x0000008eu,0x00050041u,0x00000025u,0x00000090u,0x0000006bu,0x00000029u,0x0004003du,0x00000017u,0x00000091u,0x00000090u,0x00050041u,0x00000025u,0x00000092u,0x0000001au,0x00000029u,0x0004003du,0x00000017u,0x00000093u,0x00000092u,0x00050082u,0x00000017u,0x00000094u,0x00000093u,0x0000004au,0x000500afu,0x00000012u,0x00000095u,0x00000091u,0x00000094u,0x000200f9u,0x0000008fu,0x000200f8u,0x0000008fu,0x000700f5u,0x00000012u,0x00000096u,0x0000008cu,0x00000085u,0x00000095u,0x0000008eu,0x000300f7u,0x00000098u,0x00000000u,0x000400fau,0x00000096u,0x00000097u,0x00000098u,0x000200f8u,0x00000097u,0x000200f9u,0x00000066u,0x000200f8u,0x00000098u,0x0004003du,0x00000018u,0x0000009bu,0x0000006bu,0x0004006fu,0x0000002eu,0x0000009cu,0x0000009bu,0x00050050u,0x0000002eu,0x0000009eu,0x0000009du,0x0000009du,0x00050081u,0x0000002eu,0x0000009fu,0x0000009cu,0x0000009eu,0x0004003du,0x0000002eu,0x000000a0u,0x00000030u,0x00050085u,0x0000002eu,0x000000a1u,0x0000009fu,0x000000a0u,0x0003003eu,0x0000009au,0x000000a1u,0x0004003du,0x0000002eu,0x000000a3u,0x0000009au,0x00050050u,0x0000002eu,0x000000a4u,0x0000009du,0x0000009du,0x00050083u,0x0000002eu,0x000000a5u,0x000000a3u,0x000000a4u,0x0003003eu,0x000000a2u,0x000000a5u,0x0004003du,0x0000002eu,0x000000a7u,0x0000009au,0x0004003du,0x0000002eu,0x000000a8u,0x00000036u,0x00050041u,0x0000005du,0x000000a9u,0x000000a2u,0x0000000cu,0x0004003du,0x0000001bu,0x000000aau,0x000000a9u,0x0005008eu,0x0000002eu,0x000000abu,0x000000a8u,0x000000aau,0x00050081u,0x0000002eu,0x000000acu,0x000000a7u,0x000000abu,0x0004003du,0x0000002eu,0x000000adu,0x00000041u,0x00050041u,0x0000005du,0x000000aeu,0x000000a2u,0x00000029u,0x0004003du,0x0000001bu,0x000000afu,0x000000aeu,0x0005008eu,0x0000002eu,0x000000b0u,0x000000adu,0x000000afu,0x00050081u,0x0000002eu,0x000000b1u,0x000000acu,0x000000b0u,0x0004003du,0x0000002eu,0x000000b2u,0x00000049u,0x00050081u,0x0000002eu,0x000000b3u,0x000000b1u,0x000000b2u,0x0003003eu,0x000000a6u,0x000000b3u,0x00050041u,0x0000005du,0x000000b4u,0x000000a6u,0x0000000cu,0x0004003du,0x0000001bu,0x000000b5u,0x000000b4u,0x000500b8u,0x00000012u,0x000000b6u,0x000000b5u,0x0000005cu,0x000400a8u,0x00000012u,0x000000b7u,0x000000b6u,0x000300f7u,0x000000b9u,0x00000000u,0x000400fau,0x000000b7u,0x000000b8u,0x000000b9u,0x000200f8u,0x000000b8u,0x00050041u,0x0000005du,0x000000bau,0x000000a6u,0x00000029u,0x0004003du,0x0000001bu,0x000000bbu,0x000000bau,0x000500b8u,0x00000012u,0x000000bcu,0x000000bbu,0x0000005cu,0x000200f9u,0x000000b9u,0x000200f8u,0x000000b9u,0x000700f5u,0x00000012u,0x000000bdu,0x000000b6u,0x00000098u,0x000000bcu,0x000000b8u,0x000400a8u,0x00000012u,0x000000beu,0x000000bdu,0x000300f7u,0x000000c0u,0x00000000u,0x000400fau,0x000000beu,0x000000bfu,0x000000c0u,0x000200f8u,0x000000bfu,0x00050041u,0x0000005du,0x000000c1u,0x000000a6u,0x0000000cu,0x0004003du,0x0000001bu,0x000000c2u,0x000000c1u,0x000500bau,0x00000012u,0x000000c3u,0x000000c2u,0x00000031u,0x000200f9u,0x000000c0u,0x000200f8u,0x000000c0u,0x000700f5u,0x00000012u,0x000000c4u,0x000000bdu,0x000000b9u,0x000000c3u,0x000000bfu,0x000400a8u,0x00000012u,0x000000c5u,0x000000c4u,0x000300f7u,0x000000c7u,0x00000000u,0x000400fau,0x000000c5u,0x000000c6u,0x000000c7u,0x000200f8u,0x000000c6u,0x00050041u,0x0000005du,0x000000c8u,0x000000a6u,0x00000029u,0x0004003du,0x0000001bu,0x000000c9u,0x000000c8u,0x000500bau,0x00000012u,0x000000cau,0x000000c9u,0x00000031u,0x000200f9u,0x000000c7u,0x000200f8u,0x000000c7u,0x000700f5u,0x00000012u,0x000000cbu,0x000000c4u,0x000000c0u,0x000000cau,0x000000c6u,0x000300f7u,0x000000cdu,0x00000000u,0x000400fau,0x000000cbu,0x000000ccu,0x000000cdu,0x000200f8u,0x000000ccu,0x000200f9u,0x00000066u,0x000200f8u,0x000000cdu,0x0004003du,0x0000001du,0x000000d0u,0x0000001fu,0x0004003du,0x0000002eu,0x000000d1u,0x0000009au,0x00070058u,0x00000037u,0x000000d2u,0x000000d0u,0x000000d1u,0x00000002u,0x0000005cu,0x00050051u,0x0000001bu,0x000000d3u,0x000000d2u,0x00000000u,0x0003003eu,0x000000cfu,0x000000d3u,0x0004003du,0x0000001du,0x000000d6u,0x000000d5u,0x0004003du,0x0000002eu,0x000000d7u,0x000000a6u,0x00070058u,0x00000037u,0x000000d8u,0x000000d6u,0x000000d7u,0x00000002u,0x0000005cu,0x00050051u,0x0000001bu,0x000000d9u,0x000000d8u,0x00000000u,0x0003003eu,0x000000d4u,0x000000d9u,0x0004003du,0x0000001bu,0x000000dbu,0x000000d4u,0x0004003du,0x0000001bu,0x000000dcu,0x000000cfu,0x00050083u,0x0000001bu,0x000000ddu,0x000000dbu,0x000000dcu,0x0003003eu,0x000000dau,0x000000ddu,0x0004003du,0x0000001du,0x000000dfu,0x0000001fu,0x0004003du,0x0000002eu,0x000000e0u,0x0000009au,0x00050041u,0x0000005du,0x000000e1u,0x00000030u,0x0000000cu,0x0004003du,0x0000001bu,0x000000e2u,0x000000e1u,0x00050050u,0x0000002eu,0x000000e3u,0x000000e2u,0x0000005cu,0x00050083u,0x0000002eu,0x000000e4u,0x000000e0u,0x000000e3u,0x00070058u,0x00000037u,0x000000e5u,0x000000dfu,0x000000e4u,0x00000002u,0x0000005cu,0x00050051u,0x0000001bu,0x000000e6u,0x000000e5u,0x00000000u,0x0003003eu,0x000000deu,0x000000e6u,0x0004003du,0x0000001du,0x000000e8u,0x0000001fu,0x0004003du,0x0000002eu,0x000000e9u,0x0000009au,0x00050041u,0x0000005du,0x000000eau,0x00000030u,0x0000000cu,0x0004003du,0x0000001bu,0x000000ebu,0x000000eau,0x00050050u,0x0000002eu,0x000000ecu,0x000000ebu,0x0000005cu,0x00050081u,0x0000002eu,0x000000edu,0x000000e9u,0x000000ecu,0x00070058u,0x00000037u,0x000000eeu,0x000000e8u,0x000000edu,0x00000002u,0x0000005cu,0x00050051u,0x0000001bu,0x000000efu,0x000000eeu,0x00000000u,0x0003003eu,0x000000e7u,0x000000efu,0x0004003du,0x0000001du,0x000000f1u,0x0000001fu,0x0004003du,0x0000002eu,0x000000f2u,0x0000009au,0x00050041u,0x0000005du,0x000000f3u,0x00000030u,0x00000029u,0x0004003du,0x0000001bu,0x000000f4u,0x000000f3u,0x00050050u,0x0000002eu,0x000000f5u,0x0000005cu,0x000000f4u,0x00050083u,0x0000002eu,0x000000f6u,0x000000f2u,0x000000f5u,0x00070058u,0x00000037u,0x000000f7u,0x000000f1u,0x000000f6u,0x00000002u,0x0000005cu,0x00050051u,0x0000001bu,0x000000f8u,0x000000f7u,0x00000000u,0x0003003eu,0x000000f0u,0x000000f8u,0x0004003du,0x0000001du,0x000000fau,0x0000001fu,0x0004003du,0x0000002eu,0x000000fbu,0x0000009au,0x00050041u,0x0000005du,0x000000fcu,0x00000030u,0x00000029u,0x0004003du,0x0000001bu,0x000000fdu,0x000000fcu,0x00050050u,0x0000002eu,0x000000feu,0x0000005cu,0x000000fdu,0x00050081u,0x0000002eu,0x000000ffu,0x000000fbu,0x000000feu,0x00070058u,0x00000037u,0x00000100u,0x000000fau,0x000000ffu,0x00000002u,0x0000005cu,0x00050051u,0x0000001bu,0x00000101u,0x00000100u,0x00000000u,0x0003003eu,0x000000f9u,0x00000101u,0x0004003du,0x0000001bu,0x00000103u,0x000000e7u,0x0004003du,0x0000001bu,0x00000104u,0x000000deu,0x00050083u,0x0000001bu,0x00000105u,0x00000103u,0x00000104u,0x00050085u,0x0000001bu,0x00000106u,0x00000105u,0x0000009du,0x00050041u,0x0000005du,0x00000107u,0x00000030u,0x0000000cu,0x0004003du,0x0000001bu,0x00000108u,0x00000107u,0x00050088u,0x0000001bu,0x00000109u,0x00000106u,0x00000108u,0x0003003eu,0x00000102u,0x00000109u,0x0004003du,0x0000001bu,0x0000010bu,0x000000f9u,0x0004003du,0x0000001bu,0x0000010cu,0x000000f0u,0x00050083u,0x0000001bu,0x0000010du,0x0000010bu,0x0000010cu,0x00050085u,0x0000001bu,0x0000010eu,0x0000010du,0x0000009du,0x00050041u,0x0000005du,0x0000010fu,0x00000030u,0x00000029u,0x0004003du,0x0000001bu,0x00000110u,0x0000010fu,0x00050088u,0x0000001bu,0x00000111u,0x0000010eu,0x00000110u,0x0003003eu,0x0000010au,0x00000111u,0x0004003du,0x0000001bu,0x00000113u,0x000000dau,0x0006000cu,0x0000001bu,0x00000114u,0x00000001u,0x00000004u,0x00000113u,0x0003003eu,0x00000112u,0x00000114u,0x0004003du,0x0000001bu,0x00000116u,0x00000112u,0x000500bcu,0x00000012u,0x00000118u,0x00000116u,0x00000117u,0x000300f7u,0x0000011bu,0x00000000u,0x000400fau,0x00000118u,0x0000011au,0x0000011cu,0x000200f8u,0x0000011au,0x0003003eu,0x00000119u,0x00000031u,0x000200f9u,0x0000011bu,0x000200f8u,0x0000011cu,0x0004003du,0x0000001bu,0x0000011du,0x00000112u,0x0007000cu,0x0000001bu,0x0000011fu,0x00000001u,0x00000028u,0x0000011du,0x0000011eu,0x00050088u,0x0000001bu,0x00000120u,0x00000117u,0x0000011fu,0x0003003eu,0x00000119u,0x00000120u,0x000200f9u,0x0000011bu,0x000200f8u,0x0000011bu,0x0004003du,0x0000001bu,0x00000121u,0x00000119u,0x0003003eu,0x00000115u,0x00000121u,0x0004003du,0x0000001bu,0x00000126u,0x00000102u,0x00050041u,0x0000005du,0x00000127u,0x000000a2u,0x0000000cu,0x0004003du,0x0000001bu,0x00000128u,0x00000127u,0x00050085u,0x0000001bu,0x00000129u,0x00000126u,0x00000128u,0x00050041u,0x0000005du,0x0000012au,0x00000125u,0x00000021u,0x0003003eu,0x0000012au,0x00000129u,0x0004003du,0x0000001bu,0x0000012bu,0x0000010au,0x00050041u,0x0000005du,0x0000012cu,0x000000a2u,0x0000000cu,0x0004003du,0x0000001bu,0x0000012du,0x0000012cu,0x00050085u,0x0000001bu,0x0000012eu,0x0000012bu,0x0000012du,0x00050041u,0x0000005du,0x0000012fu,0x00000125u,0x0000004au,0x0003003eu,0x0000012fu,0x0000012eu,0x0004003du,0x0000001bu,0x00000131u,0x00000102u,0x00050041u,0x0000005du,0x00000132u,0x000000a2u,0x00000029u,0x0004003du,0x0000001bu,0x00000133u,0x00000132u,0x00050085u,0x0000001bu,0x00000134u,0x00000131u,0x00000133u,0x00050041u,0x0000005du,0x00000135u,0x00000125u,0x00000130u,0x0003003eu,0x00000135u,0x00000134u,0x0004003du,0x0000001bu,0x00000137u,0x0000010au,0x00050041u,0x0000005du,0x00000138u,0x000000a2u,0x00000029u,0x0004003du,0x0000001bu,0x00000139u,0x00000138u,0x00050085u,0x0000001bu,0x0000013au,0x00000137u,0x00000139u,0x00050041u,0x0000005du,0x0000013bu,0x00000125u,0x00000136u,0x0003003eu,0x0000013bu,0x0000013au,0x0004003du,0x0000001bu,0x0000013du,0x00000102u,0x00050041u,0x0000005du,0x0000013eu,0x00000125u,0x0000013cu,0x0003003eu,0x0000013eu,0x0000013du,0x0004003du,0x0000001bu,0x00000140u,0x0000010au,0x00050041u,0x0000005du,0x00000141u,0x00000125u,0x0000013fu,0x0003003eu,0x00000141u,0x00000140u,0x0003003eu,0x00000142u,0x0000000cu,0x0003003eu,0x00000143u,0x0000000cu,0x000200f9u,0x00000144u,0x000200f8u,0x00000144u,0x000400f6u,0x00000146u,0x00000147u,0x00000000u,0x000200f9u,0x00000148u,0x000200f8u,0x00000148u,0x0004003du,0x00000006u,0x00000149u,0x00000143u,0x000500b0u,0x00000012u,0x0000014au,0x00000149u,0x00000122u,0x000400fau,0x0000014au,0x00000145u,0x00000146u,0x000200f8u,0x00000145u,0x0004003du,0x00000006u,0x0000014cu,0x00000143u,0x0003003eu,0x0000014bu,0x0000014cu,0x000200f9u,0x0000014du,0x000200f8u,0x0000014du,0x000400f6u,0x0000014fu,0x00000150u,0x00000000u,0x000200f9u,0x00000151u,0x000200f8u,0x00000151u,0x0004003du,0x00000006u,0x00000152u,0x0000014bu,0x000500b0u,0x00000012u,0x00000153u,0x00000152u,0x00000122u,0x000400fau,0x00000153u,0x0000014eu,0x0000014fu,0x000200f8u,0x0000014eu,0x0004003du,0x00000006u,0x00000154u,0x00000142u,0x0004003du,0x0000001bu,0x00000155u,0x00000115u,0x0004003du,0x00000006u,0x00000156u,0x00000143u,0x00050041u,0x0000005du,0x00000157u,0x00000125u,0x00000156u,0x0004003du,0x0000001bu,0x00000158u,0x00000157u,0x00050085u,0x0000001bu,0x00000159u,0x00000155u,0x00000158u,0x0004003du,0x00000006u,0x0000015au,0x0000014bu,0x00050041u,0x0000005du,0x0000015bu,0x00000125u,0x0000015au,0x0004003du,0x0000001bu,0x0000015cu,0x0000015bu,0x00050085u,0x0000001bu,0x0000015du,0x00000159u,0x0000015cu,0x00050041u,0x0000005du,0x0000015eu,0x0000005au,0x00000154u,0x0004003du,0x0000001bu,0x0000015fu,0x0000015eu,0x00050081u,0x0000001bu,0x00000160u,0x0000015fu,0x0000015du,0x00050041u,0x0000005du,0x00000161u,0x0000005au,0x00000154u,0x0003003eu,0x00000161u,0x00000160u,0x0004003du,0x00000006u,0x00000162u,0x00000142u,0x00050080u,0x00000006u,0x00000163u,0x00000162u,0x0000004au,0x0003003eu,0x00000142u,0x00000163u,0x000200f9u,0x00000150u,0x000200f8u,0x00000150u,0x0004003du,0x00000006u,0x00000164u,0x0000014bu,0x00050080u,0x00000006u,0x00000165u,0x00000164u,0x0000004au,0x0003003eu,0x0000014bu,0x00000165u,0x000200f9u,0x0000014du,0x000200f8u,0x0000014fu,0x000200f9u,0x00000147u,0x000200f8u,0x00000147u,0x0004003du,0x00000006u,0x00000166u,0x00000143u,0x00050080u,0x00000006u,0x00000167u,0x00000166u,0x0000004au,0x0003003eu,0x00000143u,0x00000167u,0x000200f9u,0x00000144u,0x000200f8u,0x00000146u,0x0004003du,0x0000001bu,0x00000169u,0x00000115u,0x00050041u,0x0000005du,0x0000016au,0x00000125u,0x00000021u,0x0004003du,0x0000001bu,0x0000016bu,0x0000016au,0x00050085u,0x0000001bu,0x0000016cu,0x00000169u,0x0000016bu,0x0004003du,0x0000001bu,0x0000016du,0x000000dau,0x00050085u,0x0000001bu,0x0000016eu,0x0000016cu,0x0000016du,0x00050041u,0x0000005du,0x0000016fu,0x0000005au,0x00000168u,0x0004003du,0x0000001bu,0x00000170u,0x0000016fu,0x00050081u,0x0000001bu,0x00000171u,0x00000170u,0x0000016eu,0x00050041u,0x0000005du,0x00000172u,0x0000005au,0x00000168u,0x0003003eu,0x00000172u,0x00000171u,0x0004003du,0x0000001bu,0x00000174u,0x00000115u,0x00050041u,0x0000005du,0x00000175u,0x00000125u,0x0000004au,0x0004003du,0x0000001bu,0x00000176u,0x00000175u,0x00050085u,0x0000001bu,0x00000177u,0x00000174u,0x00000176u,0x0004003du,0x0000001bu,0x00000178u,0x000000dau,0x00050085u,0x0000001bu,0x00000179u,0x00000177u,0x00000178u,0x00050041u,0x0000005du,0x0000017au,0x0000005au,0x00000173u,0x0004003du,0x0000001bu,0x0000017bu,0x0000017au,0x00050081u,0x0000001bu,0x0000017cu,0x0000017bu,0x00000179u,0x00050041u,0x0000005du,0x0000017du,0x0000005au,0x00000173u,0x0003003eu,0x0000017du,0x0000017cu,0x0004003du,0x0000001bu,0x0000017fu,0x00000115u,0x00050041u,0x0000005du,0x00000180u,0x00000125u,0x00000130u,0x0004003du,0x0000001bu,0x00000181u,0x00000180u,0x00050085u,0x0000001bu,0x00000182u,0x0000017fu,0x00000181u,0x0004003du,0x0000001bu,0x00000183u,0x000000dau,0x00050085u,0x0000001bu,0x00000184u,0x00000182u,0x00000183u,0x00050041u,0x0000005du,0x00000185u,0x0000005au,0x0000017eu,0x0004003du,0x0000001bu,0x00000186u,0x00000185u,0x00050081u,0x0000001bu,0x00000187u,0x00000186u,0x00000184u,0x00050041u,0x0000005du,0x00000188u,0x0000005au,0x0000017eu,0x0003003eu,0x00000188u,0x00000187u,0x0004003du,0x0000001bu,0x0000018au,0x00000115u,0x00050041u,0x0000005du,0x0000018bu,0x00000125u,0x00000136u,0x0004003du,0x0000001bu,0x0000018cu,0x0000018bu,0x00050085u,0x0000001bu,0x0000018du,0x0000018au,0x0000018cu,0x0004003du,0x0000001bu,0x0000018eu,0x000000dau,0x00050085u,0x0000001bu,0x0000018fu,0x0000018du,0x0000018eu,0x00050041u,0x0000005du,0x00000190u,0x0000005au,0x00000189u,0x0004003du,0x0000001bu,0x00000191u,0x00000190u,0x00050081u,0x0000001bu,0x00000192u,0x00000191u,0x0000018fu,0x00050041u,0x0000005du,0x00000193u,0x0000005au,0x00000189u,0x0003003eu,0x00000193u,0x00000192u,0x0004003du,0x0000001bu,0x00000195u,0x00000115u,0x00050041u,0x0000005du,0x00000196u,0x00000125u,0x0000013cu,0x0004003du,0x0000001bu,0x00000197u,0x00000196u,0x00050085u,0x0000001bu,0x00000198u,0x00000195u,0x00000197u,0x0004003du,0x0000001bu,0x00000199u,0x000000dau,0x00050085u,0x0000001bu,0x0000019au,0x00000198u,0x00000199u,0x00050041u,0x0000005du,0x0000019bu,0x0000005au,0x00000194u,0x0004003du,0x0000001bu,0x0000019cu,0x0000019bu,0x00050081u,0x0000001bu,0x0000019du,0x0000019cu,0x0000019au,0x00050041u,0x0000005du,0x0000019eu,0x0000005au,0x00000194u,0x0003003eu,0x0000019eu,0x0000019du,0x0004003du,0x0000001bu,0x000001a0u,0x00000115u,0x00050041u,0x0000005du,0x000001a1u,0x00000125u,0x0000013fu,0x0004003du,0x0000001bu,0x000001a2u,0x000001a1u,0x00050085u,0x0000001bu,0x000001a3u,0x000001a0u,0x000001a2u,0x0004003du,0x0000001bu,0x000001a4u,0x000000dau,0x00050085u,0x0000001bu,0x000001a5u,0x000001a3u,0x000001a4u,0x00050041u,0x0000005du,0x000001a6u,0x0000005au,0x0000019fu,0x0004003du,0x0000001bu,0x000001a7u,0x000001a6u,0x00050081u,0x0000001bu,0x000001a8u,0x000001a7u,0x000001a5u,0x00050041u,0x0000005du,0x000001a9u,0x0000005au,0x0000019fu,0x0003003eu,0x000001a9u,0x000001a8u,0x0004003du,0x0000001bu,0x000001abu,0x00000115u,0x00050041u,0x0000005du,0x000001acu,0x0000005au,0x000001aau,0x0004003du,0x0000001bu,0x000001adu,0x000001acu,0x00050081u,0x0000001bu,0x000001aeu,0x000001adu,0x000001abu,0x00050041u,0x0000005du,0x000001afu,0x0000005au,0x000001aau,0x0003003eu,0x000001afu,0x000001aeu,0x0004003du,0x0000001bu,0x000001b1u,0x00000115u,0x0004003du,0x0000001bu,0x000001b2u,0x000000dau,0x00050085u,0x0000001bu,0x000001b3u,0x000001b1u,0x000001b2u,0x0004003du,0x0000001bu,0x000001b4u,0x000000dau,0x00050085u,0x0000001bu,0x000001b5u,0x000001b3u,0x000001b4u,0x00050041u,0x0000005du,0x000001b6u,0x0000005au,0x000001b0u,0x0004003du,0x0000001bu,0x000001b7u,0x000001b6u,0x00050081u,0x0000001bu,0x000001b8u,0x000001b7u,0x000001b5u,0x00050041u,0x0000005du,0x000001b9u,0x0000005au,0x000001b0u,0x0003003eu,0x000001b9u,0x000001b8u,0x000200f9u,0x00000066u,0x000200f8u,0x00000066u,0x0004003du,0x00000006u,0x000001bau,0x00000061u,0x00050080u,0x00000006u,0x000001bbu,0x000001bau,0x00000011u,0x0003003eu,0x00000061u,0x000001bbu,0x000200f9u,0x00000063u,0x000200f8u,0x00000065u,0x0004003du,0x00000006u,0x000001bdu,0x00000008u,0x00050084u,0x00000006u,0x000001beu,0x000001bdu,0x00000056u,0x0003003eu,0x000001bcu,0x000001beu,0x0003003eu,0x000001bfu,0x0000000cu,0x000200f9u,0x000001c0u,0x000200f8u,0x000001c0u,0x000400f6u,0x000001c2u,0x000001c3u,0x00000000u,0x000200f9u,0x000001c4u,0x000200f8u,0x000001c4u,0x0004003du,0x00000006u,0x000001c5u,0x000001bfu,0x000500b0u,0x00000012u,0x000001c6u,0x000001c5u,0x00000056u,0x000400fau,0x000001c6u,0x000001c1u,0x000001c2u,0x000200f8u,0x000001c1u,0x0004003du,0x00000006u,0x000001cbu,0x000001bcu,0x0004003du,0x00000006u,0x000001ccu,0x000001bfu,0x00050080u,0x00000006u,0x000001cdu,0x000001cbu,0x000001ccu,0x0004003du,0x00000006u,0x000001ceu,0x000001bfu,0x00050041u,0x0000005du,0x000001cfu,0x0000005au,0x000001ceu,0x0004003du,0x0000001bu,0x000001d0u,0x000001cfu,0x00060041u,0x000001d1u,0x000001d2u,0x000001cau,0x00000021u,0x000001cdu,0x0003003eu,0x000001d2u,0x000001d0u,0x000200f9u,0x000001c3u,0x000200f8u,0x000001c3u,0x0004003du,0x00000006u,0x000001d3u,0x000001bfu,0x00050080u,0x00000006u,0x000001d4u,0x000001d3u,0x0000004au,0x0003003eu,0x000001bfu,0x000001d4u,0x000200f9u,0x000001c0u,0x000200f8u,0x000001c2u,0x000100fdu,0x00010038u}; +static const size_t OF3_GM_REDUCE_LEN = 2584; +static const uint32_t OF3_GM_PREWARP_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000074u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00030005u,0x00000030u,0x00007675u,0x00030005u,0x00000039u,0x00000071u,0x00040005u,0x0000003du,0x6c6f6370u,0x00000030u,0x00030005u,0x0000003fu,0x00004d47u,0x00050006u,0x0000003fu,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x0000003fu,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x0000003fu,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x0000003fu,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x00000041u,0x00000000u,0x00040005u,0x00000049u,0x6c6f6370u,0x00000031u,0x00040005u,0x00000051u,0x72537675u,0x00000063u,0x00030005u,0x00000064u,0x00000076u,0x00040005u,0x00000068u,0x72754375u,0x00000072u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00030047u,0x0000003fu,0x00000002u,0x00050048u,0x0000003fu,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x0000003fu,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x0000003fu,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x0000003fu,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x00000041u,0x00000021u,0x00000001u,0x00040047u,0x00000041u,0x00000022u,0x00000000u,0x00040047u,0x00000068u,0x00000021u,0x00000020u,0x00040047u,0x00000068u,0x00000022u,0x00000000u,0x00040047u,0x00000073u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000033u,0x3f000000u,0x00040017u,0x0000003eu,0x00000013u,0x00000004u,0x0006001eu,0x0000003fu,0x0000003eu,0x0000003eu,0x0000003eu,0x0000003eu,0x00040020u,0x00000040u,0x00000002u,0x0000003fu,0x0004003bu,0x00000040u,0x00000041u,0x00000002u,0x0004002bu,0x00000006u,0x00000042u,0x00000002u,0x00040020u,0x00000043u,0x00000002u,0x00000013u,0x0004002bu,0x0000000au,0x0000004au,0x00000002u,0x0004002bu,0x0000000au,0x0000004du,0x00000003u,0x00040020u,0x00000054u,0x00000007u,0x00000013u,0x0004002bu,0x00000006u,0x0000005eu,0x00000003u,0x00040020u,0x0000005fu,0x00000002u,0x0000003eu,0x00090019u,0x00000065u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000066u,0x00000065u,0x00040020u,0x00000067u,0x00000000u,0x00000066u,0x0004003bu,0x00000067u,0x00000068u,0x00000000u,0x0004002bu,0x00000013u,0x0000006bu,0x00000000u,0x0004002bu,0x0000000au,0x00000072u,0x00000010u,0x0006002cu,0x0000000bu,0x00000073u,0x00000072u,0x00000072u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x00000039u,0x00000007u,0x0004003bu,0x0000002fu,0x0000003du,0x00000007u,0x0004003bu,0x0000002fu,0x00000049u,0x00000007u,0x0004003bu,0x0000002fu,0x00000051u,0x00000007u,0x0004003bu,0x00000054u,0x00000064u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000007u,0x00000031u,0x00000009u,0x0004006fu,0x0000002eu,0x00000032u,0x00000031u,0x00050050u,0x0000002eu,0x00000034u,0x00000033u,0x00000033u,0x00050081u,0x0000002eu,0x00000035u,0x00000032u,0x00000034u,0x0004003du,0x00000007u,0x00000036u,0x00000012u,0x0004006fu,0x0000002eu,0x00000037u,0x00000036u,0x00050088u,0x0000002eu,0x00000038u,0x00000035u,0x00000037u,0x0003003eu,0x00000030u,0x00000038u,0x0004003du,0x0000002eu,0x0000003au,0x00000030u,0x00050050u,0x0000002eu,0x0000003bu,0x00000033u,0x00000033u,0x00050083u,0x0000002eu,0x0000003cu,0x0000003au,0x0000003bu,0x0003003eu,0x00000039u,0x0000003cu,0x00060041u,0x00000043u,0x00000044u,0x00000041u,0x00000042u,0x0000001au,0x0004003du,0x00000013u,0x00000045u,0x00000044u,0x00060041u,0x00000043u,0x00000046u,0x00000041u,0x00000042u,0x00000024u,0x0004003du,0x00000013u,0x00000047u,0x00000046u,0x00050050u,0x0000002eu,0x00000048u,0x00000045u,0x00000047u,0x0003003eu,0x0000003du,0x00000048u,0x00060041u,0x00000043u,0x0000004bu,0x00000041u,0x00000042u,0x0000004au,0x0004003du,0x00000013u,0x0000004cu,0x0000004bu,0x00060041u,0x00000043u,0x0000004eu,0x00000041u,0x00000042u,0x0000004du,0x0004003du,0x00000013u,0x0000004fu,0x0000004eu,0x00050050u,0x0000002eu,0x00000050u,0x0000004cu,0x0000004fu,0x0003003eu,0x00000049u,0x00000050u,0x0004003du,0x0000002eu,0x00000052u,0x00000030u,0x0004003du,0x0000002eu,0x00000053u,0x0000003du,0x00050041u,0x00000054u,0x00000055u,0x00000039u,0x0000001au,0x0004003du,0x00000013u,0x00000056u,0x00000055u,0x0005008eu,0x0000002eu,0x00000057u,0x00000053u,0x00000056u,0x00050081u,0x0000002eu,0x00000058u,0x00000052u,0x00000057u,0x0004003du,0x0000002eu,0x00000059u,0x00000049u,0x00050041u,0x00000054u,0x0000005au,0x00000039u,0x00000024u,0x0004003du,0x00000013u,0x0000005bu,0x0000005au,0x0005008eu,0x0000002eu,0x0000005cu,0x00000059u,0x0000005bu,0x00050081u,0x0000002eu,0x0000005du,0x00000058u,0x0000005cu,0x00050041u,0x0000005fu,0x00000060u,0x00000041u,0x0000005eu,0x0004003du,0x0000003eu,0x00000061u,0x00000060u,0x0007004fu,0x0000002eu,0x00000062u,0x00000061u,0x00000061u,0x00000000u,0x00000001u,0x00050081u,0x0000002eu,0x00000063u,0x0000005du,0x00000062u,0x0003003eu,0x00000051u,0x00000063u,0x0004003du,0x00000066u,0x00000069u,0x00000068u,0x0004003du,0x0000002eu,0x0000006au,0x00000051u,0x00070058u,0x0000003eu,0x0000006cu,0x00000069u,0x0000006au,0x00000002u,0x0000006bu,0x00050051u,0x00000013u,0x0000006du,0x0000006cu,0x00000000u,0x0003003eu,0x00000064u,0x0000006du,0x0004003du,0x00000014u,0x0000006eu,0x00000016u,0x0004003du,0x00000007u,0x0000006fu,0x00000009u,0x0004003du,0x00000013u,0x00000070u,0x00000064u,0x00070050u,0x0000003eu,0x00000071u,0x00000070u,0x0000006bu,0x0000006bu,0x0000006bu,0x00040063u,0x0000006eu,0x0000006fu,0x00000071u,0x000100fdu,0x00010038u}; +static const size_t OF3_GM_PREWARP_LEN = 706; +static const uint32_t OF3_FLOWREG_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000144u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000037u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00060005u,0x0000000eu,0x63746566u,0x76285568u,0x763b3269u,0x003b3269u,0x00030005u,0x0000000cu,0x00000070u,0x00030005u,0x0000000du,0x006d6964u,0x00060005u,0x00000013u,0x63746566u,0x76284c68u,0x763b3269u,0x003b3269u,0x00030005u,0x00000011u,0x00000070u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000018u,0x6f6c4675u,0x006e4977u,0x00040005u,0x00000026u,0x6d754c75u,0x00000061u,0x00030005u,0x00000034u,0x00646967u,0x00080005u,0x00000037u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000003cu,0x006d6964u,0x00030005u,0x00000055u,0x00007464u,0x00030005u,0x00000056u,0x00000055u,0x00050006u,0x00000056u,0x00000000u,0x61726170u,0x0000736du,0x00030005u,0x00000058u,0x00000000u,0x00040005u,0x0000005cu,0x626d616cu,0x00006164u,0x00050005u,0x0000005fu,0x65676465u,0x68706c41u,0x00000061u,0x00040005u,0x00000063u,0x54737065u,0x00000056u,0x00030005u,0x00000068u,0x00004375u,0x00040005u,0x00000069u,0x61726170u,0x0000006du,0x00040005u,0x0000006bu,0x61726170u,0x0000006du,0x00030005u,0x0000006eu,0x00004c75u,0x00040005u,0x00000073u,0x61726170u,0x0000006du,0x00040005u,0x00000074u,0x61726170u,0x0000006du,0x00030005u,0x00000077u,0x00005275u,0x00040005u,0x0000007bu,0x61726170u,0x0000006du,0x00040005u,0x0000007cu,0x61726170u,0x0000006du,0x00030005u,0x0000007fu,0x00005575u,0x00040005u,0x00000083u,0x61726170u,0x0000006du,0x00040005u,0x00000084u,0x61726170u,0x0000006du,0x00030005u,0x00000087u,0x00004475u,0x00040005u,0x0000008bu,0x61726170u,0x0000006du,0x00040005u,0x0000008cu,0x61726170u,0x0000006du,0x00040005u,0x0000008fu,0x6d69646cu,0x00000000u,0x00030005u,0x00000093u,0x00004c6cu,0x00040005u,0x00000096u,0x61726170u,0x0000006du,0x00040005u,0x00000097u,0x61726170u,0x0000006du,0x00030005u,0x0000009au,0x0000526cu,0x00040005u,0x0000009du,0x61726170u,0x0000006du,0x00040005u,0x0000009eu,0x61726170u,0x0000006du,0x00030005u,0x000000a1u,0x0000556cu,0x00040005u,0x000000a4u,0x61726170u,0x0000006du,0x00040005u,0x000000a5u,0x61726170u,0x0000006du,0x00030005u,0x000000a8u,0x0000446cu,0x00040005u,0x000000abu,0x61726170u,0x0000006du,0x00040005u,0x000000acu,0x61726170u,0x0000006du,0x00040005u,0x000000afu,0x67616d67u,0x00000000u,0x00030005u,0x000000bbu,0x00000067u,0x00030005u,0x000000c4u,0x00004c64u,0x00030005u,0x000000c8u,0x00005264u,0x00030005u,0x000000ccu,0x00005564u,0x00030005u,0x000000d0u,0x00004464u,0x00030005u,0x000000d4u,0x00003265u,0x00030005u,0x000000d8u,0x00004c77u,0x00030005u,0x000000e1u,0x00005277u,0x00030005u,0x000000eau,0x00005577u,0x00030005u,0x000000f3u,0x00004477u,0x00040005u,0x000000fcu,0x576d7573u,0x00000000u,0x00040005u,0x00000104u,0x576d7573u,0x00000055u,0x00040005u,0x00000114u,0x66694475u,0x00000066u,0x00030005u,0x00000120u,0x00003066u,0x00050005u,0x00000121u,0x6f6c4675u,0x73624f77u,0x00000000u,0x00040005u,0x0000012au,0x74656874u,0x00000061u,0x00030005u,0x0000012eu,0x00000072u,0x00040005u,0x00000132u,0x77654e75u,0x00000000u,0x00050005u,0x0000013eu,0x6f6c4675u,0x74754f77u,0x00000000u,0x00040047u,0x00000018u,0x00000021u,0x00000020u,0x00040047u,0x00000018u,0x00000022u,0x00000000u,0x00040047u,0x00000026u,0x00000021u,0x00000022u,0x00040047u,0x00000026u,0x00000022u,0x00000000u,0x00040047u,0x00000037u,0x0000000bu,0x0000001cu,0x00030047u,0x00000056u,0x00000002u,0x00050048u,0x00000056u,0x00000000u,0x00000023u,0x00000000u,0x00040047u,0x00000058u,0x00000021u,0x00000000u,0x00040047u,0x00000058u,0x00000022u,0x00000000u,0x00040047u,0x00000121u,0x00000021u,0x00000021u,0x00040047u,0x00000121u,0x00000022u,0x00000000u,0x00030047u,0x0000013eu,0x00000019u,0x00040047u,0x0000013eu,0x00000021u,0x00000030u,0x00040047u,0x0000013eu,0x00000022u,0x00000000u,0x00040047u,0x00000143u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00030016u,0x00000009u,0x00000020u,0x00040017u,0x0000000au,0x00000009u,0x00000004u,0x00050021u,0x0000000bu,0x0000000au,0x00000008u,0x00000008u,0x00050021u,0x00000010u,0x00000009u,0x00000008u,0x00000008u,0x00090019u,0x00000015u,0x00000009u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000016u,0x00000015u,0x00040020u,0x00000017u,0x00000000u,0x00000016u,0x0004003bu,0x00000017u,0x00000018u,0x00000000u,0x0004002bu,0x00000006u,0x0000001bu,0x00000000u,0x0005002cu,0x00000007u,0x0000001cu,0x0000001bu,0x0000001bu,0x0004002bu,0x00000006u,0x0000001eu,0x00000001u,0x0004003bu,0x00000017u,0x00000026u,0x00000000u,0x00040015u,0x0000002fu,0x00000020u,0x00000000u,0x0004002bu,0x0000002fu,0x00000030u,0x00000000u,0x00040017u,0x00000035u,0x0000002fu,0x00000003u,0x00040020u,0x00000036u,0x00000001u,0x00000035u,0x0004003bu,0x00000036u,0x00000037u,0x00000001u,0x00040017u,0x00000038u,0x0000002fu,0x00000002u,0x00020014u,0x00000040u,0x00040020u,0x00000041u,0x00000007u,0x00000006u,0x0004002bu,0x0000002fu,0x0000004au,0x00000001u,0x00040020u,0x00000054u,0x00000007u,0x00000009u,0x0003001eu,0x00000056u,0x0000000au,0x00040020u,0x00000057u,0x00000002u,0x00000056u,0x0004003bu,0x00000057u,0x00000058u,0x00000002u,0x00040020u,0x00000059u,0x00000002u,0x00000009u,0x0004002bu,0x0000002fu,0x00000060u,0x00000002u,0x0004002bu,0x0000002fu,0x00000064u,0x00000003u,0x00040020u,0x00000067u,0x00000007u,0x0000000au,0x0004002bu,0x00000006u,0x00000070u,0xffffffffu,0x0005002cu,0x00000007u,0x00000071u,0x00000070u,0x0000001bu,0x0005002cu,0x00000007u,0x00000079u,0x0000001eu,0x0000001bu,0x0005002cu,0x00000007u,0x00000081u,0x0000001bu,0x00000070u,0x0005002cu,0x00000007u,0x00000089u,0x0000001bu,0x0000001eu,0x0004002bu,0x00000009u,0x000000b0u,0x3f000000u,0x00040017u,0x000000b7u,0x00000009u,0x00000002u,0x0004002bu,0x00000009u,0x000000c1u,0x3d4ccccdu,0x0004002bu,0x00000009u,0x000000c2u,0x3f800000u,0x0004003bu,0x00000017u,0x00000121u,0x00000000u,0x00090019u,0x0000013cu,0x00000009u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x0000013du,0x00000000u,0x0000013cu,0x0004003bu,0x0000013du,0x0000013eu,0x00000000u,0x0004002bu,0x0000002fu,0x00000142u,0x00000010u,0x0006002cu,0x00000035u,0x00000143u,0x00000142u,0x00000142u,0x0000004au,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000034u,0x00000007u,0x0004003bu,0x00000008u,0x0000003cu,0x00000007u,0x0004003bu,0x00000054u,0x00000055u,0x00000007u,0x0004003bu,0x00000054u,0x0000005cu,0x00000007u,0x0004003bu,0x00000054u,0x0000005fu,0x00000007u,0x0004003bu,0x00000054u,0x00000063u,0x00000007u,0x0004003bu,0x00000067u,0x00000068u,0x00000007u,0x0004003bu,0x00000008u,0x00000069u,0x00000007u,0x0004003bu,0x00000008u,0x0000006bu,0x00000007u,0x0004003bu,0x00000067u,0x0000006eu,0x00000007u,0x0004003bu,0x00000008u,0x00000073u,0x00000007u,0x0004003bu,0x00000008u,0x00000074u,0x00000007u,0x0004003bu,0x00000067u,0x00000077u,0x00000007u,0x0004003bu,0x00000008u,0x0000007bu,0x00000007u,0x0004003bu,0x00000008u,0x0000007cu,0x00000007u,0x0004003bu,0x00000067u,0x0000007fu,0x00000007u,0x0004003bu,0x00000008u,0x00000083u,0x00000007u,0x0004003bu,0x00000008u,0x00000084u,0x00000007u,0x0004003bu,0x00000067u,0x00000087u,0x00000007u,0x0004003bu,0x00000008u,0x0000008bu,0x00000007u,0x0004003bu,0x00000008u,0x0000008cu,0x00000007u,0x0004003bu,0x00000008u,0x0000008fu,0x00000007u,0x0004003bu,0x00000054u,0x00000093u,0x00000007u,0x0004003bu,0x00000008u,0x00000096u,0x00000007u,0x0004003bu,0x00000008u,0x00000097u,0x00000007u,0x0004003bu,0x00000054u,0x0000009au,0x00000007u,0x0004003bu,0x00000008u,0x0000009du,0x00000007u,0x0004003bu,0x00000008u,0x0000009eu,0x00000007u,0x0004003bu,0x00000054u,0x000000a1u,0x00000007u,0x0004003bu,0x00000008u,0x000000a4u,0x00000007u,0x0004003bu,0x00000008u,0x000000a5u,0x00000007u,0x0004003bu,0x00000054u,0x000000a8u,0x00000007u,0x0004003bu,0x00000008u,0x000000abu,0x00000007u,0x0004003bu,0x00000008u,0x000000acu,0x00000007u,0x0004003bu,0x00000054u,0x000000afu,0x00000007u,0x0004003bu,0x00000054u,0x000000bbu,0x00000007u,0x0004003bu,0x00000067u,0x000000c4u,0x00000007u,0x0004003bu,0x00000067u,0x000000c8u,0x00000007u,0x0004003bu,0x00000067u,0x000000ccu,0x00000007u,0x0004003bu,0x00000067u,0x000000d0u,0x00000007u,0x0004003bu,0x00000054u,0x000000d4u,0x00000007u,0x0004003bu,0x00000054u,0x000000d8u,0x00000007u,0x0004003bu,0x00000054u,0x000000e1u,0x00000007u,0x0004003bu,0x00000054u,0x000000eau,0x00000007u,0x0004003bu,0x00000054u,0x000000f3u,0x00000007u,0x0004003bu,0x00000054u,0x000000fcu,0x00000007u,0x0004003bu,0x00000067u,0x00000104u,0x00000007u,0x0004003bu,0x00000067u,0x00000114u,0x00000007u,0x0004003bu,0x00000067u,0x00000120u,0x00000007u,0x0004003bu,0x00000054u,0x0000012au,0x00000007u,0x0004003bu,0x00000067u,0x0000012eu,0x00000007u,0x0004003bu,0x00000067u,0x00000132u,0x00000007u,0x0004003du,0x00000035u,0x00000039u,0x00000037u,0x0007004fu,0x00000038u,0x0000003au,0x00000039u,0x00000039u,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x0000003bu,0x0000003au,0x0003003eu,0x00000034u,0x0000003bu,0x0004003du,0x00000016u,0x0000003du,0x00000018u,0x00040064u,0x00000015u,0x0000003eu,0x0000003du,0x00050067u,0x00000007u,0x0000003fu,0x0000003eu,0x0000001bu,0x0003003eu,0x0000003cu,0x0000003fu,0x00050041u,0x00000041u,0x00000042u,0x00000034u,0x00000030u,0x0004003du,0x00000006u,0x00000043u,0x00000042u,0x00050041u,0x00000041u,0x00000044u,0x0000003cu,0x00000030u,0x0004003du,0x00000006u,0x00000045u,0x00000044u,0x000500afu,0x00000040u,0x00000046u,0x00000043u,0x00000045u,0x000400a8u,0x00000040u,0x00000047u,0x00000046u,0x000300f7u,0x00000049u,0x00000000u,0x000400fau,0x00000047u,0x00000048u,0x00000049u,0x000200f8u,0x00000048u,0x00050041u,0x00000041u,0x0000004bu,0x00000034u,0x0000004au,0x0004003du,0x00000006u,0x0000004cu,0x0000004bu,0x00050041u,0x00000041u,0x0000004du,0x0000003cu,0x0000004au,0x0004003du,0x00000006u,0x0000004eu,0x0000004du,0x000500afu,0x00000040u,0x0000004fu,0x0000004cu,0x0000004eu,0x000200f9u,0x00000049u,0x000200f8u,0x00000049u,0x000700f5u,0x00000040u,0x00000050u,0x00000046u,0x00000005u,0x0000004fu,0x00000048u,0x000300f7u,0x00000052u,0x00000000u,0x000400fau,0x00000050u,0x00000051u,0x00000052u,0x000200f8u,0x00000051u,0x000100fdu,0x000200f8u,0x00000052u,0x00060041u,0x00000059u,0x0000005au,0x00000058u,0x0000001bu,0x00000030u,0x0004003du,0x00000009u,0x0000005bu,0x0000005au,0x0003003eu,0x00000055u,0x0000005bu,0x00060041u,0x00000059u,0x0000005du,0x00000058u,0x0000001bu,0x0000004au,0x0004003du,0x00000009u,0x0000005eu,0x0000005du,0x0003003eu,0x0000005cu,0x0000005eu,0x00060041u,0x00000059u,0x00000061u,0x00000058u,0x0000001bu,0x00000060u,0x0004003du,0x00000009u,0x00000062u,0x00000061u,0x0003003eu,0x0000005fu,0x00000062u,0x00060041u,0x00000059u,0x00000065u,0x00000058u,0x0000001bu,0x00000064u,0x0004003du,0x00000009u,0x00000066u,0x00000065u,0x0003003eu,0x00000063u,0x00000066u,0x0004003du,0x00000007u,0x0000006au,0x00000034u,0x0003003eu,0x00000069u,0x0000006au,0x0004003du,0x00000007u,0x0000006cu,0x0000003cu,0x0003003eu,0x0000006bu,0x0000006cu,0x00060039u,0x0000000au,0x0000006du,0x0000000eu,0x00000069u,0x0000006bu,0x0003003eu,0x00000068u,0x0000006du,0x0004003du,0x00000007u,0x0000006fu,0x00000034u,0x00050080u,0x00000007u,0x00000072u,0x0000006fu,0x00000071u,0x0003003eu,0x00000073u,0x00000072u,0x0004003du,0x00000007u,0x00000075u,0x0000003cu,0x0003003eu,0x00000074u,0x00000075u,0x00060039u,0x0000000au,0x00000076u,0x0000000eu,0x00000073u,0x00000074u,0x0003003eu,0x0000006eu,0x00000076u,0x0004003du,0x00000007u,0x00000078u,0x00000034u,0x00050080u,0x00000007u,0x0000007au,0x00000078u,0x00000079u,0x0003003eu,0x0000007bu,0x0000007au,0x0004003du,0x00000007u,0x0000007du,0x0000003cu,0x0003003eu,0x0000007cu,0x0000007du,0x00060039u,0x0000000au,0x0000007eu,0x0000000eu,0x0000007bu,0x0000007cu,0x0003003eu,0x00000077u,0x0000007eu,0x0004003du,0x00000007u,0x00000080u,0x00000034u,0x00050080u,0x00000007u,0x00000082u,0x00000080u,0x00000081u,0x0003003eu,0x00000083u,0x00000082u,0x0004003du,0x00000007u,0x00000085u,0x0000003cu,0x0003003eu,0x00000084u,0x00000085u,0x00060039u,0x0000000au,0x00000086u,0x0000000eu,0x00000083u,0x00000084u,0x0003003eu,0x0000007fu,0x00000086u,0x0004003du,0x00000007u,0x00000088u,0x00000034u,0x00050080u,0x00000007u,0x0000008au,0x00000088u,0x00000089u,0x0003003eu,0x0000008bu,0x0000008au,0x0004003du,0x00000007u,0x0000008du,0x0000003cu,0x0003003eu,0x0000008cu,0x0000008du,0x00060039u,0x0000000au,0x0000008eu,0x0000000eu,0x0000008bu,0x0000008cu,0x0003003eu,0x00000087u,0x0000008eu,0x0004003du,0x00000016u,0x00000090u,0x00000026u,0x00040064u,0x00000015u,0x00000091u,0x00000090u,0x00050067u,0x00000007u,0x00000092u,0x00000091u,0x0000001bu,0x0003003eu,0x0000008fu,0x00000092u,0x0004003du,0x00000007u,0x00000094u,0x00000034u,0x00050080u,0x00000007u,0x00000095u,0x00000094u,0x00000071u,0x0003003eu,0x00000096u,0x00000095u,0x0004003du,0x00000007u,0x00000098u,0x0000008fu,0x0003003eu,0x00000097u,0x00000098u,0x00060039u,0x00000009u,0x00000099u,0x00000013u,0x00000096u,0x00000097u,0x0003003eu,0x00000093u,0x00000099u,0x0004003du,0x00000007u,0x0000009bu,0x00000034u,0x00050080u,0x00000007u,0x0000009cu,0x0000009bu,0x00000079u,0x0003003eu,0x0000009du,0x0000009cu,0x0004003du,0x00000007u,0x0000009fu,0x0000008fu,0x0003003eu,0x0000009eu,0x0000009fu,0x00060039u,0x00000009u,0x000000a0u,0x00000013u,0x0000009du,0x0000009eu,0x0003003eu,0x0000009au,0x000000a0u,0x0004003du,0x00000007u,0x000000a2u,0x00000034u,0x00050080u,0x00000007u,0x000000a3u,0x000000a2u,0x00000081u,0x0003003eu,0x000000a4u,0x000000a3u,0x0004003du,0x00000007u,0x000000a6u,0x0000008fu,0x0003003eu,0x000000a5u,0x000000a6u,0x00060039u,0x00000009u,0x000000a7u,0x00000013u,0x000000a4u,0x000000a5u,0x0003003eu,0x000000a1u,0x000000a7u,0x0004003du,0x00000007u,0x000000a9u,0x00000034u,0x00050080u,0x00000007u,0x000000aau,0x000000a9u,0x00000089u,0x0003003eu,0x000000abu,0x000000aau,0x0004003du,0x00000007u,0x000000adu,0x0000008fu,0x0003003eu,0x000000acu,0x000000adu,0x00060039u,0x00000009u,0x000000aeu,0x00000013u,0x000000abu,0x000000acu,0x0003003eu,0x000000a8u,0x000000aeu,0x0004003du,0x00000009u,0x000000b1u,0x0000009au,0x0004003du,0x00000009u,0x000000b2u,0x00000093u,0x00050083u,0x00000009u,0x000000b3u,0x000000b1u,0x000000b2u,0x0004003du,0x00000009u,0x000000b4u,0x000000a8u,0x0004003du,0x00000009u,0x000000b5u,0x000000a1u,0x00050083u,0x00000009u,0x000000b6u,0x000000b4u,0x000000b5u,0x00050050u,0x000000b7u,0x000000b8u,0x000000b3u,0x000000b6u,0x0006000cu,0x00000009u,0x000000b9u,0x00000001u,0x00000042u,0x000000b8u,0x00050085u,0x00000009u,0x000000bau,0x000000b0u,0x000000b9u,0x0003003eu,0x000000afu,0x000000bau,0x0004003du,0x00000009u,0x000000bcu,0x0000005fu,0x0004007fu,0x00000009u,0x000000bdu,0x000000bcu,0x0004003du,0x00000009u,0x000000beu,0x000000afu,0x00050085u,0x00000009u,0x000000bfu,0x000000bdu,0x000000beu,0x0006000cu,0x00000009u,0x000000c0u,0x00000001u,0x0000001bu,0x000000bfu,0x0008000cu,0x00000009u,0x000000c3u,0x00000001u,0x0000002bu,0x000000c0u,0x000000c1u,0x000000c2u,0x0003003eu,0x000000bbu,0x000000c3u,0x0004003du,0x0000000au,0x000000c5u,0x0000006eu,0x0004003du,0x0000000au,0x000000c6u,0x00000068u,0x00050083u,0x0000000au,0x000000c7u,0x000000c5u,0x000000c6u,0x0003003eu,0x000000c4u,0x000000c7u,0x0004003du,0x0000000au,0x000000c9u,0x00000077u,0x0004003du,0x0000000au,0x000000cau,0x00000068u,0x00050083u,0x0000000au,0x000000cbu,0x000000c9u,0x000000cau,0x0003003eu,0x000000c8u,0x000000cbu,0x0004003du,0x0000000au,0x000000cdu,0x0000007fu,0x0004003du,0x0000000au,0x000000ceu,0x00000068u,0x00050083u,0x0000000au,0x000000cfu,0x000000cdu,0x000000ceu,0x0003003eu,0x000000ccu,0x000000cfu,0x0004003du,0x0000000au,0x000000d1u,0x00000087u,0x0004003du,0x0000000au,0x000000d2u,0x00000068u,0x00050083u,0x0000000au,0x000000d3u,0x000000d1u,0x000000d2u,0x0003003eu,0x000000d0u,0x000000d3u,0x0004003du,0x00000009u,0x000000d5u,0x00000063u,0x0004003du,0x00000009u,0x000000d6u,0x00000063u,0x00050085u,0x00000009u,0x000000d7u,0x000000d5u,0x000000d6u,0x0003003eu,0x000000d4u,0x000000d7u,0x0004003du,0x00000009u,0x000000d9u,0x000000bbu,0x0004003du,0x0000000au,0x000000dau,0x000000c4u,0x0004003du,0x0000000au,0x000000dbu,0x000000c4u,0x00050094u,0x00000009u,0x000000dcu,0x000000dau,0x000000dbu,0x0004003du,0x00000009u,0x000000ddu,0x000000d4u,0x00050081u,0x00000009u,0x000000deu,0x000000dcu,0x000000ddu,0x0006000cu,0x00000009u,0x000000dfu,0x00000001u,0x00000020u,0x000000deu,0x00050085u,0x00000009u,0x000000e0u,0x000000d9u,0x000000dfu,0x0003003eu,0x000000d8u,0x000000e0u,0x0004003du,0x00000009u,0x000000e2u,0x000000bbu,0x0004003du,0x0000000au,0x000000e3u,0x000000c8u,0x0004003du,0x0000000au,0x000000e4u,0x000000c8u,0x00050094u,0x00000009u,0x000000e5u,0x000000e3u,0x000000e4u,0x0004003du,0x00000009u,0x000000e6u,0x000000d4u,0x00050081u,0x00000009u,0x000000e7u,0x000000e5u,0x000000e6u,0x0006000cu,0x00000009u,0x000000e8u,0x00000001u,0x00000020u,0x000000e7u,0x00050085u,0x00000009u,0x000000e9u,0x000000e2u,0x000000e8u,0x0003003eu,0x000000e1u,0x000000e9u,0x0004003du,0x00000009u,0x000000ebu,0x000000bbu,0x0004003du,0x0000000au,0x000000ecu,0x000000ccu,0x0004003du,0x0000000au,0x000000edu,0x000000ccu,0x00050094u,0x00000009u,0x000000eeu,0x000000ecu,0x000000edu,0x0004003du,0x00000009u,0x000000efu,0x000000d4u,0x00050081u,0x00000009u,0x000000f0u,0x000000eeu,0x000000efu,0x0006000cu,0x00000009u,0x000000f1u,0x00000001u,0x00000020u,0x000000f0u,0x00050085u,0x00000009u,0x000000f2u,0x000000ebu,0x000000f1u,0x0003003eu,0x000000eau,0x000000f2u,0x0004003du,0x00000009u,0x000000f4u,0x000000bbu,0x0004003du,0x0000000au,0x000000f5u,0x000000d0u,0x0004003du,0x0000000au,0x000000f6u,0x000000d0u,0x00050094u,0x00000009u,0x000000f7u,0x000000f5u,0x000000f6u,0x0004003du,0x00000009u,0x000000f8u,0x000000d4u,0x00050081u,0x00000009u,0x000000f9u,0x000000f7u,0x000000f8u,0x0006000cu,0x00000009u,0x000000fau,0x00000001u,0x00000020u,0x000000f9u,0x00050085u,0x00000009u,0x000000fbu,0x000000f4u,0x000000fau,0x0003003eu,0x000000f3u,0x000000fbu,0x0004003du,0x00000009u,0x000000fdu,0x000000d8u,0x0004003du,0x00000009u,0x000000feu,0x000000e1u,0x00050081u,0x00000009u,0x000000ffu,0x000000fdu,0x000000feu,0x0004003du,0x00000009u,0x00000100u,0x000000eau,0x00050081u,0x00000009u,0x00000101u,0x000000ffu,0x00000100u,0x0004003du,0x00000009u,0x00000102u,0x000000f3u,0x00050081u,0x00000009u,0x00000103u,0x00000101u,0x00000102u,0x0003003eu,0x000000fcu,0x00000103u,0x0004003du,0x00000009u,0x00000105u,0x000000d8u,0x0004003du,0x0000000au,0x00000106u,0x0000006eu,0x0005008eu,0x0000000au,0x00000107u,0x00000106u,0x00000105u,0x0004003du,0x00000009u,0x00000108u,0x000000e1u,0x0004003du,0x0000000au,0x00000109u,0x00000077u,0x0005008eu,0x0000000au,0x0000010au,0x00000109u,0x00000108u,0x00050081u,0x0000000au,0x0000010bu,0x00000107u,0x0000010au,0x0004003du,0x00000009u,0x0000010cu,0x000000eau,0x0004003du,0x0000000au,0x0000010du,0x0000007fu,0x0005008eu,0x0000000au,0x0000010eu,0x0000010du,0x0000010cu,0x00050081u,0x0000000au,0x0000010fu,0x0000010bu,0x0000010eu,0x0004003du,0x00000009u,0x00000110u,0x000000f3u,0x0004003du,0x0000000au,0x00000111u,0x00000087u,0x0005008eu,0x0000000au,0x00000112u,0x00000111u,0x00000110u,0x00050081u,0x0000000au,0x00000113u,0x0000010fu,0x00000112u,0x0003003eu,0x00000104u,0x00000113u,0x0004003du,0x0000000au,0x00000115u,0x00000068u,0x0004003du,0x00000009u,0x00000116u,0x00000055u,0x0004003du,0x0000000au,0x00000117u,0x00000104u,0x0005008eu,0x0000000au,0x00000118u,0x00000117u,0x00000116u,0x00050081u,0x0000000au,0x00000119u,0x00000115u,0x00000118u,0x0004003du,0x00000009u,0x0000011au,0x00000055u,0x0004003du,0x00000009u,0x0000011bu,0x000000fcu,0x00050085u,0x00000009u,0x0000011cu,0x0000011au,0x0000011bu,0x00050081u,0x00000009u,0x0000011du,0x000000c2u,0x0000011cu,0x00070050u,0x0000000au,0x0000011eu,0x0000011du,0x0000011du,0x0000011du,0x0000011du,0x00050088u,0x0000000au,0x0000011fu,0x00000119u,0x0000011eu,0x0003003eu,0x00000114u,0x0000011fu,0x0004003du,0x00000016u,0x00000122u,0x00000121u,0x0004003du,0x00000007u,0x00000123u,0x00000034u,0x0004003du,0x00000007u,0x00000124u,0x0000003cu,0x00050050u,0x00000007u,0x00000125u,0x0000001eu,0x0000001eu,0x00050082u,0x00000007u,0x00000126u,0x00000124u,0x00000125u,0x0008000cu,0x00000007u,0x00000127u,0x00000001u,0x0000002du,0x00000123u,0x0000001cu,0x00000126u,0x00040064u,0x00000015u,0x00000128u,0x00000122u,0x0007005fu,0x0000000au,0x00000129u,0x00000128u,0x00000127u,0x00000002u,0x0000001bu,0x0003003eu,0x00000120u,0x00000129u,0x0004003du,0x00000009u,0x0000012bu,0x00000055u,0x0004003du,0x00000009u,0x0000012cu,0x0000005cu,0x00050085u,0x00000009u,0x0000012du,0x0000012bu,0x0000012cu,0x0003003eu,0x0000012au,0x0000012du,0x0004003du,0x0000000au,0x0000012fu,0x00000114u,0x0004003du,0x0000000au,0x00000130u,0x00000120u,0x00050083u,0x0000000au,0x00000131u,0x0000012fu,0x00000130u,0x0003003eu,0x0000012eu,0x00000131u,0x0004003du,0x0000000au,0x00000133u,0x00000114u,0x0004003du,0x0000000au,0x00000134u,0x0000012eu,0x0004003du,0x00000009u,0x00000135u,0x0000012au,0x0004007fu,0x00000009u,0x00000136u,0x00000135u,0x00070050u,0x0000000au,0x00000137u,0x00000136u,0x00000136u,0x00000136u,0x00000136u,0x0004003du,0x00000009u,0x00000138u,0x0000012au,0x00070050u,0x0000000au,0x00000139u,0x00000138u,0x00000138u,0x00000138u,0x00000138u,0x0008000cu,0x0000000au,0x0000013au,0x00000001u,0x0000002bu,0x00000134u,0x00000137u,0x00000139u,0x00050083u,0x0000000au,0x0000013bu,0x00000133u,0x0000013au,0x0003003eu,0x00000132u,0x0000013bu,0x0004003du,0x0000013cu,0x0000013fu,0x0000013eu,0x0004003du,0x00000007u,0x00000140u,0x00000034u,0x0004003du,0x0000000au,0x00000141u,0x00000132u,0x00040063u,0x0000013fu,0x00000140u,0x00000141u,0x000100fdu,0x00010038u,0x00050036u,0x0000000au,0x0000000eu,0x00000000u,0x0000000bu,0x00030037u,0x00000008u,0x0000000cu,0x00030037u,0x00000008u,0x0000000du,0x000200f8u,0x0000000fu,0x0004003du,0x00000016u,0x00000019u,0x00000018u,0x0004003du,0x00000007u,0x0000001au,0x0000000cu,0x0004003du,0x00000007u,0x0000001du,0x0000000du,0x00050050u,0x00000007u,0x0000001fu,0x0000001eu,0x0000001eu,0x00050082u,0x00000007u,0x00000020u,0x0000001du,0x0000001fu,0x0008000cu,0x00000007u,0x00000021u,0x00000001u,0x0000002du,0x0000001au,0x0000001cu,0x00000020u,0x00040064u,0x00000015u,0x00000022u,0x00000019u,0x0007005fu,0x0000000au,0x00000023u,0x00000022u,0x00000021u,0x00000002u,0x0000001bu,0x000200feu,0x00000023u,0x00010038u,0x00050036u,0x00000009u,0x00000013u,0x00000000u,0x00000010u,0x00030037u,0x00000008u,0x00000011u,0x00030037u,0x00000008u,0x00000012u,0x000200f8u,0x00000014u,0x0004003du,0x00000016u,0x00000027u,0x00000026u,0x0004003du,0x00000007u,0x00000028u,0x00000011u,0x0004003du,0x00000007u,0x00000029u,0x00000012u,0x00050050u,0x00000007u,0x0000002au,0x0000001eu,0x0000001eu,0x00050082u,0x00000007u,0x0000002bu,0x00000029u,0x0000002au,0x0008000cu,0x00000007u,0x0000002cu,0x00000001u,0x0000002du,0x00000028u,0x0000001cu,0x0000002bu,0x00040064u,0x00000015u,0x0000002du,0x00000027u,0x0007005fu,0x0000000au,0x0000002eu,0x0000002du,0x0000002cu,0x00000002u,0x0000001bu,0x00050051u,0x00000009u,0x00000031u,0x0000002eu,0x00000000u,0x000200feu,0x00000031u,0x00010038u}; +static const size_t OF3_FLOWREG_LEN = 1936; +static const uint32_t WFG_SYNTH_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000208u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000001cu,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00050005u,0x0000000bu,0x616d756cu,0x33667628u,0x0000003bu,0x00030005u,0x0000000au,0x00000063u,0x00030005u,0x00000018u,0x00646967u,0x00080005u,0x0000001cu,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000021u,0x006d6964u,0x00040005u,0x00000024u,0x74754f75u,0x00000000u,0x00040005u,0x0000003eu,0x44766e69u,0x00006d69u,0x00030005u,0x00000044u,0x00007675u,0x00030005u,0x0000004du,0x00000055u,0x00060006u,0x0000004du,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x0000004du,0x00000001u,0x68706c61u,0x00000061u,0x00050006u,0x0000004du,0x00000002u,0x61746562u,0x00000000u,0x00050006u,0x0000004du,0x00000003u,0x626d616cu,0x00006164u,0x00050006u,0x0000004du,0x00000004u,0x69737065u,0x006e6f6cu,0x00060006u,0x0000004du,0x00000005u,0x746f6870u,0x6163536fu,0x0000656cu,0x00050006u,0x0000004du,0x00000006u,0x30646170u,0x00000000u,0x00050006u,0x0000004du,0x00000007u,0x31646170u,0x00000000u,0x00050006u,0x0000004du,0x00000008u,0x52647568u,0x00746365u,0x00030005u,0x0000004fu,0x00000000u,0x00040005u,0x0000008cu,0x72754375u,0x00000072u,0x00030005u,0x00000098u,0x00676264u,0x00030005u,0x0000009fu,0x00007366u,0x00040005u,0x000000a9u,0x64774273u,0x00000000u,0x00050005u,0x000000aau,0x6f6c4675u,0x64774277u,0x00000000u,0x00040005u,0x000000aeu,0x64774673u,0x00000000u,0x00050005u,0x000000afu,0x6f6c4675u,0x64774677u,0x00000000u,0x00030005u,0x000000b3u,0x00313046u,0x00030005u,0x000000bau,0x00303146u,0x00040005u,0x000000c1u,0x31306663u,0x00000000u,0x00040005u,0x000000c5u,0x30316663u,0x00000000u,0x00030005u,0x000000c9u,0x0031306du,0x00030005u,0x000000d5u,0x0030316du,0x00030005u,0x000000e0u,0x00004170u,0x00030005u,0x000000e8u,0x00004270u,0x00030005u,0x000000f0u,0x00003043u,0x00040005u,0x000000f1u,0x65725075u,0x00000076u,0x00030005u,0x000000f6u,0x00003143u,0x00030005u,0x000000fbu,0x00004165u,0x00040005u,0x000000fcu,0x61726170u,0x0000006du,0x00040005u,0x0000010cu,0x61726170u,0x0000006du,0x00030005u,0x00000111u,0x00004265u,0x00040005u,0x00000112u,0x61726170u,0x0000006du,0x00040005u,0x00000122u,0x61726170u,0x0000006du,0x00040005u,0x00000127u,0x76556266u,0x00000000u,0x00040005u,0x0000012bu,0x65526266u,0x00646973u,0x00040005u,0x00000138u,0x736e6f63u,0x00747369u,0x00030005u,0x00000149u,0x0000305au,0x00030005u,0x00000157u,0x0000315au,0x00040005u,0x00000163u,0x30756174u,0x00000000u,0x00040005u,0x00000167u,0x31756174u,0x00000000u,0x00040005u,0x0000016au,0x78616d7au,0x00000000u,0x00030005u,0x0000016eu,0x00003057u,0x00030005u,0x00000179u,0x00003157u,0x00040005u,0x00000183u,0x6d757357u,0x00000000u,0x00040005u,0x00000187u,0x70726177u,0x00006465u,0x00050005u,0x000001a0u,0x736f7263u,0x64616673u,0x00000065u,0x00050005u,0x000001adu,0x746f6870u,0x7272456fu,0x00000000u,0x00050005u,0x000001b1u,0x746f6870u,0x7572546fu,0x00007473u,0x00040005u,0x000001b7u,0x73757274u,0x00000074u,0x00040005u,0x000001c3u,0x76657270u,0x00000043u,0x00040005u,0x000001c8u,0x72727563u,0x00000043u,0x00050005u,0x000001cdu,0x746e6f63u,0x44746e65u,0x00666669u,0x00050005u,0x000001d2u,0x72746e75u,0x65747375u,0x00000064u,0x00040005u,0x000001d7u,0x44676962u,0x00666669u,0x00050005u,0x000001dcu,0x70616e73u,0x75436f54u,0x00007272u,0x00040005u,0x000001e5u,0x6374756fu,0x00000000u,0x00030005u,0x000001eeu,0x0067616du,0x00030005u,0x000001f2u,0x0000006eu,0x00030005u,0x000001f6u,0x00746173u,0x00040047u,0x0000001cu,0x0000000bu,0x0000001cu,0x00030047u,0x00000024u,0x00000019u,0x00040047u,0x00000024u,0x00000021u,0x00000030u,0x00040047u,0x00000024u,0x00000022u,0x00000000u,0x00030047u,0x0000004du,0x00000002u,0x00050048u,0x0000004du,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x0000004du,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x0000004du,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x0000004du,0x00000003u,0x00000023u,0x0000000cu,0x00050048u,0x0000004du,0x00000004u,0x00000023u,0x00000010u,0x00050048u,0x0000004du,0x00000005u,0x00000023u,0x00000014u,0x00050048u,0x0000004du,0x00000006u,0x00000023u,0x00000018u,0x00050048u,0x0000004du,0x00000007u,0x00000023u,0x0000001cu,0x00050048u,0x0000004du,0x00000008u,0x00000023u,0x00000020u,0x00040047u,0x0000004fu,0x00000021u,0x00000000u,0x00040047u,0x0000004fu,0x00000022u,0x00000000u,0x00040047u,0x0000008cu,0x00000021u,0x00000021u,0x00040047u,0x0000008cu,0x00000022u,0x00000000u,0x00040047u,0x000000aau,0x00000021u,0x00000023u,0x00040047u,0x000000aau,0x00000022u,0x00000000u,0x00040047u,0x000000afu,0x00000021u,0x00000022u,0x00040047u,0x000000afu,0x00000022u,0x00000000u,0x00040047u,0x000000f1u,0x00000021u,0x00000020u,0x00040047u,0x000000f1u,0x00000022u,0x00000000u,0x00040047u,0x00000207u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00040017u,0x00000007u,0x00000006u,0x00000003u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040021u,0x00000009u,0x00000006u,0x00000008u,0x0004002bu,0x00000006u,0x0000000eu,0x3e59b3d0u,0x0004002bu,0x00000006u,0x0000000fu,0x3f371759u,0x0004002bu,0x00000006u,0x00000010u,0x3d93dd98u,0x0006002cu,0x00000007u,0x00000011u,0x0000000eu,0x0000000fu,0x00000010u,0x00040015u,0x00000015u,0x00000020u,0x00000001u,0x00040017u,0x00000016u,0x00000015u,0x00000002u,0x00040020u,0x00000017u,0x00000007u,0x00000016u,0x00040015u,0x00000019u,0x00000020u,0x00000000u,0x00040017u,0x0000001au,0x00000019u,0x00000003u,0x00040020u,0x0000001bu,0x00000001u,0x0000001au,0x0004003bu,0x0000001bu,0x0000001cu,0x00000001u,0x00040017u,0x0000001du,0x00000019u,0x00000002u,0x00090019u,0x00000022u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000004u,0x00040020u,0x00000023u,0x00000000u,0x00000022u,0x0004003bu,0x00000023u,0x00000024u,0x00000000u,0x00020014u,0x00000027u,0x0004002bu,0x00000019u,0x00000028u,0x00000000u,0x00040020u,0x00000029u,0x00000007u,0x00000015u,0x0004002bu,0x00000019u,0x00000032u,0x00000001u,0x00040017u,0x0000003cu,0x00000006u,0x00000002u,0x00040020u,0x0000003du,0x00000007u,0x0000003cu,0x0004002bu,0x00000006u,0x0000003fu,0x3f800000u,0x0004002bu,0x00000006u,0x00000047u,0x3f000000u,0x00040017u,0x0000004cu,0x00000006u,0x00000004u,0x000b001eu,0x0000004du,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x00000006u,0x0000004cu,0x00040020u,0x0000004eu,0x00000002u,0x0000004du,0x0004003bu,0x0000004eu,0x0000004fu,0x00000002u,0x0004002bu,0x00000015u,0x00000050u,0x00000008u,0x00040020u,0x00000051u,0x00000002u,0x00000006u,0x0004002bu,0x00000019u,0x00000054u,0x00000002u,0x0004002bu,0x00000019u,0x0000005cu,0x00000003u,0x00090019u,0x00000089u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000008au,0x00000089u,0x00040020u,0x0000008bu,0x00000000u,0x0000008au,0x0004003bu,0x0000008bu,0x0000008cu,0x00000000u,0x0004002bu,0x00000006u,0x0000008fu,0x00000000u,0x00040020u,0x00000097u,0x00000007u,0x00000027u,0x0004002bu,0x00000015u,0x00000099u,0x00000000u,0x0004002bu,0x00000006u,0x0000009cu,0x40600000u,0x00040020u,0x0000009eu,0x00000007u,0x00000006u,0x00040020u,0x000000a8u,0x00000007u,0x0000004cu,0x0004003bu,0x0000008bu,0x000000aau,0x00000000u,0x0004003bu,0x0000008bu,0x000000afu,0x00000000u,0x0004002bu,0x00000006u,0x000000cdu,0x3dcccccdu,0x0004002bu,0x00000015u,0x000000e2u,0x00000001u,0x0004003bu,0x0000008bu,0x000000f1u,0x00000000u,0x0004002bu,0x00000015u,0x0000014au,0x00000005u,0x0004002bu,0x00000015u,0x0000014fu,0x00000003u,0x0004002bu,0x00000015u,0x00000170u,0x00000002u,0x0004002bu,0x00000006u,0x00000189u,0x322bcc77u,0x0004002bu,0x00000006u,0x000001b2u,0x3d23d70au,0x0004002bu,0x00000006u,0x000001b3u,0x3e3851ecu,0x0004002bu,0x00000015u,0x000001bcu,0x00000004u,0x0004002bu,0x00000006u,0x000001d3u,0x3e800000u,0x0004002bu,0x00000006u,0x000001d8u,0x3e4ccccdu,0x0004002bu,0x00000006u,0x000001d9u,0x3ecccccdu,0x0004002bu,0x00000019u,0x00000206u,0x00000010u,0x0006002cu,0x0000001au,0x00000207u,0x00000206u,0x00000206u,0x00000032u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000017u,0x00000018u,0x00000007u,0x0004003bu,0x00000017u,0x00000021u,0x00000007u,0x0004003bu,0x0000003du,0x0000003eu,0x00000007u,0x0004003bu,0x0000003du,0x00000044u,0x00000007u,0x0004003bu,0x00000097u,0x00000098u,0x00000007u,0x0004003bu,0x0000009eu,0x0000009fu,0x00000007u,0x0004003bu,0x0000009eu,0x000000a1u,0x00000007u,0x0004003bu,0x000000a8u,0x000000a9u,0x00000007u,0x0004003bu,0x000000a8u,0x000000aeu,0x00000007u,0x0004003bu,0x0000003du,0x000000b3u,0x00000007u,0x0004003bu,0x0000003du,0x000000bau,0x00000007u,0x0004003bu,0x0000009eu,0x000000c1u,0x00000007u,0x0004003bu,0x0000009eu,0x000000c5u,0x00000007u,0x0004003bu,0x0000009eu,0x000000c9u,0x00000007u,0x0004003bu,0x0000009eu,0x000000d5u,0x00000007u,0x0004003bu,0x0000003du,0x000000e0u,0x00000007u,0x0004003bu,0x0000003du,0x000000e8u,0x00000007u,0x0004003bu,0x00000008u,0x000000f0u,0x00000007u,0x0004003bu,0x00000008u,0x000000f6u,0x00000007u,0x0004003bu,0x0000009eu,0x000000fbu,0x00000007u,0x0004003bu,0x00000008u,0x000000fcu,0x00000007u,0x0004003bu,0x00000008u,0x0000010cu,0x00000007u,0x0004003bu,0x0000009eu,0x00000111u,0x00000007u,0x0004003bu,0x00000008u,0x00000112u,0x00000007u,0x0004003bu,0x00000008u,0x00000122u,0x00000007u,0x0004003bu,0x0000003du,0x00000127u,0x00000007u,0x0004003bu,0x0000009eu,0x0000012bu,0x00000007u,0x0004003bu,0x0000009eu,0x00000138u,0x00000007u,0x0004003bu,0x0000009eu,0x00000149u,0x00000007u,0x0004003bu,0x0000009eu,0x00000157u,0x00000007u,0x0004003bu,0x0000009eu,0x00000163u,0x00000007u,0x0004003bu,0x0000009eu,0x00000167u,0x00000007u,0x0004003bu,0x0000009eu,0x0000016au,0x00000007u,0x0004003bu,0x0000009eu,0x0000016eu,0x00000007u,0x0004003bu,0x0000009eu,0x00000179u,0x00000007u,0x0004003bu,0x0000009eu,0x00000183u,0x00000007u,0x0004003bu,0x00000008u,0x00000187u,0x00000007u,0x0004003bu,0x00000008u,0x0000018bu,0x00000007u,0x0004003bu,0x00000008u,0x000001a0u,0x00000007u,0x0004003bu,0x0000009eu,0x000001adu,0x00000007u,0x0004003bu,0x0000009eu,0x000001b1u,0x00000007u,0x0004003bu,0x0000009eu,0x000001b7u,0x00000007u,0x0004003bu,0x00000008u,0x000001c3u,0x00000007u,0x0004003bu,0x00000008u,0x000001c8u,0x00000007u,0x0004003bu,0x0000009eu,0x000001cdu,0x00000007u,0x0004003bu,0x0000009eu,0x000001d2u,0x00000007u,0x0004003bu,0x0000009eu,0x000001d7u,0x00000007u,0x0004003bu,0x0000009eu,0x000001dcu,0x00000007u,0x0004003bu,0x00000008u,0x000001e5u,0x00000007u,0x0004003bu,0x0000009eu,0x000001eeu,0x00000007u,0x0004003bu,0x0000009eu,0x000001f2u,0x00000007u,0x0004003bu,0x0000009eu,0x000001f6u,0x00000007u,0x0004003du,0x0000001au,0x0000001eu,0x0000001cu,0x0007004fu,0x0000001du,0x0000001fu,0x0000001eu,0x0000001eu,0x00000000u,0x00000001u,0x0004007cu,0x00000016u,0x00000020u,0x0000001fu,0x0003003eu,0x00000018u,0x00000020u,0x0004003du,0x00000022u,0x00000025u,0x00000024u,0x00040068u,0x00000016u,0x00000026u,0x00000025u,0x0003003eu,0x00000021u,0x00000026u,0x00050041u,0x00000029u,0x0000002au,0x00000018u,0x00000028u,0x0004003du,0x00000015u,0x0000002bu,0x0000002au,0x00050041u,0x00000029u,0x0000002cu,0x00000021u,0x00000028u,0x0004003du,0x00000015u,0x0000002du,0x0000002cu,0x000500afu,0x00000027u,0x0000002eu,0x0000002bu,0x0000002du,0x000400a8u,0x00000027u,0x0000002fu,0x0000002eu,0x000300f7u,0x00000031u,0x00000000u,0x000400fau,0x0000002fu,0x00000030u,0x00000031u,0x000200f8u,0x00000030u,0x00050041u,0x00000029u,0x00000033u,0x00000018u,0x00000032u,0x0004003du,0x00000015u,0x00000034u,0x00000033u,0x00050041u,0x00000029u,0x00000035u,0x00000021u,0x00000032u,0x0004003du,0x00000015u,0x00000036u,0x00000035u,0x000500afu,0x00000027u,0x00000037u,0x00000034u,0x00000036u,0x000200f9u,0x00000031u,0x000200f8u,0x00000031u,0x000700f5u,0x00000027u,0x00000038u,0x0000002eu,0x00000005u,0x00000037u,0x00000030u,0x000300f7u,0x0000003au,0x00000000u,0x000400fau,0x00000038u,0x00000039u,0x0000003au,0x000200f8u,0x00000039u,0x000100fdu,0x000200f8u,0x0000003au,0x0004003du,0x00000016u,0x00000040u,0x00000021u,0x0004006fu,0x0000003cu,0x00000041u,0x00000040u,0x00050050u,0x0000003cu,0x00000042u,0x0000003fu,0x0000003fu,0x00050088u,0x0000003cu,0x00000043u,0x00000042u,0x00000041u,0x0003003eu,0x0000003eu,0x00000043u,0x0004003du,0x00000016u,0x00000045u,0x00000018u,0x0004006fu,0x0000003cu,0x00000046u,0x00000045u,0x00050050u,0x0000003cu,0x00000048u,0x00000047u,0x00000047u,0x00050081u,0x0000003cu,0x00000049u,0x00000046u,0x00000048u,0x0004003du,0x0000003cu,0x0000004au,0x0000003eu,0x00050085u,0x0000003cu,0x0000004bu,0x00000049u,0x0000004au,0x0003003eu,0x00000044u,0x0000004bu,0x00060041u,0x00000051u,0x00000052u,0x0000004fu,0x00000050u,0x00000028u,0x0004003du,0x00000006u,0x00000053u,0x00000052u,0x00060041u,0x00000051u,0x00000055u,0x0000004fu,0x00000050u,0x00000054u,0x0004003du,0x00000006u,0x00000056u,0x00000055u,0x000500b8u,0x00000027u,0x00000057u,0x00000053u,0x00000056u,0x000300f7u,0x00000059u,0x00000000u,0x000400fau,0x00000057u,0x00000058u,0x00000059u,0x000200f8u,0x00000058u,0x00060041u,0x00000051u,0x0000005au,0x0000004fu,0x00000050u,0x00000032u,0x0004003du,0x00000006u,0x0000005bu,0x0000005au,0x00060041u,0x00000051u,0x0000005du,0x0000004fu,0x00000050u,0x0000005cu,0x0004003du,0x00000006u,0x0000005eu,0x0000005du,0x000500b8u,0x00000027u,0x0000005fu,0x0000005bu,0x0000005eu,0x000200f9u,0x00000059u,0x000200f8u,0x00000059u,0x000700f5u,0x00000027u,0x00000060u,0x00000057u,0x0000003au,0x0000005fu,0x00000058u,0x000300f7u,0x00000062u,0x00000000u,0x000400fau,0x00000060u,0x00000061u,0x00000062u,0x000200f8u,0x00000061u,0x00050041u,0x00000029u,0x00000063u,0x00000018u,0x00000028u,0x0004003du,0x00000015u,0x00000064u,0x00000063u,0x0004006fu,0x00000006u,0x00000065u,0x00000064u,0x00060041u,0x00000051u,0x00000066u,0x0000004fu,0x00000050u,0x00000028u,0x0004003du,0x00000006u,0x00000067u,0x00000066u,0x000500beu,0x00000027u,0x00000068u,0x00000065u,0x00000067u,0x000200f9u,0x00000062u,0x000200f8u,0x00000062u,0x000700f5u,0x00000027u,0x00000069u,0x00000060u,0x00000059u,0x00000068u,0x00000061u,0x000300f7u,0x0000006bu,0x00000000u,0x000400fau,0x00000069u,0x0000006au,0x0000006bu,0x000200f8u,0x0000006au,0x00050041u,0x00000029u,0x0000006cu,0x00000018u,0x00000028u,0x0004003du,0x00000015u,0x0000006du,0x0000006cu,0x0004006fu,0x00000006u,0x0000006eu,0x0000006du,0x00060041u,0x00000051u,0x0000006fu,0x0000004fu,0x00000050u,0x00000054u,0x0004003du,0x00000006u,0x00000070u,0x0000006fu,0x000500b8u,0x00000027u,0x00000071u,0x0000006eu,0x00000070u,0x000200f9u,0x0000006bu,0x000200f8u,0x0000006bu,0x000700f5u,0x00000027u,0x00000072u,0x00000069u,0x00000062u,0x00000071u,0x0000006au,0x000300f7u,0x00000074u,0x00000000u,0x000400fau,0x00000072u,0x00000073u,0x00000074u,0x000200f8u,0x00000073u,0x00050041u,0x00000029u,0x00000075u,0x00000018u,0x00000032u,0x0004003du,0x00000015u,0x00000076u,0x00000075u,0x0004006fu,0x00000006u,0x00000077u,0x00000076u,0x00060041u,0x00000051u,0x00000078u,0x0000004fu,0x00000050u,0x00000032u,0x0004003du,0x00000006u,0x00000079u,0x00000078u,0x000500beu,0x00000027u,0x0000007au,0x00000077u,0x00000079u,0x000200f9u,0x00000074u,0x000200f8u,0x00000074u,0x000700f5u,0x00000027u,0x0000007bu,0x00000072u,0x0000006bu,0x0000007au,0x00000073u,0x000300f7u,0x0000007du,0x00000000u,0x000400fau,0x0000007bu,0x0000007cu,0x0000007du,0x000200f8u,0x0000007cu,0x00050041u,0x00000029u,0x0000007eu,0x00000018u,0x00000032u,0x0004003du,0x00000015u,0x0000007fu,0x0000007eu,0x0004006fu,0x00000006u,0x00000080u,0x0000007fu,0x00060041u,0x00000051u,0x00000081u,0x0000004fu,0x00000050u,0x0000005cu,0x0004003du,0x00000006u,0x00000082u,0x00000081u,0x000500b8u,0x00000027u,0x00000083u,0x00000080u,0x00000082u,0x000200f9u,0x0000007du,0x000200f8u,0x0000007du,0x000700f5u,0x00000027u,0x00000084u,0x0000007bu,0x00000074u,0x00000083u,0x0000007cu,0x000300f7u,0x00000086u,0x00000000u,0x000400fau,0x00000084u,0x00000085u,0x00000086u,0x000200f8u,0x00000085u,0x0004003du,0x00000022u,0x00000087u,0x00000024u,0x0004003du,0x00000016u,0x00000088u,0x00000018u,0x0004003du,0x0000008au,0x0000008du,0x0000008cu,0x0004003du,0x0000003cu,0x0000008eu,0x00000044u,0x00070058u,0x0000004cu,0x00000090u,0x0000008du,0x0000008eu,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x00000091u,0x00000090u,0x00000090u,0x00000000u,0x00000001u,0x00000002u,0x00050051u,0x00000006u,0x00000092u,0x00000091u,0x00000000u,0x00050051u,0x00000006u,0x00000093u,0x00000091u,0x00000001u,0x00050051u,0x00000006u,0x00000094u,0x00000091u,0x00000002u,0x00070050u,0x0000004cu,0x00000095u,0x00000092u,0x00000093u,0x00000094u,0x0000003fu,0x00040063u,0x00000087u,0x00000088u,0x00000095u,0x000100fdu,0x000200f8u,0x00000086u,0x00050041u,0x00000051u,0x0000009au,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x0000009bu,0x0000009au,0x000500bau,0x00000027u,0x0000009du,0x0000009bu,0x0000009cu,0x0003003eu,0x00000098u,0x0000009du,0x0004003du,0x00000027u,0x000000a0u,0x00000098u,0x000300f7u,0x000000a3u,0x00000000u,0x000400fau,0x000000a0u,0x000000a2u,0x000000a4u,0x000200f8u,0x000000a2u,0x0003003eu,0x000000a1u,0x0000003fu,0x000200f9u,0x000000a3u,0x000200f8u,0x000000a4u,0x00050041u,0x00000051u,0x000000a5u,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x000000a6u,0x000000a5u,0x0003003eu,0x000000a1u,0x000000a6u,0x000200f9u,0x000000a3u,0x000200f8u,0x000000a3u,0x0004003du,0x00000006u,0x000000a7u,0x000000a1u,0x0003003eu,0x0000009fu,0x000000a7u,0x0004003du,0x0000008au,0x000000abu,0x000000aau,0x0004003du,0x0000003cu,0x000000acu,0x00000044u,0x00070058u,0x0000004cu,0x000000adu,0x000000abu,0x000000acu,0x00000002u,0x0000008fu,0x0003003eu,0x000000a9u,0x000000adu,0x0004003du,0x0000008au,0x000000b0u,0x000000afu,0x0004003du,0x0000003cu,0x000000b1u,0x00000044u,0x00070058u,0x0000004cu,0x000000b2u,0x000000b0u,0x000000b1u,0x00000002u,0x0000008fu,0x0003003eu,0x000000aeu,0x000000b2u,0x0004003du,0x0000004cu,0x000000b4u,0x000000a9u,0x0007004fu,0x0000003cu,0x000000b5u,0x000000b4u,0x000000b4u,0x00000000u,0x00000001u,0x0004003du,0x00000006u,0x000000b6u,0x0000009fu,0x0005008eu,0x0000003cu,0x000000b7u,0x000000b5u,0x000000b6u,0x0004003du,0x0000003cu,0x000000b8u,0x0000003eu,0x00050085u,0x0000003cu,0x000000b9u,0x000000b7u,0x000000b8u,0x0003003eu,0x000000b3u,0x000000b9u,0x0004003du,0x0000004cu,0x000000bbu,0x000000aeu,0x0007004fu,0x0000003cu,0x000000bcu,0x000000bbu,0x000000bbu,0x00000000u,0x00000001u,0x0004003du,0x00000006u,0x000000bdu,0x0000009fu,0x0005008eu,0x0000003cu,0x000000beu,0x000000bcu,0x000000bdu,0x0004003du,0x0000003cu,0x000000bfu,0x0000003eu,0x00050085u,0x0000003cu,0x000000c0u,0x000000beu,0x000000bfu,0x0003003eu,0x000000bau,0x000000c0u,0x00050041u,0x0000009eu,0x000000c2u,0x000000a9u,0x0000005cu,0x0004003du,0x00000006u,0x000000c3u,0x000000c2u,0x0008000cu,0x00000006u,0x000000c4u,0x00000001u,0x0000002bu,0x000000c3u,0x0000008fu,0x0000003fu,0x0003003eu,0x000000c1u,0x000000c4u,0x00050041u,0x0000009eu,0x000000c6u,0x000000aeu,0x0000005cu,0x0004003du,0x00000006u,0x000000c7u,0x000000c6u,0x0008000cu,0x00000006u,0x000000c8u,0x00000001u,0x0000002bu,0x000000c7u,0x0000008fu,0x0000003fu,0x0003003eu,0x000000c5u,0x000000c8u,0x0004003du,0x0000003cu,0x000000cau,0x000000b3u,0x0006000cu,0x00000006u,0x000000cbu,0x00000001u,0x00000042u,0x000000cau,0x0003003eu,0x000000c9u,0x000000cbu,0x0004003du,0x00000006u,0x000000ccu,0x000000c9u,0x000500bau,0x00000027u,0x000000ceu,0x000000ccu,0x000000cdu,0x000300f7u,0x000000d0u,0x00000000u,0x000400fau,0x000000ceu,0x000000cfu,0x000000d0u,0x000200f8u,0x000000cfu,0x0004003du,0x00000006u,0x000000d1u,0x000000c9u,0x00050088u,0x00000006u,0x000000d2u,0x000000cdu,0x000000d1u,0x0004003du,0x0000003cu,0x000000d3u,0x000000b3u,0x0005008eu,0x0000003cu,0x000000d4u,0x000000d3u,0x000000d2u,0x0003003eu,0x000000b3u,0x000000d4u,0x000200f9u,0x000000d0u,0x000200f8u,0x000000d0u,0x0004003du,0x0000003cu,0x000000d6u,0x000000bau,0x0006000cu,0x00000006u,0x000000d7u,0x00000001u,0x00000042u,0x000000d6u,0x0003003eu,0x000000d5u,0x000000d7u,0x0004003du,0x00000006u,0x000000d8u,0x000000d5u,0x000500bau,0x00000027u,0x000000d9u,0x000000d8u,0x000000cdu,0x000300f7u,0x000000dbu,0x00000000u,0x000400fau,0x000000d9u,0x000000dau,0x000000dbu,0x000200f8u,0x000000dau,0x0004003du,0x00000006u,0x000000dcu,0x000000d5u,0x00050088u,0x00000006u,0x000000ddu,0x000000cdu,0x000000dcu,0x0004003du,0x0000003cu,0x000000deu,0x000000bau,0x0005008eu,0x0000003cu,0x000000dfu,0x000000deu,0x000000ddu,0x0003003eu,0x000000bau,0x000000dfu,0x000200f9u,0x000000dbu,0x000200f8u,0x000000dbu,0x0004003du,0x0000003cu,0x000000e1u,0x00000044u,0x00050041u,0x00000051u,0x000000e3u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x000000e4u,0x000000e3u,0x0004003du,0x0000003cu,0x000000e5u,0x000000b3u,0x0005008eu,0x0000003cu,0x000000e6u,0x000000e5u,0x000000e4u,0x00050083u,0x0000003cu,0x000000e7u,0x000000e1u,0x000000e6u,0x0003003eu,0x000000e0u,0x000000e7u,0x0004003du,0x0000003cu,0x000000e9u,0x00000044u,0x00050041u,0x00000051u,0x000000eau,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x000000ebu,0x000000eau,0x00050083u,0x00000006u,0x000000ecu,0x0000003fu,0x000000ebu,0x0004003du,0x0000003cu,0x000000edu,0x000000bau,0x0005008eu,0x0000003cu,0x000000eeu,0x000000edu,0x000000ecu,0x00050083u,0x0000003cu,0x000000efu,0x000000e9u,0x000000eeu,0x0003003eu,0x000000e8u,0x000000efu,0x0004003du,0x0000008au,0x000000f2u,0x000000f1u,0x0004003du,0x0000003cu,0x000000f3u,0x000000e0u,0x00070058u,0x0000004cu,0x000000f4u,0x000000f2u,0x000000f3u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000000f5u,0x000000f4u,0x000000f4u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000000f0u,0x000000f5u,0x0004003du,0x0000008au,0x000000f7u,0x0000008cu,0x0004003du,0x0000003cu,0x000000f8u,0x000000e8u,0x00070058u,0x0000004cu,0x000000f9u,0x000000f7u,0x000000f8u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000000fau,0x000000f9u,0x000000f9u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000000f6u,0x000000fau,0x0004003du,0x00000007u,0x000000fdu,0x000000f0u,0x0003003eu,0x000000fcu,0x000000fdu,0x00050039u,0x00000006u,0x000000feu,0x0000000bu,0x000000fcu,0x0004003du,0x0000008au,0x000000ffu,0x0000008cu,0x0004003du,0x0000003cu,0x00000100u,0x000000e0u,0x0004003du,0x0000008au,0x00000101u,0x000000aau,0x0004003du,0x0000003cu,0x00000102u,0x000000e0u,0x00070058u,0x0000004cu,0x00000103u,0x00000101u,0x00000102u,0x00000002u,0x0000008fu,0x0007004fu,0x0000003cu,0x00000104u,0x00000103u,0x00000103u,0x00000000u,0x00000001u,0x00050041u,0x00000051u,0x00000105u,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x00000106u,0x00000105u,0x0005008eu,0x0000003cu,0x00000107u,0x00000104u,0x00000106u,0x0004003du,0x0000003cu,0x00000108u,0x0000003eu,0x00050085u,0x0000003cu,0x00000109u,0x00000107u,0x00000108u,0x00050081u,0x0000003cu,0x0000010au,0x00000100u,0x00000109u,0x00070058u,0x0000004cu,0x0000010bu,0x000000ffu,0x0000010au,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x0000010du,0x0000010bu,0x0000010bu,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x0000010cu,0x0000010du,0x00050039u,0x00000006u,0x0000010eu,0x0000000bu,0x0000010cu,0x00050083u,0x00000006u,0x0000010fu,0x000000feu,0x0000010eu,0x0006000cu,0x00000006u,0x00000110u,0x00000001u,0x00000004u,0x0000010fu,0x0003003eu,0x000000fbu,0x00000110u,0x0004003du,0x00000007u,0x00000113u,0x000000f6u,0x0003003eu,0x00000112u,0x00000113u,0x00050039u,0x00000006u,0x00000114u,0x0000000bu,0x00000112u,0x0004003du,0x0000008au,0x00000115u,0x000000f1u,0x0004003du,0x0000003cu,0x00000116u,0x000000e8u,0x0004003du,0x0000008au,0x00000117u,0x000000afu,0x0004003du,0x0000003cu,0x00000118u,0x000000e8u,0x00070058u,0x0000004cu,0x00000119u,0x00000117u,0x00000118u,0x00000002u,0x0000008fu,0x0007004fu,0x0000003cu,0x0000011au,0x00000119u,0x00000119u,0x00000000u,0x00000001u,0x00050041u,0x00000051u,0x0000011bu,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x0000011cu,0x0000011bu,0x0005008eu,0x0000003cu,0x0000011du,0x0000011au,0x0000011cu,0x0004003du,0x0000003cu,0x0000011eu,0x0000003eu,0x00050085u,0x0000003cu,0x0000011fu,0x0000011du,0x0000011eu,0x00050081u,0x0000003cu,0x00000120u,0x00000116u,0x0000011fu,0x00070058u,0x0000004cu,0x00000121u,0x00000115u,0x00000120u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x00000123u,0x00000121u,0x00000121u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x00000122u,0x00000123u,0x00050039u,0x00000006u,0x00000124u,0x0000000bu,0x00000122u,0x00050083u,0x00000006u,0x00000125u,0x00000114u,0x00000124u,0x0006000cu,0x00000006u,0x00000126u,0x00000001u,0x00000004u,0x00000125u,0x0003003eu,0x00000111u,0x00000126u,0x0004003du,0x0000003cu,0x00000128u,0x00000044u,0x0004003du,0x0000003cu,0x00000129u,0x000000b3u,0x00050081u,0x0000003cu,0x0000012au,0x00000128u,0x00000129u,0x0003003eu,0x00000127u,0x0000012au,0x0004003du,0x0000003cu,0x0000012cu,0x000000b3u,0x0004003du,0x0000008au,0x0000012du,0x000000afu,0x0004003du,0x0000003cu,0x0000012eu,0x00000127u,0x00070058u,0x0000004cu,0x0000012fu,0x0000012du,0x0000012eu,0x00000002u,0x0000008fu,0x0007004fu,0x0000003cu,0x00000130u,0x0000012fu,0x0000012fu,0x00000000u,0x00000001u,0x00050041u,0x00000051u,0x00000131u,0x0000004fu,0x00000099u,0x0004003du,0x00000006u,0x00000132u,0x00000131u,0x0005008eu,0x0000003cu,0x00000133u,0x00000130u,0x00000132u,0x0004003du,0x0000003cu,0x00000134u,0x0000003eu,0x00050085u,0x0000003cu,0x00000135u,0x00000133u,0x00000134u,0x00050081u,0x0000003cu,0x00000136u,0x0000012cu,0x00000135u,0x0006000cu,0x00000006u,0x00000137u,0x00000001u,0x00000042u,0x00000136u,0x0003003eu,0x0000012bu,0x00000137u,0x0004003du,0x00000006u,0x00000139u,0x000000c1u,0x0004003du,0x00000006u,0x0000013au,0x000000c5u,0x0007000cu,0x00000006u,0x0000013bu,0x00000001u,0x00000025u,0x00000139u,0x0000013au,0x0004003du,0x00000006u,0x0000013cu,0x0000012bu,0x0004007fu,0x00000006u,0x0000013du,0x0000013cu,0x0004003du,0x0000003cu,0x0000013eu,0x000000b3u,0x0006000cu,0x00000006u,0x0000013fu,0x00000001u,0x00000042u,0x0000013eu,0x0004003du,0x0000003cu,0x00000140u,0x000000bau,0x0006000cu,0x00000006u,0x00000141u,0x00000001u,0x00000042u,0x00000140u,0x00050081u,0x00000006u,0x00000142u,0x0000013fu,0x00000141u,0x00050041u,0x0000009eu,0x00000143u,0x0000003eu,0x00000028u,0x0004003du,0x00000006u,0x00000144u,0x00000143u,0x00050081u,0x00000006u,0x00000145u,0x00000142u,0x00000144u,0x00050088u,0x00000006u,0x00000146u,0x0000013du,0x00000145u,0x0006000cu,0x00000006u,0x00000147u,0x00000001u,0x0000001bu,0x00000146u,0x00050085u,0x00000006u,0x00000148u,0x0000013bu,0x00000147u,0x0003003eu,0x00000138u,0x00000148u,0x00050041u,0x00000051u,0x0000014bu,0x0000004fu,0x0000014au,0x0004003du,0x00000006u,0x0000014cu,0x0000014bu,0x0004003du,0x00000006u,0x0000014du,0x000000fbu,0x00050085u,0x00000006u,0x0000014eu,0x0000014cu,0x0000014du,0x00050041u,0x00000051u,0x00000150u,0x0000004fu,0x0000014fu,0x0004003du,0x00000006u,0x00000151u,0x00000150u,0x0004003du,0x00000006u,0x00000152u,0x00000138u,0x00050083u,0x00000006u,0x00000153u,0x0000003fu,0x00000152u,0x00050085u,0x00000006u,0x00000154u,0x00000151u,0x00000153u,0x00050081u,0x00000006u,0x00000155u,0x0000014eu,0x00000154u,0x0004007fu,0x00000006u,0x00000156u,0x00000155u,0x0003003eu,0x00000149u,0x00000156u,0x00050041u,0x00000051u,0x00000158u,0x0000004fu,0x0000014au,0x0004003du,0x00000006u,0x00000159u,0x00000158u,0x0004003du,0x00000006u,0x0000015au,0x00000111u,0x00050085u,0x00000006u,0x0000015bu,0x00000159u,0x0000015au,0x00050041u,0x00000051u,0x0000015cu,0x0000004fu,0x0000014fu,0x0004003du,0x00000006u,0x0000015du,0x0000015cu,0x0004003du,0x00000006u,0x0000015eu,0x00000138u,0x00050083u,0x00000006u,0x0000015fu,0x0000003fu,0x0000015eu,0x00050085u,0x00000006u,0x00000160u,0x0000015du,0x0000015fu,0x00050081u,0x00000006u,0x00000161u,0x0000015bu,0x00000160u,0x0004007fu,0x00000006u,0x00000162u,0x00000161u,0x0003003eu,0x00000157u,0x00000162u,0x00050041u,0x00000051u,0x00000164u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x00000165u,0x00000164u,0x00050083u,0x00000006u,0x00000166u,0x0000003fu,0x00000165u,0x0003003eu,0x00000163u,0x00000166u,0x00050041u,0x00000051u,0x00000168u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x00000169u,0x00000168u,0x0003003eu,0x00000167u,0x00000169u,0x0004003du,0x00000006u,0x0000016bu,0x00000149u,0x0004003du,0x00000006u,0x0000016cu,0x00000157u,0x0007000cu,0x00000006u,0x0000016du,0x00000001u,0x00000028u,0x0000016bu,0x0000016cu,0x0003003eu,0x0000016au,0x0000016du,0x0004003du,0x00000006u,0x0000016fu,0x00000163u,0x00050041u,0x00000051u,0x00000171u,0x0000004fu,0x00000170u,0x0004003du,0x00000006u,0x00000172u,0x00000171u,0x0004003du,0x00000006u,0x00000173u,0x00000149u,0x0004003du,0x00000006u,0x00000174u,0x0000016au,0x00050083u,0x00000006u,0x00000175u,0x00000173u,0x00000174u,0x00050085u,0x00000006u,0x00000176u,0x00000172u,0x00000175u,0x0006000cu,0x00000006u,0x00000177u,0x00000001u,0x0000001bu,0x00000176u,0x00050085u,0x00000006u,0x00000178u,0x0000016fu,0x00000177u,0x0003003eu,0x0000016eu,0x00000178u,0x0004003du,0x00000006u,0x0000017au,0x00000167u,0x00050041u,0x00000051u,0x0000017bu,0x0000004fu,0x00000170u,0x0004003du,0x00000006u,0x0000017cu,0x0000017bu,0x0004003du,0x00000006u,0x0000017du,0x00000157u,0x0004003du,0x00000006u,0x0000017eu,0x0000016au,0x00050083u,0x00000006u,0x0000017fu,0x0000017du,0x0000017eu,0x00050085u,0x00000006u,0x00000180u,0x0000017cu,0x0000017fu,0x0006000cu,0x00000006u,0x00000181u,0x00000001u,0x0000001bu,0x00000180u,0x00050085u,0x00000006u,0x00000182u,0x0000017au,0x00000181u,0x0003003eu,0x00000179u,0x00000182u,0x0004003du,0x00000006u,0x00000184u,0x0000016eu,0x0004003du,0x00000006u,0x00000185u,0x00000179u,0x00050081u,0x00000006u,0x00000186u,0x00000184u,0x00000185u,0x0003003eu,0x00000183u,0x00000186u,0x0004003du,0x00000006u,0x00000188u,0x00000183u,0x000500bau,0x00000027u,0x0000018au,0x00000188u,0x00000189u,0x000300f7u,0x0000018du,0x00000000u,0x000400fau,0x0000018au,0x0000018cu,0x00000198u,0x000200f8u,0x0000018cu,0x0004003du,0x00000006u,0x0000018eu,0x0000016eu,0x0004003du,0x00000007u,0x0000018fu,0x000000f0u,0x0005008eu,0x00000007u,0x00000190u,0x0000018fu,0x0000018eu,0x0004003du,0x00000006u,0x00000191u,0x00000179u,0x0004003du,0x00000007u,0x00000192u,0x000000f6u,0x0005008eu,0x00000007u,0x00000193u,0x00000192u,0x00000191u,0x00050081u,0x00000007u,0x00000194u,0x00000190u,0x00000193u,0x0004003du,0x00000006u,0x00000195u,0x00000183u,0x00060050u,0x00000007u,0x00000196u,0x00000195u,0x00000195u,0x00000195u,0x00050088u,0x00000007u,0x00000197u,0x00000194u,0x00000196u,0x0003003eu,0x0000018bu,0x00000197u,0x000200f9u,0x0000018du,0x000200f8u,0x00000198u,0x0004003du,0x00000007u,0x00000199u,0x000000f0u,0x0004003du,0x00000007u,0x0000019au,0x000000f6u,0x00050041u,0x00000051u,0x0000019bu,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x0000019cu,0x0000019bu,0x00060050u,0x00000007u,0x0000019du,0x0000019cu,0x0000019cu,0x0000019cu,0x0008000cu,0x00000007u,0x0000019eu,0x00000001u,0x0000002eu,0x00000199u,0x0000019au,0x0000019du,0x0003003eu,0x0000018bu,0x0000019eu,0x000200f9u,0x0000018du,0x000200f8u,0x0000018du,0x0004003du,0x00000007u,0x0000019fu,0x0000018bu,0x0003003eu,0x00000187u,0x0000019fu,0x0004003du,0x0000008au,0x000001a1u,0x000000f1u,0x0004003du,0x0000003cu,0x000001a2u,0x00000044u,0x00070058u,0x0000004cu,0x000001a3u,0x000001a1u,0x000001a2u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001a4u,0x000001a3u,0x000001a3u,0x00000000u,0x00000001u,0x00000002u,0x0004003du,0x0000008au,0x000001a5u,0x0000008cu,0x0004003du,0x0000003cu,0x000001a6u,0x00000044u,0x00070058u,0x0000004cu,0x000001a7u,0x000001a5u,0x000001a6u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001a8u,0x000001a7u,0x000001a7u,0x00000000u,0x00000001u,0x00000002u,0x00050041u,0x00000051u,0x000001a9u,0x0000004fu,0x000000e2u,0x0004003du,0x00000006u,0x000001aau,0x000001a9u,0x00060050u,0x00000007u,0x000001abu,0x000001aau,0x000001aau,0x000001aau,0x0008000cu,0x00000007u,0x000001acu,0x00000001u,0x0000002eu,0x000001a4u,0x000001a8u,0x000001abu,0x0003003eu,0x000001a0u,0x000001acu,0x0004003du,0x00000006u,0x000001aeu,0x000000fbu,0x0004003du,0x00000006u,0x000001afu,0x00000111u,0x0007000cu,0x00000006u,0x000001b0u,0x00000001u,0x00000025u,0x000001aeu,0x000001afu,0x0003003eu,0x000001adu,0x000001b0u,0x0004003du,0x00000006u,0x000001b4u,0x000001adu,0x0008000cu,0x00000006u,0x000001b5u,0x00000001u,0x00000031u,0x000001b2u,0x000001b3u,0x000001b4u,0x00050083u,0x00000006u,0x000001b6u,0x0000003fu,0x000001b5u,0x0003003eu,0x000001b1u,0x000001b6u,0x0004003du,0x00000006u,0x000001b8u,0x00000138u,0x0008000cu,0x00000006u,0x000001b9u,0x00000001u,0x0000002bu,0x000001b8u,0x0000008fu,0x0000003fu,0x0004003du,0x00000006u,0x000001bau,0x000001b1u,0x00050085u,0x00000006u,0x000001bbu,0x000001b9u,0x000001bau,0x0003003eu,0x000001b7u,0x000001bbu,0x00050041u,0x00000051u,0x000001bdu,0x0000004fu,0x000001bcu,0x0004003du,0x00000006u,0x000001beu,0x000001bdu,0x0004003du,0x00000006u,0x000001bfu,0x00000183u,0x0008000cu,0x00000006u,0x000001c0u,0x00000001u,0x00000031u,0x0000008fu,0x000001beu,0x000001bfu,0x0004003du,0x00000006u,0x000001c1u,0x000001b7u,0x00050085u,0x00000006u,0x000001c2u,0x000001c1u,0x000001c0u,0x0003003eu,0x000001b7u,0x000001c2u,0x0004003du,0x0000008au,0x000001c4u,0x000000f1u,0x0004003du,0x0000003cu,0x000001c5u,0x00000044u,0x00070058u,0x0000004cu,0x000001c6u,0x000001c4u,0x000001c5u,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001c7u,0x000001c6u,0x000001c6u,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000001c3u,0x000001c7u,0x0004003du,0x0000008au,0x000001c9u,0x0000008cu,0x0004003du,0x0000003cu,0x000001cau,0x00000044u,0x00070058u,0x0000004cu,0x000001cbu,0x000001c9u,0x000001cau,0x00000002u,0x0000008fu,0x0008004fu,0x00000007u,0x000001ccu,0x000001cbu,0x000001cbu,0x00000000u,0x00000001u,0x00000002u,0x0003003eu,0x000001c8u,0x000001ccu,0x0004003du,0x00000007u,0x000001ceu,0x000001c8u,0x0004003du,0x00000007u,0x000001cfu,0x000001c3u,0x00050083u,0x00000007u,0x000001d0u,0x000001ceu,0x000001cfu,0x0006000cu,0x00000006u,0x000001d1u,0x00000001u,0x00000042u,0x000001d0u,0x0003003eu,0x000001cdu,0x000001d1u,0x0004003du,0x00000006u,0x000001d4u,0x000001b7u,0x0008000cu,0x00000006u,0x000001d5u,0x00000001u,0x00000031u,0x000000cdu,0x000001d3u,0x000001d4u,0x00050083u,0x00000006u,0x000001d6u,0x0000003fu,0x000001d5u,0x0003003eu,0x000001d2u,0x000001d6u,0x0004003du,0x00000006u,0x000001dau,0x000001cdu,0x0008000cu,0x00000006u,0x000001dbu,0x00000001u,0x00000031u,0x000001d8u,0x000001d9u,0x000001dau,0x0003003eu,0x000001d7u,0x000001dbu,0x0004003du,0x00000006u,0x000001ddu,0x000001d2u,0x0004003du,0x00000006u,0x000001deu,0x000001d7u,0x00050085u,0x00000006u,0x000001dfu,0x000001ddu,0x000001deu,0x0003003eu,0x000001dcu,0x000001dfu,0x0004003du,0x00000007u,0x000001e0u,0x000001a0u,0x0004003du,0x00000007u,0x000001e1u,0x000001c8u,0x0004003du,0x00000006u,0x000001e2u,0x000001dcu,0x00060050u,0x00000007u,0x000001e3u,0x000001e2u,0x000001e2u,0x000001e2u,0x0008000cu,0x00000007u,0x000001e4u,0x00000001u,0x0000002eu,0x000001e0u,0x000001e1u,0x000001e3u,0x0003003eu,0x000001a0u,0x000001e4u,0x0004003du,0x00000007u,0x000001e6u,0x000001a0u,0x0004003du,0x00000007u,0x000001e7u,0x00000187u,0x0004003du,0x00000006u,0x000001e8u,0x000001b7u,0x00060050u,0x00000007u,0x000001e9u,0x000001e8u,0x000001e8u,0x000001e8u,0x0008000cu,0x00000007u,0x000001eau,0x00000001u,0x0000002eu,0x000001e6u,0x000001e7u,0x000001e9u,0x0003003eu,0x000001e5u,0x000001eau,0x0004003du,0x00000027u,0x000001ebu,0x00000098u,0x000300f7u,0x000001edu,0x00000000u,0x000400fau,0x000001ebu,0x000001ecu,0x000001edu,0x000200f8u,0x000001ecu,0x0004003du,0x00000006u,0x000001efu,0x000000c9u,0x0004003du,0x00000006u,0x000001f0u,0x000000d5u,0x0007000cu,0x00000006u,0x000001f1u,0x00000001u,0x00000028u,0x000001efu,0x000001f0u,0x0003003eu,0x000001eeu,0x000001f1u,0x0004003du,0x00000006u,0x000001f3u,0x000001eeu,0x00050088u,0x00000006u,0x000001f4u,0x000001f3u,0x000000cdu,0x0008000cu,0x00000006u,0x000001f5u,0x00000001u,0x0000002bu,0x000001f4u,0x0000008fu,0x0000003fu,0x0003003eu,0x000001f2u,0x000001f5u,0x0004003du,0x00000006u,0x000001f7u,0x000001eeu,0x0007000cu,0x00000006u,0x000001f8u,0x00000001u,0x00000030u,0x000000cdu,0x000001f7u,0x0003003eu,0x000001f6u,0x000001f8u,0x0004003du,0x00000022u,0x000001f9u,0x00000024u,0x0004003du,0x00000016u,0x000001fau,0x00000018u,0x0004003du,0x00000006u,0x000001fbu,0x000001f6u,0x0004003du,0x00000006u,0x000001fcu,0x000001f2u,0x00070050u,0x0000004cu,0x000001fdu,0x000001fbu,0x000001fcu,0x0000008fu,0x0000003fu,0x00040063u,0x000001f9u,0x000001fau,0x000001fdu,0x000100fdu,0x000200f8u,0x000001edu,0x0004003du,0x00000022u,0x000001ffu,0x00000024u,0x0004003du,0x00000016u,0x00000200u,0x00000018u,0x0004003du,0x00000007u,0x00000201u,0x000001e5u,0x00050051u,0x00000006u,0x00000202u,0x00000201u,0x00000000u,0x00050051u,0x00000006u,0x00000203u,0x00000201u,0x00000001u,0x00050051u,0x00000006u,0x00000204u,0x00000201u,0x00000002u,0x00070050u,0x0000004cu,0x00000205u,0x00000202u,0x00000203u,0x00000204u,0x0000003fu,0x00040063u,0x000001ffu,0x00000200u,0x00000205u,0x000100fdu,0x00010038u,0x00050036u,0x00000006u,0x0000000bu,0x00000000u,0x00000009u,0x00030037u,0x00000008u,0x0000000au,0x000200f8u,0x0000000cu,0x0004003du,0x00000007u,0x0000000du,0x0000000au,0x00050094u,0x00000006u,0x00000012u,0x0000000du,0x00000011u,0x000200feu,0x00000012u,0x00010038u}; +static const size_t WFG_SYNTH_LEN = 3082; +struct Blob { const uint32_t* code; size_t words; }; +enum Shader { OF3_LUMA, OF3_DOWNSAMPLE, OF3_FLOW, OF3_EXPAND, OF3_FLOW_M4, OF3_EXPAND_M4, OF3_GM_REDUCE, OF3_GM_PREWARP, OF3_FLOWREG, WFG_SYNTH, SHADER_COUNT }; +static inline Blob blob(Shader s) { + switch (s) { + case OF3_LUMA: return { OF3_LUMA_SPV, OF3_LUMA_LEN }; + case OF3_DOWNSAMPLE: return { OF3_DOWNSAMPLE_SPV, OF3_DOWNSAMPLE_LEN }; + case OF3_FLOW: return { OF3_FLOW_SPV, OF3_FLOW_LEN }; + case OF3_EXPAND: return { OF3_EXPAND_SPV, OF3_EXPAND_LEN }; + case OF3_FLOW_M4: return { OF3_FLOW_M4_SPV, OF3_FLOW_M4_LEN }; + case OF3_EXPAND_M4: return { OF3_EXPAND_M4_SPV, OF3_EXPAND_M4_LEN }; + case OF3_GM_REDUCE: return { OF3_GM_REDUCE_SPV, OF3_GM_REDUCE_LEN }; + case OF3_GM_PREWARP: return { OF3_GM_PREWARP_SPV, OF3_GM_PREWARP_LEN }; + case OF3_FLOWREG: return { OF3_FLOWREG_SPV, OF3_FLOWREG_LEN }; + case WFG_SYNTH: return { WFG_SYNTH_SPV, WFG_SYNTH_LEN }; + default: return { nullptr, 0 }; + } +} +} } // namespace winfg::embedded diff --git a/app/src/main/cpp/winlator/winfg/framegen.cpp b/app/src/main/cpp/winlator/winfg/framegen.cpp new file mode 100644 index 0000000000..fd04cdd895 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/framegen.cpp @@ -0,0 +1,269 @@ +// win-fg — compute frame-generation engine implementation. +#include "framegen.hpp" +#include "embedded_shaders.hpp" +#include "log.hpp" +#include +#include + +namespace winfg { + +#define VKOK(x) do { if ((x) != VK_SUCCESS) { WFG_LOGE("vk fail: %s", #x); return false; } } while (0) + +uint32_t FrameGen::findMemType(uint32_t bits, VkMemoryPropertyFlags props) const { + for (uint32_t i = 0; i < memProps_.memoryTypeCount; ++i) + if ((bits & (1u << i)) && (memProps_.memoryTypes[i].propertyFlags & props) == props) + return i; + return 0; +} + +bool FrameGen::makeImage(Img& out, VkExtent2D ext, VkFormat fmt, VkImageUsageFlags usage) { + out.extent = ext; out.fmt = fmt; + VkImageCreateInfo ci{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; + ci.imageType = VK_IMAGE_TYPE_2D; + ci.format = fmt; + ci.extent = {ext.width, ext.height, 1}; + ci.mipLevels = 1; ci.arrayLayers = 1; + ci.samples = VK_SAMPLE_COUNT_1_BIT; + ci.tiling = VK_IMAGE_TILING_OPTIMAL; + ci.usage = usage; + ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + VKOK(dd_->CreateImage(device_, &ci, nullptr, &out.image)); + VkMemoryRequirements mr; dd_->GetImageMemoryRequirements(device_, out.image, &mr); + VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; + ai.allocationSize = mr.size; + ai.memoryTypeIndex = findMemType(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + VKOK(dd_->AllocateMemory(device_, &ai, nullptr, &out.mem)); + VKOK(dd_->BindImageMemory(device_, out.image, out.mem, 0)); + VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; + vi.image = out.image; vi.viewType = VK_IMAGE_VIEW_TYPE_2D; vi.format = fmt; + vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + VKOK(dd_->CreateImageView(device_, &vi, nullptr, &out.view)); + return true; +} + +void FrameGen::destroyImage(Img& i) { + if (i.view) dd_->DestroyImageView(device_, i.view, nullptr); + if (i.image) dd_->DestroyImage(device_, i.image, nullptr); + if (i.mem) dd_->FreeMemory(device_, i.mem, nullptr); + i = Img{}; +} + +// C1: allocate the per-slot host-visible SSBOs the LK reduce writes partials into. +// Host-visible + coherent so the CPU can read them back after the owning frame's +// fence signals (no staging copy needed; the buffers are tiny — kGmThreads*kGmStride +// floats each, ~64 KB). Persistently mapped. +bool FrameGen::makeGmBuffers() { + const VkDeviceSize sz = (VkDeviceSize)kGmThreads * kGmStride * sizeof(float); + const VkMemoryPropertyFlags want = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + for (int s = 0; s < kGmSlots; ++s) { + VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; + bi.size = sz; bi.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + VKOK(dd_->CreateBuffer(device_, &bi, nullptr, &gmSsbo_[s])); + VkMemoryRequirements mr; dd_->GetBufferMemoryRequirements(device_, gmSsbo_[s], &mr); + VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; + ai.allocationSize = mr.size; ai.memoryTypeIndex = findMemType(mr.memoryTypeBits, want); + VKOK(dd_->AllocateMemory(device_, &ai, nullptr, &gmSsboMem_[s])); + VKOK(dd_->BindBufferMemory(device_, gmSsbo_[s], gmSsboMem_[s], 0)); + VKOK(dd_->MapMemory(device_, gmSsboMem_[s], 0, sz, 0, &gmSsboPtr_[s])); + std::memset(gmSsboPtr_[s], 0, (size_t)sz); + gmSlotValid_[s] = false; + } + gmBuffersReady_ = true; + return true; +} + +bool FrameGen::makePipe(Pipe& p, int shaderId, + const std::vector&) { + // binding layout is derived per shader below in init(); here we only build + // the module + a generic layout supplied by caller via setLayout already set. + embedded::Blob b = embedded::blob((embedded::Shader)shaderId); + VkShaderModuleCreateInfo mi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; + mi.codeSize = b.words * 4; mi.pCode = b.code; + VKOK(dd_->CreateShaderModule(device_, &mi, nullptr, &p.module)); + VkPipelineLayoutCreateInfo li{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; + li.setLayoutCount = 1; li.pSetLayouts = &p.setLayout; + VKOK(dd_->CreatePipelineLayout(device_, &li, nullptr, &p.layout)); + VkComputePipelineCreateInfo pi{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; + pi.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + pi.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; + pi.stage.module = p.module; pi.stage.pName = "main"; + pi.layout = p.layout; + VKOK(dd_->CreateComputePipelines(device_, VK_NULL_HANDLE, 1, &pi, nullptr, &p.pipeline)); + return true; +} + +void FrameGen::destroyPipe(Pipe& p) { + if (p.pipeline) dd_->DestroyPipeline(device_, p.pipeline, nullptr); + if (p.layout) dd_->DestroyPipelineLayout(device_, p.layout, nullptr); + if (p.setLayout) dd_->DestroyDescriptorSetLayout(device_, p.setLayout, nullptr); + if (p.module) dd_->DestroyShaderModule(device_, p.module, nullptr); + p = Pipe{}; +} + +// Build a descriptor-set layout from an explicit (binding, type) list. +static bool buildSetLayout(const DeviceDispatch* dd, VkDevice dev, + const std::vector>& binds, + VkDescriptorSetLayout& out) { + std::vector b; + for (auto& kv : binds) + b.push_back({kv.first, kv.second, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}); + VkDescriptorSetLayoutCreateInfo ci{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; + ci.bindingCount = (uint32_t)b.size(); ci.pBindings = b.data(); + return dd->CreateDescriptorSetLayout(dev, &ci, nullptr, &out) == VK_SUCCESS; +} + +bool FrameGen::init(const DeviceDispatch* dd, const InstanceDispatch* id, + VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue) { + dd_ = dd; id_ = id; phys_ = phys; device_ = dev; queueFamily_ = queueFamily; queue_ = queue; + id_->GetPhysicalDeviceMemoryProperties(phys_, &memProps_); + + VkSamplerCreateInfo si{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; + si.magFilter = si.minFilter = VK_FILTER_LINEAR; + si.addressModeU = si.addressModeV = si.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + VKOK(dd_->CreateSampler(device_, &si, nullptr, &linear_)); + + // descriptor pool sized generously for our per-frame sets. + VkDescriptorPoolSize sizes[] = { + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 256}, + {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 256}, + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 64}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 16}, // C1 LK-reduce SSBOs + }; + VkDescriptorPoolCreateInfo pci{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; + pci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; + pci.maxSets = 256; pci.poolSizeCount = 4; pci.pPoolSizes = sizes; + VKOK(dd_->CreateDescriptorPool(device_, &pci, nullptr, &descPool_)); + + using B = std::pair; + const auto S = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + const auto W = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + const auto U = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + const auto SB = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + + // per-shader binding sets (match the GLSL layout(binding=...) declarations) + if (!buildSetLayout(dd_, dev, {B{32,S},B{48,W}}, pLuma_.setLayout)) return false; + if (!buildSetLayout(dd_, dev, {B{32,S},B{48,W}}, pDown_.setLayout)) return false; + if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{48,W}}, pFlow_.setLayout)) return false; + if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{48,W}}, pFlowM4_.setLayout)) return false; + // C1: expand sets gain a second UBO (binding 1 = GMUBO) for the global-motion add-back. + if (!buildSetLayout(dd_, dev, {B{0,U},B{1,U},B{32,S},B{48,W},B{49,W}}, pExpand_.setLayout)) return false; + if (!buildSetLayout(dd_, dev, {B{0,U},B{1,U},B{32,S},B{48,W},B{49,W}}, pExpandM4_.setLayout)) return false; + if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{35,S},B{48,W}}, pSynth_.setLayout)) return false; + // C1: LK-reduce (UBO, SSBO, prev, curr) and curr-luma stabilization prewarp (UBO, src, dst). + if (!buildSetLayout(dd_, dev, {B{1,U},B{16,SB},B{32,S},B{33,S}}, pGmReduce_.setLayout)) return false; + if (!buildSetLayout(dd_, dev, {B{1,U},B{32,S},B{48,W}}, pGmPrewarp_.setLayout)) return false; + // C2: flow-reg (UBO, u_in, f0_obs, luma, out). + if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{48,W}}, pFlowReg_.setLayout)) return false; + + std::vector unused; + if (!makePipe(pLuma_, embedded::OF3_LUMA, unused)) return false; + if (!makePipe(pDown_, embedded::OF3_DOWNSAMPLE, unused)) return false; + if (!makePipe(pFlow_, embedded::OF3_FLOW, unused)) return false; + if (!makePipe(pFlowM4_, embedded::OF3_FLOW_M4, unused)) return false; + if (!makePipe(pExpand_, embedded::OF3_EXPAND, unused)) return false; + if (!makePipe(pExpandM4_, embedded::OF3_EXPAND_M4, unused)) return false; + if (!makePipe(pGmReduce_, embedded::OF3_GM_REDUCE, unused)) return false; + if (!makePipe(pGmPrewarp_, embedded::OF3_GM_PREWARP, unused)) return false; + if (!makePipe(pFlowReg_, embedded::OF3_FLOWREG, unused)) return false; + if (!makePipe(pSynth_, embedded::WFG_SYNTH, unused)) return false; + if (!makeGmBuffers()) { WFG_LOGE("framegen: GM SSBO alloc failed — C1 disabled"); } + WFG_LOGI("framegen init ok (queueFamily=%u, 10 pipelines, model=%d, C1 gm=%d, C2 flow_reg=%d iters=%d)", + queueFamily_, cfg_.model, cfg_.gmMode, cfg_.frMode, cfg_.frIters); + return true; +} + +static VkExtent2D levelExtent(VkExtent2D e, int l) { + return { e.width >> l ? e.width >> l : 1u, e.height >> l ? e.height >> l : 1u }; +} + +bool FrameGen::onResize(VkExtent2D extent, VkFormat /*colorFormat*/, bool force) { + // force skips the same-extent early-out so a perf_preset change (which alters + // flowFinest_ and therefore the per-size flow-image resolutions) rebuilds them. + if (!force && ready_ && extent.width == extent_.width && extent.height == extent_.height) return true; + // tear down previous size + for (auto& i : pyrA_) destroyImage(i); pyrA_.clear(); + for (auto& i : pyrB_) destroyImage(i); pyrB_.clear(); + for (auto& i : pyrAs_) destroyImage(i); pyrAs_.clear(); + for (auto& i : flowLvl_) destroyImage(i); flowLvl_.clear(); + destroyImage(flowExpA_); destroyImage(flowExpB_); + destroyImage(flowRegA_); destroyImage(flowRegB_); // C2 + extent_ = extent; ready_ = false; + + const VkImageUsageFlags lumaUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; + // flowLvl_ is cleared every frame (per-frame reset) and C2 copies the cleaned + // finest level back into it — both need TRANSFER_DST. The C2 ping-pong images + // are the copy SOURCE (TRANSFER_SRC). + const VkImageUsageFlags flowUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + const VkImageUsageFlags regUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + pyrA_.resize(kLevels); pyrB_.resize(kLevels); flowLvl_.resize(kLevels); + for (int l = 0; l < kLevels; ++l) { + VkExtent2D e = levelExtent(extent, l); + if (!makeImage(pyrA_[l], e, VK_FORMAT_R32_SFLOAT, lumaUsage)) return false; + if (!makeImage(pyrB_[l], e, VK_FORMAT_R32_SFLOAT, lumaUsage)) return false; + if (!makeImage(flowLvl_[l], e, VK_FORMAT_R16G16B16A16_SFLOAT, flowUsage)) return false; + } + // C1: stabilized curr luma — only the levels the dense flow reads (finest..coarsest). + pyrAs_.resize(kLevels); + for (int l = flowFinest_; l < kLevels; ++l) + if (!makeImage(pyrAs_[l], levelExtent(extent, l), VK_FORMAT_R32_SFLOAT, lumaUsage)) return false; + if (!makeImage(flowExpA_, extent, VK_FORMAT_R16G16B16A16_SFLOAT, flowUsage)) return false; + if (!makeImage(flowExpB_, extent, VK_FORMAT_R16G16B16A16_SFLOAT, flowUsage)) return false; + // C2: TV-L1 ping-pong scratch at the finest solved flow level (perf_preset-driven res). + if (!makeImage(flowRegA_, levelExtent(extent, flowFinest_), VK_FORMAT_R16G16B16A16_SFLOAT, regUsage)) return false; + if (!makeImage(flowRegB_, levelExtent(extent, flowFinest_), VK_FORMAT_R16G16B16A16_SFLOAT, regUsage)) return false; + ready_ = true; + WFG_LOGI("framegen resized to %ux%u (%d pyramid levels, kFlowFinest=%d perf_preset=%d)", + extent.width, extent.height, kLevels, flowFinest_, cfg_.perfPreset); + return true; +} + +void FrameGen::barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to) { + VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; + b.oldLayout = from; b.newLayout = to; + b.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; + b.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + b.image = img; b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); +} + +// NOTE: descriptor-set allocation/update per record() and the exact per-level +// flow wiring are implemented in record_impl.inc for readability; the graph is: +// luma(curr)->pyrA[0], luma(prev)->pyrB[0] +// downsample pyrA/pyrB to kLevels +// coarse->fine flow (per level) into flowLvl +// expand flowLvl[0] -> flowExpA/flowExpB +// synth(prev,curr,flowExpA,flowExpB, alpha) -> out + +void FrameGen::destroy() { + if (!device_) return; + dd_->DeviceWaitIdle(device_); + for (auto& i : pyrA_) destroyImage(i); pyrA_.clear(); + for (auto& i : pyrB_) destroyImage(i); pyrB_.clear(); + for (auto& i : pyrAs_) destroyImage(i); pyrAs_.clear(); + for (auto& i : flowLvl_) destroyImage(i); flowLvl_.clear(); + destroyImage(flowExpA_); destroyImage(flowExpB_); + destroyImage(flowRegA_); destroyImage(flowRegB_); // C2 + destroyPipe(pLuma_); destroyPipe(pDown_); destroyPipe(pFlow_); destroyPipe(pFlowM4_); + destroyPipe(pExpand_); destroyPipe(pExpandM4_); destroyPipe(pSynth_); + destroyPipe(pGmReduce_); destroyPipe(pGmPrewarp_); + destroyPipe(pFlowReg_); // C2 + for (int s = 0; s < kGmSlots; ++s) { + if (gmSsboMem_[s]) dd_->UnmapMemory(device_, gmSsboMem_[s]); + if (gmSsbo_[s]) dd_->DestroyBuffer(device_, gmSsbo_[s], nullptr); + if (gmSsboMem_[s]) dd_->FreeMemory(device_, gmSsboMem_[s], nullptr); + gmSsbo_[s] = VK_NULL_HANDLE; gmSsboMem_[s] = VK_NULL_HANDLE; gmSsboPtr_[s] = nullptr; + } + gmBuffersReady_ = false; + if (descPool_) dd_->DestroyDescriptorPool(device_, descPool_, nullptr); + if (linear_) dd_->DestroySampler(device_, linear_, nullptr); + descPool_ = VK_NULL_HANDLE; linear_ = VK_NULL_HANDLE; device_ = VK_NULL_HANDLE; ready_ = false; +} + +} // namespace winfg + +// record() + its scratch helpers reopen namespace winfg themselves, so include +// this OUTSIDE the namespace block above (keeps FrameGen:: members attached). +#include "record_impl.inc" diff --git a/app/src/main/cpp/winlator/winfg/framegen.hpp b/app/src/main/cpp/winlator/winfg/framegen.hpp new file mode 100644 index 0000000000..266d9a4144 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/framegen.hpp @@ -0,0 +1,151 @@ +// win-fg — compute frame-generation engine. +// Owns the compute pipelines (our of3_* optical flow + wfg_synth) and the +// per-resolution intermediate images, and records the flow+synth graph that +// turns (prev, curr) into an interpolated frame. Written for win-fg; no code +// from bionic-fg / lsfg / GameScope. +#pragma once +#include "vk_dispatch.hpp" +#include "config.hpp" +#include + +namespace winfg { + +class FrameGen { +public: + bool init(const DeviceDispatch* dd, const InstanceDispatch* id, + VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue); + // Applies a new config. Recomputes the active finest flow level from + // cfg_.perfPreset; if it changed while resources are live, safely rebuilds the + // affected per-size flow images (like a resize) and resets the flow predictor, + // so a perf_preset change is FULLY LIVE — no FG toggle needed. Defined in + // record_impl.inc (needs the scratch-state teardown). See flowFinestForPreset. + void configure(const Config& c); + // (Re)build per-resolution resources for a swapchain of the given size/format. + // force=true rebuilds even when the extent is unchanged (used by configure() + // when a perf_preset change alters the finest solved flow level). + bool onResize(VkExtent2D extent, VkFormat colorFormat, bool force = false); + // Record the whole flow+synth graph into cmd. prevView/currView are SAMPLED + // views of the two real frames; outView is a STORAGE view of the target + // image the generated frame is written into. alpha in (0,1). + // gmSlot selects which C1 global-motion SSBO to reduce into / read back; the + // caller MUST pass the ring-slot index of the FrameCtx it just fence-waited + // (that guarantees this slot's PREVIOUS reduce has completed and is safe to + // read on the host — see the decoupled-LK note in record_impl.inc). + void record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView, + VkImageView outView, float alpha, uint32_t gmSlot = 0); + void destroy(); + bool valid() const { return device_ != VK_NULL_HANDLE && ready_; } + const Config& config() const { return cfg_; } + + // public so the record_impl.inc free helpers can reference them + struct Img { VkImage image = VK_NULL_HANDLE; VkDeviceMemory mem = VK_NULL_HANDLE; + VkImageView view = VK_NULL_HANDLE; VkExtent2D extent{}; VkFormat fmt{}; }; + struct Pipe { VkPipeline pipeline = VK_NULL_HANDLE; VkPipelineLayout layout = VK_NULL_HANDLE; + VkDescriptorSetLayout setLayout = VK_NULL_HANDLE; VkShaderModule module = VK_NULL_HANDLE; }; + + // ── C1 GLOBAL-MOTION PRE-WARP constants (public so record_impl.inc's free + // helpers can size/index the SSBO pool). See of3_gm_reduce/of3_gm_prewarp. ── + static constexpr int kGmSlots = 3; // >= present ring size; one SSBO per in-flight ctx + static constexpr int kGmLevel = 3; // 1/8-res luma pyramid level for the LK estimate + static constexpr int kGmThreads = 512; // fixed reduce threads (8 groups * local_size_x 64) + static constexpr int kGmStride = 32; // floats/thread: 21 H + 6 b + coverage + resid + pad + // Finest pyramid level the dense flow is solved at (0 = full res). This is now + // RUNTIME-SELECTABLE via conf.toml perf_preset (0 Quality=1 / 1 Balanced=2 / + // 2 Performance=3). kFlowFinestDefault is the Balanced value (today's behaviour); + // the ACTIVE level lives in flowFinest_ and is read through flowFinest(). onResize + // sizes the stabilized-curr pyramid + C2 scratch from it, and record_impl.inc + // wires the flow/expand inputs to it — both must agree, so they all read + // flowFinest()/flowFinest_ (never a hard-coded 2). (Was a static constexpr = 2.) + static constexpr int kFlowFinestDefault = 2; // Balanced (perf_preset=1) + // Map perf_preset -> finest solved level. Out-of-range -> Balanced. A higher + // level = coarser (cheaper) flow = smaller base-FPS drop. configure() clamps the + // result against kLevels so at least two solved levels always remain. + static int flowFinestForPreset(int preset) { + switch (preset) { + case 0: return 1; // Quality ~1/2-res + case 2: return 3; // Performance ~1/8-res + case 1: default: return kFlowFinestDefault; // Balanced ~1/4-res (today) + } + } + // The ACTIVE finest solved flow level (set by configure() from perf_preset). + int flowFinest() const { return flowFinest_; } + +private: + uint32_t findMemType(uint32_t bits, VkMemoryPropertyFlags props) const; + bool makeImage(Img& out, VkExtent2D ext, VkFormat fmt, VkImageUsageFlags usage); + void destroyImage(Img& i); + bool makeGmBuffers(); // allocate the kGmSlots host-visible LK-reduce SSBOs + // Read back one reduce SSBO, solve the 6x6 inverse-compositional LK step, and + // update the running/applied global affine. Returns true if it engaged this + // frame. Implemented in record_impl.inc (has the ScratchState/UBO context). + bool updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent); + bool makePipe(Pipe& p, int shaderId, + const std::vector& bindings); + void destroyPipe(Pipe& p); + void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to); + + const DeviceDispatch* dd_ = nullptr; + const InstanceDispatch* id_ = nullptr; + VkPhysicalDevice phys_ = VK_NULL_HANDLE; + VkDevice device_ = VK_NULL_HANDLE; + VkQueue queue_ = VK_NULL_HANDLE; + uint32_t queueFamily_ = 0; + VkPhysicalDeviceMemoryProperties memProps_{}; + VkSampler linear_ = VK_NULL_HANDLE; + VkDescriptorPool descPool_ = VK_NULL_HANDLE; + + Config cfg_; + VkExtent2D extent_{}; + bool ready_ = false; + // ACTIVE finest solved flow level (perf_preset). Default = Balanced (today's 2) + // so an unconfigured engine and an unset conf.toml are byte-identical to before. + int flowFinest_ = kFlowFinestDefault; + + // pipelines + Pipe pLuma_, pDown_, pFlow_, pFlowM4_, pExpand_, pExpandM4_, pSynth_; + // C1: LK normal-equation reduce + curr-luma stabilization pre-warp + Pipe pGmReduce_, pGmPrewarp_; + // C2: TV-L1 flow-regularization iteration (one dispatch per iteration) + Pipe pFlowReg_; + + // per-resolution resources + // 7 levels (was 5): the coarsest levels set the max motion the solver can track. + // At 5 levels the reach was only ~±84px/frame at 720p, so fast camera motion + // (150-300px/frame at the periphery) saturated the search -> incoherent vectors + // -> oil-paint melt. Two more (tiny) coarse levels push the reach to ~±300px so + // large global motion is captured coherently instead of smeared. Near-zero cost: + // the extra levels are 40x22 and 20x11 images. + static const int kLevels = 7; + std::vector pyrA_, pyrB_; // luma pyramids for curr / prev + std::vector pyrAs_; // C1: STABILIZED curr luma (flow levels only) + std::vector flowLvl_; // per-level flow scratch + Img flowExpA_, flowExpB_; // fwd / bwd expanded flow (+conf) + // C2: TV-L1 ping-pong scratch at kFlowFinest res. flowLvl_[kFlowFinest] holds + // the fixed observation f0 (never written during the iterations); u ping-pongs + // between these two; the final iterate is copied back into flowLvl_[kFlowFinest] + // so of3_expand consumes the cleaned field with no binding change (⇒ skipping + // C2 leaves flowLvl_ byte-identical to pre-C2). + Img flowRegA_, flowRegB_; + + // ── C1 global-motion state ──────────────────────────────────────────────── + // Host-visible SSBOs the reduce shader writes per-thread partials into; the + // CPU sums + solves them. One per ring slot so a readback never races a live + // submission (the caller fence-waited its slot before calling record()). + VkBuffer gmSsbo_[kGmSlots] {}; + VkDeviceMemory gmSsboMem_[kGmSlots]{}; + void* gmSsboPtr_[kGmSlots]{}; + bool gmBuffersReady_ = false; + // running affine params p1..p6 in centered-UV space (see GMUBO in config.hpp); + // identity = all zero. gmLinAt_ records the linearization params in effect when + // each slot's reduce was dispatched (the correct IC-update base for that slot). + double gmRun_[6] {}; + double gmLinAt_[kGmSlots][6] {}; + bool gmSlotValid_[kGmSlots]{}; + bool gmHaveEst_ = false; // at least one good solve so far + int gmStableCount_ = 0; // consecutive good solves (auto-engage threshold) + bool gmEngaged_ = false; // is the affine being APPLIED this frame + float gmLastTransPx_ = 0.0f; // estimated global translation magnitude (full-res px), for logging + unsigned long long gmFrames_ = 0; +}; + +} // namespace winfg diff --git a/app/src/main/cpp/winlator/winfg/log.hpp b/app/src/main/cpp/winlator/winfg/log.hpp new file mode 100644 index 0000000000..e013e6f623 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/log.hpp @@ -0,0 +1,20 @@ +// win-fg — logging. On Android goes to logcat (tag "win-fg") so device bring-up +// can trace the layer; elsewhere falls back to stderr. +#pragma once +#if defined(__ANDROID__) + #include + #define WFG_LOGI(...) __android_log_print(ANDROID_LOG_INFO, "win-fg", __VA_ARGS__) + #define WFG_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "win-fg", __VA_ARGS__) +#else + #include + #define WFG_LOGI(...) do { std::fprintf(stderr, "[win-fg] " __VA_ARGS__); std::fprintf(stderr, "\n"); } while(0) + #define WFG_LOGE(...) do { std::fprintf(stderr, "[win-fg][E] " __VA_ARGS__); std::fprintf(stderr, "\n"); } while(0) +#endif + +// Runtime-gated granular debug trace. The gate is a RUNTIME bool (Config::debug), +// not a compile-time switch — a shipping .so carries the full trail but pays only +// a predicted-not-taken bool test per step when debug is off (no logcat write, no +// arg evaluation of the message). Same "win-fg" tag so the app captures it under +// its own UID. Used to step the present path so a freeze leaves an obvious last +// line at the stage that hung. Usage: WFG_LOGD(dbg, "P#%llu step ...", n); +#define WFG_LOGD(cond, ...) do { if (cond) WFG_LOGI(__VA_ARGS__); } while(0) diff --git a/app/src/main/cpp/winlator/winfg/record_impl.inc b/app/src/main/cpp/winlator/winfg/record_impl.inc new file mode 100644 index 0000000000..f14b2902de --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/record_impl.inc @@ -0,0 +1,649 @@ +// win-fg — FrameGen::record() and its lazy per-size descriptor/UBO setup. +// Included from framegen.cpp (has access to FrameGen privates). Written for +// win-fg; standard Vulkan compute wiring, no third-party code. +// +// ── C1 GLOBAL-MOTION PRE-WARP (this file wires it end to end) ───────────────── +// The dense SAD flow search melts on fast camera pans because the global motion +// saturates its window. C1 estimates the per-frame camera affine with a cheap +// inverse-compositional Lucas-Kanade solve (of3_gm_reduce accumulates the 6x6 +// normal equations at 1/8 res → CPU 6x6 Cholesky here), then of3_gm_prewarp +// removes it from the curr luma pyramid BEFORE the search, so the search only +// sees small, coherent, object-only residual motion. of3_expand(_m4) composes +// the global affine back so wfg_synth is unchanged and the final warp is correct. +// +// DECOUPLED (stall-free) SCHEDULING: a true in-frame CPU solve would need a +// mid-frame GPU submit+readback stall — unacceptable on a GPU-bound title. So we +// read back the reduce SSBO the caller ALREADY fence-waited (its ring slot from a +// couple of presents ago) and run ONE Gauss-Newton step per frame, warm-started +// from the running estimate. Camera motion is temporally smooth, so a ~1-2 frame +// old affine is an excellent predictor; and because the SAME affine is removed +// (prewarp) and added back (expand), the result is EXACT for any affine we pick — +// an approximate/stale one only changes how much residual the search must absorb, +// never correctness. Identity affine ⇒ byte-identical to the pre-C1 pipeline, so +// the bail-to-identity safety path can never be worse than "no pre-warp". + +namespace { +struct ScratchState { + // host-visible UBO buffers + VkBuffer synthUbo = VK_NULL_HANDLE; VkDeviceMemory synthUboMem = VK_NULL_HANDLE; void* synthUboPtr = nullptr; + std::vector flowUbo; std::vector flowUboMem; std::vector flowUboPtr; + VkBuffer expandUbo = VK_NULL_HANDLE; VkDeviceMemory expandUboMem = VK_NULL_HANDLE; void* expandUboPtr = nullptr; + // C2: flow-regularization UBO (shared by all iterations; refreshed per frame). + VkBuffer flowRegUbo = VK_NULL_HANDLE; VkDeviceMemory flowRegUboMem = VK_NULL_HANDLE; void* flowRegUboPtr = nullptr; + // C1: per-slot global-motion UBO (double-buffered by ring slot so a live GPU + // read is never overwritten by the next frame — see the header note). + VkBuffer gmUbo[winfg::FrameGen::kGmSlots]{}; + VkDeviceMemory gmUboMem[winfg::FrameGen::kGmSlots]{}; + void* gmUboPtr[winfg::FrameGen::kGmSlots]{}; + // persistent descriptor sets + VkDescriptorSet sLumaCurr = VK_NULL_HANDLE, sLumaPrev = VK_NULL_HANDLE; + std::vector sDownA, sDownB, sFlow; + VkDescriptorSet sExpand[winfg::FrameGen::kGmSlots]{}; // per-slot (binds gmUbo[slot]) + // C2: three flow-reg sets covering every (u_in → u_out) pairing of the + // ping-pong. sFlowReg0: in=flowLvl_[F] (=f0), out=A. sFlowRegAB: in=A, out=B. + // sFlowRegBA: in=B, out=A. f0 (binding 33) = flowLvl_[F] in all three. + VkDescriptorSet sFlowReg0 = VK_NULL_HANDLE, sFlowRegAB = VK_NULL_HANDLE, sFlowRegBA = VK_NULL_HANDLE; + VkDescriptorSet sSynth = VK_NULL_HANDLE; + // C1: per-slot reduce set + per-slot per-level prewarp sets + VkDescriptorSet sGmReduce[winfg::FrameGen::kGmSlots]{}; + std::vector sGmPrewarp[winfg::FrameGen::kGmSlots]; // sized kLevels; [flowFinest()..) used + VkExtent2D builtFor{0,0}; + bool built = false; + bool flowInited = false; // flow images laid out once, then persist (temporal predictor) +}; +ScratchState g_scratch; // one swapchain in flight in this first-draft engine +} + +static bool makeUbo(const winfg::DeviceDispatch* dd, VkDevice dev, + const VkPhysicalDeviceMemoryProperties& mp, + VkDeviceSize size, VkBuffer& buf, VkDeviceMemory& mem, void*& ptr) { + VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; + bi.size = size; bi.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + if (dd->CreateBuffer(dev, &bi, nullptr, &buf) != VK_SUCCESS) return false; + VkMemoryRequirements mr; dd->GetBufferMemoryRequirements(dev, buf, &mr); + uint32_t idx = 0; VkMemoryPropertyFlags want = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + for (uint32_t i = 0; i < mp.memoryTypeCount; ++i) + if ((mr.memoryTypeBits & (1u<AllocateMemory(dev, &ai, nullptr, &mem) != VK_SUCCESS) return false; + if (dd->BindBufferMemory(dev, buf, mem, 0) != VK_SUCCESS) return false; + return dd->MapMemory(dev, mem, 0, size, 0, &ptr) == VK_SUCCESS; +} + +static VkDescriptorSet allocSet(const winfg::DeviceDispatch* dd, VkDevice dev, + VkDescriptorPool pool, VkDescriptorSetLayout layout) { + VkDescriptorSetAllocateInfo ai{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; + ai.descriptorPool = pool; ai.descriptorSetCount = 1; ai.pSetLayouts = &layout; + VkDescriptorSet s = VK_NULL_HANDLE; dd->AllocateDescriptorSets(dev, &ai, &s); return s; +} + +// write helpers +static void wImg(const winfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet set, uint32_t binding, + VkDescriptorType type, VkImageView view, VkSampler samp, VkImageLayout layout) { + VkDescriptorImageInfo ii{}; ii.imageView = view; ii.sampler = samp; ii.imageLayout = layout; + VkWriteDescriptorSet w{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}; + w.dstSet = set; w.dstBinding = binding; w.descriptorCount = 1; w.descriptorType = type; w.pImageInfo = ⅈ + dd->UpdateDescriptorSets(dev, 1, &w, 0, nullptr); +} +static void wUbo(const winfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet set, uint32_t binding, + VkBuffer buf, VkDeviceSize range) { + VkDescriptorBufferInfo bi{}; bi.buffer = buf; bi.range = range; + VkWriteDescriptorSet w{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}; + w.dstSet = set; w.dstBinding = binding; w.descriptorCount = 1; + w.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; w.pBufferInfo = &bi; + dd->UpdateDescriptorSets(dev, 1, &w, 0, nullptr); +} +static void wSsbo(const winfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet set, uint32_t binding, + VkBuffer buf, VkDeviceSize range) { + VkDescriptorBufferInfo bi{}; bi.buffer = buf; bi.range = range; + VkWriteDescriptorSet w{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}; + w.dstSet = set; w.dstBinding = binding; w.descriptorCount = 1; + w.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; w.pBufferInfo = &bi; + dd->UpdateDescriptorSets(dev, 1, &w, 0, nullptr); +} + +// ── C1 CPU-side linear algebra (clean-room, textbook) ──────────────────────── +// 6x6 symmetric positive-definite solve via Cholesky. Returns false if not PD +// (a bad/ill-conditioned frame → caller bails to identity). Damped by the caller. +static bool cholSolve6(double A[6][6], const double b[6], double x[6]) { + double L[6][6] = {{0}}; + for (int i = 0; i < 6; ++i) { + for (int j = 0; j <= i; ++j) { + double s = A[i][j]; + for (int k = 0; k < j; ++k) s -= L[i][k] * L[j][k]; + if (i == j) { + if (s <= 1e-20) return false; // not positive-definite + L[i][j] = std::sqrt(s); + } else { + L[i][j] = s / L[j][j]; + } + } + } + double y[6]; + for (int i = 0; i < 6; ++i) { double s = b[i]; for (int k = 0; k < i; ++k) s -= L[i][k]*y[k]; y[i] = s / L[i][i]; } + for (int i = 5; i >= 0; --i) { double s = y[i]; for (int k = i+1; k < 6; ++k) s -= L[k][i]*x[k]; x[i] = s / L[i][i]; } + return true; +} +// affine <-> params. params p=(p1,p2,p3,p4,p5,p6); M = I + [[p1,p3,p5],[p2,p4,p6]]. +static void affFromParams(const double p[6], double M[3][3]) { + M[0][0]=1.0+p[0]; M[0][1]=p[2]; M[0][2]=p[4]; + M[1][0]=p[1]; M[1][1]=1.0+p[3]; M[1][2]=p[5]; + M[2][0]=0.0; M[2][1]=0.0; M[2][2]=1.0; +} +static void paramsFromAff(const double M[3][3], double p[6]) { + p[0]=M[0][0]-1.0; p[2]=M[0][1]; p[4]=M[0][2]; + p[1]=M[1][0]; p[3]=M[1][1]-1.0; p[5]=M[1][2]; +} +static bool invAff(const double M[3][3], double out[3][3]) { + double a=M[0][0], b=M[0][1], tx=M[0][2], c=M[1][0], d=M[1][1], ty=M[1][2]; + double det = a*d - b*c; + if (std::fabs(det) < 1e-12) return false; + double id = 1.0/det; + out[0][0]= d*id; out[0][1]= -b*id; out[0][2]= (b*ty - d*tx)*id; + out[1][0]= -c*id; out[1][1]= a*id; out[1][2]= (c*tx - a*ty)*id; + out[2][0]=0.0; out[2][1]=0.0; out[2][2]=1.0; + return true; +} +static void mulAff(const double A[3][3], const double B[3][3], double out[3][3]) { + for (int i = 0; i < 2; ++i) + for (int j = 0; j < 3; ++j) + out[i][j] = A[i][0]*B[0][j] + A[i][1]*B[1][j] + A[i][2]*B[2][j]; + out[2][0]=0.0; out[2][1]=0.0; out[2][2]=1.0; +} + +namespace winfg { + +// Lazily allocate per-size UBOs + descriptor sets and wire the fixed (internal- +// resource) bindings once. External views (prev/curr/out) are wired per frame. +static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, + const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool, + VkSampler samp, VkExtent2D ext, + std::vector& pyrA, std::vector& pyrB, + std::vector& pyrAs, + std::vector& flowLvl, FrameGen::Img& expA, FrameGen::Img& expB, + const FrameGen::Pipe& pLuma, const FrameGen::Pipe& pDown, + const FrameGen::Pipe& pFlow, const FrameGen::Pipe& pExpand, + const FrameGen::Pipe& pSynth, const FrameGen::Pipe& pGmReduce, + const FrameGen::Pipe& pGmPrewarp, const FrameGen::Pipe& pFlowReg, + FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo, + int kLevels, const Config& cfg); + +// Tear down the lazily-built scratch (all UBO buffers + every descriptor set) so a +// live perf_preset rebuild neither leaks them nor exhausts the descriptor pool. +// The CALLER must have made the device idle first — no in-flight command buffer may +// still reference these. Resetting the pool frees every set FrameGen allocated (all +// sets come from this pool); the mapped UBO memory is unmapped + freed explicitly. +static void destroyScratch(const DeviceDispatch* dd, VkDevice dev, VkDescriptorPool pool) { + auto freeUbo = [&](VkBuffer& b, VkDeviceMemory& m, void*& p) { + if (m) dd->UnmapMemory(dev, m); + if (b) dd->DestroyBuffer(dev, b, nullptr); + if (m) dd->FreeMemory(dev, m, nullptr); + b = VK_NULL_HANDLE; m = VK_NULL_HANDLE; p = nullptr; + }; + auto& S = g_scratch; + freeUbo(S.synthUbo, S.synthUboMem, S.synthUboPtr); + freeUbo(S.expandUbo, S.expandUboMem, S.expandUboPtr); + freeUbo(S.flowRegUbo, S.flowRegUboMem, S.flowRegUboPtr); + for (size_t i = 0; i < S.flowUbo.size(); ++i) freeUbo(S.flowUbo[i], S.flowUboMem[i], S.flowUboPtr[i]); + for (int s = 0; s < FrameGen::kGmSlots; ++s) freeUbo(S.gmUbo[s], S.gmUboMem[s], S.gmUboPtr[s]); + if (pool && dd->ResetDescriptorPool) dd->ResetDescriptorPool(dev, pool, 0); // reclaim all sets at once + S = ScratchState{}; // built=false -> next record() rebuilds via ensureScratch +} + +// ── perf_preset apply / live rebuild ───────────────────────────────────────── +// Sets the config, resolves the perf_preset -> finest-solved-level, and — when +// that level changed while resources are already live — safely rebuilds the +// affected per-size flow images (a resize) + scratch descriptor sets and resets +// the flow predictor. This makes a perf_preset change FULLY LIVE per-present (the +// conf.toml hot-reload path calls this), so no FG toggle / bg-fg cycle is needed. +void FrameGen::configure(const Config& c) { + cfg_ = c; cfg_.sanitize(); + // Map preset -> finest level, clamped so at least TWO solved levels always + // remain (coarse->fine needs a range). With kLevels=7 the presets (1/2/3) never + // hit the clamp; the guard is defensive for future level/preset tuning. + int want = flowFinestForPreset(cfg_.perfPreset); + const int maxFinest = kLevels - 2; // keep >= 2 solved levels + if (want > maxFinest) { + WFG_LOGE("perf-preset=%d wants kFlowFinest=%d but only %d pyramid levels exist " + "(need >=2 solved) — clamping to %d", cfg_.perfPreset, want, kLevels, maxFinest); + want = maxFinest; + } + if (want < 1) want = 1; // never solve full-res (level 0) + + const int prevFinest = flowFinest_; + flowFinest_ = want; + const bool live = (flowFinest_ != prevFinest) && ready_; + WFG_LOGI("perf-preset=%d -> kFlowFinest=%d (was %d) live-rebuild=%d ready=%d", + cfg_.perfPreset, flowFinest_, prevFinest, live ? 1 : 0, ready_ ? 1 : 0); + + if (!live) return; // unchanged, or not yet built (initial configure before onResize) + + // The per-size flow images (pyrAs_/flowReg*/flowLvl_ wiring) and the scratch + // descriptor sets were built for the OLD finest level. Rebuild them so record() + // never reads/writes mismatched-size images. + dd_->DeviceWaitIdle(device_); // no in-flight cmd buf may touch these + destroyScratch(dd_, device_, descPool_); // free old scratch (UBOs + all sets) + if (!onResize(extent_, VK_FORMAT_UNDEFINED, /*force=*/true)) + WFG_LOGE("perf-preset live rebuild: onResize FAILED at %ux%u — FG disabled until next resize", + extent_.width, extent_.height); + // Reset the persistent flow predictor so stale, differently-scaled state never + // feeds the new resolution (avoids a melt/garbage frame on switch). The per-frame + // flow field (flowLvl_) is already cleared every frame; the cross-frame state is + // the C1 global-motion estimate + its per-slot reduce partials (dispatched against + // the old pyramid) — drop both back to identity. + for (int i = 0; i < 6; ++i) gmRun_[i] = 0.0; + for (int s = 0; s < kGmSlots; ++s) { gmSlotValid_[s] = false; for (int i = 0; i < 6; ++i) gmLinAt_[s][i] = 0.0; } + gmHaveEst_ = false; gmEngaged_ = false; gmStableCount_ = 0; gmLastTransPx_ = 0.0f; + WFG_LOGI("perf-preset live rebuild DONE (kFlowFinest=%d, flow predictor reset)", flowFinest_); +} + +// ── C1: read back one reduce SSBO, run one inverse-compositional LK step ────── +// Updates the running/applied global affine. Returns whether GM engages this frame. +bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) { + ++gmFrames_; + if (!gmBuffersReady_ || cfg_.gmMode == 2 /*off*/) { + // off: keep identity applied; keep estimating cheaply is pointless when off. + gmEngaged_ = false; gmStableCount_ = 0; + // still refresh the linearization record so a live switch to auto starts clean + for (int i = 0; i < 6; ++i) gmRun_[i] = 0.0; + for (int i = 0; i < 6; ++i) gmLinAt_[gmSlot][i] = gmRun_[i]; + gmLastTransPx_ = 0.0f; + return false; + } + + bool good = false; + if (gmSlotValid_[gmSlot]) { + const float* pt = (const float*)gmSsboPtr_[gmSlot]; + double sums[32]; for (int k = 0; k < 32; ++k) sums[k] = 0.0; + for (int t = 0; t < kGmThreads; ++t) { + const float* row = pt + (size_t)t * kGmStride; + for (int k = 0; k < kGmStride; ++k) sums[k] += (double)row[k]; + } + double coverage = sums[27]; + // require a few percent of the level's pixels as inliers + double lvlpx = double((fullExtent.width >> kGmLevel) * (fullExtent.height >> kGmLevel)); + double minCov = 0.03 * (lvlpx > 0 ? lvlpx : 1.0); + if (coverage > minCov && coverage > 64.0) { + double H[6][6]; int idx = 0; + for (int r = 0; r < 6; ++r) for (int c = r; c < 6; ++c) { H[r][c] = H[c][r] = sums[idx]; ++idx; } + double b[6]; for (int i = 0; i < 6; ++i) b[i] = sums[21 + i]; + // Levenberg damping for conditioning (relative + tiny absolute). + for (int i = 0; i < 6; ++i) H[i][i] += 1e-3 * H[i][i] + 1e-9; + double dp[6]; + if (cholSolve6(H, b, dp)) { + // reject wild steps (something non-affine / a scene cut) + bool bounded = std::fabs(dp[0]) < 0.5 && std::fabs(dp[1]) < 0.5 && + std::fabs(dp[2]) < 0.5 && std::fabs(dp[3]) < 0.5 && + std::fabs(dp[4]) < 0.25 && std::fabs(dp[5]) < 0.25; + if (bounded) { + // IC update: M_new = M_lin ∘ W(dp)^-1 (compose onto the SLOT's + // linearization base, which is what this reduce linearized around). + double Mlin[3][3], Md[3][3], Mdi[3][3], Mnew[3][3]; + affFromParams(gmLinAt_[gmSlot], Mlin); + affFromParams(dp, Md); + if (invAff(Md, Mdi)) { + mulAff(Mlin, Mdi, Mnew); + double pnew[6]; paramsFromAff(Mnew, pnew); + // final sanity clamp on the composed estimate + bool sane = std::fabs(pnew[0]) < 0.6 && std::fabs(pnew[1]) < 0.6 && + std::fabs(pnew[2]) < 0.6 && std::fabs(pnew[3]) < 0.6 && + std::fabs(pnew[4]) < 0.5 && std::fabs(pnew[5]) < 0.5; + if (sane) { for (int i = 0; i < 6; ++i) gmRun_[i] = pnew[i]; good = true; gmHaveEst_ = true; } + } + } + } + } + } + + if (good) ++gmStableCount_; else gmStableCount_ = 0; + + // engage policy + switch (cfg_.gmMode) { + case 1: gmEngaged_ = gmHaveEst_; break; // on + case 2: gmEngaged_ = false; break; // off (unreachable; handled above) + default: gmEngaged_ = (gmStableCount_ >= 3); break; // auto: 3 consecutive good solves + } + + // record the linearization base for the reduce we are about to dispatch into + // this slot this frame (i.e. the current running estimate). + for (int i = 0; i < 6; ++i) gmLinAt_[gmSlot][i] = gmRun_[i]; + gmSlotValid_[gmSlot] = true; // this frame's reduce will (re)write it + + gmLastTransPx_ = (float)std::sqrt( + (gmRun_[4]*fullExtent.width) * (gmRun_[4]*fullExtent.width) + + (gmRun_[5]*fullExtent.height) * (gmRun_[5]*fullExtent.height)); + return gmEngaged_; +} + +void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView, + VkImageView outView, float alpha, uint32_t gmSlot) { + if (!valid()) return; + if (gmSlot >= (uint32_t)kGmSlots) gmSlot = 0; + const bool m4 = (cfg_.model == 4); + const Pipe& flowP = m4 ? pFlowM4_ : pFlow_; + const Pipe& expandP = m4 ? pExpandM4_ : pExpand_; + + if (!g_scratch.built || g_scratch.builtFor.width != extent_.width || g_scratch.builtFor.height != extent_.height) { + ensureScratch(this, dd_, device_, memProps_, descPool_, linear_, extent_, + pyrA_, pyrB_, pyrAs_, flowLvl_, flowExpA_, flowExpB_, + pLuma_, pDown_, flowP, expandP, pSynth_, pGmReduce_, pGmPrewarp_, + pFlowReg_, flowRegA_, flowRegB_, gmSsbo_, kLevels, cfg_); + } + + // ── C1: solve the global-motion affine (reads the SSBO the caller fence-waited) ── + bool gmEngaged = updateGlobalMotion(gmSlot, extent_); + // Build this slot's GMUBO from the running / applied affine. + if (g_scratch.gmUboPtr[gmSlot]) { + GMUBO g{}; + g.lin[0]=(float)gmRun_[0]; g.lin[1]=(float)gmRun_[1]; g.lin[2]=(float)gmRun_[2]; g.lin[3]=(float)gmRun_[3]; + g.linT[0]=(float)gmRun_[4]; g.linT[1]=(float)gmRun_[5]; g.linT[2]=gmEngaged?1.0f:0.0f; g.linT[3]=0.0f; + if (gmEngaged) { + g.app[0]=(float)gmRun_[0]; g.app[1]=(float)gmRun_[1]; g.app[2]=(float)gmRun_[2]; g.app[3]=(float)gmRun_[3]; + g.appT[0]=(float)gmRun_[4]; g.appT[1]=(float)gmRun_[5]; + } // else app/appT stay 0 -> identity -> prewarp/expand are pre-C1 no-ops + std::memcpy(g_scratch.gmUboPtr[gmSlot], &g, sizeof(g)); + } + // Log engage state + estimated global translation periodically (tag win-fg). + { + static int lastEng = -1; + if (gmEngaged != (lastEng == 1) || (gmFrames_ % 300ull) == 0) { + WFG_LOGI("C1 global-motion: engaged=%d mode=%d stable=%d transPx=%.1f (model=%d)", + gmEngaged ? 1 : 0, cfg_.gmMode, gmStableCount_, gmLastTransPx_, cfg_.model); + lastEng = gmEngaged ? 1 : 0; + } + } + + // update UBOs for this frame + SynthUBO su{cfg_.flowScale, alpha, cfg_.beta, cfg_.lambda, cfg_.epsilon, cfg_.photoScale, 0, 0, + cfg_.hudX0, cfg_.hudY0, cfg_.hudX1, cfg_.hudY1}; + if (g_scratch.synthUboPtr) std::memcpy(g_scratch.synthUboPtr, &su, sizeof(su)); + + // wire per-frame external views + wImg(dd_, device_, g_scratch.sLumaCurr, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + wImg(dd_, device_, g_scratch.sLumaPrev, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, prevView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + wImg(dd_, device_, g_scratch.sSynth, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, prevView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + wImg(dd_, device_, g_scratch.sSynth, 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + wImg(dd_, device_, g_scratch.sSynth, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, outView, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_GENERAL); + + auto disp = [&](const Pipe& p, VkDescriptorSet set, VkExtent2D e) { + dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, p.pipeline); + dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, p.layout, 0, 1, &set, 0, nullptr); + dd_->CmdDispatch(cmd, (e.width + 15) / 16, (e.height + 15) / 16, 1); + }; + auto bar = [&](FrameGen::Img& i){ barrier(cmd, i.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL); }; + + // Internal images are created UNDEFINED and fully recomputed every frame, so + // discard-transition them all to GENERAL up front (all descriptors use GENERAL + // for these). This also fixes the first-frame layout (storage writes require + // GENERAL, not UNDEFINED). + for (auto& i : pyrA_) barrier(cmd, i.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + for (auto& i : pyrB_) barrier(cmd, i.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + for (int l = flowFinest_; l < kLevels; ++l) barrier(cmd, pyrAs_[l].image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + barrier(cmd, flowExpA_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + barrier(cmd, flowExpB_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + // C2: ping-pong scratch to GENERAL (storage writes require it; contents discarded). + barrier(cmd, flowRegA_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + barrier(cmd, flowRegB_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL); + // Reset the flow field to zero every frame. The coarsest level uses it as its + // search predictor; carrying it across frames lets a spurious vector feed + // forward until it diverges and melts the image (the bg/fg pause was resetting + // it — that's why artifacts vanished on resume). Fresh zero every frame = + // stable, standard pyramid flow, no feedback loop. + { + VkClearColorValue zero{}; + VkImageSubresourceRange rng{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + for (int l = flowFinest_; l < kLevels; ++l) { + VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; + b.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + b.srcAccessMask = 0; b.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + b.image = flowLvl_[l].image; b.subresourceRange = rng; + b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); + dd_->CmdClearColorImage(cmd, flowLvl_[l].image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &zero, 1, &rng); + b.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; b.newLayout = VK_IMAGE_LAYOUT_GENERAL; + b.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; b.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b); + } + } + + // 1) luma of curr/prev at full res + disp(pLuma_, g_scratch.sLumaCurr, levelExtent(extent_, 0)); + disp(pLuma_, g_scratch.sLumaPrev, levelExtent(extent_, 0)); + bar(pyrA_[0]); bar(pyrB_[0]); + // 2) downsample pyramids + for (int l = 1; l < kLevels; ++l) { + disp(pDown_, g_scratch.sDownA[l - 1], levelExtent(extent_, l)); + disp(pDown_, g_scratch.sDownB[l - 1], levelExtent(extent_, l)); + bar(pyrA_[l]); bar(pyrB_[l]); + } + // 2b) C1: LK normal-equation reduce (fixed grid, 1/8-res) → this slot's SSBO. + // Reads raw prev/curr luma at kGmLevel; writes per-thread partials. A + // compute→host barrier makes the write visible to the CPU readback that + // happens when this slot comes round again (~1-2 frames later). + if (gmBuffersReady_ && g_scratch.sGmReduce[gmSlot]) { + dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.pipeline); + dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.layout, 0, 1, &g_scratch.sGmReduce[gmSlot], 0, nullptr); + dd_->CmdDispatch(cmd, (uint32_t)(kGmThreads / 64), 1, 1); + VkMemoryBarrier mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; + mb.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; mb.dstAccessMask = VK_ACCESS_HOST_READ_BIT; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, + 0, 1, &mb, 0, nullptr, 0, nullptr); + } + // 2c) C1: pre-warp curr luma pyramid by the applied affine → stabilized pyramid + // (identity affine ⇒ exact copy, so the flow below is unchanged when + // disengaged). The dense flow reads pyrAs from here on. + for (int l = flowFinest_; l < kLevels; ++l) { + disp(pGmPrewarp_, g_scratch.sGmPrewarp[gmSlot][l], levelExtent(extent_, l)); + bar(pyrAs_[l]); + } + // 3) coarse->fine flow (only down to flowFinest_ — reduced res for perf; the + // finest level is perf_preset-selectable). Curr input is now the STABILIZED + // pyramid (pyrAs), wired in ensureScratch. + for (int l = kLevels - 1; l >= flowFinest_; --l) { + disp(flowP, g_scratch.sFlow[l], levelExtent(extent_, l)); + bar(flowLvl_[l]); + } + + // 3b) ── C2: TV-L1 flow regularization on the finest residual field ────────── + // Run frIters semi-implicit TV-L1 denoising iterations on flowLvl_[flowFinest_] + // (the object-only residual left by C1). flowLvl_[F] is the fixed data term f0 + // (read, never written here); u ping-pongs A<->B; the final iterate is copied + // back into flowLvl_[F] so of3_expand consumes the cleaned field unchanged. + // Disengaged (frMode==off or frIters==0) ⇒ flowLvl_[F] untouched ⇒ byte-identical + // to pre-C2. Identity/zero iterations is therefore never worse than "no reg". + const bool frEngaged = (cfg_.frMode != 2) && (cfg_.frIters > 0); + if (frEngaged) { + const int F = flowFinest_; + const VkExtent2D fe = levelExtent(extent_, F); + if (g_scratch.flowRegUboPtr) { + FlowRegUBO fu{cfg_.frDt, cfg_.frLambda, cfg_.frEdge, cfg_.frEps}; + std::memcpy(g_scratch.flowRegUboPtr, &fu, sizeof(fu)); + } + FrameGen::Img* last = nullptr; + for (int it = 0; it < cfg_.frIters; ++it) { + VkDescriptorSet set; FrameGen::Img* outImg; + if (it == 0) { set = g_scratch.sFlowReg0; outImg = &flowRegA_; } + else if (it % 2 == 1) { set = g_scratch.sFlowRegAB; outImg = &flowRegB_; } + else { set = g_scratch.sFlowRegBA; outImg = &flowRegA_; } + dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.pipeline); + dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.layout, 0, 1, &set, 0, nullptr); + dd_->CmdDispatch(cmd, (fe.width + 15) / 16, (fe.height + 15) / 16, 1); + bar(*outImg); + last = outImg; + } + // Copy the cleaned finest flow back into flowLvl_[F] (GENERAL->GENERAL). + // Barrier: C2's f0 reads (SHADER_READ of flowLvl_[F]) and the last iterate + // write must complete before the transfer overwrites/reads. + VkMemoryBarrier mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; + mb.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + mb.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 1, &mb, 0, nullptr, 0, nullptr); + VkImageCopy region{}; + region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; + region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; + region.extent = {fe.width, fe.height, 1}; + dd_->CmdCopyImage(cmd, last->image, VK_IMAGE_LAYOUT_GENERAL, + flowLvl_[F].image, VK_IMAGE_LAYOUT_GENERAL, 1, ®ion); + VkMemoryBarrier mb2{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; + mb2.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + mb2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + 0, 1, &mb2, 0, nullptr, 0, nullptr); + } + { // periodic C2 status (tag win-fg), mirrors the C1 log cadence + static int lastFr = -1; + int fe = frEngaged ? 1 : 0; + if (fe != lastFr || (gmFrames_ % 300ull) == 0) { + WFG_LOGI("C2 flow-reg: engaged=%d mode=%d iters=%d lambda=%.2f dt=%.2f edge=%.1f eps=%.3f (model=%d)", + fe, cfg_.frMode, cfg_.frIters, cfg_.frLambda, cfg_.frDt, cfg_.frEdge, cfg_.frEps, cfg_.model); + lastFr = fe; + } + } + + // 4) expand finest solved flow -> fwd/bwd (+conf), + C1 global-motion add-back. + disp(expandP, g_scratch.sExpand[gmSlot], levelExtent(extent_, 0)); + bar(flowExpA_); bar(flowExpB_); + // 5) synthesise interpolated frame + disp(pSynth_, g_scratch.sSynth, levelExtent(extent_, 0)); +} + +// ---- lazy scratch builder ---- +static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev, + const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool, + VkSampler samp, VkExtent2D ext, + std::vector& pyrA, std::vector& pyrB, + std::vector& pyrAs, + std::vector& flowLvl, FrameGen::Img& expA, FrameGen::Img& expB, + const FrameGen::Pipe& pLuma, const FrameGen::Pipe& pDown, + const FrameGen::Pipe& pFlow, const FrameGen::Pipe& pExpand, + const FrameGen::Pipe& pSynth, const FrameGen::Pipe& pGmReduce, + const FrameGen::Pipe& pGmPrewarp, const FrameGen::Pipe& pFlowReg, + FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo, + int kLevels, const Config& cfg) { + auto& S = g_scratch; + S = ScratchState{}; + const auto GEN = VK_IMAGE_LAYOUT_GENERAL; + + makeUbo(dd, dev, mp, sizeof(SynthUBO), S.synthUbo, S.synthUboMem, S.synthUboPtr); + makeUbo(dd, dev, mp, sizeof(FlowUBO), S.expandUbo, S.expandUboMem, S.expandUboPtr); + if (S.expandUboPtr) { FlowUBO u{cfg.flowScale, 0, 0.6f, 1.6f}; std::memcpy(S.expandUboPtr, &u, sizeof(u)); } + // C2: flow-reg UBO (params refreshed each frame in record() for hot-reload). + makeUbo(dd, dev, mp, sizeof(FlowRegUBO), S.flowRegUbo, S.flowRegUboMem, S.flowRegUboPtr); + if (S.flowRegUboPtr) { FlowRegUBO fu{cfg.frDt, cfg.frLambda, cfg.frEdge, cfg.frEps}; std::memcpy(S.flowRegUboPtr, &fu, sizeof(fu)); } + S.flowUbo.resize(kLevels); S.flowUboMem.resize(kLevels); S.flowUboPtr.resize(kLevels); + for (int l = 0; l < kLevels; ++l) { + makeUbo(dd, dev, mp, sizeof(FlowUBO), S.flowUbo[l], S.flowUboMem[l], S.flowUboPtr[l]); + if (S.flowUboPtr[l]) { FlowUBO u{cfg.flowScale, (uint32_t)l, 0.6f, 1.6f}; std::memcpy(S.flowUboPtr[l], &u, sizeof(u)); } + } + // C1: per-slot GMUBO (initialised to identity) + for (int s = 0; s < FrameGen::kGmSlots; ++s) { + makeUbo(dd, dev, mp, sizeof(GMUBO), S.gmUbo[s], S.gmUboMem[s], S.gmUboPtr[s]); + if (S.gmUboPtr[s]) { GMUBO g{}; std::memcpy(S.gmUboPtr[s], &g, sizeof(g)); } + } + + // luma sets (external src wired per frame; dst is pyramid[0]) + S.sLumaCurr = allocSet(dd, dev, pool, pLuma.setLayout); + S.sLumaPrev = allocSet(dd, dev, pool, pLuma.setLayout); + wImg(dd, dev, S.sLumaCurr, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrA[0].view, VK_NULL_HANDLE, GEN); + wImg(dd, dev, S.sLumaPrev, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrB[0].view, VK_NULL_HANDLE, GEN); + + // downsample sets (fixed) + S.sDownA.resize(kLevels - 1); S.sDownB.resize(kLevels - 1); + for (int l = 1; l < kLevels; ++l) { + S.sDownA[l-1] = allocSet(dd, dev, pool, pDown.setLayout); + S.sDownB[l-1] = allocSet(dd, dev, pool, pDown.setLayout); + wImg(dd, dev, S.sDownA[l-1], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrA[l-1].view, samp, GEN); + wImg(dd, dev, S.sDownA[l-1], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrA[l].view, VK_NULL_HANDLE, GEN); + wImg(dd, dev, S.sDownB[l-1], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[l-1].view, samp, GEN); + wImg(dd, dev, S.sDownB[l-1], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrB[l].view, VK_NULL_HANDLE, GEN); + } + + // flow sets (fixed): predictor = coarser flow level, or self at coarsest. + // C1: the CURR input (binding 33) is the STABILIZED pyramid pyrAs for the + // solved flow levels; prev stays raw. Below kFlowFinest the level is never + // dispatched, so leaving those at raw curr is harmless. + S.sFlow.resize(kLevels); + for (int l = 0; l < kLevels; ++l) { + S.sFlow[l] = allocSet(dd, dev, pool, pFlow.setLayout); + int pred = (l + 1 < kLevels) ? l + 1 : l; + VkImageView currLvl = (l >= fg->flowFinest()) ? pyrAs[l].view : pyrA[l].view; + wUbo(dd, dev, S.sFlow[l], 0, S.flowUbo[l], sizeof(FlowUBO)); + wImg(dd, dev, S.sFlow[l], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[l].view, samp, GEN); + wImg(dd, dev, S.sFlow[l], 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currLvl, samp, GEN); + wImg(dd, dev, S.sFlow[l], 34, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[pred].view, samp, GEN); + wImg(dd, dev, S.sFlow[l], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowLvl[l].view, VK_NULL_HANDLE, GEN); + } + + // C1: reduce sets (one per slot) — prev/curr raw luma at kGmLevel + SSBO + GMUBO. + if (gmSsbo) { + for (int s = 0; s < FrameGen::kGmSlots; ++s) { + if (!gmSsbo[s]) continue; + S.sGmReduce[s] = allocSet(dd, dev, pool, pGmReduce.setLayout); + wUbo (dd, dev, S.sGmReduce[s], 1, S.gmUbo[s], sizeof(GMUBO)); + wSsbo(dd, dev, S.sGmReduce[s], 16, gmSsbo[s], VK_WHOLE_SIZE); + wImg (dd, dev, S.sGmReduce[s], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[FrameGen::kGmLevel].view, samp, GEN); // prev = template + wImg (dd, dev, S.sGmReduce[s], 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrA[FrameGen::kGmLevel].view, samp, GEN); // curr = image + } + } + + // C1: prewarp sets (one per slot, per solved flow level) — raw curr in, stabilized out. + for (int s = 0; s < FrameGen::kGmSlots; ++s) { + S.sGmPrewarp[s].assign(kLevels, VK_NULL_HANDLE); + for (int l = fg->flowFinest(); l < kLevels; ++l) { + S.sGmPrewarp[s][l] = allocSet(dd, dev, pool, pGmPrewarp.setLayout); + wUbo(dd, dev, S.sGmPrewarp[s][l], 1, S.gmUbo[s], sizeof(GMUBO)); + wImg(dd, dev, S.sGmPrewarp[s][l], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrA[l].view, samp, GEN); + wImg(dd, dev, S.sGmPrewarp[s][l], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrAs[l].view, VK_NULL_HANDLE, GEN); + } + } + + // expand sets (one per slot): flow inputs fixed; binding 1 = that slot's GMUBO. + for (int s = 0; s < FrameGen::kGmSlots; ++s) { + S.sExpand[s] = allocSet(dd, dev, pool, pExpand.setLayout); + wUbo(dd, dev, S.sExpand[s], 0, S.expandUbo, sizeof(FlowUBO)); + wUbo(dd, dev, S.sExpand[s], 1, S.gmUbo[s], sizeof(GMUBO)); + wImg(dd, dev, S.sExpand[s], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[fg->flowFinest()].view, samp, GEN); + wImg(dd, dev, S.sExpand[s], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, expA.view, VK_NULL_HANDLE, GEN); + wImg(dd, dev, S.sExpand[s], 49, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, expB.view, VK_NULL_HANDLE, GEN); + } + + // C2: flow-reg sets. F = kFlowFinest. f0 (binding 33) = flowLvl_[F] in all; luma + // (binding 34) = prev luma at F (pyrB) for the edge-aware weight. u_in (32) and + // u_out (48) alternate to realize the ping-pong (see ScratchState comment). + { + const int F = fg->flowFinest(); + S.sFlowReg0 = allocSet(dd, dev, pool, pFlowReg.setLayout); + S.sFlowRegAB = allocSet(dd, dev, pool, pFlowReg.setLayout); + S.sFlowRegBA = allocSet(dd, dev, pool, pFlowReg.setLayout); + VkDescriptorSet all3[3] = {S.sFlowReg0, S.sFlowRegAB, S.sFlowRegBA}; + for (VkDescriptorSet s : all3) { + wUbo(dd, dev, s, 0, S.flowRegUbo, sizeof(FlowRegUBO)); + wImg(dd, dev, s, 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[F].view, samp, GEN); // f0 + wImg(dd, dev, s, 34, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[F].view, samp, GEN); // luma + } + // iter0: in=flowLvl_[F] (=f0), out=A + wImg(dd, dev, S.sFlowReg0, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[F].view, samp, GEN); + wImg(dd, dev, S.sFlowReg0, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowRegA.view, VK_NULL_HANDLE, GEN); + // odd iters: in=A, out=B + wImg(dd, dev, S.sFlowRegAB, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowRegA.view, samp, GEN); + wImg(dd, dev, S.sFlowRegAB, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowRegB.view, VK_NULL_HANDLE, GEN); + // even iters (>0): in=B, out=A + wImg(dd, dev, S.sFlowRegBA, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowRegB.view, samp, GEN); + wImg(dd, dev, S.sFlowRegBA, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowRegA.view, VK_NULL_HANDLE, GEN); + } + + // synth set: external prev/curr/out wired per frame; flow inputs fixed + S.sSynth = allocSet(dd, dev, pool, pSynth.setLayout); + wUbo(dd, dev, S.sSynth, 0, S.synthUbo, sizeof(SynthUBO)); + // GENERAL (not SR): these internal flow images stay in GENERAL across the whole + // record() (written as storage by expand, sampled here) — see the discard + // transition at the top of record(). + wImg(dd, dev, S.sSynth, 34, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, expA.view, samp, GEN); + wImg(dd, dev, S.sSynth, 35, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, expB.view, samp, GEN); + + S.builtFor = ext; S.built = true; + return true; +} + +} // namespace winfg diff --git a/app/src/main/cpp/winlator/winfg/vk_dispatch.hpp b/app/src/main/cpp/winlator/winfg/vk_dispatch.hpp new file mode 100644 index 0000000000..6b16e59f47 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/vk_dispatch.hpp @@ -0,0 +1,123 @@ +// win-fg — minimal Vulkan layer dispatch tables. +// Structure follows the public Khronos loader/layer interface and the +// renderdoc "Vulkan layer guide" skeleton (learning references, Apache-2.0 / +// CC-BY). No code from bionic-fg / lsfg / GameScope. +#pragma once +#include +#include +#include + +namespace winfg { + +// The loader sets the first pointer-sized word of a dispatchable handle to the +// dispatch table pointer; layers key their own maps on that value so that all +// handles sharing a chain resolve to the same table. +static inline void* dispatch_key(void* handle) { return *reinterpret_cast(handle); } + +// Instance-level functions we call from the layer. +struct InstanceDispatch { + PFN_vkGetInstanceProcAddr GetInstanceProcAddr = nullptr; + PFN_vkDestroyInstance DestroyInstance = nullptr; + PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties = nullptr; + PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties = nullptr; + // Device-context logging (affected-device fingerprint). Properties2 is core 1.1; + // may be null on a 1.0 instance — always null-check before calling. + PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties = nullptr; + PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2 = nullptr; + // Surface caps — used to clamp the extra-image-headroom request to the surface's + // maxImageCount so the bump never exceeds what the driver can grant. + PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR = nullptr; +}; + +// Device-level functions we call. Populated by walking vkGetDeviceProcAddr on +// the next layer down at device-create time. +struct DeviceDispatch { + PFN_vkGetDeviceProcAddr GetDeviceProcAddr = nullptr; + PFN_vkDestroyDevice DestroyDevice = nullptr; + PFN_vkGetDeviceQueue GetDeviceQueue = nullptr; + PFN_vkQueueSubmit QueueSubmit = nullptr; + // Synchronization2 submit path (core 1.3 + KHR alias). DXVK may use either the + // legacy QueueSubmit or QueueSubmit2/2KHR; both are hooked for the guest-submit + // diagnostic. May be null if the device did not enable them — always null-check. + PFN_vkQueueSubmit2 QueueSubmit2 = nullptr; + PFN_vkQueueSubmit2KHR QueueSubmit2KHR = nullptr; + PFN_vkQueueWaitIdle QueueWaitIdle = nullptr; + PFN_vkDeviceWaitIdle DeviceWaitIdle = nullptr; + + // swapchain / present + PFN_vkCreateSwapchainKHR CreateSwapchainKHR = nullptr; + PFN_vkDestroySwapchainKHR DestroySwapchainKHR = nullptr; + PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR = nullptr; + PFN_vkAcquireNextImageKHR AcquireNextImageKHR = nullptr; + // Alternate acquire entry (VK_KHR_swapchain 1.1+ / device-group). DXVK may use + // either AcquireNextImageKHR or AcquireNextImage2KHR — both hooked for the + // guest-acquire diagnostic. May be null — always null-check. + PFN_vkAcquireNextImage2KHR AcquireNextImage2KHR = nullptr; + PFN_vkQueuePresentKHR QueuePresentKHR = nullptr; + + // resources + PFN_vkCreateImage CreateImage = nullptr; + PFN_vkDestroyImage DestroyImage = nullptr; + PFN_vkCreateImageView CreateImageView = nullptr; + PFN_vkDestroyImageView DestroyImageView = nullptr; + PFN_vkAllocateMemory AllocateMemory = nullptr; + PFN_vkFreeMemory FreeMemory = nullptr; + PFN_vkBindImageMemory BindImageMemory = nullptr; + PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements = nullptr; + PFN_vkCreateBuffer CreateBuffer = nullptr; + PFN_vkDestroyBuffer DestroyBuffer = nullptr; + PFN_vkGetBufferMemoryRequirements GetBufferMemoryRequirements = nullptr; + PFN_vkBindBufferMemory BindBufferMemory = nullptr; + PFN_vkMapMemory MapMemory = nullptr; + PFN_vkUnmapMemory UnmapMemory = nullptr; + PFN_vkCreateSampler CreateSampler = nullptr; + PFN_vkDestroySampler DestroySampler = nullptr; + + // pipeline / descriptors + PFN_vkCreateShaderModule CreateShaderModule = nullptr; + PFN_vkDestroyShaderModule DestroyShaderModule = nullptr; + PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout = nullptr; + PFN_vkDestroyDescriptorSetLayout DestroyDescriptorSetLayout = nullptr; + PFN_vkCreatePipelineLayout CreatePipelineLayout = nullptr; + PFN_vkDestroyPipelineLayout DestroyPipelineLayout = nullptr; + PFN_vkCreateComputePipelines CreateComputePipelines = nullptr; + PFN_vkDestroyPipeline DestroyPipeline = nullptr; + PFN_vkCreateDescriptorPool CreateDescriptorPool = nullptr; + PFN_vkDestroyDescriptorPool DestroyDescriptorPool = nullptr; + // Frees every set in the pool at once — used by FrameGen::configure() to reclaim + // the old scratch descriptor sets when a perf_preset change forces a live rebuild + // (otherwise repeated preset switches would exhaust the pool). May be null in + // theory; the rebuild path null-checks before calling. + PFN_vkResetDescriptorPool ResetDescriptorPool = nullptr; + PFN_vkAllocateDescriptorSets AllocateDescriptorSets = nullptr; + PFN_vkUpdateDescriptorSets UpdateDescriptorSets = nullptr; + + // command recording + PFN_vkCreateCommandPool CreateCommandPool = nullptr; + PFN_vkDestroyCommandPool DestroyCommandPool = nullptr; + PFN_vkAllocateCommandBuffers AllocateCommandBuffers = nullptr; + PFN_vkFreeCommandBuffers FreeCommandBuffers = nullptr; + PFN_vkBeginCommandBuffer BeginCommandBuffer = nullptr; + PFN_vkEndCommandBuffer EndCommandBuffer = nullptr; + PFN_vkCmdBindPipeline CmdBindPipeline = nullptr; + PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets = nullptr; + PFN_vkCmdDispatch CmdDispatch = nullptr; + PFN_vkCmdPipelineBarrier CmdPipelineBarrier = nullptr; + PFN_vkCmdCopyImage CmdCopyImage = nullptr; + PFN_vkCmdCopyImageToBuffer CmdCopyImageToBuffer = nullptr; // capture readback + PFN_vkCmdBlitImage CmdBlitImage = nullptr; + PFN_vkCmdClearColorImage CmdClearColorImage = nullptr; + PFN_vkCreateFence CreateFence = nullptr; + PFN_vkDestroyFence DestroyFence = nullptr; + PFN_vkWaitForFences WaitForFences = nullptr; + PFN_vkResetFences ResetFences = nullptr; + PFN_vkCreateSemaphore CreateSemaphore = nullptr; + PFN_vkDestroySemaphore DestroySemaphore = nullptr; +}; + +template +static inline void load(PFN& slot, PFN_vkGetDeviceProcAddr gdpa, VkDevice dev, const char* name) { + slot = reinterpret_cast(gdpa(dev, name)); +} + +} // namespace winfg diff --git a/app/src/main/cpp/winlator/winfg/winfg_engine.cpp b/app/src/main/cpp/winlator/winfg/winfg_engine.cpp new file mode 100644 index 0000000000..c2737e2610 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/winfg_engine.cpp @@ -0,0 +1,204 @@ +// See winfg_engine.h. +#include "winfg_engine.h" +#include "winfg_vkd.h" +#include "log.hpp" +#include +#include + +namespace winfg { +namespace { + +// 2x: the guest layer synthesises at 0.35, not 0.5 - biased towards prev to +// cut the double-exposure ghost on HUD/text ("iterative bring-up knob" in +// layer.cpp). Kept for parity, since that is the tuning that was proven. +// 3x/4x: evenly spaced; never exercised by the guest layer, so this is the +// new ground native opens up and the first thing to judge by eye. +float alphaFor(uint32_t k, uint32_t n) { + if (n <= 1) return 0.35f; + return (float)(k + 1) / (float)(n + 1); +} + +VkImageMemoryBarrier bar(VkImage img, VkImageLayout from, VkImageLayout to, + VkAccessFlags src, VkAccessFlags dst) { + VkImageMemoryBarrier b{}; + b.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + b.oldLayout = from; b.newLayout = to; + b.srcAccessMask = src; b.dstAccessMask = dst; + b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + b.image = img; + b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + return b; +} + +} // namespace + +Engine::Engine() = default; +Engine::~Engine() { destroyRing(); fg_.destroy(); } + +bool Engine::init(const VkTable& table, VkPhysicalDevice phys, VkDevice dev, + uint32_t queueFamily, VkQueue queue) { + if (!winfgVkdInit(table, dd_, id_)) { + WFG_LOGE("native: dispatch incomplete; frame generation unavailable"); + return false; + } + phys_ = phys; dev_ = dev; qf_ = queueFamily; queue_ = queue; + id_.GetPhysicalDeviceMemoryProperties(phys_, &memProps_); + if (!fg_.init(&dd_, &id_, phys_, dev_, qf_, queue_)) { + WFG_LOGE("native: FrameGen::init failed"); + unavailable_ = true; + return false; + } + WFG_LOGI("native: chain ready (10 pipelines, embedded shaders)"); + return true; +} + +void Engine::configure(uint32_t multiplier, int model, int perfPreset, float flowScale) { + cfg_.enabled = true; + cfg_.multiplier = (int)std::max(2, multiplier); + cfg_.model = (model == 3) ? 3 : 4; + cfg_.perfPreset = std::clamp(perfPreset, 0, 2); + cfg_.flowScale = std::clamp(flowScale, 0.25f, 1.0f); + fg_.configure(cfg_); +} + +bool Engine::prepare(uint32_t w, uint32_t h, VkFormat fmt) { + if (unavailable_ || w == 0 || h == 0 || fmt == VK_FORMAT_UNDEFINED) return false; + if (builtW_ == w && builtH_ == h && builtFmt_ == fmt && fg_.valid()) return true; + + // onResize rebuilds the pyramids/scratch; our own input ring follows it. + if (!fg_.onResize(VkExtent2D{w, h}, fmt, /*force=*/false)) { + WFG_LOGE("native: onResize %ux%u failed; frame generation unavailable", w, h); + unavailable_ = true; + return false; + } + destroyRing(); + for (Slot& s : ring_) { + if (!makeSlot(s, w, h, fmt)) { destroyRing(); unavailable_ = true; return false; } + } + builtW_ = w; builtH_ = h; builtFmt_ = fmt; + history_ = 0; curr_ = 0; frames_ = 0; + WFG_LOGI("native: built %ux%u fmt=%d model=%d preset=%d flow=%.2f", + w, h, (int)fmt, cfg_.model, cfg_.perfPreset, (double)cfg_.flowScale); + return true; +} + +uint32_t Engine::plan(uint32_t capacity) const { + if (!valid() || history_ < 2) return 0; // need prev AND curr + const uint32_t want = (uint32_t)std::max(cfg_.multiplier - 1, 0); + return std::min({want, capacity, kMaxGenerations}); +} + +void Engine::process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, + uint32_t /*generations*/) { + if (!valid()) return; + // Rotate: the slot we are about to overwrite is the OLD prev; after the + // copy it is the new curr and the other slot is prev. + curr_ = 1 - curr_; + Slot& dst = ring_[curr_]; + + // source is GENERAL (composite render pass leaves it there); the slot may + // be in any layout from last use - UNDEFINED is legal as "discard". + VkImageMemoryBarrier pre[2] = { + bar(source, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT), + bar(dst.img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 0, VK_ACCESS_TRANSFER_WRITE_BIT), + }; + dd_.CmdPipelineBarrier(cmd, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 2, pre); + + VkImageCopy region{}; + region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; + region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; + region.extent = {w, h, 1}; + dd_.CmdCopyImage(cmd, source, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + dst.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + + // source back to GENERAL for the real-frame copy that follows; the new + // curr becomes SHADER_READ_ONLY, which is what the chain samples it as. + VkImageMemoryBarrier post[2] = { + bar(source, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, + VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT), + bar(dst.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT), + }; + dd_.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, nullptr, 0, nullptr, 2, post); + dst.valid = true; + if (history_ < 2) history_++; + frames_++; +} + +void Engine::generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t count, + VkImage targetImage, VkImageView targetView, uint32_t w, uint32_t h) { + if (!valid() || history_ < 2) return; + const Slot& prev = ring_[1 - curr_]; + const Slot& curr = ring_[curr_]; + if (!prev.valid || !curr.valid) return; + + // The chain writes the output through a STORAGE descriptor in GENERAL. + // The composite ring already keeps its targets in GENERAL; make the + // prior contents' writes visible and take ownership for the compute write. + VkImageMemoryBarrier toWrite = bar(targetImage, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, + VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_SHADER_WRITE_BIT); + dd_.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &toWrite); + + // gmSlot indexes the C1 global-motion SSBO read back on the CPU next + // frame; kGmSlots (3) >= our frames in flight (2), so rotating per source + // frame keeps a slot from being read while its reduce is still in flight. + fg_.record(cmd, prev.view, curr.view, targetView, alphaFor(generation, count), gmSlot_); + if (generation + 1 == count) gmSlot_ = (gmSlot_ + 1) % (uint32_t)FrameGen::kGmSlots; + + (void)w; (void)h; +} + +void Engine::reset() { history_ = 0; frames_ = 0; } + +// ---- input ring -------------------------------------------------------------- + +uint32_t Engine::memType(uint32_t bits, VkMemoryPropertyFlags props) const { + for (uint32_t i = 0; i < memProps_.memoryTypeCount; i++) + if ((bits & (1u << i)) && (memProps_.memoryTypes[i].propertyFlags & props) == props) return i; + return 0; +} + +bool Engine::makeSlot(Slot& s, uint32_t w, uint32_t h, VkFormat fmt) { + VkImageCreateInfo ii{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; + ii.imageType = VK_IMAGE_TYPE_2D; ii.extent = {w, h, 1}; + ii.mipLevels = 1; ii.arrayLayers = 1; ii.format = fmt; + ii.tiling = VK_IMAGE_TILING_OPTIMAL; ii.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + ii.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + ii.samples = VK_SAMPLE_COUNT_1_BIT; ii.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + if (dd_.CreateImage(dev_, &ii, nullptr, &s.img) != VK_SUCCESS) return false; + VkMemoryRequirements req; dd_.GetImageMemoryRequirements(dev_, s.img, &req); + VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; + ai.allocationSize = req.size; + ai.memoryTypeIndex = memType(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (dd_.AllocateMemory(dev_, &ai, nullptr, &s.mem) != VK_SUCCESS) { destroySlot(s); return false; } + dd_.BindImageMemory(dev_, s.img, s.mem, 0); + VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; + vi.image = s.img; vi.viewType = VK_IMAGE_VIEW_TYPE_2D; vi.format = fmt; + vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + if (dd_.CreateImageView(dev_, &vi, nullptr, &s.view) != VK_SUCCESS) { destroySlot(s); return false; } + s.valid = false; + return true; +} + +void Engine::destroySlot(Slot& s) { + if (s.view) dd_.DestroyImageView(dev_, s.view, nullptr); + if (s.img) dd_.DestroyImage(dev_, s.img, nullptr); + if (s.mem) dd_.FreeMemory(dev_, s.mem, nullptr); + s = Slot{}; +} + +void Engine::destroyRing() { + if (dev_ == VK_NULL_HANDLE || !dd_.DeviceWaitIdle) return; + if (ring_[0].img || ring_[1].img) dd_.DeviceWaitIdle(dev_); + destroySlot(ring_[0]); destroySlot(ring_[1]); + history_ = 0; +} + +} // namespace winfg diff --git a/app/src/main/cpp/winlator/winfg/winfg_engine.h b/app/src/main/cpp/winlator/winfg/winfg_engine.h new file mode 100644 index 0000000000..087e01f98c --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/winfg_engine.h @@ -0,0 +1,102 @@ +#pragma once +// ============================================================================ +// winfg_engine — win-fg (Bannerlator's own frame generation) running inside +// the compositor, behind the same contract the LSFG engine uses: +// +// prepare(w, h, format) build/rebuild the chain for this size +// plan(capacity) how many frames to generate this time +// process(cmd, source, w, h, gens) take frame N in (becomes "curr") +// generateInto(cmd, k, n, ...) synthesise generated frame k of n +// +// Why this exists: as a guest-side Vulkan layer, win-fg's generated frames +// had to cross Wine -> DRI3 -> our X server -> the compositor, where the +// per-window latest-wins overwrite dropped them before they were ever +// presented - the HUD counted 2x, the panel got 1x. Here the chain runs in the +// compositor's own command stream and its frames are presented directly, on +// the same multi-present path that is device-proven for LSFG Native. +// +// Unlike LSFG this needs nothing from the user: the ten shaders are ours +// (MIT, see LICENSE.win-fg / NOTICE_FIDELITYFX_OPTICALFLOW.md) and embedded. +// +// The chain (framegen.cpp) is used unmodified. Its inputs are two sampled +// rgba8 views (prev, curr) and its output a GENERAL storage view; the guest +// layer transitions curr to SHADER_READ_ONLY before record() and the output +// UNDEFINED -> GENERAL, so we do exactly the same around the same call. +// ============================================================================ +#include +#include +#include "framegen.hpp" +#include "vk_dispatch.hpp" + +struct VkTable; + +namespace winfg { + +// Hard ceiling on generated frames per source frame (2x..4x -> 1..3), matching +// the LSFG engine and the drawer's buttons. +constexpr uint32_t kMaxGenerations = 3; + +class Engine { +public: + Engine(); + ~Engine(); + Engine(const Engine&) = delete; + Engine& operator=(const Engine&) = delete; + + bool init(const VkTable& table, VkPhysicalDevice phys, VkDevice dev, + uint32_t queueFamily, VkQueue queue); + bool valid() const { return fg_.valid() && !unavailable_; } + bool unavailable() const { return unavailable_; } + + // model 3/4, perf preset 0..2, flow scale - the same knobs the drawer + // already exposes for win-fg; they map straight onto winfg::Config. + void configure(uint32_t multiplier, int model, int perfPreset, float flowScale); + + bool prepare(uint32_t width, uint32_t height, VkFormat format); + + // 0 until there is a previous frame to interpolate from. + uint32_t plan(uint32_t capacity) const; + + // Copy the composited frame into the input ring as "curr" (the previous + // one becomes "prev"). `source` must be in GENERAL. + void process(VkCommandBuffer cmd, VkImage source, uint32_t width, uint32_t height, + uint32_t generations); + + // Synthesise generated frame `generation` of `count` into the storage view. + // The target must be in GENERAL (the composite ring keeps it there). + void generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t count, + VkImage targetImage, VkImageView targetView, + uint32_t width, uint32_t height); + + void reset(); + +private: + struct Slot { VkImage img = VK_NULL_HANDLE; VkDeviceMemory mem = VK_NULL_HANDLE; + VkImageView view = VK_NULL_HANDLE; bool valid = false; }; + bool makeSlot(Slot& s, uint32_t w, uint32_t h, VkFormat fmt); + void destroySlot(Slot& s); + void destroyRing(); + uint32_t memType(uint32_t bits, VkMemoryPropertyFlags props) const; + + DeviceDispatch dd_{}; + InstanceDispatch id_{}; + VkPhysicalDevice phys_ = VK_NULL_HANDLE; + VkDevice dev_ = VK_NULL_HANDLE; + uint32_t qf_ = 0; + VkQueue queue_ = VK_NULL_HANDLE; + VkPhysicalDeviceMemoryProperties memProps_{}; + + FrameGen fg_; + Config cfg_; + bool unavailable_ = false; + + Slot ring_[2]; + int curr_ = 0; // index of "curr" in ring_; prev is 1 - curr_ + uint32_t history_ = 0; // frames copied so far (need 2) + uint32_t gmSlot_ = 0; // rotates through FrameGen::kGmSlots + uint32_t builtW_ = 0, builtH_ = 0; + VkFormat builtFmt_ = VK_FORMAT_UNDEFINED; + uint64_t frames_ = 0; +}; + +} // namespace winfg diff --git a/app/src/main/cpp/winlator/winfg/winfg_vkd.cpp b/app/src/main/cpp/winlator/winfg/winfg_vkd.cpp new file mode 100644 index 0000000000..d76f357c13 --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/winfg_vkd.cpp @@ -0,0 +1,56 @@ +// See winfg_vkd.h. +#include "winfg_vkd.h" +#include "../VulkanRendererContext.h" +#include + +bool winfgVkdInit(const VkTable& table, winfg::DeviceDispatch& dd, winfg::InstanceDispatch& id) { + bool ok = true; +#define COPY(dst, fn) \ + do { \ + dst.fn = table.fn; \ + if (!dst.fn) { \ + __android_log_print(ANDROID_LOG_ERROR, "WinFgVkd", \ + "entry point vk" #fn " did not resolve"); \ + ok = false; \ + } \ + } while (0) + COPY(dd, AllocateDescriptorSets); + COPY(dd, AllocateMemory); + COPY(dd, BindBufferMemory); + COPY(dd, BindImageMemory); + COPY(dd, CmdBindDescriptorSets); + COPY(dd, CmdBindPipeline); + COPY(dd, CmdClearColorImage); + COPY(dd, CmdCopyImage); + COPY(dd, CmdDispatch); + COPY(dd, CmdPipelineBarrier); + COPY(dd, CreateBuffer); + COPY(dd, CreateComputePipelines); + COPY(dd, CreateDescriptorPool); + COPY(dd, CreateDescriptorSetLayout); + COPY(dd, CreateImage); + COPY(dd, CreateImageView); + COPY(dd, CreatePipelineLayout); + COPY(dd, CreateSampler); + COPY(dd, CreateShaderModule); + COPY(dd, DestroyBuffer); + COPY(dd, DestroyDescriptorPool); + COPY(dd, DestroyDescriptorSetLayout); + COPY(dd, DestroyImage); + COPY(dd, DestroyImageView); + COPY(dd, DestroyPipeline); + COPY(dd, DestroyPipelineLayout); + COPY(dd, DestroySampler); + COPY(dd, DestroyShaderModule); + COPY(dd, DeviceWaitIdle); + COPY(dd, FreeMemory); + COPY(dd, GetBufferMemoryRequirements); + COPY(dd, GetImageMemoryRequirements); + COPY(dd, MapMemory); + COPY(dd, ResetDescriptorPool); + COPY(dd, UnmapMemory); + COPY(dd, UpdateDescriptorSets); + COPY(id, GetPhysicalDeviceMemoryProperties); +#undef COPY + return ok; +} diff --git a/app/src/main/cpp/winlator/winfg/winfg_vkd.h b/app/src/main/cpp/winlator/winfg/winfg_vkd.h new file mode 100644 index 0000000000..35ed22d5af --- /dev/null +++ b/app/src/main/cpp/winlator/winfg/winfg_vkd.h @@ -0,0 +1,19 @@ +#pragma once +// ============================================================================ +// winfg_vkd — fill win-fg's own dispatch tables from the renderer's VkTable. +// +// win-fg's chain (framegen.cpp / record_impl.inc) was written as a Vulkan +// LAYER and calls through winfg::DeviceDispatch / InstanceDispatch. Inside the +// compositor there is no layer chain to resolve those from, so they are filled +// from the renderer's per-context table instead - the same bridge lsfg_vkd +// provides for the LSFG chain, for the same reason: an adrenotools driver +// shares no global symbols with the system loader. +// +// Only the entry points the chain actually calls are filled (36 device-level +// plus GetPhysicalDeviceMemoryProperties); everything else in the structs +// stays null and is never reached. winfgVkdInit reports a false if any of +// those failed to resolve, so a null is never called mid-frame. +// ============================================================================ +#include "vk_dispatch.hpp" +struct VkTable; +bool winfgVkdInit(const VkTable& table, winfg::DeviceDispatch& dd, winfg::InstanceDispatch& id); diff --git a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt index e21f2047ce..71d9c613fd 100644 --- a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt @@ -14,6 +14,7 @@ import android.widget.Button import android.widget.ProgressBar import android.widget.TextView import com.steamdeck.launcher.core.FileUtils +import com.steamdeck.launcher.gpu.FrameGen import com.steamdeck.launcher.runtime.LinuxRuntime import com.steamdeck.launcher.runtime.LinuxRuntimeInstaller @@ -28,6 +29,7 @@ class MainActivity : Activity() { private lateinit var progress: ProgressBar private lateinit var playButton: Button private lateinit var runtimeButton: Button + private lateinit var frameGenButton: Button private val ui = Handler(Looper.getMainLooper()) @Volatile private var busy = false @@ -41,6 +43,8 @@ class MainActivity : Activity() { progress = findViewById(R.id.progress) playButton = findViewById(R.id.play) runtimeButton = findViewById(R.id.runtime) + frameGenButton = findViewById(R.id.frame_gen) + frameGenButton.setOnClickListener { pickFrameGen() } playButton.setOnClickListener { startActivity(Intent(this, SessionActivity::class.java)) } runtimeButton.setOnClickListener { onRuntimeButton() } @@ -119,7 +123,36 @@ class MainActivity : Activity() { ui.post { render() } } + /** Off, or an engine at 2x/3x/4x. Saved, and pushed to a running session on the next resume. */ + private fun pickFrameGen() { + val choices = arrayOf("Off", + "Win-FG 2×", "Win-FG 3×", "Win-FG 4×", + "LSFG 2× (needs Lossless Scaling)", "LSFG 3× (needs Lossless Scaling)", "LSFG 4× (needs Lossless Scaling)") + val engine = FrameGen.engine(this) + val current = when (engine) { + FrameGen.ENGINE_WINFG -> FrameGen.multiplier(this) - 1 + FrameGen.ENGINE_LSFG -> FrameGen.multiplier(this) + 2 + else -> 0 + } + AlertDialog.Builder(this) + .setTitle(R.string.frame_gen_title) + .setSingleChoiceItems(choices, current) { dialog, which -> + when (which) { + 0 -> FrameGen.set(this, FrameGen.ENGINE_OFF, 2) + in 1..3 -> FrameGen.set(this, FrameGen.ENGINE_WINFG, which + 1) + else -> FrameGen.set(this, FrameGen.ENGINE_LSFG, which - 2) + } + dialog.dismiss() + render() + } + .setNeutralButton(android.R.string.ok, null) + .setMessage(null) + .show() + Log.i(TAG, "frame generation picker: " + FrameGen.label(this)) + } + private fun render() { + frameGenButton.text = getString(R.string.frame_gen, FrameGen.label(this)) val installed = LinuxRuntimeInstaller.installedVersion(this) val ready = LinuxRuntime.isInstalled(this) progress.visibility = if (busy) View.VISIBLE else View.GONE diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index c01aece3f1..933da410f8 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -16,6 +16,7 @@ import android.view.View import android.view.WindowManager import android.widget.FrameLayout import com.steamdeck.launcher.core.FileUtils +import com.steamdeck.launcher.gpu.FrameGen import com.steamdeck.launcher.gpu.TurnipDriver import com.steamdeck.launcher.input.EvdevKeys import com.steamdeck.launcher.input.OnScreenControls @@ -121,6 +122,7 @@ class SessionActivity : Activity(), SurfaceHolder.Callback { CompositorHost.newSession() SessionService.start(this) } + applyFrameGen() } override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {} @@ -272,8 +274,23 @@ class SessionActivity : Activity(), SurfaceHolder.Callback { Log.i(TAG, "on-screen controls " + (if (show) "shown" else "hidden")) } + /** + * The saved frame-generation setting, pushed to the compositor. Off the main thread: LSFG's + * first use translates the shader chain out of Lossless.dll, which takes seconds. + */ + private fun applyFrameGen() { + val hz = refreshHz() + Thread({ + val problem = FrameGen.apply(this, hz) + if (problem != null) runOnUiThread { + android.widget.Toast.makeText(this, problem, android.widget.Toast.LENGTH_LONG).show() + } + }, "frame-gen").start() + } + override fun onResume() { super.onResume() + if (CompositorHost.isStarted) applyFrameGen() (getSystemService(INPUT_SERVICE) as? InputManager) ?.registerInputDeviceListener(deviceListener, Handler(Looper.getMainLooper())) updateOnScreenControls() diff --git a/app/src/main/java/com/steamdeck/launcher/gpu/FrameGen.kt b/app/src/main/java/com/steamdeck/launcher/gpu/FrameGen.kt new file mode 100644 index 0000000000..901d9ca82b --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/gpu/FrameGen.kt @@ -0,0 +1,86 @@ +package com.steamdeck.launcher.gpu + +import android.content.Context +import android.util.Log +import com.steamdeck.launcher.wayland.WaylandCompositor + +/** + * The frame-generation setting and how it reaches the compositor. + * + * Both engines generate on gamescope's final output inside our compositor, so they work for any + * game with nothing changed in the runtime. Win-FG is our own and needs nothing; LSFG needs the + * shader chain from the user's copy of Lossless Scaling (see [LsfgNative]). Every compositor + * setter is a value store on the native side, so this can be applied before the compositor is + * up and changed live from the main screen while a session runs. + */ +object FrameGen { + const val ENGINE_OFF = "off" + const val ENGINE_WINFG = "winfg" + const val ENGINE_LSFG = "lsfg" + + /** Win-FG's Performance preset, pinned: changing it live rebuilds the whole chain. */ + private const val WINFG_PERF_PRESET = 2 + /** Bidirectional flow with the occlusion gate — the chain's own default. */ + private const val WINFG_MODEL = 4 + /** Optical-flow resolution as a fraction of the output; Bannerlator's per-engine defaults. */ + private const val FLOW_SCALE_WINFG = 0.60f + private const val FLOW_SCALE_LSFG = 0.80f + + private const val PREFS = "frame_gen" + + fun engine(context: Context): String = + context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getString("engine", ENGINE_OFF) ?: ENGINE_OFF + + fun multiplier(context: Context): Int = + context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getInt("multiplier", 2).coerceIn(2, 4) + + fun set(context: Context, engine: String, multiplier: Int) { + context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit() + .putString("engine", engine).putInt("multiplier", multiplier).apply() + } + + /** "Off", "Win-FG 2×", "LSFG 3×" — for the main screen. */ + fun label(context: Context): String = when (engine(context)) { + ENGINE_WINFG -> "Win-FG ${multiplier(context)}×" + ENGINE_LSFG -> "LSFG ${multiplier(context)}×" + else -> "Off" + } + + /** + * Pushes the saved setting into the compositor. Returns a message for the user when the + * engine cannot run (LSFG without Lossless Scaling), or null. + */ + fun apply(context: Context, refreshHz: Float): String? { + val engine = engine(context) + val multiplier = multiplier(context) + var problem: String? = null + when (engine) { + ENGINE_LSFG -> { + val status = LsfgNative.ensureCache(context) + if (status != LsfgNative.STATUS_OK) { + problem = if (status == LsfgNative.STATUS_NOT_INSTALLED) + "LSFG needs Lossless Scaling installed from the Steam client" + else "LSFG: " + LsfgNative.statusName(status) + Log.w(TAG, problem) + WaylandCompositor.nativeSetFrameGenArmed(false, 0) + return problem + } + WaylandCompositor.nativeSetFrameGenEngine(WaylandCompositor.FG_ENGINE_LSFG) + WaylandCompositor.nativeSetLsfgCachePath(LsfgNative.cacheFile(context).absolutePath) + WaylandCompositor.nativeSetFrameGenTuning(FLOW_SCALE_LSFG, refreshHz) + WaylandCompositor.nativeSetFrameGenArmed(true, multiplier) + } + ENGINE_WINFG -> { + WaylandCompositor.nativeSetFrameGenEngine(WaylandCompositor.FG_ENGINE_WINFG) + WaylandCompositor.nativeSetWinFgTuning(WINFG_MODEL, WINFG_PERF_PRESET) + WaylandCompositor.nativeSetFrameGenTuning(FLOW_SCALE_WINFG, refreshHz) + WaylandCompositor.nativeSetFrameGenArmed(true, multiplier) + } + else -> WaylandCompositor.nativeSetFrameGenArmed(false, 0) + } + Log.i(TAG, "frame generation: $engine x$multiplier at ${refreshHz}Hz") + return problem + } + + private const val TAG = "FrameGen" +} diff --git a/app/src/main/java/com/steamdeck/launcher/gpu/LsfgNative.java b/app/src/main/java/com/steamdeck/launcher/gpu/LsfgNative.java new file mode 100644 index 0000000000..350d75a143 --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/gpu/LsfgNative.java @@ -0,0 +1,99 @@ +package com.steamdeck.launcher.gpu; + +import android.content.Context; +import android.util.Log; + +import com.steamdeck.launcher.runtime.LinuxRuntime; + +import java.io.File; + +/** + * LSFG frame generation's shader chain: extracted from the user's own copy of Lossless Scaling + * and cached on device. + * + *

The 25 compute shaders are not redistributable. They live as resources inside the user's + * paid {@code Lossless.dll} (Steam app 993090), which in this app the user installs from the + * Steam client itself — so the DLL sits in the runtime's own Steam library. It is mapped + * read-only and parsed as data, never loaded or executed. Extraction is slow enough to be worth + * doing once (the DXBC chain is translated to SPIR-V), so the result is cached, keyed on the + * DLL's size and hash. Call {@link #ensureCache} off the main thread. + * + *

Ported from Bannerlator's LsfgNative; the native side is the same lsfg_jni.cpp compiled into + * the compositor library. + */ +public final class LsfgNative { + private static final String TAG = "LsfgNative"; + + static { System.loadLibrary("bannerwayland"); } + + private LsfgNative() {} + + // Mirrors lsfg::DllStatus. + public static final int STATUS_OK = 0; + public static final int STATUS_NOT_INSTALLED = 1; + public static final int STATUS_UNREADABLE_FILE = 2; + public static final int STATUS_NOT_PORTABLE_EXECUTABLE = 3; + public static final int STATUS_MISSING_SHADERS = 4; + public static final int STATUS_TRANSLATION_FAILED = 5; + public static final int STATUS_CACHE_UNUSABLE = 6; + + private static native int nativeValidateDll(String dllPath); + private static native int nativeDllVariant(String dllPath, boolean preferFp16); + private static native int nativeBuildCache(String dllPath, String cachePath, boolean preferFp16); + private static native boolean nativeCacheMatchesSource(String cachePath, String dllPath); + private static native int nativeCacheVariant(String cachePath); + private static native String nativeStatusName(int status); + private static native String nativeVariantName(int variant); + + /** Where Lossless Scaling lands when installed from the client inside the runtime. */ + public static File losslessDll(Context context) { + return new File(LinuxRuntime.rootDir(context), + "root/.local/share/Steam/steamapps/common/Lossless Scaling/Lossless.dll"); + } + + /** Where the translated SPIR-V chain is cached. */ + public static File cacheFile(Context context) { + return new File(context.getFilesDir(), "lsfg-native/shaders.cache"); + } + + public static boolean isInstalled(Context context) { + return losslessDll(context).isFile(); + } + + /** + * Makes sure a usable cache exists for the installed DLL, building it if the DLL is new or + * changed. Returns a {@code STATUS_*} code; {@link #STATUS_OK} means the engine can start. + */ + public static int ensureCache(Context context) { + File dll = losslessDll(context); + if (!dll.isFile()) return STATUS_NOT_INSTALLED; + File cache = cacheFile(context); + try { + if (cache.isFile() && nativeCacheMatchesSource(cache.getPath(), dll.getPath())) { + return STATUS_OK; + } + int status = nativeValidateDll(dll.getPath()); + if (status != STATUS_OK) { + Log.w(TAG, "Lossless.dll rejected: " + statusName(status)); + return status; + } + //noinspection ResultOfMethodCallIgnored + cache.getParentFile().mkdirs(); + status = nativeBuildCache(dll.getPath(), cache.getPath(), true); + Log.i(TAG, "cache build: " + statusName(status) + + (status == STATUS_OK ? " (" + nativeVariantName(nativeCacheVariant(cache.getPath())) + ")" : "")); + return status; + } catch (Throwable t) { + Log.e(TAG, "ensureCache", t); + return STATUS_CACHE_UNUSABLE; + } + } + + public static String statusName(int status) { + try { + return nativeStatusName(status); + } catch (Throwable t) { + return "status " + status; + } + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d606cc76db..035f677335 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -91,6 +91,15 @@ android:textSize="13sp" android:text="@string/install_runtime" /> +