Skip to content

Commit

Permalink
Merge branch 'dev/adunn/expose_ctab' into 'main'
Browse files Browse the repository at this point in the history
Expose DXSO CTAB info to DXVK

See merge request lightspeedrtx/dxvk-remix-nv!727
  • Loading branch information
AlexDunn committed Apr 10, 2024
2 parents 72d83c3 + 25ff36b commit 9822a2f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 14 deletions.
45 changes: 43 additions & 2 deletions src/dxso/dxso_ctab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace dxvk {

DxsoCtab::DxsoCtab(DxsoReader& reader, uint32_t commentTokenCount) {
const char* pStart = reader.currentPtr();

m_size = reader.readu32();

if (m_size != sizeof(DxsoCtab))
if (m_size != ctabHeaderSize)
throw DxvkError("DxsoCtab: ctab size invalid");

m_creator = reader.readu32();
Expand All @@ -14,6 +16,45 @@ namespace dxvk {
m_constantInfo = reader.readu32();
m_flags = reader.readu32();
m_target = reader.readu32();
}

reader.skip(m_constantInfo - ctabHeaderSize);

struct ConstantInfo {
uint32_t Name; // LPCSTR offset
uint16_t RegisterSet; // D3DXREGISTER_SET
uint16_t RegisterIndex; // register number
uint16_t RegisterCount; // number of registers
uint16_t Reserved; // reserved
uint32_t TypeInfo; // D3DXSHADER_TYPEINFO offset
uint32_t DefaultValue; // offset of default value
};

struct TypeInfo {
uint16_t Class; // D3DXPARAMETER_CLASS
uint16_t Type; // D3DXPARAMETER_TYPE
uint16_t Rows; // number of rows (matrices)
uint16_t Columns; // number of columns (vectors and matrices)
uint16_t Elements; // array dimension
uint16_t StructMembers; // number of struct members
uint32_t StructMemberInfo; // D3DXSHADER_STRUCTMEMBERINFO[Members] offset
};

for (uint32_t j = 0; j < m_constants; j++) {
ConstantInfo info;
info.Name = reader.readu32();
info.RegisterSet = reader.readu16();
info.RegisterIndex = reader.readu16();
info.RegisterCount = reader.readu16();
info.Reserved = reader.readu16();
info.TypeInfo = reader.readu32();
info.DefaultValue = reader.readu32();

Constant constant;
constant.name = std::string(pStart + info.Name);
constant.registerIndex = info.RegisterIndex;
constant.registerCount = info.RegisterCount;

m_constantData.push_back(constant);
}
}
}
16 changes: 12 additions & 4 deletions src/dxso/dxso_ctab.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,32 @@ namespace dxvk {
/**
* \brief DXSO CTAB
*
* Stores meta information about the shader
* Stores meta information about the shader constant table
*/
class DxsoCtab : public RcObject {
class DxsoCtab {

public:
DxsoCtab() = default;

DxsoCtab(DxsoReader& reader, uint32_t commentTokenCount);

private:
inline static const uint32_t ctabHeaderSize = 0x1c;

uint32_t m_size;
uint32_t m_size = 0;
uint32_t m_creator;
uint32_t m_version;
uint32_t m_constants;
uint32_t m_constantInfo;
uint32_t m_flags;
uint32_t m_target;

struct Constant {
std::string name;
uint32_t registerIndex;
uint32_t registerCount;
};

std::vector<Constant> m_constantData;
};

}
10 changes: 9 additions & 1 deletion src/dxso/dxso_decoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "dxso_decoder.h"

#include "dxso_tables.h"
#include "dxso_ctab.h"

namespace dxvk {

Expand Down Expand Up @@ -224,9 +225,16 @@ namespace dxvk {
return true;

case DxsoOpcode::Comment:
{
// NV-DXVK start: expose CTAB data
DxsoReader reader((char*) iter.ptrAt(0));
if (reader.readTag() == DxbcTag("CTAB")) {
m_ctab = DxsoCtab(reader, tokenLength);
}
// NV-DXVK end
iter = iter.skip(tokenLength);
return true;

}
default: {
uint32_t sourceIdx = 0;
for (uint32_t i = 0; i < tokenLength; i++) {
Expand Down
11 changes: 10 additions & 1 deletion src/dxso/dxso_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "dxso_common.h"
#include "dxso_enums.h"
#include "dxso_code.h"
#include "dxso_ctab.h"

namespace dxvk {

Expand Down Expand Up @@ -232,6 +233,12 @@ namespace dxvk {
return m_programInfo;
}

// NV-DXVK start: expose CTAB data
const DxsoCtab& getCtabInfo() const {
return m_ctab;
}
// NV-DXVK end

/**
* \brief Decodes an instruction
*
Expand Down Expand Up @@ -268,7 +275,9 @@ namespace dxvk {
const DxsoProgramInfo& m_programInfo;

DxsoInstructionContext m_ctx;

// NV-DXVK start: expose CTAB data
DxsoCtab m_ctab;
// NV-DXVK end
};

std::ostream& operator << (std::ostream& os, DxsoUsage usage);
Expand Down
13 changes: 11 additions & 2 deletions src/dxso/dxso_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ namespace dxvk {

DxsoAnalyzer analyzer(info);

this->runAnalyzer(analyzer, m_code.iter());
// NV-DXVK start: expose CTAB data
this->runAnalyzer(analyzer, m_code.iter(), m_ctab);
// NV-DXVK end

return info;
}
Expand Down Expand Up @@ -48,9 +50,12 @@ namespace dxvk {
return compiler->compile();
}

// NV-DXVK start: expose CTAB data
void DxsoModule::runAnalyzer(
DxsoAnalyzer& analyzer,
DxsoCodeIter iter) const {
DxsoCodeIter iter,
DxsoCtab& ctabInfo) const {
// NV-DXVK end
DxsoCodeIter start = iter;

DxsoDecodeContext decoder(m_header.info());
Expand All @@ -75,6 +80,10 @@ namespace dxvk {
tokenCount += 1;

analyzer.finalize(tokenCount);

// NV-DXVK start: expose CTAB data
ctabInfo = decoder.getCtabInfo();
// NV-DXVK end
}

void DxsoModule::runCompiler(
Expand Down
9 changes: 7 additions & 2 deletions src/dxso/dxso_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ namespace dxvk {
// NV-DXVK start: expose shader outputs for vertex capture
const DxsoIsgn& osgn() {
return m_osgn;
}

const DxsoCtab& ctab() {
return m_ctab;
}
// NV-DXVK end

Expand All @@ -76,7 +80,8 @@ namespace dxvk {

void runAnalyzer(
DxsoAnalyzer& analyzer,
DxsoCodeIter iter) const;
DxsoCodeIter iter,
DxsoCtab& ctabInfo) const;

DxsoHeader m_header;
DxsoCode m_code;
Expand All @@ -91,7 +96,7 @@ namespace dxvk {
DxsoShaderMetaInfo m_meta;
uint32_t m_maxDefinedConst;
DxsoDefinedConstants m_constants;

DxsoCtab m_ctab;
};

}
5 changes: 3 additions & 2 deletions src/dxso/dxso_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace dxvk {
}

auto readu32() { return this->readNum<uint32_t> (); }
// NV-DXVK start: expose CTAB data
auto readu16() { return this->readNum<uint16_t> (); }
// NV-DXVK end
auto readf32() { return this->readNum<float> (); }

DxbcTag readTag();
Expand Down Expand Up @@ -54,7 +57,5 @@ namespace dxvk {
this->read(&result, sizeof(result));
return result;
}

};

}

0 comments on commit 9822a2f

Please sign in to comment.