2017-11-13 00:22:52 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../dxbc_common.h"
|
|
|
|
#include "../dxbc_decoder.h"
|
|
|
|
#include "../dxbc_type.h"
|
|
|
|
|
|
|
|
#include "../../spirv/spirv_module.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \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;
|
|
|
|
DxbcComponentMask regMask;
|
|
|
|
DxbcSystemValue sv;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief DXBC code generator
|
|
|
|
*
|
|
|
|
* SPIR-V code generator. Implements simple micro ops that are
|
|
|
|
* generated when parsing the DXBC shader code. Some of these
|
|
|
|
* may require different implementations for each shader stage
|
|
|
|
* and are therefore implemented in a sub class.
|
|
|
|
*/
|
|
|
|
class DxbcCodeGen : public RcObject {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxbcCodeGen();
|
|
|
|
|
|
|
|
virtual ~DxbcCodeGen();
|
|
|
|
|
2017-11-16 01:30:17 +01:00
|
|
|
void dclTemps(uint32_t n);
|
|
|
|
|
|
|
|
DxbcValue defConstScalar(uint32_t v);
|
|
|
|
|
|
|
|
DxbcValue defConstVector(
|
|
|
|
uint32_t x, uint32_t y,
|
|
|
|
uint32_t z, uint32_t w);
|
|
|
|
|
|
|
|
void fnReturn();
|
2017-11-13 02:07:13 +01:00
|
|
|
|
|
|
|
DxbcPointer ptrTempReg(
|
|
|
|
uint32_t regId);
|
|
|
|
|
2017-11-16 01:30:17 +01:00
|
|
|
DxbcValue opAbs(
|
|
|
|
const DxbcValue& src);
|
|
|
|
|
2017-11-17 11:41:46 +01:00
|
|
|
DxbcValue opAdd(
|
|
|
|
const DxbcValue& a,
|
|
|
|
const DxbcValue& b);
|
|
|
|
|
|
|
|
DxbcValue opMul(
|
|
|
|
const DxbcValue& a,
|
|
|
|
const DxbcValue& b);
|
|
|
|
|
2017-11-16 01:30:17 +01:00
|
|
|
DxbcValue opNeg(
|
|
|
|
const DxbcValue& src);
|
|
|
|
|
2017-11-17 11:41:46 +01:00
|
|
|
DxbcValue opSaturate(
|
|
|
|
const DxbcValue& src);
|
|
|
|
|
2017-11-16 01:30:17 +01:00
|
|
|
DxbcValue regCast(
|
|
|
|
const DxbcValue& src,
|
|
|
|
const DxbcValueType& type);
|
|
|
|
|
|
|
|
DxbcValue regExtract(
|
|
|
|
const DxbcValue& src,
|
|
|
|
DxbcComponentMask mask);
|
|
|
|
|
|
|
|
DxbcValue regSwizzle(
|
|
|
|
const DxbcValue& src,
|
|
|
|
const DxbcComponentSwizzle& swizzle,
|
|
|
|
DxbcComponentMask mask);
|
|
|
|
|
|
|
|
DxbcValue regInsert(
|
|
|
|
const DxbcValue& dst,
|
|
|
|
const DxbcValue& src,
|
|
|
|
DxbcComponentMask mask);
|
2017-11-13 02:07:13 +01:00
|
|
|
|
|
|
|
DxbcValue regLoad(
|
2017-11-16 01:30:17 +01:00
|
|
|
const DxbcPointer& ptr);
|
2017-11-13 02:07:13 +01:00
|
|
|
|
|
|
|
void regStore(
|
2017-11-16 01:30:17 +01:00
|
|
|
const DxbcPointer& ptr,
|
|
|
|
const DxbcValue& val,
|
|
|
|
DxbcComponentMask mask);
|
2017-11-13 02:07:13 +01:00
|
|
|
|
2017-11-17 19:49:44 +01:00
|
|
|
virtual void dclInterfaceVar(
|
|
|
|
DxbcOperandType regType,
|
|
|
|
uint32_t regId,
|
|
|
|
uint32_t regDim,
|
|
|
|
DxbcComponentMask regMask,
|
|
|
|
DxbcSystemValue sv) = 0;
|
|
|
|
|
|
|
|
virtual DxbcPointer ptrInterfaceVar(
|
|
|
|
DxbcOperandType regType,
|
|
|
|
uint32_t regId) = 0;
|
|
|
|
|
|
|
|
virtual DxbcPointer ptrInterfaceVarIndexed(
|
|
|
|
DxbcOperandType regType,
|
|
|
|
uint32_t regId,
|
|
|
|
const DxbcValue& index) = 0;
|
|
|
|
|
2017-11-13 00:22:52 +01:00
|
|
|
virtual Rc<DxvkShader> finalize() = 0;
|
|
|
|
|
|
|
|
static Rc<DxbcCodeGen> create(
|
|
|
|
const DxbcProgramVersion& version);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
constexpr static uint32_t PerVertex_Position = 0;
|
|
|
|
constexpr static uint32_t PerVertex_PointSize = 1;
|
|
|
|
constexpr static uint32_t PerVertex_CullDist = 2;
|
|
|
|
constexpr static uint32_t PerVertex_ClipDist = 3;
|
|
|
|
|
|
|
|
SpirvModule m_module;
|
|
|
|
|
|
|
|
std::vector<uint32_t> m_entryPointInterfaces;
|
|
|
|
uint32_t m_entryPointId = 0;
|
|
|
|
|
|
|
|
std::vector<DxbcPointer> m_rRegs;
|
|
|
|
|
|
|
|
uint32_t defScalarType(
|
|
|
|
DxbcScalarType type);
|
|
|
|
|
|
|
|
uint32_t defValueType(
|
|
|
|
const DxbcValueType& type);
|
|
|
|
|
|
|
|
uint32_t defPointerType(
|
|
|
|
const DxbcPointerType& type);
|
|
|
|
|
|
|
|
uint32_t defPerVertexBlock();
|
|
|
|
|
2017-11-16 01:30:17 +01:00
|
|
|
DxbcPointer defVar(
|
|
|
|
const DxbcValueType& type,
|
|
|
|
spv::StorageClass storageClass);
|
|
|
|
|
2017-11-13 00:22:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|