@@ -297,28 +297,28 @@ void wrapShader(T m) {
297297 .def_readonly (" bind_point" , &Shader::Binding::bind_point);
298298
299299 c
300- .def_static (" create" , &Shader::create)
301- .def_static (" compile" , [](std::string src, Shader::Type type) -> std::shared_ptr<Shader> {
302- if (type == Shader::UNKNOWN) return std::shared_ptr<Shader> ();
303- const char * targets[] = { " ps_5_1 " , " vs_5_1 " , nullptr };
304- ID3DBlob * code, *error_msgs;
305- HRESULT hr = D3DCompile (src.c_str (), src.size (), nullptr , nullptr , nullptr , " main" , targets[(int )type], 0 , 0 , &code, &error_msgs);
306- if (FAILED (hr)) {
307- LOG (WARN) << " Shader compilation failed!" ;
308- LOG (INFO) << std::string ((const char *)error_msgs->GetBufferPointer (), error_msgs->GetBufferSize ());
309- code->Release ();
310- error_msgs->Release ();
311- return std::shared_ptr<Shader> ();
312- }
313- ByteCode bc ((const char *)code->GetBufferPointer (), ((const char *)code->GetBufferPointer ()) + code->GetBufferSize ());
314- code->Release ();
315- error_msgs->Release ();
316- return Shader::create (bc);
317- } )
300+ .def_static (" create" , &Shader::create, py::arg ( " bytecode " ), py::arg ( " name_remap " )=std::unordered_map<std::string, std::string>() )
301+ .def_static (" compile" , [](std::string src, Shader::Type type, const std::unordered_map<std::string, std::string> & name_remap = std::unordered_map<std::string, std::string>()) -> py::object {
302+ if (type == Shader::UNKNOWN) return py::none ();
303+ const char * targets[] = { " vs_5_0 " , " ps_5_0 " , nullptr };
304+ ID3DBlob * code, *error_msgs;
305+ HRESULT hr = D3DCompile (src.c_str (), src.size (), nullptr , nullptr , nullptr , " main" , targets[(int )type], 0 , 0 , &code, &error_msgs);
306+ if (FAILED (hr)) {
307+ LOG (WARN) << " Shader compilation failed!" ;
308+ LOG (INFO) << std::string ((const char *)error_msgs->GetBufferPointer (), error_msgs->GetBufferSize ());
309+ if (code) code->Release ();
310+ if (error_msgs) error_msgs->Release ();
311+ return py::none ();
312+ }
313+ ByteCode bc ((const char *)code->GetBufferPointer (), ((const char *)code->GetBufferPointer ()) + code->GetBufferSize ());
314+ if (code) code->Release ();
315+ if (error_msgs) error_msgs->Release ();
316+ return py::cast ( Shader::create (bc, name_remap) );
317+ }, py::arg ( " code " ), py::arg ( " type " ), py::arg ( " name_remap " ) = std::unordered_map<std::string, std::string>() )
318318 .def (" append" , &Shader::append, py::call_guard<py::gil_scoped_release>())
319319// .def("subset", Shader::subset, py::call_guard<py::gil_scoped_release>())
320- .def (" renameCBuffer " , &Shader::renameCBuffer, py::call_guard<py::gil_scoped_release>())
321- .def (" renameOutput " , &Shader::renameOutput, py::call_guard<py::gil_scoped_release>())
320+ .def (" rename_cbuffer " , &Shader::renameCBuffer, py::call_guard<py::gil_scoped_release>(), py::arg ( " old_name " ), py::arg ( " new_name " ), py::arg ( " new_slot " ) = - 1 )
321+ .def (" rename_output " , &Shader::renameOutput, py::call_guard<py::gil_scoped_release>(), py::arg ( " old_name " ), py::arg ( " new_name " ), py::arg ( " sys_id " ) = 0 )
322322 .def (" disassemble" , &Shader::disassemble, py::call_guard<py::gil_scoped_release>())
323323
324324 .def_property_readonly (" type" , &Shader::type, py::call_guard<py::gil_scoped_release>())
@@ -512,8 +512,16 @@ struct PythonController : public GameController {
512512 py::list mb = inspect.attr (" getmembers" )(m);
513513 for (auto c : mb) {
514514 py::object cls = py::cast<py::tuple>(c)[1 ];
515- if (py::cast<bool >(inspect.attr (" isclass" )(cls)) && PyObject_IsSubclass (cls.ptr (), base_controller.ptr ()))
516- controllers.push_back (Controller (cls (PythonControllerRef (this ))));
515+ if (py::cast<bool >(inspect.attr (" isclass" )(cls)) && PyObject_IsSubclass (cls.ptr (), base_controller.ptr ())) {
516+ try {
517+ py::object new_ctl = cls (PythonControllerRef (this ));
518+ if (!new_ctl.is_none ())
519+ controllers.push_back (Controller (new_ctl));
520+ }
521+ catch (py::error_already_set e) {
522+ LOG (WARN) << " Failed to create controller. " << e.what ();
523+ }
524+ }
517525 }
518526 }
519527 }
0 commit comments