Skip to content

Commit

Permalink
BaseApplication: highlight numImages dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jul 17, 2023
1 parent 1b3bd56 commit 7de5c4b
Showing 1 changed file with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,10 @@ private static void addDebugMessengerCreateInfo(

/**
* Allocate a command buffer for each image in the main swapchain.
*
* @param numBuffersNeeded the number of command buffers to create
*/
private static void allocateCommandBuffers() {
int numBuffersNeeded = chainImageHandles.size();
private static void allocateCommandBuffers(int numBuffersNeeded) {
if (commandBuffers == null) {
commandBuffers = new ArrayList<>(numBuffersNeeded);
} else {
Expand Down Expand Up @@ -979,11 +980,11 @@ private static void allocateCommandBuffers() {

/**
* Allocate a descriptor set for each frame in flight.
*
* @param numSets the number of descriptor sets to allocate
*/
private static void allocateDescriptorSets() {
private static void allocateDescriptorSets(int numSets) {
int numBytes = UniformValues.numBytes();

int numSets = chainImageHandles.size();
descriptorSetHandles = new ArrayList<>(numSets);

try (MemoryStack stack = MemoryStack.stackPush()) {
Expand Down Expand Up @@ -1128,8 +1129,10 @@ private static void cleanupGlfw() {

/**
* Create the swapchain for the main window.
*
* @return the number of images in the swapchain
*/
private static void createChain() {
private static int createChain() {
try (MemoryStack stack = MemoryStack.stackPush()) {
// swap-chain creation information:
VkSwapchainCreateInfoKHR createInfo
Expand Down Expand Up @@ -1218,27 +1221,30 @@ private static void createChain() {
long imageHandle = pHandles.get(imageIndex);
chainImageHandles.add(imageHandle);
}

return numImages;
}
}

/**
* Create the main swapchain and all resources that depend on it.
*/
private static void createChainResources() {
createChain();
createImageViews();
int numImages = createChain();

createImageViews(numImages);
createDepthResources();
createPass();
createFrameBuffers();
createDescriptorPool();
createUbos();
allocateDescriptorSets();
createFrameBuffers(numImages);
createDescriptorPool(numImages);
createUbos(numImages);
allocateDescriptorSets(numImages);
createPipeline();

allocateCommandBuffers();
recordCommandBuffers();
allocateCommandBuffers(numImages);
recordCommandBuffers(numImages);

createSyncObjects();
createSyncObjects(numImages);
}

/**
Expand Down Expand Up @@ -1301,10 +1307,10 @@ private static void createDepthResources() {

/**
* Create the (empty) descriptor-set pool for UBOs and samplers.
*
* @param numImages the number of images in the swap chain
*/
private static void createDescriptorPool() {
int numImages = chainImageHandles.size();

private static void createDescriptorPool(int numImages) {
try (MemoryStack stack = MemoryStack.stackPush()) {
VkDescriptorPoolSize.Buffer pContents
= VkDescriptorPoolSize.calloc(2, stack);
Expand Down Expand Up @@ -1384,9 +1390,10 @@ private static void createDescriptorSetLayout() {

/**
* Create a frame buffer for each image in the swapchain.
*
* @param numImages the number of images in the swap chain
*/
private static void createFrameBuffers() {
int numImages = chainImageHandles.size();
private static void createFrameBuffers(int numImages) {
chainFrameBufferHandles = new ArrayList<>(numImages);

try (MemoryStack stack = MemoryStack.stackPush()) {
Expand Down Expand Up @@ -1419,9 +1426,10 @@ private static void createFrameBuffers() {

/**
* Create a view for each image in the swapchain.
*
* @param numImages the number of images in the swap chain
*/
private static void createImageViews() {
int numImages = chainImageHandles.size();
private static void createImageViews(int numImages) {
chainViewHandles = new ArrayList<>(numImages);

for (long imageHandle : chainImageHandles) {
Expand Down Expand Up @@ -1836,11 +1844,11 @@ private static void createSurface() {

/**
* Create synchronization objects for each image in the swapchain.
*
* @param numImages the number of images in the swap chain
*/
private static void createSyncObjects() {
private static void createSyncObjects(int numImages) {
inFlightFrames = new Frame[maxFramesInFlight];

int numImages = chainImageHandles.size();
framesInFlight = new HashMap<>(numImages);

for (int i = 0; i < maxFramesInFlight; ++i) {
Expand Down Expand Up @@ -1879,9 +1887,10 @@ private static void createTextureSampler() {

/**
* Create a uniform buffer object (UBO) for each image in the swapchain.
*
* @param numUbos the number of UBOs to create
*/
private static void createUbos() {
int numUbos = chainImageHandles.size();
private static void createUbos(int numUbos) {
ubos = new ArrayList<>(numUbos);

int numBytes = UniformValues.numBytes();
Expand Down Expand Up @@ -2325,10 +2334,10 @@ private static void mainUpdateLoop() {

/**
* Record a command buffer for each image in the main swapchain.
*
* @param numImages the number of images in the swap chain
*/
private static void recordCommandBuffers() {
int numImages = chainImageHandles.size();

private static void recordCommandBuffers(int numImages) {
try (MemoryStack stack = MemoryStack.stackPush()) {
// Begin recording:
VkCommandBufferBeginInfo beginInfo
Expand Down

0 comments on commit 7de5c4b

Please sign in to comment.