2017-11-01 00:01:40 +01:00
|
|
|
#include "dxbc_chunk_isgn.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-05-31 22:13:08 +02:00
|
|
|
DxbcIsgn::DxbcIsgn(DxbcReader reader, DxbcTag tag) {
|
2017-11-01 00:01:40 +01:00
|
|
|
uint32_t elementCount = reader.readu32();
|
|
|
|
reader.skip(sizeof(uint32_t));
|
|
|
|
|
|
|
|
std::array<DxbcScalarType, 4> componentTypes = {
|
|
|
|
DxbcScalarType::Uint32, DxbcScalarType::Uint32,
|
|
|
|
DxbcScalarType::Sint32, DxbcScalarType::Float32,
|
|
|
|
};
|
2019-01-12 15:17:51 +01:00
|
|
|
|
|
|
|
// https://github.com/DarkStarSword/3d-fixes/blob/master/dx11shaderanalyse.py#L101
|
|
|
|
bool hasStream = (tag == "ISG1") || (tag == "OSG1") || (tag == "PSG1") || (tag == "OSG5");
|
|
|
|
bool hasPrecision = (tag == "ISG1") || (tag == "OSG1") || (tag == "PSG1");
|
2017-11-01 00:01:40 +01:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < elementCount; i++) {
|
|
|
|
DxbcSgnEntry entry;
|
2019-01-12 15:17:51 +01:00
|
|
|
entry.streamId = hasStream ? reader.readu32() : 0;
|
2017-11-01 00:01:40 +01:00
|
|
|
entry.semanticName = reader.clone(reader.readu32()).readString();
|
|
|
|
entry.semanticIndex = reader.readu32();
|
|
|
|
entry.systemValue = static_cast<DxbcSystemValue>(reader.readu32());
|
|
|
|
entry.componentType = componentTypes.at(reader.readu32());
|
|
|
|
entry.registerId = reader.readu32();
|
|
|
|
entry.componentMask = bit::extract(reader.readu32(), 0, 3);
|
2018-05-31 22:13:08 +02:00
|
|
|
|
2019-01-12 15:17:51 +01:00
|
|
|
if (hasPrecision)
|
|
|
|
reader.readu32();
|
|
|
|
|
2017-11-01 00:01:40 +01:00
|
|
|
m_entries.push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxbcIsgn::~DxbcIsgn() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-07 12:45:02 +01:00
|
|
|
|
2018-01-01 23:31:01 +01:00
|
|
|
const DxbcSgnEntry* DxbcIsgn::findByRegister(uint32_t registerId) const {
|
|
|
|
for (auto e = this->begin(); e != this->end(); e++) {
|
|
|
|
if (e->registerId == registerId)
|
|
|
|
return &(*e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-07 12:45:02 +01:00
|
|
|
const DxbcSgnEntry* DxbcIsgn::find(
|
|
|
|
const std::string& semanticName,
|
2018-06-23 20:13:00 +02:00
|
|
|
uint32_t semanticIndex,
|
|
|
|
uint32_t streamId) const {
|
2017-12-07 12:45:02 +01:00
|
|
|
for (auto e = this->begin(); e != this->end(); e++) {
|
2017-12-30 15:30:31 +01:00
|
|
|
if (e->semanticIndex == semanticIndex
|
2018-06-23 20:13:00 +02:00
|
|
|
&& e->streamId == streamId
|
2017-12-30 15:30:31 +01:00
|
|
|
&& compareSemanticNames(semanticName, e->semanticName))
|
2017-12-07 12:45:02 +01:00
|
|
|
return &(*e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-30 15:30:31 +01:00
|
|
|
|
2018-07-01 15:24:21 +02:00
|
|
|
DxbcRegMask DxbcIsgn::regMask(
|
|
|
|
uint32_t registerId) const {
|
|
|
|
DxbcRegMask mask;
|
|
|
|
|
|
|
|
for (auto e = this->begin(); e != this->end(); e++) {
|
|
|
|
if (e->registerId == registerId)
|
|
|
|
mask |= e->componentMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-26 17:11:49 +01:00
|
|
|
uint32_t DxbcIsgn::maxRegisterCount() const {
|
|
|
|
uint32_t result = 0;
|
|
|
|
for (auto e = this->begin(); e != this->end(); e++)
|
|
|
|
result = std::max(result, e->registerId + 1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-10 23:57:37 +02:00
|
|
|
void DxbcIsgn::printEntries() const {
|
|
|
|
for (auto entry = this->begin(); entry != this->end(); entry++) {
|
|
|
|
Logger::debug(str::format("SGN Entry:\n\t",
|
|
|
|
"semanticName: ", entry->semanticName, "\n\t",
|
|
|
|
"semanticIndex: ", entry->semanticIndex, "\n\t",
|
|
|
|
"registerId: ", entry->registerId, "\n\t",
|
|
|
|
"componentMask: ", entry->componentMask.maskString(), "\n\t",
|
|
|
|
"componentType: ", entry->componentType, "\n\t",
|
|
|
|
"systemValue: ", entry->systemValue, "\n\t",
|
|
|
|
"streamId: ", entry->streamId, "\n",
|
|
|
|
"\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 17:11:49 +01:00
|
|
|
|
2017-12-30 15:30:31 +01:00
|
|
|
bool DxbcIsgn::compareSemanticNames(
|
2022-08-10 14:11:47 +02:00
|
|
|
const std::string& a, const std::string& b) {
|
2017-12-30 15:30:31 +01:00
|
|
|
if (a.size() != b.size())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < a.size(); i++) {
|
2022-08-10 14:11:47 +02:00
|
|
|
char ac = a[i];
|
|
|
|
char bc = b[i];
|
|
|
|
|
|
|
|
if (ac != bc) {
|
|
|
|
if (ac >= 'A' && ac <= 'Z') ac += 'a' - 'A';
|
|
|
|
if (bc >= 'A' && bc <= 'Z') bc += 'a' - 'A';
|
|
|
|
|
|
|
|
if (ac != bc)
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-30 15:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-10 23:57:37 +02:00
|
|
|
}
|