本文整理汇总了C++中TypeDesc::numelements方法的典型用法代码示例。如果您正苦于以下问题:C++ TypeDesc::numelements方法的具体用法?C++ TypeDesc::numelements怎么用?C++ TypeDesc::numelements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeDesc
的用法示例。
在下文中一共展示了TypeDesc::numelements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attribute
bool
oiio_attribute_tuple_typed (const std::string &name,
TypeDesc type, tuple &obj)
{
if (type.basetype == TypeDesc::INT) {
std::vector<int> vals;
py_to_stdvector (vals, obj);
if (vals.size() == type.numelements()*type.aggregate)
return OIIO::attribute (name, type, &vals[0]);
return false;
}
if (type.basetype == TypeDesc::FLOAT) {
std::vector<float> vals;
py_to_stdvector (vals, obj);
if (vals.size() == type.numelements()*type.aggregate)
return OIIO::attribute (name, type, &vals[0]);
return false;
}
if (type.basetype == TypeDesc::STRING) {
std::vector<std::string> vals;
py_to_stdvector (vals, obj);
if (vals.size() == type.numelements()*type.aggregate) {
std::vector<ustring> u;
for (size_t i = 0, e = vals.size(); i < e; ++i)
u.push_back (ustring(vals[i]));
return OIIO::attribute (name, type, &u[0]);
}
return false;
}
return false;
}
示例2: name
void
OSOReaderToMaster::symbol (SymType symtype, TypeSpec typespec, const char *name_)
{
ustring name(name_);
Symbol sym (name, typespec, symtype);
TypeDesc t = typespec.simpletype();
int nvals = t.aggregate * (t.is_unsized_array() ? 1 : t.numelements());
if (sym.symtype() == SymTypeParam || sym.symtype() == SymTypeOutputParam) {
// Skip structs for now, they're just placeholders
if (typespec.is_structure()) {
}
else if (typespec.simpletype().basetype == TypeDesc::FLOAT) {
sym.dataoffset ((int) m_master->m_fdefaults.size());
expand (m_master->m_fdefaults, nvals);
} else if (typespec.simpletype().basetype == TypeDesc::INT) {
sym.dataoffset ((int) m_master->m_idefaults.size());
expand (m_master->m_idefaults, nvals);
} else if (typespec.simpletype().basetype == TypeDesc::STRING) {
sym.dataoffset ((int) m_master->m_sdefaults.size());
expand (m_master->m_sdefaults, nvals);
} else if (typespec.is_closure_based()) {
// Closures are pointers, so we allocate a string default taking
// adventage of their default being NULL as well.
sym.dataoffset ((int) m_master->m_sdefaults.size());
expand (m_master->m_sdefaults, nvals);
} else {
ASSERT (0 && "unexpected type");
}
}
if (sym.symtype() == SymTypeConst) {
if (typespec.simpletype().basetype == TypeDesc::FLOAT) {
sym.dataoffset ((int) m_master->m_fconsts.size());
expand (m_master->m_fconsts, nvals);
} else if (typespec.simpletype().basetype == TypeDesc::INT) {
sym.dataoffset ((int) m_master->m_iconsts.size());
expand (m_master->m_iconsts, nvals);
} else if (typespec.simpletype().basetype == TypeDesc::STRING) {
sym.dataoffset ((int) m_master->m_sconsts.size());
expand (m_master->m_sconsts, nvals);
} else {
ASSERT (0 && "unexpected type");
}
}
#if 0
// FIXME -- global_heap_offset is quite broken. But also not necessary.
// We made need to fix this later.
if (sym.symtype() == SymTypeGlobal) {
sym.dataoffset (m_shadingsys.global_heap_offset (sym.name()));
}
#endif
sym.lockgeom (m_shadingsys.lockgeom_default());
m_master->m_symbols.push_back (sym);
m_symmap[name] = int(m_master->m_symbols.size()) - 1;
// Start the index at which we add specified defaults
m_sym_default_index = 0;
}
示例3: typespec
std::ostream &
Symbol::print_vals (std::ostream &out, int maxvals) const
{
if (! data())
return out;
TypeDesc t = typespec().simpletype();
int n = std::min (int(t.aggregate * t.numelements()), maxvals);
if (t.basetype == TypeDesc::FLOAT) {
for (int j = 0; j < n; ++j)
out << (j ? " " : "") << ((float *)data())[j];
} else if (t.basetype == TypeDesc::INT) {
for (int j = 0; j < n; ++j)
out << (j ? " " : "") << ((int *)data())[j];
} else if (t.basetype == TypeDesc::STRING) {
for (int j = 0; j < n; ++j)
out << (j ? " " : "") << "\""
<< Strutil::escape_chars(((ustring *)data())[j].string())
<< "\"";
}
if (int(t.aggregate * t.numelements()) > maxvals)
out << "...";
return out;
}
示例4: if
void
BackendLLVM::llvm_generate_debug_uninit (const Opcode &op)
{
for (int i = 0; i < op.nargs(); ++i) {
Symbol &sym (*opargsym (op, i));
if (! op.argread(i))
continue;
if (sym.typespec().is_closure_based())
continue;
TypeDesc t = sym.typespec().simpletype();
if (t.basetype != TypeDesc::FLOAT && t.basetype != TypeDesc::INT &&
t.basetype != TypeDesc::STRING)
continue; // just check float, int, string based types
llvm::Value *ncheck = ll.constant (int(t.numelements() * t.aggregate));
llvm::Value *offset = ll.constant(0);
// Some special cases...
if (op.opname() == Strings::op_for && i == 0) {
// The first argument of 'for' is the condition temp, but
// note that it may not have had its initializer run yet, so
// don't generate uninit test code for it.
continue;
}
if (op.opname() == op_aref && i == 1) {
// Special case -- array assignment -- only check one element
llvm::Value *ind = llvm_load_value (*opargsym (op, 2));
llvm::Value *agg = ll.constant(t.aggregate);
offset = t.aggregate == 1 ? ind : ll.op_mul (ind, agg);
ncheck = agg;
} else if (op.opname() == op_compref && i == 1) {
// Special case -- component assignment -- only check one channel
llvm::Value *ind = llvm_load_value (*opargsym (op, 2));
offset = ind;
ncheck = ll.constant(1);
}
llvm::Value *args[] = { ll.constant(t),
llvm_void_ptr(sym),
sg_void_ptr(),
ll.constant(op.sourcefile()),
ll.constant(op.sourceline()),
ll.constant(sym.name()),
offset,
ncheck
};
ll.call_function ("osl_uninit_check", args, 8);
}
}
示例5: if
inline std::string
print_vals (const Symbol &s)
{
std::stringstream out;
TypeDesc t = s.typespec().simpletype();
int n = t.aggregate * t.numelements();
if (t.basetype == TypeDesc::FLOAT) {
for (int j = 0; j < n; ++j)
out << (j ? " " : "") << ((float *)s.data())[j];
} else if (t.basetype == TypeDesc::INT) {
for (int j = 0; j < n; ++j)
out << (j ? " " : "") << ((int *)s.data())[j];
} else if (t.basetype == TypeDesc::STRING) {
for (int j = 0; j < n; ++j)
out << (j ? " " : "") << "\"" << ((ustring *)s.data())[j] << "\"";
}
return out.str();
}
示例6: ASSERT
void
BackendLLVM::llvm_generate_debugnan (const Opcode &op)
{
for (int i = 0; i < op.nargs(); ++i) {
Symbol &sym (*opargsym (op, i));
if (! op.argwrite(i))
continue;
TypeDesc t = sym.typespec().simpletype();
if (t.basetype != TypeDesc::FLOAT)
continue; // just check float-based types
llvm::Value *ncomps = ll.constant (int(t.numelements() * t.aggregate));
llvm::Value *offset = ll.constant(0);
llvm::Value *ncheck = ncomps;
if (op.opname() == op_aassign) {
// Special case -- array assignment -- only check one element
ASSERT (i == 0 && "only arg 0 is written for aassign");
llvm::Value *ind = llvm_load_value (*opargsym (op, 1));
llvm::Value *agg = ll.constant(t.aggregate);
offset = t.aggregate == 1 ? ind : ll.op_mul (ind, agg);
ncheck = agg;
} else if (op.opname() == op_compassign) {
// Special case -- component assignment -- only check one channel
ASSERT (i == 0 && "only arg 0 is written for compassign");
llvm::Value *ind = llvm_load_value (*opargsym (op, 1));
offset = ind;
ncheck = ll.constant(1);
}
llvm::Value *args[] = { ncomps,
llvm_void_ptr(sym),
ll.constant((int)sym.has_derivs()),
sg_void_ptr(),
ll.constant(op.sourcefile()),
ll.constant(op.sourceline()),
ll.constant(sym.name()),
offset,
ncheck,
ll.constant(op.opname())
};
ll.call_function ("osl_naninf_check", args, 10);
}
}
示例7: sscanf
static void
parse_elements (string_view name, TypeDesc type, const char *type_code,
string_view value, ImageIOParameter ¶m)
{
int num_items = type.numelements() * type.aggregate;
T *data = (T*) param.data();
// Erase any leading whitespace
value.remove_prefix (value.find_first_not_of (" \t"));
for (int i = 0; i < num_items; ++i) {
// Make a temporary copy so we for sure have a 0-terminated string.
std::string temp = value;
// Grab the first value from it
sscanf (temp.c_str(), type_code, &data[i]);
// Skip the value (eat until we find a delimiter -- space, comma, tab)
value.remove_prefix (value.find_first_of (" ,\t"));
// Skip the delimiter
value.remove_prefix (value.find_first_not_of (" ,\t"));
if (value.empty())
break; // done if nothing left to parse
}
}
示例8:
void
RuntimeOptimizer::llvm_generate_debugnan (const Opcode &op)
{
for (int i = 0; i < op.nargs(); ++i) {
Symbol &sym (*opargsym (op, i));
if (! op.argwrite(i))
continue;
TypeDesc t = sym.typespec().simpletype();
if (t.basetype != TypeDesc::FLOAT)
continue; // just check float-based types
int ncomps = t.numelements() * t.aggregate;
llvm::Value *args[] = { llvm_constant(ncomps),
llvm_void_ptr(sym),
llvm_constant((int)sym.has_derivs()),
sg_void_ptr(),
llvm_constant(op.sourcefile()),
llvm_constant(op.sourceline()),
llvm_constant(sym.name()) };
llvm_call_function ("osl_naninf_check", args, 7);
}
}
示例9: inst
llvm::Function*
BackendLLVM::build_llvm_instance (bool groupentry)
{
// Make a layer function: void layer_func(ShaderGlobals*, GroupData*)
// Note that the GroupData* is passed as a void*.
std::string unique_layer_name = Strutil::format ("%s_%d", inst()->layername(), inst()->id());
ll.current_function (
ll.make_function (unique_layer_name,
!groupentry, // fastcall for non-entry layer functions
ll.type_void(), // return type
llvm_type_sg_ptr(), llvm_type_groupdata_ptr()));
// Get shader globals and groupdata pointers
m_llvm_shaderglobals_ptr = ll.current_function_arg(0); //arg_it++;
m_llvm_groupdata_ptr = ll.current_function_arg(1); //arg_it++;
llvm::BasicBlock *entry_bb = ll.new_basic_block (unique_layer_name);
m_exit_instance_block = NULL;
// Set up a new IR builder
ll.new_builder (entry_bb);
#if 0 /* helpful for debuggin */
if (llvm_debug() && groupentry)
llvm_gen_debug_printf (Strutil::format("\n\n\n\nGROUP! %s",group().name()));
if (llvm_debug())
llvm_gen_debug_printf (Strutil::format("enter layer %s %s",
inst()->layername(), inst()->shadername()));
#endif
if (shadingsys().countlayerexecs())
ll.call_function ("osl_incr_layers_executed", sg_void_ptr());
if (groupentry) {
if (m_num_used_layers > 1) {
// If this is the group entry point, clear all the "layer
// executed" bits. If it's not the group entry (but rather is
// an upstream node), then set its bit!
int sz = (m_num_used_layers + 3) & (~3); // round up to 32 bits
ll.op_memset (ll.void_ptr(layer_run_ptr(0)), 0, sz, 4 /*align*/);
}
// Group entries also need to allot space for ALL layers' params
// that are closures (to avoid weird order of layer eval problems).
for (int i = 0; i < group().nlayers(); ++i) {
ShaderInstance *gi = group()[i];
if (gi->unused())
continue;
FOREACH_PARAM (Symbol &sym, gi) {
if (sym.typespec().is_closure_based()) {
int arraylen = std::max (1, sym.typespec().arraylength());
llvm::Value *val = ll.constant_ptr(NULL, ll.type_void_ptr());
for (int a = 0; a < arraylen; ++a) {
llvm::Value *arrind = sym.typespec().is_array() ? ll.constant(a) : NULL;
llvm_store_value (val, sym, 0, arrind, 0);
}
}
}
// Unconditionally execute earlier layers that are not lazy
if (! gi->run_lazily() && i < group().nlayers()-1)
llvm_call_layer (i, true /* unconditionally run */);
}
}
// Setup the symbols
m_named_values.clear ();
BOOST_FOREACH (Symbol &s, inst()->symbols()) {
// Skip constants -- we always inline scalar constants, and for
// array constants we will just use the pointers to the copy of
// the constant that belongs to the instance.
if (s.symtype() == SymTypeConst)
continue;
// Skip structure placeholders
if (s.typespec().is_structure())
continue;
// Allocate space for locals, temps, aggregate constants
if (s.symtype() == SymTypeLocal || s.symtype() == SymTypeTemp ||
s.symtype() == SymTypeConst)
getOrAllocateLLVMSymbol (s);
// Set initial value for constants, closures, and strings that are
// not parameters.
if (s.symtype() != SymTypeParam && s.symtype() != SymTypeOutputParam &&
s.symtype() != SymTypeGlobal &&
(s.is_constant() || s.typespec().is_closure_based() ||
s.typespec().is_string_based() ||
((s.symtype() == SymTypeLocal || s.symtype() == SymTypeTemp)
&& shadingsys().debug_uninit())))
llvm_assign_initial_value (s);
// If debugnan is turned on, globals check that their values are ok
if (s.symtype() == SymTypeGlobal && shadingsys().debug_nan()) {
TypeDesc t = s.typespec().simpletype();
if (t.basetype == TypeDesc::FLOAT) { // just check float-based types
int ncomps = t.numelements() * t.aggregate;
llvm::Value *args[] = { ll.constant(ncomps), llvm_void_ptr(s),
ll.constant((int)s.has_derivs()), sg_void_ptr(),
ll.constant(ustring(inst()->shadername())),
ll.constant(0), ll.constant(s.name()),
ll.constant(0), ll.constant(ncomps),
ll.constant("<none>")
};
ll.call_function ("osl_naninf_check", args, 10);
}
//.........这里部分代码省略.........
示例10: varname
//.........这里部分代码省略.........
}
if (entrylayers.size()) {
std::vector<const char *> layers;
std::cout << "Entry layers:";
for (size_t i = 0; i < entrylayers.size(); ++i) {
ustring layername (entrylayers[i]); // convert to ustring
int layid = shadingsys->find_layer (*shadergroup, layername);
layers.push_back (layername.c_str());
entrylayer_index.push_back (layid);
std::cout << ' ' << entrylayers[i] << "(" << layid << ")";
}
std::cout << "\n";
shadingsys->attribute (shadergroup.get(), "entry_layers",
TypeDesc(TypeDesc::STRING,(int)entrylayers.size()),
&layers[0]);
}
if (extraoptions.size())
shadingsys->attribute ("options", extraoptions);
ShadingContext *ctx = shadingsys->get_context ();
// Because we can only call find_symbol or get_symbol on something that
// has been set up to shade (or executed), we call execute() but tell it
// not to actually run the shader.
ShaderGlobals sg;
setup_shaderglobals (sg, shadingsys, 0, 0);
if (raytype_opt)
shadingsys->optimize_group (shadergroup.get(), raytype_bit, ~raytype_bit);
shadingsys->execute (ctx, *shadergroup, sg, false);
if (entryoutputs.size()) {
std::cout << "Entry outputs:";
for (size_t i = 0; i < entryoutputs.size(); ++i) {
ustring name (entryoutputs[i]); // convert to ustring
const ShaderSymbol *sym = shadingsys->find_symbol (*shadergroup, name);
if (!sym) {
std::cout << "\nEntry output " << entryoutputs[i] << " not found. Abording.\n";
exit (EXIT_FAILURE);
}
entrylayer_symbols.push_back (sym);
std::cout << ' ' << entryoutputs[i];
}
std::cout << "\n";
}
// For each output file specified on the command line...
for (size_t i = 0; i < outputfiles.size(); ++i) {
// Make a ustring version of the output name, for fast manipulation
outputvarnames.push_back (ustring(outputvars[i]));
// Start with a NULL ImageBuf pointer
outputimgs.push_back (NULL);
// Ask for a pointer to the symbol's data, as computed by this
// shader.
TypeDesc t;
const void *data = shadingsys->get_symbol (*ctx, outputvarnames[i], t);
if (!data) {
std::cout << "Output " << outputvars[i]
<< " not found, skipping.\n";
continue; // Skip if symbol isn't found
}
std::cout << "Output " << outputvars[i] << " to "
<< outputfiles[i] << "\n";
// And the "base" type, i.e. the type of each element or channel
TypeDesc tbase = TypeDesc ((TypeDesc::BASETYPE)t.basetype);
// But which type are we going to write? Use the true data type
// from OSL, unless the command line options indicated that
// something else was desired.
TypeDesc outtypebase = tbase;
if (dataformatname == "uint8")
outtypebase = TypeDesc::UINT8;
else if (dataformatname == "half")
outtypebase = TypeDesc::HALF;
else if (dataformatname == "float")
outtypebase = TypeDesc::FLOAT;
// Number of channels to write to the image is the number of (array)
// elements times the number of channels (e.g. 1 for scalar, 3 for
// vector, etc.)
int nchans = t.numelements() * t.aggregate;
// Make an ImageBuf of the right type and size to hold this
// symbol's output, and initially clear it to all black pixels.
OIIO::ImageSpec spec (xres, yres, nchans, TypeDesc::FLOAT);
outputimgs[i] = new OIIO::ImageBuf(outputfiles[i], spec);
outputimgs[i]->set_write_format (outtypebase);
OIIO::ImageBufAlgo::zero (*outputimgs[i]);
}
if (outputimgs.empty()) {
OIIO::ImageSpec spec (xres, yres, 3, TypeDesc::FLOAT);
outputimgs.push_back(new OIIO::ImageBuf(spec));
}
shadingsys->release_context (ctx); // don't need this anymore for now
}
示例11: paramname
static void
action_param (int argc, const char *argv[])
{
std::string command = argv[0];
bool use_reparam = false;
if (OIIO::Strutil::istarts_with(command, "--reparam") ||
OIIO::Strutil::istarts_with(command, "-reparam"))
use_reparam = true;
ParamValueList ¶ms (use_reparam ? reparams : (::params));
string_view paramname (argv[1]);
string_view stringval (argv[2]);
TypeDesc type = TypeDesc::UNKNOWN;
bool unlockgeom = false;
float f[16];
size_t pos;
while ((pos = command.find_first_of(":")) != std::string::npos) {
command = command.substr (pos+1, std::string::npos);
std::vector<std::string> splits;
OIIO::Strutil::split (command, splits, ":", 1);
if (splits.size() < 1) {}
else if (OIIO::Strutil::istarts_with(splits[0],"type="))
type.fromstring (splits[0].c_str()+5);
else if (OIIO::Strutil::istarts_with(splits[0],"lockgeom="))
unlockgeom = (strtol (splits[0].c_str()+9, NULL, 10) == 0);
}
// If it is or might be a matrix, look for 16 comma-separated floats
if ((type == TypeDesc::UNKNOWN || type == TypeDesc::TypeMatrix)
&& sscanf (stringval.c_str(),
"%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
&f[0], &f[1], &f[2], &f[3],
&f[4], &f[5], &f[6], &f[7], &f[8], &f[9], &f[10], &f[11],
&f[12], &f[13], &f[14], &f[15]) == 16) {
params.push_back (ParamValue());
params.back().init (paramname, TypeDesc::TypeMatrix, 1, f);
if (unlockgeom)
params.back().interp (ParamValue::INTERP_VERTEX);
return;
}
// If it is or might be a vector type, look for 3 comma-separated floats
if ((type == TypeDesc::UNKNOWN || equivalent(type,TypeDesc::TypeVector))
&& sscanf (stringval.c_str(), "%g, %g, %g", &f[0], &f[1], &f[2]) == 3) {
if (type == TypeDesc::UNKNOWN)
type = TypeDesc::TypeVector;
params.push_back (ParamValue());
params.back().init (paramname, type, 1, f);
if (unlockgeom)
params.back().interp (ParamValue::INTERP_VERTEX);
return;
}
// If it is or might be an int, look for an int that takes up the whole
// string.
if ((type == TypeDesc::UNKNOWN || type == TypeDesc::TypeInt)) {
char *endptr = NULL;
int ival = strtol(stringval.c_str(),&endptr,10);
if (endptr && *endptr == 0) {
params.push_back (ParamValue());
params.back().init (paramname, TypeDesc::TypeInt, 1, &ival);
if (unlockgeom)
params.back().interp (ParamValue::INTERP_VERTEX);
return;
}
}
// If it is or might be an float, look for a float that takes up the
// whole string.
if ((type == TypeDesc::UNKNOWN || type == TypeDesc::TypeFloat)) {
char *endptr = NULL;
float fval = (float) strtod(stringval.c_str(),&endptr);
if (endptr && *endptr == 0) {
params.push_back (ParamValue());
params.back().init (paramname, TypeDesc::TypeFloat, 1, &fval);
if (unlockgeom)
params.back().interp (ParamValue::INTERP_VERTEX);
return;
}
}
// Catch-all for float types and arrays
if (type.basetype == TypeDesc::FLOAT) {
int n = type.aggregate * type.numelements();
std::vector<float> vals (n);
for (int i = 0; i < n; ++i) {
OIIO::Strutil::parse_float (stringval, vals[i]);
OIIO::Strutil::parse_char (stringval, ',');
}
params.push_back (ParamValue());
params.back().init (paramname, type, 1, &vals[0]);
if (unlockgeom)
params.back().interp (ParamValue::INTERP_VERTEX);
return;
}
// Catch-all for int types and arrays
if (type.basetype == TypeDesc::INT) {
int n = type.aggregate * type.numelements();
std::vector<int> vals (n);
for (int i = 0; i < n; ++i) {
OIIO::Strutil::parse_int (stringval, vals[i]);
//.........这里部分代码省略.........
示例12: sizeof
llvm::Type *
BackendLLVM::llvm_type_groupdata ()
{
// If already computed, return it
if (m_llvm_type_groupdata)
return m_llvm_type_groupdata;
std::vector<llvm::Type*> fields;
int offset = 0;
int order = 0;
if (llvm_debug() >= 2)
std::cout << "Group param struct:\n";
// First, add the array that tells if each layer has run. But only make
// slots for the layers that may be called/used.
if (llvm_debug() >= 2)
std::cout << " layers run flags: " << m_num_used_layers
<< " at offset " << offset << "\n";
int sz = (m_num_used_layers + 3) & (~3); // Round up to 32 bit boundary
fields.push_back (ll.type_array (ll.type_bool(), sz));
offset += sz * sizeof(bool);
++order;
// Now add the array that tells which userdata have been initialized,
// and the space for the userdata values.
int nuserdata = (int) group().m_userdata_names.size();
if (nuserdata) {
if (llvm_debug() >= 2)
std::cout << " userdata initialized flags: " << nuserdata
<< " at offset " << offset << ", field " << order << "\n";
ustring *names = & group().m_userdata_names[0];
TypeDesc *types = & group().m_userdata_types[0];
int *offsets = & group().m_userdata_offsets[0];
int sz = (nuserdata + 3) & (~3);
fields.push_back (ll.type_array (ll.type_bool(), sz));
offset += nuserdata * sizeof(bool);
++order;
for (int i = 0; i < nuserdata; ++i) {
TypeDesc type = types[i];
int n = type.numelements() * 3; // always make deriv room
type.arraylen = n;
fields.push_back (llvm_type (type));
// Alignment
int align = type.basesize();
offset = OIIO::round_to_multiple_of_pow2 (offset, align);
if (llvm_debug() >= 2)
std::cout << " userdata " << names[i] << ' ' << type
<< ", field " << order << ", offset " << offset << "\n";
offsets[i] = offset;
offset += int(type.size());
++order;
}
}
// For each layer in the group, add entries for all params that are
// connected or interpolated, and output params. Also mark those
// symbols with their offset within the group struct.
m_param_order_map.clear ();
for (int layer = 0; layer < group().nlayers(); ++layer) {
ShaderInstance *inst = group()[layer];
if (inst->unused())
continue;
FOREACH_PARAM (Symbol &sym, inst) {
TypeSpec ts = sym.typespec();
if (ts.is_structure()) // skip the struct symbol itself
continue;
const int arraylen = std::max (1, sym.typespec().arraylength());
const int derivSize = (sym.has_derivs() ? 3 : 1);
ts.make_array (arraylen * derivSize);
fields.push_back (llvm_type (ts));
// Alignment
size_t align = sym.typespec().is_closure_based() ? sizeof(void*) :
sym.typespec().simpletype().basesize();
if (offset & (align-1))
offset += align - (offset & (align-1));
if (llvm_debug() >= 2)
std::cout << " " << inst->layername()
<< " (" << inst->id() << ") " << sym.mangled()
<< " " << ts.c_str() << ", field " << order
<< ", size " << derivSize * int(sym.size())
<< ", offset " << offset << std::endl;
sym.dataoffset ((int)offset);
offset += derivSize* int(sym.size());
m_param_order_map[&sym] = order;
++order;
}
}
示例13: if
// Add the attribute -- figure out the type
void
parse_param(string_view paramname, string_view val, ImageSpec& spec)
{
TypeDesc type; // start out unknown
// If the param string starts with a type name, that's what it is
if (size_t typeportion = type.fromstring(paramname)) {
paramname.remove_prefix(typeportion);
Strutil::skip_whitespace(paramname);
}
// If the value string starts with a type name, that's what it is
else if (size_t typeportion = type.fromstring(val)) {
val.remove_prefix(typeportion);
Strutil::skip_whitespace(val);
}
if (type.basetype == TypeDesc::UNKNOWN) {
// If we didn't find a type name, try to guess
if (val.size() >= 2 && val.front() == '\"' && val.back() == '\"') {
// Surrounded by quotes? it's a string (strip off the quotes)
val.remove_prefix(1);
val.remove_suffix(1);
type = TypeDesc::TypeString;
} else if (Strutil::string_is<int>(val)) {
// Looks like an int, is an int
type = TypeDesc::TypeInt;
} else if (Strutil::string_is<float>(val)) {
// Looks like a float, is a float
type = TypeDesc::TypeFloat;
} else {
// Everything else is assumed a string
type = TypeDesc::TypeString;
}
}
// Read the values and set the attribute
int n = type.numelements() * type.aggregate;
if (type.basetype == TypeDesc::INT) {
std::vector<int> values(n);
for (int i = 0; i < n; ++i) {
Strutil::parse_int(val, values[i]);
Strutil::parse_char(val, ','); // optional
}
if (n > 0)
spec.attribute(paramname, type, &values[0]);
}
if (type.basetype == TypeDesc::FLOAT) {
std::vector<float> values(n);
for (int i = 0; i < n; ++i) {
Strutil::parse_float(val, values[i]);
Strutil::parse_char(val, ','); // optional
}
if (n > 0)
spec.attribute(paramname, type, &values[0]);
} else if (type.basetype == TypeDesc::STRING) {
std::vector<ustring> values(n);
for (int i = 0; i < n; ++i) {
string_view v;
Strutil::parse_string(val, v);
Strutil::parse_char(val, ','); // optional
values[i] = v;
}
if (n > 0)
spec.attribute(paramname, type, &values[0]);
}
}
示例14: q
int
Dictionary::dict_value (int nodeID, ustring attribname,
TypeDesc type, void *data)
{
if (nodeID <= 0 || nodeID >= (int)m_nodes.size())
return 0; // invalid node ID
const Dictionary::Node &node (m_nodes[nodeID]);
Dictionary::Query q (node.document, nodeID, attribname, type);
Dictionary::QueryMap::iterator qfound = m_cache.find (q);
if (qfound != m_cache.end()) {
// previously found
int offset = qfound->second.valueoffset;
int n = type.numelements() * type.aggregate;
if (type.basetype == TypeDesc::STRING) {
ASSERT (n == 1 && "no string arrays in XML");
((ustring *)data)[0] = m_stringdata[offset];
return 1;
}
if (type.basetype == TypeDesc::INT) {
for (int i = 0; i < n; ++i)
((int *)data)[i] = m_intdata[offset++];
return 1;
}
if (type.basetype == TypeDesc::FLOAT) {
for (int i = 0; i < n; ++i)
((float *)data)[i] = m_floatdata[offset++];
return 1;
}
return 0; // Unknown type
}
// OK, the entry wasn't in the cache, we need to decode it and cache it.
const char *val = NULL;
if (attribname.empty()) {
val = node.node.value();
} else {
for (pugi::xml_attribute_iterator ait = node.node.attributes_begin();
ait != node.node.attributes_end(); ++ait) {
if (ait->name() == attribname) {
val = ait->value();
break;
}
}
}
if (val == NULL)
return 0; // not found
Dictionary::QueryResult r (false, 0);
int n = type.numelements() * type.aggregate;
if (type.basetype == TypeDesc::STRING && n == 1) {
r.valueoffset = (int) m_stringdata.size();
ustring s (val);
m_stringdata.push_back (s);
((ustring *)data)[0] = s;
m_cache[q] = r;
return 1;
}
if (type.basetype == TypeDesc::INT) {
r.valueoffset = (int) m_intdata.size();
for (int i = 0; i < n; ++i) {
int v = (int) strtol (val, (char **)&val, 10);
while (isspace(*val) || *val == ',')
++val;
m_intdata.push_back (v);
((int *)data)[i] = v;
}
m_cache[q] = r;
return 1;
}
if (type.basetype == TypeDesc::FLOAT) {
r.valueoffset = (int) m_floatdata.size();
for (int i = 0; i < n; ++i) {
float v = (float) strtod (val, (char **)&val);
while (isspace(*val) || *val == ',')
++val;
m_floatdata.push_back (v);
((float *)data)[i] = v;
}
m_cache[q] = r;
return 1;
}
// Anything that's left is an unsupported type
return 0;
}
示例15: Mshadptr
//.........这里部分代码省略.........
double runtime = 0;
std::vector<float> pixel;
if (outputfiles.size() != 0)
std::cout << "\n";
// grab this once since we will be shading several points
ShadingSystemImpl *ssi = (ShadingSystemImpl *)shadingsys;
void* thread_info = ssi->create_thread_info();
for (int iter = 0; iter < iters; ++iter) {
for (int y = 0, n = 0; y < yres; ++y) {
for (int x = 0; x < xres; ++x, ++n) {
shaderglobals.u = (xres == 1) ? 0.5f : (float) x / (xres - 1);
shaderglobals.v = (yres == 1) ? 0.5f : (float) y / (yres - 1);
shaderglobals.P = Vec3 (shaderglobals.u, shaderglobals.v, 1.0f);
shaderglobals.dPdx = Vec3 (shaderglobals.dudx, shaderglobals.dudy, 0.0f);
shaderglobals.dPdy = Vec3 (shaderglobals.dvdx, shaderglobals.dvdy, 0.0f);
shaderglobals.N = Vec3 (0, 0, 1);
shaderglobals.Ng = Vec3 (0, 0, 1);
shaderglobals.dPdu = Vec3 (1.0f, 0.0f, 0.0f);
shaderglobals.dPdv = Vec3 (0.0f, 1.0f, 0.0f);
shaderglobals.surfacearea = 1;
// Request a shading context, bind it, execute the shaders.
// FIXME -- this will eventually be replaced with a public
// ShadingSystem call that encapsulates it.
ShadingContext *ctx = ssi->get_context (thread_info);
timer.reset ();
timer.start ();
// run shader for this point
ctx->execute (ShadUseSurface, *shaderstate, shaderglobals);
runtime += timer ();
if (iter == (iters - 1)) {
// extract any output vars into images (on last iteration only)
for (size_t i = 0; i < outputfiles.size(); ++i) {
Symbol *sym = ctx->symbol (ShadUseSurface, ustring(outputvars[i]));
if (! sym) {
if (n == 0) {
std::cout << "Output " << outputvars[i] << " not found, skipping.\n";
outputimgs.push_back(0); // invalid image
}
continue;
}
if (n == 0)
std::cout << "Output " << outputvars[i] << " to " << outputfiles[i]<< "\n";
TypeDesc t = sym->typespec().simpletype();
TypeDesc tbase = TypeDesc ((TypeDesc::BASETYPE)t.basetype);
TypeDesc outtypebase = tbase;
if (dataformatname == "uint8")
outtypebase = TypeDesc::UINT8;
else if (dataformatname == "half")
outtypebase = TypeDesc::HALF;
else if (dataformatname == "float")
outtypebase = TypeDesc::FLOAT;
int nchans = t.numelements() * t.aggregate;
pixel.resize (nchans);
if (n == 0) {
OIIO::ImageSpec spec (xres, yres, nchans, outtypebase);
OIIO::ImageBuf* img = new OIIO::ImageBuf(outputfiles[i], spec);
#if OPENIMAGEIO_VERSION >= 900 /* 0.9.0 */
OIIO::ImageBufAlgo::zero (*img);
#else
img->zero ();
#endif
outputimgs.push_back(img);
}
OIIO::convert_types (tbase, ctx->symbol_data (*sym, 0),
TypeDesc::FLOAT, &pixel[0], nchans);
outputimgs[i]->setpixel (x, y, &pixel[0]);
}
}
ssi->release_context (ctx, thread_info);
}
}
}
ssi->destroy_thread_info(thread_info);
if (outputfiles.size() == 0)
std::cout << "\n";
// write any images to disk
for (size_t i = 0; i < outputimgs.size(); ++i) {
if (outputimgs[i]) {
outputimgs[i]->save();
delete outputimgs[i];
}
}
if (debug || stats) {
std::cout << "\n";
std::cout << "Setup: " << Strutil::timeintervalformat (setuptime,2) << "\n";
std::cout << "Run : " << Strutil::timeintervalformat (runtime,2) << "\n";
std::cout << "\n";
std::cout << shadingsys->getstats (5) << "\n";
}
ShadingSystem::destroy (shadingsys);
return EXIT_SUCCESS;
}