xpra icon
Bug tracker and wiki

Ticket #925: opencl-reinit-notest.patch

File opencl-reinit-notest.patch, 4.7 KB (added by Antoine Martin, 4 years ago)

reinit before running to ensure we get a clean context, and avoid running selftest (different thread)

  • xpra/codecs/csc_opencl/colorspace_converter.py

     
    548548        self.dst_width = dst_width
    549549        self.dst_height = dst_height
    550550        self.dst_format = dst_format
    551         self.init_with_device()
     551        if self.src_format.endswith("P"):
     552            #yuv 2 rgb:
     553            self.do_convert_image = self.convert_image_yuv
     554        else:
     555            #rgb 2 yuv:
     556            self.do_convert_image = self.convert_image_rgb
    552557
    553558    def init_with_device(self):
     559        rebuild_kernels()
    554560        global context, program
    555561        self.context = context
    556562        self.program = program
    557         self.queue = pyopencl.CommandQueue(self.context)
    558         fm = pyopencl.filter_mode.NEAREST
    559         self.sampler = pyopencl.Sampler(self.context, False, pyopencl.addressing_mode.CLAMP_TO_EDGE, fm)
    560563        k_def = KERNELS_DEFS.get((self.src_format, self.dst_format))
    561564        assert k_def, "no kernel found for %s to %s" % (self.src_format, self.dst_format)
    562565        self.kernel_function_name, _, self.channel_order, src = k_def
    563         if self.src_format.endswith("P"):
    564             #yuv 2 rgb:
    565             self.do_convert_image = self.convert_image_yuv
    566         else:
    567             #rgb 2 yuv:
    568             self.do_convert_image = self.convert_image_rgb
    569566        log("init_context(..) kernel source=%s", src)
    570567        self.kernel_function = getattr(self.program, self.kernel_function_name)
    571         log("init_context(..) channel order=%s, filter mode=%s", CHANNEL_ORDER_TO_STR.get(self.channel_order, self.channel_order), FILTER_MODE_TO_STR.get(fm, fm))
    572568        log("init_context(..) kernel_function %s: %s", self.kernel_function_name, self.kernel_function)
    573569        assert self.kernel_function
    574570
     
    652648
    653649
    654650    def convert_image(self, image, retry=0):
     651        self.reinit()
    655652        global context, program
    656653        if self.do_convert_image==None:
    657654            raise Exception("not initialized!")
     
    761758        assert image.get_pixel_format()==self.src_format, "invalid source format: %s (expected %s)" % (image.get_pixel_format(), self.src_format)
    762759        assert width>=self.src_width and height>=self.src_height, "expected source image with dimensions of at least %sx%s but got %sx%s" % (self.src_width, self.src_height, width, height)
    763760
     761        self.queue = pyopencl.CommandQueue(self.context)
     762        fm = pyopencl.filter_mode.NEAREST
     763        self.sampler = pyopencl.Sampler(self.context, False, pyopencl.addressing_mode.CLAMP_TO_EDGE, fm)
     764        log("init_context(..) channel order=%s, filter mode=%s", CHANNEL_ORDER_TO_STR.get(self.channel_order, self.channel_order), FILTER_MODE_TO_STR.get(fm, fm))
     765
    764766        #adjust work dimensions for subsampling:
    765767        #(we process N pixels at a time in each dimension)
    766768        divs = get_subsampling_divs(self.dst_format)
     
    773775        shape = (stride//4, self.src_height)
    774776        log("convert_image() type=%s, input image format=%s, shape=%s, work size: local=%s, global=%s", type(pixels), iformat, shape, localWorkSize, globalWorkSize)
    775777        idata = memoryview_to_bytes(pixels)
    776         if type(idata)==str:
     778        if True or type(idata)==str:
    777779            #str is not a buffer, so we have to copy the data
    778780            #alternatively, we could copy it first ourselves using this:
    779781            #pixels = numpy.fromstring(pixels, dtype=numpy.byte).data
     
    807809        kstart = time.time()
    808810        log("convert_image(%s) calling %s%s after %.1fms", image, self.kernel_function_name, tuple(kernelargs), 1000.0*(kstart-start))
    809811        self.kernel_function(*kernelargs)
    810         self.queue.finish()
     812        self.queue.flush()
    811813        #free input image:
    812814        iimage.release()
    813815        kend = time.time()
     
    817819        pixels = []
    818820        for i in range(3):
    819821            out_array = numpy.empty(out_sizes[i], dtype=numpy.byte)
    820             pixels.append(out_array.data)
    821             pyopencl.enqueue_read_buffer(self.queue, out_buffers[i], out_array, is_blocking=False)
     822            pyopencl.enqueue_read_buffer(self.queue, out_buffers[i], out_array, is_blocking=None).wait()
     823            pixels.append(out_array.tobytes())
    822824        readstart = time.time()
    823825        log("queue read events took %.1fms (3 planes of size %s, with strides=%s)", 1000.0*(readstart-kend), out_sizes, strides)
    824826        self.queue.finish()
     
    833835def selftest(full=False):
    834836    from xpra.codecs.codec_checks import testcsc
    835837    from xpra.codecs.csc_opencl import colorspace_converter
    836     testcsc(colorspace_converter, full)
     838    #testcsc(colorspace_converter, full)