Do I need to memory map/unmap a buffer every time the content of the buffer changes? - vulkan

I'm doing a Vulkan project that renders into an outgoing stream instead of presenting it (no swapchain et al): the rendered image is copied to another image (vkCmdCopyImage) then that later image is memory mapped (vkMapMemory), data is copied somewhere else then it is unmapped (vkUnmapMemory). This is happing at every frame. Is there a way to map the (second) image once, enter the main loop (render a frame at each cycle) then unmap it as part of the application clean-up ?
I tried this but it looks like whenever something is copied to the image, the earlier mapping doesn't work and it has to be unmapped and mapped again.

It is never necessary in Vulkan to unmap memory you have mapped. Even deleting the memory implicitly unmaps it.
However, it is necessary to synchronize access to that memory properly. For modifying an image on the GPU, using execution&memory dependencies to ensure the availability and visibility of the GPU modifications to the host, events that the CPU can wait on/test to ensure that the modification is visible, and if the memory is not host-coherent you will need to invoke vkInvalidateMappedMemoryRanges to ensure visibility of such changes to the host.

Related

What's mean "VkPipelineColorBlendAttachmentState contains the configuration per attached framebuffer"?

I read the Color blending Vulkan tutorial.
and this page says :
The first struct, VkPipelineColorBlendAttachmentState contains the configuration per attached framebuffer and the second struct, VkPipelineColorBlendStateCreateInfo contains the global color blending settings.In our case we only have one framebuffer
The second structure references the array of structures for all of the framebuffers
However, in Framebuffers chapter, framebuffers were created as many as the number of imageView.
But the code associated with it is the same.
And per-framebuffer struct no framebuffer-related members.
How attach color blend attachment to framebuffer?
My guess is that automatically attachment VkFramebufferCreateInfo::pAttachments when command recording(render pass begin), it's right?
or VkSubpassDescription::pColorAttachments ?
because specification say:
The value of attachmentCount must be greater than the index of all color attachments that are not VK_ATTACHMENT_UNUSED in VkSubpassDescription::pColorAttachments or VkSubpassDescription2::pColorAttachments for the subpass in which this pipeline is used.
Sometimes, tutorials do not use proper wording. This is one of those times.
Recall that a pipeline is built against a specific subpass of a specific render pass. Also recall that subpasses have a list of (among other things) color attachments that represent the render targets for rendering operations in that subpass.
What the tutorial means is that VkPipelineColorBlendAttachmentState defines the blend state for a particular attachment in the subpass designated by the pipeline. The array of VkPipelineColorBlendAttachmentState structs mirrors the array of color attachments used in the subpass the pipeline is being built for. So the third element of VkPipelineColorBlendStateCreateInfo::pAttachments corresponds to the third element in VkSubpassDescription::pColorAttachments for the subpass the pipeline is being built for.
For some reason, this tutorial refers to these attachments as "attached framebuffer," as this is absolutely the wrong term to use. They're just attachments.
Framebuffers provide the images that will be used as attachments when you begin a render pass. But the pipeline doesn't (really) care what image object you use. It cares about what color attachment in the subpass you're talking about.

Sencha Touch 2 Memory Management Options

I'm looking into ways to save memory in Sencha Touch 2. I see two options, as I'll describe below.
I'd like to get advice on the difference of memory consumption between the two options, and to know if I'm missing anything.
Memory-saving options
Remove and Destroy
Remove unused components from their containers, and destory them. When they're needed again, re-create them.
Advantage:
this approach can be greatly assisted by container ref's 'autoCreate' option and by container config's 'autoDestroy' option.
Disadvantage:
to re-create the view as it was before destruction, you need to make sure every important piece of information you wish to recreate (e.g. scroll-location in list, map-center in map) is kept as state elsewhere.
Remove
Remove unused components from their containers WITHOUT destroying them. When they're needed again, re-attach them to their containers.
Advantages
no need to keep GUI-related information somewhere as state.
the component could be updated even when not appearing in the DOM.
Disadvantages
the component is cleared from the DOM, but the Sencha object is still kept in memory
you'd need to keep detached components somewhere, and make sure to check for - and attach - existing ones before creating new ones
I also posted this on the Sencha forums: http://www.sencha.com/forum/showthread.php?200314-Memory-Management-Options
I got the following, rather general answer:
If you remove the component but do not destroy it, you minimize DOM size but of course you still have that component in device memory. The benefit is since DOM size is down, you have better performance and DOM size is going to have a larger impact than having some components in memory.

Storing of image in on-chip memory of MCB1700 evaluation board

I work with MCB1700 evaluation board.
It has (320 x 240) TF LCD Display.
IDE: Keil uvision4 4.03q.
My task is to download picture from PC to MCB1700, display it on LCD
and download on USB-stick (that connects to the board).
I need 320*240*2 = 153600 bytes of memory.
MCB1700 has only 64kB SRAM, and 512kB of on-chip Flash memory.
Obviously, I must store picture in Flash memory.
As I understand, I should bind pointer directly to memory address.
/* Base addresses */
#define LPC_FLASH_BASE (0x00000000UL) //beginning address of on-chip Flash
#define LPC_IMAGE_ADDR (LPC_FLASH_BASE + 0x10000)
#define ImagePtr ((unsigned short *) LPC_IMAGE_ADDR )
//read-write operations
ImagePtr[0] = 0x0124; //First pixel
…
ImagePtr[320*240] = 0xFA37; //Last pixel
unsigned short A = ImagePtr[0];
Is it correct?
I have a doubts because of Target’s options.
Flash memory’s area is defined like Read/Only IROM1.
Does it mean that we can only read data from Flash and must change Memory area in IROM and IRAM fields to perform writing operation? For example in such way:
You might do better to let the compiler/linker decide where to place the image in Flash:
static const unsigned short Image[320*240] = { <image data> } ;
will place Image as an array in ROM1 memory.
You cannot write directly to flash memory, it is normally read-only, and while write operations are word oriented, a word cannot be written unless it is previously erased and erasure is page or sector oriented - so it is somewhat more complex to manage that your example code.
In my suggestion above I have included an initialiser. Now it is obviously impractical to manually initialise 320*240 elements, but it is simple enough to write a PC based tool that will generate the necessary initialiser code directly from an image file.
Alternatively, if the image cannot be static, you might reserve part of your Flash for the image and then write code to write the flash memory and where necessary erase pages from data downloaded from a serial port or USB for example. In this case the Flash memory must be page aligned and comprise of an integer multiple of Flash pages.
For flexibility you should not rely on the target dialog settings and instead create a custom scatter file, where you can then create a custom section and allocate your image memory to it using armcc extension __attribute__ variable qualifiers.

How to release memory in iphone?

I have a UITablView with search box, when you type a text, content will show according starting character typed in serach box then when you select uitableview cell, it goes to another page, which has nearly 30 objects like, UILabel and UITextView. This is the way I constructed the page. When I select a company, I get a memory warning: "Did recieve memory warning level 1".
I verified every object, I had given release statement. Still I am getting the problem. How should I avoid the problem?
For starter, launch your application with Instruments using the memory leaks template. This probably can tells you what objects are stay in the memory.
in xcode 5 just go to product -> analyse ... then see the list of the memory leaks break point... just go throw the break point and try to release those are not required variable and class object ....
some bref
Or
This tool tells you what library is leaking, then you can debug your code as you deem suitable. If it is well organized, you will be able to see immediately what object is leaking and fix the problem with ease.

How to control a movieclip that was loaded using loadclip() in AS2?

This is in AS2. I'm loading an external AS2 swf using the loadclip function.
But I don't know how to call its gotoAndPlay or stop functions. How do I reference to them?
When I trace the loaded file it says
_level0.mcContainer.instance42
The object path always varies every load like now it's instance42 sometimes it becomes instance7 or instance10.
Ok. I was wrong. instance42 refers to the anonymous instances inside the loaded swf. upon loading the loaded clip replaces the container movieclip, hence I can refer to the loaded swf using mcContainer.