Skip to content

Commit

Permalink
feat: add ri impl for type and res
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Jan 23, 2025
1 parent 85ff96a commit b0c5ed9
Show file tree
Hide file tree
Showing 17 changed files with 1,545 additions and 1,074 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
[submodule "source/extern/Vulkan-Headers"]
path = source/extern/Vulkan-Headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
[submodule "source/extern/VulkanMemoryAllocator"]
path = source/extern/VulkanMemoryAllocator
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
1 change: 1 addition & 0 deletions source/extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (NOT GAME_MODULES_ONLY)
option(ENABLE_CTEST OFF)

add_subdirectory(glslang)
add_subdirectory(VulkanMemoryAllocator)

set(VULKAN_HEADERS_INSTALL_DIR "{CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers" )
option(VOLK_INSTALL "" OFF)
Expand Down
1 change: 1 addition & 0 deletions source/extern/VulkanMemoryAllocator
Submodule VulkanMemoryAllocator added at 7ab848
1 change: 1 addition & 0 deletions source/ref_nri/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_library(ref_nri SHARED ${REF_NRI_HEADERS} ${REF_NRI_COMMON_SOURCES} ${REF_NR
target_include_directories(ref_nri PRIVATE ${STB_INCLUDE_DIR} "../ref_base" "${NRI_DIR}/External/vulkan/include")
target_link_libraries(ref_nri PRIVATE NRI)
target_link_libraries(ref_nri PRIVATE volk)
target_link_libraries(ref_nri PRIVATE VulkanMemoryAllocator)
target_link_libraries(ref_nri PRIVATE glslang::glslang glslang::glslang-default-resource-limits glslang::SPIRV glslang::SPVRemapper qcore volk)
target_include_directories(ref_nri PRIVATE ${NRI_INCLUDE_DIR})
target_include_directories(ref_nri PRIVATE ${MINIZ_INCLUDE_DIR})
Expand Down
4 changes: 4 additions & 0 deletions source/ref_nri/r_frame_cmd_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ struct frame_tex_buffers_s {
NriRect screen;
NriDescriptor *colorAttachment;
NriTexture *colorTexture;

struct RITexture_s* riColorTexture;

NriDescriptor *depthAttachment;
NriTexture* depthTexture;

struct RITexture_s* riDepthTexture;

// used for post processing
struct pogo_buffers_s {
Expand Down
38 changes: 35 additions & 3 deletions source/ref_nri/r_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ rserr_t RF_Init( const char *applicationName, const char *screenshotPrefix, int
selectedAdapterIdx = i;
}
}
struct RIDeviceInit_s deviceInit = {};
struct RIDeviceDesc_s deviceInit = {};
deviceInit.physicalAdapter = &phyiscalAdapters[selectedAdapterIdx];
InitRIDevice(&rsh.renderer, &deviceInit, &rsh.device );

Expand Down Expand Up @@ -265,23 +265,50 @@ rserr_t RF_SetMode( int x, int y, int width, int height, int displayFrequency, b
return rserr_unknown;
}
{
struct RIWindowHandle_s windowHandle = {};

NriWindow nriWindow = { 0 };
switch( handle.winType ) {
case VID_WINDOW_WAYLAND:
windowHandle.type = RI_WINDOW_WAYLAND;
windowHandle.wayland.surface = handle.window.wayland.surface;
windowHandle.wayland.display = handle.window.wayland.display;

nriWindow.wayland.surface = handle.window.wayland.surface;
nriWindow.wayland.display = handle.window.wayland.display;
break;
case VID_WINDOW_TYPE_X11:
windowHandle.type = RI_WINDOW_X11;
windowHandle.x11.window = handle.window.x11.window;
windowHandle.x11.dpy = handle.window.x11.dpy;

nriWindow.x11.window = handle.window.x11.window;
nriWindow.x11.dpy = handle.window.x11.dpy;
break;
case VID_WINDOW_WIN32:
windowHandle.type = RI_WINDOW_WIN32;
windowHandle.windows.hwnd = handle.window.win.hwnd;

nriWindow.windows.hwnd = handle.window.win.hwnd;
break;
default:
assert( false );
break;
}
struct RISwapchainDesc_s swapchainInit = {};
swapchainInit.windowHandle = &windowHandle;
swapchainInit.imageCount = 3;
swapchainInit.queue = &rsh.device.queues[RI_QUEUE_GRAPHICS];
swapchainInit.width = width;
swapchainInit.height = height;
swapchainInit.format = RI_SWAPCHAIN_BT709_G22_8BIT;
InitRISwapchain(&rsh.device, &swapchainInit, &rsh.riSwapchain);

arrsetlen( rsh.backBuffers, rsh.riSwapchain.imageCount);
for( uint32_t i = 0; i < rsh.riSwapchain.imageCount; i++ ) {
rsh.backBuffers[i].riColorTexture = rsh.riSwapchain.images + i;
}


NriSwapChainDesc swapChainDesc = {
.commandQueue = rsh.nri.graphicsCommandQueue,
Expand All @@ -308,7 +335,10 @@ rserr_t RF_SetMode( int x, int y, int width, int height, int displayFrequency, b
rsh.backBuffers[i].colorTexture = swapChainTextures[i];
rsh.backBuffers[i].postProcessingSampler = R_ResolveSamplerDescriptor( IT_NOFILTERING );
{
NriTexture2DViewDesc textureViewDesc = { swapChainTextures[i], NriTexture2DViewType_COLOR_ATTACHMENT, swapChainDesc->format };
NriTexture2DViewDesc textureViewDesc = {
swapChainTextures[i],
NriTexture2DViewType_COLOR_ATTACHMENT,
swapChainDesc->format };
NRI_ABORT_ON_FAILURE( rsh.nri.coreI.CreateTexture2DView( &textureViewDesc, &rsh.backBuffers[i].colorAttachment ) );
}

Expand Down Expand Up @@ -336,7 +366,9 @@ rserr_t RF_SetMode( int x, int y, int width, int height, int displayFrequency, b
rsh.backBuffers[i].memoryLen += numAllocations;

NriTexture2DViewDesc attachmentViewDesc = {
.texture = rsh.backBuffers[i].pogoBuffers[pogoIdx].colorTexture, .viewType = NriTexture2DViewType_COLOR_ATTACHMENT, .format = textureDesc.format };
.texture = rsh.backBuffers[i].pogoBuffers[pogoIdx].colorTexture,
.viewType = NriTexture2DViewType_COLOR_ATTACHMENT,
.format = textureDesc.format };
NRI_ABORT_ON_FAILURE( rsh.nri.coreI.CreateTexture2DView( &attachmentViewDesc, &rsh.backBuffers[i].pogoBuffers[pogoIdx].colorAttachment ) );

NriTexture2DViewDesc shaderViewDesc = {
Expand Down
Loading

0 comments on commit b0c5ed9

Please sign in to comment.