mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-06 04:33:49 +01:00
Merge pull request #11119 from hrydgard/vk-nulltexture
Never bind a NULL image view in Vulkan, not even through thin3d
This commit is contained in:
4 files changed
+37
-33
No files matched your search
@@ -215,11 +215,6 @@ void DrawEngineVulkan::DestroyDeviceObjects() {
|
||||
vulkan_->Delete().QueueDeletePipelineLayout(pipelineLayout_);
|
||||
if (descriptorSetLayout_ != VK_NULL_HANDLE)
|
||||
vulkan_->Delete().QueueDeleteDescriptorSetLayout(descriptorSetLayout_);
|
||||
if (nullTexture_) {
|
||||
nullTexture_->Destroy();
|
||||
delete nullTexture_;
|
||||
nullTexture_ = nullptr;
|
||||
}
|
||||
if (vertexCache_) {
|
||||
vertexCache_->Destroy(vulkan_);
|
||||
delete vertexCache_;
|
||||
@@ -265,29 +260,6 @@ void DrawEngineVulkan::BeginFrame() {
|
||||
// TODO: How can we make this nicer...
|
||||
((TessellationDataTransferVulkan *)tessDataTransfer)->SetPushBuffer(frame->pushUBO);
|
||||
|
||||
if (!nullTexture_) {
|
||||
VkCommandBuffer cmdInit = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER);
|
||||
nullTexture_ = new VulkanTexture(vulkan_, textureCache_->GetAllocator());
|
||||
nullTexture_->SetTag("Null");
|
||||
int w = 8;
|
||||
int h = 8;
|
||||
nullTexture_->CreateDirect(cmdInit, w, h, 1, VK_FORMAT_A8B8G8R8_UNORM_PACK32, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
|
||||
uint32_t bindOffset;
|
||||
VkBuffer bindBuf;
|
||||
uint32_t *data = (uint32_t *)frame->pushUBO->Push(w * h * 4, &bindOffset, &bindBuf);
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
// data[y*w + x] = ((x ^ y) & 1) ? 0xFF808080 : 0xFF000000; // gray/black checkerboard
|
||||
data[y*w + x] = 0; // black
|
||||
}
|
||||
}
|
||||
nullTexture_->UploadMip(cmdInit, 0, w, h, bindBuf, bindOffset, w);
|
||||
nullTexture_->EndCreate(cmdInit);
|
||||
} else {
|
||||
nullTexture_->Touch();
|
||||
}
|
||||
|
||||
DirtyAllUBOs();
|
||||
|
||||
// Wipe the vertex cache if it's grown too large.
|
||||
@@ -796,7 +768,7 @@ void DrawEngineVulkan::DoFlush() {
|
||||
textureCache_->ApplyTexture();
|
||||
textureCache_->GetVulkanHandles(imageView, sampler);
|
||||
if (imageView == VK_NULL_HANDLE)
|
||||
imageView = nullTexture_->GetImageView();
|
||||
imageView = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::NULL_IMAGEVIEW);
|
||||
if (sampler == VK_NULL_HANDLE)
|
||||
sampler = nullSampler_;
|
||||
}
|
||||
@@ -902,7 +874,7 @@ void DrawEngineVulkan::DoFlush() {
|
||||
textureCache_->ApplyTexture();
|
||||
textureCache_->GetVulkanHandles(imageView, sampler);
|
||||
if (imageView == VK_NULL_HANDLE)
|
||||
imageView = nullTexture_->GetImageView();
|
||||
imageView = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::NULL_IMAGEVIEW);
|
||||
if (sampler == VK_NULL_HANDLE)
|
||||
sampler = nullSampler_;
|
||||
}
|
||||
|
||||
@@ -267,8 +267,7 @@ private:
|
||||
VkImageView imageView = VK_NULL_HANDLE;
|
||||
VkSampler sampler = VK_NULL_HANDLE;
|
||||
|
||||
// Null texture
|
||||
VulkanTexture *nullTexture_ = nullptr;
|
||||
// For null texture
|
||||
VkSampler nullSampler_ = VK_NULL_HANDLE;
|
||||
|
||||
DrawEngineVulkanStats stats_;
|
||||
|
||||
@@ -258,6 +258,7 @@ enum class NativeObject {
|
||||
BOUND_TEXTURE0_IMAGEVIEW,
|
||||
BOUND_TEXTURE1_IMAGEVIEW,
|
||||
RENDER_MANAGER,
|
||||
NULL_IMAGEVIEW,
|
||||
};
|
||||
|
||||
enum FBColorDepth {
|
||||
|
||||
@@ -481,6 +481,8 @@ public:
|
||||
return (uintptr_t)boundImageView_[1];
|
||||
case NativeObject::RENDER_MANAGER:
|
||||
return (uintptr_t)&renderManager_;
|
||||
case NativeObject::NULL_IMAGEVIEW:
|
||||
return (uintptr_t)GetNullTexture()->GetImageView();
|
||||
default:
|
||||
Crash();
|
||||
return 0;
|
||||
@@ -490,12 +492,15 @@ public:
|
||||
void HandleEvent(Event ev, int width, int height, void *param1, void *param2) override;
|
||||
|
||||
private:
|
||||
VulkanTexture *GetNullTexture();
|
||||
VulkanContext *vulkan_ = nullptr;
|
||||
|
||||
VulkanRenderManager renderManager_;
|
||||
|
||||
VulkanDeviceAllocator *allocator_ = nullptr;
|
||||
|
||||
VulkanTexture *nullTexture_ = nullptr;
|
||||
|
||||
VKPipeline *curPipeline_ = nullptr;
|
||||
VKBuffer *curVBuffers_[4]{};
|
||||
int curVBufferOffsets_[4]{};
|
||||
@@ -609,6 +614,32 @@ static inline VkSamplerAddressMode AddressModeToVulkan(Draw::TextureAddressMode
|
||||
}
|
||||
}
|
||||
|
||||
VulkanTexture *VKContext::GetNullTexture() {
|
||||
if (!nullTexture_) {
|
||||
VkCommandBuffer cmdInit = renderManager_.GetInitCmd();
|
||||
nullTexture_ = new VulkanTexture(vulkan_, allocator_);
|
||||
nullTexture_->SetTag("Null");
|
||||
int w = 8;
|
||||
int h = 8;
|
||||
nullTexture_->CreateDirect(cmdInit, w, h, 1, VK_FORMAT_A8B8G8R8_UNORM_PACK32, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
|
||||
uint32_t bindOffset;
|
||||
VkBuffer bindBuf;
|
||||
uint32_t *data = (uint32_t *)push_->Push(w * h * 4, &bindOffset, &bindBuf);
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
// data[y*w + x] = ((x ^ y) & 1) ? 0xFF808080 : 0xFF000000; // gray/black checkerboard
|
||||
data[y*w + x] = 0; // black
|
||||
}
|
||||
}
|
||||
nullTexture_->UploadMip(cmdInit, 0, w, h, bindBuf, bindOffset, w);
|
||||
nullTexture_->EndCreate(cmdInit);
|
||||
} else {
|
||||
nullTexture_->Touch();
|
||||
}
|
||||
return nullTexture_;
|
||||
}
|
||||
|
||||
class VKSamplerState : public SamplerState {
|
||||
public:
|
||||
VKSamplerState(VulkanContext *vulkan, const SamplerStateDesc &desc) : vulkan_(vulkan) {
|
||||
@@ -791,6 +822,7 @@ VKContext::VKContext(VulkanContext *vulkan, bool splitSubmit)
|
||||
}
|
||||
|
||||
VKContext::~VKContext() {
|
||||
delete nullTexture_;
|
||||
allocator_->Destroy();
|
||||
// We have to delete on queue, so this can free its queued deletions.
|
||||
vulkan_->Delete().QueueCallback([](void *ptr) {
|
||||
@@ -1121,7 +1153,7 @@ void VKContext::UpdateBuffer(Buffer *buffer, const uint8_t *data, size_t offset,
|
||||
void VKContext::BindTextures(int start, int count, Texture **textures) {
|
||||
for (int i = start; i < start + count; i++) {
|
||||
boundTextures_[i] = static_cast<VKTexture *>(textures[i]);
|
||||
boundImageView_[i] = boundTextures_[i] ? boundTextures_[i]->GetImageView() : VK_NULL_HANDLE;
|
||||
boundImageView_[i] = boundTextures_[i] ? boundTextures_[i]->GetImageView() : GetNullTexture()->GetImageView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user