Skip to content

Commit

Permalink
Fix static check error (3)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaojbao committed Oct 31, 2024
1 parent b86d36b commit bc32393
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions lgc/util/RegStackUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,47 @@ static const struct {

static const MsgPackScanner::Spec msgPackScannerSpec(&items);

template <typename T> class OptionalPOD {
template <typename T> class OptionalPod {
public:
T &value() {
assert(haveValue);
return val;
assert(m_haveValue);
return m_value;
}

const T &value() const {
assert(haveValue);
return val;
assert(m_haveValue);
return m_value;
}

T value_or(T other) const { return (haveValue ? val : other); }
T value_or(T other) const { return (m_haveValue ? m_value : other); }

bool hasValue() const { return haveValue; }
bool hasValue() const { return m_haveValue; }

void operator=(const T other) {
val = other;
haveValue = true;
void operator=(const T &other) {
m_value = other;
m_haveValue = true;
}

explicit operator bool() const { return m_haveValue; }

friend raw_ostream &operator<<(raw_ostream &stream, const OptionalPod<T> t) {
if (t.hasValue()) {
return stream << t.value();
}
return stream << "no value";
}

private:
T val = {};
bool haveValue = false;
T m_value = {};
bool m_haveValue = false;
};

// Struct for reg/stack usage.
struct Usage {
unsigned maxRecursionDepth;
unsigned callableShaderCount;
unsigned backendStackSize;
OptionalPOD<unsigned> frontendStackSize;
OptionalPod<unsigned> frontendStackSize;
unsigned stackFrameSizeInBytes;
unsigned scratchMemorySize;
unsigned ldsSize;
Expand All @@ -131,7 +140,7 @@ struct Usage {
stream << " maxRecursionDepth " << usage.maxRecursionDepth << "\n"
<< " callableShaderCount " << usage.callableShaderCount << "\n"
<< " backendStackSize " << usage.backendStackSize << "\n"
<< " frontendStackSize " << usage.frontendStackSize.value() << "\n"
<< " frontendStackSize " << usage.frontendStackSize << "\n"
<< " stackFrameSizeInBytes " << usage.stackFrameSizeInBytes << "\n"
<< " scratchMemorySize " << usage.scratchMemorySize << "\n"
<< " ldsSize " << usage.ldsSize << "\n"
Expand Down Expand Up @@ -344,7 +353,7 @@ void RegStackUsageImpl::merge(const RegStackUsageImpl &shaderUsage) {
// For backend stack usage (scratch used within a func in continuations) and frontend stack usage (CPS stack),
// take the maximum of multiple modules.
m_usage.backendStackSize = std::max(m_usage.backendStackSize, shaderUsage.m_usage.backendStackSize);
if (m_usage.frontendStackSize.hasValue() || shaderUsage.m_usage.frontendStackSize.hasValue()) {
if (m_usage.frontendStackSize || shaderUsage.m_usage.frontendStackSize) {
m_usage.frontendStackSize =
std::max(m_usage.frontendStackSize.value_or(0), shaderUsage.m_usage.frontendStackSize.value_or(0));
}
Expand Down Expand Up @@ -386,7 +395,7 @@ void RegStackUsageImpl::finalize(unsigned frontendGlobalAlignment) {
#ifndef NDEBUG
m_finalized = true;
#endif
if (m_usage.frontendStackSize.hasValue()) {
if (m_usage.frontendStackSize) {
// Continuations support.
// Currently this uses a universal whole-pipeline frontendCallDepth and multiplies it in to frontendStackSize.
// The calculation could be made more sophisticated by:
Expand Down Expand Up @@ -438,7 +447,7 @@ void RegStackUsageImpl::finalize(unsigned frontendGlobalAlignment) {
// @param startOffset : Start offset of the ELF in the buffer
//
void RegStackUsageImpl::updateAndWrite(const Usage &usage, SmallVectorImpl<char> &elfBuffer, size_t startOffset) {
if (usage.frontendStackSize.hasValue()) {
if (usage.frontendStackSize) {
// Set backendStackSize even if 0, otherwise PAL gives the driver a junk value.
m_msgPackScanner.set(items.csBackendStackSize, usage.backendStackSize);
m_msgPackScanner.set(items.csFrontendStackSize, usage.frontendStackSize.value());
Expand Down

0 comments on commit bc32393

Please sign in to comment.