gfx: better hashing strategies (#3969)

This commit is contained in:
Yun Hsiao Wu
2021-10-13 16:03:58 +08:00
committed by GitHub
parent 70dae69670
commit 8f8569f39e
74 changed files with 626 additions and 1571 deletions
+5 -3
View File
@@ -29,6 +29,8 @@
#pragma once
#include <cstdint>
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
#include <BaseTsd.h>
#if !defined(__SSIZE_T) && !defined(_SSIZE_T_)
@@ -325,10 +327,10 @@ It should work same as apples CFSwapInt32LittleToHost(..)
#define CC_CPU CC_CPU_UNKNOWN
#endif
#if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__) || defined(__arm64__) || defined(_aarch64_) || defined(__mips64) || defined(__mips64_)
#define CC_CPU_ARCH CC_CPU_ARCH_64
#else
#if INTPTR_MAX == INT32_MAX
#define CC_CPU_ARCH CC_CPU_ARCH_32
#else
#define CC_CPU_ARCH CC_CPU_ARCH_64
#endif
// C11 features
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -850,7 +850,7 @@ bool js_register_cc_gfx_DeviceManager(se::Object* obj);
bool register_all_gfx(se::Object* obj);
JSB_REGISTER_OBJECT_TYPE(cc::gfx::DeviceManager);
SE_DECLARE_FUNC(js_gfx_DeviceManager_destroy);
SE_DECLARE_FUNC(js_gfx_DeviceManager_create);
SE_DECLARE_FUNC(js_gfx_DeviceManager_destroy);
SE_DECLARE_FUNC(js_gfx_DeviceManager_addSurfaceEventListener);
@@ -43,8 +43,8 @@ class FrameGraph final {
public:
using ResourceHandleBlackboard = Blackboard<StringHandle, Handle::IndexType, Handle::UNINITIALIZED>;
FrameGraph() = default;
~FrameGraph() = default;
FrameGraph() = default;
~FrameGraph() = default;
FrameGraph(const FrameGraph &) = delete;
FrameGraph(FrameGraph &&) noexcept = delete;
FrameGraph &operator=(const FrameGraph &) = delete;
@@ -64,8 +64,8 @@ public:
template <typename Data, typename SetupMethod, typename ExecuteMethod>
const CallbackPass<Data, ExecuteMethod> &addPass(PassInsertPoint insertPoint, const StringHandle &name, SetupMethod setup, ExecuteMethod &&execute) noexcept;
template <typename ResourceType>
TypedHandle<ResourceType> create(const StringHandle &name, const typename ResourceType::Descriptor &desc) noexcept;
template <typename DescriptorType, typename ResourceType = typename ResourceTypeLookupTable<DescriptorType>::Resource>
TypedHandle<ResourceType> create(const StringHandle &name, const DescriptorType &desc) noexcept;
template <typename ResourceType>
TypedHandle<ResourceType> importExternal(const StringHandle &name, ResourceType &resource) noexcept;
void move(TextureHandle from, TextureHandle to, uint8_t mipmapLevel, uint8_t faceId, uint8_t arrayPosition) noexcept;
@@ -113,8 +113,8 @@ const CallbackPass<Data, ExecuteMethod> &FrameGraph::addPass(const PassInsertPoi
return *pass;
}
template <typename ResourceType>
TypedHandle<ResourceType> FrameGraph::create(const StringHandle &name, const typename ResourceType::Descriptor &desc) noexcept {
template <typename DescriptorType, typename ResourceType>
TypedHandle<ResourceType> FrameGraph::create(const StringHandle &name, const DescriptorType &desc) noexcept {
auto *const virtualResource = new ResourceEntry<ResourceType>(name, static_cast<ID>(_virtualResources.size()), desc);
return TypedHandle<ResourceType>(create(virtualResource));
}
@@ -132,9 +132,9 @@ void FrameGraph::enableMerge(bool const enable) noexcept {
//////////////////////////////////////////////////////////////////////////
template <typename ResourceType>
TypedHandle<ResourceType> PassNodeBuilder::create(const StringHandle &name, const typename ResourceType::Descriptor &desc) const noexcept {
return _graph.create<ResourceType>(name, desc);
template <typename DescriptorType, typename ResourceType>
TypedHandle<ResourceType> PassNodeBuilder::create(const StringHandle &name, const DescriptorType &desc) const noexcept {
return _graph.create(name, desc);
}
template <typename ResourceType>
@@ -40,8 +40,8 @@ public:
PassNodeBuilder &operator=(const PassNodeBuilder &) = delete;
PassNodeBuilder &operator=(PassNodeBuilder &&) = delete;
template <typename ResourceType>
TypedHandle<ResourceType> create(const StringHandle &name, const typename ResourceType::Descriptor &desc) const noexcept;
template <typename DescriptorType, typename ResourceType = typename ResourceTypeLookupTable<DescriptorType>::Resource>
TypedHandle<ResourceType> create(const StringHandle &name, const DescriptorType &desc) const noexcept;
template <typename ResourceType>
TypedHandle<ResourceType> importExternal(const StringHandle &name, ResourceType &resource) const noexcept;
template <typename ResourceType>
+11 -4
View File
@@ -44,13 +44,16 @@ struct DeviceResourceCreator final {
}
};
template <typename DescriptorType>
struct ResourceTypeLookupTable final {};
template <typename DeviceResourceType, typename DescriptorType,
typename DeviceResourceCreatorType = DeviceResourceCreator<DeviceResourceType, DescriptorType>>
class Resource final {
public:
using Allocator = ResourceAllocator<DeviceResourceType, DescriptorType, DeviceResourceCreatorType>;
using DeviceResource = DeviceResourceType;
using Descriptor = DescriptorType;
using Allocator = ResourceAllocator<DeviceResourceType, DescriptorType, DeviceResourceCreatorType>;
using DeviceResource = DeviceResourceType;
using Descriptor = DescriptorType;
Resource() = default;
explicit Resource(const Descriptor &desc);
@@ -136,7 +139,11 @@ const DescriptorType &Resource<DeviceResourceType, DescriptorType, DeviceResourc
} \
}; \
using Type = Resource<gfx::Type, gfx::Type##Info>; \
using Type##Handle = TypedHandle<Type>;
using Type##Handle = TypedHandle<Type>; \
template <> \
struct ResourceTypeLookupTable<gfx::Type##Info> final { \
using Resource = Type; \
};
// Descriptors must have std::hash specialization and == operators
DEFINE_GFX_RESOURCE(Buffer)
@@ -28,6 +28,7 @@
#include <algorithm>
#include <unordered_map>
#include "base/memory/Memory.h"
#include "gfx-base/GFXDef.h"
namespace cc {
namespace framegraph {
@@ -62,9 +63,9 @@ private:
ResourceAllocator() noexcept = default;
~ResourceAllocator() = default;
std::unordered_map<DescriptorType, DeviceResourcePool> _livepool{};
std::unordered_map<DescriptorType, DeviceResourcePoolGC> _deadpool{};
uint64_t _age{0};
std::unordered_map<DescriptorType, DeviceResourcePool, gfx::Hasher<DescriptorType>> _livepool{};
std::unordered_map<DescriptorType, DeviceResourcePoolGC, gfx::Hasher<DescriptorType>> _deadpool{};
uint64_t _age{0};
};
//////////////////////////////////////////////////////////////////////////
@@ -249,15 +249,15 @@ PipelineState *DeviceAgent::createPipelineState() {
return CC_NEW(PipelineStateAgent(actor));
}
Sampler *DeviceAgent::createSampler(const SamplerInfo &info, uint32_t hash) {
Sampler *DeviceAgent::createSampler(const SamplerInfo &info, size_t hash) {
return _actor->createSampler(info, hash);
}
GlobalBarrier *DeviceAgent::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) {
GlobalBarrier *DeviceAgent::createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) {
return _actor->createGlobalBarrier(info, hash);
}
TextureBarrier *DeviceAgent::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) {
TextureBarrier *DeviceAgent::createTextureBarrier(const TextureBarrierInfo &info, size_t hash) {
return _actor->createTextureBarrier(info, hash);
}
@@ -80,9 +80,9 @@ public:
PipelineLayout * createPipelineLayout() override;
PipelineState * createPipelineState() override;
Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override;
Sampler * createSampler(const SamplerInfo &info, size_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, size_t hash) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override;
+2 -4
View File
@@ -27,7 +27,6 @@
#include "GFXBuffer.h"
#include "GFXDevice.h"
#include "GFXObject.h"
namespace cc {
namespace gfx {
@@ -38,9 +37,8 @@ Buffer::Buffer()
Buffer::~Buffer() = default;
uint32_t Buffer::computeHash(const BufferInfo &info) {
std::hash<BufferInfo> hasher;
return utils::toUint(hasher(info));
size_t Buffer::computeHash(const BufferInfo &info) {
return Hasher<BufferInfo>()(info);
}
void Buffer::initialize(const BufferInfo &info) {
+1 -1
View File
@@ -35,7 +35,7 @@ public:
Buffer();
~Buffer() override;
static uint32_t computeHash(const BufferInfo &info);
static size_t computeHash(const BufferInfo &info);
void initialize(const BufferInfo &info);
void initialize(const BufferViewInfo &info);
+11 -34
View File
@@ -44,6 +44,7 @@
* * @ts-nullable: declare the member optional
* * @ts-overrides `YAML declaration`: overrides any parsed results, use with caution
* * each struct member have to be specified in a single line, including optional parser directives
* * members with a name starts with an underscore is automatically ignored
*/
namespace cc {
@@ -797,17 +798,6 @@ struct Rect {
int32_t y{0};
uint32_t width{0U};
uint32_t height{0U};
bool operator==(const Rect &rs) const {
return x == rs.x &&
y == rs.y &&
width == rs.width &&
height == rs.height;
}
bool operator!=(const Rect &rs) const {
return !(*this == rs);
}
};
struct Extent {
@@ -863,19 +853,6 @@ struct Viewport {
uint32_t height{0U};
float minDepth{0.F};
float maxDepth{1.F};
bool operator==(const Viewport &rs) const {
return (left == rs.left &&
top == rs.top &&
width == rs.width &&
height == rs.height &&
math::IsEqualF(minDepth, rs.minDepth) &&
math::IsEqualF(maxDepth, maxDepth));
}
bool operator!=(const Viewport &rs) const {
return !(*this == rs);
}
};
struct Color {
@@ -883,13 +860,6 @@ struct Color {
float y{0.F};
float z{0.F};
float w{0.F};
bool operator==(const Color &rhs) const {
return (math::IsEqualF(x, rhs.x) &&
math::IsEqualF(y, rhs.y) &&
math::IsEqualF(z, rhs.z) &&
math::IsEqualF(w, rhs.w));
}
};
using ColorList = vector<Color>;
@@ -922,12 +892,13 @@ struct DeviceInfo {
BindingMappingInfo bindingMappingInfo;
};
struct BufferInfo {
struct ALIGNAS(8) BufferInfo {
BufferUsage usage{BufferUsageBit::NONE};
MemoryUsage memUsage{MemoryUsageBit::NONE};
uint32_t size{0U};
uint32_t stride{0U}; // in bytes
BufferFlags flags{BufferFlagBit::NONE};
uint32_t _padding{0U};
};
struct BufferViewInfo {
@@ -963,7 +934,7 @@ struct IndirectBuffer {
DrawInfoList drawInfos;
};
struct TextureInfo {
struct ALIGNAS(8) TextureInfo {
TextureType type{TextureType::TEX2D};
TextureUsage usage{TextureUsageBit::NONE};
Format format{Format::UNKNOWN};
@@ -975,9 +946,12 @@ struct TextureInfo {
SampleCount samples{SampleCount::ONE};
uint32_t depth{1U};
void * externalRes{nullptr}; // CVPixelBuffer for Metal, EGLImage for GLES
#if CC_CPU_ARCH == CC_CPU_ARCH_32
uint32_t _padding{0U};
#endif
};
struct TextureViewInfo {
struct ALIGNAS(8) TextureViewInfo {
Texture * texture{nullptr};
TextureType type{TextureType::TEX2D};
Format format{Format::UNKNOWN};
@@ -985,6 +959,9 @@ struct TextureViewInfo {
uint32_t levelCount{1U};
uint32_t baseLayer{0U};
uint32_t layerCount{1U};
#if CC_CPU_ARCH == CC_CPU_ARCH_32
uint32_t _padding{0U};
#endif
};
struct SamplerInfo {
+140 -152
View File
@@ -23,167 +23,108 @@
THE SOFTWARE.
****************************************************************************/
#include <boost/functional/hash.hpp>
#include "base/CoreStd.h"
#include "base/Utils.h"
#include "GFXDef.h"
#include "GFXTexture.h"
#include "gfx-base/GFXDef-common.h"
namespace std {
std::size_t hash<cc::gfx::RenderPassInfo>::operator()(const cc::gfx::RenderPassInfo& info) const {
static auto computeAttachmentHash = [](const cc::gfx::ColorAttachment& attachment, uint32_t& seed) {
seed ^= toNumber(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.loadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.storeOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
for (cc::gfx::AccessType type : attachment.beginAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
for (cc::gfx::AccessType type : attachment.endAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
};
static auto computeDSAttachmentHash = [](const cc::gfx::DepthStencilAttachment& attachment, uint32_t& seed) {
seed ^= toNumber(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.depthLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.depthStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.stencilLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(attachment.stencilStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
for (auto type : attachment.beginAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
for (auto type : attachment.endAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
};
uint32_t seed = 0;
if (!info.subpasses.empty()) {
for (const auto& subpass : info.subpasses) {
for (const uint32_t iaIndex : subpass.inputs) {
if (iaIndex >= info.colorAttachments.size()) break;
const auto& ia = info.colorAttachments[iaIndex];
seed += cc::utils::toUint(4 + ia.beginAccesses.size() + ia.endAccesses.size());
}
for (const uint32_t caIndex : subpass.colors) {
if (caIndex >= info.colorAttachments.size()) break;
const auto& ca = info.colorAttachments[caIndex];
seed += cc::utils::toUint(4 + ca.beginAccesses.size() + ca.endAccesses.size());
}
for (const uint32_t raIndex : subpass.resolves) {
if (raIndex >= info.colorAttachments.size()) break;
const auto& ra = info.colorAttachments[raIndex];
seed += cc::utils::toUint(4 + ra.beginAccesses.size() + ra.endAccesses.size());
}
for (const uint32_t paIndex : subpass.preserves) {
if (paIndex >= info.colorAttachments.size()) break;
const auto& pa = info.colorAttachments[paIndex];
seed += cc::utils::toUint(4 + pa.beginAccesses.size() + pa.endAccesses.size());
}
if (subpass.depthStencil != cc::gfx::INVALID_BINDING) {
if (subpass.depthStencil < info.colorAttachments.size()) {
const auto& ds = info.colorAttachments[subpass.depthStencil];
seed += cc::utils::toUint(4 + ds.beginAccesses.size() + ds.endAccesses.size());
} else {
const auto& ds = info.depthStencilAttachment;
seed += cc::utils::toUint(6 + ds.beginAccesses.size() + ds.endAccesses.size());
}
}
}
for (const auto& subpass : info.subpasses) {
for (const uint32_t iaIndex : subpass.inputs) {
if (iaIndex >= info.colorAttachments.size()) break;
computeAttachmentHash(info.colorAttachments[iaIndex], seed);
}
for (const uint32_t caIndex : subpass.colors) {
if (caIndex >= info.colorAttachments.size()) break;
computeAttachmentHash(info.colorAttachments[caIndex], seed);
}
for (const uint32_t raIndex : subpass.resolves) {
if (raIndex >= info.colorAttachments.size()) break;
computeAttachmentHash(info.colorAttachments[raIndex], seed);
}
for (const uint32_t paIndex : subpass.preserves) {
if (paIndex >= info.colorAttachments.size()) break;
computeAttachmentHash(info.colorAttachments[paIndex], seed);
}
if (subpass.depthStencil != cc::gfx::INVALID_BINDING) {
if (subpass.depthStencil < info.colorAttachments.size()) {
computeAttachmentHash(info.colorAttachments[subpass.depthStencil], seed);
} else {
computeDSAttachmentHash(info.depthStencilAttachment, seed);
}
}
}
} else {
for (const auto& ca : info.colorAttachments) {
seed += cc::utils::toUint(4 + ca.beginAccesses.size() + ca.endAccesses.size());
}
seed += cc::utils::toUint(6 + info.depthStencilAttachment.beginAccesses.size() + info.depthStencilAttachment.endAccesses.size());
for (const auto& ca : info.colorAttachments) {
computeAttachmentHash(ca, seed);
}
computeDSAttachmentHash(info.depthStencilAttachment, seed);
}
return seed;
}
std::size_t hash<cc::gfx::FramebufferInfo>::operator()(const cc::gfx::FramebufferInfo& info) const {
auto seed = cc::utils::toUint(info.colorTextures.size() * 2 + (info.depthStencilTexture ? 2 : 0));
for (const auto* attachment : info.colorTextures) {
seed ^= attachment->getHash() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= attachment->getTypedID() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
if (info.depthStencilTexture) {
seed ^= info.depthStencilTexture->getHash() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.depthStencilTexture->getTypedID() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
return seed;
}
std::size_t hash<cc::gfx::TextureInfo>::operator()(const cc::gfx::TextureInfo& info) const {
uint32_t seed = 10;
seed ^= toNumber(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.samples) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.width + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.height + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.depth + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.layerCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.levelCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
}
std::size_t hash<cc::gfx::TextureViewInfo>::operator()(const cc::gfx::TextureViewInfo& info) const {
uint32_t seed = 7;
seed ^= info.texture->getHash() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.baseLevel + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.levelCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.baseLayer + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.layerCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
}
std::size_t hash<cc::gfx::BufferInfo>::operator()(const cc::gfx::BufferInfo& info) const {
uint32_t seed = 4;
seed ^= toNumber(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.memUsage) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= toNumber(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= info.size + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
}
} // namespace std
namespace cc {
namespace gfx {
// T must have no implicit padding
template <typename T>
size_t quickHashTrivialStruct(const T* info, size_t count = 1) {
static_assert(std::is_trivially_copyable<T>::value && sizeof(T) % 8 == 0, "T must be 8 bytes aligned and trivially copyable");
return boost::hash_range(reinterpret_cast<const uint64_t*>(info), reinterpret_cast<const uint64_t*>(info + count));
}
template <>
size_t Hasher<ColorAttachment>::operator()(const ColorAttachment& info) const {
size_t seed = 6;
boost::hash_combine(seed, info.format);
boost::hash_combine(seed, info.sampleCount);
boost::hash_combine(seed, info.loadOp);
boost::hash_combine(seed, info.storeOp);
boost::hash_combine(seed, info.beginAccesses);
boost::hash_combine(seed, info.endAccesses);
return seed;
}
template <>
size_t Hasher<DepthStencilAttachment>::operator()(const DepthStencilAttachment& info) const {
size_t seed = 8;
boost::hash_combine(seed, info.format);
boost::hash_combine(seed, info.sampleCount);
boost::hash_combine(seed, info.depthLoadOp);
boost::hash_combine(seed, info.depthStoreOp);
boost::hash_combine(seed, info.stencilLoadOp);
boost::hash_combine(seed, info.stencilStoreOp);
boost::hash_combine(seed, info.beginAccesses);
boost::hash_combine(seed, info.endAccesses);
return seed;
}
template <>
size_t Hasher<SubpassInfo>::operator()(const SubpassInfo& info) const {
size_t seed = 8;
boost::hash_combine(seed, info.inputs);
boost::hash_combine(seed, info.colors);
boost::hash_combine(seed, info.resolves);
boost::hash_combine(seed, info.preserves);
boost::hash_combine(seed, info.depthStencil);
boost::hash_combine(seed, info.depthStencilResolve);
boost::hash_combine(seed, info.depthResolveMode);
boost::hash_combine(seed, info.stencilResolveMode);
return seed;
}
template <>
size_t Hasher<SubpassDependency>::operator()(const SubpassDependency& info) const {
size_t seed = 4;
boost::hash_combine(seed, info.srcSubpass);
boost::hash_combine(seed, info.dstSubpass);
boost::hash_combine(seed, info.srcAccesses);
boost::hash_combine(seed, info.dstAccesses);
return seed;
}
template <>
size_t Hasher<RenderPassInfo>::operator()(const RenderPassInfo& info) const {
size_t seed = 4;
boost::hash_combine(seed, info.colorAttachments);
boost::hash_combine(seed, info.depthStencilAttachment);
boost::hash_combine(seed, info.subpasses);
boost::hash_combine(seed, info.dependencies);
return seed;
}
template <>
size_t Hasher<FramebufferInfo>::operator()(const FramebufferInfo& info) const {
size_t seed = 3;
boost::hash_combine(seed, info.renderPass);
boost::hash_combine(seed, info.colorTextures);
boost::hash_combine(seed, info.depthStencilTexture);
return seed;
}
template <>
size_t Hasher<TextureInfo>::operator()(const TextureInfo& info) const {
return quickHashTrivialStruct(&info);
}
template <>
size_t Hasher<TextureViewInfo>::operator()(const TextureViewInfo& info) const {
return quickHashTrivialStruct(&info);
}
template <>
size_t Hasher<BufferInfo>::operator()(const BufferInfo& info) const {
return quickHashTrivialStruct(&info);
}
bool operator==(const ColorAttachment& lhs, const ColorAttachment& rhs) {
return lhs.format == rhs.format &&
lhs.sampleCount == rhs.sampleCount &&
@@ -237,6 +178,53 @@ bool operator==(const FramebufferInfo& lhs, const FramebufferInfo& rhs) {
lhs.depthStencilTexture == rhs.depthStencilTexture;
}
bool operator==(const Viewport& lhs, const Viewport& rhs) {
return lhs.left == rhs.left &&
lhs.top == rhs.top &&
lhs.width == rhs.width &&
lhs.height == rhs.height &&
lhs.minDepth == rhs.minDepth &&
lhs.maxDepth == rhs.maxDepth;
}
bool operator!=(const Viewport& lhs, const Viewport& rhs) {
return !(lhs == rhs);
}
bool operator==(const Rect& lhs, const Rect& rhs) {
return lhs.x == rhs.x &&
lhs.y == rhs.y &&
lhs.width == rhs.width &&
lhs.height == rhs.height;
}
bool operator!=(const Rect& lhs, const Rect& rhs) {
return !(lhs == rhs);
}
bool operator==(const Color& lhs, const Color& rhs) {
return lhs.x == rhs.x &&
lhs.y == rhs.y &&
lhs.z == rhs.z &&
lhs.w == rhs.w;
}
bool operator==(const Offset& lhs, const Offset& rhs) {
return lhs.x == rhs.x &&
lhs.y == rhs.y &&
lhs.z == rhs.z;
}
bool operator==(const Extent& lhs, const Extent& rhs) {
return lhs.width == rhs.width &&
lhs.height == rhs.height &&
lhs.depth == rhs.depth;
}
bool operator==(const Size& lhs, const Size& rhs) {
return lhs.x == rhs.x &&
lhs.y == rhs.y &&
lhs.z == rhs.z;
}
bool operator==(const TextureInfo& lhs, const TextureInfo& rhs) {
return !memcmp(&lhs, &rhs, sizeof(TextureInfo));
}
+26 -23
View File
@@ -28,33 +28,36 @@
#include <functional>
#include "GFXDef-common.h"
namespace std {
template <>
struct hash<cc::gfx::RenderPassInfo> { std::size_t operator()(const cc::gfx::RenderPassInfo& info) const; };
template <>
struct hash<cc::gfx::FramebufferInfo> { std::size_t operator()(const cc::gfx::FramebufferInfo& info) const; };
template <>
struct hash<cc::gfx::TextureInfo> { std::size_t operator()(const cc::gfx::TextureInfo& info) const; };
template <>
struct hash<cc::gfx::TextureViewInfo> { std::size_t operator()(const cc::gfx::TextureViewInfo& info) const; };
template <>
struct hash<cc::gfx::BufferInfo> { std::size_t operator()(const cc::gfx::BufferInfo& info) const; };
} // namespace std
namespace cc {
namespace gfx {
extern bool operator==(const ColorAttachment& lhs, const ColorAttachment& rhs);
extern bool operator==(const DepthStencilAttachment& lhs, const DepthStencilAttachment& rhs);
extern bool operator==(const SubpassInfo& lhs, const SubpassInfo& rhs);
extern bool operator==(const SubpassDependency& lhs, const SubpassDependency& rhs);
extern bool operator==(const RenderPassInfo& lhs, const RenderPassInfo& rhs);
extern bool operator==(const FramebufferInfo& lhs, const FramebufferInfo& rhs);
extern bool operator==(const TextureInfo& lhs, const TextureInfo& rhs);
extern bool operator==(const TextureViewInfo& lhs, const TextureViewInfo& rhs);
extern bool operator==(const BufferInfo& lhs, const BufferInfo& rhs);
template <typename T, typename Enable = std::enable_if_t<std::is_class<T>::value>>
struct Hasher final { size_t operator()(const T& info) const; };
struct SwapchainTextureInfo {
// make this boost::hash compatible
template <typename T, typename Enable = std::enable_if_t<std::is_class<T>::value>>
size_t hash_value(const T& info) { return Hasher<T>()(info); } // NOLINT(readability-identifier-naming)
bool operator==(const ColorAttachment& lhs, const ColorAttachment& rhs);
bool operator==(const DepthStencilAttachment& lhs, const DepthStencilAttachment& rhs);
bool operator==(const SubpassInfo& lhs, const SubpassInfo& rhs);
bool operator==(const SubpassDependency& lhs, const SubpassDependency& rhs);
bool operator==(const RenderPassInfo& lhs, const RenderPassInfo& rhs);
bool operator==(const FramebufferInfo& lhs, const FramebufferInfo& rhs);
bool operator==(const Viewport& lhs, const Viewport& rhs);
bool operator==(const Rect& lhs, const Rect& rhs);
bool operator==(const Color& lhs, const Color& rhs);
bool operator==(const Offset& lhs, const Offset& rhs);
bool operator==(const Extent& lhs, const Extent& rhs);
bool operator==(const Size& lhs, const Size& rhs);
bool operator==(const TextureInfo& lhs, const TextureInfo& rhs);
bool operator==(const TextureViewInfo& lhs, const TextureViewInfo& rhs);
bool operator==(const BufferInfo& lhs, const BufferInfo& rhs);
bool operator!=(const Viewport& lhs, const Viewport& rhs);
bool operator!=(const Rect& lhs, const Rect& rhs);
struct SwapchainTextureInfo final {
Swapchain* swapchain{nullptr};
Format format{Format::UNKNOWN};
uint32_t width{0};
@@ -55,6 +55,12 @@ bool Device::initialize(const DeviceInfo &info) {
_bindingMappingInfo.samplerOffsets.push_back(0);
}
#if CC_CPU_ARCH == CC_CPU_ARCH_32
static_assert(sizeof(void*) == 4, "pointer size assumption broken");
#else
static_assert(sizeof(void*) == 8, "pointer size assumption broken");
#endif
return doInit(info);
}
+9 -9
View File
@@ -133,9 +133,9 @@ protected:
virtual PipelineLayout * createPipelineLayout() = 0;
virtual PipelineState * createPipelineState() = 0;
virtual Sampler * createSampler(const SamplerInfo &info, uint32_t hash) = 0;
virtual GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) = 0;
virtual TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) = 0;
virtual Sampler * createSampler(const SamplerInfo &info, size_t hash) = 0;
virtual GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) = 0;
virtual TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, size_t hash) = 0;
// For context switching between threads
virtual void bindContext(bool bound) {}
@@ -159,9 +159,9 @@ protected:
uint32_t _numTriangles{0U};
MemoryStatus _memoryStatus;
unordered_map<uint32_t, Sampler *> _samplers;
unordered_map<uint32_t, GlobalBarrier *> _globalBarriers;
unordered_map<uint32_t, TextureBarrier *> _textureBarriers;
unordered_map<size_t, Sampler *> _samplers;
unordered_map<size_t, GlobalBarrier *> _globalBarriers;
unordered_map<size_t, TextureBarrier *> _textureBarriers;
private:
vector<Swapchain *> _swapchains;
@@ -261,7 +261,7 @@ PipelineState *Device::createPipelineState(const PipelineStateInfo &info) {
}
Sampler *Device::getSampler(const SamplerInfo &info) {
uint32_t hash = gfx::Sampler::computeHash(info);
size_t hash = gfx::Sampler::computeHash(info);
if (!_samplers.count(hash)) {
_samplers[hash] = createSampler(info, hash);
}
@@ -269,7 +269,7 @@ Sampler *Device::getSampler(const SamplerInfo &info) {
}
GlobalBarrier *Device::getGlobalBarrier(const GlobalBarrierInfo &info) {
uint32_t hash = gfx::GlobalBarrier::computeHash(info);
size_t hash = gfx::GlobalBarrier::computeHash(info);
if (!_globalBarriers.count(hash)) {
_globalBarriers[hash] = createGlobalBarrier(info, hash);
}
@@ -277,7 +277,7 @@ GlobalBarrier *Device::getGlobalBarrier(const GlobalBarrierInfo &info) {
}
TextureBarrier *Device::getTextureBarrier(const TextureBarrierInfo &info) {
uint32_t hash = gfx::TextureBarrier::computeHash(info);
size_t hash = gfx::TextureBarrier::computeHash(info);
if (!_textureBarriers.count(hash)) {
_textureBarriers[hash] = createTextureBarrier(info, hash);
}
@@ -38,9 +38,8 @@ Framebuffer::Framebuffer()
Framebuffer::~Framebuffer() = default;
uint32_t Framebuffer::computeHash(const FramebufferInfo &info) {
std::hash<FramebufferInfo> hasher;
return utils::toUint(hasher(info));
size_t Framebuffer::computeHash(const FramebufferInfo &info) {
return Hasher<FramebufferInfo>()(info);
}
void Framebuffer::initialize(const FramebufferInfo &info) {
@@ -35,7 +35,7 @@ public:
Framebuffer();
~Framebuffer() override;
static uint32_t computeHash(const FramebufferInfo &info);
static size_t computeHash(const FramebufferInfo &info);
void initialize(const FramebufferInfo &info);
void destroy();
@@ -23,6 +23,8 @@
THE SOFTWARE.
****************************************************************************/
#include <boost/functional/hash.hpp>
#include "base/CoreStd.h"
#include "GFXBuffer.h"
@@ -38,19 +40,17 @@ InputAssembler::InputAssembler()
InputAssembler::~InputAssembler() = default;
uint32_t InputAssembler::computeAttributesHash() const {
// https://stackoverflow.com/questions/20511347/a-good-hash-function-for-a-vector
// 6: Attribute has 6 elements.
std::size_t seed = _attributes.size() * 6;
size_t InputAssembler::computeAttributesHash() const {
size_t seed = _attributes.size() * 6;
for (const auto &attribute : _attributes) {
seed ^= std::hash<std::string>{}(attribute.name) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(attribute.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= attribute.isNormalized + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= attribute.stream + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= attribute.isInstanced + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= attribute.location + 0x9e3779b9 + (seed << 6) + (seed >> 2);
boost::hash_combine(seed, attribute.name);
boost::hash_combine(seed, attribute.format);
boost::hash_combine(seed, attribute.isNormalized);
boost::hash_combine(seed, attribute.stream);
boost::hash_combine(seed, attribute.isInstanced);
boost::hash_combine(seed, attribute.location);
}
return static_cast<uint32_t>(seed);
return seed;
}
void InputAssembler::initialize(const InputAssemblerInfo &info) {
@@ -42,7 +42,7 @@ public:
inline const BufferList & getVertexBuffers() const { return _vertexBuffers; }
inline Buffer * getIndexBuffer() const { return _indexBuffer; }
inline Buffer * getIndirectBuffer() const { return _indirectBuffer; }
inline uint32_t getAttributesHash() const { return _attributesHash; }
inline size_t getAttributesHash() const { return _attributesHash; }
inline const DrawInfo &getDrawInfo() const { return _drawInfo; }
@@ -66,10 +66,10 @@ protected:
virtual void doInit(const InputAssemblerInfo &info) = 0;
virtual void doDestroy() = 0;
uint32_t computeAttributesHash() const;
size_t computeAttributesHash() const;
AttributeList _attributes;
uint32_t _attributesHash = 0;
size_t _attributesHash = 0;
BufferList _vertexBuffers;
Buffer * _indexBuffer{nullptr};
@@ -23,6 +23,8 @@
THE SOFTWARE.
****************************************************************************/
#include <boost/functional/hash.hpp>
#include "base/CoreStd.h"
#include "GFXObject.h"
@@ -40,84 +42,22 @@ RenderPass::RenderPass()
RenderPass::~RenderPass() = default;
// Based on render pass compatibility
uint32_t RenderPass::computeHash() {
// https://stackoverflow.com/questions/20511347/a-good-hash-function-for-a-vector
uint32_t seed = 0;
if (!_subpasses.empty()) {
for (const SubpassInfo &subPass : _subpasses) {
for (const uint32_t iaIndex : subPass.inputs) {
if (iaIndex >= _colorAttachments.size()) break;
seed += 2;
}
for (const uint32_t caIndex : subPass.colors) {
if (caIndex >= _colorAttachments.size()) break;
seed += 2;
}
for (const uint32_t raIndex : subPass.resolves) {
if (raIndex >= _colorAttachments.size()) break;
seed += 2;
}
for (const uint32_t paIndex : subPass.preserves) {
if (paIndex >= _colorAttachments.size()) break;
seed += 2;
}
if (subPass.depthStencil != INVALID_BINDING) {
seed += 2;
}
}
for (const SubpassInfo &subpass : _subpasses) {
for (const uint32_t iaIndex : subpass.inputs) {
if (iaIndex >= _colorAttachments.size()) break;
const ColorAttachment &ia = _colorAttachments[iaIndex];
seed ^= static_cast<uint32_t>(ia.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(ia.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
for (const uint32_t caIndex : subpass.colors) {
if (caIndex >= _colorAttachments.size()) break;
const ColorAttachment &ca = _colorAttachments[caIndex];
seed ^= static_cast<uint32_t>(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
for (const uint32_t raIndex : subpass.resolves) {
if (raIndex >= _colorAttachments.size()) break;
const ColorAttachment &ca = _colorAttachments[raIndex];
seed ^= static_cast<uint32_t>(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
for (const uint32_t paIndex : subpass.preserves) {
if (paIndex >= _colorAttachments.size()) break;
const ColorAttachment &ca = _colorAttachments[paIndex];
seed ^= static_cast<uint32_t>(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
if (subpass.depthStencil != INVALID_BINDING) {
if (subpass.depthStencil < _colorAttachments.size()) {
const auto &ds = _colorAttachments[subpass.depthStencil];
seed ^= static_cast<uint32_t>(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(ds.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
} else {
const auto &ds = _depthStencilAttachment;
seed ^= static_cast<uint32_t>(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(ds.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
}
}
} else {
seed = static_cast<uint32_t>(_colorAttachments.size() * 2 + 2);
for (const ColorAttachment &colorAttachment : _colorAttachments) {
seed ^= static_cast<uint32_t>(colorAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(colorAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
seed ^= static_cast<uint32_t>(_depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= static_cast<uint32_t>(_depthStencilAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
size_t RenderPass::computeHash() {
size_t seed = _colorAttachments.size() * 2 + 3;
for (const ColorAttachment &ca : _colorAttachments) {
boost::hash_combine(seed, ca.format);
boost::hash_combine(seed, ca.sampleCount);
}
const auto &ds = _depthStencilAttachment;
boost::hash_combine(seed, ds.format);
boost::hash_combine(seed, ds.sampleCount);
boost::hash_combine(seed, _subpasses);
return seed;
}
uint32_t RenderPass::computeHash(const RenderPassInfo &info) {
std::hash<RenderPassInfo> hasher;
return utils::toUint(hasher(info));
size_t RenderPass::computeHash(const RenderPassInfo &info) {
return Hasher<RenderPassInfo>()(info);
}
void RenderPass::initialize(const RenderPassInfo &info) {
@@ -35,7 +35,7 @@ public:
RenderPass();
~RenderPass() override;
static uint32_t computeHash(const RenderPassInfo &info);
static size_t computeHash(const RenderPassInfo &info);
void initialize(const RenderPassInfo &info);
void destroy();
@@ -44,10 +44,10 @@ public:
inline const DepthStencilAttachment &getDepthStencilAttachment() const { return _depthStencilAttachment; }
inline const SubpassInfoList & getSubpasses() const { return _subpasses; }
inline const SubpassDependencyList & getDependencies() const { return _dependencies; }
inline uint32_t getHash() const { return _hash; }
inline size_t getHash() const { return _hash; }
protected:
uint32_t computeHash();
size_t computeHash();
virtual void doInit(const RenderPassInfo &info) = 0;
virtual void doDestroy() = 0;
@@ -56,7 +56,7 @@ protected:
DepthStencilAttachment _depthStencilAttachment;
SubpassInfoList _subpasses;
SubpassDependencyList _dependencies;
uint32_t _hash = 0;
size_t _hash = 0;
};
} // namespace gfx
+9 -10
View File
@@ -28,6 +28,7 @@
#include "GFXSwapchain.h"
#include "GFXTexture.h"
#include <boost/functional/hash.hpp>
namespace cc {
namespace gfx {
@@ -38,19 +39,17 @@ Texture::Texture()
Texture::~Texture() = default;
uint32_t Texture::computeHash(const TextureInfo &info) {
std::hash<TextureInfo> hasher;
return utils::toUint(hasher(info));
size_t Texture::computeHash(const TextureInfo &info) {
return Hasher<TextureInfo>()(info);
}
uint32_t Texture::computeHash(const TextureViewInfo &info) {
std::hash<TextureViewInfo> hasher;
return utils::toUint(hasher(info));
size_t Texture::computeHash(const TextureViewInfo &info) {
return Hasher<TextureViewInfo>()(info);
}
uint32_t Texture::computeHash(const Texture *texture) {
uint32_t hash = texture->isTextureView() ? computeHash(texture->getViewInfo()) : computeHash(texture->getInfo());
if (texture->_swapchain) hash ^= (texture->_swapchain->getObjectID()) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
size_t Texture::computeHash(const Texture *texture) {
size_t hash = texture->isTextureView() ? computeHash(texture->getViewInfo()) : computeHash(texture->getInfo());
if (texture->_swapchain) boost::hash_combine(hash, texture->_swapchain->getObjectID());
return hash;
}
@@ -100,7 +99,7 @@ void Texture::destroy() {
_viewInfo = TextureViewInfo();
_isTextureView = false;
_size = _hash = 0;
_hash = _size = 0;
}
///////////////////////////// Swapchain Specific /////////////////////////////
+7 -7
View File
@@ -35,8 +35,8 @@ public:
Texture();
~Texture() override;
static uint32_t computeHash(const TextureInfo &info);
static uint32_t computeHash(const TextureViewInfo &info);
static size_t computeHash(const TextureInfo &info);
static size_t computeHash(const TextureViewInfo &info);
void initialize(const TextureInfo &info);
void initialize(const TextureViewInfo &info);
@@ -48,7 +48,7 @@ public:
inline bool isTextureView() const { return _isTextureView; }
inline uint32_t getSize() const { return _size; }
inline uint32_t getHash() const { return _hash; }
inline size_t getHash() const { return _hash; }
// convenient getter for common usages
inline Format getFormat() const { return _info.format; }
@@ -63,9 +63,9 @@ protected:
virtual void doDestroy() = 0;
virtual void doResize(uint32_t width, uint32_t height, uint32_t size) = 0;
static uint32_t computeHash(const Texture *texture);
static void initialize(const SwapchainTextureInfo &info, Texture *out);
virtual void doInit(const SwapchainTextureInfo &info) = 0;
static size_t computeHash(const Texture *texture);
static void initialize(const SwapchainTextureInfo &info, Texture *out);
virtual void doInit(const SwapchainTextureInfo &info) = 0;
TextureInfo _info;
TextureViewInfo _viewInfo;
@@ -73,7 +73,7 @@ protected:
Swapchain *_swapchain{nullptr};
bool _isTextureView{false};
uint32_t _size{0U};
uint32_t _hash{0U};
size_t _hash{0U};
};
} // namespace gfx
@@ -23,6 +23,8 @@
THE SOFTWARE.
****************************************************************************/
#include <boost/functional/hash.hpp>
#include "base/CoreStd.h"
#include "GFXGlobalBarrier.h"
@@ -31,22 +33,16 @@
namespace cc {
namespace gfx {
GlobalBarrier::GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash)
GlobalBarrier::GlobalBarrier(const GlobalBarrierInfo &info, size_t hash)
: GFXObject(ObjectType::GLOBAL_BARRIER) {
_info = info;
_hash = hash;
}
uint32_t GlobalBarrier::computeHash(const GlobalBarrierInfo &info) {
auto seed = utils::toUint(info.prevAccesses.size() + info.nextAccesses.size());
for (const AccessType type : info.prevAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
for (const AccessType type : info.nextAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
size_t GlobalBarrier::computeHash(const GlobalBarrierInfo &info) {
size_t seed = 2;
boost::hash_combine(seed, info.prevAccesses);
boost::hash_combine(seed, info.nextAccesses);
return seed;
}
@@ -32,16 +32,16 @@ namespace gfx {
class CC_DLL GlobalBarrier : public GFXObject {
public:
GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash);
GlobalBarrier(const GlobalBarrierInfo &info, size_t hash);
static uint32_t computeHash(const GlobalBarrierInfo &info);
static size_t computeHash(const GlobalBarrierInfo &info);
inline const GlobalBarrierInfo &getInfo() const { return _info; }
inline const uint32_t & getHash() const { return _hash; }
inline const size_t & getHash() const { return _hash; }
protected:
GlobalBarrierInfo _info;
uint32_t _hash{0U};
size_t _hash{0U};
};
} // namespace gfx
@@ -30,14 +30,14 @@
namespace cc {
namespace gfx {
Sampler::Sampler(const SamplerInfo &info, uint32_t hash)
Sampler::Sampler(const SamplerInfo &info, size_t hash)
: GFXObject(ObjectType::SAMPLER) {
_info = info;
_hash = hash;
}
uint32_t Sampler::computeHash(const SamplerInfo &info) {
uint32_t hash = toNumber(info.minFilter);
size_t Sampler::computeHash(const SamplerInfo &info) {
size_t hash = toNumber(info.minFilter);
hash |= (toNumber(info.magFilter) << 2);
hash |= (toNumber(info.mipFilter) << 4);
hash |= (toNumber(info.addressU) << 6);
@@ -33,16 +33,16 @@ namespace gfx {
class CC_DLL Sampler : public GFXObject {
public:
Sampler(const SamplerInfo &info, uint32_t hash);
Sampler(const SamplerInfo &info, size_t hash);
static uint32_t computeHash(const SamplerInfo &info);
static size_t computeHash(const SamplerInfo &info);
inline const SamplerInfo &getInfo() const { return _info; }
inline const uint32_t & getHash() const { return _hash; }
inline const size_t & getHash() const { return _hash; }
protected:
SamplerInfo _info;
uint32_t _hash{0U};
size_t _hash{0U};
};
} // namespace gfx
@@ -23,6 +23,8 @@
THE SOFTWARE.
****************************************************************************/
#include <boost/functional/hash.hpp>
#include "base/CoreStd.h"
#include "../GFXQueue.h"
@@ -32,26 +34,19 @@
namespace cc {
namespace gfx {
TextureBarrier::TextureBarrier(const TextureBarrierInfo &info, uint32_t hash)
TextureBarrier::TextureBarrier(const TextureBarrierInfo &info, size_t hash)
: GFXObject(ObjectType::TEXTURE_BARRIER) {
_info = info;
_hash = hash;
}
uint32_t TextureBarrier::computeHash(const TextureBarrierInfo &info) {
auto seed = utils::toUint(info.prevAccesses.size() + info.nextAccesses.size() + 3);
for (const AccessType type : info.prevAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
for (const AccessType type : info.nextAccesses) {
seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
seed ^= info.discardContents + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= (info.srcQueue ? toNumber(info.srcQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= (info.dstQueue ? toNumber(info.dstQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
size_t TextureBarrier::computeHash(const TextureBarrierInfo &info) {
size_t seed = 5;
boost::hash_combine(seed, info.prevAccesses);
boost::hash_combine(seed, info.nextAccesses);
boost::hash_combine(seed, info.discardContents);
boost::hash_combine(seed, info.srcQueue);
boost::hash_combine(seed, info.dstQueue);
return seed;
}
@@ -32,16 +32,16 @@ namespace gfx {
class CC_DLL TextureBarrier : public GFXObject {
public:
TextureBarrier(const TextureBarrierInfo &info, uint32_t hash);
TextureBarrier(const TextureBarrierInfo &info, size_t hash);
static uint32_t computeHash(const TextureBarrierInfo &info);
static size_t computeHash(const TextureBarrierInfo &info);
inline const TextureBarrierInfo &getInfo() const { return _info; }
inline const uint32_t & getHash() const { return _hash; }
inline const size_t & getHash() const { return _hash; }
protected:
TextureBarrierInfo _info;
uint32_t _hash{0U};
size_t _hash{0U};
};
} // namespace gfx
@@ -136,15 +136,15 @@ PipelineState *EmptyDevice::createPipelineState() {
return CC_NEW(EmptyPipelineState());
}
Sampler *EmptyDevice::createSampler(const SamplerInfo &info, uint32_t hash) {
Sampler *EmptyDevice::createSampler(const SamplerInfo &info, size_t hash) {
return CC_NEW(Sampler(info, hash));
}
GlobalBarrier *EmptyDevice::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) {
GlobalBarrier *EmptyDevice::createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) {
return CC_NEW(GlobalBarrier(info, hash));
}
TextureBarrier *EmptyDevice::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) {
TextureBarrier *EmptyDevice::createTextureBarrier(const TextureBarrierInfo &info, size_t hash) {
return CC_NEW(TextureBarrier(info, hash));
}
@@ -72,9 +72,9 @@ public:
PipelineLayout * createPipelineLayout() override;
PipelineState * createPipelineState() override;
Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override;
Sampler * createSampler(const SamplerInfo &info, size_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, size_t hash) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override;
@@ -1194,7 +1194,7 @@ void cmdFuncGLES2CreateRenderPass(GLES2Device * /*device*/, GLES2GPURenderPass *
statistics.storeSubpass = index;
};
auto calculateLifeCycle = [&](GLES2GPURenderPass::AttachmentStatistics &statistics, uint32_t targetAttachment) {
for (size_t j = 0U; j < gpuRenderPass->subpasses.size(); ++j) {
for (uint32_t j = 0U; j < utils::toUint(gpuRenderPass->subpasses.size()); ++j) {
auto &subpass = gpuRenderPass->subpasses[j];
for (size_t k = 0U; k < subpass.colors.size(); ++k) {
if (subpass.colors[k] == targetAttachment) {
@@ -1220,7 +1220,7 @@ void cmdFuncGLES2CreateRenderPass(GLES2Device * /*device*/, GLES2GPURenderPass *
bool hasDepth = gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN;
gpuRenderPass->statistics.resize(gpuRenderPass->colorAttachments.size() + hasDepth);
for (size_t i = 0U; i < gpuRenderPass->statistics.size(); ++i) {
for (uint32_t i = 0U; i < utils::toUint(gpuRenderPass->statistics.size()); ++i) {
calculateLifeCycle(gpuRenderPass->statistics[i], i);
CC_ASSERT(gpuRenderPass->statistics[i].loadSubpass != SUBPASS_EXTERNAL &&
gpuRenderPass->statistics[i].storeSubpass != SUBPASS_EXTERNAL);
@@ -1440,7 +1440,7 @@ void cmdFuncGLES2CreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpu
gpuFBO->uberColorAttachmentIndices.clear();
bool hasDepth{gpuFBO->gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN};
gpuFBO->uberDepthStencil = hasDepth ? gpuFBO->gpuColorTextures.size() : INVALID_BINDING;
gpuFBO->uberDepthStencil = hasDepth ? utils::toUint(gpuFBO->gpuColorTextures.size()) : INVALID_BINDING;
for (uint32_t i = 0U; i < gpuFBO->gpuColorTextures.size(); ++i) {
if (i == gpuFBO->uberFinalOutput) continue;
const auto *gpuTexture = gpuFBO->gpuColorTextures[i];
@@ -327,15 +327,15 @@ PipelineState *GLES2Device::createPipelineState() {
return CC_NEW(GLES2PipelineState);
}
Sampler *GLES2Device::createSampler(const SamplerInfo &info, uint32_t hash) {
Sampler *GLES2Device::createSampler(const SamplerInfo &info, size_t hash) {
return CC_NEW(GLES2Sampler(info, hash));
}
GlobalBarrier *GLES2Device::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) {
GlobalBarrier *GLES2Device::createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) {
return CC_NEW(GlobalBarrier(info, hash));
}
TextureBarrier *GLES2Device::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) {
TextureBarrier *GLES2Device::createTextureBarrier(const TextureBarrierInfo &info, size_t hash) {
return CC_NEW(TextureBarrier(info, hash));
}
@@ -100,9 +100,9 @@ protected:
PipelineLayout * createPipelineLayout() override;
PipelineState * createPipelineState() override;
Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override;
Sampler * createSampler(const SamplerInfo &info, size_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, size_t hash) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override;
@@ -30,7 +30,7 @@
namespace cc {
namespace gfx {
GLES2Sampler::GLES2Sampler(const SamplerInfo &info, uint32_t hash) : Sampler(info, hash) {
GLES2Sampler::GLES2Sampler(const SamplerInfo &info, size_t hash) : Sampler(info, hash) {
_typedID = generateObjectID<decltype(this)>();
_gpuSampler = CC_NEW(GLES2GPUSampler);
@@ -36,7 +36,7 @@ class GLES2GPUSampler;
class CC_GLES2_API GLES2Sampler final : public Sampler {
public:
GLES2Sampler(const SamplerInfo &info, uint32_t hash);
GLES2Sampler(const SamplerInfo &info, size_t hash);
~GLES2Sampler() override;
inline GLES2GPUSampler *gpuSampler() const { return _gpuSampler; }
@@ -320,15 +320,15 @@ PipelineState *GLES3Device::createPipelineState() {
return CC_NEW(GLES3PipelineState);
}
Sampler *GLES3Device::createSampler(const SamplerInfo &info, uint32_t hash) {
Sampler *GLES3Device::createSampler(const SamplerInfo &info, size_t hash) {
return CC_NEW(GLES3Sampler(info, hash));
}
GlobalBarrier *GLES3Device::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) {
GlobalBarrier *GLES3Device::createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) {
return CC_NEW(GLES3GlobalBarrier(info, hash));
}
TextureBarrier *GLES3Device::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) {
TextureBarrier *GLES3Device::createTextureBarrier(const TextureBarrierInfo &info, size_t hash) {
return CC_NEW(TextureBarrier(info, hash));
}
@@ -98,9 +98,9 @@ protected:
PipelineLayout * createPipelineLayout() override;
PipelineState * createPipelineState() override;
Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override;
Sampler * createSampler(const SamplerInfo &info, size_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, size_t hash) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override;
@@ -29,7 +29,7 @@
namespace cc {
namespace gfx {
GLES3GlobalBarrier::GLES3GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) : GlobalBarrier(info, hash) {
GLES3GlobalBarrier::GLES3GlobalBarrier(const GlobalBarrierInfo &info, size_t hash) : GlobalBarrier(info, hash) {
_typedID = generateObjectID<decltype(this)>();
_gpuBarrier = CC_NEW(GLES3GPUGlobalBarrier);
@@ -35,7 +35,7 @@ class GLES3GPUGlobalBarrier;
class CC_GLES3_API GLES3GlobalBarrier : public GlobalBarrier {
public:
explicit GLES3GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash);
explicit GLES3GlobalBarrier(const GlobalBarrierInfo &info, size_t hash);
~GLES3GlobalBarrier() override;
inline const GLES3GPUGlobalBarrier *gpuBarrier() const { return _gpuBarrier; }
@@ -30,7 +30,7 @@
namespace cc {
namespace gfx {
GLES3Sampler::GLES3Sampler(const SamplerInfo &info, uint32_t hash) : Sampler(info, hash) {
GLES3Sampler::GLES3Sampler(const SamplerInfo &info, size_t hash) : Sampler(info, hash) {
_typedID = generateObjectID<decltype(this)>();
_gpuSampler = CC_NEW(GLES3GPUSampler);
@@ -35,7 +35,7 @@ class GLES3GPUSampler;
class CC_GLES3_API GLES3Sampler final : public Sampler {
public:
explicit GLES3Sampler(const SamplerInfo &info, uint32_t hash);
explicit GLES3Sampler(const SamplerInfo &info, size_t hash);
~GLES3Sampler() override;
inline GLES3GPUSampler *gpuSampler() const { return _gpuSampler; }
+3 -3
View File
@@ -106,9 +106,9 @@ protected:
DescriptorSetLayout *createDescriptorSetLayout() override;
PipelineLayout *createPipelineLayout() override;
PipelineState *createPipelineState() override;
GlobalBarrier *createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo& info, uint32_t hash) override;
Sampler *createSampler(const SamplerInfo& info, uint32_t hash) override;
GlobalBarrier *createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo& info, size_t hash) override;
Sampler *createSampler(const SamplerInfo& info, size_t hash) override;
Swapchain *createSwapchain() override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override;
+5 -5
View File
@@ -213,7 +213,7 @@ void CCMTLDevice::present() {
//hold this pointer before update _currentFrameIndex
_currentBufferPoolId = _currentFrameIndex;
_currentFrameIndex = (_currentFrameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
std::vector<id<CAMetalDrawable>> releaseQ;
for (auto* swapchain: _swapchains) {
auto drawable = swapchain->currentDrawable();
@@ -233,7 +233,7 @@ void CCMTLDevice::present() {
[cmdBuffer presentDrawable:drawable];
[drawable release];
}
[cmdBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) {
onPresentCompleted();
}];
@@ -307,15 +307,15 @@ PipelineState *CCMTLDevice::createPipelineState() {
return CC_NEW(CCMTLPipelineState);
}
GlobalBarrier *CCMTLDevice::createGlobalBarrier(const GlobalBarrierInfo& info, uint32_t hash) {
GlobalBarrier *CCMTLDevice::createGlobalBarrier(const GlobalBarrierInfo& info, size_t hash) {
return new GlobalBarrier(info, hash);
}
TextureBarrier *CCMTLDevice::createTextureBarrier(const TextureBarrierInfo& info, uint32_t hash) {
TextureBarrier *CCMTLDevice::createTextureBarrier(const TextureBarrierInfo& info, size_t hash) {
return new TextureBarrier(info, hash);
}
Sampler *CCMTLDevice::createSampler(const SamplerInfo &info, uint32_t hash) {
Sampler *CCMTLDevice::createSampler(const SamplerInfo &info, size_t hash) {
return new CCMTLSampler(info, hash);
}
+1 -1
View File
@@ -34,7 +34,7 @@ namespace gfx {
class CCMTLSampler final : public Sampler {
public:
explicit CCMTLSampler(const SamplerInfo& info, uint32_t hash);
explicit CCMTLSampler(const SamplerInfo& info, size_t hash);
~CCMTLSampler();
CCMTLSampler() = delete;
CCMTLSampler(const CCMTLSampler &)=delete;
@@ -34,7 +34,7 @@
namespace cc {
namespace gfx {
CCMTLSampler::CCMTLSampler(const SamplerInfo& info, uint32_t hash) : Sampler(info, hash) {
CCMTLSampler::CCMTLSampler(const SamplerInfo& info, size_t hash) : Sampler(info, hash) {
_typedID = generateObjectID<decltype(this)>();
MTLSamplerDescriptor *descriptor = [[MTLSamplerDescriptor alloc] init];
#if (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
+9 -9
View File
@@ -40,8 +40,8 @@ namespace cc {
namespace gfx {
namespace {
std::unordered_map<uint, PipelineState*> pipelineMap;
std::unordered_map<uint, RenderPass*> renderPassMap;
std::unordered_map<size_t, PipelineState*> pipelineMap;
std::unordered_map<size_t, RenderPass*> renderPassMap;
EShLanguage getShaderStage(ShaderStageFlagBit type) {
switch (type) {
@@ -357,13 +357,13 @@ gfx::Shader *createShader(CCMTLDevice *device) {
}
CCMTLGPUPipelineState *getClearRenderPassPipelineState(CCMTLDevice *device, RenderPass * curPass) {
uint rpHash = curPass->getHash();
size_t rpHash = curPass->getHash();
const auto iter = pipelineMap.find(rpHash);
if(iter != pipelineMap.end()) {
auto *ccMtlPiplineState = static_cast<CCMTLPipelineState *>(iter->second);
return ccMtlPiplineState->getGPUPipelineState();
}
RenderPass* renderPass = nullptr;
const auto rpIter = renderPassMap.find(rpHash);
if(rpIter != renderPassMap.end()) {
@@ -379,7 +379,7 @@ CCMTLGPUPipelineState *getClearRenderPassPipelineState(CCMTLDevice *device, Rend
uint32_t color = subpasses[curSubpassIndex].colors[i];
colorAttachments.push_back(originAttachments[color]);
}
uint32_t depthStencil = subpasses[curSubpassIndex].depthStencil;
if(depthStencil >= subpasses[curSubpassIndex].colors.size()) {
depthStencilAttachment = curPass->getDepthStencilAttachment();
@@ -407,7 +407,7 @@ CCMTLGPUPipelineState *getClearRenderPassPipelineState(CCMTLDevice *device, Rend
});
}
}
gfx::Attribute position = {"a_position", gfx::Format::RG32F, false, 0, false};
gfx::PipelineStateInfo pipelineInfo;
pipelineInfo.primitive = gfx::PrimitiveMode::TRIANGLE_LIST;
@@ -944,7 +944,7 @@ String mu::spirv2MSL(const uint32_t *ir, size_t word_count,
auto active = msl.get_active_interface_variables();
spirv_cross::ShaderResources resources = msl.get_shader_resources(active);
msl.set_enabled_interface_variables(std::move(active));
// Set some options.
spirv_cross::CompilerMSL::Options options;
options.enable_decoration_binding = true;
@@ -1049,7 +1049,7 @@ String mu::spirv2MSL(const uint32_t *ir, size_t word_count,
samplerIndex++;
}
}
if(executionModel == spv::ExecutionModelFragment) {
gpuShader->outputs.resize(resources.stage_outputs.size());
for(size_t i = 0; i < resources.stage_outputs.size(); i++) {
@@ -1061,7 +1061,7 @@ String mu::spirv2MSL(const uint32_t *ir, size_t word_count,
gpuShader->outputs[i].set = set;
gpuShader->outputs[i].binding = attachmentIndex;
}
if(!resources.subpass_inputs.empty()) {
gpuShader->inputs.resize(resources.subpass_inputs.size());
for(size_t i = 0; i < resources.subpass_inputs.size(); i++) {
@@ -225,15 +225,15 @@ PipelineState *DeviceValidator::createPipelineState() {
return result;
}
Sampler *DeviceValidator::createSampler(const SamplerInfo &info, uint32_t hash) {
Sampler *DeviceValidator::createSampler(const SamplerInfo &info, size_t hash) {
return _actor->createSampler(info, hash);
}
GlobalBarrier *DeviceValidator::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) {
GlobalBarrier *DeviceValidator::createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) {
return _actor->createGlobalBarrier(info, hash);
}
TextureBarrier *DeviceValidator::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) {
TextureBarrier *DeviceValidator::createTextureBarrier(const TextureBarrierInfo &info, size_t hash) {
return _actor->createTextureBarrier(info, hash);
}
@@ -71,9 +71,9 @@ public:
PipelineLayout * createPipelineLayout() override;
PipelineState * createPipelineState() override;
Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override;
Sampler * createSampler(const SamplerInfo &info, size_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, size_t hash) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override;
+10 -13
View File
@@ -23,6 +23,8 @@
THE SOFTWARE.
****************************************************************************/
#include <boost/functional/hash.hpp>
#include "VKStd.h"
#include "VKCommands.h"
@@ -307,21 +309,16 @@ struct SubpassDependencyManager final {
}
void append(const VkSubpassDependency2 &dependency) {
uint32_t hash = 6U;
hash ^= (dependency.srcSubpass) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= (dependency.srcStageMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= (dependency.srcAccessMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= (dependency.dstSubpass) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= (dependency.dstStageMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= (dependency.dstAccessMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
// only cares about src/dst attributes
size_t hash = boost::hash_range(reinterpret_cast<const uint64_t *>(&dependency.srcSubpass),
reinterpret_cast<const uint64_t *>(&dependency.dependencyFlags));
if (_hashes.count(hash)) return;
subpassDependencies.push_back(dependency);
_hashes.insert(hash);
}
private:
unordered_set<uint32_t> _hashes;
unordered_set<size_t> _hashes;
};
void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) {
@@ -603,7 +600,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
statistics.storeSubpass = index;
};
auto calculateLifeCycle = [&](uint32_t targetAttachment, AttachmentStatistics &statistics) {
for (size_t j = 0U; j < subpassCount; ++j) {
for (uint32_t j = 0U; j < utils::toUint(subpassCount); ++j) {
auto &subpass = subpassDescriptions[j];
for (size_t k = 0U; k < subpass.colorAttachmentCount; ++k) {
if (subpass.pColorAttachments[k].attachment == targetAttachment) {
@@ -628,7 +625,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
}
};
attachmentStatistics.resize(colorAttachmentCount + hasDepth);
for (size_t i = 0U; i < colorAttachmentCount + hasDepth; ++i) {
for (uint32_t i = 0U; i < utils ::toUint(colorAttachmentCount + hasDepth); ++i) {
attachmentStatistics[i].clear();
calculateLifeCycle(i, attachmentStatistics[i]);
CC_ASSERT(attachmentStatistics[i].loadSubpass != VK_SUBPASS_EXTERNAL &&
@@ -654,7 +651,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
VkSubpassDependency2 beginDependency;
uint32_t lastLoadSubpass{VK_SUBPASS_EXTERNAL};
bool beginDependencyValid{false};
for (size_t i = 0U; i < colorAttachmentCount + hasDepth; ++i) {
for (uint32_t i = 0U; i < utils ::toUint(colorAttachmentCount + hasDepth); ++i) {
auto &statistics = attachmentStatistics[i];
if (lastLoadSubpass != statistics.loadSubpass) {
if (beginDependencyValid) dependencyManager.append(beginDependency);
@@ -686,7 +683,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
VkSubpassDependency2 endDependency;
uint32_t lastStoreSubpass{VK_SUBPASS_EXTERNAL};
bool endDependencyValid{false};
for (size_t i = 0U; i < colorAttachmentCount + hasDepth; ++i) {
for (uint32_t i = 0U; i < utils ::toUint(colorAttachmentCount + hasDepth); ++i) {
auto &statistics = attachmentStatistics[i];
if (lastStoreSubpass != statistics.storeSubpass) {
if (endDependencyValid) dependencyManager.append(endDependency);
@@ -726,15 +726,15 @@ PipelineState *CCVKDevice::createPipelineState() {
return CC_NEW(CCVKPipelineState);
}
Sampler *CCVKDevice::createSampler(const SamplerInfo &info, uint32_t hash) {
Sampler *CCVKDevice::createSampler(const SamplerInfo &info, size_t hash) {
return CC_NEW(CCVKSampler(info, hash));
}
GlobalBarrier *CCVKDevice::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) {
GlobalBarrier *CCVKDevice::createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) {
return CC_NEW(CCVKGlobalBarrier(info, hash));
}
TextureBarrier *CCVKDevice::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) {
TextureBarrier *CCVKDevice::createTextureBarrier(const TextureBarrierInfo &info, size_t hash) {
return CC_NEW(CCVKTextureBarrier(info, hash));
}
+3 -3
View File
@@ -118,9 +118,9 @@ protected:
PipelineLayout * createPipelineLayout() override;
PipelineState * createPipelineState() override;
Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override;
Sampler * createSampler(const SamplerInfo &info, size_t hash) override;
GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) override;
TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, size_t hash) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override;
@@ -29,7 +29,7 @@
namespace cc {
namespace gfx {
CCVKGlobalBarrier::CCVKGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) : GlobalBarrier(info, hash) {
CCVKGlobalBarrier::CCVKGlobalBarrier(const GlobalBarrierInfo &info, size_t hash) : GlobalBarrier(info, hash) {
_typedID = generateObjectID<decltype(this)>();
_gpuBarrier = CC_NEW(CCVKGPUGlobalBarrier);
@@ -35,7 +35,7 @@ class CCVKGPUGlobalBarrier;
class CC_VULKAN_API CCVKGlobalBarrier : public GlobalBarrier {
public:
explicit CCVKGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash);
explicit CCVKGlobalBarrier(const GlobalBarrierInfo &info, size_t hash);
~CCVKGlobalBarrier() override;
inline const CCVKGPUGlobalBarrier *gpuBarrier() const { return _gpuBarrier; }
@@ -30,7 +30,7 @@
namespace cc {
namespace gfx {
CCVKSampler::CCVKSampler(const SamplerInfo &info, uint32_t hash) : Sampler(info, hash) {
CCVKSampler::CCVKSampler(const SamplerInfo &info, size_t hash) : Sampler(info, hash) {
_typedID = generateObjectID<decltype(this)>();
_gpuSampler = CC_NEW(CCVKGPUSampler);
@@ -35,7 +35,7 @@ class CCVKGPUSampler;
class CC_VULKAN_API CCVKSampler final : public Sampler {
public:
explicit CCVKSampler(const SamplerInfo &info, uint32_t hash);
explicit CCVKSampler(const SamplerInfo &info, size_t hash);
~CCVKSampler() override;
inline CCVKGPUSampler *gpuSampler() const { return _gpuSampler; }
@@ -30,7 +30,7 @@
namespace cc {
namespace gfx {
CCVKTextureBarrier::CCVKTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) : TextureBarrier(info, hash) {
CCVKTextureBarrier::CCVKTextureBarrier(const TextureBarrierInfo &info, size_t hash) : TextureBarrier(info, hash) {
_typedID = generateObjectID<decltype(this)>();
_gpuBarrier = CC_NEW(CCVKGPUTextureBarrier);
@@ -35,7 +35,7 @@ class CCVKGPUTextureBarrier;
class CC_VULKAN_API CCVKTextureBarrier : public TextureBarrier {
public:
explicit CCVKTextureBarrier(const TextureBarrierInfo &info, uint32_t hash);
explicit CCVKTextureBarrier(const TextureBarrierInfo &info, size_t hash);
~CCVKTextureBarrier() override;
inline const CCVKGPUTextureBarrier *gpuBarrier() const { return _gpuBarrier; }
@@ -670,7 +670,7 @@ void ClusterLightCulling::clusterLightCulling(scene::Camera* camera) {
bufferInfo.size = clusterBufferSize;
bufferInfo.stride = clusterBufferSize;
bufferInfo.flags = gfx::BufferFlagBit::NONE;
data.clusterBuffer = builder.create<framegraph::Buffer>(fgStrHandleClusterBuffer, bufferInfo);
data.clusterBuffer = builder.create(fgStrHandleClusterBuffer, bufferInfo);
builder.writeToBlackboard(fgStrHandleClusterBuffer, data.clusterBuffer);
}
// only rebuild cluster necceray
@@ -689,7 +689,7 @@ void ClusterLightCulling::clusterLightCulling(scene::Camera* camera) {
bufferInfo.size = atomicIndexBufferSize;
bufferInfo.stride = atomicIndexBufferSize;
bufferInfo.flags = gfx::BufferFlagBit::NONE;
data.globalIndexBuffer = builder.create<framegraph::Buffer>(fgStrHandleClusterGlobalIndexBuffer, bufferInfo);
data.globalIndexBuffer = builder.create(fgStrHandleClusterGlobalIndexBuffer, bufferInfo);
builder.writeToBlackboard(fgStrHandleClusterGlobalIndexBuffer, data.globalIndexBuffer);
}
// atomic counter for building the light grid
@@ -735,7 +735,7 @@ void ClusterLightCulling::clusterLightCulling(scene::Camera* camera) {
bufferInfo.size = _lightBufferStride * _lightBufferCount;
bufferInfo.stride = _lightBufferStride;
bufferInfo.flags = gfx::BufferFlagBit::NONE;
data.lightBuffer = builder.create<framegraph::Buffer>(fgStrHandleClusterLightBuffer, bufferInfo);
data.lightBuffer = builder.create(fgStrHandleClusterLightBuffer, bufferInfo);
builder.writeToBlackboard(fgStrHandleClusterLightBuffer, data.lightBuffer);
_lightBufferResized = false;
}
@@ -753,7 +753,7 @@ void ClusterLightCulling::clusterLightCulling(scene::Camera* camera) {
bufferInfo.size = lightIndicesBufferSize;
bufferInfo.stride = lightIndicesBufferSize;
bufferInfo.flags = gfx::BufferFlagBit::NONE;
data.lightIndexBuffer = builder.create<framegraph::Buffer>(fgStrHandleClusterLightIndexBuffer, bufferInfo);
data.lightIndexBuffer = builder.create(fgStrHandleClusterLightIndexBuffer, bufferInfo);
builder.writeToBlackboard(fgStrHandleClusterLightIndexBuffer, data.lightIndexBuffer);
}
data.lightIndexBuffer = builder.write(data.lightIndexBuffer);
@@ -770,7 +770,7 @@ void ClusterLightCulling::clusterLightCulling(scene::Camera* camera) {
bufferInfo.size = lightGridBufferSize;
bufferInfo.stride = lightGridBufferSize;
bufferInfo.flags = gfx::BufferFlagBit::NONE;
data.lightGridBuffer = builder.create<framegraph::Buffer>(fgStrHandleClusterLightGridBuffer, bufferInfo);
data.lightGridBuffer = builder.create(fgStrHandleClusterLightGridBuffer, bufferInfo);
builder.writeToBlackboard(fgStrHandleClusterLightGridBuffer, data.lightGridBuffer);
}
data.lightGridBuffer = builder.write(data.lightGridBuffer);
@@ -30,7 +30,7 @@
namespace cc {
namespace pipeline {
unordered_map<uint, gfx::PipelineState *> PipelineStateManager::psoHashMap;
unordered_map<size_t, gfx::PipelineState *> PipelineStateManager::psoHashMap;
gfx::PipelineState *PipelineStateManager::getOrCreatePipelineState(const scene::Pass * pass,
gfx::Shader * shader,
@@ -41,7 +41,7 @@ public:
static void destroyAll();
private:
static unordered_map<uint, gfx::PipelineState *> psoHashMap;
static unordered_map<size_t, gfx::PipelineState *> psoHashMap;
};
} // namespace pipeline
@@ -23,10 +23,12 @@
THE SOFTWARE.
****************************************************************************/
#include "RenderPipeline.h"
#include <boost/functional/hash.hpp>
#include "InstancedBuffer.h"
#include "PipelineStateManager.h"
#include "RenderFlow.h"
#include "RenderPipeline.h"
#include "gfx-base/GFXCommandBuffer.h"
#include "gfx-base/GFXDescriptorSet.h"
#include "gfx-base/GFXDescriptorSetLayout.h"
@@ -161,7 +163,7 @@ gfx::Color RenderPipeline::getClearcolor(scene::Camera *camera) const {
}
void RenderPipeline::updateQuadVertexData(const Vec4 &viewport, gfx::Buffer *buffer) {
float vbData[16] = {0};
float vbData[16] = {0};
genQuadVertexData(viewport, vbData);
buffer->update(vbData, sizeof(vbData));
}
@@ -170,17 +172,14 @@ gfx::InputAssembler *RenderPipeline::getIAByRenderArea(const gfx::Rect &renderAr
auto bufferWidth{static_cast<float>(_width)};
auto bufferHeight{static_cast<float>(_height)};
Vec4 viewport{
static_cast<float>(renderArea.x) / bufferWidth,
static_cast<float>(renderArea.y) / bufferHeight,
static_cast<float>(renderArea.width) / bufferWidth,
static_cast<float>(renderArea.height) / bufferHeight,
static_cast<float>(renderArea.x) / bufferWidth,
static_cast<float>(renderArea.y) / bufferHeight,
static_cast<float>(renderArea.width) / bufferWidth,
static_cast<float>(renderArea.height) / bufferHeight,
};
uint32_t hash = 4;
hash ^= *reinterpret_cast<uint32_t*>(&viewport.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= *reinterpret_cast<uint32_t*>(&viewport.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= *reinterpret_cast<uint32_t*>(&viewport.z) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
hash ^= *reinterpret_cast<uint32_t*>(&viewport.w) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
size_t hash = boost::hash_range(reinterpret_cast<const uint64_t *>(&viewport.x),
reinterpret_cast<const uint64_t *>(&viewport.x + 4));
const auto iter = _quadIA.find(hash);
if (iter != _quadIA.end()) {
@@ -126,14 +126,14 @@ protected:
scene::Model * _profiler{nullptr};
// has not initBuiltinRes,
// create temporary default Texture to binding sampler2d
gfx::Texture * _defaultTexture{nullptr};
uint _width{0};
uint _height{0};
gfx::Buffer * _quadIB{nullptr};
std::vector<gfx::Buffer *> _quadVB;
std::unordered_map<uint, gfx::InputAssembler *> _quadIA;
gfx::Texture * _defaultTexture{nullptr};
uint _width{0};
uint _height{0};
gfx::Buffer * _quadIB{nullptr};
std::vector<gfx::Buffer *> _quadVB;
std::unordered_map<size_t, gfx::InputAssembler *> _quadIA;
framegraph::FrameGraph _fg;
framegraph::FrameGraph _fg;
unordered_map<gfx::ClearFlags, gfx::RenderPass *> _renderPasses;
// use cluster culling or not
@@ -177,7 +177,7 @@ void BloomStage::render(scene::Camera *camera) {
colorTexInfo.width = static_cast<uint>(pipeline->getWidth() * shadingScale);
colorTexInfo.height = static_cast<uint>(pipeline->getHeight() * shadingScale);
data.inputTexHandle = builder.create<framegraph::Texture>(
data.inputTexHandle = builder.create(
RenderPipeline::fgStrHandleOutColorTexture, colorTexInfo);
}
@@ -193,7 +193,7 @@ void BloomStage::render(scene::Camera *camera) {
colorTexInfo.width = static_cast<uint>(renderArea.width * shadingScale);
colorTexInfo.height = static_cast<uint>(renderArea.height * shadingScale);
data.outputTexHandle = builder.create<framegraph::Texture>(prefilterTexHandle, colorTexInfo);
data.outputTexHandle = builder.create(prefilterTexHandle, colorTexInfo);
}
data.outputTexHandle = builder.write(data.outputTexHandle, colorAttachmentInfo);
builder.writeToBlackboard(prefilterTexHandle, data.outputTexHandle);
@@ -268,7 +268,7 @@ void BloomStage::render(scene::Camera *camera) {
colorTexInfo.width = static_cast<uint>(renderArea.width * shadingScale);
colorTexInfo.height = static_cast<uint>(renderArea.height * shadingScale);
data.outputTexHandle = builder.create<framegraph::Texture>(downsampleTexHandles[data.index], colorTexInfo);
data.outputTexHandle = builder.create(downsampleTexHandles[data.index], colorTexInfo);
}
data.outputTexHandle = builder.write(data.outputTexHandle, colorAttachmentInfo);
builder.writeToBlackboard(downsampleTexHandles[data.index], data.outputTexHandle);
@@ -345,7 +345,7 @@ void BloomStage::render(scene::Camera *camera) {
colorTexInfo.width = static_cast<uint>(renderArea.width * shadingScale);
colorTexInfo.height = static_cast<uint>(renderArea.height * shadingScale);
data.outputTexHandle = builder.create<framegraph::Texture>(
data.outputTexHandle = builder.create(
upsampleTexHandles[data.index], colorTexInfo);
}
data.outputTexHandle = builder.write(data.outputTexHandle, colorAttachmentInfo);
@@ -427,7 +427,7 @@ void BloomStage::render(scene::Camera *camera) {
colorTexInfo.width = static_cast<uint>(renderArea.width * shadingScale);
colorTexInfo.height = static_cast<uint>(renderArea.height * shadingScale);
data.bloomOutTexHandle = builder.create<framegraph::Texture>(
data.bloomOutTexHandle = builder.create(
RenderPipeline::fgStrHandleBloomOutTexture, colorTexInfo);
}
data.bloomOutTexHandle = builder.write(data.bloomOutTexHandle, colorAttachmentInfo);
@@ -126,7 +126,7 @@ void PostProcessStage::render(scene::Camera *camera) {
colorTexInfo.width = static_cast<uint>(pipeline->getWidth() * shadingScale);
colorTexInfo.height = static_cast<uint>(pipeline->getHeight() * shadingScale);
data.outColorTex = builder.create<framegraph::Texture>(RenderPipeline::fgStrHandleOutColorTexture, colorTexInfo);
data.outColorTex = builder.create(RenderPipeline::fgStrHandleOutColorTexture, colorTexInfo);
}
data.outColorTex = builder.read(data.outColorTex);
@@ -156,7 +156,7 @@ void PostProcessStage::render(scene::Camera *camera) {
static_cast<uint>(camera->window->getWidth() * shadingScale),
static_cast<uint>(camera->window->getHeight() * shadingScale),
};
data.backBuffer = builder.create<framegraph::Texture>(fgStrHandlePostProcessOutTexture, textureInfo);
data.backBuffer = builder.create(fgStrHandlePostProcessOutTexture, textureInfo);
data.backBuffer = builder.write(data.backBuffer, colorAttachmentInfo);
builder.writeToBlackboard(fgStrHandlePostProcessOutTexture, data.backBuffer);
@@ -174,18 +174,18 @@ void GbufferStage::render(scene::Camera *camera) {
};
for (int i = 0; i < DeferredPipeline::GBUFFER_COUNT - 1; ++i) {
if (i != 0) { // positions & normals need more precision
data.gbuffer[i] = builder.create<framegraph::Texture>(DeferredPipeline::fgStrHandleGbufferTexture[i], gbufferInfoFloat);
data.gbuffer[i] = builder.create(DeferredPipeline::fgStrHandleGbufferTexture[i], gbufferInfoFloat);
} else {
data.gbuffer[i] = builder.create<framegraph::Texture>(DeferredPipeline::fgStrHandleGbufferTexture[i], gbufferInfo);
data.gbuffer[i] = builder.create(DeferredPipeline::fgStrHandleGbufferTexture[i], gbufferInfo);
}
}
auto subpassEnabled = _device->hasFeature(gfx::Feature::INPUT_ATTACHMENT_BENEFIT);
if (subpassEnabled) {
// when subpass enabled, the color result (gles2/gles3) will write to gbuffer[3] and the blit to color texture, so the format should be RGBA16F
data.gbuffer[3] = builder.create<framegraph::Texture>(DeferredPipeline::fgStrHandleGbufferTexture[3], gbufferInfoFloat);
data.gbuffer[3] = builder.create(DeferredPipeline::fgStrHandleGbufferTexture[3], gbufferInfoFloat);
} else {
data.gbuffer[3] = builder.create<framegraph::Texture>(DeferredPipeline::fgStrHandleGbufferTexture[3], gbufferInfo);
data.gbuffer[3] = builder.create(DeferredPipeline::fgStrHandleGbufferTexture[3], gbufferInfo);
}
gfx::Color clearColor{0.0, 0.0, 0.0, 0.0};
@@ -209,7 +209,7 @@ void GbufferStage::render(scene::Camera *camera) {
static_cast<uint>(pipeline->getWidth() * shadingScale),
static_cast<uint>(pipeline->getHeight() * shadingScale),
};
data.depth = builder.create<framegraph::Texture>(DeferredPipeline::fgStrHandleOutDepthTexture, depthTexInfo);
data.depth = builder.create(DeferredPipeline::fgStrHandleOutDepthTexture, depthTexInfo);
framegraph::RenderTargetAttachment::Descriptor depthInfo;
depthInfo.usage = framegraph::RenderTargetAttachment::Usage::DEPTH_STENCIL;
@@ -376,7 +376,7 @@ void LightingStage::fgLightingPass(scene::Camera *camera) {
colorTexInfo.usage = gfx::TextureUsageBit::COLOR_ATTACHMENT | gfx::TextureUsageBit::SAMPLED;
colorTexInfo.width = static_cast<uint>(pipeline->getWidth() * shadingScale);
colorTexInfo.height = static_cast<uint>(pipeline->getHeight() * shadingScale);
data.outputTex = builder.create<framegraph::Texture>(RenderPipeline::fgStrHandleOutColorTexture, colorTexInfo);
data.outputTex = builder.create(RenderPipeline::fgStrHandleOutColorTexture, colorTexInfo);
framegraph::RenderTargetAttachment::Descriptor colorAttachmentInfo;
colorAttachmentInfo.usage = framegraph::RenderTargetAttachment::Usage::COLOR;
@@ -465,7 +465,7 @@ void LightingStage::fgTransparent(scene::Camera *camera) {
colorAttachmentInfo.loadOp = gfx::LoadOp::CLEAR;
colorAttachmentInfo.clearColor = clearColor;
data.outputTex = builder.create<framegraph::Texture>(DeferredPipeline::fgStrHandleOutColorTexture, colorTexInfo);
data.outputTex = builder.create(DeferredPipeline::fgStrHandleOutColorTexture, colorTexInfo);
}
data.outputTex = builder.write(data.outputTex, colorAttachmentInfo);
@@ -486,7 +486,7 @@ void LightingStage::fgTransparent(scene::Camera *camera) {
static_cast<uint>(pipeline->getWidth() * shadingScale),
static_cast<uint>(pipeline->getHeight() * shadingScale),
};
data.depth = builder.create<framegraph::Texture>(DeferredPipeline::fgStrHandleOutDepthTexture, depthTexInfo);
data.depth = builder.create(DeferredPipeline::fgStrHandleOutDepthTexture, depthTexInfo);
}
data.depth = builder.write(data.depth, depthAttachmentInfo);
builder.writeToBlackboard(DeferredPipeline::fgStrHandleOutDepthTexture, data.depth);
@@ -595,7 +595,7 @@ void LightingStage::fgSsprPass(scene::Camera *camera) {
gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_SRC | gfx::TextureUsageBit::TRANSFER_DST;
colorTexInfo.width = _ssprTexWidth;
colorTexInfo.height = _ssprTexHeight;
data.reflection = builder.create<framegraph::Texture>(reflectTexHandle, colorTexInfo);
data.reflection = builder.create(reflectTexHandle, colorTexInfo);
framegraph::RenderTargetAttachment::Descriptor colorAttachmentInfo;
colorAttachmentInfo.usage = framegraph::RenderTargetAttachment::Usage::COLOR;
@@ -634,7 +634,7 @@ void LightingStage::fgSsprPass(scene::Camera *camera) {
colorTexInfo.usage = gfx::TextureUsageBit::STORAGE | gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_SRC | gfx::TextureUsageBit::TRANSFER_DST;
colorTexInfo.width = _ssprTexWidth;
colorTexInfo.height = _ssprTexHeight;
data.reflection = builder.create<framegraph::Texture>(reflectTexHandle, colorTexInfo);
data.reflection = builder.create(reflectTexHandle, colorTexInfo);
}
data.reflection = builder.read(framegraph::TextureHandle(builder.readFromBlackboard(reflectTexHandle)));
@@ -700,7 +700,7 @@ void LightingStage::fgSsprPass(scene::Camera *camera) {
colorTexInfo.usage = gfx::TextureUsageBit::STORAGE | gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_SRC;
colorTexInfo.width = _ssprTexWidth;
colorTexInfo.height = _ssprTexHeight;
data.denoise = builder.create<framegraph::Texture>(denoiseTexHandle[_denoiseIndex], colorTexInfo);
data.denoise = builder.create(denoiseTexHandle[_denoiseIndex], colorTexInfo);
data.denoise = builder.write(data.denoise);
builder.writeToBlackboard(denoiseTexHandle[_denoiseIndex], data.denoise);
@@ -168,7 +168,7 @@ void ForwardStage::render(scene::Camera *camera) {
colorTexInfo.usage = gfx::TextureUsageBit::COLOR_ATTACHMENT | gfx::TextureUsageBit::SAMPLED;
colorTexInfo.width = static_cast<uint>(pipeline->getWidth() * shadingScale);
colorTexInfo.height = static_cast<uint>(pipeline->getHeight() * shadingScale);
data.outputTex = builder.create<framegraph::Texture>(RenderPipeline::fgStrHandleOutColorTexture, colorTexInfo);
data.outputTex = builder.create(RenderPipeline::fgStrHandleOutColorTexture, colorTexInfo);
framegraph::RenderTargetAttachment::Descriptor colorAttachmentInfo;
colorAttachmentInfo.usage = framegraph::RenderTargetAttachment::Usage::COLOR;
colorAttachmentInfo.clearColor = _clearColors[0];
@@ -202,7 +202,7 @@ void ForwardStage::render(scene::Camera *camera) {
depthAttachmentInfo.clearStencil = camera->clearStencil;
depthAttachmentInfo.endAccesses = {gfx::AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE};
data.depth = builder.create<framegraph::Texture>(RenderPipeline::fgStrHandleOutDepthTexture, depthTexInfo);
data.depth = builder.create(RenderPipeline::fgStrHandleOutDepthTexture, depthTexInfo);
data.depth = builder.write(data.depth, depthAttachmentInfo);
builder.writeToBlackboard(RenderPipeline::fgStrHandleOutDepthTexture, data.depth);
builder.setViewport(pipeline->getViewport(camera), _renderArea);
@@ -36,7 +36,7 @@
namespace cc {
namespace pipeline {
std::unordered_map<uint, cc::gfx::RenderPass *> ShadowFlow::renderPassHashMap;
std::unordered_map<size_t, cc::gfx::RenderPass *> ShadowFlow::renderPassHashMap;
RenderFlowInfo ShadowFlow::initInfo = {
"ShadowFlow",
@@ -207,7 +207,7 @@ void ShadowFlow::initShadowFrameBuffer(RenderPipeline *pipeline, const scene::Li
rpInfo.colorAttachments.emplace_back(colorAttachment);
rpInfo.depthStencilAttachment = depthStencilAttachment;
uint rpHash = cc::gfx::RenderPass::computeHash(rpInfo);
size_t rpHash = cc::gfx::RenderPass::computeHash(rpInfo);
auto iter = renderPassHashMap.find(rpHash);
if (iter != renderPassHashMap.end()) {
_renderPass = iter->second;
@@ -62,7 +62,7 @@ private:
vector<const scene::Light *> _validLights;
vector<gfx::Texture *> _usedTextures;
static std::unordered_map<uint, cc::gfx::RenderPass*> renderPassHashMap;
static std::unordered_map<size_t, cc::gfx::RenderPass *> renderPassHashMap;
};
} // namespace pipeline
} // namespace cc
+1 -1
View File
@@ -1240,7 +1240,7 @@ class NativeClass(object):
elif cursor.kind == cindex.CursorKind.FIELD_DECL:
self.fields.append(NativeField(cursor, self.generator))
if (self.is_struct or self._current_visibility == cindex.AccessSpecifier.PUBLIC) and NativeField.can_parse(cursor.type, self.generator, cursor):
if (self.is_struct or self._current_visibility == cindex.AccessSpecifier.PUBLIC) and NativeField.can_parse(cursor.type, self.generator, cursor) and not self.generator.should_skip(self.class_name, cursor.displayname):
self.public_fields.append(NativeField(cursor, self.generator))
elif cursor.kind == cindex.CursorKind.CXX_ACCESS_SPEC_DECL:
self._current_visibility = cursor.access_specifier
+52 -48
View File
@@ -76,6 +76,8 @@ while (enumCap) {
header = header.replace(/\/\*.*?\*\//gs, '');
header = header.replace(/\s*[*&](.)/g, (_, c) => (c === '>' ? '' : ' ') + c);
header = header.replace(/(?:\w*::)?vector<(.+?)>/g, '$1[]');
// and preprocessors
header = header.replace(/\s*#(if|else|elif|end).*/gm, '');
const typedefRE = /^\s*using\s+(.+?)\s*=\s*(.+?);/gsm;
const typedefMap = { lists: {}, others: [] };
@@ -122,7 +124,7 @@ const getMemberList = (() => {
};
})();
const structRE = /struct\s+(\w+).*?{\s*(.+?)\s*};/gs;
const structRE = /(struct\s+(?:\w+\(\w+\)\s+)?)(\w+).*?{\s*(.+?)\s*};/gs;
const structMemberRE = /^\s*(const\w*\s*)?([\w[\]]+)\s+?(\w+)(?:\s*[={]?\s*(.*?)\s*}*\s*)?;(?:\s*\/\/\s*@ts-(.*?)$)?/gm;
const structMap = {};
const replaceConstants = (() => {
@@ -150,60 +152,62 @@ const getArrayValue = (decayedType, value) => {
};
let structCap = structRE.exec(header);
while (structCap) {
const struct = structMap[structCap[1]] = {};
const struct = structMap[structCap[2]] = {};
struct.member = {};
// structRE can not reliably extract the corrent member declaration range
const memberList = getMemberList(header, structCap.index);
// structRE can not reliably extract the correct member declaration range
const memberList = getMemberList(header, structCap.index + structCap[1].length);
let memberCap = structMemberRE.exec(memberList);
while (memberCap) {
let type = memberCap[2];
let readonly = false;
if (typedefMap.lists[type]) {
type = typedefMap.lists[type];
} else {
type = type.replace(/(\b)(void)(\b)/, '$1number$1');
type = type.replace(/(\b)(?:uint\w+?_t|int\w+?_t|float)(\b)/, '$1number$1');
type = type.replace(/(\b)(?:bool)(\b)/, '$1boolean$2');
type = type.replace(/(\b)(?:String)(\b)/, '$1string$2');
}
if (memberCap[1]) { readonly = true; }
const isArray = type.endsWith('[]');
const decayedType = isArray ? type.slice(0, -2) : type;
let value = memberCap[4];
let n = Number.parseInt(value);
if (!Number.isNaN(n)) {
if (!value.startsWith('0x')) { value = n; } // keep hexadecimal numbers
} else if (value) {
value = replaceConstants(value);
if (isArray) { value = getArrayValue(decayedType, value); }
} else {
if (isArray) { value = '[]'; }
else if (type === 'string') { value = '\'\''; }
else { value = `new ${type}()`; }
}
const info = struct.member[memberCap[3]] = {
// all the overridable values
readonly, type, value, isArray, decayedType,
};
const directives = memberCap[5];
if (directives) {
if (directives.startsWith('nullable')) {
info.type += ' | null';
info.value = 'null';
} else if (directives.startsWith('overrides')) {
let overrides = {};
try { overrides = yaml.load(memberCap[5].slice(9)); }
catch (e) { console.warn(e); }
Object.assign(info, overrides);
if (!memberCap[3].startsWith('_')) {
let type = memberCap[2];
let readonly = false;
if (typedefMap.lists[type]) {
type = typedefMap.lists[type];
} else {
type = type.replace(/(\b)(void)(\b)/, '$1number$1');
type = type.replace(/(\b)(?:uint\w+?_t|int\w+?_t|float)(\b)/, '$1number$1');
type = type.replace(/(\b)(?:bool)(\b)/, '$1boolean$2');
type = type.replace(/(\b)(?:String)(\b)/, '$1string$2');
}
if (memberCap[1]) { readonly = true; }
const isArray = type.endsWith('[]');
const decayedType = isArray ? type.slice(0, -2) : type;
let value = memberCap[4];
let n = Number.parseInt(value);
if (!Number.isNaN(n)) {
if (!value.startsWith('0x')) { value = n; } // keep hexadecimal numbers
} else if (value) {
value = replaceConstants(value);
if (isArray) { value = getArrayValue(decayedType, value); }
} else {
if (isArray) { value = '[]'; }
else if (type === 'string') { value = '\'\''; }
else { value = `new ${type}()`; }
}
const info = struct.member[memberCap[3]] = {
// all the overridable values
readonly, type, value, isArray, decayedType,
};
const directives = memberCap[5];
if (directives) {
if (directives.startsWith('nullable')) {
info.type += ' | null';
info.value = 'null';
} else if (directives.startsWith('overrides')) {
let overrides = {};
try { overrides = yaml.load(memberCap[5].slice(9)); }
catch (e) { console.warn(e); }
Object.assign(info, overrides);
}
}
if (info.type === 'number' && info.value === 'null!') { info.value = 0; }
}
if (info.type === 'number' && info.value === 'null!') { info.value = 0; }
memberCap = structMemberRE.exec(memberList);
}
+4 -1
View File
@@ -72,7 +72,10 @@ skip = Buffer::[Buffer initialize update],
Sampler::[Sampler],
GlobalBarrier::[GlobalBarrier],
TextureBarrier::[TextureBarrier],
Device::[Device copyBuffersToTexture copyTextureToBuffers createBuffer createTexture getInstance]
Device::[Device copyBuffersToTexture copyTextureToBuffers createBuffer createTexture getInstance],
TextureInfo::[_*],
TextureViewInfo::[_*],
BufferInfo::[_*]
getter_setter = Device::[gfxAPI deviceName memoryStatus queue commandBuffer renderer vendor numDrawCalls numInstances numTris capabilities],
Shader::[name stages attributes blocks samplers],