[dxbc] Implemented derivatives

This commit is contained in:
Philip Rebohle 2017-12-19 20:26:05 +01:00
parent 342e99a11c
commit d1720c0c52
7 changed files with 196 additions and 23 deletions

View File

@ -74,6 +74,9 @@ namespace dxvk {
case DxbcInstClass::VectorCmp:
return this->emitVectorCmp(ins);
case DxbcInstClass::VectorDeriv:
return this->emitVectorDeriv(ins);
case DxbcInstClass::VectorDot:
return this->emitVectorDot(ins);
@ -981,6 +984,50 @@ namespace dxvk {
}
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,

View File

@ -305,6 +305,9 @@ namespace dxvk {
void emitVectorCmp(
const DxbcShaderInstruction& ins);
void emitVectorDeriv(
const DxbcShaderInstruction& ins);
void emitVectorDot(
const DxbcShaderInstruction& ins);

View File

@ -42,9 +42,15 @@ namespace dxvk {
/* Default */
{ },
/* 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::Float32 },
@ -457,13 +463,25 @@ namespace dxvk {
/* BufInfo */
{ },
/* 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 */
{ },
/* Gather4Po */

View File

@ -36,6 +36,7 @@ namespace dxvk {
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

View File

@ -59,12 +59,14 @@ namespace dxvk {
m_memory(memory),
m_mapPtr(mapPtr),
m_size (size) {
TRACE(this, heap, size);
// Mark the entire chunk as free
m_freeList.push_back(FreeSlice { 0, size });
}
DxvkMemoryChunk::~DxvkMemoryChunk() {
TRACE(this);
m_heap->freeDeviceMemory(m_memory);
}

View File

@ -641,6 +641,19 @@ namespace dxvk {
}
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::opConvertFtoS(
uint32_t resultType,
uint32_t operand) {
@ -693,19 +706,6 @@ namespace dxvk {
}
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::opCompositeConstruct(
uint32_t resultType,
uint32_t valueCount,
@ -760,6 +760,84 @@ namespace dxvk {
}
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::opVectorShuffle(
uint32_t resultType,
uint32_t vectorLeft,

View File

@ -236,6 +236,10 @@ namespace dxvk {
uint32_t operand1,
uint32_t operand2);
uint32_t opNot(
uint32_t resultType,
uint32_t operand);
uint32_t opConvertFtoS(
uint32_t resultType,
uint32_t operand);
@ -252,10 +256,6 @@ namespace dxvk {
uint32_t resultType,
uint32_t operand);
uint32_t opNot(
uint32_t resultType,
uint32_t operand);
uint32_t opCompositeConstruct(
uint32_t resultType,
uint32_t valueCount,
@ -274,6 +274,30 @@ namespace dxvk {
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 opVectorShuffle(
uint32_t resultType,
uint32_t vectorLeft,