render to texture

This commit is contained in:
InoriRus
2022-02-14 11:58:44 +10:00
parent 9a912716f8
commit 38bde7e8b3
35 changed files with 2119 additions and 1237 deletions
@@ -65,31 +65,30 @@ struct VulkanMemory
uint64_t unique_id = 0;
};
struct VideoOutVulkanImage
struct VulkanImage
{
VkFormat format = VK_FORMAT_UNDEFINED;
VkExtent2D extent = {};
VkImage image = nullptr;
VkImageView image_view = nullptr;
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
Graphics::VulkanMemory memory;
};
struct DepthStencilVulkanImage
struct VideoOutVulkanImage: public VulkanImage
{
VkFormat format = VK_FORMAT_UNDEFINED;
VkExtent2D extent = {};
VkImage image = nullptr;
VkImageView image_view = nullptr;
Graphics::VulkanMemory memory;
};
struct TextureVulkanImage
struct DepthStencilVulkanImage: public VulkanImage
{
};
struct TextureVulkanImage: public VulkanImage
{
};
struct RenderTextureVulkanImage: public VulkanImage
{
VkFormat format = VK_FORMAT_UNDEFINED;
VkExtent2D extent = {};
VkImage image = nullptr;
VkImageView image_view = nullptr;
Graphics::VulkanMemory memory;
};
struct VulkanBuffer
@@ -16,6 +16,7 @@ class CommandProcessor;
struct VideoOutVulkanImage;
struct DepthStencilVulkanImage;
struct TextureVulkanImage;
struct RenderTextureVulkanImage;
struct VulkanCommandPool;
struct VulkanBuffer;
struct VulkanFramebuffer;
@@ -82,11 +83,14 @@ void GraphicsRenderWriteBack();
void GraphicsRenderDispatchDirect(CommandBuffer* buffer, HardwareContext* ctx, uint32_t thread_group_x, uint32_t thread_group_y,
uint32_t thread_group_z, uint32_t mode);
void GraphicsRenderMemoryBarrier(CommandBuffer* buffer);
void GraphicsRenderRenderTextureBarrier(CommandBuffer* buffer, uint64_t vaddr, uint64_t size);
void DeleteFramebuffer(VideoOutVulkanImage* image);
void DeleteFramebuffer(DepthStencilVulkanImage* image);
void DeleteFramebuffer(RenderTextureVulkanImage* image);
void DeleteDescriptor(VulkanBuffer* buffer);
void DeleteDescriptor(TextureVulkanImage* image);
void DeleteDescriptor(RenderTextureVulkanImage* image);
int GraphicsRenderAddEqEvent(LibKernel::EventQueue::KernelEqueue eq, int id, void* udata);
int GraphicsRenderDeleteEqEvent(LibKernel::EventQueue::KernelEqueue eq, int id);
@@ -1,10 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_DEPTHSTENCILBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_DEPTHSTENCILBUFFER_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_DEPTHSTENCILBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_DEPTHSTENCILBUFFER_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/GpuMemory.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
@@ -45,4 +45,4 @@ public:
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_DEPTHSTENCILBUFFER_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_DEPTHSTENCILBUFFER_H_ */
@@ -1,7 +1,8 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_GPUMEMORY_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_GPUMEMORY_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_GPUMEMORY_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_GPUMEMORY_H_
#include "Kyty/Core/Common.h"
#include "Kyty/Core/Vector.h"
#include "Emulator/Common.h"
@@ -12,9 +13,7 @@ namespace Kyty::Libs::Graphics {
struct GraphicContext;
struct VulkanMemory;
struct VulkanBuffer;
struct TextureVulkanImage;
struct VideoOutVulkanImage;
struct DepthStencilVulkanImage;
struct VulkanImage;
enum class GpuMemoryMode
{
@@ -24,7 +23,7 @@ enum class GpuMemoryMode
ReadWrite
};
enum class GpuMemoryObjectType
enum class GpuMemoryObjectType : uint64_t
{
Invalid,
VideoOutBuffer,
@@ -33,7 +32,16 @@ enum class GpuMemoryObjectType
IndexBuffer,
VertexBuffer,
StorageBuffer,
Texture
Texture,
RenderTexture,
Max
};
struct GpuMemoryObject
{
GpuMemoryObjectType type = GpuMemoryObjectType::Invalid;
void* obj = nullptr;
};
class GpuObject
@@ -68,21 +76,21 @@ void GpuMemoryInit();
void GpuMemorySetAllocatedRange(uint64_t vaddr, uint64_t size);
void GpuMemoryFree(GraphicContext* ctx, uint64_t vaddr, uint64_t size);
void* GpuMemoryGetObject(GraphicContext* ctx, uint64_t vaddr, uint64_t size, const GpuObject& info);
void* GpuMemoryGetObject(GraphicContext* ctx, const uint64_t* vaddr, const uint64_t* size, int vaddr_num, const GpuObject& info);
void GpuMemoryResetHash(GraphicContext* ctx, uint64_t vaddr, uint64_t size, GpuMemoryObjectType type);
void* GpuMemoryCreateObject(GraphicContext* ctx, uint64_t vaddr, uint64_t size, const GpuObject& info);
void* GpuMemoryCreateObject(GraphicContext* ctx, const uint64_t* vaddr, const uint64_t* size, int vaddr_num, const GpuObject& info);
void GpuMemoryResetHash(GraphicContext* ctx, const uint64_t* vaddr, const uint64_t* size, int vaddr_num, GpuMemoryObjectType type);
void GpuMemoryDbgDump();
void GpuMemoryFlush(GraphicContext* ctx);
void GpuMemoryFrameDone();
void GpuMemoryWriteBack(GraphicContext* ctx);
Vector<GpuMemoryObject> GpuMemoryFindObjects(uint64_t vaddr, uint64_t size);
bool VulkanAllocate(GraphicContext* ctx, VulkanMemory* mem);
void VulkanFree(GraphicContext* ctx, VulkanMemory* mem);
void VulkanMapMemory(GraphicContext* ctx, VulkanMemory* mem, void** data);
void VulkanUnmapMemory(GraphicContext* ctx, VulkanMemory* mem);
void VulkanBindImageMemory(GraphicContext* ctx, TextureVulkanImage* image, VulkanMemory* mem);
void VulkanBindImageMemory(GraphicContext* ctx, VideoOutVulkanImage* image, VulkanMemory* mem);
void VulkanBindImageMemory(GraphicContext* ctx, DepthStencilVulkanImage* image, VulkanMemory* mem);
void VulkanBindImageMemory(GraphicContext* ctx, VulkanImage* image, VulkanMemory* mem);
void VulkanBindBufferMemory(GraphicContext* ctx, VulkanBuffer* buffer, VulkanMemory* mem);
void GpuMemoryRegisterOwner(uint32_t* owner_handle, const char* name);
@@ -96,4 +104,4 @@ void GpuMemoryUnregisterResource(uint32_t resource_handle);
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_GPUMEMORY_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_GPUMEMORY_H_ */
@@ -1,10 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_INDEXBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_INDEXBUFFER_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_INDEXBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_INDEXBUFFER_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/GpuMemory.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
@@ -34,4 +34,4 @@ public:
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_INDEXBUFFER_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_INDEXBUFFER_H_ */
@@ -1,10 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_LABEL_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_LABEL_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_LABEL_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_LABEL_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/GpuMemory.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
@@ -60,4 +60,4 @@ void LabelSet(CommandBuffer* buffer, Label* label);
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_LABEL_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_LABEL_H_ */
@@ -0,0 +1,55 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_RENDERTEXTURE_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_RENDERTEXTURE_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
namespace Kyty::Libs::Graphics {
struct GraphicContext;
struct VulkanMemory;
enum class RenderTextureFormat : uint64_t
{
R8G8B8A8Unorm
};
class RenderTextureObject: public GpuObject
{
public:
static constexpr int PARAM_FORMAT = 0;
static constexpr int PARAM_WIDTH = 1;
static constexpr int PARAM_HEIGHT = 2;
static constexpr int PARAM_TILED = 3;
static constexpr int PARAM_NEO = 4;
static constexpr int PARAM_PITCH = 5;
explicit RenderTextureObject(RenderTextureFormat pixel_format, uint32_t width, uint32_t height, bool tiled, bool neo, uint32_t pitch)
{
params[PARAM_FORMAT] = static_cast<uint64_t>(pixel_format);
params[PARAM_WIDTH] = width;
params[PARAM_HEIGHT] = height;
params[PARAM_TILED] = tiled ? 1 : 0;
params[PARAM_NEO] = neo ? 1 : 0;
params[PARAM_PITCH] = pitch;
check_hash = true;
type = Graphics::GpuMemoryObjectType::RenderTexture;
}
void* Create(GraphicContext* ctx, const uint64_t* vaddr, const uint64_t* size, int vaddr_num, VulkanMemory* mem) const override;
bool Equal(const uint64_t* other) const override;
[[nodiscard]] write_back_func_t GetWriteBackFunc() const override { return nullptr; };
[[nodiscard]] delete_func_t GetDeleteFunc() const override;
[[nodiscard]] update_func_t GetUpdateFunc() const override;
};
} // namespace Kyty::Libs::Graphics
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_RENDERTEXTURE_H_ */
@@ -1,10 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_STORAGEBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_STORAGEBUFFER_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_STORAGEBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_STORAGEBUFFER_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/GpuMemory.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
@@ -37,4 +37,4 @@ public:
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_STORAGEBUFFER_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_STORAGEBUFFER_H_ */
@@ -1,10 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_TEXTURE_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_TEXTURE_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_TEXTURE_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_TEXTURE_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/GpuMemory.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
@@ -28,7 +28,7 @@ public:
static constexpr int PARAM_NEO = 6;
static constexpr int PARAM_SWIZZLE = 7;
TextureObject(uint32_t dfmt, uint32_t nfmt, uint32_t width, uint32_t height, uint32_t pitch, uint32_t levels, bool htile, bool neo,
TextureObject(uint32_t dfmt, uint32_t nfmt, uint32_t width, uint32_t height, uint32_t pitch, uint32_t levels, uint32_t tile, bool neo,
uint32_t swizzle, uint32_t usage)
{
params[PARAM_DFMT_NFMT] = (static_cast<uint64_t>(dfmt) << 32u) | nfmt;
@@ -36,7 +36,7 @@ public:
params[PARAM_WIDTH_HEIGHT] = (static_cast<uint64_t>(width) << 32u) | height;
params[PARAM_USAGE] = usage;
params[PARAM_LEVELS] = levels;
params[PARAM_TILE] = htile ? 1 : 0;
params[PARAM_TILE] = tile;
params[PARAM_NEO] = neo ? 1 : 0;
params[PARAM_SWIZZLE] = swizzle;
check_hash = true;
@@ -55,4 +55,4 @@ public:
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_TEXTURE_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_TEXTURE_H_ */
@@ -1,10 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_VERTEXBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_VERTEXBUFFER_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_VERTEXBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_VERTEXBUFFER_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/GpuMemory.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
@@ -34,4 +34,4 @@ public:
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_VERTEXBUFFER_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_VERTEXBUFFER_H_ */
@@ -1,10 +1,10 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_VIDEOOUTBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_VIDEOOUTBUFFER_H_
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_VIDEOOUTBUFFER_H_
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_VIDEOOUTBUFFER_H_
#include "Kyty/Core/Common.h"
#include "Emulator/Common.h"
#include "Emulator/Graphics/GpuMemory.h"
#include "Emulator/Graphics/Objects/GpuMemory.h"
#ifdef KYTY_EMU_ENABLED
@@ -47,4 +47,4 @@ public:
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_VIDEOOUTBUFFER_H_ */
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_OBJECTS_VIDEOOUTBUFFER_H_ */
@@ -15,6 +15,8 @@ enum class TileMode
VideoOutTiled,
TextureLinear,
TextureTiled,
// RenderTextureLinear,
// RenderTextureTiled,
};
void TileInit();
@@ -25,8 +27,8 @@ void TileConvertTiledToLinear(void* dst, const void* src, TileMode mode, uint32_
void TileGetDepthSize(uint32_t width, uint32_t height, uint32_t z_format, uint32_t stencil_format, bool htile, bool neo,
uint32_t* stencil_size, uint32_t* htile_size, uint32_t* depth_size, uint32_t* pitch);
void TileGetVideoOutSize(uint32_t width, uint32_t height, bool tile, bool neo, uint32_t* size, uint32_t* pitch);
void TileGetTextureSize(uint32_t dfmt, uint32_t nfmt, uint32_t width, uint32_t height, uint32_t pitch, uint32_t levels, bool tile, bool neo,
uint32_t* total_size, uint32_t* level_sizes, uint32_t* padded_width, uint32_t* padded_height);
void TileGetTextureSize(uint32_t dfmt, uint32_t nfmt, uint32_t width, uint32_t height, uint32_t pitch, uint32_t levels, uint32_t tile,
bool neo, uint32_t* total_size, uint32_t* level_sizes, uint32_t* padded_width, uint32_t* padded_height);
} // namespace Kyty::Libs::Graphics
@@ -17,7 +17,7 @@ namespace Kyty::Libs::Graphics {
class CommandBuffer;
struct GraphicContext;
struct VulkanBuffer;
struct VideoOutVulkanImage;
struct VulkanImage;
struct TextureVulkanImage;
struct DepthStencilVulkanImage;
struct VulkanSwapchain;
@@ -30,16 +30,16 @@ struct BufferImageCopy
uint32_t pitch;
};
void UtilBufferToImage(CommandBuffer* buffer, VulkanBuffer* src_buffer, uint32_t src_pitch, VideoOutVulkanImage* dst_image);
void UtilBufferToImage(CommandBuffer* buffer, VulkanBuffer* src_buffer, uint32_t src_pitch, VulkanImage* dst_image);
void UtilBufferToImage(CommandBuffer* buffer, VulkanBuffer* src_buffer, TextureVulkanImage* dst_image,
const Vector<BufferImageCopy>& regions, uint64_t dst_layout);
void UtilBlitImage(CommandBuffer* buffer, VideoOutVulkanImage* src_image, VulkanSwapchain* dst_swapchain);
void UtilFillImage(GraphicContext* ctx, VideoOutVulkanImage* dst_image, const void* src_data, uint64_t size, uint32_t src_pitch);
void UtilBlitImage(CommandBuffer* buffer, VulkanImage* src_image, VulkanSwapchain* dst_swapchain);
void UtilFillImage(GraphicContext* ctx, VulkanImage* dst_image, const void* src_data, uint64_t size, uint32_t src_pitch);
void UtilFillImage(GraphicContext* ctx, TextureVulkanImage* dst_image, const void* src_data, uint64_t size,
const Vector<BufferImageCopy>& regions, uint64_t dst_layout);
void UtilCopyBuffer(VulkanBuffer* src_buffer, VulkanBuffer* dst_buffer, uint64_t size);
void UtilSetImageLayoutOptimal(DepthStencilVulkanImage* image);
void UtilSetImageLayoutOptimal(VideoOutVulkanImage* image);
void UtilSetDepthLayoutOptimal(DepthStencilVulkanImage* image);
void UtilSetImageLayoutOptimal(VulkanImage* image);
void VulkanCreateBuffer(GraphicContext* gctx, uint64_t size, VulkanBuffer* buffer);
void VulkanDeleteBuffer(GraphicContext* gctx, VulkanBuffer* buffer);