Reland "Make compiling the amd vulkan memory allocator optional."
This reverts commit6a5a91e164
. Reason for revert: chrome gn updated, so this should roll fine now Original change's description: > Revert "Make compiling the amd vulkan memory allocator optional." > > This reverts commit23da19863e
. > > Reason for revert: break chrome roll, need to land chrome change first > > Original change's description: > > Make compiling the amd vulkan memory allocator optional. > > > > Change-Id: I79b9f78b52f215076a371cbd0ff057d61dd855f0 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/285380 > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,brianosman@google.com,penghuang@chromium.org > > Change-Id: Ifc17a07f5cdfcf7b38272e5c44e5b894019cf44a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/285538 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,brianosman@google.com,penghuang@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I4767039236137d3eaece2e16abef57278ce199ed Reviewed-on: https://skia-review.googlesource.com/c/skia/+/285662 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
3088c69b5f
commit
b16beb94a3
7
BUILD.gn
7
BUILD.gn
@ -89,6 +89,9 @@ config("skia_private") {
|
||||
if (skia_use_gl && skia_use_angle) {
|
||||
defines += [ "SK_ANGLE" ]
|
||||
}
|
||||
if (skia_use_vma) {
|
||||
defines += [ "SK_USE_VMA" ]
|
||||
}
|
||||
}
|
||||
|
||||
# Any code that's linked into Skia-the-library should use this config via += skia_library_configs.
|
||||
@ -562,7 +565,9 @@ optional("gpu") {
|
||||
|
||||
if (skia_use_vulkan) {
|
||||
public_defines += [ "SK_VULKAN" ]
|
||||
deps += [ "third_party/vulkanmemoryallocator" ]
|
||||
if (skia_use_vma) {
|
||||
deps += [ "third_party/vulkanmemoryallocator" ]
|
||||
}
|
||||
sources += skia_vk_sources
|
||||
if (skia_enable_vulkan_debug_layers) {
|
||||
public_defines += [ "SK_ENABLE_VK_LAYERS" ]
|
||||
|
@ -105,6 +105,7 @@ declare_args() {
|
||||
skia_use_sfntly = skia_use_icu
|
||||
skia_enable_vulkan_debug_layers = skia_enable_gpu_debug_layers
|
||||
skia_enable_direct3d_debug_layer = skia_enable_gpu_debug_layers
|
||||
skia_use_vma = skia_use_vulkan
|
||||
}
|
||||
|
||||
# Our tools require static linking (they use non-exported symbols), and the GPU backend.
|
||||
|
@ -12,13 +12,18 @@
|
||||
#include "src/gpu/vk/GrVkMemory.h"
|
||||
#include "src/gpu/vk/GrVkUtil.h"
|
||||
|
||||
GrVkAMDMemoryAllocator::GrVkAMDMemoryAllocator(VkPhysicalDevice physicalDevice,
|
||||
VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface)
|
||||
: fAllocator(VK_NULL_HANDLE)
|
||||
, fInterface(std::move(interface))
|
||||
, fDevice(device) {
|
||||
#define GR_COPY_FUNCTION(NAME) functions.vk##NAME = fInterface->fFunctions.f##NAME
|
||||
#ifndef SK_USE_VMA
|
||||
sk_sp<GrVkMemoryAllocator> GrVkAMDMemoryAllocator::Make(VkPhysicalDevice physicalDevice,
|
||||
VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface) {
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
|
||||
sk_sp<GrVkMemoryAllocator> GrVkAMDMemoryAllocator::Make(VkPhysicalDevice physicalDevice,
|
||||
VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface) {
|
||||
#define GR_COPY_FUNCTION(NAME) functions.vk##NAME = interface->fFunctions.f##NAME
|
||||
|
||||
VmaVulkanFunctions functions;
|
||||
GR_COPY_FUNCTION(GetPhysicalDeviceProperties);
|
||||
@ -55,9 +60,20 @@ GrVkAMDMemoryAllocator::GrVkAMDMemoryAllocator(VkPhysicalDevice physicalDevice,
|
||||
info.pHeapSizeLimit = nullptr;
|
||||
info.pVulkanFunctions = &functions;
|
||||
|
||||
vmaCreateAllocator(&info, &fAllocator);
|
||||
VmaAllocator allocator;
|
||||
vmaCreateAllocator(&info, &allocator);
|
||||
|
||||
return sk_sp<GrVkAMDMemoryAllocator>(new GrVkAMDMemoryAllocator(allocator, device,
|
||||
std::move(interface)));
|
||||
}
|
||||
|
||||
GrVkAMDMemoryAllocator::GrVkAMDMemoryAllocator(VmaAllocator allocator,
|
||||
VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface)
|
||||
: fAllocator(allocator)
|
||||
, fInterface(std::move(interface))
|
||||
, fDevice(device) {}
|
||||
|
||||
GrVkAMDMemoryAllocator::~GrVkAMDMemoryAllocator() {
|
||||
vmaDestroyAllocator(fAllocator);
|
||||
fAllocator = VK_NULL_HANDLE;
|
||||
@ -273,3 +289,4 @@ uint64_t GrVkAMDMemoryAllocator::totalAllocatedMemory() const {
|
||||
return stats.total.usedBytes + stats.total.unusedBytes;
|
||||
}
|
||||
|
||||
#endif // SK_USE_VMA
|
||||
|
@ -8,21 +8,30 @@
|
||||
#ifndef GrVkAMDMemoryAllocator_DEFINED
|
||||
#define GrVkAMDMemoryAllocator_DEFINED
|
||||
|
||||
|
||||
#include "include/gpu/vk/GrVkMemoryAllocator.h"
|
||||
|
||||
#include "GrVulkanMemoryAllocator.h"
|
||||
|
||||
struct GrVkInterface;
|
||||
|
||||
#ifndef SK_USE_VMA
|
||||
class GrVkAMDMemoryAllocator {
|
||||
public:
|
||||
static sk_sp<GrVkMemoryAllocator> Make(VkPhysicalDevice physicalDevice, VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface);
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#include "GrVulkanMemoryAllocator.h"
|
||||
|
||||
class GrVkAMDMemoryAllocator : public GrVkMemoryAllocator {
|
||||
public:
|
||||
GrVkAMDMemoryAllocator(VkPhysicalDevice physicalDevice, VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface);
|
||||
static sk_sp<GrVkMemoryAllocator> Make(VkPhysicalDevice physicalDevice, VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface);
|
||||
|
||||
~GrVkAMDMemoryAllocator() override;
|
||||
|
||||
bool allocateMemoryForImage(VkImage image, AllocationPropertyFlags flags, GrVkBackendMemory*) override;
|
||||
bool allocateMemoryForImage(VkImage image, AllocationPropertyFlags flags,
|
||||
GrVkBackendMemory*) override;
|
||||
|
||||
bool allocateMemoryForBuffer(VkBuffer buffer, BufferUsage usage,
|
||||
AllocationPropertyFlags flags, GrVkBackendMemory*) override;
|
||||
@ -43,6 +52,9 @@ public:
|
||||
uint64_t totalAllocatedMemory() const override;
|
||||
|
||||
private:
|
||||
GrVkAMDMemoryAllocator(VmaAllocator allocator, VkDevice device,
|
||||
sk_sp<const GrVkInterface> interface);
|
||||
|
||||
VmaAllocator fAllocator;
|
||||
|
||||
// If a future version of the AMD allocator has helper functions for flushing and invalidating
|
||||
@ -54,4 +66,6 @@ private:
|
||||
typedef GrVkMemoryAllocator INHERITED;
|
||||
};
|
||||
|
||||
#endif // SK_USE_VMA
|
||||
|
||||
#endif
|
||||
|
@ -139,9 +139,20 @@ sk_sp<GrGpu> GrVkGpu::Make(const GrVkBackendContext& backendContext,
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
sk_sp<GrVkMemoryAllocator> memoryAllocator = backendContext.fMemoryAllocator;
|
||||
if (!memoryAllocator) {
|
||||
// We were not given a memory allocator at creation
|
||||
memoryAllocator = GrVkAMDMemoryAllocator::Make(backendContext.fPhysicalDevice,
|
||||
backendContext.fDevice, interface);
|
||||
}
|
||||
if (!memoryAllocator) {
|
||||
SkDEBUGFAIL("No supplied vulkan memory allocator and unable to create one internally.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<GrVkGpu> vkGpu(new GrVkGpu(context, options, backendContext, interface,
|
||||
instanceVersion, physDevVersion));
|
||||
instanceVersion, physDevVersion,
|
||||
std::move(memoryAllocator)));
|
||||
if (backendContext.fProtectedContext == GrProtected::kYes &&
|
||||
!vkGpu->vkCaps().supportsProtectedMemory()) {
|
||||
return nullptr;
|
||||
@ -153,10 +164,11 @@ sk_sp<GrGpu> GrVkGpu::Make(const GrVkBackendContext& backendContext,
|
||||
|
||||
GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options,
|
||||
const GrVkBackendContext& backendContext, sk_sp<const GrVkInterface> interface,
|
||||
uint32_t instanceVersion, uint32_t physicalDeviceVersion)
|
||||
uint32_t instanceVersion, uint32_t physicalDeviceVersion,
|
||||
sk_sp<GrVkMemoryAllocator> memoryAllocator)
|
||||
: INHERITED(context)
|
||||
, fInterface(std::move(interface))
|
||||
, fMemoryAllocator(backendContext.fMemoryAllocator)
|
||||
, fMemoryAllocator(std::move(memoryAllocator))
|
||||
, fPhysicalDevice(backendContext.fPhysicalDevice)
|
||||
, fDevice(backendContext.fDevice)
|
||||
, fQueue(backendContext.fQueue)
|
||||
@ -165,12 +177,7 @@ GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options,
|
||||
, fDisconnected(false)
|
||||
, fProtectedContext(backendContext.fProtectedContext) {
|
||||
SkASSERT(!backendContext.fOwnsInstanceAndDevice);
|
||||
|
||||
if (!fMemoryAllocator) {
|
||||
// We were not given a memory allocator at creation
|
||||
fMemoryAllocator.reset(new GrVkAMDMemoryAllocator(backendContext.fPhysicalDevice,
|
||||
fDevice, fInterface));
|
||||
}
|
||||
SkASSERT(fMemoryAllocator);
|
||||
|
||||
fCompiler = new SkSL::Compiler();
|
||||
|
||||
|
@ -169,7 +169,8 @@ private:
|
||||
};
|
||||
|
||||
GrVkGpu(GrContext*, const GrContextOptions&, const GrVkBackendContext&,
|
||||
sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion);
|
||||
sk_sp<const GrVkInterface>, uint32_t instanceVersion, uint32_t physicalDeviceVersion,
|
||||
sk_sp<GrVkMemoryAllocator>);
|
||||
|
||||
void onResetContext(uint32_t resetBits) override {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user