Skip to content

Commit f70e58f

Browse files
committed
Support OSLQuery from a given bytecode
This is handy feature to have for applications which has OSL in-memory bytecode cache but still needs to run OSLQuery on such shaders without creating temporary files on the disk. Currently only explicit query.open_bytecode() call is supported, this is because it's not really possible to distinguish filepath from memory buffer being passed to the constructor.
1 parent 8e9f129 commit f70e58f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/include/OSL/oslquery.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ class OSLQUERYPUBLIC OSLQuery {
9797
bool open (string_view shadername,
9898
string_view searchpath = string_view());
9999

100+
/// Get info on the shader from it's compiled bytecode. Return
101+
/// true for success, false if the shader could not be found or
102+
/// opened properly.
103+
/// Meant to be called from an app which caches bytecodes from
104+
/// it's own side and wants to get shader info on runtime without
105+
/// creating a temporary file.
106+
bool open_bytecode (string_view buffer);
107+
100108
/// Meant to be called at runtime from an app with a full ShadingSystem,
101109
/// fill out an OSLQuery structure for the given layer of the group.
102110
/// This is much faster than using open() to read it from an oso file on

src/liboslquery/oslquery.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,12 @@ OSLQuery::open (string_view shadername,
306306
return ok;
307307
}
308308

309+
bool
310+
OSLQuery::open_bytecode (string_view buffer)
311+
{
312+
OSOReaderQuery oso (*this);
313+
bool ok = oso.parse_memory (buffer);
314+
return ok;
315+
}
309316

310317
OSL_NAMESPACE_EXIT

0 commit comments

Comments
 (0)