mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Refactor ShaderVariable use and non-32-bit precision. Closes #2466
This commit is contained in:
@@ -1044,22 +1044,40 @@ static void FillShaderVarData(ShaderVariable &var, const ShaderConstant &elem, c
|
||||
|
||||
src++;
|
||||
|
||||
if(var.type == VarType::Double)
|
||||
var.value.f64v[dst] = o.toDouble();
|
||||
if(var.type == VarType::Float || var.type == VarType::Half)
|
||||
var.value.f32v[dst] = o.toFloat();
|
||||
else if(var.type == VarType::ULong)
|
||||
var.value.u64v[dst] = o.toULongLong();
|
||||
else if(var.type == VarType::SLong)
|
||||
var.value.s64v[dst] = o.toLongLong();
|
||||
else if(var.type == VarType::Bool)
|
||||
var.value.u32v[dst] = o.toBool() ? 1 : 0;
|
||||
else if(var.type == VarType::UInt || var.type == VarType::UShort || var.type == VarType::UByte)
|
||||
var.value.u32v[dst] = o.toUInt();
|
||||
else if(var.type == VarType::SInt || var.type == VarType::SShort || var.type == VarType::SByte)
|
||||
var.value.s32v[dst] = o.toInt();
|
||||
else
|
||||
var.value.f32v[dst] = o.toFloat();
|
||||
switch(var.type)
|
||||
{
|
||||
case VarType::Float: var.value.f32v[dst] = o.toFloat(); break;
|
||||
case VarType::Double: var.value.f64v[dst] = o.toDouble(); break;
|
||||
case VarType::Half: var.value.f16v[dst] = rdhalf::make(o.toFloat()); break;
|
||||
case VarType::Bool: var.value.u32v[dst] = o.toBool() ? 1 : 0; break;
|
||||
case VarType::ULong: var.value.u64v[dst] = o.toULongLong(); break;
|
||||
case VarType::UInt: var.value.u32v[dst] = o.toUInt(); break;
|
||||
case VarType::UShort: var.value.u16v[dst] = o.toUInt() & 0xffff; break;
|
||||
case VarType::UByte: var.value.u8v[dst] = o.toUInt() & 0xff; break;
|
||||
case VarType::SLong: var.value.s64v[dst] = o.toLongLong(); break;
|
||||
case VarType::SInt:
|
||||
var.value.s32v[dst] = o.toInt();
|
||||
break;
|
||||
break;
|
||||
case VarType::SShort:
|
||||
var.value.u16v[dst] = (int16_t)qBound((int)INT16_MIN, o.toInt(), (int)INT16_MAX);
|
||||
break;
|
||||
case VarType::SByte:
|
||||
var.value.u8v[dst] = (int8_t)qBound((int)INT8_MIN, o.toInt(), (int)INT8_MAX);
|
||||
break;
|
||||
case VarType::GPUPointer:
|
||||
// treat this as a 64-bit unsigned integer
|
||||
var.value.u64v[dst] = o.toULongLong();
|
||||
break;
|
||||
case VarType::ConstantBlock:
|
||||
case VarType::ReadOnlyResource:
|
||||
case VarType::ReadWriteResource:
|
||||
case VarType::Sampler:
|
||||
case VarType::Unknown:
|
||||
qCritical() << "Unexpected variable type" << ToQStr(var.type) << "in variable"
|
||||
<< (QString)var.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1469,7 +1487,7 @@ QVariantList GetVariants(ResourceFormat format, const ShaderConstantDescriptor &
|
||||
else if(format.compByteWidth == 4)
|
||||
ret.push_back(readObj<float>(data, end, ok));
|
||||
else if(format.compByteWidth == 2)
|
||||
ret.push_back(RENDERDOC_HalfToFloat(readObj<uint16_t>(data, end, ok)));
|
||||
ret.push_back((float)rdhalf::make(readObj<uint16_t>(data, end, ok)));
|
||||
}
|
||||
else if(format.compType == CompType::SInt)
|
||||
{
|
||||
@@ -1638,36 +1656,67 @@ QString RowString(const ShaderVariable &v, uint32_t row, VarType type)
|
||||
if(v.type == VarType::GPUPointer)
|
||||
return ToQStr(v.GetPointer());
|
||||
|
||||
if(type == VarType::Double)
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.f64v[row * v.columns + 0],
|
||||
v.value.f64v[row * v.columns + 1], v.value.f64v[row * v.columns + 2],
|
||||
v.value.f64v[row * v.columns + 3]);
|
||||
else if(type == VarType::SLong)
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.s64v[row * v.columns + 0],
|
||||
v.value.s64v[row * v.columns + 1], v.value.s64v[row * v.columns + 2],
|
||||
v.value.s64v[row * v.columns + 3]);
|
||||
else if(type == VarType::ULong)
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.u64v[row * v.columns + 0],
|
||||
v.value.u64v[row * v.columns + 1], v.value.u64v[row * v.columns + 2],
|
||||
v.value.u64v[row * v.columns + 3]);
|
||||
else if(type == VarType::SInt || type == VarType::SShort || type == VarType::SByte)
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.s32v[row * v.columns + 0],
|
||||
v.value.s32v[row * v.columns + 1], v.value.s32v[row * v.columns + 2],
|
||||
v.value.s32v[row * v.columns + 3]);
|
||||
else if(type == VarType::UInt || type == VarType::UShort || type == VarType::UByte)
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.u32v[row * v.columns + 0],
|
||||
v.value.u32v[row * v.columns + 1], v.value.u32v[row * v.columns + 2],
|
||||
v.value.u32v[row * v.columns + 3]);
|
||||
else if(type == VarType::Bool)
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex,
|
||||
v.value.u32v[row * v.columns + 0] ? true : false,
|
||||
v.value.u32v[row * v.columns + 1] ? true : false,
|
||||
v.value.u32v[row * v.columns + 2] ? true : false,
|
||||
v.value.u32v[row * v.columns + 3] ? true : false);
|
||||
else
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.f32v[row * v.columns + 0],
|
||||
v.value.f32v[row * v.columns + 1], v.value.f32v[row * v.columns + 2],
|
||||
v.value.f32v[row * v.columns + 3]);
|
||||
switch(type)
|
||||
{
|
||||
case VarType::Float:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.f32v[row * v.columns + 0],
|
||||
v.value.f32v[row * v.columns + 1], v.value.f32v[row * v.columns + 2],
|
||||
v.value.f32v[row * v.columns + 3]);
|
||||
case VarType::Double:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.f64v[row * v.columns + 0],
|
||||
v.value.f64v[row * v.columns + 1], v.value.f64v[row * v.columns + 2],
|
||||
v.value.f64v[row * v.columns + 3]);
|
||||
case VarType::Half:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.f16v[row * v.columns + 0],
|
||||
v.value.f16v[row * v.columns + 1], v.value.f16v[row * v.columns + 2],
|
||||
v.value.f16v[row * v.columns + 3]);
|
||||
case VarType::Bool:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex,
|
||||
v.value.u32v[row * v.columns + 0] ? true : false,
|
||||
v.value.u32v[row * v.columns + 1] ? true : false,
|
||||
v.value.u32v[row * v.columns + 2] ? true : false,
|
||||
v.value.u32v[row * v.columns + 3] ? true : false);
|
||||
case VarType::ULong:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.u64v[row * v.columns + 0],
|
||||
v.value.u64v[row * v.columns + 1], v.value.u64v[row * v.columns + 2],
|
||||
v.value.u64v[row * v.columns + 3]);
|
||||
case VarType::UInt:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.u32v[row * v.columns + 0],
|
||||
v.value.u32v[row * v.columns + 1], v.value.u32v[row * v.columns + 2],
|
||||
v.value.u32v[row * v.columns + 3]);
|
||||
case VarType::UShort:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.u16v[row * v.columns + 0],
|
||||
v.value.u16v[row * v.columns + 1], v.value.u16v[row * v.columns + 2],
|
||||
v.value.u16v[row * v.columns + 3]);
|
||||
case VarType::UByte:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.u8v[row * v.columns + 0],
|
||||
v.value.u8v[row * v.columns + 1], v.value.u8v[row * v.columns + 2],
|
||||
v.value.u8v[row * v.columns + 3]);
|
||||
case VarType::SLong:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.s64v[row * v.columns + 0],
|
||||
v.value.s64v[row * v.columns + 1], v.value.s64v[row * v.columns + 2],
|
||||
v.value.s64v[row * v.columns + 3]);
|
||||
case VarType::SInt:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.s32v[row * v.columns + 0],
|
||||
v.value.s32v[row * v.columns + 1], v.value.s32v[row * v.columns + 2],
|
||||
v.value.s32v[row * v.columns + 3]);
|
||||
case VarType::SShort:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.s16v[row * v.columns + 0],
|
||||
v.value.s16v[row * v.columns + 1], v.value.s16v[row * v.columns + 2],
|
||||
v.value.s16v[row * v.columns + 3]);
|
||||
case VarType::SByte:
|
||||
return RowValuesToString((int)v.columns, v.displayAsHex, v.value.s8v[row * v.columns + 0],
|
||||
v.value.s8v[row * v.columns + 1], v.value.s8v[row * v.columns + 2],
|
||||
v.value.s8v[row * v.columns + 3]);
|
||||
case VarType::GPUPointer: return ToQStr(v.GetPointer());
|
||||
case VarType::ConstantBlock:
|
||||
case VarType::ReadOnlyResource:
|
||||
case VarType::ReadWriteResource:
|
||||
case VarType::Sampler:
|
||||
case VarType::Unknown: break;
|
||||
}
|
||||
|
||||
return lit("???");
|
||||
}
|
||||
|
||||
QString VarString(const ShaderVariable &v)
|
||||
|
||||
@@ -228,6 +228,7 @@ struct Formatter
|
||||
static void shutdown();
|
||||
|
||||
static QString Format(double f, bool hex = false);
|
||||
static QString Format(rdhalf f, bool hex = false) { return Format((float)f, hex); }
|
||||
static QString HumanFormat(uint64_t u);
|
||||
static QString Format(uint64_t u, bool hex = false)
|
||||
{
|
||||
|
||||
@@ -364,6 +364,25 @@ struct TypeConversion<double, false>
|
||||
static PyObject *ConvertToPy(const double &in) { return PyFloat_FromDouble(in); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TypeConversion<rdhalf, false>
|
||||
{
|
||||
static int ConvertFromPy(PyObject *in, rdhalf &out)
|
||||
{
|
||||
if(!PyFloat_Check(in))
|
||||
return SWIG_TypeError;
|
||||
|
||||
out.set(float(PyFloat_AsDouble(in)));
|
||||
|
||||
if(PyErr_Occurred())
|
||||
return SWIG_OverflowError;
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
static PyObject *ConvertToPy(const rdhalf &in) { return PyFloat_FromDouble((float)in); }
|
||||
};
|
||||
|
||||
// partial specialisation for enums, we just convert as their underlying type,
|
||||
// whatever integer size that happens to be
|
||||
template <typename T>
|
||||
|
||||
@@ -100,6 +100,7 @@ VA_IGNORE_REST_OF_FILE
|
||||
%ignore rdcfixedarray::operator[];
|
||||
%ignore rdcliteral;
|
||||
%ignore rdcpair;
|
||||
%ignore rdhalf;
|
||||
%ignore bytebuf;
|
||||
|
||||
// special handling for RENDERDOC_GetDefaultCaptureOptions to transform output parameter to a return value
|
||||
@@ -331,6 +332,7 @@ TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, ResourceId, 8)
|
||||
TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, bool, 4)
|
||||
TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, bool, 8)
|
||||
TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, float, 16)
|
||||
TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, rdhalf, 16)
|
||||
TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, int32_t, 16)
|
||||
TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, uint32_t, 16)
|
||||
TEMPLATE_FIXEDARRAY_INSTANTIATE(rdcfixedarray, double, 16)
|
||||
|
||||
Reference in New Issue
Block a user