ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location, TiledMode tiledMode, Transaction& transaction, Flags flags) : m_document(location.document()) , m_sprite(location.sprite()) , m_layer(location.layer()) , m_cel(NULL) , m_celImage(NULL) , m_celCreated(false) , m_flags(flags) , m_srcImage(NULL) , m_dstImage(NULL) , m_closed(false) , m_committed(false) , m_transaction(transaction) { create_buffers(); if (m_layer->isImage()) { m_cel = m_layer->cel(location.frame()); if (m_cel) m_celImage = m_cel->imageRef(); } // Create a new cel if (m_cel == NULL) { m_celCreated = true; m_cel = new Cel(location.frame(), ImageRef(NULL)); } m_origCelPos = m_cel->position(); // Region to draw gfx::Rect celBounds( m_cel->x(), m_cel->y(), m_celImage ? m_celImage->width(): m_sprite->width(), m_celImage ? m_celImage->height(): m_sprite->height()); gfx::Rect spriteBounds(0, 0, m_sprite->width(), m_sprite->height()); if (tiledMode == TiledMode::NONE) { // Non-tiled m_bounds = celBounds.createUnion(spriteBounds); } else { // Tiled m_bounds = spriteBounds; } // We have to adjust the cel position to match the m_dstImage // position (the new m_dstImage will be used in RenderEngine to // draw this cel). m_cel->setPosition(m_bounds.x, m_bounds.y); if (m_celCreated) { getDestCanvas(); m_cel->data()->setImage(m_dstImage); static_cast<LayerImage*>(m_layer)->addCel(m_cel); } }
recvbuf_t * get_full_recv_buffer(void) { recvbuf_t * rbuf; LOCK(); #ifdef HAVE_SIGNALED_IO /* * make sure there are free buffers when we * wander off to do lengthy packet processing with * any buffer we grab from the full list. * * fixes malloc() interrupted by SIGIO risk * (Bug 889) */ if (NULL == free_recv_list || buffer_shortfall > 0) { /* * try to get us some more buffers */ create_buffers(RECV_INC); } #endif /* * try to grab a full buffer */ UNLINK_FIFO(rbuf, full_recv_fifo, link); if (rbuf != NULL) full_recvbufs--; UNLOCK(); return rbuf; }
ExpandCelCanvas::ExpandCelCanvas(Context* context, TiledMode tiledMode, UndoTransaction& undo, Flags flags) : m_cel(NULL) , m_celImage(NULL) , m_celCreated(false) , m_flags(flags) , m_srcImage(NULL) , m_dstImage(NULL) , m_closed(false) , m_committed(false) , m_undo(undo) { create_buffers(); DocumentLocation location = context->activeLocation(); m_document = location.document(); m_sprite = location.sprite(); m_layer = location.layer(); if (m_layer->isImage()) { m_cel = static_cast<LayerImage*>(m_layer)->getCel(location.frame()); if (m_cel) m_celImage = m_cel->image(); } // If there is no Cel if (m_cel == NULL) { // Create the cel m_celCreated = true; m_cel = new Cel(location.frame(), 0); static_cast<LayerImage*>(m_layer)->addCel(m_cel); } m_origCelPos = m_cel->position(); // Region to draw gfx::Rect celBounds( m_cel->x(), m_cel->y(), m_celImage ? m_celImage->width(): m_sprite->width(), m_celImage ? m_celImage->height(): m_sprite->height()); gfx::Rect spriteBounds(0, 0, m_sprite->width(), m_sprite->height()); if (tiledMode == TILED_NONE) { // Non-tiled m_bounds = celBounds.createUnion(spriteBounds); } else { // Tiled m_bounds = spriteBounds; } // We have to adjust the cel position to match the m_dstImage // position (the new m_dstImage will be used in RenderEngine to // draw this cel). m_cel->setPosition(m_bounds.x, m_bounds.y); }
/*! * @brief Sets up the DirectSound for playback * @details Example code: * @code * HRESULT hr; * struct dsound_data * p_retval = (struct dsound_data*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct dsound_data)); * if (NULL != p_retval) * { * hr = init_ds_data(hWnd, p_WFE, p_retval); * if (SUCCEEDED(hr)) * { HeapFree(GetProcessHeap(), 0, p_tib); * return (DSOUNDPLAY)(p_retval); * } * } * debug_outputln("%s %4.4u", __FILE__, __LINE__); * HeapFree(GetProcessHeap(), 0, p_retval); * return NULL; * @endcode * @param[in] hwnd handle to the window that goes into the call of IDirectSound::SetCooperationLevel. Can be NULL, in which case either * a foreground window or the desktop window will be used. See <a href="http://msdn.microsoft.com/en-us/library/ms898135.aspx">this link</a> for more information. * @param[in] p_WFE pointer to the WAVEFORMATEX structure, describing the data to be played. * @param[out] p_ds_data refernce to the structure, whose members will be filled with DirectSound interface pointers. * @retrun returns the status of the operation, test it with SUCCEEDED() or FAILED() macros. */ static HRESULT init_ds_data(HWND hwnd, WAVEFORMATEX const * p_WFE, dxaudio_player_thread_information_block_t * p_ds_data) { HRESULT hr = E_FAIL; hr = DirectSoundCreate8(&DSDEVID_DefaultVoicePlayback, &p_ds_data->p_direct_sound_8_, NULL); if (FAILED(hr)) { debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr); goto error; } if (NULL == hwnd) { hwnd = GetForegroundWindow(); } if (NULL == hwnd) { hwnd = GetDesktopWindow(); } /* Quoting MSDN: */ /* "[..]After creating a device object, you must set the cooperative level */ /* for the device by using the IDirectSound8::SetCooperativeLevel method. */ /* Unless you do this, no sounds will be heard." */ hr = p_ds_data->p_direct_sound_8_->SetCooperativeLevel(hwnd, DSSCL_PRIORITY); if (FAILED(hr)) { debug_outputln("%4.4u %s : 0x%8.8x", __LINE__, __FILE__, hr); goto error; } CopyMemory(&p_ds_data->p_dsound_data->wfe_, p_WFE, sizeof(WAVEFORMATEX)); p_ds_data->p_dsound_data->wfe_.cbSize = sizeof(WAVEFORMATEX); p_ds_data->p_dsound_data->nSingleBufferSize_ = p_ds_data->p_dsound_data->play_settings_.play_buffer_size_; hr = create_buffers(p_ds_data->p_direct_sound_8_, &p_ds_data->p_dsound_data->wfe_, p_ds_data->p_dsound_data->number_of_chunks_, p_ds_data->p_dsound_data->nSingleBufferSize_, &p_ds_data->p_primary_sound_buffer_, &p_ds_data->p_secondary_sound_buffer_ ); if (FAILED(hr)) { debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr); goto error; } hr = set_play_notifications(p_ds_data->p_secondary_sound_buffer_, &p_ds_data->notification_array_[0], COUNTOF_ARRAY(p_ds_data->notification_array_)); if (FAILED(hr)) { debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr); goto error; } return hr; error: if (NULL != p_ds_data->p_direct_sound_8_) { p_ds_data->p_direct_sound_8_->Release(); p_ds_data->p_direct_sound_8_ = NULL; } return hr; }
explicit streaming_source_voice(Load &&loader) : end_flag_(false), loader_(std::forward<Load>(loader)), buffers_(create_buffers(kBufferSize_)), source_(create_source()) { for (int i = 0; i < kBufferSize_; ++i) { read(buffers_[i]); } alSourceQueueBuffers(*source_, kBufferSize_, &buffers_[0]); }
int sound_xaudio2::init(osd_options const &options) { HRESULT result; WAVEFORMATEX format = {0}; auto init_start = std::chrono::system_clock::now(); std::chrono::milliseconds init_time; CoInitializeEx(nullptr, COINIT_MULTITHREADED); // Make sure our XAudio2Create entrypoint is bound if (!XAudio2Create) { osd_printf_error("Could not find XAudio2. Please try to reinstall DirectX runtime package.\n"); return 1; } // Create the IXAudio2 object HR_GOERR(this->XAudio2Create(m_xAudio2.GetAddressOf(), 0, XAUDIO2_DEFAULT_PROCESSOR)); // make a format description for what we want format.wBitsPerSample = 16; format.wFormatTag = WAVE_FORMAT_PCM; format.nChannels = 2; format.nSamplesPerSec = sample_rate(); format.nBlockAlign = format.wBitsPerSample * format.nChannels / 8; format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; m_sample_bytes = format.nBlockAlign; // Create the buffers create_buffers(format); // Initialize our events m_hEventBufferCompleted = CreateEvent(nullptr, FALSE, FALSE, nullptr); m_hEventDataAvailable = CreateEvent(nullptr, FALSE, FALSE, nullptr); m_hEventExiting = CreateEvent(nullptr, FALSE, FALSE, nullptr); // create the voices and start them HR_GOERR(create_voices(format)); HR_GOERR(m_sourceVoice->Start()); // Start the thread listening m_audioThread = std::thread([](sound_xaudio2* self) { self->process_audio(); }, this); init_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - init_start); osd_printf_verbose("Sound: XAudio2 initialized. %d ms.\n", static_cast<int>(init_time.count())); m_initialized = TRUE; return 0; Error: this->exit(); return 1; }
void CMidiInputFilterer::reset() { if( !m_created_buffers ) { create_buffers(); } memset( m_got_poly_pressure, 0, number_of_midi_channels * number_of_notes * sizeof( bool ) ); memset( m_got_control_change, 0, number_of_midi_channels * number_of_notes * sizeof( bool ) ); memset( m_got_channel_pressure, 0, number_of_midi_channels * sizeof( bool ) ); memset( m_got_pitchbend, 0, number_of_midi_channels * sizeof( bool ) ); }
VertexArray::VertexArray( const std::vector<float>& vertex_data, const std::vector<unsigned int>& index_data, std::vector<unsigned int> attribute_sizes ): attribute_sizes(attribute_sizes), vertex_data(vertex_data), index_data(index_data) { init(); create_buffers(); }
static unsigned long try_to_load_aligned(unsigned long address, dev_t dev, int b[], int size) { struct buffer_head * bh, * tmp, * arr[8]; unsigned long offset; int * p; int block; bh = create_buffers(address, size); if (!bh) return 0; /* do any of the buffers already exist? punt if so.. */ p = b; for (offset = 0 ; offset < PAGE_SIZE ; offset += size) { block = *(p++); if (!block) goto not_aligned; if (find_buffer(dev, block, size)) goto not_aligned; } tmp = bh; p = b; block = 0; while (1) { arr[block++] = bh; bh->b_count = 1; bh->b_dirt = 0; bh->b_uptodate = 0; bh->b_dev = dev; bh->b_blocknr = *(p++); nr_buffers++; insert_into_queues(bh); if (bh->b_this_page) bh = bh->b_this_page; else break; } buffermem += PAGE_SIZE; bh->b_this_page = tmp; mem_map[MAP_NR(address)]++; read_buffers(arr,block); while (block-- > 0) brelse(arr[block]); ++current->maj_flt; return address; not_aligned: while ((tmp = bh) != NULL) { bh = bh->b_this_page; put_unused_buffer_head(tmp); } return 0; }
recvbuf_t * get_free_recv_buffer_alloc(void) { recvbuf_t *buffer; buffer = get_free_recv_buffer(); if (NULL == buffer) { create_buffers(RECV_INC); buffer = get_free_recv_buffer(); } NTP_ENSURE(buffer != NULL); return (buffer); }
void Hologram::create_frame_data(int count) { frame_data_.resize(count); create_fences(); create_command_buffers(); if (!use_push_constants_) { create_buffers(); create_buffer_memory(); create_descriptor_sets(); } frame_data_index_ = 0; }
void init_recvbuff(int nbufs) { /* * Init buffer free list and stat counters */ free_recvbufs = total_recvbufs = 0; full_recvbufs = lowater_adds = 0; create_buffers(nbufs); #ifdef DEBUG atexit(&uninit_recvbuff); #endif }
int sound_xaudio2::init(osd_options const &options) { HRESULT result; // Make sure our XAudio2Create entrypoint is bound int status = XAudio2Create.initialize(); if (status != 0) { osd_printf_error("Could not find XAudio2 library\n"); return 1; } // Create the IXAudio2 object IXAudio2 *temp_xaudio2 = nullptr; HR_RET1(this->XAudio2Create(&temp_xaudio2, 0, XAUDIO2_DEFAULT_PROCESSOR)); m_xAudio2 = xaudio2_ptr(temp_xaudio2); // make a format description for what we want WAVEFORMATEX format = { 0 }; format.wBitsPerSample = 16; format.wFormatTag = WAVE_FORMAT_PCM; format.nChannels = 2; format.nSamplesPerSec = sample_rate(); format.nBlockAlign = format.wBitsPerSample * format.nChannels / 8; format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; m_sample_bytes = format.nBlockAlign; // Create the buffers create_buffers(format); // Initialize our events m_hEventBufferCompleted = CreateEvent(nullptr, FALSE, FALSE, nullptr); m_hEventDataAvailable = CreateEvent(nullptr, FALSE, FALSE, nullptr); m_hEventExiting = CreateEvent(nullptr, FALSE, FALSE, nullptr); // create the voices and start them HR_RET1(create_voices(format)); HR_RET1(m_sourceVoice->Start()); // Start the thread listening m_audioThread = std::thread([](sound_xaudio2* self) { self->process_audio(); }, this); osd_printf_verbose("Sound: XAudio2 initialized\n"); return 0; }
gs_vertbuffer_t *device_vertexbuffer_create(gs_device_t *device, struct gs_vb_data *data, uint32_t flags) { struct gs_vertex_buffer *vb = bzalloc(sizeof(struct gs_vertex_buffer)); vb->device = device; vb->data = data; vb->num = data->num; vb->dynamic = flags & GS_DYNAMIC; if (!create_buffers(vb)) { blog(LOG_ERROR, "device_vertexbuffer_create (GL) failed"); gs_vertexbuffer_destroy(vb); return NULL; } return vb; }
void init_recvbuff(int nbufs) { /* * Init buffer free list and stat counters */ free_recvbufs = total_recvbufs = 0; full_recvbufs = lowater_adds = 0; create_buffers(nbufs); #if defined(SYS_WINNT) InitializeCriticalSection(&RecvLock); #endif #ifdef DEBUG atexit(&uninit_recvbuff); #endif }
/* * Try to increase the number of buffers available: the size argument * is used to determine what kind of buffers we want. */ static int grow_buffers(int pri, int size) { unsigned long page; struct buffer_head *bh, *tmp; if ((size & 511) || (size > PAGE_SIZE)) { printk("VFS: grow_buffers: size = %d\n",size); return 0; } if(!(page = __get_free_page(pri))) return 0; bh = create_buffers(page, size); if (!bh) { free_page(page); return 0; } tmp = bh; while (1) { if (free_list) { tmp->b_next_free = free_list; tmp->b_prev_free = free_list->b_prev_free; free_list->b_prev_free->b_next_free = tmp; free_list->b_prev_free = tmp; } else { tmp->b_prev_free = tmp; tmp->b_next_free = tmp; } free_list = tmp; ++nr_buffers; if (tmp->b_this_page) tmp = tmp->b_this_page; else break; } tmp->b_this_page = bh; buffermem += PAGE_SIZE; return 1; }
recvbuf_t * get_full_recv_buffer(void) { recvbuf_t *rbuf; LOCK(); #ifdef HAVE_SIGNALED_IO /* * make sure there are free buffers when we * wander off to do lengthy packet processing with * any buffer we grab from the full list. * * fixes malloc() interrupted by SIGIO risk * (Bug 889) */ if (NULL == free_recv_list || buffer_shortfall > 0) { /* * try to get us some more buffers */ create_buffers(RECV_INC); } #endif /* * try to grab a full buffer */ rbuf = ISC_LIST_HEAD(full_recv_list); if (rbuf != NULL) { ISC_LIST_DEQUEUE_TYPE(full_recv_list, rbuf, link, recvbuf_t); --full_recvbufs; } else /* * Make sure we reset the full count to 0 */ full_recvbufs = 0; UNLOCK(); return (rbuf); }
struct chip_swap * nandsim_swap_init(const char *swap_file, uint32_t nof_blks, uint32_t blk_size) { struct chip_swap *swap; int err = 0; if ((swap_file == NULL) || (nof_blks == 0) || (blk_size == 0)) return (NULL); swap = malloc(sizeof(*swap), M_NANDSIM, M_WAITOK | M_ZERO); SLIST_INIT(&swap->free_bs); STAILQ_INIT(&swap->used_bs); swap->blk_size = blk_size; swap->nof_blks = nof_blks; err = init_block_state(swap); if (err) { nandsim_swap_destroy(swap); return (NULL); } err = create_buffers(swap); if (err) { nandsim_swap_destroy(swap); return (NULL); } err = swap_file_open(swap, swap_file); if (err) { nandsim_swap_destroy(swap); return (NULL); } return (swap); }
ExpandCelCanvas::ExpandCelCanvas(Context* context, TiledMode tiledMode, UndoTransaction& undo) : m_cel(NULL) , m_celImage(NULL) , m_celCreated(false) , m_closed(false) , m_committed(false) , m_undo(undo) { create_buffers(); DocumentLocation location = context->getActiveLocation(); m_document = location.document(); m_sprite = location.sprite(); m_layer = location.layer(); if (m_layer->isImage()) { m_cel = static_cast<LayerImage*>(m_layer)->getCel(location.frame()); if (m_cel) m_celImage = m_sprite->getStock()->getImage(m_cel->getImage()); } // If there is no Cel if (m_cel == NULL) { // Create the image m_celImage = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight()); clear_image(m_celImage, m_sprite->getTransparentColor()); // Create the cel m_cel = new Cel(location.frame(), 0); static_cast<LayerImage*>(m_layer)->addCel(m_cel); m_celCreated = true; } m_originalCelX = m_cel->getX(); m_originalCelY = m_cel->getY(); // Region to draw int x1, y1, x2, y2; if (tiledMode == TILED_NONE) { // Non-tiled x1 = MIN(m_cel->getX(), 0); y1 = MIN(m_cel->getY(), 0); x2 = MAX(m_cel->getX()+m_celImage->getWidth(), m_sprite->getWidth()); y2 = MAX(m_cel->getY()+m_celImage->getHeight(), m_sprite->getHeight()); } else { // Tiled x1 = 0; y1 = 0; x2 = m_sprite->getWidth(); y2 = m_sprite->getHeight(); } // create two copies of the image region which we'll modify with the tool m_srcImage = crop_image(m_celImage, x1-m_cel->getX(), y1-m_cel->getY(), x2-x1, y2-y1, m_sprite->getTransparentColor(), src_buffer); m_dstImage = Image::createCopy(m_srcImage, dst_buffer); // We have to adjust the cel position to match the m_dstImage // position (the new m_dstImage will be used in RenderEngine to // draw this cel). m_cel->setPosition(x1, y1); }
HRESULT sound_direct_sound::dsound_init() { assert(!m_dsound); HRESULT result; // create the DirectSound object result = DirectSoundCreate(nullptr, &m_dsound, nullptr); if (result != DS_OK) { osd_printf_error("Error creating DirectSound: %08x\n", (unsigned)result); goto error; } // get the capabilities DSCAPS dsound_caps; dsound_caps.dwSize = sizeof(dsound_caps); result = m_dsound->GetCaps(&dsound_caps); if (result != DS_OK) { osd_printf_error("Error getting DirectSound capabilities: %08x\n", (unsigned)result); goto error; } // set the cooperative level { #ifdef SDLMAME_WIN32 SDL_SysWMinfo wminfo; SDL_VERSION(&wminfo.version); SDL_GetWindowWMInfo(osd_common_t::s_window_list.front()->platform_window<SDL_Window*>(), &wminfo); HWND const window = wminfo.info.win.window; #else // SDLMAME_WIN32 HWND const window = osd_common_t::s_window_list.front()->platform_window<HWND>(); #endif // SDLMAME_WIN32 result = m_dsound->SetCooperativeLevel(window, DSSCL_PRIORITY); } if (result != DS_OK) { osd_printf_error("Error setting DirectSound cooperative level: %08x\n", (unsigned)result); goto error; } { // make a format description for what we want WAVEFORMATEX stream_format; stream_format.wBitsPerSample = 16; stream_format.wFormatTag = WAVE_FORMAT_PCM; stream_format.nChannels = 2; stream_format.nSamplesPerSec = sample_rate(); stream_format.nBlockAlign = stream_format.wBitsPerSample * stream_format.nChannels / 8; stream_format.nAvgBytesPerSec = stream_format.nSamplesPerSec * stream_format.nBlockAlign; // compute the buffer size based on the output sample rate DWORD stream_buffer_size = stream_format.nSamplesPerSec * stream_format.nBlockAlign * m_audio_latency / 10; stream_buffer_size = std::max(DWORD(1024), (stream_buffer_size / 1024) * 1024); LOG(("stream_buffer_size = %u\n", (unsigned)stream_buffer_size)); // create the buffers m_bytes_per_sample = stream_format.nBlockAlign; m_stream_buffer_in = 0; result = create_buffers(stream_buffer_size, stream_format); if (result != DS_OK) goto error; } // start playing result = m_stream_buffer.play_looping(); if (result != DS_OK) { osd_printf_error("Error playing: %08x\n", (UINT32)result); goto error; } return DS_OK; // error handling error: destroy_buffers(); dsound_kill(); return result; }
int PluginArray::start_plugins(MWindow *mwindow, EDL *edl, PluginServer *plugin_server, KeyFrame *keyframe, int64_t start, int64_t end, File *file) { this->mwindow = mwindow; this->edl = edl; this->plugin_server = plugin_server; this->keyframe = keyframe; this->start = start; this->end = end; this->file = file; cache = new CICache(mwindow->preferences); buffer_size = get_bufsize(); get_recordable_tracks(); create_modules(); create_buffers(); if(!plugin_server->realtime) { PluginServer *plugin; int i; if(!plugin_server->multichannel) { // ============================ single channel plugins // start 1 plugin for each track for(i = 0; i < total_tracks(); i++) { append(plugin = new PluginServer(*plugin_server)); plugin->set_mwindow(mwindow); plugin->set_keyframe(keyframe); plugin->append_module(modules[i]); plugin->open_plugin(0, mwindow->preferences, mwindow->edl, 0); if(i == 0) plugin->set_interactive(); plugin->start_loop(start, end, buffer_size, 1); } } else { // ============================ multichannel // start 1 plugin for all tracks append(plugin = new PluginServer(*plugin_server)); plugin->set_mwindow(mwindow); plugin->set_keyframe(keyframe); for(i = 0; i < total_tracks(); i++) plugin->append_module(modules[i]); plugin->open_plugin(0, mwindow->preferences, mwindow->edl, 0); // set one plugin for progress bars plugin->set_interactive(); plugin->start_loop(start, end, buffer_size, total_tracks()); } //printf("PluginArray::start_plugins 5\n"); } else { PluginServer *plugin; int i; if(!plugin_server->multichannel) { // single channel plugins // start 1 plugin for each track for(i = 0; i < total_tracks(); i++) { append(plugin = new PluginServer(*plugin_server)); plugin->set_mwindow(mwindow); plugin->set_keyframe(keyframe); plugin->append_module(modules[i]); plugin->open_plugin(0, mwindow->preferences, mwindow->edl, 0); plugin->get_parameters(start, end, 1); plugin->init_realtime(0, 1, get_bufsize()); } } else { // multichannel // start 1 plugin for all tracks append(plugin = new PluginServer(*plugin_server)); plugin->set_mwindow(mwindow); plugin->set_keyframe(keyframe); for(i = 0; i < total_tracks(); i++) plugin->append_module(modules[i]); plugin->open_plugin(0, mwindow->preferences, mwindow->edl, 0); plugin->get_parameters(start, end, total_tracks()); plugin->init_realtime(0, total_tracks(), get_bufsize()); } } //printf("PluginArray::start_plugins 8\n"); return 0; }
cl_int compute_buffer_sizes(cl_context context, cl_command_queue* cmd_queue, cl_uint cqc, cl_kernel kern, size_t width, size_t height, size_t swapoffy, size_t **y) { size_t *yy, offset = 0; cl_mem wdth, hght, *offy, src, dst; unsigned long long *delays; double total = 0; yy = (size_t*)malloc(cqc * sizeof(*yy)); if (yy == NULL) { printf("Memory allocation failed!\n"); return -1; } //simple case with only 1 device if (cqc == 1) { yy[0] = 0; *y = yy; return 0; } delays = (unsigned long long*)malloc(cqc * sizeof(*delays)); if (delays == NULL) { printf("Memory allocation failed!\n"); return -1; } if (create_buffers(context, swapoffy * (width / 8), width, swapoffy, &src, &dst, &wdth, &hght, &offy, &offset, NULL, 1)) return -1; if (setup_kernel_stack(kern, wdth, hght, offy[0], src, dst)) return -1; unsigned int execs = 1; while (TRUE) { unsigned int i; for (i = 0; i < cqc; i++) { size_t global_work_size[2] = {width / 32, swapoffy}; //Dry run first to allow the buffers to get into memory if (clEnqueueNDRangeKernel(cmd_queue[i], kern, 2, NULL, global_work_size, NULL, 0, NULL, NULL)) return -1; clFinish(cmd_queue[i]); //Now the real deal delays[i] = get_time(); for (unsigned int j = 0; j < execs; j++) { if (clEnqueueNDRangeKernel(cmd_queue[i], kern, 2, NULL, global_work_size, NULL, 0, NULL, NULL)) return -1; } clFinish(cmd_queue[i]); delays[i] = get_time() - delays[i]; if (delays[i] == 0) break; printf("Device %d took %lu time units to complete the timing run\n", i, (long unsigned int)delays[i]); } if (delays[i] == 0) { printf("Device %d completed %d executions in 0 time units\n", i, execs); execs++; printf("Retrying timing runs with %d executions\n", execs); continue; } break; } for (unsigned int i = 0; i < cqc; i++) total += delays[i]; size_t current_offset = 0; for (unsigned int i = 0; i < cqc; i++) { yy[i] = current_offset; printf("Device %d will take Y offset: "SZTF"\n", i, yy[i]); current_offset += (1 - (delays[i] / total)) * height; } *y = yy; free(delays); clReleaseMemObject(src); clReleaseMemObject(dst); clReleaseMemObject(hght); clReleaseMemObject(wdth); clReleaseMemObject(offy[0]); free(offy); return 0; }
void init_video() { init_displays(); init_backgrounds(); create_buffers(); }
ExpandCelCanvas::ExpandCelCanvas( Site site, Layer* layer, TiledMode tiledMode, Transaction& transaction, Flags flags) : m_document(static_cast<app::Document*>(site.document())) , m_sprite(site.sprite()) , m_layer(layer) , m_frame(site.frame()) , m_cel(NULL) , m_celImage(NULL) , m_celCreated(false) , m_flags(flags) , m_srcImage(NULL) , m_dstImage(NULL) , m_closed(false) , m_committed(false) , m_transaction(transaction) , m_canCompareSrcVsDst((m_flags & NeedsSource) == NeedsSource) { ASSERT(!singleton); singleton = this; create_buffers(); if (m_layer && m_layer->isImage()) { m_cel = m_layer->cel(site.frame()); if (m_cel) m_celImage = m_cel->imageRef(); } // Create a new cel if (!m_cel) { m_celCreated = true; m_cel = new Cel(site.frame(), ImageRef(NULL)); } m_origCelPos = m_cel->position(); // Region to draw gfx::Rect celBounds( m_cel->x(), m_cel->y(), m_celImage ? m_celImage->width(): m_sprite->width(), m_celImage ? m_celImage->height(): m_sprite->height()); gfx::Rect spriteBounds(0, 0, m_sprite->width(), m_sprite->height()); if (tiledMode == TiledMode::NONE) { // Non-tiled m_bounds = celBounds.createUnion(spriteBounds); } else { // Tiled m_bounds = spriteBounds; } // We have to adjust the cel position to match the m_dstImage // position (the new m_dstImage will be used in RenderEngine to // draw this cel). m_cel->setPosition(m_bounds.x, m_bounds.y); if (m_celCreated) { getDestCanvas(); m_cel->data()->setImage(m_dstImage); if (m_layer && m_layer->isImage()) static_cast<LayerImage*>(m_layer)->addCel(m_cel); } }
int start_simulation(void) { cl_device_id *dev; cl_uint devc; cl_context context; cl_command_queue *cmd_queue; cl_mem src, dst, wdth, hght, *offy; cl_int err; cl_kernel kern; cl_program prog; cl_platform_id pform; size_t rows, columns, runs, print_each = 0, offsetx, offsety, *y, swapoffy; int gui_enabled, platform, device; unsigned int *buff0; unsigned int i; struct dispatcher_context *c; int random; char fname[1024]; cl_uint cqc; #if 1 do { printf("Width: "); scanf(SZTF, &columns); if (columns % 32) { printf("Width must be a multiple of 32\n"); continue; } if (columns == 0) { printf("Width must be > 0\n"); continue; } break; } while (true); do { printf("Height: "); scanf(SZTF, &rows); if (rows == 0) { printf("Width must be > 0\n"); continue; } break; } while (true); printf("Runs: "); scanf(SZTF, &runs); printf("Random? "); scanf("%d", &random); if (!random) { printf("File name: "); scanf("%s", fname); printf("Offset X: "); scanf(SZTF, &offsetx); printf("Offset Y: "); scanf(SZTF, &offsety); } printf("GUI? "); scanf("%d", &gui_enabled); if (!gui_enabled) { printf("Print after run: "); scanf(SZTF, &print_each); } printf("Platform index: "); scanf("%d", &platform); printf("Device index (-1 for all): "); scanf("%d", &device); do { printf("Swap offset: "); scanf(SZTF, &swapoffy); if (swapoffy == 0) swapoffy = rows; if (rows % swapoffy != 0) { printf("Swap offset must be a factor of the row count\n"); continue; } break; } while (true); #else columns = 512; rows = 512; runs = 1000; gui_enabled = 1; print_each = 0; random = 1; offsetx = 0; offsety = 0; platform = 0; device = 0; swapoffy = rows; #endif err = get_devices(&dev, &devc, &pform, platform, device); if (err) return err; err = initialize_context_cmd_queue(dev, devc, pform, &context, &cmd_queue, &cqc); if (err) return err; err = load_kernel(context, dev, devc, &prog, &kern); if (err) return err; buff0 = (unsigned int*)malloc(rows * (columns / 8)); if (!buff0) return -1; if (random) { srand((unsigned int)time(NULL)); for (i = 0; i < (rows * (columns / 8)) / 4; i++) { buff0[i] = rand() | (rand() << 16); } } else { memset(buff0, 0, rows * (columns / 8)); if (!load_file_to_buffer(buff0, fname, offsetx, offsety, columns, rows)) return -1; } err = compute_buffer_sizes(context, cmd_queue, cqc, kern, columns, rows, swapoffy, &y); if (err) return err; err = create_buffers(context, swapoffy * (columns / 8), columns, swapoffy, &src, &dst, &wdth, &hght, &offy, y, buff0, devc); if (err) return err; if (gui_enabled) { if (!initialize_window()) return -1; } c = (struct dispatcher_context *)malloc(sizeof(*c)); if (!c) return -1; c->cmd_queue = cmd_queue; c->cqc = cqc; c->kern = kern; c->columns = columns; c->rows = rows; c->print_each = print_each; c->runs = runs; c->gui_enabled = gui_enabled; c->buff0 = buff0; c->src = src; c->dst = dst; c->wdth = wdth; c->hght = hght; c->offy = offy; c->y = y; c->swapoffy = swapoffy; c->context = context; c->win_height = rows; return start_dispatcher(c); }
bool Particle_renderer::init(Resource_manager& resource_manager, Constant_buffer_cache& constant_buffer_cache) { Flags<Effect_provider::Options, uint32_t> flags; flags.set(Effect_provider::Options::Use_custom_constant_buffers, true); effect_ = resource_manager.load<Effect>("Effects/Particle_rendering/Particle_renderer.effect", flags.data()); if (!effect_) { return false; } techniques_.color_map = effect_->technique("Color_map"); techniques_.color_map_soft = effect_->technique("Color_map_soft"); techniques_.array_color_map = effect_->technique("Array_color_map"); techniques_.array_color_map_soft = effect_->technique("Array_color_map_soft"); lighting_techniques_.color_map_soft = effect_->technique("Lighting_color_map_soft"); Vertex_layout_description::Element elements[] = { Vertex_layout_description::Element("Position", 0, Data_format::R32G32B32A32_Float), Vertex_layout_description::Element("Properties", 0, Data_format::R32G32B32A32_Float) }; static const Vertex_layout_description description(2, elements); input_layout_ = rendering_tool_.vertex_layout_cache().input_layout(description, techniques_.color_map->program()->signature()); if (!input_layout_) { return false; } color_texture_offset_ = effect_->sampler_offset("g_color_map"); color_texture_array_offset_ = effect_->sampler_offset("g_color_map_array"); irradiance_volume_texture_offset_ = effect_->sampler_offset("g_irradiance_volume_map0"); auto& device = rendering_tool_.device(); Constant_buffer_adapter* change_per_camera_adapter = effect_->constant_buffer_adapter("Change_per_camera"); if (!constant_buffer_cache.connect(change_per_camera_adapter, "Change_per_camera")) { return false; } Constant_buffer_adapter* change_per_light_adapter = effect_->constant_buffer_adapter("Change_per_light"); if (!constant_buffer_cache.connect(change_per_light_adapter, "Change_per_light")) { return false; } if (!change_per_light_.init(change_per_light_adapter)) { return false; } effect_->create_default_constant_buffers(device); if (!create_buffers()) { return false; } return create_render_states(); }