Commit 2ed93ab1 by Ben Clayton

clang-format the src/Vulkan directory

Bug: b/144825072 Change-Id: I1bd5196b34a7974a41dcb95814a1ae8643b26f22 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39658 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 595d9112
......@@ -26,8 +26,7 @@
#include <unordered_map>
#include <unordered_set>
namespace
{
namespace {
class Broadcaster : public vk::dbg::EventListener
{
......@@ -40,17 +39,17 @@ public:
void onLineBreakpointHit(Thread::ID) override;
void onFunctionBreakpointHit(Thread::ID) override;
void add(EventListener*);
void remove(EventListener*);
void add(EventListener *);
void remove(EventListener *);
private:
template <typename F>
inline void foreach(F&&);
template<typename F>
inline void foreach(F &&);
template <typename F>
inline void modify(F&&);
template<typename F>
inline void modify(F &&);
using ListenerSet = std::unordered_set<EventListener*>;
using ListenerSet = std::unordered_set<EventListener *>;
std::recursive_mutex mutex;
std::shared_ptr<ListenerSet> listeners = std::make_shared<ListenerSet>();
int listenersInUse = 0;
......@@ -58,36 +57,36 @@ private:
void Broadcaster::onThreadStarted(Thread::ID id)
{
foreach([&](EventListener* l) { l->onThreadStarted(id); });
foreach([&](EventListener *l) { l->onThreadStarted(id); });
}
void Broadcaster::onThreadStepped(Thread::ID id)
{
foreach([&](EventListener* l) { l->onThreadStepped(id); });
foreach([&](EventListener *l) { l->onThreadStepped(id); });
}
void Broadcaster::onLineBreakpointHit(Thread::ID id)
{
foreach([&](EventListener* l) { l->onLineBreakpointHit(id); });
foreach([&](EventListener *l) { l->onLineBreakpointHit(id); });
}
void Broadcaster::onFunctionBreakpointHit(Thread::ID id)
{
foreach([&](EventListener* l) { l->onFunctionBreakpointHit(id); });
foreach([&](EventListener *l) { l->onFunctionBreakpointHit(id); });
}
void Broadcaster::add(EventListener* l)
void Broadcaster::add(EventListener *l)
{
modify([&]() { listeners->emplace(l); });
}
void Broadcaster::remove(EventListener* l)
void Broadcaster::remove(EventListener *l)
{
modify([&]() { listeners->erase(l); });
}
template <typename F>
void Broadcaster::foreach(F&& f)
template<typename F>
void Broadcaster::foreach(F &&f)
{
std::unique_lock<std::recursive_mutex> lock(mutex);
++listenersInUse;
......@@ -96,8 +95,8 @@ void Broadcaster::foreach(F&& f)
--listenersInUse;
}
template <typename F>
void Broadcaster::modify(F&& f)
template<typename F>
void Broadcaster::modify(F &&f)
{
std::unique_lock<std::recursive_mutex> lock(mutex);
if(listenersInUse > 0)
......@@ -111,10 +110,8 @@ void Broadcaster::modify(F&& f)
} // namespace
namespace vk
{
namespace dbg
{
namespace vk {
namespace dbg {
////////////////////////////////////////////////////////////////////////////////
// Context::Impl
......@@ -124,16 +121,16 @@ class Context::Impl : public Context
public:
// Context compliance
Lock lock() override;
void addListener(EventListener*) override;
void removeListener(EventListener*) override;
EventListener* broadcast() override;
void addListener(EventListener *) override;
void removeListener(EventListener *) override;
EventListener *broadcast() override;
void addFile(const std::shared_ptr<File>& file);
void addFile(const std::shared_ptr<File> &file);
Broadcaster broadcaster;
std::mutex mutex;
std::vector<EventListener*> eventListeners;
std::vector<EventListener *> eventListeners;
std::unordered_map<std::thread::id, std::shared_ptr<Thread>> threadsByStdId;
std::unordered_set<std::string> functionBreakpoints;
std::unordered_map<std::string, std::vector<int>> pendingBreakpoints;
......@@ -154,22 +151,22 @@ Context::Lock Context::Impl::lock()
return Lock(this);
}
void Context::Impl::addListener(EventListener* l)
void Context::Impl::addListener(EventListener *l)
{
broadcaster.add(l);
}
void Context::Impl::removeListener(EventListener* l)
void Context::Impl::removeListener(EventListener *l)
{
broadcaster.remove(l);
}
EventListener* Context::Impl::broadcast()
EventListener *Context::Impl::broadcast()
{
return &broadcaster;
}
void Context::Impl::addFile(const std::shared_ptr<File>& file)
void Context::Impl::addFile(const std::shared_ptr<File> &file)
{
files.add(file->id, file);
......@@ -194,14 +191,14 @@ std::shared_ptr<Context> Context::create()
////////////////////////////////////////////////////////////////////////////////
// Context::Lock
////////////////////////////////////////////////////////////////////////////////
Context::Lock::Lock(Impl* ctx) :
ctx(ctx)
Context::Lock::Lock(Impl *ctx)
: ctx(ctx)
{
ctx->mutex.lock();
}
Context::Lock::Lock(Lock&& o) :
ctx(o.ctx)
Context::Lock::Lock(Lock &&o)
: ctx(o.ctx)
{
o.ctx = nullptr;
}
......@@ -211,7 +208,7 @@ Context::Lock::~Lock()
unlock();
}
Context::Lock& Context::Lock::operator=(Lock&& o)
Context::Lock &Context::Lock::operator=(Lock &&o)
{
ctx = o.ctx;
o.ctx = nullptr;
......@@ -264,15 +261,15 @@ std::vector<std::shared_ptr<Thread>> Context::Lock::threads()
return out;
}
std::shared_ptr<File> Context::Lock::createVirtualFile(const std::string& name,
const std::string& source)
std::shared_ptr<File> Context::Lock::createVirtualFile(const std::string &name,
const std::string &source)
{
auto file = File::createVirtual(ctx->nextFileID++, name, source);
ctx->addFile(file);
return file;
}
std::shared_ptr<File> Context::Lock::createPhysicalFile(const std::string& path)
std::shared_ptr<File> Context::Lock::createPhysicalFile(const std::string &path)
{
auto file = File::createPhysical(ctx->nextFileID++, path);
ctx->addFile(file);
......@@ -296,7 +293,7 @@ std::vector<std::shared_ptr<File>> Context::Lock::files()
}
std::shared_ptr<Frame> Context::Lock::createFrame(
const std::shared_ptr<File>& file)
const std::shared_ptr<File> &file)
{
auto frame = std::make_shared<Frame>(ctx->nextFrameID++);
ctx->frames.add(frame->id, frame);
......@@ -313,7 +310,7 @@ std::shared_ptr<Frame> Context::Lock::get(Frame::ID id)
}
std::shared_ptr<Scope> Context::Lock::createScope(
const std::shared_ptr<File>& file)
const std::shared_ptr<File> &file)
{
auto scope = std::make_shared<Scope>(ctx->nextScopeID++, file, createVariableContainer());
ctx->scopes.add(scope->id, scope);
......@@ -337,17 +334,17 @@ std::shared_ptr<VariableContainer> Context::Lock::get(VariableContainer::ID id)
return ctx->variableContainers.get(id);
}
void Context::Lock::addFunctionBreakpoint(const std::string& name)
void Context::Lock::addFunctionBreakpoint(const std::string &name)
{
ctx->functionBreakpoints.emplace(name);
}
void Context::Lock::addPendingBreakpoints(const std::string& filename, const std::vector<int>& lines)
void Context::Lock::addPendingBreakpoints(const std::string &filename, const std::vector<int> &lines)
{
ctx->pendingBreakpoints.emplace(filename, lines);
}
bool Context::Lock::isFunctionBreakpoint(const std::string& name)
bool Context::Lock::isFunctionBreakpoint(const std::string &name)
{
return ctx->functionBreakpoints.count(name) > 0;
}
......
......@@ -21,10 +21,8 @@
#include <string>
#include <vector>
namespace vk
{
namespace dbg
{
namespace vk {
namespace dbg {
// Forward declarations.
class Thread;
......@@ -50,12 +48,12 @@ public:
class Lock
{
public:
Lock(Impl*);
Lock(Lock&&);
Lock(Impl *);
Lock(Lock &&);
~Lock();
// move-assignment operator.
Lock& operator=(Lock&&);
Lock &operator=(Lock &&);
// unlock() explicitly unlocks before the Lock destructor is called.
// It is illegal to call any other methods after calling unlock().
......@@ -77,12 +75,12 @@ public:
// filesystem.
// name is the unique name of the file.
// source is the content of the file.
std::shared_ptr<File> createVirtualFile(const std::string& name,
const std::string& source);
std::shared_ptr<File> createVirtualFile(const std::string &name,
const std::string &source);
// createPhysicalFile() returns a new file that is backed by the file
// at path.
std::shared_ptr<File> createPhysicalFile(const std::string& path);
std::shared_ptr<File> createPhysicalFile(const std::string &path);
// get() returns the file with the given ID, or null if the file
// does not exist or no longer has any external shared_ptr references.
......@@ -93,7 +91,7 @@ public:
// createFrame() returns a new frame for the given file.
std::shared_ptr<Frame> createFrame(
const std::shared_ptr<File>& file);
const std::shared_ptr<File> &file);
// get() returns the frame with the given ID, or null if the frame
// does not exist or no longer has any external shared_ptr references.
......@@ -101,7 +99,7 @@ public:
// createScope() returns a new scope for the given file.
std::shared_ptr<Scope> createScope(
const std::shared_ptr<File>& file);
const std::shared_ptr<File> &file);
// get() returns the scope with the given ID, or null if the scope
// does not exist.
......@@ -117,21 +115,21 @@ public:
// addFunctionBreakpoint() adds a breakpoint to the start of the
// function with the given name.
void addFunctionBreakpoint(const std::string& name);
void addFunctionBreakpoint(const std::string &name);
// addPendingBreakpoints() adds a number of breakpoints to the file with
// the given name which has not yet been created with a call to
// createVirtualFile() or createPhysicalFile().
void addPendingBreakpoints(const std::string& name, const std::vector<int>& lines);
void addPendingBreakpoints(const std::string &name, const std::vector<int> &lines);
// isFunctionBreakpoint() returns true if the function with the given
// name has a function breakpoint set.
bool isFunctionBreakpoint(const std::string& name);
bool isFunctionBreakpoint(const std::string &name);
private:
Lock(const Lock&) = delete;
Lock& operator=(const Lock&) = delete;
Impl* ctx;
Lock(const Lock &) = delete;
Lock &operator=(const Lock &) = delete;
Impl *ctx;
};
// create() creates and returns a new Context.
......@@ -144,15 +142,15 @@ public:
virtual Lock lock() = 0;
// addListener() registers an EventListener for event notifications.
virtual void addListener(EventListener*) = 0;
virtual void addListener(EventListener *) = 0;
// removeListener() unregisters an EventListener that was previously
// registered by a call to addListener().
virtual void removeListener(EventListener*) = 0;
virtual void removeListener(EventListener *) = 0;
// broadcast() returns an EventListener that will broadcast all methods on
// to all registered EventListeners.
virtual EventListener* broadcast() = 0;
virtual EventListener *broadcast() = 0;
};
} // namespace dbg
......
......@@ -13,5 +13,5 @@
// limitations under the License.
#ifndef ENABLE_VK_DEBUGGER
#error "Source files in {SwiftShader}/src/Vulkan/Debug should not be built unless ENABLE_VK_DEBUGGER is defined"
#endif // ENABLE_VK_DEBUGGER
# error "Source files in {SwiftShader}/src/Vulkan/Debug should not be built unless ENABLE_VK_DEBUGGER is defined"
#endif // ENABLE_VK_DEBUGGER
......@@ -37,8 +37,9 @@ private:
std::unordered_set<int> breakpoints; // guarded by breakpointMutex
};
FileBase::FileBase(ID id, std::string dir, std::string name, std::string source) :
File(id, std::move(dir), std::move(name), std::move(source)) {}
FileBase::FileBase(ID id, std::string dir, std::string name, std::string source)
: File(id, std::move(dir), std::move(name), std::move(source))
{}
void FileBase::clearBreakpoints()
{
......@@ -71,8 +72,9 @@ public:
private:
};
VirtualFile::VirtualFile(ID id, std::string name, std::string source) :
FileBase(id, "", std::move(name), std::move(source)) {}
VirtualFile::VirtualFile(ID id, std::string name, std::string source)
: FileBase(id, "", std::move(name), std::move(source))
{}
bool VirtualFile::isVirtual() const
{
......@@ -93,8 +95,9 @@ struct PhysicalFile : public FileBase
PhysicalFile::PhysicalFile(ID id,
std::string dir,
std::string name) :
FileBase(id, std::move(dir), std::move(name), "") {}
std::string name)
: FileBase(id, std::move(dir), std::move(name), "")
{}
bool PhysicalFile::isVirtual() const
{
......
......@@ -76,11 +76,12 @@ protected:
inline File(ID id, std::string dir, std::string name, std::string source);
};
File::File(ID id, std::string dir, std::string name, std::string source) :
id(std::move(id)),
dir(std::move(dir)),
name(std::move(name)),
source(source) {}
File::File(ID id, std::string dir, std::string name, std::string source)
: id(std::move(id))
, dir(std::move(dir))
, name(std::move(name))
, source(source)
{}
std::string File::path() const
{
......
......@@ -25,17 +25,19 @@ namespace dbg {
// ID; instead it is used to prevent implicit casts between identifiers of
// different T types.
// IDs are typically used as a map key to value of type T.
template <typename T>
template<typename T>
class ID
{
public:
inline ID() :
id(0) {}
inline ID(int id) :
id(id) {}
inline bool operator==(const ID<T>& rhs) const { return id == rhs.id; }
inline bool operator!=(const ID<T>& rhs) const { return id != rhs.id; }
inline bool operator<(const ID<T>& rhs) const { return id < rhs.id; }
inline ID()
: id(0)
{}
inline ID(int id)
: id(id)
{}
inline bool operator==(const ID<T> &rhs) const { return id == rhs.id; }
inline bool operator!=(const ID<T> &rhs) const { return id != rhs.id; }
inline bool operator<(const ID<T> &rhs) const { return id < rhs.id; }
inline ID operator++() { return ID(++id); }
inline ID operator++(int) { return ID(id++); }
......@@ -52,10 +54,10 @@ private:
namespace std {
// std::hash implementation for vk::dbg::ID<T>
template <typename T>
template<typename T>
struct hash<vk::dbg::ID<T> >
{
std::size_t operator()(const vk::dbg::ID<T>& id) const noexcept
std::size_t operator()(const vk::dbg::ID<T> &id) const noexcept
{
return std::hash<int>()(id.value());
}
......
......@@ -26,15 +26,16 @@ class File;
struct Location
{
Location() = default;
inline Location(int line, const std::shared_ptr<File>& file);
inline Location(int line, const std::shared_ptr<File> &file);
int line = 0; // 1 based. 0 represents no line.
int line = 0; // 1 based. 0 represents no line.
std::shared_ptr<File> file;
};
Location::Location(int line, const std::shared_ptr<File>& file) :
line(line),
file(file) {}
Location::Location(int line, const std::shared_ptr<File> &file)
: line(line)
, file(file)
{}
} // namespace dbg
} // namespace vk
......
......@@ -17,10 +17,8 @@
#include <memory>
namespace vk
{
namespace dbg
{
namespace vk {
namespace dbg {
class Context;
......@@ -29,7 +27,7 @@ class Context;
class Server
{
public:
static std::shared_ptr<Server> create(const std::shared_ptr<Context>&, int port);
static std::shared_ptr<Server> create(const std::shared_ptr<Context> &, int port);
virtual ~Server() = default;
......
......@@ -21,11 +21,12 @@
namespace vk {
namespace dbg {
Thread::Thread(ID id, Context* ctx) :
id(id),
broadcast(ctx->broadcast()) {}
Thread::Thread(ID id, Context *ctx)
: id(id)
, broadcast(ctx->broadcast())
{}
void Thread::setName(const std::string& name)
void Thread::setName(const std::string &name)
{
std::unique_lock<std::mutex> lock(mutex);
name_ = name;
......@@ -37,7 +38,7 @@ std::string Thread::name() const
return name_;
}
void Thread::update(const Location& location)
void Thread::update(const Location &location)
{
std::unique_lock<std::mutex> lock(mutex);
frames.back()->location = location;
......@@ -53,30 +54,30 @@ void Thread::update(const Location& location)
switch(state_)
{
case State::Paused:
{
stateCV.wait(lock, [this] { return state_ != State::Paused; });
break;
}
case State::Stepping:
{
if(!pauseAtFrame || pauseAtFrame == frames.back())
case State::Paused:
{
broadcast->onThreadStepped(id);
state_ = State::Paused;
stateCV.wait(lock, [this] { return state_ != State::Paused; });
pauseAtFrame = 0;
break;
}
case State::Stepping:
{
if(!pauseAtFrame || pauseAtFrame == frames.back())
{
broadcast->onThreadStepped(id);
state_ = State::Paused;
stateCV.wait(lock, [this] { return state_ != State::Paused; });
pauseAtFrame = 0;
}
break;
}
break;
}
case State::Running:
break;
case State::Running:
break;
}
}
void Thread::enter(Context::Lock& ctxlck, const std::shared_ptr<File>& file, const std::string& function)
void Thread::enter(Context::Lock &ctxlck, const std::shared_ptr<File> &file, const std::string &function)
{
auto frame = ctxlck.createFrame(file);
auto isFunctionBreakpoint = ctxlck.isFunctionBreakpoint(function);
......
......@@ -41,8 +41,8 @@ public:
using ID = dbg::ID<Scope>;
inline Scope(ID id,
const std::shared_ptr<File>& file,
const std::shared_ptr<VariableContainer>& variables);
const std::shared_ptr<File> &file,
const std::shared_ptr<VariableContainer> &variables);
// The unique identifier of the scope.
const ID id;
......@@ -55,11 +55,12 @@ public:
};
Scope::Scope(ID id,
const std::shared_ptr<File>& file,
const std::shared_ptr<VariableContainer>& variables) :
id(id),
file(file),
variables(variables) {}
const std::shared_ptr<File> &file,
const std::shared_ptr<VariableContainer> &variables)
: id(id)
, file(file)
, variables(variables)
{}
// Frame holds a number of variable scopes for one of a thread's stack frame,
// and is used to provide source data for the DAP 'StackFrame' type:
......@@ -93,8 +94,9 @@ public:
std::shared_ptr<Scope> hovers;
};
Frame::Frame(ID id) :
id(id) {}
Frame::Frame(ID id)
: id(id)
{}
// Thread holds the state for a single thread of execution.
class Thread
......@@ -110,17 +112,17 @@ public:
Paused // Thread is currently paused.
};
Thread(ID id, Context* ctx);
Thread(ID id, Context *ctx);
// setName() sets the name of the thread.
void setName(const std::string&);
void setName(const std::string &);
// name() returns the name of the thread.
std::string name() const;
// enter() pushes the thread's stack with a new frame created with the given
// file and function.
void enter(Context::Lock& lock, const std::shared_ptr<File>& file, const std::string& function);
void enter(Context::Lock &lock, const std::shared_ptr<File> &file, const std::string &function);
// exit() pops the thread's stack frame.
void exit();
......@@ -170,13 +172,13 @@ public:
// update() updates the current stack frame's location, and potentially
// blocks until the thread is resumed with one of the methods above.
void update(const Location& location);
void update(const Location &location);
// The unique identifier of the thread.
const ID id;
private:
EventListener* const broadcast;
EventListener *const broadcast;
mutable std::mutex mutex;
std::string name_;
......
......@@ -36,32 +36,32 @@ std::string Type::string() const
{
switch(kind)
{
case Kind::Bool:
return "bool";
case Kind::U8:
return "uint8_t";
case Kind::S8:
return "int8_t";
case Kind::U16:
return "uint16_t";
case Kind::S16:
return "int16_t";
case Kind::F32:
return "float";
case Kind::U32:
return "uint32_t";
case Kind::S32:
return "int32_t";
case Kind::F64:
return "double";
case Kind::U64:
return "uint64_t";
case Kind::S64:
return "int64_t";
case Kind::Ptr:
return elem->string() + "*";
case Kind::VariableContainer:
return "struct";
case Kind::Bool:
return "bool";
case Kind::U8:
return "uint8_t";
case Kind::S8:
return "int8_t";
case Kind::U16:
return "uint16_t";
case Kind::S16:
return "int16_t";
case Kind::F32:
return "float";
case Kind::U32:
return "uint32_t";
case Kind::S32:
return "int32_t";
case Kind::F64:
return "double";
case Kind::U64:
return "uint64_t";
case Kind::S64:
return "int64_t";
case Kind::Ptr:
return elem->string() + "*";
case Kind::VariableContainer:
return "struct";
}
return "";
}
......
......@@ -50,7 +50,7 @@ class Type
public:
Type() = default;
inline Type(Kind kind);
inline Type(Kind kind, const std::shared_ptr<const Type>& elem);
inline Type(Kind kind, const std::shared_ptr<const Type> &elem);
// string() returns a string representation of the type.
std::string string() const;
......@@ -59,12 +59,14 @@ public:
const std::shared_ptr<const Type> elem; // Element type of pointer.
};
Type::Type(Kind kind) :
kind(kind) {}
Type::Type(Kind kind)
: kind(kind)
{}
Type::Type(Kind kind, const std::shared_ptr<const Type>& elem) :
kind(kind),
elem(elem) {}
Type::Type(Kind kind, const std::shared_ptr<const Type> &elem)
: kind(kind)
, elem(elem)
{}
// clang-format off
template <typename T> struct TypeOf;
......
......@@ -12,66 +12,66 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Type.hpp"
#include "Value.hpp"
#include "Type.hpp"
#include "Variable.hpp"
namespace vk {
namespace dbg {
const FormatFlags FormatFlags::Default = {
"[", // listPrefix
"]", // listSuffix
", ", // listDelimiter
"", // listIndent
&FormatFlags::Default, // subListFmt
"[", // listPrefix
"]", // listSuffix
", ", // listDelimiter
"", // listIndent
&FormatFlags::Default, // subListFmt
};
std::string Value::string(const FormatFlags& fmt /* = FormatFlags::Default */) const
std::string Value::string(const FormatFlags &fmt /* = FormatFlags::Default */) const
{
switch(type()->kind)
{
case Kind::Bool:
return *reinterpret_cast<const bool*>(get()) ? "true" : "false";
case Kind::U8:
return std::to_string(*reinterpret_cast<const uint8_t*>(get()));
case Kind::S8:
return std::to_string(*reinterpret_cast<const int8_t*>(get()));
case Kind::U16:
return std::to_string(*reinterpret_cast<const uint16_t*>(get()));
case Kind::S16:
return std::to_string(*reinterpret_cast<const int16_t*>(get()));
case Kind::F32:
return std::to_string(*reinterpret_cast<const float*>(get()));
case Kind::U32:
return std::to_string(*reinterpret_cast<const uint32_t*>(get()));
case Kind::S32:
return std::to_string(*reinterpret_cast<const int32_t*>(get()));
case Kind::F64:
return std::to_string(*reinterpret_cast<const double*>(get()));
case Kind::U64:
return std::to_string(*reinterpret_cast<const uint64_t*>(get()));
case Kind::S64:
return std::to_string(*reinterpret_cast<const int64_t*>(get()));
case Kind::Ptr:
return std::to_string(reinterpret_cast<uintptr_t>(get()));
case Kind::VariableContainer:
{
auto const* vc = static_cast<const VariableContainer*>(this);
std::string out = "";
auto subfmt = *fmt.subListFmt;
subfmt.listIndent = fmt.listIndent + fmt.subListFmt->listIndent;
bool first = true;
vc->foreach(0, [&](const Variable& var) {
if(!first) { out += fmt.listDelimiter; }
first = false;
out += fmt.listIndent;
out += var.name;
out += ": ";
out += var.value->string(subfmt);
});
return fmt.listPrefix + out + fmt.listSuffix;
}
case Kind::Bool:
return *reinterpret_cast<const bool *>(get()) ? "true" : "false";
case Kind::U8:
return std::to_string(*reinterpret_cast<const uint8_t *>(get()));
case Kind::S8:
return std::to_string(*reinterpret_cast<const int8_t *>(get()));
case Kind::U16:
return std::to_string(*reinterpret_cast<const uint16_t *>(get()));
case Kind::S16:
return std::to_string(*reinterpret_cast<const int16_t *>(get()));
case Kind::F32:
return std::to_string(*reinterpret_cast<const float *>(get()));
case Kind::U32:
return std::to_string(*reinterpret_cast<const uint32_t *>(get()));
case Kind::S32:
return std::to_string(*reinterpret_cast<const int32_t *>(get()));
case Kind::F64:
return std::to_string(*reinterpret_cast<const double *>(get()));
case Kind::U64:
return std::to_string(*reinterpret_cast<const uint64_t *>(get()));
case Kind::S64:
return std::to_string(*reinterpret_cast<const int64_t *>(get()));
case Kind::Ptr:
return std::to_string(reinterpret_cast<uintptr_t>(get()));
case Kind::VariableContainer:
{
auto const *vc = static_cast<const VariableContainer *>(this);
std::string out = "";
auto subfmt = *fmt.subListFmt;
subfmt.listIndent = fmt.listIndent + fmt.subListFmt->listIndent;
bool first = true;
vc->foreach(0, [&](const Variable &var) {
if(!first) { out += fmt.listDelimiter; }
first = false;
out += fmt.listIndent;
out += var.name;
out += ": ";
out += var.value->string(subfmt);
});
return fmt.listPrefix + out + fmt.listSuffix;
}
}
return "";
}
......
......@@ -33,7 +33,7 @@ struct FormatFlags
std::string listSuffix; // Suffix to lists.
std::string listDelimiter; // List item delimiter.
std::string listIndent; // List item indententation prefix.
const FormatFlags* subListFmt; // Format used for list sub items.
const FormatFlags *subListFmt; // Format used for list sub items.
};
// Value holds a value that can be read and possible written to.
......@@ -47,51 +47,51 @@ public:
// string() returns a string representation of the value using the specified
// FormatFlags.
virtual std::string string(const FormatFlags& = FormatFlags::Default) const;
virtual std::string string(const FormatFlags & = FormatFlags::Default) const;
// get() returns a pointer to the value.
virtual const void* get() const = 0;
virtual const void *get() const = 0;
// set() changes the value to a copy of the value at ptr.
// set() returns true if the value was changed, or false if the value cannot
// be set.
virtual bool set(void* ptr) { return false; }
virtual bool set(void *ptr) { return false; }
};
// Constant is an immutable value.
template <typename T>
template<typename T>
class Constant : public Value
{
public:
inline Constant(const T& value);
inline Constant(const T &value);
inline std::shared_ptr<Type> type() const override;
inline const void* get() const override;
inline const void *get() const override;
private:
const T value;
};
template <typename T>
Constant<T>::Constant(const T& value) :
value(value)
template<typename T>
Constant<T>::Constant(const T &value)
: value(value)
{
}
template <typename T>
template<typename T>
std::shared_ptr<Type> Constant<T>::type() const
{
return TypeOf<T>::get();
}
template <typename T>
const void* Constant<T>::get() const
template<typename T>
const void *Constant<T>::get() const
{
return &value;
}
// make_constant() returns a shared_ptr to a Constant with the given value.
template <typename T>
inline std::shared_ptr<Constant<T>> make_constant(const T& value)
template<typename T>
inline std::shared_ptr<Constant<T>> make_constant(const T &value)
{
return std::shared_ptr<Constant<T>>(new vk::dbg::Constant<T>(value));
}
......
......@@ -45,38 +45,39 @@ public:
// foreach() calls cb with each of the variables in the container.
// F must be a function with the signature void(const Variable&).
template <typename F>
inline void foreach(size_t startIndex, const F& cb) const;
template<typename F>
inline void foreach(size_t startIndex, const F &cb) const;
// find() looks up the variable with the given name.
// If the variable with the given name is found, cb is called with the
// variable and find() returns true.
template <typename F>
inline bool find(const std::string& name, const F& cb) const;
template<typename F>
inline bool find(const std::string &name, const F &cb) const;
// put() places the variable var into the container.
inline void put(const Variable& var);
inline void put(const Variable &var);
// put() places the variable with the given name and value into the container.
inline void put(const std::string& name, const std::shared_ptr<Value>& value);
inline void put(const std::string &name, const std::shared_ptr<Value> &value);
// The unique identifier of the variable.
const ID id;
private:
inline std::shared_ptr<Type> type() const override;
inline const void* get() const override;
inline const void *get() const override;
mutable std::mutex mutex;
std::vector<Variable> variables;
std::unordered_map<std::string, int> indices;
};
VariableContainer::VariableContainer(ID id) :
id(id) {}
VariableContainer::VariableContainer(ID id)
: id(id)
{}
template <typename F>
void VariableContainer::foreach(size_t startIndex, const F& cb) const
template<typename F>
void VariableContainer::foreach(size_t startIndex, const F &cb) const
{
std::unique_lock<std::mutex> lock(mutex);
for(size_t i = startIndex; i < variables.size(); i++)
......@@ -85,11 +86,11 @@ void VariableContainer::foreach(size_t startIndex, const F& cb) const
}
}
template <typename F>
bool VariableContainer::find(const std::string& name, const F& cb) const
template<typename F>
bool VariableContainer::find(const std::string &name, const F &cb) const
{
std::unique_lock<std::mutex> lock(mutex);
for(auto const& var : variables)
for(auto const &var : variables)
{
if(var.name == name)
{
......@@ -100,7 +101,7 @@ bool VariableContainer::find(const std::string& name, const F& cb) const
return false;
}
void VariableContainer::put(const Variable& var)
void VariableContainer::put(const Variable &var)
{
std::unique_lock<std::mutex> lock(mutex);
auto it = indices.find(var.name);
......@@ -115,8 +116,8 @@ void VariableContainer::put(const Variable& var)
}
}
void VariableContainer::put(const std::string& name,
const std::shared_ptr<Value>& value)
void VariableContainer::put(const std::string &name,
const std::shared_ptr<Value> &value)
{
put({ name, value });
}
......@@ -126,7 +127,7 @@ std::shared_ptr<Type> VariableContainer::type() const
return TypeOf<VariableContainer>::get();
}
const void* VariableContainer::get() const
const void *VariableContainer::get() const
{
return nullptr;
}
......
......@@ -27,7 +27,7 @@ namespace dbg {
// remaining std::shared_ptr<V> references.
// WeakMap is not thread-safe and requires the use of an external mutex to be
// used by multiple threads, concurrently.
template <typename K, typename V>
template<typename K, typename V>
class WeakMap
{
using Map = std::map<K, std::weak_ptr<V>>;
......@@ -37,10 +37,10 @@ public:
class iterator
{
public:
inline iterator(const MapIterator& it, const MapIterator& end);
inline iterator(const MapIterator &it, const MapIterator &end);
inline void operator++();
inline bool operator==(const iterator&) const;
inline bool operator!=(const iterator&) const;
inline bool operator==(const iterator &) const;
inline bool operator!=(const iterator &) const;
inline std::pair<K, std::shared_ptr<V>> operator*() const;
private:
......@@ -65,17 +65,17 @@ public:
// get() returns the std::shared_ptr<V> value for the given key, or nullptr
// if the map does not contain the key, or the last remaining
// std::shared_ptr<V> reference to the value has been dropped.
inline std::shared_ptr<V> get(const K& key) const;
inline std::shared_ptr<V> get(const K &key) const;
// add() attempts to insert the key-value pair into the map.
// add() returns true if there was no existing entry with the given key,
// and the pair was added, otherwise false.
inline bool add(const K& key, const std::shared_ptr<V>& val);
inline bool add(const K &key, const std::shared_ptr<V> &val);
// remove() attempts to remove the entry with the given key from the map.
// remove() returns true if there was no existing entry with the given key,
// and the entry was removed, otherwise false.
inline bool remove(const K& key);
inline bool remove(const K &key);
private:
// reap() removes any entries that have values with no external references.
......@@ -85,22 +85,22 @@ private:
size_t reapAtSize = 32;
};
template <typename K, typename V>
WeakMap<K, V>::iterator::iterator(const MapIterator& it, const MapIterator& end) :
it(it),
end(end)
template<typename K, typename V>
WeakMap<K, V>::iterator::iterator(const MapIterator &it, const MapIterator &end)
: it(it)
, end(end)
{
skipNull();
}
template <typename K, typename V>
template<typename K, typename V>
void WeakMap<K, V>::iterator::operator++()
{
it++;
skipNull();
}
template <typename K, typename V>
template<typename K, typename V>
void WeakMap<K, V>::iterator::skipNull()
{
for(; it != end; ++it)
......@@ -115,51 +115,51 @@ void WeakMap<K, V>::iterator::skipNull()
}
}
template <typename K, typename V>
bool WeakMap<K, V>::iterator::operator==(const iterator& rhs) const
template<typename K, typename V>
bool WeakMap<K, V>::iterator::operator==(const iterator &rhs) const
{
return it == rhs.it;
}
template <typename K, typename V>
bool WeakMap<K, V>::iterator::operator!=(const iterator& rhs) const
template<typename K, typename V>
bool WeakMap<K, V>::iterator::operator!=(const iterator &rhs) const
{
return it != rhs.it;
}
template <typename K, typename V>
template<typename K, typename V>
std::pair<K, std::shared_ptr<V>> WeakMap<K, V>::iterator::operator*() const
{
return { it->first, sptr };
}
template <typename K, typename V>
template<typename K, typename V>
typename WeakMap<K, V>::iterator WeakMap<K, V>::begin() const
{
return iterator(map.begin(), map.end());
}
template <typename K, typename V>
template<typename K, typename V>
typename WeakMap<K, V>::iterator WeakMap<K, V>::end() const
{
return iterator(map.end(), map.end());
}
template <typename K, typename V>
template<typename K, typename V>
size_t WeakMap<K, V>::approx_size() const
{
return map.size();
}
template <typename K, typename V>
std::shared_ptr<V> WeakMap<K, V>::get(const K& key) const
template<typename K, typename V>
std::shared_ptr<V> WeakMap<K, V>::get(const K &key) const
{
auto it = map.find(key);
return (it != map.end()) ? it->second.lock() : nullptr;
}
template <typename K, typename V>
bool WeakMap<K, V>::add(const K& key, const std::shared_ptr<V>& val)
template<typename K, typename V>
bool WeakMap<K, V>::add(const K &key, const std::shared_ptr<V> &val)
{
if(map.size() > reapAtSize)
{
......@@ -169,13 +169,13 @@ bool WeakMap<K, V>::add(const K& key, const std::shared_ptr<V>& val)
return map.emplace(key, val).second;
}
template <typename K, typename V>
bool WeakMap<K, V>::remove(const K& key)
template<typename K, typename V>
bool WeakMap<K, V>::remove(const K &key)
{
return map.erase(key) > 0;
}
template <typename K, typename V>
template<typename K, typename V>
void WeakMap<K, V>::reap()
{
for(auto it = map.begin(); it != map.end();)
......
......@@ -20,34 +20,36 @@
namespace vk {
Buffer::Buffer(const VkBufferCreateInfo* pCreateInfo, void* mem) :
flags(pCreateInfo->flags), size(pCreateInfo->size), usage(pCreateInfo->usage),
sharingMode(pCreateInfo->sharingMode)
Buffer::Buffer(const VkBufferCreateInfo *pCreateInfo, void *mem)
: flags(pCreateInfo->flags)
, size(pCreateInfo->size)
, usage(pCreateInfo->usage)
, sharingMode(pCreateInfo->sharingMode)
{
if(pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT)
{
queueFamilyIndexCount = pCreateInfo->queueFamilyIndexCount;
queueFamilyIndices = reinterpret_cast<uint32_t*>(mem);
queueFamilyIndices = reinterpret_cast<uint32_t *>(mem);
memcpy(queueFamilyIndices, pCreateInfo->pQueueFamilyIndices, sizeof(uint32_t) * queueFamilyIndexCount);
}
const auto* nextInfo = reinterpret_cast<const VkBaseInStructure*>(pCreateInfo->pNext);
const auto *nextInfo = reinterpret_cast<const VkBaseInStructure *>(pCreateInfo->pNext);
for(; nextInfo != nullptr; nextInfo = nextInfo->pNext)
{
if(nextInfo->sType == VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO)
{
const auto* externalInfo = reinterpret_cast<const VkExternalMemoryBufferCreateInfo*>(nextInfo);
const auto *externalInfo = reinterpret_cast<const VkExternalMemoryBufferCreateInfo *>(nextInfo);
supportedExternalMemoryHandleTypes = externalInfo->handleTypes;
}
}
}
void Buffer::destroy(const VkAllocationCallbacks* pAllocator)
void Buffer::destroy(const VkAllocationCallbacks *pAllocator)
{
vk::deallocate(queueFamilyIndices, pAllocator);
}
size_t Buffer::ComputeRequiredAllocationSize(const VkBufferCreateInfo* pCreateInfo)
size_t Buffer::ComputeRequiredAllocationSize(const VkBufferCreateInfo *pCreateInfo)
{
return (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) ? sizeof(uint32_t) * pCreateInfo->queueFamilyIndexCount : 0;
}
......@@ -72,36 +74,36 @@ const VkMemoryRequirements Buffer::getMemoryRequirements() const
memoryRequirements.alignment = REQUIRED_MEMORY_ALIGNMENT;
}
memoryRequirements.memoryTypeBits = vk::MEMORY_TYPE_GENERIC_BIT;
memoryRequirements.size = size; // TODO: also reserve space for a header containing
// the size of the buffer (for robust buffer access)
memoryRequirements.size = size; // TODO: also reserve space for a header containing
// the size of the buffer (for robust buffer access)
return memoryRequirements;
}
bool Buffer::canBindToMemory(DeviceMemory* pDeviceMemory) const
bool Buffer::canBindToMemory(DeviceMemory *pDeviceMemory) const
{
return pDeviceMemory->checkExternalMemoryHandleType(supportedExternalMemoryHandleTypes);
}
void Buffer::bind(DeviceMemory* pDeviceMemory, VkDeviceSize pMemoryOffset)
void Buffer::bind(DeviceMemory *pDeviceMemory, VkDeviceSize pMemoryOffset)
{
memory = pDeviceMemory->getOffsetPointer(pMemoryOffset);
}
void Buffer::copyFrom(const void* srcMemory, VkDeviceSize pSize, VkDeviceSize pOffset)
void Buffer::copyFrom(const void *srcMemory, VkDeviceSize pSize, VkDeviceSize pOffset)
{
ASSERT((pSize + pOffset) <= size);
memcpy(getOffsetPointer(pOffset), srcMemory, pSize);
}
void Buffer::copyTo(void* dstMemory, VkDeviceSize pSize, VkDeviceSize pOffset) const
void Buffer::copyTo(void *dstMemory, VkDeviceSize pSize, VkDeviceSize pOffset) const
{
ASSERT((pSize + pOffset) <= size);
memcpy(dstMemory, getOffsetPointer(pOffset), pSize);
}
void Buffer::copyTo(Buffer* dstBuffer, const VkBufferCopy& pRegion) const
void Buffer::copyTo(Buffer *dstBuffer, const VkBufferCopy &pRegion) const
{
copyTo(dstBuffer->getOffsetPointer(pRegion.dstOffset), pRegion.size, pRegion.srcOffset);
}
......@@ -112,7 +114,7 @@ void Buffer::fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data)
ASSERT((bytes + dstOffset) <= size);
uint32_t* memToWrite = static_cast<uint32_t*>(getOffsetPointer(dstOffset));
uint32_t *memToWrite = static_cast<uint32_t *>(getOffsetPointer(dstOffset));
// Vulkan 1.1 spec: "If VK_WHOLE_SIZE is used and the remaining size of the buffer is
// not a multiple of 4, then the nearest smaller multiple is used."
......@@ -122,21 +124,21 @@ void Buffer::fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data)
}
}
void Buffer::update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData)
void Buffer::update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData)
{
ASSERT((dataSize + dstOffset) <= size);
memcpy(getOffsetPointer(dstOffset), pData, dataSize);
}
void* Buffer::getOffsetPointer(VkDeviceSize offset) const
void *Buffer::getOffsetPointer(VkDeviceSize offset) const
{
return reinterpret_cast<uint8_t*>(memory) + offset;
return reinterpret_cast<uint8_t *>(memory) + offset;
}
uint8_t* Buffer::end() const
uint8_t *Buffer::end() const
{
return reinterpret_cast<uint8_t*>(getOffsetPointer(size + 1));
return reinterpret_cast<uint8_t *>(getOffsetPointer(size + 1));
}
} // namespace vk
......@@ -24,40 +24,40 @@ class DeviceMemory;
class Buffer : public Object<Buffer, VkBuffer>
{
public:
Buffer(const VkBufferCreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator);
Buffer(const VkBufferCreateInfo *pCreateInfo, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkBufferCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkBufferCreateInfo *pCreateInfo);
const VkMemoryRequirements getMemoryRequirements() const;
void bind(DeviceMemory* pDeviceMemory, VkDeviceSize pMemoryOffset);
void copyFrom(const void* srcMemory, VkDeviceSize size, VkDeviceSize offset);
void copyTo(void* dstMemory, VkDeviceSize size, VkDeviceSize offset) const;
void copyTo(Buffer* dstBuffer, const VkBufferCopy& pRegion) const;
void bind(DeviceMemory *pDeviceMemory, VkDeviceSize pMemoryOffset);
void copyFrom(const void *srcMemory, VkDeviceSize size, VkDeviceSize offset);
void copyTo(void *dstMemory, VkDeviceSize size, VkDeviceSize offset) const;
void copyTo(Buffer *dstBuffer, const VkBufferCopy &pRegion) const;
void fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data);
void update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData);
void* getOffsetPointer(VkDeviceSize offset) const;
void update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData);
void *getOffsetPointer(VkDeviceSize offset) const;
inline VkDeviceSize getSize() const { return size; }
uint8_t* end() const;
bool canBindToMemory(DeviceMemory* pDeviceMemory) const;
uint8_t *end() const;
bool canBindToMemory(DeviceMemory *pDeviceMemory) const;
private:
void* memory = nullptr;
VkBufferCreateFlags flags = 0;
VkDeviceSize size = 0;
VkBufferUsageFlags usage = 0;
VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE;
uint32_t queueFamilyIndexCount = 0;
uint32_t* queueFamilyIndices = nullptr;
void *memory = nullptr;
VkBufferCreateFlags flags = 0;
VkDeviceSize size = 0;
VkBufferUsageFlags usage = 0;
VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE;
uint32_t queueFamilyIndexCount = 0;
uint32_t *queueFamilyIndices = nullptr;
VkExternalMemoryHandleTypeFlags supportedExternalMemoryHandleTypes = (VkExternalMemoryHandleTypeFlags)0;
};
static inline Buffer* Cast(VkBuffer object)
static inline Buffer *Cast(VkBuffer object)
{
return Buffer::Cast(object);
}
} // namespace vk
#endif // VK_BUFFER_HPP_
#endif // VK_BUFFER_HPP_
......@@ -18,22 +18,24 @@
namespace vk {
BufferView::BufferView(const VkBufferViewCreateInfo* pCreateInfo, void* mem) :
buffer(vk::Cast(pCreateInfo->buffer)), format(pCreateInfo->format), offset(pCreateInfo->offset)
BufferView::BufferView(const VkBufferViewCreateInfo *pCreateInfo, void *mem)
: buffer(vk::Cast(pCreateInfo->buffer))
, format(pCreateInfo->format)
, offset(pCreateInfo->offset)
{
if(pCreateInfo->range == VK_WHOLE_SIZE)
{
range = buffer->getSize() - offset;
}
else
{
range = pCreateInfo->range;
}
if(pCreateInfo->range == VK_WHOLE_SIZE)
{
range = buffer->getSize() - offset;
}
else
{
range = pCreateInfo->range;
}
}
void * BufferView::getPointer() const
void *BufferView::getPointer() const
{
return buffer->getOffsetPointer(offset);
return buffer->getOffsetPointer(offset);
}
} // namespace vk
\ No newline at end of file
......@@ -15,9 +15,9 @@
#ifndef VK_BUFFER_VIEW_HPP_
#define VK_BUFFER_VIEW_HPP_
#include "VkObject.hpp"
#include "VkFormat.h"
#include "VkImageView.hpp"
#include "VkObject.hpp"
namespace vk {
......@@ -26,9 +26,9 @@ class Buffer;
class BufferView : public Object<BufferView, VkBufferView>
{
public:
BufferView(const VkBufferViewCreateInfo* pCreateInfo, void* mem);
BufferView(const VkBufferViewCreateInfo *pCreateInfo, void *mem);
static size_t ComputeRequiredAllocationSize(const VkBufferViewCreateInfo* pCreateInfo)
static size_t ComputeRequiredAllocationSize(const VkBufferViewCreateInfo *pCreateInfo)
{
return 0;
}
......@@ -38,19 +38,19 @@ public:
uint32_t getRangeInBytes() const { return static_cast<uint32_t>(range); }
VkFormat getFormat() const { return format; }
const uint32_t id = ImageView::nextID++; // ID space for sampling function cache, shared with imageviews
const uint32_t id = ImageView::nextID++; // ID space for sampling function cache, shared with imageviews
private:
Buffer *buffer;
VkFormat format;
Buffer *buffer;
VkFormat format;
VkDeviceSize offset;
VkDeviceSize range;
};
static inline BufferView* Cast(VkBufferView object)
static inline BufferView *Cast(VkBufferView object)
{
return BufferView::Cast(object);
}
} // namespace vk
#endif // VK_BUFFER_VIEW_HPP_
#endif // VK_BUFFER_VIEW_HPP_
......@@ -20,16 +20,16 @@
namespace vk {
CommandPool::CommandPool(const VkCommandPoolCreateInfo* pCreateInfo, void* mem)
CommandPool::CommandPool(const VkCommandPoolCreateInfo *pCreateInfo, void *mem)
{
// FIXME (b/119409619): use an allocator here so we can control all memory allocations
void* deviceMemory = vk::allocate(sizeof(std::set<VkCommandBuffer>), REQUIRED_MEMORY_ALIGNMENT,
void *deviceMemory = vk::allocate(sizeof(std::set<VkCommandBuffer>), REQUIRED_MEMORY_ALIGNMENT,
DEVICE_MEMORY, GetAllocationScope());
ASSERT(deviceMemory);
commandBuffers = new (deviceMemory) std::set<VkCommandBuffer>();
commandBuffers = new(deviceMemory) std::set<VkCommandBuffer>();
}
void CommandPool::destroy(const VkAllocationCallbacks* pAllocator)
void CommandPool::destroy(const VkAllocationCallbacks *pAllocator)
{
// Free command Buffers allocated in allocateCommandBuffers
for(auto commandBuffer : *commandBuffers)
......@@ -41,20 +41,20 @@ void CommandPool::destroy(const VkAllocationCallbacks* pAllocator)
vk::deallocate(commandBuffers, DEVICE_MEMORY);
}
size_t CommandPool::ComputeRequiredAllocationSize(const VkCommandPoolCreateInfo* pCreateInfo)
size_t CommandPool::ComputeRequiredAllocationSize(const VkCommandPoolCreateInfo *pCreateInfo)
{
return 0;
}
VkResult CommandPool::allocateCommandBuffers(VkCommandBufferLevel level, uint32_t commandBufferCount, VkCommandBuffer* pCommandBuffers)
VkResult CommandPool::allocateCommandBuffers(VkCommandBufferLevel level, uint32_t commandBufferCount, VkCommandBuffer *pCommandBuffers)
{
for(uint32_t i = 0; i < commandBufferCount; i++)
{
// FIXME (b/119409619): use an allocator here so we can control all memory allocations
void* deviceMemory = vk::allocate(sizeof(DispatchableCommandBuffer), REQUIRED_MEMORY_ALIGNMENT,
void *deviceMemory = vk::allocate(sizeof(DispatchableCommandBuffer), REQUIRED_MEMORY_ALIGNMENT,
DEVICE_MEMORY, DispatchableCommandBuffer::GetAllocationScope());
ASSERT(deviceMemory);
DispatchableCommandBuffer* commandBuffer = new (deviceMemory) DispatchableCommandBuffer(level);
DispatchableCommandBuffer *commandBuffer = new(deviceMemory) DispatchableCommandBuffer(level);
if(commandBuffer)
{
pCommandBuffers[i] = *commandBuffer;
......@@ -78,7 +78,7 @@ VkResult CommandPool::allocateCommandBuffers(VkCommandBufferLevel level, uint32_
return VK_SUCCESS;
}
void CommandPool::freeCommandBuffers(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers)
void CommandPool::freeCommandBuffers(uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers)
{
for(uint32_t i = 0; i < commandBufferCount; ++i)
{
......
......@@ -23,25 +23,25 @@ namespace vk {
class CommandPool : public Object<CommandPool, VkCommandPool>
{
public:
CommandPool(const VkCommandPoolCreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator);
CommandPool(const VkCommandPoolCreateInfo *pCreateInfo, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkCommandPoolCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkCommandPoolCreateInfo *pCreateInfo);
VkResult allocateCommandBuffers(VkCommandBufferLevel level, uint32_t commandBufferCount, VkCommandBuffer* pCommandBuffers);
void freeCommandBuffers(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers);
VkResult allocateCommandBuffers(VkCommandBufferLevel level, uint32_t commandBufferCount, VkCommandBuffer *pCommandBuffers);
void freeCommandBuffers(uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers);
VkResult reset(VkCommandPoolResetFlags flags);
void trim(VkCommandPoolTrimFlags flags);
private:
std::set<VkCommandBuffer>* commandBuffers;
std::set<VkCommandBuffer> *commandBuffers;
};
static inline CommandPool* Cast(VkCommandPool object)
static inline CommandPool *Cast(VkCommandPool object)
{
return CommandPool::Cast(object);
}
} // namespace vk
#endif // VK_COMMAND_POOL_HPP_
#endif // VK_COMMAND_POOL_HPP_
......@@ -14,19 +14,19 @@
#include "VkDebug.hpp"
#include <string>
#include <atomic>
#include <stdarg.h>
#include <atomic>
#include <string>
#if defined(__unix__)
#define PTRACE
#include <sys/types.h>
#include <sys/ptrace.h>
# define PTRACE
# include <sys/ptrace.h>
# include <sys/types.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <windows.h>
# include <windows.h>
#elif defined(__APPLE__) || defined(__MACH__)
#include <unistd.h>
#include <sys/sysctl.h>
# include <sys/sysctl.h>
# include <unistd.h>
#endif
namespace {
......@@ -140,7 +140,7 @@ void abort(const char *format, ...)
void trace_assert(const char *format, ...)
{
static std::atomic<bool> asserted = {false};
static std::atomic<bool> asserted = { false };
va_list vararg;
va_start(vararg, format);
......
......@@ -17,19 +17,19 @@
#ifndef VK_DEBUG_H_
#define VK_DEBUG_H_
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#if !defined(TRACE_OUTPUT_FILE)
#define TRACE_OUTPUT_FILE "debug.txt"
# define TRACE_OUTPUT_FILE "debug.txt"
#endif
#if defined(__GNUC__) || defined(__clang__)
#define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2)))
# define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2)))
#else
#define CHECK_PRINTF_ARGS
# define CHECK_PRINTF_ARGS
#endif
namespace vk {
......@@ -53,11 +53,11 @@ void trace_assert(const char *format, ...) CHECK_PRINTF_ARGS;
// A macro to output a trace of a function call and its arguments to the
// debugging log. Disabled if SWIFTSHADER_DISABLE_TRACE is defined.
#if defined(SWIFTSHADER_DISABLE_TRACE)
#define TRACE(message, ...) (void(0))
#define TRACE_ASSERT(message, ...) (void(0))
# define TRACE(message, ...) (void(0))
# define TRACE_ASSERT(message, ...) (void(0))
#else
#define TRACE(message, ...) vk::trace("%s:%d TRACE: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define TRACE_ASSERT(message, ...) vk::trace_assert("%s:%d %s TRACE_ASSERT: " message "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
# define TRACE(message, ...) vk::trace("%s:%d TRACE: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
# define TRACE_ASSERT(message, ...) vk::trace_assert("%s:%d %s TRACE_ASSERT: " message "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#endif
// A macro to print a warning message to the debugging log and stderr to denote
......@@ -81,26 +81,34 @@ void trace_assert(const char *format, ...) CHECK_PRINTF_ARGS;
// WARN() in release builds (NDEBUG && !DCHECK_ALWAYS_ON)
#undef DABORT
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#define DABORT(message, ...) ABORT(message, ##__VA_ARGS__)
# define DABORT(message, ...) ABORT(message, ##__VA_ARGS__)
#else
#define DABORT(message, ...) WARN(message, ##__VA_ARGS__)
# define DABORT(message, ...) WARN(message, ##__VA_ARGS__)
#endif
// A macro asserting a condition.
// If the condition fails, the condition and message is passed to DABORT().
#undef ASSERT_MSG
#define ASSERT_MSG(expression, format, ...) do { \
if(!(expression)) { \
DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \
} } while(0)
#define ASSERT_MSG(expression, format, ...) \
do \
{ \
if(!(expression)) \
{ \
DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \
} \
} while(0)
// A macro asserting a condition.
// If the condition fails, the condition is passed to DABORT().
#undef ASSERT
#define ASSERT(expression) do { \
if(!(expression)) { \
DABORT("ASSERT(%s)\n", #expression); \
} } while(0)
#define ASSERT(expression) \
do \
{ \
if(!(expression)) \
{ \
DABORT("ASSERT(%s)\n", #expression); \
} \
} while(0)
// A macro to indicate functionality currently unimplemented for a feature
// advertised as supported. For unsupported features not advertised as supported
......@@ -124,12 +132,16 @@ void trace_assert(const char *format, ...) CHECK_PRINTF_ARGS;
// A macro asserting a condition and performing a return.
#undef ASSERT_OR_RETURN
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#define ASSERT_OR_RETURN(expression) ASSERT(expression)
# define ASSERT_OR_RETURN(expression) ASSERT(expression)
#else
#define ASSERT_OR_RETURN(expression) do { \
if(!(expression)) { \
return; \
} } while(0)
# define ASSERT_OR_RETURN(expression) \
do \
{ \
if(!(expression)) \
{ \
return; \
} \
} while(0)
#endif
#endif // VK_DEBUG_H_
#endif // VK_DEBUG_H_
......@@ -20,35 +20,34 @@
#include <algorithm>
#include <memory>
namespace
{
namespace {
inline VkDescriptorSet asDescriptorSet(uint8_t* memory)
inline VkDescriptorSet asDescriptorSet(uint8_t *memory)
{
return vk::TtoVkT<vk::DescriptorSet, VkDescriptorSet>(reinterpret_cast<vk::DescriptorSet*>(memory));
return vk::TtoVkT<vk::DescriptorSet, VkDescriptorSet>(reinterpret_cast<vk::DescriptorSet *>(memory));
}
inline uint8_t* asMemory(VkDescriptorSet descriptorSet)
inline uint8_t *asMemory(VkDescriptorSet descriptorSet)
{
return reinterpret_cast<uint8_t*>(vk::Cast(descriptorSet));
return reinterpret_cast<uint8_t *>(vk::Cast(descriptorSet));
}
} // anonymous namespace
namespace vk {
DescriptorPool::DescriptorPool(const VkDescriptorPoolCreateInfo* pCreateInfo, void* mem) :
pool(static_cast<uint8_t*>(mem)),
poolSize(ComputeRequiredAllocationSize(pCreateInfo))
DescriptorPool::DescriptorPool(const VkDescriptorPoolCreateInfo *pCreateInfo, void *mem)
: pool(static_cast<uint8_t *>(mem))
, poolSize(ComputeRequiredAllocationSize(pCreateInfo))
{
}
void DescriptorPool::destroy(const VkAllocationCallbacks* pAllocator)
void DescriptorPool::destroy(const VkAllocationCallbacks *pAllocator)
{
vk::deallocate(pool, pAllocator);
}
size_t DescriptorPool::ComputeRequiredAllocationSize(const VkDescriptorPoolCreateInfo* pCreateInfo)
size_t DescriptorPool::ComputeRequiredAllocationSize(const VkDescriptorPoolCreateInfo *pCreateInfo)
{
size_t size = pCreateInfo->maxSets * sw::align(sizeof(DescriptorSetHeader), 16);
......@@ -61,7 +60,7 @@ size_t DescriptorPool::ComputeRequiredAllocationSize(const VkDescriptorPoolCreat
return size;
}
VkResult DescriptorPool::allocateSets(uint32_t descriptorSetCount, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets)
VkResult DescriptorPool::allocateSets(uint32_t descriptorSetCount, const VkDescriptorSetLayout *pSetLayouts, VkDescriptorSet *pDescriptorSets)
{
// FIXME (b/119409619): use an allocator here so we can control all memory allocations
std::unique_ptr<size_t[]> layoutSizes(new size_t[descriptorSetCount]);
......@@ -82,7 +81,7 @@ VkResult DescriptorPool::allocateSets(uint32_t descriptorSetCount, const VkDescr
return result;
}
uint8_t* DescriptorPool::findAvailableMemory(size_t size)
uint8_t *DescriptorPool::findAvailableMemory(size_t size)
{
if(nodes.empty())
{
......@@ -113,7 +112,7 @@ uint8_t* DescriptorPool::findAvailableMemory(size_t size)
++nextIt;
for(auto it = itBegin; nextIt != itEnd; ++it, ++nextIt)
{
uint8_t* freeSpaceStart = it->set + it->size;
uint8_t *freeSpaceStart = it->set + it->size;
freeSpace = nextIt->set - freeSpaceStart;
if(freeSpace >= size)
{
......@@ -124,7 +123,7 @@ uint8_t* DescriptorPool::findAvailableMemory(size_t size)
return nullptr;
}
VkResult DescriptorPool::allocateSets(size_t* sizes, uint32_t numAllocs, VkDescriptorSet* pDescriptorSets)
VkResult DescriptorPool::allocateSets(size_t *sizes, uint32_t numAllocs, VkDescriptorSet *pDescriptorSets)
{
size_t totalSize = 0;
for(uint32_t i = 0; i < numAllocs; i++)
......@@ -139,7 +138,7 @@ VkResult DescriptorPool::allocateSets(size_t* sizes, uint32_t numAllocs, VkDescr
// Attempt to allocate single chunk of memory
{
uint8_t* memory = findAvailableMemory(totalSize);
uint8_t *memory = findAvailableMemory(totalSize);
if(memory)
{
for(uint32_t i = 0; i < numAllocs; i++)
......@@ -156,7 +155,7 @@ VkResult DescriptorPool::allocateSets(size_t* sizes, uint32_t numAllocs, VkDescr
// Atttempt to allocate each descriptor set separately
for(uint32_t i = 0; i < numAllocs; i++)
{
uint8_t* memory = findAvailableMemory(sizes[i]);
uint8_t *memory = findAvailableMemory(sizes[i]);
if(memory)
{
pDescriptorSets[i] = asDescriptorSet(memory);
......@@ -180,7 +179,7 @@ VkResult DescriptorPool::allocateSets(size_t* sizes, uint32_t numAllocs, VkDescr
return VK_SUCCESS;
}
void DescriptorPool::freeSets(uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets)
void DescriptorPool::freeSets(uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets)
{
for(uint32_t i = 0; i < descriptorSetCount; i++)
{
......
......@@ -23,41 +23,44 @@ namespace vk {
class DescriptorPool : public Object<DescriptorPool, VkDescriptorPool>
{
public:
DescriptorPool(const VkDescriptorPoolCreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator);
DescriptorPool(const VkDescriptorPoolCreateInfo *pCreateInfo, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkDescriptorPoolCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkDescriptorPoolCreateInfo *pCreateInfo);
VkResult allocateSets(uint32_t descriptorSetCount, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets);
void freeSets(uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets);
VkResult allocateSets(uint32_t descriptorSetCount, const VkDescriptorSetLayout *pSetLayouts, VkDescriptorSet *pDescriptorSets);
void freeSets(uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets);
VkResult reset();
private:
VkResult allocateSets(size_t* sizes, uint32_t numAllocs, VkDescriptorSet* pDescriptorSets);
uint8_t* findAvailableMemory(size_t size);
VkResult allocateSets(size_t *sizes, uint32_t numAllocs, VkDescriptorSet *pDescriptorSets);
uint8_t *findAvailableMemory(size_t size);
void freeSet(const VkDescriptorSet descriptorSet);
size_t computeTotalFreeSize() const;
struct Node
{
Node(uint8_t* set, size_t size) : set(set), size(size) {}
bool operator<(const Node& node) const { return set < node.set; }
bool operator==(const uint8_t* other) const { return set == other; }
Node(uint8_t *set, size_t size)
: set(set)
, size(size)
{}
bool operator<(const Node &node) const { return set < node.set; }
bool operator==(const uint8_t *other) const { return set == other; }
uint8_t* set = nullptr;
uint8_t *set = nullptr;
size_t size = 0;
};
std::set<Node> nodes;
uint8_t* pool = nullptr;
uint8_t *pool = nullptr;
size_t poolSize = 0;
};
static inline DescriptorPool* Cast(VkDescriptorPool object)
static inline DescriptorPool *Cast(VkDescriptorPool object)
{
return DescriptorPool::Cast(object);
}
} // namespace vk
#endif // VK_DESCRIPTOR_POOL_HPP_
#endif // VK_DESCRIPTOR_POOL_HPP_
......@@ -26,29 +26,29 @@ class DescriptorSetLayout;
struct alignas(16) DescriptorSetHeader
{
DescriptorSetLayout* layout;
DescriptorSetLayout *layout;
};
class alignas(16) DescriptorSet
{
public:
static inline DescriptorSet* Cast(VkDescriptorSet object)
static inline DescriptorSet *Cast(VkDescriptorSet object)
{
return static_cast<DescriptorSet*>(static_cast<void*>(object));
return static_cast<DescriptorSet *>(static_cast<void *>(object));
}
using Bindings = std::array<vk::DescriptorSet*, vk::MAX_BOUND_DESCRIPTOR_SETS>;
using Bindings = std::array<vk::DescriptorSet *, vk::MAX_BOUND_DESCRIPTOR_SETS>;
using DynamicOffsets = std::array<uint32_t, vk::MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC>;
DescriptorSetHeader header;
alignas(16) uint8_t data[1];
};
inline DescriptorSet* Cast(VkDescriptorSet object)
inline DescriptorSet *Cast(VkDescriptorSet object)
{
return DescriptorSet::Cast(object);
}
} // namespace vk
#endif // VK_DESCRIPTOR_SET_HPP_
#endif // VK_DESCRIPTOR_SET_HPP_
......@@ -17,9 +17,9 @@
#include "VkObject.hpp"
#include "Vulkan/VkSampler.hpp"
#include "Vulkan/VkImageView.hpp"
#include "Device/Sampler.hpp"
#include "Vulkan/VkImageView.hpp"
#include "Vulkan/VkSampler.hpp"
namespace vk {
......@@ -35,14 +35,14 @@ struct alignas(16) SampledImageDescriptor
// TODO(b/129523279): Minimize to the data actually needed.
vk::Sampler sampler;
vk::Device* device;
vk::Device *device;
uint32_t imageViewId;
VkImageViewType type;
VkFormat format;
VkComponentMapping swizzle;
alignas(16) sw::Texture texture;
VkExtent3D extent; // Of base mip-level.
VkExtent3D extent; // Of base mip-level.
int arrayLayers;
int mipLevels;
int sampleCount;
......@@ -72,26 +72,26 @@ struct alignas(16) BufferDescriptor
~BufferDescriptor() = delete;
void *ptr;
int sizeInBytes; // intended size of the bound region -- slides along with dynamic offsets
int robustnessSize; // total accessible size from static offset -- does not move with dynamic offset
int sizeInBytes; // intended size of the bound region -- slides along with dynamic offsets
int robustnessSize; // total accessible size from static offset -- does not move with dynamic offset
};
class DescriptorSetLayout : public Object<DescriptorSetLayout, VkDescriptorSetLayout>
{
public:
DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator);
DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *pCreateInfo, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkDescriptorSetLayoutCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkDescriptorSetLayoutCreateInfo *pCreateInfo);
static size_t GetDescriptorSize(VkDescriptorType type);
static void WriteDescriptorSet(Device* device, const VkWriteDescriptorSet& descriptorWrites);
static void CopyDescriptorSet(const VkCopyDescriptorSet& descriptorCopies);
static void WriteDescriptorSet(Device *device, const VkWriteDescriptorSet &descriptorWrites);
static void CopyDescriptorSet(const VkCopyDescriptorSet &descriptorCopies);
static void WriteDescriptorSet(Device* device, DescriptorSet *dstSet, VkDescriptorUpdateTemplateEntry const &entry, char const *src);
static void WriteDescriptorSet(Device *device, DescriptorSet *dstSet, VkDescriptorUpdateTemplateEntry const &entry, char const *src);
static void WriteTextureLevelInfo(sw::Texture *texture, int level, int width, int height, int depth, int pitchP, int sliceP, int samplePitchP, int sampleMax);
void initialize(DescriptorSet* descriptorSet);
void initialize(DescriptorSet *descriptorSet);
// Returns the total size of the descriptor set in bytes.
size_t getDescriptorSetAllocationSize() const;
......@@ -125,9 +125,9 @@ public:
bool isBindingDynamic(uint32_t binding) const;
// Returns the VkDescriptorSetLayoutBinding for the given binding.
VkDescriptorSetLayoutBinding const & getBindingLayout(uint32_t binding) const;
VkDescriptorSetLayoutBinding const &getBindingLayout(uint32_t binding) const;
uint8_t* getOffsetPointer(DescriptorSet *descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t* typeSize) const;
uint8_t *getOffsetPointer(DescriptorSet *descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t *typeSize) const;
private:
size_t getDescriptorSetDataSize() const;
......@@ -135,16 +135,16 @@ private:
static bool isDynamic(VkDescriptorType type);
VkDescriptorSetLayoutCreateFlags flags;
uint32_t bindingCount;
VkDescriptorSetLayoutBinding* bindings;
size_t* bindingOffsets;
uint32_t bindingCount;
VkDescriptorSetLayoutBinding *bindings;
size_t *bindingOffsets;
};
static inline DescriptorSetLayout* Cast(VkDescriptorSetLayout object)
static inline DescriptorSetLayout *Cast(VkDescriptorSetLayout object)
{
return DescriptorSetLayout::Cast(object);
}
} // namespace vk
#endif // VK_DESCRIPTOR_SET_LAYOUT_HPP_
#endif // VK_DESCRIPTOR_SET_LAYOUT_HPP_
......@@ -19,10 +19,10 @@
namespace vk {
DescriptorUpdateTemplate::DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, void* mem) :
descriptorUpdateEntryCount(pCreateInfo->descriptorUpdateEntryCount),
descriptorUpdateEntries(reinterpret_cast<VkDescriptorUpdateTemplateEntry*>(mem)),
descriptorSetLayout(vk::Cast(pCreateInfo->descriptorSetLayout))
DescriptorUpdateTemplate::DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, void *mem)
: descriptorUpdateEntryCount(pCreateInfo->descriptorUpdateEntryCount)
, descriptorUpdateEntries(reinterpret_cast<VkDescriptorUpdateTemplateEntry *>(mem))
, descriptorSetLayout(vk::Cast(pCreateInfo->descriptorSetLayout))
{
for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)
{
......@@ -30,20 +30,20 @@ DescriptorUpdateTemplate::DescriptorUpdateTemplate(const VkDescriptorUpdateTempl
}
}
size_t DescriptorUpdateTemplate::ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info)
size_t DescriptorUpdateTemplate::ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo *info)
{
return info->descriptorUpdateEntryCount * sizeof(VkDescriptorUpdateTemplateEntry);
}
void DescriptorUpdateTemplate::updateDescriptorSet(Device* device, VkDescriptorSet vkDescriptorSet, const void* pData)
void DescriptorUpdateTemplate::updateDescriptorSet(Device *device, VkDescriptorSet vkDescriptorSet, const void *pData)
{
DescriptorSet* descriptorSet = vk::Cast(vkDescriptorSet);
DescriptorSet *descriptorSet = vk::Cast(vkDescriptorSet);
for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)
{
DescriptorSetLayout::WriteDescriptorSet(device, descriptorSet, descriptorUpdateEntries[i],
reinterpret_cast<char const *>(pData));
reinterpret_cast<char const *>(pData));
}
}
......
......@@ -25,23 +25,23 @@ class Device;
class DescriptorUpdateTemplate : public Object<DescriptorUpdateTemplate, VkDescriptorUpdateTemplate>
{
public:
DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, void* mem);
DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, void *mem);
static size_t ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info);
static size_t ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo *info);
void updateDescriptorSet(Device* device, VkDescriptorSet descriptorSet, const void* pData);
void updateDescriptorSet(Device *device, VkDescriptorSet descriptorSet, const void *pData);
private:
uint32_t descriptorUpdateEntryCount = 0;
VkDescriptorUpdateTemplateEntry* descriptorUpdateEntries = nullptr;
DescriptorSetLayout* descriptorSetLayout = nullptr;
uint32_t descriptorUpdateEntryCount = 0;
VkDescriptorUpdateTemplateEntry *descriptorUpdateEntries = nullptr;
DescriptorSetLayout *descriptorSetLayout = nullptr;
};
static inline DescriptorUpdateTemplate* Cast(VkDescriptorUpdateTemplate object)
static inline DescriptorUpdateTemplate *Cast(VkDescriptorUpdateTemplate object)
{
return DescriptorUpdateTemplate::Cast(object);
}
} // namespace vk
#endif // VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_
#endif // VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_
......@@ -23,7 +23,7 @@
#include <chrono>
#include <climits>
#include <new> // Must #include this to use "placement new"
#include <new> // Must #include this to use "placement new"
namespace {
......@@ -36,18 +36,18 @@ std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> now
namespace vk {
std::shared_ptr<rr::Routine> Device::SamplingRoutineCache::query(const vk::Device::SamplingRoutineCache::Key& key) const
std::shared_ptr<rr::Routine> Device::SamplingRoutineCache::query(const vk::Device::SamplingRoutineCache::Key &key) const
{
return cache.query(key);
}
void Device::SamplingRoutineCache::add(const vk::Device::SamplingRoutineCache::Key& key, const std::shared_ptr<rr::Routine>& routine)
void Device::SamplingRoutineCache::add(const vk::Device::SamplingRoutineCache::Key &key, const std::shared_ptr<rr::Routine> &routine)
{
ASSERT(routine);
cache.add(key, routine);
}
rr::Routine* Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key& key) const
rr::Routine *Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key &key) const
{
return cache.queryConstCache(key).get();
}
......@@ -57,31 +57,32 @@ void Device::SamplingRoutineCache::updateConstCache()
cache.updateConstCache();
}
Device::Device(const VkDeviceCreateInfo* pCreateInfo, void* mem, PhysicalDevice *physicalDevice, const VkPhysicalDeviceFeatures *enabledFeatures, const std::shared_ptr<marl::Scheduler>& scheduler)
: physicalDevice(physicalDevice),
queues(reinterpret_cast<Queue*>(mem)),
enabledExtensionCount(pCreateInfo->enabledExtensionCount),
enabledFeatures(enabledFeatures ? *enabledFeatures : VkPhysicalDeviceFeatures{}), // "Setting pEnabledFeatures to NULL and not including a VkPhysicalDeviceFeatures2 in the pNext member of VkDeviceCreateInfo is equivalent to setting all members of the structure to VK_FALSE."
scheduler(scheduler)
Device::Device(const VkDeviceCreateInfo *pCreateInfo, void *mem, PhysicalDevice *physicalDevice, const VkPhysicalDeviceFeatures *enabledFeatures, const std::shared_ptr<marl::Scheduler> &scheduler)
: physicalDevice(physicalDevice)
, queues(reinterpret_cast<Queue *>(mem))
, enabledExtensionCount(pCreateInfo->enabledExtensionCount)
, enabledFeatures(enabledFeatures ? *enabledFeatures : VkPhysicalDeviceFeatures{})
, // "Setting pEnabledFeatures to NULL and not including a VkPhysicalDeviceFeatures2 in the pNext member of VkDeviceCreateInfo is equivalent to setting all members of the structure to VK_FALSE."
scheduler(scheduler)
{
for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
{
const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
const VkDeviceQueueCreateInfo &queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
queueCount += queueCreateInfo.queueCount;
}
uint32_t queueID = 0;
for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
{
const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
const VkDeviceQueueCreateInfo &queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
for(uint32_t j = 0; j < queueCreateInfo.queueCount; j++, queueID++)
{
new (&queues[queueID]) Queue(this, scheduler.get());
new(&queues[queueID]) Queue(this, scheduler.get());
}
}
extensions = reinterpret_cast<ExtensionName*>(static_cast<uint8_t*>(mem) + (sizeof(Queue) * queueCount));
extensions = reinterpret_cast<ExtensionName *>(static_cast<uint8_t *>(mem) + (sizeof(Queue) * queueCount));
for(uint32_t i = 0; i < enabledExtensionCount; i++)
{
strncpy(extensions[i], pCreateInfo->ppEnabledExtensionNames[i], VK_MAX_EXTENSION_NAME_SIZE);
......@@ -90,7 +91,7 @@ Device::Device(const VkDeviceCreateInfo* pCreateInfo, void* mem, PhysicalDevice
if(pCreateInfo->enabledLayerCount)
{
// "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations."
UNIMPLEMENTED("enabledLayerCount"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
UNIMPLEMENTED("enabledLayerCount"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
}
// FIXME (b/119409619): use an allocator here so we can control all memory allocations
......@@ -98,7 +99,7 @@ Device::Device(const VkDeviceCreateInfo* pCreateInfo, void* mem, PhysicalDevice
samplingRoutineCache.reset(new SamplingRoutineCache());
}
void Device::destroy(const VkAllocationCallbacks* pAllocator)
void Device::destroy(const VkAllocationCallbacks *pAllocator)
{
for(uint32_t i = 0; i < queueCount; i++)
{
......@@ -108,7 +109,7 @@ void Device::destroy(const VkAllocationCallbacks* pAllocator)
vk::deallocate(queues, pAllocator);
}
size_t Device::ComputeRequiredAllocationSize(const VkDeviceCreateInfo* pCreateInfo)
size_t Device::ComputeRequiredAllocationSize(const VkDeviceCreateInfo *pCreateInfo)
{
uint32_t queueCount = 0;
for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
......@@ -119,7 +120,7 @@ size_t Device::ComputeRequiredAllocationSize(const VkDeviceCreateInfo* pCreateIn
return (sizeof(Queue) * queueCount) + (pCreateInfo->enabledExtensionCount * sizeof(ExtensionName));
}
bool Device::hasExtension(const char* extensionName) const
bool Device::hasExtension(const char *extensionName) const
{
for(uint32_t i = 0; i < enabledExtensionCount; i++)
{
......@@ -138,7 +139,7 @@ VkQueue Device::getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex) const
return queues[queueIndex];
}
VkResult Device::waitForFences(uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
VkResult Device::waitForFences(uint32_t fenceCount, const VkFence *pFences, VkBool32 waitAll, uint64_t timeout)
{
using time_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
const time_point start = now();
......@@ -146,27 +147,27 @@ VkResult Device::waitForFences(uint32_t fenceCount, const VkFence* pFences, VkBo
bool infiniteTimeout = (timeout > max_timeout);
const time_point end_ns = start + std::chrono::nanoseconds(std::min(max_timeout, timeout));
if(waitAll != VK_FALSE) // All fences must be signaled
if(waitAll != VK_FALSE) // All fences must be signaled
{
for(uint32_t i = 0; i < fenceCount; i++)
{
if(timeout == 0)
{
if(Cast(pFences[i])->getStatus() != VK_SUCCESS) // At least one fence is not signaled
if(Cast(pFences[i])->getStatus() != VK_SUCCESS) // At least one fence is not signaled
{
return VK_TIMEOUT;
}
}
else if(infiniteTimeout)
{
if(Cast(pFences[i])->wait() != VK_SUCCESS) // At least one fence is not signaled
if(Cast(pFences[i])->wait() != VK_SUCCESS) // At least one fence is not signaled
{
return VK_TIMEOUT;
}
}
else
{
if(Cast(pFences[i])->wait(end_ns) != VK_SUCCESS) // At least one fence is not signaled
if(Cast(pFences[i])->wait(end_ns) != VK_SUCCESS) // At least one fence is not signaled
{
return VK_TIMEOUT;
}
......@@ -175,7 +176,7 @@ VkResult Device::waitForFences(uint32_t fenceCount, const VkFence* pFences, VkBo
return VK_SUCCESS;
}
else // At least one fence must be signaled
else // At least one fence must be signaled
{
marl::containers::vector<marl::Event, 8> events;
for(uint32_t i = 0; i < fenceCount; i++)
......@@ -211,8 +212,8 @@ VkResult Device::waitIdle()
return VK_SUCCESS;
}
void Device::getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
VkDescriptorSetLayoutSupport* pSupport) const
void Device::getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
VkDescriptorSetLayoutSupport *pSupport) const
{
// From Vulkan Spec 13.2.1 Descriptor Set Layout, in description of vkGetDescriptorSetLayoutSupport:
// "This command does not consider other limits such as maxPerStageDescriptor*, and so a descriptor
......@@ -223,8 +224,8 @@ void Device::getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo
pSupport->supported = VK_TRUE;
}
void Device::updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites,
uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies)
void Device::updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies)
{
for(uint32_t i = 0; i < descriptorWriteCount; i++)
{
......@@ -237,18 +238,18 @@ void Device::updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDe
}
}
void Device::getRequirements(VkMemoryDedicatedRequirements* requirements) const
void Device::getRequirements(VkMemoryDedicatedRequirements *requirements) const
{
requirements->prefersDedicatedAllocation = VK_FALSE;
requirements->requiresDedicatedAllocation = VK_FALSE;
}
Device::SamplingRoutineCache* Device::getSamplingRoutineCache() const
Device::SamplingRoutineCache *Device::getSamplingRoutineCache() const
{
return samplingRoutineCache.get();
}
rr::Routine* Device::findInConstCache(const SamplingRoutineCache::Key& key) const
rr::Routine *Device::findInConstCache(const SamplingRoutineCache::Key &key) const
{
return samplingRoutineCache->queryConst(key);
}
......@@ -259,7 +260,7 @@ void Device::updateSamplingRoutineConstCache()
samplingRoutineCache->updateConstCache();
}
std::mutex& Device::getSamplingRoutineCacheMutex()
std::mutex &Device::getSamplingRoutineCacheMutex()
{
return samplingRoutineCacheMutex;
}
......
......@@ -21,8 +21,12 @@
#include <memory>
#include <mutex>
namespace marl { class Scheduler; }
namespace sw { class Blitter; }
namespace marl {
class Scheduler;
}
namespace sw {
class Blitter;
}
namespace vk {
......@@ -34,28 +38,30 @@ class Device
public:
static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_DEVICE; }
Device(const VkDeviceCreateInfo* pCreateInfo, void* mem, PhysicalDevice *physicalDevice, const VkPhysicalDeviceFeatures *enabledFeatures, const std::shared_ptr<marl::Scheduler>& scheduler);
void destroy(const VkAllocationCallbacks* pAllocator);
Device(const VkDeviceCreateInfo *pCreateInfo, void *mem, PhysicalDevice *physicalDevice, const VkPhysicalDeviceFeatures *enabledFeatures, const std::shared_ptr<marl::Scheduler> &scheduler);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkDeviceCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkDeviceCreateInfo *pCreateInfo);
bool hasExtension(const char* extensionName) const;
bool hasExtension(const char *extensionName) const;
VkQueue getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex) const;
VkResult waitForFences(uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout);
VkResult waitForFences(uint32_t fenceCount, const VkFence *pFences, VkBool32 waitAll, uint64_t timeout);
VkResult waitIdle();
void getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
VkDescriptorSetLayoutSupport* pSupport) const;
void getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
VkDescriptorSetLayoutSupport *pSupport) const;
PhysicalDevice *getPhysicalDevice() const { return physicalDevice; }
void updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites,
uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies);
void getRequirements(VkMemoryDedicatedRequirements* requirements) const;
void updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies);
void getRequirements(VkMemoryDedicatedRequirements *requirements) const;
const VkPhysicalDeviceFeatures &getEnabledFeatures() const { return enabledFeatures; }
sw::Blitter* getBlitter() const { return blitter.get(); }
sw::Blitter *getBlitter() const { return blitter.get(); }
class SamplingRoutineCache
{
public:
SamplingRoutineCache() : cache(1024) {}
SamplingRoutineCache()
: cache(1024)
{}
~SamplingRoutineCache() {}
struct Key
......@@ -64,27 +70,27 @@ public:
uint32_t sampler;
uint32_t imageView;
inline bool operator == (const Key& rhs) const;
inline bool operator==(const Key &rhs) const;
struct Hash
{
inline std::size_t operator()(const Key& key) const noexcept;
inline std::size_t operator()(const Key &key) const noexcept;
};
};
std::shared_ptr<rr::Routine> query(const Key& key) const;
void add(const Key& key, const std::shared_ptr<rr::Routine>& routine);
std::shared_ptr<rr::Routine> query(const Key &key) const;
void add(const Key &key, const std::shared_ptr<rr::Routine> &routine);
rr::Routine* queryConst(const Key& key) const;
rr::Routine *queryConst(const Key &key) const;
void updateConstCache();
private:
sw::LRUConstCache<Key, std::shared_ptr<rr::Routine>, Key::Hash> cache;
};
SamplingRoutineCache* getSamplingRoutineCache() const;
std::mutex& getSamplingRoutineCacheMutex();
rr::Routine* findInConstCache(const SamplingRoutineCache::Key& key) const;
SamplingRoutineCache *getSamplingRoutineCache() const;
std::mutex &getSamplingRoutineCacheMutex();
rr::Routine *findInConstCache(const SamplingRoutineCache::Key &key) const;
void updateSamplingRoutineConstCache();
private:
......@@ -96,24 +102,24 @@ private:
std::mutex samplingRoutineCacheMutex;
uint32_t enabledExtensionCount = 0;
typedef char ExtensionName[VK_MAX_EXTENSION_NAME_SIZE];
ExtensionName* extensions = nullptr;
ExtensionName *extensions = nullptr;
const VkPhysicalDeviceFeatures enabledFeatures = {};
std::shared_ptr<marl::Scheduler> scheduler;
};
using DispatchableDevice = DispatchableObject<Device, VkDevice>;
static inline Device* Cast(VkDevice object)
static inline Device *Cast(VkDevice object)
{
return DispatchableDevice::Cast(object);
}
inline bool vk::Device::SamplingRoutineCache::Key::operator == (const Key& rhs) const
inline bool vk::Device::SamplingRoutineCache::Key::operator==(const Key &rhs) const
{
return instruction == rhs.instruction && sampler == rhs.sampler && imageView == rhs.imageView;
}
inline std::size_t vk::Device::SamplingRoutineCache::Key::Hash::operator() (const Key& key) const noexcept
inline std::size_t vk::Device::SamplingRoutineCache::Key::Hash::operator()(const Key &key) const noexcept
{
// Combine three 32-bit integers into a 64-bit hash.
// 2642239 is the largest prime which when cubed is smaller than 2^64.
......@@ -125,4 +131,4 @@ inline std::size_t vk::Device::SamplingRoutineCache::Key::Hash::operator() (cons
} // namespace vk
#endif // VK_DEVICE_HPP_
#endif // VK_DEVICE_HPP_
......@@ -24,19 +24,19 @@ class DeviceMemory::ExternalBase
public:
virtual ~ExternalBase() = default;
// Allocate the memory according to |size|. On success return VK_SUCCESS
// and sets |*pBuffer|.
virtual VkResult allocate(size_t size, void** pBuffer) = 0;
// Allocate the memory according to |size|. On success return VK_SUCCESS
// and sets |*pBuffer|.
virtual VkResult allocate(size_t size, void **pBuffer) = 0;
// Deallocate previously allocated memory at |buffer|.
virtual void deallocate(void* buffer, size_t size) = 0;
// Deallocate previously allocated memory at |buffer|.
virtual void deallocate(void *buffer, size_t size) = 0;
// Return the handle type flag bit supported by this implementation.
// A value of 0 corresponds to non-external memory.
// Return the handle type flag bit supported by this implementation.
// A value of 0 corresponds to non-external memory.
virtual VkExternalMemoryHandleTypeFlagBits getFlagBit() const = 0;
#if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
virtual VkResult exportFd(int* pFd) const
virtual VkResult exportFd(int *pFd) const
{
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
}
......@@ -56,24 +56,24 @@ class ExternalMemoryTraits
public:
VkExternalMemoryHandleTypeFlagBits typeFlagBit;
size_t instanceSize;
void (*instanceInit)(void* external, const VkMemoryAllocateInfo* pAllocateInfo);
void (*instanceInit)(void *external, const VkMemoryAllocateInfo *pAllocateInfo);
};
// Template function that parses a |pAllocateInfo.pNext| chain to verify that
// it asks for the creation or import of a memory type managed by implementation
// class T. On success, return true and sets |pTraits| accordingly. Otherwise
// return false.
template <typename T>
static bool parseCreateInfo(const VkMemoryAllocateInfo* pAllocateInfo,
ExternalMemoryTraits* pTraits)
template<typename T>
static bool parseCreateInfo(const VkMemoryAllocateInfo *pAllocateInfo,
ExternalMemoryTraits *pTraits)
{
if(T::supportsAllocateInfo(pAllocateInfo))
{
pTraits->typeFlagBit = T::typeFlagBit;
pTraits->instanceSize = sizeof(T);
pTraits->instanceInit = [](void* external,
const VkMemoryAllocateInfo* pAllocateInfo) {
new (external) T(pAllocateInfo);
pTraits->instanceInit = [](void *external,
const VkMemoryAllocateInfo *pAllocateInfo) {
new(external) T(pAllocateInfo);
};
return true;
}
......@@ -85,20 +85,20 @@ static bool parseCreateInfo(const VkMemoryAllocateInfo* pAllocateInfo,
class DeviceMemoryHostExternalBase : public DeviceMemory::ExternalBase
{
public:
// Does not support any external memory type at all.
// Does not support any external memory type at all.
static const VkExternalMemoryHandleTypeFlagBits typeFlagBit = (VkExternalMemoryHandleTypeFlagBits)0;
// Always return true as is used as a fallback in findTraits() below.
static bool supportsAllocateInfo(const VkMemoryAllocateInfo* pAllocateInfo)
// Always return true as is used as a fallback in findTraits() below.
static bool supportsAllocateInfo(const VkMemoryAllocateInfo *pAllocateInfo)
{
return true;
}
DeviceMemoryHostExternalBase(const VkMemoryAllocateInfo* pAllocateInfo) {}
DeviceMemoryHostExternalBase(const VkMemoryAllocateInfo *pAllocateInfo) {}
VkResult allocate(size_t size, void** pBuffer) override
VkResult allocate(size_t size, void **pBuffer) override
{
void* buffer = vk::allocate(size, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY);
void *buffer = vk::allocate(size, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY);
if(!buffer)
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
......@@ -106,7 +106,7 @@ public:
return VK_SUCCESS;
}
void deallocate(void* buffer, size_t size) override
void deallocate(void *buffer, size_t size) override
{
vk::deallocate(buffer, DEVICE_MEMORY);
}
......@@ -120,17 +120,17 @@ public:
} // namespace vk
#if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
# if defined(__linux__) || defined(__ANDROID__)
# include "VkDeviceMemoryExternalLinux.hpp"
# else
# error "Missing VK_KHR_external_memory_fd implementation for this platform!"
# endif
# if defined(__linux__) || defined(__ANDROID__)
# include "VkDeviceMemoryExternalLinux.hpp"
# else
# error "Missing VK_KHR_external_memory_fd implementation for this platform!"
# endif
#endif
namespace vk {
static void findTraits(const VkMemoryAllocateInfo* pAllocateInfo,
ExternalMemoryTraits* pTraits)
static void findTraits(const VkMemoryAllocateInfo *pAllocateInfo,
ExternalMemoryTraits *pTraits)
{
#if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
if(parseCreateInfo<OpaqueFdExternalMemory>(pAllocateInfo, pTraits))
......@@ -141,9 +141,10 @@ static void findTraits(const VkMemoryAllocateInfo* pAllocateInfo,
parseCreateInfo<DeviceMemoryHostExternalBase>(pAllocateInfo, pTraits);
}
DeviceMemory::DeviceMemory(const VkMemoryAllocateInfo* pAllocateInfo, void* mem) :
size(pAllocateInfo->allocationSize), memoryTypeIndex(pAllocateInfo->memoryTypeIndex),
external(reinterpret_cast<ExternalBase *>(mem))
DeviceMemory::DeviceMemory(const VkMemoryAllocateInfo *pAllocateInfo, void *mem)
: size(pAllocateInfo->allocationSize)
, memoryTypeIndex(pAllocateInfo->memoryTypeIndex)
, external(reinterpret_cast<ExternalBase *>(mem))
{
ASSERT(size);
......@@ -152,7 +153,7 @@ DeviceMemory::DeviceMemory(const VkMemoryAllocateInfo* pAllocateInfo, void* mem)
traits.instanceInit(external, pAllocateInfo);
}
void DeviceMemory::destroy(const VkAllocationCallbacks* pAllocator)
void DeviceMemory::destroy(const VkAllocationCallbacks *pAllocator)
{
if(buffer)
{
......@@ -163,7 +164,7 @@ void DeviceMemory::destroy(const VkAllocationCallbacks* pAllocator)
vk::deallocate(external, pAllocator);
}
size_t DeviceMemory::ComputeRequiredAllocationSize(const VkMemoryAllocateInfo* pAllocateInfo)
size_t DeviceMemory::ComputeRequiredAllocationSize(const VkMemoryAllocateInfo *pAllocateInfo)
{
ExternalMemoryTraits traits;
findTraits(pAllocateInfo, &traits);
......@@ -180,7 +181,7 @@ VkResult DeviceMemory::allocate()
return result;
}
VkResult DeviceMemory::map(VkDeviceSize pOffset, VkDeviceSize pSize, void** ppData)
VkResult DeviceMemory::map(VkDeviceSize pOffset, VkDeviceSize pSize, void **ppData)
{
*ppData = getOffsetPointer(pOffset);
......@@ -192,15 +193,15 @@ VkDeviceSize DeviceMemory::getCommittedMemoryInBytes() const
return size;
}
void* DeviceMemory::getOffsetPointer(VkDeviceSize pOffset) const
void *DeviceMemory::getOffsetPointer(VkDeviceSize pOffset) const
{
ASSERT(buffer);
return reinterpret_cast<char*>(buffer) + pOffset;
return reinterpret_cast<char *>(buffer) + pOffset;
}
bool DeviceMemory::checkExternalMemoryHandleType(
VkExternalMemoryHandleTypeFlags supportedHandleTypes) const
VkExternalMemoryHandleTypeFlags supportedHandleTypes) const
{
if(!supportedHandleTypes)
{
......@@ -222,7 +223,7 @@ bool DeviceMemory::checkExternalMemoryHandleType(
}
#if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
VkResult DeviceMemory::exportFd(int* pFd) const
VkResult DeviceMemory::exportFd(int *pFd) const
{
return external->exportFd(pFd);
}
......
......@@ -23,43 +23,41 @@ namespace vk {
class DeviceMemory : public Object<DeviceMemory, VkDeviceMemory>
{
public:
DeviceMemory(const VkMemoryAllocateInfo* pCreateInfo, void* mem);
DeviceMemory(const VkMemoryAllocateInfo *pCreateInfo, void *mem);
static size_t ComputeRequiredAllocationSize(const VkMemoryAllocateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkMemoryAllocateInfo *pCreateInfo);
#if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
VkResult exportFd(int* pFd) const;
VkResult exportFd(int *pFd) const;
#endif
void destroy(const VkAllocationCallbacks* pAllocator);
void destroy(const VkAllocationCallbacks *pAllocator);
VkResult allocate();
VkResult map(VkDeviceSize offset, VkDeviceSize size, void** ppData);
VkResult map(VkDeviceSize offset, VkDeviceSize size, void **ppData);
VkDeviceSize getCommittedMemoryInBytes() const;
void* getOffsetPointer(VkDeviceSize pOffset) const;
void *getOffsetPointer(VkDeviceSize pOffset) const;
uint32_t getMemoryTypeIndex() const { return memoryTypeIndex; }
// If this is external memory, return true iff its handle type matches the bitmask
// provided by |supportedExternalHandleTypes|. Otherwise, always return true.
bool checkExternalMemoryHandleType(
VkExternalMemoryHandleTypeFlags supportedExternalMemoryHandleType) const;
VkExternalMemoryHandleTypeFlags supportedExternalMemoryHandleType) const;
// Internal implementation class for external memory. Platform-specific.
class ExternalBase;
private:
void* buffer = nullptr;
VkDeviceSize size = 0;
uint32_t memoryTypeIndex = 0;
ExternalBase* external = nullptr;
void *buffer = nullptr;
VkDeviceSize size = 0;
uint32_t memoryTypeIndex = 0;
ExternalBase *external = nullptr;
};
static inline DeviceMemory* Cast(VkDeviceMemory object)
static inline DeviceMemory *Cast(VkDeviceMemory object)
{
return DeviceMemory::Cast(object);
}
} // namespace vk
#endif // VK_DEVICE_MEMORY_HPP_
#endif // VK_DEVICE_MEMORY_HPP_
......@@ -34,16 +34,16 @@ public:
AllocateInfo() = default;
// Parse the VkMemoryAllocateInfo.pNext chain to initialize an AllocateInfo.
AllocateInfo(const VkMemoryAllocateInfo* pAllocateInfo)
AllocateInfo(const VkMemoryAllocateInfo *pAllocateInfo)
{
const auto* createInfo = reinterpret_cast<const VkBaseInStructure*>(pAllocateInfo->pNext);
const auto *createInfo = reinterpret_cast<const VkBaseInStructure *>(pAllocateInfo->pNext);
while(createInfo)
{
switch(createInfo->sType)
{
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR:
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR:
{
const auto* importInfo = reinterpret_cast<const VkImportMemoryFdInfoKHR*>(createInfo);
const auto *importInfo = reinterpret_cast<const VkImportMemoryFdInfoKHR *>(createInfo);
if(importInfo->handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
{
......@@ -53,9 +53,9 @@ public:
fd = importInfo->fd;
}
break;
case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO:
case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO:
{
const auto* exportInfo = reinterpret_cast<const VkExportMemoryAllocateInfo*>(createInfo);
const auto *exportInfo = reinterpret_cast<const VkExportMemoryAllocateInfo *>(createInfo);
if(exportInfo->handleTypes != VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
{
......@@ -65,8 +65,7 @@ public:
}
break;
default:
;
default:;
}
createInfo = createInfo->pNext;
}
......@@ -75,14 +74,14 @@ public:
static const VkExternalMemoryHandleTypeFlagBits typeFlagBit = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
static bool supportsAllocateInfo(const VkMemoryAllocateInfo* pAllocateInfo)
static bool supportsAllocateInfo(const VkMemoryAllocateInfo *pAllocateInfo)
{
AllocateInfo info(pAllocateInfo);
return info.importFd || info.exportFd;
}
explicit OpaqueFdExternalMemory(const VkMemoryAllocateInfo* pAllocateInfo)
: allocateInfo(pAllocateInfo)
explicit OpaqueFdExternalMemory(const VkMemoryAllocateInfo *pAllocateInfo)
: allocateInfo(pAllocateInfo)
{
}
......@@ -91,7 +90,7 @@ public:
memfd.close();
}
VkResult allocate(size_t size, void** pBuffer) override
VkResult allocate(size_t size, void **pBuffer) override
{
if(allocateInfo.importFd)
{
......@@ -113,7 +112,7 @@ public:
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
}
void* addr = memfd.mapReadWrite(0, size);
void *addr = memfd.mapReadWrite(0, size);
if(!addr)
{
return VK_ERROR_MEMORY_MAP_FAILED;
......@@ -122,7 +121,7 @@ public:
return VK_SUCCESS;
}
void deallocate(void* buffer, size_t size) override
void deallocate(void *buffer, size_t size) override
{
memfd.unmap(buffer, size);
}
......@@ -132,7 +131,7 @@ public:
return typeFlagBit;
}
VkResult exportFd(int* pFd) const override
VkResult exportFd(int *pFd) const override
{
int fd = memfd.exportFd();
if(fd < 0)
......@@ -144,6 +143,6 @@ public:
}
private:
LinuxMemFd memfd;
LinuxMemFd memfd;
AllocateInfo allocateInfo;
};
......@@ -24,11 +24,11 @@ namespace vk {
class Event : public Object<Event, VkEvent>
{
public:
Event(const VkEventCreateInfo* pCreateInfo, void* mem)
Event(const VkEventCreateInfo *pCreateInfo, void *mem)
{
}
static size_t ComputeRequiredAllocationSize(const VkEventCreateInfo* pCreateInfo)
static size_t ComputeRequiredAllocationSize(const VkEventCreateInfo *pCreateInfo)
{
return 0;
}
......@@ -62,16 +62,16 @@ public:
}
private:
VkResult status = VK_EVENT_RESET; // guarded by mutex
VkResult status = VK_EVENT_RESET; // guarded by mutex
std::mutex mutex;
std::condition_variable condition;
};
static inline Event* Cast(VkEvent object)
static inline Event *Cast(VkEvent object)
{
return Event::Cast(object);
}
} // namespace vk
#endif // VK_EVENT_HPP_
#endif // VK_EVENT_HPP_
......@@ -27,10 +27,11 @@ namespace vk {
class Fence : public Object<Fence, VkFence>, public sw::TaskEvents
{
public:
Fence(const VkFenceCreateInfo* pCreateInfo, void* mem) :
event(marl::Event::Mode::Manual, (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) != 0) {}
Fence(const VkFenceCreateInfo *pCreateInfo, void *mem)
: event(marl::Event::Mode::Manual, (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) != 0)
{}
static size_t ComputeRequiredAllocationSize(const VkFenceCreateInfo* pCreateInfo)
static size_t ComputeRequiredAllocationSize(const VkFenceCreateInfo *pCreateInfo)
{
return 0;
}
......@@ -51,13 +52,13 @@ public:
return VK_SUCCESS;
}
template <class CLOCK, class DURATION>
VkResult wait(const std::chrono::time_point<CLOCK, DURATION>& timeout)
template<class CLOCK, class DURATION>
VkResult wait(const std::chrono::time_point<CLOCK, DURATION> &timeout)
{
return event.wait_until(timeout) ? VK_SUCCESS : VK_TIMEOUT;
}
const marl::Event& getEvent() const { return event; }
const marl::Event &getEvent() const { return event; }
// TaskEvents compliance
void start() override
......@@ -76,17 +77,17 @@ public:
}
private:
Fence(const Fence&) = delete;
Fence(const Fence &) = delete;
marl::WaitGroup wg;
const marl::Event event;
};
static inline Fence* Cast(VkFence object)
static inline Fence *Cast(VkFence object)
{
return Fence::Cast(object);
}
} // namespace vk
#endif // VK_FENCE_HPP_
#endif // VK_FENCE_HPP_
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -15,15 +15,15 @@
#include "VkFramebuffer.hpp"
#include "VkImageView.hpp"
#include "VkRenderPass.hpp"
#include <algorithm>
#include <memory.h>
#include <algorithm>
namespace vk {
Framebuffer::Framebuffer(const VkFramebufferCreateInfo* pCreateInfo, void* mem) :
attachmentCount(pCreateInfo->attachmentCount),
attachments(reinterpret_cast<ImageView**>(mem)),
extent{pCreateInfo->width, pCreateInfo->height, pCreateInfo->layers}
Framebuffer::Framebuffer(const VkFramebufferCreateInfo *pCreateInfo, void *mem)
: attachmentCount(pCreateInfo->attachmentCount)
, attachments(reinterpret_cast<ImageView **>(mem))
, extent{ pCreateInfo->width, pCreateInfo->height, pCreateInfo->layers }
{
for(uint32_t i = 0; i < attachmentCount; i++)
{
......@@ -31,12 +31,12 @@ Framebuffer::Framebuffer(const VkFramebufferCreateInfo* pCreateInfo, void* mem)
}
}
void Framebuffer::destroy(const VkAllocationCallbacks* pAllocator)
void Framebuffer::destroy(const VkAllocationCallbacks *pAllocator)
{
vk::deallocate(attachments, pAllocator);
}
void Framebuffer::clear(const RenderPass* renderPass, uint32_t clearValueCount, const VkClearValue* pClearValues, const VkRect2D& renderArea)
void Framebuffer::clear(const RenderPass *renderPass, uint32_t clearValueCount, const VkClearValue *pClearValues, const VkRect2D &renderArea)
{
ASSERT(attachmentCount == renderPass->getAttachmentCount());
......@@ -59,7 +59,7 @@ void Framebuffer::clear(const RenderPass* renderPass, uint32_t clearValueCount,
if(renderPass->isMultiView())
{
attachments[i]->clearWithLayerMask(pClearValues[i], aspectMask, renderArea,
renderPass->getAttachmentViewMask(i));
renderPass->getAttachmentViewMask(i));
}
else
{
......@@ -68,7 +68,7 @@ void Framebuffer::clear(const RenderPass* renderPass, uint32_t clearValueCount,
}
}
void Framebuffer::clearAttachment(const RenderPass* renderPass, uint32_t subpassIndex, const VkClearAttachment& attachment, const VkClearRect& rect)
void Framebuffer::clearAttachment(const RenderPass *renderPass, uint32_t subpassIndex, const VkClearAttachment &attachment, const VkClearRect &rect)
{
VkSubpassDescription subpass = renderPass->getSubpass(subpassIndex);
......@@ -85,7 +85,7 @@ void Framebuffer::clearAttachment(const RenderPass* renderPass, uint32_t subpass
if(renderPass->isMultiView())
{
imageView->clearWithLayerMask(attachment.clearValue, attachment.aspectMask, rect.rect,
renderPass->getViewMask(subpassIndex));
renderPass->getViewMask(subpassIndex));
}
else
{
......@@ -105,7 +105,7 @@ void Framebuffer::clearAttachment(const RenderPass* renderPass, uint32_t subpass
if(renderPass->isMultiView())
{
imageView->clearWithLayerMask(attachment.clearValue, attachment.aspectMask, rect.rect,
renderPass->getViewMask(subpassIndex));
renderPass->getViewMask(subpassIndex));
}
else
{
......@@ -120,9 +120,9 @@ ImageView *Framebuffer::getAttachment(uint32_t index) const
return attachments[index];
}
void Framebuffer::resolve(const RenderPass* renderPass, uint32_t subpassIndex)
void Framebuffer::resolve(const RenderPass *renderPass, uint32_t subpassIndex)
{
auto const& subpass = renderPass->getSubpass(subpassIndex);
auto const &subpass = renderPass->getSubpass(subpassIndex);
if(subpass.pResolveAttachments)
{
for(uint32_t i = 0; i < subpass.colorAttachmentCount; i++)
......@@ -134,7 +134,7 @@ void Framebuffer::resolve(const RenderPass* renderPass, uint32_t subpassIndex)
if(renderPass->isMultiView())
{
imageView->resolveWithLayerMask(attachments[resolveAttachment],
renderPass->getViewMask(subpassIndex));
renderPass->getViewMask(subpassIndex));
}
else
{
......@@ -145,9 +145,9 @@ void Framebuffer::resolve(const RenderPass* renderPass, uint32_t subpassIndex)
}
}
size_t Framebuffer::ComputeRequiredAllocationSize(const VkFramebufferCreateInfo* pCreateInfo)
size_t Framebuffer::ComputeRequiredAllocationSize(const VkFramebufferCreateInfo *pCreateInfo)
{
return pCreateInfo->attachmentCount * sizeof(void*);
return pCreateInfo->attachmentCount * sizeof(void *);
}
} // namespace vk
......@@ -25,29 +25,29 @@ class RenderPass;
class Framebuffer : public Object<Framebuffer, VkFramebuffer>
{
public:
Framebuffer(const VkFramebufferCreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator);
Framebuffer(const VkFramebufferCreateInfo *pCreateInfo, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator);
void clear(const RenderPass* renderPass, uint32_t clearValueCount, const VkClearValue* pClearValues, const VkRect2D& renderArea);
void clearAttachment(const RenderPass* renderPass, uint32_t subpassIndex, const VkClearAttachment& attachment, const VkClearRect& rect);
void clear(const RenderPass *renderPass, uint32_t clearValueCount, const VkClearValue *pClearValues, const VkRect2D &renderArea);
void clearAttachment(const RenderPass *renderPass, uint32_t subpassIndex, const VkClearAttachment &attachment, const VkClearRect &rect);
static size_t ComputeRequiredAllocationSize(const VkFramebufferCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkFramebufferCreateInfo *pCreateInfo);
ImageView *getAttachment(uint32_t index) const;
void resolve(const RenderPass* renderPass, uint32_t subpassIndex);
void resolve(const RenderPass *renderPass, uint32_t subpassIndex);
const VkExtent3D& getExtent() const { return extent; }
const VkExtent3D &getExtent() const { return extent; }
private:
uint32_t attachmentCount = 0;
ImageView** attachments = nullptr;
uint32_t attachmentCount = 0;
ImageView **attachments = nullptr;
const VkExtent3D extent = {};
};
static inline Framebuffer* Cast(VkFramebuffer object)
static inline Framebuffer *Cast(VkFramebuffer object)
{
return Framebuffer::Cast(object);
}
} // namespace vk
#endif // VK_FRAMEBUFFER_HPP_
#endif // VK_FRAMEBUFFER_HPP_
......@@ -36,7 +36,7 @@ VkComponentMapping ResolveComponentMapping(VkComponentMapping m, vk::Format form
format.componentCount() < 4 ? VK_COMPONENT_SWIZZLE_ONE : VK_COMPONENT_SWIZZLE_A,
};
return {table[m.r], table[m.g], table[m.b], table[m.a]};
return { table[m.r], table[m.g], table[m.b], table[m.a] };
}
VkImageSubresourceRange ResolveRemainingLevelsLayers(VkImageSubresourceRange range, const vk::Image *image)
......@@ -56,20 +56,22 @@ namespace vk {
std::atomic<uint32_t> ImageView::nextID(1);
ImageView::ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem, const vk::SamplerYcbcrConversion *ycbcrConversion) :
image(vk::Cast(pCreateInfo->image)), viewType(pCreateInfo->viewType), format(pCreateInfo->format),
components(ResolveComponentMapping(pCreateInfo->components, format)),
subresourceRange(ResolveRemainingLevelsLayers(pCreateInfo->subresourceRange, image)),
ycbcrConversion(ycbcrConversion)
ImageView::ImageView(const VkImageViewCreateInfo *pCreateInfo, void *mem, const vk::SamplerYcbcrConversion *ycbcrConversion)
: image(vk::Cast(pCreateInfo->image))
, viewType(pCreateInfo->viewType)
, format(pCreateInfo->format)
, components(ResolveComponentMapping(pCreateInfo->components, format))
, subresourceRange(ResolveRemainingLevelsLayers(pCreateInfo->subresourceRange, image))
, ycbcrConversion(ycbcrConversion)
{
}
size_t ImageView::ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo)
size_t ImageView::ComputeRequiredAllocationSize(const VkImageViewCreateInfo *pCreateInfo)
{
return 0;
}
void ImageView::destroy(const VkAllocationCallbacks* pAllocator)
void ImageView::destroy(const VkAllocationCallbacks *pAllocator)
{
}
......@@ -79,40 +81,40 @@ bool ImageView::imageTypesMatch(VkImageType imageType) const
switch(viewType)
{
case VK_IMAGE_VIEW_TYPE_1D:
return (imageType == VK_IMAGE_TYPE_1D) &&
(subresourceRange.layerCount == 1);
case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
return imageType == VK_IMAGE_TYPE_1D;
case VK_IMAGE_VIEW_TYPE_2D:
return ((imageType == VK_IMAGE_TYPE_2D) ||
((imageType == VK_IMAGE_TYPE_3D) &&
(imageArrayLayers == 1))) &&
(subresourceRange.layerCount == 1);
case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
return (imageType == VK_IMAGE_TYPE_2D) ||
((imageType == VK_IMAGE_TYPE_3D) &&
(imageArrayLayers == 1));
case VK_IMAGE_VIEW_TYPE_CUBE:
return image->isCube() &&
(imageArrayLayers >= subresourceRange.layerCount) &&
(subresourceRange.layerCount == 6);
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
return image->isCube() &&
(imageArrayLayers >= subresourceRange.layerCount) &&
(subresourceRange.layerCount >= 6);
case VK_IMAGE_VIEW_TYPE_3D:
return (imageType == VK_IMAGE_TYPE_3D) &&
(imageArrayLayers == 1) &&
(subresourceRange.layerCount == 1);
default:
UNREACHABLE("Unexpected viewType %d", (int)viewType);
case VK_IMAGE_VIEW_TYPE_1D:
return (imageType == VK_IMAGE_TYPE_1D) &&
(subresourceRange.layerCount == 1);
case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
return imageType == VK_IMAGE_TYPE_1D;
case VK_IMAGE_VIEW_TYPE_2D:
return ((imageType == VK_IMAGE_TYPE_2D) ||
((imageType == VK_IMAGE_TYPE_3D) &&
(imageArrayLayers == 1))) &&
(subresourceRange.layerCount == 1);
case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
return (imageType == VK_IMAGE_TYPE_2D) ||
((imageType == VK_IMAGE_TYPE_3D) &&
(imageArrayLayers == 1));
case VK_IMAGE_VIEW_TYPE_CUBE:
return image->isCube() &&
(imageArrayLayers >= subresourceRange.layerCount) &&
(subresourceRange.layerCount == 6);
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
return image->isCube() &&
(imageArrayLayers >= subresourceRange.layerCount) &&
(subresourceRange.layerCount >= 6);
case VK_IMAGE_VIEW_TYPE_3D:
return (imageType == VK_IMAGE_TYPE_3D) &&
(imageArrayLayers == 1) &&
(subresourceRange.layerCount == 1);
default:
UNREACHABLE("Unexpected viewType %d", (int)viewType);
}
return false;
}
void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags aspectMask, const VkRect2D& renderArea)
void ImageView::clear(const VkClearValue &clearValue, const VkImageAspectFlags aspectMask, const VkRect2D &renderArea)
{
// Note: clearing ignores swizzling, so components is ignored.
......@@ -131,7 +133,7 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a
image->clear(clearValue, format, renderArea, sr);
}
void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags aspectMask, const VkClearRect& renderArea)
void ImageView::clear(const VkClearValue &clearValue, const VkImageAspectFlags aspectMask, const VkClearRect &renderArea)
{
// Note: clearing ignores swizzling, so components is ignored.
......@@ -161,13 +163,13 @@ void ImageView::clearWithLayerMask(const VkClearValue &clearValue, VkImageAspect
{
uint32_t layer = sw::log2i(layerMask);
layerMask &= ~(1 << layer);
VkClearRect r = {renderArea, layer, 1};
VkClearRect r = { renderArea, layer, 1 };
r.baseArrayLayer = layer;
clear(clearValue, aspectMask, r);
}
}
void ImageView::resolve(ImageView* resolveAttachment, int layer)
void ImageView::resolve(ImageView *resolveAttachment, int layer)
{
if((subresourceRange.levelCount != 1) || (resolveAttachment->subresourceRange.levelCount != 1))
{
......@@ -175,16 +177,14 @@ void ImageView::resolve(ImageView* resolveAttachment, int layer)
}
VkImageCopy region;
region.srcSubresource =
{
region.srcSubresource = {
subresourceRange.aspectMask,
subresourceRange.baseMipLevel,
subresourceRange.baseArrayLayer + layer,
1
};
region.srcOffset = { 0, 0, 0 };
region.dstSubresource =
{
region.dstSubresource = {
resolveAttachment->subresourceRange.aspectMask,
resolveAttachment->subresourceRange.baseMipLevel,
resolveAttachment->subresourceRange.baseArrayLayer + layer,
......@@ -197,7 +197,7 @@ void ImageView::resolve(ImageView* resolveAttachment, int layer)
image->copyTo(resolveAttachment->image, region);
}
void ImageView::resolve(ImageView* resolveAttachment)
void ImageView::resolve(ImageView *resolveAttachment)
{
if((subresourceRange.levelCount != 1) || (resolveAttachment->subresourceRange.levelCount != 1))
{
......@@ -205,16 +205,14 @@ void ImageView::resolve(ImageView* resolveAttachment)
}
VkImageCopy region;
region.srcSubresource =
{
region.srcSubresource = {
subresourceRange.aspectMask,
subresourceRange.baseMipLevel,
subresourceRange.baseArrayLayer,
subresourceRange.layerCount
};
region.srcOffset = { 0, 0, 0 };
region.dstSubresource =
{
region.dstSubresource = {
resolveAttachment->subresourceRange.aspectMask,
resolveAttachment->subresourceRange.baseMipLevel,
resolveAttachment->subresourceRange.baseArrayLayer,
......@@ -237,17 +235,17 @@ void ImageView::resolveWithLayerMask(ImageView *resolveAttachment, uint32_t laye
}
}
const Image* ImageView::getImage(Usage usage) const
const Image *ImageView::getImage(Usage usage) const
{
switch(usage)
{
case RAW:
return image;
case SAMPLING:
return image->getSampledImage(format);
default:
UNIMPLEMENTED("usage %d", int(usage));
return nullptr;
case RAW:
return image;
case SAMPLING:
return image->getSampledImage(format);
default:
UNIMPLEMENTED("usage %d", int(usage));
return nullptr;
}
}
......@@ -283,12 +281,11 @@ VkExtent3D ImageView::getMipLevelExtent(uint32_t mipLevel) const
subresourceRange.baseMipLevel + mipLevel);
}
void *ImageView::getOffsetPointer(const VkOffset3D& offset, VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer, Usage usage) const
void *ImageView::getOffsetPointer(const VkOffset3D &offset, VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer, Usage usage) const
{
ASSERT(mipLevel < subresourceRange.levelCount);
VkImageSubresourceLayers imageSubresourceLayers =
{
VkImageSubresourceLayers imageSubresourceLayers = {
static_cast<VkImageAspectFlags>(aspect),
subresourceRange.baseMipLevel + mipLevel,
subresourceRange.baseArrayLayer + layer,
......
......@@ -17,8 +17,8 @@
#include "VkDebug.hpp"
#include "VkFormat.h"
#include "VkObject.hpp"
#include "VkImage.hpp"
#include "VkObject.hpp"
#include <atomic>
......@@ -32,18 +32,22 @@ public:
// Image usage:
// RAW: Use the base image as is
// SAMPLING: Image used for texture sampling
enum Usage { RAW, SAMPLING };
enum Usage
{
RAW,
SAMPLING
};
ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem, const vk::SamplerYcbcrConversion *ycbcrConversion);
void destroy(const VkAllocationCallbacks* pAllocator);
ImageView(const VkImageViewCreateInfo *pCreateInfo, void *mem, const vk::SamplerYcbcrConversion *ycbcrConversion);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkImageViewCreateInfo *pCreateInfo);
void clear(const VkClearValue& clearValues, VkImageAspectFlags aspectMask, const VkRect2D& renderArea);
void clear(const VkClearValue& clearValue, VkImageAspectFlags aspectMask, const VkClearRect& renderArea);
void clear(const VkClearValue &clearValues, VkImageAspectFlags aspectMask, const VkRect2D &renderArea);
void clear(const VkClearValue &clearValue, VkImageAspectFlags aspectMask, const VkClearRect &renderArea);
void clearWithLayerMask(const VkClearValue &clearValue, VkImageAspectFlags aspectMask, const VkRect2D &renderArea, uint32_t layerMask);
void resolve(ImageView* resolveAttachment);
void resolve(ImageView* resolveAttachment, int layer);
void resolve(ImageView *resolveAttachment);
void resolve(ImageView *resolveAttachment, int layer);
void resolveWithLayerMask(ImageView *resolveAttachment, uint32_t layerMask);
VkImageViewType getType() const { return viewType; }
......@@ -59,15 +63,15 @@ public:
{
switch(image->getSampleCountFlagBits())
{
case VK_SAMPLE_COUNT_1_BIT: return 1;
case VK_SAMPLE_COUNT_4_BIT: return 4;
default:
UNIMPLEMENTED("Sample count flags %d", image->getSampleCountFlagBits());
return 1;
case VK_SAMPLE_COUNT_1_BIT: return 1;
case VK_SAMPLE_COUNT_4_BIT: return 4;
default:
UNIMPLEMENTED("Sample count flags %d", image->getSampleCountFlagBits());
return 1;
}
}
void *getOffsetPointer(const VkOffset3D& offset, VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer, Usage usage = RAW) const;
void *getOffsetPointer(const VkOffset3D &offset, VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer, Usage usage = RAW) const;
bool hasDepthAspect() const { return (subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0; }
bool hasStencilAspect() const { return (subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0; }
......@@ -81,15 +85,15 @@ public:
private:
static std::atomic<uint32_t> nextID;
friend class BufferView; // ImageView/BufferView share the ID space above.
friend class BufferView; // ImageView/BufferView share the ID space above.
bool imageTypesMatch(VkImageType imageType) const;
const Image* getImage(Usage usage) const;
bool imageTypesMatch(VkImageType imageType) const;
const Image *getImage(Usage usage) const;
Image *const image = nullptr;
const VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_2D;
const Format format;
const VkComponentMapping components = {};
Image *const image = nullptr;
const VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_2D;
const Format format;
const VkComponentMapping components = {};
const VkImageSubresourceRange subresourceRange = {};
const vk::SamplerYcbcrConversion *ycbcrConversion = nullptr;
......@@ -99,18 +103,18 @@ private:
inline VkComponentMapping ResolveIdentityMapping(VkComponentMapping m)
{
return {
(m.r == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_R : m.r,
(m.g == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_G : m.g,
(m.b == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_B : m.b,
(m.a == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_A : m.a,
};
(m.r == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_R : m.r,
(m.g == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_G : m.g,
(m.b == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_B : m.b,
(m.a == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_A : m.a,
};
}
static inline ImageView* Cast(VkImageView object)
static inline ImageView *Cast(VkImageView object)
{
return ImageView::Cast(object);
}
} // namespace vk
#endif // VK_IMAGE_VIEW_HPP_
#endif // VK_IMAGE_VIEW_HPP_
......@@ -17,17 +17,17 @@
namespace vk {
Instance::Instance(const VkInstanceCreateInfo* pCreateInfo, void* mem, VkPhysicalDevice physicalDevice)
: physicalDevice(physicalDevice)
Instance::Instance(const VkInstanceCreateInfo *pCreateInfo, void *mem, VkPhysicalDevice physicalDevice)
: physicalDevice(physicalDevice)
{
}
void Instance::destroy(const VkAllocationCallbacks* pAllocator)
void Instance::destroy(const VkAllocationCallbacks *pAllocator)
{
vk::destroy(physicalDevice, pAllocator);
}
VkResult Instance::getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) const
VkResult Instance::getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) const
{
if(!pPhysicalDevices)
{
......@@ -47,7 +47,7 @@ VkResult Instance::getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysical
}
VkResult Instance::getPhysicalDeviceGroups(uint32_t *pPhysicalDeviceGroupCount,
VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) const
VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) const
{
if(!pPhysicalDeviceGroupProperties)
{
......
......@@ -24,14 +24,14 @@ class Instance
public:
static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE; }
Instance(const VkInstanceCreateInfo* pCreateInfo, void* mem, VkPhysicalDevice physicalDevice);
void destroy(const VkAllocationCallbacks* pAllocator);
Instance(const VkInstanceCreateInfo *pCreateInfo, void *mem, VkPhysicalDevice physicalDevice);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkInstanceCreateInfo*) { return 0; }
static size_t ComputeRequiredAllocationSize(const VkInstanceCreateInfo *) { return 0; }
VkResult getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) const;
VkResult getPhysicalDevices(uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) const;
VkResult getPhysicalDeviceGroups(uint32_t *pPhysicalDeviceGroupCount,
VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) const;
VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) const;
private:
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
......@@ -39,11 +39,11 @@ private:
using DispatchableInstance = DispatchableObject<Instance, VkInstance>;
static inline Instance* Cast(VkInstance object)
static inline Instance *Cast(VkInstance object)
{
return DispatchableInstance::Cast(object);
}
} // namespace vk
#endif // VK_INSTANCE_HPP_
#endif // VK_INSTANCE_HPP_
......@@ -15,24 +15,22 @@
#ifndef VK_OBJECT_HPP_
#define VK_OBJECT_HPP_
#include "VkConfig.h"
#include "VkMemory.h"
#include "VkConfig.h"
#include "System/Memory.hpp"
namespace vk {
void* allocate(size_t count, size_t alignment, const VkAllocationCallbacks* pAllocator, VkSystemAllocationScope allocationScope)
void *allocate(size_t count, size_t alignment, const VkAllocationCallbacks *pAllocator, VkSystemAllocationScope allocationScope)
{
return pAllocator ?
pAllocator->pfnAllocation(pAllocator->pUserData, count, alignment, allocationScope) :
sw::allocate(count, alignment);
return pAllocator ? pAllocator->pfnAllocation(pAllocator->pUserData, count, alignment, allocationScope) : sw::allocate(count, alignment);
}
void deallocate(void* ptr, const VkAllocationCallbacks* pAllocator)
void deallocate(void *ptr, const VkAllocationCallbacks *pAllocator)
{
pAllocator ? pAllocator->pfnFree(pAllocator->pUserData, ptr) : sw::deallocate(ptr);
}
} // namespace vk
#endif // VK_OBJECT_HPP_
#endif // VK_OBJECT_HPP_
......@@ -19,34 +19,34 @@
#include "VkDebug.hpp"
#include "VkMemory.h"
#include <new>
#include <Vulkan/VulkanPlatform.h>
#include <vulkan/vk_icd.h>
#include <new>
namespace vk {
template<typename T, typename VkT>
static inline T* VkTtoT(VkT vkObject)
static inline T *VkTtoT(VkT vkObject)
{
return static_cast<T*>(static_cast<void*>(vkObject));
return static_cast<T *>(static_cast<void *>(vkObject));
}
template<typename T, typename VkT>
static inline VkT TtoVkT(T* object)
static inline VkT TtoVkT(T *object)
{
return { static_cast<uint64_t>(reinterpret_cast<uintptr_t>(object)) };
}
// For use in the placement new to make it verbose that we're allocating an object using device memory
static constexpr VkAllocationCallbacks* DEVICE_MEMORY = nullptr;
static constexpr VkAllocationCallbacks *DEVICE_MEMORY = nullptr;
template<typename T, typename VkT, typename CreateInfo, typename... ExtendedInfo>
static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject, ExtendedInfo... extendedInfo)
static VkResult Create(const VkAllocationCallbacks *pAllocator, const CreateInfo *pCreateInfo, VkT *outObject, ExtendedInfo... extendedInfo)
{
*outObject = VK_NULL_HANDLE;
size_t size = T::ComputeRequiredAllocationSize(pCreateInfo);
void* memory = nullptr;
void *memory = nullptr;
if(size)
{
memory = vk::allocate(size, REQUIRED_MEMORY_ALIGNMENT, pAllocator, T::GetAllocationScope());
......@@ -56,14 +56,14 @@ static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo
}
}
void* objectMemory = vk::allocate(sizeof(T), alignof(T), pAllocator, T::GetAllocationScope());
void *objectMemory = vk::allocate(sizeof(T), alignof(T), pAllocator, T::GetAllocationScope());
if(!objectMemory)
{
vk::deallocate(memory, pAllocator);
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
auto object = new (objectMemory) T(pCreateInfo, memory, extendedInfo...);
auto object = new(objectMemory) T(pCreateInfo, memory, extendedInfo...);
if(!object)
{
......@@ -85,10 +85,10 @@ class ObjectBase
public:
using VkType = VkT;
void destroy(const VkAllocationCallbacks* pAllocator) {} // Method defined by objects to delete their content, if necessary
void destroy(const VkAllocationCallbacks *pAllocator) {} // Method defined by objects to delete their content, if necessary
template<typename CreateInfo, typename... ExtendedInfo>
static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject, ExtendedInfo... extendedInfo)
static VkResult Create(const VkAllocationCallbacks *pAllocator, const CreateInfo *pCreateInfo, VkT *outObject, ExtendedInfo... extendedInfo)
{
return vk::Create<T, VkT, CreateInfo>(pAllocator, pCreateInfo, outObject, extendedInfo...);
}
......@@ -104,10 +104,10 @@ public:
{
// The static_cast<T*> is used to make sure the returned pointer points to the
// beginning of the object, even if the derived class uses multiple inheritance
return vk::TtoVkT<T, VkT>(static_cast<T*>(this));
return vk::TtoVkT<T, VkT>(static_cast<T *>(this));
}
static inline T* Cast(VkT vkObject)
static inline T *Cast(VkT vkObject)
{
return vk::VkTtoT<T, VkT>(vkObject);
}
......@@ -123,40 +123,40 @@ class DispatchableObject
public:
static constexpr VkSystemAllocationScope GetAllocationScope() { return T::GetAllocationScope(); }
template<typename ...Args>
DispatchableObject(Args... args) : object(args...)
template<typename... Args>
DispatchableObject(Args... args)
: object(args...)
{
}
~DispatchableObject() = delete;
void destroy(const VkAllocationCallbacks* pAllocator)
void destroy(const VkAllocationCallbacks *pAllocator)
{
object.destroy(pAllocator);
}
void operator delete(void* ptr, const VkAllocationCallbacks* pAllocator)
void operator delete(void *ptr, const VkAllocationCallbacks *pAllocator)
{
// Should never happen
ASSERT(false);
}
template<typename CreateInfo, typename... ExtendedInfo>
static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject, ExtendedInfo... extendedInfo)
static VkResult Create(const VkAllocationCallbacks *pAllocator, const CreateInfo *pCreateInfo, VkT *outObject, ExtendedInfo... extendedInfo)
{
return vk::Create<DispatchableObject<T, VkT>, VkT, CreateInfo>(pAllocator, pCreateInfo, outObject, extendedInfo...);
}
template<typename CreateInfo>
static size_t ComputeRequiredAllocationSize(const CreateInfo* pCreateInfo)
static size_t ComputeRequiredAllocationSize(const CreateInfo *pCreateInfo)
{
return T::ComputeRequiredAllocationSize(pCreateInfo);
}
static inline T* Cast(VkT vkObject)
static inline T *Cast(VkT vkObject)
{
return (vkObject == VK_NULL_HANDLE) ? nullptr :
&(reinterpret_cast<DispatchableObject<T, VkT>*>(vkObject)->object);
return (vkObject == VK_NULL_HANDLE) ? nullptr : &(reinterpret_cast<DispatchableObject<T, VkT> *>(vkObject)->object);
}
operator VkT()
......@@ -167,4 +167,4 @@ public:
} // namespace vk
#endif // VK_OBJECT_HPP_
#endif // VK_OBJECT_HPP_
......@@ -15,11 +15,11 @@
#ifndef VK_PHYSICAL_DEVICE_HPP_
#define VK_PHYSICAL_DEVICE_HPP_
#include "VkObject.hpp"
#include "VkFormat.h"
#include "VkObject.hpp"
#ifdef VK_USE_PLATFORM_ANDROID_KHR
#include <vulkan/vk_android_native_buffer.h>
# include <vulkan/vk_android_native_buffer.h>
#endif
namespace vk {
......@@ -29,65 +29,65 @@ class PhysicalDevice
public:
static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE; }
PhysicalDevice(const void*, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator) {}
PhysicalDevice(const void *, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator) {}
static size_t ComputeRequiredAllocationSize(const void*) { return 0; }
static size_t ComputeRequiredAllocationSize(const void *) { return 0; }
const VkPhysicalDeviceFeatures& getFeatures() const;
void getFeatures(VkPhysicalDeviceSamplerYcbcrConversionFeatures* features) const;
void getFeatures(VkPhysicalDevice16BitStorageFeatures* features) const;
void getFeatures(VkPhysicalDeviceVariablePointerFeatures* features) const;
void getFeatures(VkPhysicalDevice8BitStorageFeaturesKHR* features) const;
void getFeatures(VkPhysicalDeviceMultiviewFeatures* features) const;
void getFeatures(VkPhysicalDeviceProtectedMemoryFeatures* features) const;
void getFeatures(VkPhysicalDeviceShaderDrawParameterFeatures* features) const;
void getFeatures(VkPhysicalDeviceLineRasterizationFeaturesEXT* features) const;
void getFeatures(VkPhysicalDeviceProvokingVertexFeaturesEXT* features) const;
bool hasFeatures(const VkPhysicalDeviceFeatures& requestedFeatures) const;
const VkPhysicalDeviceFeatures &getFeatures() const;
void getFeatures(VkPhysicalDeviceSamplerYcbcrConversionFeatures *features) const;
void getFeatures(VkPhysicalDevice16BitStorageFeatures *features) const;
void getFeatures(VkPhysicalDeviceVariablePointerFeatures *features) const;
void getFeatures(VkPhysicalDevice8BitStorageFeaturesKHR *features) const;
void getFeatures(VkPhysicalDeviceMultiviewFeatures *features) const;
void getFeatures(VkPhysicalDeviceProtectedMemoryFeatures *features) const;
void getFeatures(VkPhysicalDeviceShaderDrawParameterFeatures *features) const;
void getFeatures(VkPhysicalDeviceLineRasterizationFeaturesEXT *features) const;
void getFeatures(VkPhysicalDeviceProvokingVertexFeaturesEXT *features) const;
bool hasFeatures(const VkPhysicalDeviceFeatures &requestedFeatures) const;
const VkPhysicalDeviceProperties& getProperties() const;
void getProperties(VkPhysicalDeviceIDProperties* properties) const;
void getProperties(VkPhysicalDeviceMaintenance3Properties* properties) const;
void getProperties(VkPhysicalDeviceMultiviewProperties* properties) const;
void getProperties(VkPhysicalDevicePointClippingProperties* properties) const;
void getProperties(VkPhysicalDeviceProtectedMemoryProperties* properties) const;
void getProperties(VkPhysicalDeviceSubgroupProperties* properties) const;
void getProperties(const VkExternalMemoryHandleTypeFlagBits* handleType, VkExternalImageFormatProperties* properties) const;
void getProperties(VkSamplerYcbcrConversionImageFormatProperties* properties) const;
const VkPhysicalDeviceProperties &getProperties() const;
void getProperties(VkPhysicalDeviceIDProperties *properties) const;
void getProperties(VkPhysicalDeviceMaintenance3Properties *properties) const;
void getProperties(VkPhysicalDeviceMultiviewProperties *properties) const;
void getProperties(VkPhysicalDevicePointClippingProperties *properties) const;
void getProperties(VkPhysicalDeviceProtectedMemoryProperties *properties) const;
void getProperties(VkPhysicalDeviceSubgroupProperties *properties) const;
void getProperties(const VkExternalMemoryHandleTypeFlagBits *handleType, VkExternalImageFormatProperties *properties) const;
void getProperties(VkSamplerYcbcrConversionImageFormatProperties *properties) const;
#ifdef __ANDROID__
void getProperties(VkPhysicalDevicePresentationPropertiesANDROID* properties) const;
void getProperties(VkPhysicalDevicePresentationPropertiesANDROID *properties) const;
#endif
void getProperties(const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties) const;
void getProperties(const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties) const;
void getProperties(const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties) const;
void getProperties(VkPhysicalDeviceDriverPropertiesKHR* properties) const;
void getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT* properties) const;
void getProperties(VkPhysicalDeviceProvokingVertexPropertiesEXT* properties) const;
void getProperties(const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo, VkExternalBufferProperties *pExternalBufferProperties) const;
void getProperties(const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo, VkExternalFenceProperties *pExternalFenceProperties) const;
void getProperties(const VkPhysicalDeviceExternalSemaphoreInfo *pExternalSemaphoreInfo, VkExternalSemaphoreProperties *pExternalSemaphoreProperties) const;
void getProperties(VkPhysicalDeviceDriverPropertiesKHR *properties) const;
void getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT *properties) const;
void getProperties(VkPhysicalDeviceProvokingVertexPropertiesEXT *properties) const;
void getFormatProperties(Format format, VkFormatProperties* pFormatProperties) const;
void getFormatProperties(Format format, VkFormatProperties *pFormatProperties) const;
void getImageFormatProperties(Format format, VkImageType type, VkImageTiling tiling,
VkImageUsageFlags usage, VkImageCreateFlags flags,
VkImageFormatProperties* pImageFormatProperties) const;
VkImageFormatProperties *pImageFormatProperties) const;
uint32_t getQueueFamilyPropertyCount() const;
void getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,
VkQueueFamilyProperties* pQueueFamilyProperties) const;
VkQueueFamilyProperties *pQueueFamilyProperties) const;
void getQueueFamilyProperties(uint32_t pQueueFamilyPropertyCount,
VkQueueFamilyProperties2* pQueueFamilyProperties) const;
const VkPhysicalDeviceMemoryProperties& getMemoryProperties() const;
VkQueueFamilyProperties2 *pQueueFamilyProperties) const;
const VkPhysicalDeviceMemoryProperties &getMemoryProperties() const;
private:
const VkPhysicalDeviceLimits& getLimits() const;
const VkPhysicalDeviceLimits &getLimits() const;
VkSampleCountFlags getSampleCounts() const;
};
using DispatchablePhysicalDevice = DispatchableObject<PhysicalDevice, VkPhysicalDevice>;
static inline PhysicalDevice* Cast(VkPhysicalDevice object)
static inline PhysicalDevice *Cast(VkPhysicalDevice object)
{
return DispatchablePhysicalDevice::Cast(object);
}
} // namespace vk
#endif // VK_PHYSICAL_DEVICE_HPP_
#endif // VK_PHYSICAL_DEVICE_HPP_
......@@ -16,9 +16,9 @@
#define VK_PIPELINE_HPP_
#include "VkObject.hpp"
#include "Device/Renderer.hpp"
#include "Vulkan/VkDescriptorSet.hpp"
#include "Vulkan/VkPipelineCache.hpp"
#include "Device/Renderer.hpp"
#include <memory>
namespace sw {
......@@ -46,22 +46,25 @@ public:
return vk::TtoVkT<Pipeline, VkPipeline>(this);
}
static inline Pipeline* Cast(VkPipeline object)
static inline Pipeline *Cast(VkPipeline object)
{
return vk::VkTtoT<Pipeline, VkPipeline>(object);
}
void destroy(const VkAllocationCallbacks* pAllocator)
void destroy(const VkAllocationCallbacks *pAllocator)
{
destroyPipeline(pAllocator);
}
virtual void destroyPipeline(const VkAllocationCallbacks* pAllocator) = 0;
virtual void destroyPipeline(const VkAllocationCallbacks *pAllocator) = 0;
#ifndef NDEBUG
virtual VkPipelineBindPoint bindPoint() const = 0;
#endif
PipelineLayout const * getLayout() const { return layout; }
PipelineLayout const *getLayout() const
{
return layout;
}
protected:
PipelineLayout const *layout = nullptr;
......@@ -72,10 +75,10 @@ protected:
class GraphicsPipeline : public Pipeline, public ObjectBase<GraphicsPipeline, VkPipeline>
{
public:
GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, void* mem, const Device *device);
GraphicsPipeline(const VkGraphicsPipelineCreateInfo *pCreateInfo, void *mem, const Device *device);
virtual ~GraphicsPipeline() = default;
void destroyPipeline(const VkAllocationCallbacks* pAllocator) override;
void destroyPipeline(const VkAllocationCallbacks *pAllocator) override;
#ifndef NDEBUG
VkPipelineBindPoint bindPoint() const override
......@@ -84,21 +87,21 @@ public:
}
#endif
static size_t ComputeRequiredAllocationSize(const VkGraphicsPipelineCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkGraphicsPipelineCreateInfo *pCreateInfo);
void compileShaders(const VkAllocationCallbacks* pAllocator, const VkGraphicsPipelineCreateInfo* pCreateInfo, PipelineCache* pipelineCache);
void compileShaders(const VkAllocationCallbacks *pAllocator, const VkGraphicsPipelineCreateInfo *pCreateInfo, PipelineCache *pipelineCache);
uint32_t computePrimitiveCount(uint32_t vertexCount) const;
const sw::Context& getContext() const;
const VkRect2D& getScissor() const;
const VkViewport& getViewport() const;
const sw::Color<float>& getBlendConstants() const;
const sw::Context &getContext() const;
const VkRect2D &getScissor() const;
const VkViewport &getViewport() const;
const sw::Color<float> &getBlendConstants() const;
bool hasDynamicState(VkDynamicState dynamicState) const;
bool hasPrimitiveRestartEnable() const { return primitiveRestartEnable; }
private:
void setShader(const VkShaderStageFlagBits& stage, const std::shared_ptr<sw::SpirvShader> spirvShader);
const std::shared_ptr<sw::SpirvShader> getShader(const VkShaderStageFlagBits& stage) const;
void setShader(const VkShaderStageFlagBits &stage, const std::shared_ptr<sw::SpirvShader> spirvShader);
const std::shared_ptr<sw::SpirvShader> getShader(const VkShaderStageFlagBits &stage) const;
std::shared_ptr<sw::SpirvShader> vertexShader;
std::shared_ptr<sw::SpirvShader> fragmentShader;
......@@ -113,10 +116,10 @@ private:
class ComputePipeline : public Pipeline, public ObjectBase<ComputePipeline, VkPipeline>
{
public:
ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo, void* mem, const Device *device);
ComputePipeline(const VkComputePipelineCreateInfo *pCreateInfo, void *mem, const Device *device);
virtual ~ComputePipeline() = default;
void destroyPipeline(const VkAllocationCallbacks* pAllocator) override;
void destroyPipeline(const VkAllocationCallbacks *pAllocator) override;
#ifndef NDEBUG
VkPipelineBindPoint bindPoint() const override
......@@ -125,26 +128,26 @@ public:
}
#endif
static size_t ComputeRequiredAllocationSize(const VkComputePipelineCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkComputePipelineCreateInfo *pCreateInfo);
void compileShaders(const VkAllocationCallbacks* pAllocator, const VkComputePipelineCreateInfo* pCreateInfo, PipelineCache* pipelineCache);
void compileShaders(const VkAllocationCallbacks *pAllocator, const VkComputePipelineCreateInfo *pCreateInfo, PipelineCache *pipelineCache);
void run(uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ,
vk::DescriptorSet::Bindings const &descriptorSets,
vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets,
sw::PushConstantStorage const &pushConstants);
uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ,
vk::DescriptorSet::Bindings const &descriptorSets,
vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets,
sw::PushConstantStorage const &pushConstants);
protected:
std::shared_ptr<sw::SpirvShader> shader;
std::shared_ptr<sw::ComputeProgram> program;
};
static inline Pipeline* Cast(VkPipeline object)
static inline Pipeline *Cast(VkPipeline object)
{
return Pipeline::Cast(object);
}
} // namespace vk
#endif // VK_PIPELINE_HPP_
#endif // VK_PIPELINE_HPP_
......@@ -17,12 +17,12 @@
namespace vk {
PipelineCache::SpirvShaderKey::SpecializationInfo::SpecializationInfo(const VkSpecializationInfo* specializationInfo)
PipelineCache::SpirvShaderKey::SpecializationInfo::SpecializationInfo(const VkSpecializationInfo *specializationInfo)
{
if(specializationInfo)
{
auto ptr = reinterpret_cast<VkSpecializationInfo*>(
allocate(sizeof(VkSpecializationInfo), REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY));
auto ptr = reinterpret_cast<VkSpecializationInfo *>(
allocate(sizeof(VkSpecializationInfo), REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY));
info = std::shared_ptr<VkSpecializationInfo>(ptr, Deleter());
......@@ -30,8 +30,8 @@ PipelineCache::SpirvShaderKey::SpecializationInfo::SpecializationInfo(const VkSp
if(specializationInfo->mapEntryCount > 0)
{
size_t entriesSize = specializationInfo->mapEntryCount * sizeof(VkSpecializationMapEntry);
VkSpecializationMapEntry* mapEntries = reinterpret_cast<VkSpecializationMapEntry*>(
allocate(entriesSize, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY));
VkSpecializationMapEntry *mapEntries = reinterpret_cast<VkSpecializationMapEntry *>(
allocate(entriesSize, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY));
memcpy(mapEntries, specializationInfo->pMapEntries, entriesSize);
info->pMapEntries = mapEntries;
}
......@@ -39,7 +39,7 @@ PipelineCache::SpirvShaderKey::SpecializationInfo::SpecializationInfo(const VkSp
info->dataSize = specializationInfo->dataSize;
if(specializationInfo->dataSize > 0)
{
void* data = allocate(specializationInfo->dataSize, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY);
void *data = allocate(specializationInfo->dataSize, REQUIRED_MEMORY_ALIGNMENT, DEVICE_MEMORY);
memcpy(data, specializationInfo->pData, specializationInfo->dataSize);
info->pData = data;
}
......@@ -50,17 +50,17 @@ PipelineCache::SpirvShaderKey::SpecializationInfo::SpecializationInfo(const VkSp
}
}
void PipelineCache::SpirvShaderKey::SpecializationInfo::Deleter::operator() (VkSpecializationInfo* info) const
void PipelineCache::SpirvShaderKey::SpecializationInfo::Deleter::operator()(VkSpecializationInfo *info) const
{
if(info)
{
deallocate(const_cast<VkSpecializationMapEntry*>(info->pMapEntries), DEVICE_MEMORY);
deallocate(const_cast<void*>(info->pData), DEVICE_MEMORY);
deallocate(const_cast<VkSpecializationMapEntry *>(info->pMapEntries), DEVICE_MEMORY);
deallocate(const_cast<void *>(info->pData), DEVICE_MEMORY);
deallocate(info, DEVICE_MEMORY);
}
}
bool PipelineCache::SpirvShaderKey::SpecializationInfo::operator<(const SpecializationInfo& specializationInfo) const
bool PipelineCache::SpirvShaderKey::SpecializationInfo::operator<(const SpecializationInfo &specializationInfo) const
{
if(info && specializationInfo.info)
{
......@@ -97,17 +97,17 @@ bool PipelineCache::SpirvShaderKey::SpecializationInfo::operator<(const Speciali
}
PipelineCache::SpirvShaderKey::SpirvShaderKey(const VkShaderStageFlagBits pipelineStage,
const std::string& entryPointName,
const std::vector<uint32_t>& insns,
const vk::RenderPass *renderPass,
const uint32_t subpassIndex,
const VkSpecializationInfo* specializationInfo) :
pipelineStage(pipelineStage),
entryPointName(entryPointName),
insns(insns),
renderPass(renderPass),
subpassIndex(subpassIndex),
specializationInfo(specializationInfo)
const std::string &entryPointName,
const std::vector<uint32_t> &insns,
const vk::RenderPass *renderPass,
const uint32_t subpassIndex,
const VkSpecializationInfo *specializationInfo)
: pipelineStage(pipelineStage)
, entryPointName(entryPointName)
, insns(insns)
, renderPass(renderPass)
, subpassIndex(subpassIndex)
, specializationInfo(specializationInfo)
{
}
......@@ -153,10 +153,11 @@ bool PipelineCache::SpirvShaderKey::operator<(const SpirvShaderKey &other) const
return (specializationInfo < other.specializationInfo);
}
PipelineCache::PipelineCache(const VkPipelineCacheCreateInfo* pCreateInfo, void* mem) :
dataSize(ComputeRequiredAllocationSize(pCreateInfo)), data(reinterpret_cast<uint8_t*>(mem))
PipelineCache::PipelineCache(const VkPipelineCacheCreateInfo *pCreateInfo, void *mem)
: dataSize(ComputeRequiredAllocationSize(pCreateInfo))
, data(reinterpret_cast<uint8_t *>(mem))
{
CacheHeader* header = reinterpret_cast<CacheHeader*>(mem);
CacheHeader *header = reinterpret_cast<CacheHeader *>(mem);
header->headerLength = sizeof(CacheHeader);
header->headerVersion = VK_PIPELINE_CACHE_HEADER_VERSION_ONE;
header->vendorID = VENDOR_ID;
......@@ -175,17 +176,17 @@ PipelineCache::~PipelineCache()
computePrograms.clear();
}
void PipelineCache::destroy(const VkAllocationCallbacks* pAllocator)
void PipelineCache::destroy(const VkAllocationCallbacks *pAllocator)
{
vk::deallocate(data, pAllocator);
}
size_t PipelineCache::ComputeRequiredAllocationSize(const VkPipelineCacheCreateInfo* pCreateInfo)
size_t PipelineCache::ComputeRequiredAllocationSize(const VkPipelineCacheCreateInfo *pCreateInfo)
{
return pCreateInfo->initialDataSize + sizeof(CacheHeader);
}
VkResult PipelineCache::getData(size_t* pDataSize, void* pData)
VkResult PipelineCache::getData(size_t *pDataSize, void *pData)
{
if(!pData)
{
......@@ -207,11 +208,11 @@ VkResult PipelineCache::getData(size_t* pDataSize, void* pData)
return VK_SUCCESS;
}
VkResult PipelineCache::merge(uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches)
VkResult PipelineCache::merge(uint32_t srcCacheCount, const VkPipelineCache *pSrcCaches)
{
for(uint32_t i = 0; i < srcCacheCount; i++)
{
PipelineCache* srcCache = Cast(pSrcCaches[i]);
PipelineCache *srcCache = Cast(pSrcCaches[i]);
{
std::unique_lock<std::mutex> lock(spirvShadersMutex);
......@@ -227,24 +228,24 @@ VkResult PipelineCache::merge(uint32_t srcCacheCount, const VkPipelineCache* pSr
return VK_SUCCESS;
}
const std::shared_ptr<sw::SpirvShader>* PipelineCache::operator[](const PipelineCache::SpirvShaderKey& key) const
const std::shared_ptr<sw::SpirvShader> *PipelineCache::operator[](const PipelineCache::SpirvShaderKey &key) const
{
auto it = spirvShaders.find(key);
return (it != spirvShaders.end()) ? &(it->second) : nullptr;
}
void PipelineCache::insert(const PipelineCache::SpirvShaderKey& key, const std::shared_ptr<sw::SpirvShader> &shader)
void PipelineCache::insert(const PipelineCache::SpirvShaderKey &key, const std::shared_ptr<sw::SpirvShader> &shader)
{
spirvShaders[key] = shader;
}
const std::shared_ptr<sw::ComputeProgram>* PipelineCache::operator[](const PipelineCache::ComputeProgramKey& key) const
const std::shared_ptr<sw::ComputeProgram> *PipelineCache::operator[](const PipelineCache::ComputeProgramKey &key) const
{
auto it = computePrograms.find(key);
return (it != computePrograms.end()) ? &(it->second) : nullptr;
}
void PipelineCache::insert(const PipelineCache::ComputeProgramKey& key, const std::shared_ptr<sw::ComputeProgram> &computeProgram)
void PipelineCache::insert(const PipelineCache::ComputeProgramKey &key, const std::shared_ptr<sw::ComputeProgram> &computeProgram)
{
computePrograms[key] = computeProgram;
}
......
......@@ -40,46 +40,46 @@ class RenderPass;
class PipelineCache : public Object<PipelineCache, VkPipelineCache>
{
public:
PipelineCache(const VkPipelineCacheCreateInfo* pCreateInfo, void* mem);
PipelineCache(const VkPipelineCacheCreateInfo *pCreateInfo, void *mem);
virtual ~PipelineCache();
void destroy(const VkAllocationCallbacks* pAllocator);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkPipelineCacheCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkPipelineCacheCreateInfo *pCreateInfo);
VkResult getData(size_t* pDataSize, void* pData);
VkResult merge(uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches);
VkResult getData(size_t *pDataSize, void *pData);
VkResult merge(uint32_t srcCacheCount, const VkPipelineCache *pSrcCaches);
struct SpirvShaderKey
{
struct SpecializationInfo
{
SpecializationInfo(const VkSpecializationInfo* specializationInfo);
SpecializationInfo(const VkSpecializationInfo *specializationInfo);
bool operator<(const SpecializationInfo& specializationInfo) const;
bool operator<(const SpecializationInfo &specializationInfo) const;
const VkSpecializationInfo* get() const { return info.get(); }
const VkSpecializationInfo *get() const { return info.get(); }
private:
struct Deleter
{
void operator()(VkSpecializationInfo*) const;
void operator()(VkSpecializationInfo *) const;
};
std::shared_ptr<VkSpecializationInfo> info;
};
SpirvShaderKey(const VkShaderStageFlagBits pipelineStage,
const std::string& entryPointName,
const std::vector<uint32_t>& insns,
const std::string &entryPointName,
const std::vector<uint32_t> &insns,
const vk::RenderPass *renderPass,
const uint32_t subpassIndex,
const VkSpecializationInfo* specializationInfo);
const VkSpecializationInfo *specializationInfo);
bool operator<(const SpirvShaderKey &other) const;
const VkShaderStageFlagBits& getPipelineStage() const { return pipelineStage; }
const std::string& getEntryPointName() const { return entryPointName; }
const std::vector<uint32_t>& getInsns() const { return insns; }
const VkShaderStageFlagBits &getPipelineStage() const { return pipelineStage; }
const std::string &getEntryPointName() const { return entryPointName; }
const std::vector<uint32_t> &getInsns() const { return insns; }
const vk::RenderPass *getRenderPass() const { return renderPass; }
uint32_t getSubpassIndex() const { return subpassIndex; }
const VkSpecializationInfo *getSpecializationInfo() const { return specializationInfo.get(); }
......@@ -93,14 +93,15 @@ public:
const SpecializationInfo specializationInfo;
};
std::mutex& getShaderMutex() { return spirvShadersMutex; }
const std::shared_ptr<sw::SpirvShader>* operator[](const PipelineCache::SpirvShaderKey& key) const;
void insert(const PipelineCache::SpirvShaderKey& key, const std::shared_ptr<sw::SpirvShader> &shader);
std::mutex &getShaderMutex() { return spirvShadersMutex; }
const std::shared_ptr<sw::SpirvShader> *operator[](const PipelineCache::SpirvShaderKey &key) const;
void insert(const PipelineCache::SpirvShaderKey &key, const std::shared_ptr<sw::SpirvShader> &shader);
struct ComputeProgramKey
{
ComputeProgramKey(const sw::SpirvShader* shader, const vk::PipelineLayout* layout) :
shader(shader), layout(layout)
ComputeProgramKey(const sw::SpirvShader *shader, const vk::PipelineLayout *layout)
: shader(shader)
, layout(layout)
{}
bool operator<(const ComputeProgramKey &other) const
......@@ -108,17 +109,17 @@ public:
return std::tie(shader, layout) < std::tie(other.shader, other.layout);
}
const sw::SpirvShader* getShader() const { return shader; }
const vk::PipelineLayout* getLayout() const { return layout; }
const sw::SpirvShader *getShader() const { return shader; }
const vk::PipelineLayout *getLayout() const { return layout; }
private:
const sw::SpirvShader* shader;
const vk::PipelineLayout* layout;
const sw::SpirvShader *shader;
const vk::PipelineLayout *layout;
};
std::mutex& getProgramMutex() { return computeProgramsMutex; }
const std::shared_ptr<sw::ComputeProgram>* operator[](const PipelineCache::ComputeProgramKey& key) const;
void insert(const PipelineCache::ComputeProgramKey& key, const std::shared_ptr<sw::ComputeProgram> &computeProgram);
std::mutex &getProgramMutex() { return computeProgramsMutex; }
const std::shared_ptr<sw::ComputeProgram> *operator[](const PipelineCache::ComputeProgramKey &key) const;
void insert(const PipelineCache::ComputeProgramKey &key, const std::shared_ptr<sw::ComputeProgram> &computeProgram);
private:
struct CacheHeader
......@@ -127,11 +128,11 @@ private:
uint32_t headerVersion;
uint32_t vendorID;
uint32_t deviceID;
uint8_t pipelineCacheUUID[VK_UUID_SIZE];
uint8_t pipelineCacheUUID[VK_UUID_SIZE];
};
size_t dataSize = 0;
uint8_t* data = nullptr;
uint8_t *data = nullptr;
std::mutex spirvShadersMutex;
std::map<SpirvShaderKey, std::shared_ptr<sw::SpirvShader>> spirvShaders;
......@@ -140,11 +141,11 @@ private:
std::map<ComputeProgramKey, std::shared_ptr<sw::ComputeProgram>> computePrograms;
};
static inline PipelineCache* Cast(VkPipelineCache object)
static inline PipelineCache *Cast(VkPipelineCache object)
{
return PipelineCache::Cast(object);
}
} // namespace vk
#endif // VK_PIPELINE_CACHE_HPP_
#endif // VK_PIPELINE_CACHE_HPP_
......@@ -17,13 +17,14 @@
namespace vk {
PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo* pCreateInfo, void* mem)
: setLayoutCount(pCreateInfo->setLayoutCount), pushConstantRangeCount(pCreateInfo->pushConstantRangeCount)
PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo *pCreateInfo, void *mem)
: setLayoutCount(pCreateInfo->setLayoutCount)
, pushConstantRangeCount(pCreateInfo->pushConstantRangeCount)
{
char* hostMem = reinterpret_cast<char*>(mem);
char *hostMem = reinterpret_cast<char *>(mem);
size_t setLayoutsSize = pCreateInfo->setLayoutCount * sizeof(DescriptorSetLayout*);
setLayouts = reinterpret_cast<DescriptorSetLayout**>(hostMem);
size_t setLayoutsSize = pCreateInfo->setLayoutCount * sizeof(DescriptorSetLayout *);
setLayouts = reinterpret_cast<DescriptorSetLayout **>(hostMem);
for(uint32_t i = 0; i < pCreateInfo->setLayoutCount; i++)
{
setLayouts[i] = vk::Cast(pCreateInfo->pSetLayouts[i]);
......@@ -31,11 +32,11 @@ PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo* pCreateInfo, vo
hostMem += setLayoutsSize;
size_t pushConstantRangesSize = pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange);
pushConstantRanges = reinterpret_cast<VkPushConstantRange*>(hostMem);
pushConstantRanges = reinterpret_cast<VkPushConstantRange *>(hostMem);
memcpy(pushConstantRanges, pCreateInfo->pPushConstantRanges, pushConstantRangesSize);
hostMem += pushConstantRangesSize;
dynamicOffsetBases = reinterpret_cast<uint32_t*>(hostMem);
dynamicOffsetBases = reinterpret_cast<uint32_t *>(hostMem);
uint32_t dynamicOffsetBase = 0;
for(uint32_t i = 0; i < setLayoutCount; i++)
{
......@@ -46,16 +47,16 @@ PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo* pCreateInfo, vo
}
}
void PipelineLayout::destroy(const VkAllocationCallbacks* pAllocator)
void PipelineLayout::destroy(const VkAllocationCallbacks *pAllocator)
{
vk::deallocate(setLayouts, pAllocator); // pushConstantRanges are in the same allocation
vk::deallocate(setLayouts, pAllocator); // pushConstantRanges are in the same allocation
}
size_t PipelineLayout::ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo* pCreateInfo)
size_t PipelineLayout::ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo *pCreateInfo)
{
return (pCreateInfo->setLayoutCount * sizeof(DescriptorSetLayout*)) +
return (pCreateInfo->setLayoutCount * sizeof(DescriptorSetLayout *)) +
(pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange)) +
(pCreateInfo->setLayoutCount * sizeof(uint32_t)); // dynamicOffsetBases
(pCreateInfo->setLayoutCount * sizeof(uint32_t)); // dynamicOffsetBases
}
size_t PipelineLayout::getNumDescriptorSets() const
......@@ -63,7 +64,7 @@ size_t PipelineLayout::getNumDescriptorSets() const
return setLayoutCount;
}
DescriptorSetLayout const* PipelineLayout::getDescriptorSetLayout(size_t descriptorSet) const
DescriptorSetLayout const *PipelineLayout::getDescriptorSetLayout(size_t descriptorSet) const
{
ASSERT(descriptorSet < setLayoutCount);
return setLayouts[descriptorSet];
......
......@@ -22,31 +22,31 @@ namespace vk {
class PipelineLayout : public Object<PipelineLayout, VkPipelineLayout>
{
public:
PipelineLayout(const VkPipelineLayoutCreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator);
PipelineLayout(const VkPipelineLayoutCreateInfo *pCreateInfo, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo *pCreateInfo);
size_t getNumDescriptorSets() const;
DescriptorSetLayout const* getDescriptorSetLayout(size_t descriptorSet) const;
DescriptorSetLayout const *getDescriptorSetLayout(size_t descriptorSet) const;
// Returns the starting index into the pipeline's dynamic offsets array for
// the given descriptor set.
uint32_t getDynamicOffsetBase(size_t descriptorSet) const;
private:
uint32_t setLayoutCount = 0;
DescriptorSetLayout** setLayouts = nullptr;
uint32_t pushConstantRangeCount = 0;
VkPushConstantRange* pushConstantRanges = nullptr;
uint32_t* dynamicOffsetBases = nullptr; // Base offset per set layout.
uint32_t setLayoutCount = 0;
DescriptorSetLayout **setLayouts = nullptr;
uint32_t pushConstantRangeCount = 0;
VkPushConstantRange *pushConstantRanges = nullptr;
uint32_t *dynamicOffsetBases = nullptr; // Base offset per set layout.
};
static inline PipelineLayout* Cast(VkPipelineLayout object)
static inline PipelineLayout *Cast(VkPipelineLayout object)
{
return PipelineLayout::Cast(object);
}
} // namespace vk
#endif // VK_PIPELINE_LAYOUT_HPP_
#endif // VK_PIPELINE_LAYOUT_HPP_
......@@ -20,7 +20,12 @@
namespace vk {
Query::Query() : finished(marl::Event::Mode::Manual), state(UNAVAILABLE), type(INVALID_TYPE), value(0) {}
Query::Query()
: finished(marl::Event::Mode::Manual)
, state(UNAVAILABLE)
, type(INVALID_TYPE)
, value(0)
{}
void Query::reset()
{
......@@ -82,9 +87,10 @@ void Query::add(int64_t v)
value += v;
}
QueryPool::QueryPool(const VkQueryPoolCreateInfo* pCreateInfo, void* mem) :
pool(reinterpret_cast<Query*>(mem)), type(pCreateInfo->queryType),
count(pCreateInfo->queryCount)
QueryPool::QueryPool(const VkQueryPoolCreateInfo *pCreateInfo, void *mem)
: pool(reinterpret_cast<Query *>(mem))
, type(pCreateInfo->queryType)
, count(pCreateInfo->queryCount)
{
// According to the Vulkan spec, section 34.1. Features:
// "pipelineStatisticsQuery specifies whether the pipeline statistics
......@@ -100,22 +106,22 @@ QueryPool::QueryPool(const VkQueryPoolCreateInfo* pCreateInfo, void* mem) :
// Construct all queries
for(uint32_t i = 0; i < count; i++)
{
new (&pool[i]) Query();
new(&pool[i]) Query();
}
}
void QueryPool::destroy(const VkAllocationCallbacks* pAllocator)
void QueryPool::destroy(const VkAllocationCallbacks *pAllocator)
{
vk::deallocate(pool, pAllocator);
}
size_t QueryPool::ComputeRequiredAllocationSize(const VkQueryPoolCreateInfo* pCreateInfo)
size_t QueryPool::ComputeRequiredAllocationSize(const VkQueryPoolCreateInfo *pCreateInfo)
{
return sizeof(Query) * pCreateInfo->queryCount;
}
VkResult QueryPool::getResults(uint32_t firstQuery, uint32_t queryCount, size_t dataSize,
void* pData, VkDeviceSize stride, VkQueryResultFlags flags) const
void *pData, VkDeviceSize stride, VkQueryResultFlags flags) const
{
// dataSize must be large enough to contain the result of each query
ASSERT(static_cast<size_t>(stride * queryCount) <= dataSize);
......@@ -124,7 +130,7 @@ VkResult QueryPool::getResults(uint32_t firstQuery, uint32_t queryCount, size_t
ASSERT((firstQuery + queryCount) <= count);
VkResult result = VK_SUCCESS;
uint8_t* data = static_cast<uint8_t*>(pData);
uint8_t *data = static_cast<uint8_t *>(pData);
for(uint32_t i = firstQuery; i < (firstQuery + queryCount); i++, data += stride)
{
// If VK_QUERY_RESULT_WAIT_BIT and VK_QUERY_RESULT_PARTIAL_BIT are both not set
......@@ -134,7 +140,7 @@ VkResult QueryPool::getResults(uint32_t firstQuery, uint32_t queryCount, size_t
// queries if VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is set.
auto &query = pool[i];
if(flags & VK_QUERY_RESULT_WAIT_BIT) // Must wait for query to finish
if(flags & VK_QUERY_RESULT_WAIT_BIT) // Must wait for query to finish
{
query.wait();
}
......@@ -145,29 +151,29 @@ VkResult QueryPool::getResults(uint32_t firstQuery, uint32_t queryCount, size_t
if(current.state == Query::ACTIVE)
{
result = VK_NOT_READY;
writeResult = (flags & VK_QUERY_RESULT_PARTIAL_BIT); // Allow writing partial results
writeResult = (flags & VK_QUERY_RESULT_PARTIAL_BIT); // Allow writing partial results
}
if(flags & VK_QUERY_RESULT_64_BIT)
{
uint64_t* result64 = reinterpret_cast<uint64_t*>(data);
uint64_t *result64 = reinterpret_cast<uint64_t *>(data);
if(writeResult)
{
result64[0] = current.value;
}
if(flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) // Output query availablity
if(flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) // Output query availablity
{
result64[1] = current.state;
}
}
else
{
uint32_t* result32 = reinterpret_cast<uint32_t*>(data);
uint32_t *result32 = reinterpret_cast<uint32_t *>(data);
if(writeResult)
{
result32[0] = static_cast<uint32_t>(current.value);
}
if(flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) // Output query availablity
if(flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) // Output query availablity
{
result32[1] = current.state;
}
......@@ -213,7 +219,9 @@ void QueryPool::writeTimestamp(uint32_t query)
ASSERT(type == VK_QUERY_TYPE_TIMESTAMP);
pool[query].set(std::chrono::time_point_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now()).time_since_epoch().count());
std::chrono::system_clock::now())
.time_since_epoch()
.count());
}
} // namespace vk
......@@ -42,8 +42,8 @@ public:
struct Data
{
State state; // The current query state.
int64_t value; // The current query value.
State state; // The current query state.
int64_t value; // The current query value.
};
// reset() sets the state of the Query to UNAVAILABLE, sets the type to
......@@ -92,32 +92,32 @@ private:
class QueryPool : public Object<QueryPool, VkQueryPool>
{
public:
QueryPool(const VkQueryPoolCreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator);
QueryPool(const VkQueryPoolCreateInfo *pCreateInfo, void *mem);
void destroy(const VkAllocationCallbacks *pAllocator);
static size_t ComputeRequiredAllocationSize(const VkQueryPoolCreateInfo* pCreateInfo);
static size_t ComputeRequiredAllocationSize(const VkQueryPoolCreateInfo *pCreateInfo);
VkResult getResults(uint32_t firstQuery, uint32_t queryCount, size_t dataSize,
void* pData, VkDeviceSize stride, VkQueryResultFlags flags) const;
void *pData, VkDeviceSize stride, VkQueryResultFlags flags) const;
void begin(uint32_t query, VkQueryControlFlags flags);
void end(uint32_t query);
void reset(uint32_t firstQuery, uint32_t queryCount);
void writeTimestamp(uint32_t query);
inline Query* getQuery(uint32_t query) const { return &(pool[query]); }
inline Query *getQuery(uint32_t query) const { return &(pool[query]); }
private:
Query* pool;
Query *pool;
VkQueryType type;
uint32_t count;
};
static inline QueryPool* Cast(VkQueryPool object)
static inline QueryPool *Cast(VkQueryPool object)
{
return QueryPool::Cast(object);
}
} // namespace vk
#endif // VK_QUERY_POOL_HPP_
#endif // VK_QUERY_POOL_HPP_
......@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "VkQueue.hpp"
#include "VkCommandBuffer.hpp"
#include "VkFence.hpp"
#include "VkQueue.hpp"
#include "VkSemaphore.hpp"
#include "WSI/VkSwapchainKHR.hpp"
#include "Device/Renderer.hpp"
#include "WSI/VkSwapchainKHR.hpp"
#include "marl/defer.h"
#include "marl/scheduler.h"
......@@ -28,7 +28,7 @@
namespace {
VkSubmitInfo* DeepCopySubmitInfo(uint32_t submitCount, const VkSubmitInfo* pSubmits)
VkSubmitInfo *DeepCopySubmitInfo(uint32_t submitCount, const VkSubmitInfo *pSubmits)
{
size_t submitSize = sizeof(VkSubmitInfo) * submitCount;
size_t totalSize = submitSize;
......@@ -40,32 +40,32 @@ VkSubmitInfo* DeepCopySubmitInfo(uint32_t submitCount, const VkSubmitInfo* pSubm
totalSize += pSubmits[i].commandBufferCount * sizeof(VkCommandBuffer);
}
uint8_t* mem = static_cast<uint8_t*>(
vk::allocate(totalSize, vk::REQUIRED_MEMORY_ALIGNMENT, vk::DEVICE_MEMORY, vk::Fence::GetAllocationScope()));
uint8_t *mem = static_cast<uint8_t *>(
vk::allocate(totalSize, vk::REQUIRED_MEMORY_ALIGNMENT, vk::DEVICE_MEMORY, vk::Fence::GetAllocationScope()));
auto submits = new (mem) VkSubmitInfo[submitCount];
auto submits = new(mem) VkSubmitInfo[submitCount];
memcpy(mem, pSubmits, submitSize);
mem += submitSize;
for(uint32_t i = 0; i < submitCount; i++)
{
size_t size = pSubmits[i].waitSemaphoreCount * sizeof(VkSemaphore);
submits[i].pWaitSemaphores = reinterpret_cast<const VkSemaphore*>(mem);
submits[i].pWaitSemaphores = reinterpret_cast<const VkSemaphore *>(mem);
memcpy(mem, pSubmits[i].pWaitSemaphores, size);
mem += size;
size = pSubmits[i].waitSemaphoreCount * sizeof(VkPipelineStageFlags);
submits[i].pWaitDstStageMask = reinterpret_cast<const VkPipelineStageFlags*>(mem);
submits[i].pWaitDstStageMask = reinterpret_cast<const VkPipelineStageFlags *>(mem);
memcpy(mem, pSubmits[i].pWaitDstStageMask, size);
mem += size;
size = pSubmits[i].signalSemaphoreCount * sizeof(VkSemaphore);
submits[i].pSignalSemaphores = reinterpret_cast<const VkSemaphore*>(mem);
submits[i].pSignalSemaphores = reinterpret_cast<const VkSemaphore *>(mem);
memcpy(mem, pSubmits[i].pSignalSemaphores, size);
mem += size;
size = pSubmits[i].commandBufferCount * sizeof(VkCommandBuffer);
submits[i].pCommandBuffers = reinterpret_cast<const VkCommandBuffer*>(mem);
submits[i].pCommandBuffers = reinterpret_cast<const VkCommandBuffer *>(mem);
memcpy(mem, pSubmits[i].pCommandBuffers, size);
mem += size;
}
......@@ -77,7 +77,8 @@ VkSubmitInfo* DeepCopySubmitInfo(uint32_t submitCount, const VkSubmitInfo* pSubm
namespace vk {
Queue::Queue(Device* device, marl::Scheduler *scheduler) : device(device)
Queue::Queue(Device *device, marl::Scheduler *scheduler)
: device(device)
{
queueThread = std::thread(&Queue::taskLoop, this, scheduler);
}
......@@ -94,7 +95,7 @@ Queue::~Queue()
garbageCollect();
}
VkResult Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, Fence* fence)
VkResult Queue::submit(uint32_t submitCount, const VkSubmitInfo *pSubmits, Fence *fence)
{
garbageCollect();
......@@ -113,7 +114,7 @@ VkResult Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, Fence
return VK_SUCCESS;
}
void Queue::submitQueue(const Task& task)
void Queue::submitQueue(const Task &task)
{
if(renderer == nullptr)
{
......@@ -122,7 +123,7 @@ void Queue::submitQueue(const Task& task)
for(uint32_t i = 0; i < task.submitCount; i++)
{
auto& submitInfo = task.pSubmits[i];
auto &submitInfo = task.pSubmits[i];
for(uint32_t j = 0; j < submitInfo.waitSemaphoreCount; j++)
{
vk::Cast(submitInfo.pWaitSemaphores[j])->wait(submitInfo.pWaitDstStageMask[j]);
......@@ -158,7 +159,7 @@ void Queue::submitQueue(const Task& task)
}
}
void Queue::taskLoop(marl::Scheduler* scheduler)
void Queue::taskLoop(marl::Scheduler *scheduler)
{
marl::Thread::setName("Queue<%p>", this);
scheduler->bind();
......@@ -170,15 +171,15 @@ void Queue::taskLoop(marl::Scheduler* scheduler)
switch(task.type)
{
case Task::KILL_THREAD:
ASSERT_MSG(pending.count() == 0, "queue has remaining work!");
return;
case Task::SUBMIT_QUEUE:
submitQueue(task);
break;
default:
UNIMPLEMENTED("task.type %d", static_cast<int>(task.type));
break;
case Task::KILL_THREAD:
ASSERT_MSG(pending.count() == 0, "queue has remaining work!");
return;
case Task::SUBMIT_QUEUE:
submitQueue(task);
break;
default:
UNIMPLEMENTED("task.type %d", static_cast<int>(task.type));
break;
}
}
}
......@@ -211,7 +212,7 @@ void Queue::garbageCollect()
}
#ifndef __ANDROID__
VkResult Queue::present(const VkPresentInfoKHR* presentInfo)
VkResult Queue::present(const VkPresentInfoKHR *presentInfo)
{
// This is a hack to deal with screen tearing for now.
// Need to correctly implement threading using VkSemaphore
......
......@@ -17,12 +17,14 @@
#include "VkObject.hpp"
#include "Device/Renderer.hpp"
#include <thread>
#include <vulkan/vk_icd.h>
#include <thread>
#include "System/Synchronization.hpp"
namespace marl { class Scheduler; }
namespace marl {
class Scheduler;
}
namespace sw {
......@@ -41,7 +43,7 @@ class Queue
VK_LOADER_DATA loaderData = { ICD_LOADER_MAGIC };
public:
Queue(Device* device, marl::Scheduler *scheduler);
Queue(Device *device, marl::Scheduler *scheduler);
~Queue();
operator VkQueue()
......@@ -49,39 +51,43 @@ public:
return reinterpret_cast<VkQueue>(this);
}
VkResult submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, Fence* fence);
VkResult submit(uint32_t submitCount, const VkSubmitInfo *pSubmits, Fence *fence);
VkResult waitIdle();
#ifndef __ANDROID__
VkResult present(const VkPresentInfoKHR* presentInfo);
VkResult present(const VkPresentInfoKHR *presentInfo);
#endif
private:
struct Task
{
uint32_t submitCount = 0;
VkSubmitInfo* pSubmits = nullptr;
sw::TaskEvents* events = nullptr;
enum Type { KILL_THREAD, SUBMIT_QUEUE };
VkSubmitInfo *pSubmits = nullptr;
sw::TaskEvents *events = nullptr;
enum Type
{
KILL_THREAD,
SUBMIT_QUEUE
};
Type type = SUBMIT_QUEUE;
};
void taskLoop(marl::Scheduler* scheduler);
void taskLoop(marl::Scheduler *scheduler);
void garbageCollect();
void submitQueue(const Task& task);
void submitQueue(const Task &task);
Device* device;
Device *device;
std::unique_ptr<sw::Renderer> renderer;
sw::Chan<Task> pending;
sw::Chan<VkSubmitInfo*> toDelete;
sw::Chan<VkSubmitInfo *> toDelete;
std::thread queueThread;
};
static inline Queue* Cast(VkQueue object)
static inline Queue *Cast(VkQueue object)
{
return reinterpret_cast<Queue*>(object);
return reinterpret_cast<Queue *>(object);
}
} // namespace vk
#endif // VK_QUEUE_HPP_
#endif // VK_QUEUE_HPP_
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment