Skip to content

Commit

Permalink
[dxso] Implement TexDepth
Browse files Browse the repository at this point in the history
  • Loading branch information
DadSchoorse authored and misyltoad committed Aug 12, 2021
1 parent 7acbd0f commit a2330b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/dxso/dxso_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ namespace dxvk {
return this->emitTextureSample(ctx);
case DxsoOpcode::TexKill:
return this->emitTextureKill(ctx);
case DxsoOpcode::TexDepth:
return this->emitTextureDepth(ctx);

case DxsoOpcode::TexM3x3Pad:
case DxsoOpcode::TexM3x2Pad:
Expand Down Expand Up @@ -3055,6 +3057,30 @@ void DxsoCompiler::emitControlFlowGenericLoop(
}
}

void DxsoCompiler::emitTextureDepth(const DxsoInstructionContext& ctx) {
const uint32_t fType = m_module.defFloatType(32);

DxsoRegMask srcMask(true, true, false, false);
uint32_t r5 = emitRegisterLoad(ctx.src[0], srcMask).id;
uint32_t x = 0;
uint32_t y = 1;

uint32_t xValue = m_module.opCompositeExtract(fType, r5, 1, &x);
uint32_t yValue = m_module.opCompositeExtract(fType, r5, 1, &y);

// The docs say if yValue is 0 the result is 1.0 but native drivers return
// 0 for xValue <= 0. So we don't have to do anything special since -INF and
// NAN get clamped to 0 at the end of the shader.
uint32_t result = m_module.opFDiv(fType, xValue, yValue);

DxsoBaseRegister depth;
depth.id = { DxsoRegisterType::DepthOut, 0 };

DxsoRegisterPointer depthPtr = emitGetOperandPtr(depth, nullptr);

m_module.opStore(depthPtr.id, result);
}


uint32_t DxsoCompiler::emitSample(
bool projected,
Expand Down
1 change: 1 addition & 0 deletions src/dxso/dxso_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ namespace dxvk {
void emitTexCoord(const DxsoInstructionContext& ctx);
void emitTextureSample(const DxsoInstructionContext& ctx);
void emitTextureKill(const DxsoInstructionContext& ctx);
void emitTextureDepth(const DxsoInstructionContext& ctx);

uint32_t emitSample(
bool projected,
Expand Down

0 comments on commit a2330b8

Please sign in to comment.