2017-10-16 17:50:09 +02:00
|
|
|
#pragma once
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
#include <array>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
#include "../spirv/spirv_module.h"
|
|
|
|
|
2018-03-23 01:04:04 +01:00
|
|
|
#include "dxbc_analysis.h"
|
2017-12-13 15:32:54 +01:00
|
|
|
#include "dxbc_chunk_isgn.h"
|
|
|
|
#include "dxbc_decoder.h"
|
|
|
|
#include "dxbc_defs.h"
|
2018-06-23 17:14:35 +02:00
|
|
|
#include "dxbc_modinfo.h"
|
2017-12-18 00:46:44 +01:00
|
|
|
#include "dxbc_names.h"
|
|
|
|
#include "dxbc_util.h"
|
2017-10-16 17:50:09 +02:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2017-12-14 12:53:53 +01:00
|
|
|
/**
|
2017-12-18 00:46:44 +01:00
|
|
|
* \brief Vector type
|
2017-12-14 12:53:53 +01:00
|
|
|
*
|
2017-12-18 00:46:44 +01:00
|
|
|
* Convenience struct that stores a scalar
|
|
|
|
* type and a component count. The compiler
|
|
|
|
* can use this to generate SPIR-V types.
|
2017-12-14 12:53:53 +01:00
|
|
|
*/
|
2017-12-18 00:46:44 +01:00
|
|
|
struct DxbcVectorType {
|
|
|
|
DxbcScalarType ctype;
|
|
|
|
uint32_t ccount;
|
2017-12-13 15:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-18 16:41:05 +01:00
|
|
|
/**
|
|
|
|
* \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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
/**
|
2017-12-18 00:46:44 +01:00
|
|
|
* \brief Register info
|
2017-12-13 15:32:54 +01:00
|
|
|
*
|
2017-12-18 16:41:05 +01:00
|
|
|
* Stores the array type of a register and
|
2017-12-18 00:46:44 +01:00
|
|
|
* its storage class. The compiler can use
|
|
|
|
* this to generate SPIR-V pointer types.
|
2017-12-13 15:32:54 +01:00
|
|
|
*/
|
2017-12-18 00:46:44 +01:00
|
|
|
struct DxbcRegisterInfo {
|
2017-12-18 16:41:05 +01:00
|
|
|
DxbcArrayType type;
|
2017-12-18 00:46:44 +01:00
|
|
|
spv::StorageClass sclass;
|
2017-12-13 15:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-18 00:46:44 +01:00
|
|
|
* \brief Register value
|
2017-12-13 15:32:54 +01:00
|
|
|
*
|
2017-12-18 00:46:44 +01:00
|
|
|
* Stores a vector type and a SPIR-V ID that
|
|
|
|
* represents an intermediate value. This is
|
|
|
|
* used to track the type of such values.
|
2017-12-13 15:32:54 +01:00
|
|
|
*/
|
2017-12-18 00:46:44 +01:00
|
|
|
struct DxbcRegisterValue {
|
|
|
|
DxbcVectorType type;
|
|
|
|
uint32_t id;
|
2017-12-13 15:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-18 00:46:44 +01:00
|
|
|
* \brief Register pointer
|
2017-12-13 15:32:54 +01:00
|
|
|
*
|
2017-12-18 00:46:44 +01:00
|
|
|
* 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.
|
2017-12-13 15:32:54 +01:00
|
|
|
*/
|
2017-12-18 00:46:44 +01:00
|
|
|
struct DxbcRegisterPointer {
|
|
|
|
DxbcVectorType type;
|
|
|
|
uint32_t id;
|
2017-12-13 15:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-20 22:50:05 +01:00
|
|
|
struct DxbcXreg {
|
2020-09-11 13:07:02 +02:00
|
|
|
uint32_t ccount = 0;
|
|
|
|
uint32_t alength = 0;
|
|
|
|
uint32_t varId = 0;
|
2017-12-20 22:50:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-29 00:51:31 +01:00
|
|
|
struct DxbcGreg {
|
|
|
|
DxbcResourceType type = DxbcResourceType::Raw;
|
|
|
|
uint32_t elementStride = 0;
|
|
|
|
uint32_t elementCount = 0;
|
|
|
|
uint32_t varId = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-26 14:54:05 +02:00
|
|
|
/**
|
|
|
|
* \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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-26 19:00:22 +02:00
|
|
|
/**
|
|
|
|
* \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;
|
|
|
|
};
|
2018-06-24 01:07:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2018-05-26 19:00:22 +02:00
|
|
|
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
/**
|
2017-12-18 00:46:44 +01:00
|
|
|
* \brief Vertex shader-specific structure
|
2017-12-13 15:32:54 +01:00
|
|
|
*/
|
2017-12-18 00:46:44 +01:00
|
|
|
struct DxbcCompilerVsPart {
|
2017-12-18 16:41:05 +01:00
|
|
|
uint32_t functionId = 0;
|
2017-12-21 12:37:20 +01:00
|
|
|
|
2017-12-27 12:49:25 +01:00
|
|
|
uint32_t builtinVertexId = 0;
|
|
|
|
uint32_t builtinInstanceId = 0;
|
|
|
|
uint32_t builtinBaseVertex = 0;
|
|
|
|
uint32_t builtinBaseInstance = 0;
|
2017-12-18 16:41:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Geometry shader-specific structure
|
|
|
|
*/
|
|
|
|
struct DxbcCompilerGsPart {
|
|
|
|
DxbcPrimitive inputPrimitive = DxbcPrimitive::Undefined;
|
|
|
|
DxbcPrimitiveTopology outputTopology = DxbcPrimitiveTopology::Undefined;
|
|
|
|
uint32_t outputVertexCount = 0;
|
|
|
|
uint32_t functionId = 0;
|
2018-02-04 23:36:00 +01:00
|
|
|
|
2018-02-15 18:07:40 +01:00
|
|
|
uint32_t builtinLayer = 0;
|
2018-03-26 23:32:07 +02:00
|
|
|
uint32_t builtinViewportId = 0;
|
2018-05-22 19:36:53 +02:00
|
|
|
uint32_t builtinInvocationId = 0;
|
2019-10-26 23:19:59 +02:00
|
|
|
uint32_t invocationCount = 0;
|
2017-12-13 15:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-18 00:46:44 +01:00
|
|
|
* \brief Pixel shader-specific structure
|
2017-12-13 15:32:54 +01:00
|
|
|
*/
|
2017-12-18 00:46:44 +01:00
|
|
|
struct DxbcCompilerPsPart {
|
2017-12-18 16:41:05 +01:00
|
|
|
uint32_t functionId = 0;
|
|
|
|
|
2018-01-29 10:54:36 +01:00
|
|
|
uint32_t builtinFragCoord = 0;
|
|
|
|
uint32_t builtinDepth = 0;
|
2019-09-15 14:56:23 +02:00
|
|
|
uint32_t builtinStencilRef = 0;
|
2018-01-29 10:54:36 +01:00
|
|
|
uint32_t builtinIsFrontFace = 0;
|
|
|
|
uint32_t builtinSampleId = 0;
|
|
|
|
uint32_t builtinSampleMaskIn = 0;
|
|
|
|
uint32_t builtinSampleMaskOut = 0;
|
2018-02-15 18:07:40 +01:00
|
|
|
uint32_t builtinLayer = 0;
|
2018-06-27 12:02:54 +02:00
|
|
|
uint32_t builtinViewportId = 0;
|
2018-05-26 19:25:20 +02:00
|
|
|
|
2019-04-30 14:42:21 +02:00
|
|
|
uint32_t builtinLaneId = 0;
|
2018-05-26 19:25:20 +02:00
|
|
|
uint32_t killState = 0;
|
2019-04-30 21:07:52 +02:00
|
|
|
|
|
|
|
uint32_t specRsSampleCount = 0;
|
2017-12-13 15:32:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-21 17:27:40 +01:00
|
|
|
/**
|
|
|
|
* \brief Compute shader-specific structure
|
|
|
|
*/
|
|
|
|
struct DxbcCompilerCsPart {
|
|
|
|
uint32_t functionId = 0;
|
2018-11-23 14:39:33 +01:00
|
|
|
|
|
|
|
uint32_t workgroupSizeX = 0;
|
|
|
|
uint32_t workgroupSizeY = 0;
|
|
|
|
uint32_t workgroupSizeZ = 0;
|
2017-12-28 16:03:17 +01:00
|
|
|
|
|
|
|
uint32_t builtinGlobalInvocationId = 0;
|
|
|
|
uint32_t builtinLocalInvocationId = 0;
|
|
|
|
uint32_t builtinLocalInvocationIndex = 0;
|
|
|
|
uint32_t builtinWorkgroupId = 0;
|
2017-12-21 17:27:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-01-29 14:37:06 +01:00
|
|
|
/**
|
|
|
|
* \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;
|
2018-03-01 12:08:06 +01:00
|
|
|
uint32_t instanceCount = 1;
|
2018-03-06 18:29:20 +01:00
|
|
|
|
|
|
|
uint32_t instanceId = 0;
|
|
|
|
uint32_t instanceIdPtr = 0;
|
2018-01-29 14:37:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Hull shader control point phase
|
|
|
|
*
|
|
|
|
* Defines the function for the control
|
|
|
|
* point phase program of a hull shader.
|
|
|
|
*/
|
|
|
|
struct DxbcCompilerHsControlPointPhase {
|
2018-03-05 17:23:00 +01:00
|
|
|
uint32_t functionId = 0;
|
2018-01-29 14:37:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \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 {
|
2018-03-01 12:47:24 +01:00
|
|
|
DxbcCompilerHsPhase currPhaseType = DxbcCompilerHsPhase::None;
|
|
|
|
size_t currPhaseId = 0;
|
|
|
|
|
2018-03-10 15:02:27 +01:00
|
|
|
float maxTessFactor = 64.0f;
|
|
|
|
|
2018-03-05 14:07:15 +01:00
|
|
|
uint32_t vertexCountIn = 0;
|
|
|
|
uint32_t vertexCountOut = 0;
|
|
|
|
|
2018-03-05 17:23:00 +01:00
|
|
|
uint32_t builtinInvocationId = 0;
|
2018-03-05 14:07:15 +01:00
|
|
|
uint32_t builtinTessLevelOuter = 0;
|
|
|
|
uint32_t builtinTessLevelInner = 0;
|
2018-01-29 14:37:06 +01:00
|
|
|
|
2018-03-06 14:00:03 +01:00
|
|
|
uint32_t outputPerPatch = 0;
|
|
|
|
uint32_t outputPerVertex = 0;
|
|
|
|
|
2018-03-06 15:05:58 +01:00
|
|
|
uint32_t invocationBlockBegin = 0;
|
|
|
|
uint32_t invocationBlockEnd = 0;
|
2018-09-13 14:54:54 +02:00
|
|
|
|
|
|
|
uint32_t outputPerPatchMask = 0;
|
2018-03-06 15:05:58 +01:00
|
|
|
|
2018-01-29 14:37:06 +01:00
|
|
|
DxbcCompilerHsControlPointPhase cpPhase;
|
|
|
|
std::vector<DxbcCompilerHsForkJoinPhase> forkPhases;
|
|
|
|
std::vector<DxbcCompilerHsForkJoinPhase> joinPhases;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Domain shader-specific structure
|
|
|
|
*/
|
|
|
|
struct DxbcCompilerDsPart {
|
2018-03-06 16:47:35 +01:00
|
|
|
uint32_t functionId = 0;
|
2018-03-05 14:07:15 +01:00
|
|
|
|
2018-03-06 16:47:35 +01:00
|
|
|
uint32_t builtinTessCoord = 0;
|
2018-03-05 14:07:15 +01:00
|
|
|
uint32_t builtinTessLevelOuter = 0;
|
|
|
|
uint32_t builtinTessLevelInner = 0;
|
2018-03-06 16:47:35 +01:00
|
|
|
|
|
|
|
uint32_t vertexCountIn = 0;
|
|
|
|
|
|
|
|
uint32_t inputPerPatch = 0;
|
|
|
|
uint32_t inputPerVertex = 0;
|
2018-01-29 14:37:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
enum class DxbcCfgBlockType : uint32_t {
|
2017-12-30 17:22:36 +01:00
|
|
|
If, Loop, Switch,
|
2017-12-18 11:53:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct DxbcCfgBlockIf {
|
2018-05-18 22:26:16 +02:00
|
|
|
uint32_t ztestId;
|
2017-12-18 11:53:28 +01:00
|
|
|
uint32_t labelIf;
|
|
|
|
uint32_t labelElse;
|
|
|
|
uint32_t labelEnd;
|
2018-05-18 22:26:16 +02:00
|
|
|
size_t headerPtr;
|
2017-12-18 11:53:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct DxbcCfgBlockLoop {
|
|
|
|
uint32_t labelHeader;
|
|
|
|
uint32_t labelBegin;
|
|
|
|
uint32_t labelContinue;
|
|
|
|
uint32_t labelBreak;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-30 17:22:36 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
struct DxbcCfgBlock {
|
|
|
|
DxbcCfgBlockType type;
|
|
|
|
|
|
|
|
union {
|
2017-12-30 17:22:36 +01:00
|
|
|
DxbcCfgBlockIf b_if;
|
|
|
|
DxbcCfgBlockLoop b_loop;
|
|
|
|
DxbcCfgBlockSwitch b_switch;
|
2017-12-18 11:53:28 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
struct DxbcBufferInfo {
|
2018-01-02 16:57:37 +01:00
|
|
|
DxbcImageInfo image;
|
2018-03-21 12:11:18 +01:00
|
|
|
DxbcScalarType stype;
|
2017-12-28 16:03:17 +01:00
|
|
|
DxbcResourceType type;
|
|
|
|
uint32_t typeId;
|
|
|
|
uint32_t varId;
|
|
|
|
uint32_t stride;
|
2019-06-05 00:58:25 +02:00
|
|
|
uint32_t align;
|
2017-12-28 16:03:17 +01:00
|
|
|
};
|
|
|
|
|
2018-06-01 13:57:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief SPIR-V extension set
|
|
|
|
*
|
|
|
|
* Keeps track of which optional SPIR-V extensions
|
|
|
|
* are enabled so that any required setup code is
|
|
|
|
* only run once.
|
|
|
|
*/
|
|
|
|
struct DxbcSpirvExtensions {
|
|
|
|
bool shaderViewportIndexLayer = false;
|
|
|
|
};
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
/**
|
|
|
|
* \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.
|
|
|
|
*/
|
2017-12-14 12:53:53 +01:00
|
|
|
class DxbcCompiler {
|
2017-10-16 17:50:09 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-12-14 12:53:53 +01:00
|
|
|
DxbcCompiler(
|
2018-04-15 21:00:08 +02:00
|
|
|
const std::string& fileName,
|
2018-06-23 17:14:35 +02:00
|
|
|
const DxbcModuleInfo& moduleInfo,
|
2018-10-08 09:34:56 +02:00
|
|
|
const DxbcProgramInfo& programInfo,
|
2017-12-07 16:29:34 +01:00
|
|
|
const Rc<DxbcIsgn>& isgn,
|
2018-03-23 01:04:04 +01:00
|
|
|
const Rc<DxbcIsgn>& osgn,
|
2019-01-26 14:52:29 +01:00
|
|
|
const Rc<DxbcIsgn>& psgn,
|
2018-03-23 01:04:04 +01:00
|
|
|
const DxbcAnalysisInfo& analysis);
|
2017-12-14 12:53:53 +01:00
|
|
|
~DxbcCompiler();
|
2017-10-16 17:50:09 +02:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
/**
|
|
|
|
* \brief Processes a single instruction
|
|
|
|
* \param [in] ins The instruction
|
|
|
|
*/
|
2017-12-18 00:46:44 +01:00
|
|
|
void processInstruction(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-11-13 00:22:52 +01:00
|
|
|
|
2018-07-25 22:45:23 +02:00
|
|
|
/**
|
|
|
|
* \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();
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
/**
|
|
|
|
* \brief Finalizes the shader
|
|
|
|
* \returns The final shader object
|
|
|
|
*/
|
2017-12-08 18:14:05 +01:00
|
|
|
Rc<DxvkShader> finalize();
|
2017-10-16 17:50:09 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-06-23 17:14:35 +02:00
|
|
|
DxbcModuleInfo m_moduleInfo;
|
2018-10-08 09:34:56 +02:00
|
|
|
DxbcProgramInfo m_programInfo;
|
2017-12-13 15:32:54 +01:00
|
|
|
SpirvModule m_module;
|
2017-11-13 00:22:52 +01:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
Rc<DxbcIsgn> m_isgn;
|
|
|
|
Rc<DxbcIsgn> m_osgn;
|
2019-01-26 14:52:29 +01:00
|
|
|
Rc<DxbcIsgn> m_psgn;
|
2017-11-13 00:22:52 +01:00
|
|
|
|
2018-03-23 01:04:04 +01:00
|
|
|
const DxbcAnalysisInfo* m_analysis;
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// Resource slot description for the shader. This will
|
|
|
|
// be used to map D3D11 bindings to DXVK bindings.
|
2022-06-07 10:44:56 +02:00
|
|
|
std::vector<DxvkBindingInfo> m_bindings;
|
2017-12-08 17:08:26 +01:00
|
|
|
|
2017-12-20 22:50:05 +01:00
|
|
|
////////////////////////////////////////////////
|
|
|
|
// Temporary r# vector registers with immediate
|
|
|
|
// indexing, and x# vector array registers.
|
2017-12-13 15:32:54 +01:00
|
|
|
std::vector<uint32_t> m_rRegs;
|
2017-12-20 22:50:05 +01:00
|
|
|
std::vector<DxbcXreg> m_xRegs;
|
2017-12-10 10:34:18 +01:00
|
|
|
|
2017-12-29 00:51:31 +01:00
|
|
|
/////////////////////////////////////////////
|
|
|
|
// Thread group shared memory (g#) registers
|
|
|
|
std::vector<DxbcGreg> m_gRegs;
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// v# registers as defined by the shader. The type of each
|
|
|
|
// of these inputs is either float4 or an array of float4.
|
2018-07-01 15:24:21 +02:00
|
|
|
std::array<
|
|
|
|
DxbcRegisterPointer,
|
|
|
|
DxbcMaxInterfaceRegs> m_vRegs;
|
|
|
|
std::vector<DxbcSvMapping> m_vMappings;
|
2017-12-10 03:39:35 +01:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// 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.
|
2018-07-01 15:24:21 +02:00
|
|
|
std::array<
|
|
|
|
DxbcRegisterPointer,
|
|
|
|
DxbcMaxInterfaceRegs> m_oRegs;
|
|
|
|
std::vector<DxbcSvMapping> m_oMappings;
|
2018-06-24 01:07:48 +02:00
|
|
|
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
// xfb output registers for geometry shaders
|
|
|
|
std::vector<DxbcXfbVar> m_xfbVars;
|
2017-11-13 00:22:52 +01:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Shader resource variables. These provide access to
|
|
|
|
// constant buffers, samplers, textures, and UAVs.
|
2017-12-14 12:53:53 +01:00
|
|
|
std::array<DxbcConstantBuffer, 16> m_constantBuffers;
|
|
|
|
std::array<DxbcSampler, 16> m_samplers;
|
|
|
|
std::array<DxbcShaderResource, 128> m_textures;
|
2017-12-28 16:03:17 +01:00
|
|
|
std::array<DxbcUav, 64> m_uavs;
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
///////////////////////////////////////////////
|
|
|
|
// Control flow information. Stores labels for
|
|
|
|
// currently active if-else blocks and loops.
|
|
|
|
std::vector<DxbcCfgBlock> m_controlFlowBlocks;
|
|
|
|
|
2018-08-27 12:47:52 +02:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Function state tracking. Required in order
|
|
|
|
// to properly end functions in some cases.
|
|
|
|
bool m_insideFunction = false;
|
2019-09-22 22:06:42 +02:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Array of input values. Since v# registers are indexable
|
|
|
|
// in DXBC, we need to copy them into an array first.
|
2019-10-23 16:36:52 +02:00
|
|
|
uint32_t m_vArrayLength = 0;
|
|
|
|
uint32_t m_vArrayLengthId = 0;
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
uint32_t m_vArray = 0;
|
2017-12-11 14:36:35 +01:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
// Per-vertex input and output blocks. Depending on
|
|
|
|
// the shader stage, these may be declared as arrays.
|
2018-03-24 16:23:31 +01:00
|
|
|
uint32_t m_perVertexIn = 0;
|
2017-12-13 15:32:54 +01:00
|
|
|
uint32_t m_perVertexOut = 0;
|
2017-12-09 01:49:30 +01:00
|
|
|
|
2018-03-24 11:29:07 +01:00
|
|
|
uint32_t m_clipDistances = 0;
|
|
|
|
uint32_t m_cullDistances = 0;
|
|
|
|
|
2018-04-08 18:25:44 +02:00
|
|
|
uint32_t m_primitiveIdIn = 0;
|
|
|
|
uint32_t m_primitiveIdOut = 0;
|
|
|
|
|
2017-12-19 17:41:23 +01:00
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// Immediate constant buffer. If defined, this is
|
|
|
|
// an array of four-component uint32 vectors.
|
2022-04-09 13:48:28 +02:00
|
|
|
uint32_t m_immConstBuf = 0;
|
|
|
|
std::vector<char> m_immConstData;
|
2017-12-19 17:41:23 +01:00
|
|
|
|
2018-03-12 12:25:10 +01:00
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// Sample pos array. If defined, this iis an array
|
|
|
|
// of 32 four-component float vectors.
|
|
|
|
uint32_t m_samplePositions = 0;
|
|
|
|
|
2018-01-11 17:11:51 +01:00
|
|
|
////////////////////////////////////////////
|
|
|
|
// Struct type used for UAV counter buffers
|
|
|
|
uint32_t m_uavCtrStructType = 0;
|
|
|
|
uint32_t m_uavCtrPointerType = 0;
|
|
|
|
|
2019-09-22 22:06:42 +02:00
|
|
|
////////////////////////////////
|
|
|
|
// Function IDs for subroutines
|
|
|
|
std::unordered_map<uint32_t, uint32_t> m_subroutines;
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// Entry point description - we'll need to declare
|
|
|
|
// the function ID and all input/output variables.
|
|
|
|
std::vector<uint32_t> m_entryPointInterfaces;
|
|
|
|
uint32_t m_entryPointId = 0;
|
2017-12-08 17:08:26 +01:00
|
|
|
|
2018-01-12 14:25:26 +01:00
|
|
|
////////////////////////////////////////////
|
|
|
|
// Inter-stage shader interface slots. Also
|
|
|
|
// covers vertex input and fragment output.
|
2022-04-09 13:48:28 +02:00
|
|
|
uint32_t m_inputMask = 0u;
|
|
|
|
uint32_t m_outputMask = 0u;
|
2018-06-23 20:19:46 +02:00
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
///////////////////////////////////
|
|
|
|
// Shader-specific data structures
|
|
|
|
DxbcCompilerVsPart m_vs;
|
2018-01-29 14:37:06 +01:00
|
|
|
DxbcCompilerHsPart m_hs;
|
|
|
|
DxbcCompilerDsPart m_ds;
|
2017-12-18 16:41:05 +01:00
|
|
|
DxbcCompilerGsPart m_gs;
|
2017-12-18 00:46:44 +01:00
|
|
|
DxbcCompilerPsPart m_ps;
|
2017-12-21 17:27:40 +01:00
|
|
|
DxbcCompilerCsPart m_cs;
|
2018-06-01 13:57:26 +02:00
|
|
|
|
|
|
|
/////////////////////////////
|
|
|
|
// Enabled SPIR-V extensions
|
|
|
|
DxbcSpirvExtensions m_extensions;
|
2021-03-18 17:46:45 +01:00
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
// Global state stuff
|
|
|
|
bool m_precise = true;
|
|
|
|
|
2022-03-22 17:32:43 +01:00
|
|
|
DxbcOpcode m_lastOp = DxbcOpcode::Nop;
|
|
|
|
DxbcOpcode m_currOp = DxbcOpcode::Nop;
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
// Shader interface and metadata declaration methods
|
2017-12-18 11:53:28 +01:00
|
|
|
void emitDcl(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitDclGlobalFlags(
|
2017-12-18 11:53:28 +01:00
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-18 00:46:44 +01:00
|
|
|
|
|
|
|
void emitDclTemps(
|
2017-12-18 11:53:28 +01:00
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-18 00:46:44 +01:00
|
|
|
|
2017-12-20 22:50:05 +01:00
|
|
|
void emitDclIndexableTemp(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitDclInterfaceReg(
|
2017-12-18 11:53:28 +01:00
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-18 00:46:44 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-07-30 20:52:42 +02:00
|
|
|
void emitDclConstantBufferVar(
|
|
|
|
uint32_t regIdx,
|
2018-07-30 22:08:01 +02:00
|
|
|
uint32_t numConstants,
|
2019-10-28 14:17:46 +01:00
|
|
|
const char* name,
|
|
|
|
bool asSsbo);
|
2018-07-30 20:52:42 +02:00
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitDclSampler(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-02-04 22:59:15 +01:00
|
|
|
void emitDclStream(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
void emitDclResourceTyped(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitDclResourceRawStructured(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitDclThreadGroupSharedMemory(
|
2017-12-18 00:46:44 +01:00
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-10 20:01:38 +01:00
|
|
|
|
2017-12-18 16:41:05 +01:00
|
|
|
void emitDclGsInputPrimitive(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitDclGsOutputTopology(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitDclMaxOutputVertexCount(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-03-01 12:47:24 +01:00
|
|
|
void emitDclInputControlPointCount(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitDclOutputControlPointCount(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-03-10 15:02:27 +01:00
|
|
|
void emitDclHsMaxTessFactor(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-03-01 14:36:17 +01:00
|
|
|
void emitDclTessDomain(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitDclTessPartitioning(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitDclTessOutputPrimitive(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
void emitDclThreadGroup(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-05-22 19:36:53 +02:00
|
|
|
void emitDclGsInstanceCount(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-01-11 17:11:51 +01:00
|
|
|
uint32_t emitDclUavCounter(
|
|
|
|
uint32_t regId);
|
|
|
|
|
2017-12-19 17:41:23 +01:00
|
|
|
////////////////////////
|
|
|
|
// Custom data handlers
|
|
|
|
void emitDclImmediateConstantBuffer(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-07-30 20:52:42 +02:00
|
|
|
void emitDclImmediateConstantBufferBaked(
|
|
|
|
uint32_t dwordCount,
|
|
|
|
const uint32_t* dwordArray);
|
|
|
|
|
|
|
|
void emitDclImmediateConstantBufferUbo(
|
|
|
|
uint32_t dwordCount,
|
|
|
|
const uint32_t* dwordArray);
|
|
|
|
|
2017-12-19 17:41:23 +01:00
|
|
|
void emitCustomData(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
//////////////////////////////
|
|
|
|
// Instruction class handlers
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVectorAlu(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVectorCmov(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-13 15:32:54 +01:00
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVectorCmp(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-13 15:32:54 +01:00
|
|
|
|
2017-12-19 20:26:05 +01:00
|
|
|
void emitVectorDeriv(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVectorDot(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-10 12:08:20 +01:00
|
|
|
|
2017-12-18 16:41:05 +01:00
|
|
|
void emitVectorIdiv(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVectorImul(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-08 17:08:26 +01:00
|
|
|
|
2019-09-16 00:48:39 +02:00
|
|
|
void emitVectorMsad(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-20 23:50:39 +01:00
|
|
|
void emitVectorShift(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVectorSinCos(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 16:41:05 +01:00
|
|
|
void emitGeometryEmit(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
void emitAtomic(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-01-11 17:11:51 +01:00
|
|
|
void emitAtomicCounter(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-29 00:51:31 +01:00
|
|
|
void emitBarrier(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-30 03:44:19 +01:00
|
|
|
void emitBitExtract(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitBitInsert(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-05-12 01:39:23 +02:00
|
|
|
void emitBitScan(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-30 01:26:37 +01:00
|
|
|
void emitBufferQuery(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
void emitBufferLoad(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitBufferStore(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-30 13:18:31 +01:00
|
|
|
void emitConvertFloat16(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-06-07 14:32:56 +02:00
|
|
|
void emitConvertFloat64(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-03-01 09:26:17 +01:00
|
|
|
void emitHullShaderPhase(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-03-01 12:08:06 +01:00
|
|
|
void emitHullShaderInstCnt(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-02-26 16:46:34 +01:00
|
|
|
void emitInterpolate(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-27 01:37:15 +01:00
|
|
|
void emitTextureQuery(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-02-04 22:41:23 +01:00
|
|
|
void emitTextureQueryLod(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-02-04 19:30:39 +01:00
|
|
|
void emitTextureQueryMs(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-03-12 12:25:10 +01:00
|
|
|
void emitTextureQueryMsPos(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-27 01:37:15 +01:00
|
|
|
void emitTextureFetch(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-01-17 02:12:29 +01:00
|
|
|
void emitTextureGather(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-27 01:37:15 +01:00
|
|
|
void emitTextureSample(
|
2017-12-18 00:46:44 +01:00
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2018-01-01 17:14:06 +01:00
|
|
|
void emitTypedUavLoad(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitTypedUavStore(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
/////////////////////////////////////
|
|
|
|
// Control flow instruction handlers
|
|
|
|
void emitControlFlowIf(
|
2017-12-18 00:46:44 +01:00
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
void emitControlFlowElse(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowEndIf(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-30 17:22:36 +01:00
|
|
|
void emitControlFlowSwitch(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowCase(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowDefault(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowEndSwitch(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
void emitControlFlowLoop(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowEndLoop(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-29 22:54:25 +01:00
|
|
|
void emitControlFlowBreak(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
void emitControlFlowBreakc(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowRet(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2018-03-10 15:04:58 +01:00
|
|
|
|
|
|
|
void emitControlFlowRetc(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-18 11:53:28 +01:00
|
|
|
|
2017-12-18 16:41:05 +01:00
|
|
|
void emitControlFlowDiscard(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2019-09-22 22:06:42 +02:00
|
|
|
void emitControlFlowLabel(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowCall(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
|
|
|
void emitControlFlowCallc(
|
|
|
|
const DxbcShaderInstruction& ins);
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
void emitControlFlow(
|
|
|
|
const DxbcShaderInstruction& ins);
|
2017-12-18 00:46:44 +01:00
|
|
|
|
2017-12-30 03:44:19 +01:00
|
|
|
////////////////////////////////////////////////
|
|
|
|
// Constant building methods. These are used to
|
|
|
|
// generate constant vectors that store the same
|
|
|
|
// value in each component.
|
|
|
|
DxbcRegisterValue emitBuildConstVecf32(
|
2018-01-08 22:26:45 +01:00
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float z,
|
|
|
|
float w,
|
2017-12-30 03:44:19 +01:00
|
|
|
const DxbcRegMask& writeMask);
|
|
|
|
|
2018-01-10 18:58:17 +01:00
|
|
|
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);
|
|
|
|
|
2018-08-15 19:51:07 +02:00
|
|
|
DxbcRegisterValue emitBuildConstVecf64(
|
|
|
|
double xy,
|
|
|
|
double zw,
|
|
|
|
const DxbcRegMask& writeMask);
|
2020-11-24 18:09:19 +01:00
|
|
|
|
|
|
|
DxbcRegisterValue emitBuildVector(
|
|
|
|
DxbcRegisterValue scalar,
|
|
|
|
uint32_t count);
|
2018-08-15 19:51:07 +02:00
|
|
|
|
2020-11-24 18:09:19 +01:00
|
|
|
DxbcRegisterValue emitBuildZeroVector(
|
|
|
|
DxbcVectorType type);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
/////////////////////////////////////////
|
|
|
|
// 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);
|
|
|
|
|
2018-03-01 10:11:15 +01:00
|
|
|
DxbcRegisterValue emitRegisterConcat(
|
|
|
|
DxbcRegisterValue value1,
|
|
|
|
DxbcRegisterValue value2);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
DxbcRegisterValue emitRegisterExtend(
|
|
|
|
DxbcRegisterValue value,
|
|
|
|
uint32_t size);
|
|
|
|
|
|
|
|
DxbcRegisterValue emitRegisterAbsolute(
|
|
|
|
DxbcRegisterValue value);
|
|
|
|
|
|
|
|
DxbcRegisterValue emitRegisterNegate(
|
|
|
|
DxbcRegisterValue value);
|
|
|
|
|
2017-12-18 11:53:28 +01:00
|
|
|
DxbcRegisterValue emitRegisterZeroTest(
|
|
|
|
DxbcRegisterValue value,
|
|
|
|
DxbcZeroTest test);
|
|
|
|
|
2018-09-03 01:01:44 +02:00
|
|
|
DxbcRegisterValue emitRegisterMaskBits(
|
|
|
|
DxbcRegisterValue value,
|
|
|
|
uint32_t mask);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
DxbcRegisterValue emitSrcOperandModifiers(
|
|
|
|
DxbcRegisterValue value,
|
|
|
|
DxbcRegModifiers modifiers);
|
|
|
|
|
|
|
|
DxbcRegisterValue emitDstOperandModifiers(
|
|
|
|
DxbcRegisterValue value,
|
|
|
|
DxbcOpModifiers modifiers);
|
|
|
|
|
2018-07-25 22:45:23 +02:00
|
|
|
////////////////////////////////
|
|
|
|
// Pointer manipulation methods
|
|
|
|
DxbcRegisterPointer emitArrayAccess(
|
|
|
|
DxbcRegisterPointer pointer,
|
|
|
|
spv::StorageClass sclass,
|
|
|
|
uint32_t index);
|
|
|
|
|
2018-02-04 22:41:23 +01:00
|
|
|
///////////////////////////////////////
|
|
|
|
// Image register manipulation methods
|
|
|
|
uint32_t emitLoadSampledImage(
|
|
|
|
const DxbcShaderResource& textureResource,
|
|
|
|
const DxbcSampler& samplerResource,
|
|
|
|
bool isDepthCompare);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
////////////////////////
|
|
|
|
// Address load methods
|
|
|
|
DxbcRegisterPointer emitGetTempPtr(
|
|
|
|
const DxbcRegister& operand);
|
|
|
|
|
2017-12-20 22:50:05 +01:00
|
|
|
DxbcRegisterPointer emitGetIndexableTempPtr(
|
|
|
|
const DxbcRegister& operand);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
DxbcRegisterPointer emitGetInputPtr(
|
|
|
|
const DxbcRegister& operand);
|
|
|
|
|
|
|
|
DxbcRegisterPointer emitGetOutputPtr(
|
|
|
|
const DxbcRegister& operand);
|
|
|
|
|
2018-06-02 18:09:59 +02:00
|
|
|
DxbcRegisterPointer emitGetConstBufPtr(
|
|
|
|
const DxbcRegister& operand);
|
|
|
|
|
2017-12-19 17:41:23 +01:00
|
|
|
DxbcRegisterPointer emitGetImmConstBufPtr(
|
|
|
|
const DxbcRegister& operand);
|
2017-12-18 00:46:44 +01:00
|
|
|
|
|
|
|
DxbcRegisterPointer emitGetOperandPtr(
|
|
|
|
const DxbcRegister& operand);
|
|
|
|
|
2018-01-02 12:07:49 +01:00
|
|
|
DxbcRegisterPointer emitGetAtomicPointer(
|
|
|
|
const DxbcRegister& operand,
|
|
|
|
const DxbcRegister& address);
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
///////////////////////////////
|
|
|
|
// Resource load/store methods
|
|
|
|
DxbcRegisterValue emitRawBufferLoad(
|
|
|
|
const DxbcRegister& operand,
|
|
|
|
DxbcRegisterValue elementIndex,
|
|
|
|
DxbcRegMask writeMask);
|
|
|
|
|
|
|
|
void emitRawBufferStore(
|
|
|
|
const DxbcRegister& operand,
|
|
|
|
DxbcRegisterValue elementIndex,
|
|
|
|
DxbcRegisterValue value);
|
|
|
|
|
2018-01-02 16:57:37 +01:00
|
|
|
//////////////////////////
|
|
|
|
// Resource query methods
|
2018-12-13 13:38:17 +01:00
|
|
|
DxbcRegisterValue emitQueryBufferSize(
|
|
|
|
const DxbcRegister& resource);
|
|
|
|
|
2018-01-02 16:57:37 +01:00
|
|
|
DxbcRegisterValue emitQueryTexelBufferSize(
|
|
|
|
const DxbcRegister& resource);
|
|
|
|
|
|
|
|
DxbcRegisterValue emitQueryTextureLods(
|
|
|
|
const DxbcRegister& resource);
|
|
|
|
|
2018-02-04 19:30:39 +01:00
|
|
|
DxbcRegisterValue emitQueryTextureSamples(
|
|
|
|
const DxbcRegister& resource);
|
|
|
|
|
2018-01-02 16:57:37 +01:00
|
|
|
DxbcRegisterValue emitQueryTextureSize(
|
|
|
|
const DxbcRegister& resource,
|
|
|
|
DxbcRegisterValue lod);
|
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
////////////////////////////////////
|
|
|
|
// Buffer index calculation methods
|
|
|
|
DxbcRegisterValue emitCalcBufferIndexStructured(
|
|
|
|
DxbcRegisterValue structId,
|
|
|
|
DxbcRegisterValue structOffset,
|
|
|
|
uint32_t structStride);
|
|
|
|
|
|
|
|
DxbcRegisterValue emitCalcBufferIndexRaw(
|
|
|
|
DxbcRegisterValue byteOffset);
|
|
|
|
|
2018-04-21 18:09:29 +02:00
|
|
|
DxbcRegisterValue emitCalcTexCoord(
|
|
|
|
DxbcRegisterValue coordVector,
|
|
|
|
const DxbcImageInfo& imageInfo);
|
|
|
|
|
|
|
|
DxbcRegisterValue emitLoadTexCoord(
|
|
|
|
const DxbcRegister& coordReg,
|
|
|
|
const DxbcImageInfo& imageInfo);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
//////////////////////////////
|
|
|
|
// Operand load/store methods
|
|
|
|
DxbcRegisterValue emitIndexLoad(
|
|
|
|
DxbcRegIndex index);
|
|
|
|
|
|
|
|
DxbcRegisterValue emitValueLoad(
|
|
|
|
DxbcRegisterPointer ptr);
|
|
|
|
|
|
|
|
void emitValueStore(
|
|
|
|
DxbcRegisterPointer ptr,
|
|
|
|
DxbcRegisterValue value,
|
|
|
|
DxbcRegMask writeMask);
|
|
|
|
|
2018-01-10 18:58:17 +01:00
|
|
|
DxbcRegisterValue emitRegisterLoadRaw(
|
|
|
|
const DxbcRegister& reg);
|
|
|
|
|
2019-01-28 21:14:17 +01:00
|
|
|
DxbcRegisterValue emitConstantBufferLoad(
|
|
|
|
const DxbcRegister& reg,
|
|
|
|
DxbcRegMask writeMask);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
DxbcRegisterValue emitRegisterLoad(
|
|
|
|
const DxbcRegister& reg,
|
|
|
|
DxbcRegMask writeMask);
|
|
|
|
|
|
|
|
void emitRegisterStore(
|
|
|
|
const DxbcRegister& reg,
|
|
|
|
DxbcRegisterValue value);
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2018-05-26 14:54:05 +02:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Spec constant declaration and access
|
2019-04-30 21:05:46 +02:00
|
|
|
uint32_t emitNewSpecConstant(
|
|
|
|
DxvkSpecConstantId specId,
|
|
|
|
DxbcScalarType type,
|
|
|
|
uint32_t value,
|
|
|
|
const char* name);
|
|
|
|
|
2017-12-21 12:37:20 +01:00
|
|
|
////////////////////////////
|
|
|
|
// Input/output preparation
|
2017-12-21 16:00:36 +01:00
|
|
|
void emitInputSetup();
|
2017-12-21 12:37:20 +01:00
|
|
|
void emitInputSetup(uint32_t vertexCount);
|
2017-12-21 16:00:36 +01:00
|
|
|
|
|
|
|
void emitOutputSetup();
|
2018-09-01 17:56:01 +02:00
|
|
|
void emitOutputMapping();
|
2018-11-22 17:39:10 +01:00
|
|
|
void emitOutputDepthClamp();
|
2017-12-21 16:00:36 +01:00
|
|
|
|
2018-11-23 15:57:54 +01:00
|
|
|
void emitInitWorkgroupMemory();
|
|
|
|
|
2017-12-21 16:00:36 +01:00
|
|
|
//////////////////////////////////////////
|
|
|
|
// 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);
|
|
|
|
|
2018-03-06 14:49:11 +01:00
|
|
|
void emitHsSystemValueStore(
|
|
|
|
DxbcSystemValue sv,
|
|
|
|
DxbcRegMask mask,
|
|
|
|
const DxbcRegisterValue& value);
|
|
|
|
|
2018-03-06 16:47:35 +01:00
|
|
|
void emitDsSystemValueStore(
|
|
|
|
DxbcSystemValue sv,
|
|
|
|
DxbcRegMask mask,
|
|
|
|
const DxbcRegisterValue& value);
|
|
|
|
|
2017-12-21 16:00:36 +01:00
|
|
|
void emitGsSystemValueStore(
|
|
|
|
DxbcSystemValue sv,
|
|
|
|
DxbcRegMask mask,
|
|
|
|
const DxbcRegisterValue& value);
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2018-04-18 21:14:34 +02:00
|
|
|
void emitPsSystemValueStore(
|
|
|
|
DxbcSystemValue sv,
|
|
|
|
DxbcRegMask mask,
|
|
|
|
const DxbcRegisterValue& value);
|
|
|
|
|
2018-03-24 11:29:07 +01:00
|
|
|
///////////////////////////////
|
|
|
|
// Special system value stores
|
|
|
|
void emitClipCullStore(
|
|
|
|
DxbcSystemValue sv,
|
|
|
|
uint32_t dstArray);
|
|
|
|
|
|
|
|
void emitClipCullLoad(
|
|
|
|
DxbcSystemValue sv,
|
|
|
|
uint32_t srcArray);
|
|
|
|
|
2018-05-26 19:25:20 +02:00
|
|
|
///////////////////////////////
|
|
|
|
// Some state checking methods
|
|
|
|
uint32_t emitUavWriteTest(
|
|
|
|
const DxbcBufferInfo& uav);
|
|
|
|
|
2018-03-06 15:52:29 +01:00
|
|
|
//////////////////////////////////////
|
|
|
|
// Common function definition methods
|
2018-02-01 18:07:24 +01:00
|
|
|
void emitInit();
|
|
|
|
|
2018-08-27 12:47:52 +02:00
|
|
|
void emitFunctionBegin(
|
|
|
|
uint32_t entryPoint,
|
|
|
|
uint32_t returnType,
|
|
|
|
uint32_t funcType);
|
|
|
|
|
|
|
|
void emitFunctionEnd();
|
2018-03-06 15:52:29 +01:00
|
|
|
|
2018-08-27 12:47:52 +02:00
|
|
|
void emitFunctionLabel();
|
|
|
|
|
|
|
|
void emitMainFunctionBegin();
|
2018-03-06 15:52:29 +01:00
|
|
|
|
|
|
|
/////////////////////////////////
|
|
|
|
// Shader initialization methods
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVsInit();
|
2018-01-29 14:37:06 +01:00
|
|
|
void emitHsInit();
|
2018-03-01 07:00:54 +01:00
|
|
|
void emitDsInit();
|
2017-12-18 16:41:05 +01:00
|
|
|
void emitGsInit();
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitPsInit();
|
2017-12-21 17:27:40 +01:00
|
|
|
void emitCsInit();
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
///////////////////////////////
|
|
|
|
// Shader finalization methods
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitVsFinalize();
|
2018-01-29 14:37:06 +01:00
|
|
|
void emitHsFinalize();
|
2018-03-01 07:00:54 +01:00
|
|
|
void emitDsFinalize();
|
2017-12-18 16:41:05 +01:00
|
|
|
void emitGsFinalize();
|
2017-12-18 00:46:44 +01:00
|
|
|
void emitPsFinalize();
|
2017-12-21 17:27:40 +01:00
|
|
|
void emitCsFinalize();
|
2018-06-24 01:07:48 +02:00
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
// Xfb related methods
|
|
|
|
void emitXfbOutputDeclarations();
|
|
|
|
|
|
|
|
void emitXfbOutputSetup(
|
2018-07-25 22:45:23 +02:00
|
|
|
uint32_t streamId,
|
|
|
|
bool passthrough);
|
2017-12-18 00:46:44 +01:00
|
|
|
|
2018-03-01 12:08:06 +01:00
|
|
|
///////////////////////////////
|
|
|
|
// Hull shader phase methods
|
|
|
|
void emitHsControlPointPhase(
|
|
|
|
const DxbcCompilerHsControlPointPhase& phase);
|
|
|
|
|
|
|
|
void emitHsForkJoinPhase(
|
|
|
|
const DxbcCompilerHsForkJoinPhase& phase);
|
|
|
|
|
2018-03-05 16:14:46 +01:00
|
|
|
void emitHsPhaseBarrier();
|
|
|
|
|
2018-03-06 15:05:58 +01:00
|
|
|
void emitHsInvocationBlockBegin(
|
|
|
|
uint32_t count);
|
|
|
|
|
|
|
|
void emitHsInvocationBlockEnd();
|
2018-09-13 14:54:54 +02:00
|
|
|
|
|
|
|
void emitHsOutputSetup();
|
2018-03-06 15:05:58 +01:00
|
|
|
|
2018-03-06 14:00:03 +01:00
|
|
|
uint32_t emitTessInterfacePerPatch(
|
|
|
|
spv::StorageClass storageClass);
|
|
|
|
|
|
|
|
uint32_t emitTessInterfacePerVertex(
|
|
|
|
spv::StorageClass storageClass,
|
|
|
|
uint32_t vertexCount);
|
|
|
|
|
2017-12-21 12:37:20 +01:00
|
|
|
//////////////
|
|
|
|
// Misc stuff
|
|
|
|
void emitDclInputArray(
|
|
|
|
uint32_t vertexCount);
|
|
|
|
|
2018-03-24 16:23:31 +01:00
|
|
|
void emitDclInputPerVertex(
|
|
|
|
uint32_t vertexCount,
|
|
|
|
const char* varName);
|
|
|
|
|
2018-03-24 11:29:07 +01:00
|
|
|
uint32_t emitDclClipCullDistanceArray(
|
|
|
|
uint32_t length,
|
|
|
|
spv::BuiltIn builtIn,
|
|
|
|
spv::StorageClass storageClass);
|
|
|
|
|
2018-03-05 17:23:00 +01:00
|
|
|
DxbcCompilerHsControlPointPhase emitNewHullShaderControlPointPhase();
|
|
|
|
|
2018-03-06 15:52:29 +01:00
|
|
|
DxbcCompilerHsControlPointPhase emitNewHullShaderPassthroughPhase();
|
|
|
|
|
2018-03-01 09:26:17 +01:00
|
|
|
DxbcCompilerHsForkJoinPhase emitNewHullShaderForkJoinPhase();
|
|
|
|
|
2018-03-12 12:25:10 +01:00
|
|
|
uint32_t emitSamplePosArray();
|
|
|
|
|
2021-01-28 15:54:36 +01:00
|
|
|
void emitFloatControl();
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
///////////////////////////////
|
|
|
|
// Variable definition methods
|
|
|
|
uint32_t emitNewVariable(
|
|
|
|
const DxbcRegisterInfo& info);
|
2017-12-08 17:08:26 +01:00
|
|
|
|
2017-12-21 12:37:20 +01:00
|
|
|
uint32_t emitNewBuiltinVariable(
|
|
|
|
const DxbcRegisterInfo& info,
|
|
|
|
spv::BuiltIn builtIn,
|
|
|
|
const char* name);
|
|
|
|
|
2018-03-05 14:07:15 +01:00
|
|
|
uint32_t emitBuiltinTessLevelOuter(
|
|
|
|
spv::StorageClass storageClass);
|
|
|
|
|
|
|
|
uint32_t emitBuiltinTessLevelInner(
|
|
|
|
spv::StorageClass storageClass);
|
2018-06-01 13:57:26 +02:00
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
// Extension enablement methods
|
|
|
|
void enableShaderViewportIndexLayer();
|
2018-03-05 14:07:15 +01:00
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
////////////////
|
|
|
|
// Misc methods
|
2017-12-30 17:22:36 +01:00
|
|
|
DxbcCfgBlock* cfgFindBlock(
|
|
|
|
const std::initializer_list<DxbcCfgBlockType>& types);
|
2017-12-18 11:53:28 +01:00
|
|
|
|
2017-12-28 16:03:17 +01:00
|
|
|
DxbcBufferInfo getBufferInfo(
|
|
|
|
const DxbcRegister& reg);
|
|
|
|
|
2018-04-12 13:57:15 +02:00
|
|
|
uint32_t getTexSizeDim(
|
|
|
|
const DxbcImageInfo& imageType) const;
|
|
|
|
|
2018-01-02 16:57:37 +01:00
|
|
|
uint32_t getTexLayerDim(
|
|
|
|
const DxbcImageInfo& imageType) const;
|
|
|
|
|
|
|
|
uint32_t getTexCoordDim(
|
|
|
|
const DxbcImageInfo& imageType) const;
|
|
|
|
|
2018-01-01 17:14:06 +01:00
|
|
|
DxbcRegMask getTexCoordMask(
|
|
|
|
const DxbcImageInfo& imageType) const;
|
|
|
|
|
2018-01-01 23:31:01 +01:00
|
|
|
DxbcVectorType getInputRegType(
|
|
|
|
uint32_t regIdx) const;
|
|
|
|
|
2018-04-18 21:14:34 +02:00
|
|
|
DxbcVectorType getOutputRegType(
|
|
|
|
uint32_t regIdx) const;
|
|
|
|
|
2018-04-23 00:46:27 +02:00
|
|
|
DxbcImageInfo getResourceType(
|
|
|
|
DxbcResourceDim resourceType,
|
|
|
|
bool isUav) const;
|
2018-01-08 13:39:37 +01:00
|
|
|
|
2018-03-21 12:11:18 +01:00
|
|
|
spv::ImageFormat getScalarImageFormat(
|
|
|
|
DxbcScalarType type) const;
|
|
|
|
|
2018-06-07 14:32:56 +02:00
|
|
|
bool isDoubleType(
|
|
|
|
DxbcScalarType type) const;
|
|
|
|
|
2020-09-11 13:07:02 +02:00
|
|
|
DxbcRegisterPointer getIndexableTempPtr(
|
|
|
|
const DxbcRegister& operand,
|
|
|
|
DxbcRegisterValue vectorId);
|
2022-03-22 17:32:43 +01:00
|
|
|
|
|
|
|
bool caseBlockIsFallthrough() const;
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
///////////////////////////
|
|
|
|
// Type definition methods
|
2017-12-18 00:46:44 +01:00
|
|
|
uint32_t getScalarTypeId(
|
|
|
|
DxbcScalarType type);
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
uint32_t getVectorTypeId(
|
|
|
|
const DxbcVectorType& type);
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2017-12-18 16:41:05 +01:00
|
|
|
uint32_t getArrayTypeId(
|
|
|
|
const DxbcArrayType& type);
|
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
uint32_t getPointerTypeId(
|
|
|
|
const DxbcRegisterInfo& type);
|
2017-11-16 01:30:17 +01:00
|
|
|
|
2017-12-18 00:46:44 +01:00
|
|
|
uint32_t getPerVertexBlockId();
|
2019-09-22 22:06:42 +02:00
|
|
|
|
|
|
|
uint32_t getFunctionId(
|
|
|
|
uint32_t functionNr);
|
2017-10-16 19:53:17 +02:00
|
|
|
|
2018-03-01 12:08:06 +01:00
|
|
|
DxbcCompilerHsForkJoinPhase* getCurrentHsForkJoinPhase();
|
2018-02-01 18:07:24 +01:00
|
|
|
|
2017-10-16 17:50:09 +02:00
|
|
|
};
|
|
|
|
|
2018-10-08 09:34:56 +02:00
|
|
|
}
|