void MakeDelaunay(const std::vector<float2>& vertexes, std::vector<uint3>& output)
	{
		output.clear();
		if (vertexes.size() < 3) {
			return;
		}
		int N = (int)vertexes.size();
		std::vector<std::pair<float2, int>> vertPairs(N);
		int index = 0;
		for (const float2& vert : vertexes) {
			vertPairs[index] = std::pair<float2, int>(vert, index);
			index++;
		}
		std::sort(vertPairs.begin(), vertPairs.end());
		std::vector<float2> tmp;
		tmp.reserve(vertPairs.size());
		for (std::pair<float2, int>& pr : vertPairs) {
			tmp.push_back(pr.first);
		}
		std::vector<int3>	cTriangles;
		Triangulate(tmp, cTriangles);
		for (int3& triangle : cTriangles) {
			if (triangle.x < N &&
				triangle.y < N &&
				triangle.z < N) {
				output.push_back(uint3((uint32_t)vertPairs[triangle.x].second, (uint32_t)vertPairs[triangle.y].second, vertPairs[triangle.z].second));
			}
		}
	}
Example #2
0
void ClFFT::init( Ptr<cl::Context> context, Ptr<cl::CommandQueue> queue, clFFT_Dimension& dim, clFFT_Dim3& dim3 )
{
	m_context = context;
	m_queue = queue;
	m_size = uint3(dim3.x, dim3.y, dim3.z);
	cl_int err = CL_SUCCESS;
	*m_fftPlan = clFFT_CreatePlan((*m_context)(), clFFT_Dim3(m_size.x, m_size.y, 1), clFFT_2D, clFFT_SplitComplexFormat, &err);
	if(!*m_fftPlan || err)
		throw cl::Error(ERR_OPENCL, "clFFT_CreatePlan");
}
Example #3
0
	GpuFftCS4::GpuFftCS4(uint32_t width, uint32_t height, bool forward)
			: width_(width), height_(height), forward_(forward)
	{
		RenderFactory& rf = Context::Instance().RenderFactoryInstance();

		src_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Read | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_GR32F);
		src_->Resize(3 * width * height * sizeof(float) * 2);

		dst_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Read | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_GR32F);
		dst_->Resize(3 * width * height * sizeof(float) * 2);

		tmp_buffer_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Read | EAH_GPU_Unordered | EAH_GPU_Structured, nullptr, EF_GR32F);
		tmp_buffer_->Resize(3 * width * height * sizeof(float) * 2);

		quad_layout_ = rf.MakeRenderLayout();
		quad_layout_->TopologyType(RenderLayout::TT_TriangleStrip);

		float2 xyzs[] =
		{
			float2(-1, +1),
			float2(+1, +1),
			float2(-1, -1),
			float2(+1, -1)
		};
		ElementInitData init_data;
		init_data.row_pitch = sizeof(xyzs);
		init_data.slice_pitch = 0;
		init_data.data = xyzs;
		GraphicsBufferPtr quad_vb = rf.MakeVertexBuffer(BU_Static, EAH_GPU_Read | EAH_Immutable, &init_data);
		quad_layout_->BindVertexStream(quad_vb, std::make_tuple(vertex_element(VEU_Position, 0, EF_GR32F)));

		tex_fb_ = rf.MakeFrameBuffer();

		effect_ = SyncLoadRenderEffect("FFT.fxml");
		buf2tex_tech_ = effect_->TechniqueByName("Buf2Tex");
		radix008a_tech_ = effect_->TechniqueByName("FFTRadix008A4");
		radix008a_first_tech_ = effect_->TechniqueByName("FFTRadix008AFirst4");
		radix008a_final_tech_ = effect_->TechniqueByName("FFTRadix008AFinal4");
		real_tex_ep_ = effect_->ParameterByName("real_tex");
		imag_tex_ep_ = effect_->ParameterByName("imag_tex");

		*(effect_->ParameterByName("input_buf")) = dst_;

		*(effect_->ParameterByName("tex_width_height")) = uint2(width, height);
		uint32_t n = width * height;
		*(effect_->ParameterByName("addr_offset")) = uint3(0 * n, 1 * n, 2 * n);

		*(effect_->ParameterByName("forward")) = static_cast<int32_t>(forward_);
		*(effect_->ParameterByName("scale")) = 1.0f / (width_ * height_);
	}
Example #4
0
void drive_operation()
{

    // Uint64 tests

    CQLValue a1(Uint64(10));
    CQLValue a2(Uint64(15));
    CQLValue a3(Uint64(25));
    CQLValue a4(Uint64(30));
    CQLValue a5(Uint64(150));

    PEGASUS_TEST_ASSERT(a1 != a2);
    PEGASUS_TEST_ASSERT(a5 == a5);
    PEGASUS_TEST_ASSERT(a1 < a2);
    PEGASUS_TEST_ASSERT(a2 >= a1);
    PEGASUS_TEST_ASSERT(a1 <= a2);
    PEGASUS_TEST_ASSERT(a2 > a1);

    // Sint64 tests

    CQLValue b1(Sint64(10));
    CQLValue b2(Sint64(15));
    CQLValue b3(Sint64(25));
    CQLValue b4(Sint64(30));
    CQLValue b5(Sint64(150));

    PEGASUS_TEST_ASSERT(b1 != b2);
    PEGASUS_TEST_ASSERT(b5 == b5);
    PEGASUS_TEST_ASSERT(b1 < b2);
    PEGASUS_TEST_ASSERT(b2 >= b1);
    PEGASUS_TEST_ASSERT(b1 <= b2);
    PEGASUS_TEST_ASSERT(b2 > b1);

    // Real64 tests

    CQLValue c1(Real64(10.00));
    CQLValue c2(Real64(15.00));
    CQLValue c3(Real64(25.00));
    CQLValue c4(Real64(30.00));
    CQLValue c5(Real64(150.00));

    PEGASUS_TEST_ASSERT(c1 != c2);
    PEGASUS_TEST_ASSERT(c5 == c5);
    PEGASUS_TEST_ASSERT(c1 < c2);
    PEGASUS_TEST_ASSERT(c2 >= c1);
    PEGASUS_TEST_ASSERT(c1 <= c2);
    PEGASUS_TEST_ASSERT(c2 > c1);

    // Misc
    PEGASUS_TEST_ASSERT(a1 == b1);
    PEGASUS_TEST_ASSERT(a1 == c1);
    PEGASUS_TEST_ASSERT(b1 == a1);
    PEGASUS_TEST_ASSERT(b1 == c1);
    PEGASUS_TEST_ASSERT(c1 == a1);
    PEGASUS_TEST_ASSERT(c1 == b1);

    PEGASUS_TEST_ASSERT(a2 != b1);
    PEGASUS_TEST_ASSERT(a2 != c1);
    PEGASUS_TEST_ASSERT(b2 != a1);
    PEGASUS_TEST_ASSERT(b2 != c1);
    PEGASUS_TEST_ASSERT(c2 != a1);
    PEGASUS_TEST_ASSERT(c2 != b1);

    PEGASUS_TEST_ASSERT(a2 >= b1);
    PEGASUS_TEST_ASSERT(a2 >= c1);
    PEGASUS_TEST_ASSERT(b2 >= a1);
    PEGASUS_TEST_ASSERT(b2 >= c1);
    PEGASUS_TEST_ASSERT(c2 >= a1);
    PEGASUS_TEST_ASSERT(c2 >= b1);

    PEGASUS_TEST_ASSERT(a2 <= b3);
    PEGASUS_TEST_ASSERT(a2 <= c3);
    PEGASUS_TEST_ASSERT(b2 <= a3);
    PEGASUS_TEST_ASSERT(b2 <= c3);
    PEGASUS_TEST_ASSERT(c2 <= a3);
    PEGASUS_TEST_ASSERT(c2 <= b3);

    PEGASUS_TEST_ASSERT(a2 > b1);
    PEGASUS_TEST_ASSERT(a2 > c1);
    PEGASUS_TEST_ASSERT(b2 > a1);
    PEGASUS_TEST_ASSERT(b2 > c1);
    PEGASUS_TEST_ASSERT(c2 > a1);
    PEGASUS_TEST_ASSERT(c2 > b1);

    PEGASUS_TEST_ASSERT(a2 < b3);
    PEGASUS_TEST_ASSERT(a2 < c3);
    PEGASUS_TEST_ASSERT(b2 < a3);
    PEGASUS_TEST_ASSERT(b2 < c3);
    PEGASUS_TEST_ASSERT(c2 < a3);
    PEGASUS_TEST_ASSERT(c2 < b3);

    //Overflow testing
    CQLValue real1(Real64(0.00000001));
    CQLValue sint1(Sint64(-1));
    CQLValue uint1(Sint64(1));
    CQLValue uint2(Uint64(0));

    PEGASUS_TEST_ASSERT(uint1 > sint1);
    PEGASUS_TEST_ASSERT(real1 > sint1);
    PEGASUS_TEST_ASSERT(uint2 > sint1);
    PEGASUS_TEST_ASSERT(real1 > uint2);

    CQLValue real2(Real64(25.00000000000001));
    CQLValue real3(Real64(24.99999999999999));
    CQLValue sint2(Sint64(25));
    CQLValue uint3(Uint64(25));

    PEGASUS_TEST_ASSERT(real2 > real3);
    PEGASUS_TEST_ASSERT(real2 > sint2);
    PEGASUS_TEST_ASSERT(real2 > uint3);
    PEGASUS_TEST_ASSERT(real3 < sint2);
    PEGASUS_TEST_ASSERT(real3 < uint3);

    // String tests

    CQLValue d1(String("HELLO"));
    CQLValue d2(String("HEL"));
    CQLValue d3(String("LO"));
    CQLValue d4(String("AHELLO"));
    CQLValue d5(String("ZHELLO"));

    PEGASUS_TEST_ASSERT(d1 == d2 + d3);
    PEGASUS_TEST_ASSERT(d1 != d2 + d4);

    PEGASUS_TEST_ASSERT(d1 <= d5);
    PEGASUS_TEST_ASSERT(d1 <  d5);

    PEGASUS_TEST_ASSERT(d1 >= d4);
    PEGASUS_TEST_ASSERT(d1 >  d4);

    String str1("0x10");
    String str2("10");
    String str3("10B");
    String str4("10.10");


    CQLValue e1( str1, CQLValue::Hex);
    CQLValue e2( str2, CQLValue::Decimal);
    CQLValue e3( str3, CQLValue::Binary);
    CQLValue e4( str4, CQLValue::Real);

    CQLValue e5(Uint64(16));
    CQLValue e6(Uint64(10));
    CQLValue e7(Uint64(2));
    CQLValue e8(Real64(10.10));

    PEGASUS_TEST_ASSERT(e1 == e5);
    PEGASUS_TEST_ASSERT(e2 == e6);
    PEGASUS_TEST_ASSERT(e3 == e7);
    PEGASUS_TEST_ASSERT(e4 == e8);

    Array<Uint64> array1;

    array1.append(1);
    array1.append(2);
    array1.append(3);
    array1.append(4);
    array1.append(5);
    array1.append(6);
    array1.append(7);
    array1.append(8);
    array1.append(9);
    array1.append(10);

    Array<Sint64> array2;

    array2.append(1);
    array2.append(2);
    array2.append(3);
    array2.append(4);
    array2.append(5);
    array2.append(6);
    array2.append(7);
    array2.append(8);
    array2.append(9);
    array2.append(10);
    array2.append(3);

    Array<Real64> array3;

    array3.append(1.00);
    array3.append(2.00);
    array3.append(3.00);
    array3.append(9.00);
    array3.append(10.00);
    array3.append(3.00);
    array3.append(4.00);
    array3.append(5.00);
    array3.append(6.00);
    array3.append(7.00);
    array3.append(8.00);

    Array<Uint64> array4;

    array4.append(1);
    array4.append(23);
    array4.append(3);
    array4.append(4);
    array4.append(5);
    array4.append(6);
    array4.append(7);
    array4.append(88);
    array4.append(9);
    array4.append(10);

    Array<Sint64> array5;

    array5.append(-1);
    array5.append(2);
    array5.append(3);
    array5.append(4);
    array5.append(5);
    array5.append(-6);
    array5.append(7);
    array5.append(8);
    array5.append(9);
    array5.append(10);
    array5.append(-3);

    Array<Real64> array6;

    array6.append(1.23);
    array6.append(2.00);
    array6.append(3.00);
    array6.append(9.00);
    array6.append(10.00);
    array6.append(3.00);
    array6.append(4.14);
    array6.append(5.00);
    array6.append(6.00);
    array6.append(7.00);
    array6.append(8.00);

    CIMValue cv1(array1);
    CIMValue cv2(array2);
    CIMValue cv3(array3);
    CIMValue cv4(array4);
    CIMValue cv5(array5);
    CIMValue cv6(array6);

    CQLValue vr1(cv1);
    CQLValue vr2(cv1);
    CQLValue vr3(cv2);
    CQLValue vr4(cv3);
    CQLValue vr5(cv4);
    CQLValue vr6(cv5);
    CQLValue vr7(cv6);

    PEGASUS_TEST_ASSERT(vr1 == vr2);
    PEGASUS_TEST_ASSERT(vr1 == vr3);
    PEGASUS_TEST_ASSERT(vr1 == vr4);
    PEGASUS_TEST_ASSERT(vr4 == vr3);

    PEGASUS_TEST_ASSERT(vr1 != vr5);
    PEGASUS_TEST_ASSERT(vr3 != vr6);
    PEGASUS_TEST_ASSERT(vr4 != vr7);

    const CIMName _cimName(String("CIM_OperatingSystem"));

    CIMInstance _i1(_cimName);
    CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules")));
    CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2)));
    CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
    CIMProperty _p4(CIMName("TimeOfLastStateChange"),
                    CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

    _i1.addProperty(_p1);
    _i1.addProperty(_p2);
    _i1.addProperty(_p3);
    _i1.addProperty(_p4);

    CIMInstance _i2(_cimName);
    CIMProperty _p5(CIMName("Description"),
                    CIMValue(String("Dave Rules Everything")));
    CIMProperty _p6(CIMName("EnabledState"),CIMValue(Uint16(2)));
    CIMProperty _p7(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
    CIMProperty _p8(CIMName("TimeOfLastStateChange"),
                    CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

    _i2.addProperty(_p5);
    _i2.addProperty(_p6);
    _i2.addProperty(_p7);
    _i2.addProperty(_p8);

    CQLValue cql1(_i1);
    CQLValue cql2(_i1);
    CQLValue cql3(_i2);
    CQLValue cql4(_i2);

    //PEGASUS_TEST_ASSERT(cql1 == cql1);

    return;
}
Example #5
0
texture_data make_texture_data(ID3D11Device* p_device, ID3D11DeviceContext* p_ctx, 
	texture_type type, ID3D11Texture2D* p_tex)
{
	assert(p_device);
	assert(p_ctx);
	assert(type != texture_type::unknown);
	assert(p_tex);

	// create a staging texture & fill it with p_tex data.
	D3D11_TEXTURE2D_DESC desc;
	p_tex->GetDesc(&desc);
	desc.Usage = D3D11_USAGE_STAGING;
	desc.BindFlags = 0;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
	desc.MiscFlags = desc.MiscFlags & (~D3D11_RESOURCE_MISC_GENERATE_MIPS);

	com_ptr<ID3D11Texture2D> p_tex_staging;
	HRESULT hr = p_device->CreateTexture2D(&desc, nullptr, &p_tex_staging.ptr);
	assert(hr == S_OK);
	p_ctx->CopyResource(p_tex_staging, p_tex);


#ifdef SPARKI_DEBUG
	if (type == texture_type::texture_cube) assert(desc.ArraySize == 6);
#endif // SPAKIR_DEBUG

	// create a texture_data object
	texture_data td(type, uint3(desc.Width, desc.Height, 1), 
		desc.MipLevels, desc.ArraySize, make_pixel_format(desc.Format));
	
	const size_t fmt_byte_count = byte_count(td.format);
	uint8_t* ptr = td.buffer.data();

	// for each array slice 
	// for each mipmap level of the slice
	// map p_tex_tmp[array_slice][mipmap_level] and copy its' contents into the texture_data object.
	for (UINT a = 0; a < desc.ArraySize; ++a) {
		for (UINT m = 0; m < desc.MipLevels; ++m) {
			const UINT index = D3D11CalcSubresource(m, a, desc.MipLevels);

			D3D11_MAPPED_SUBRESOURCE map;
			hr = p_ctx->Map(p_tex_staging, index, D3D11_MAP_READ, 0, &map);
			assert(hr == S_OK);

			const UINT w = desc.Width >> m;
			const UINT h = desc.Height >> m;
			const size_t mip_bc = w * h * fmt_byte_count;
			assert(mip_bc > 0);
			assert(mip_bc <= map.DepthPitch);

			if (mip_bc == map.DepthPitch) {
				std::memcpy(ptr, map.pData, mip_bc);
				ptr += mip_bc;
			}
			else {
				uint8_t* p_src = reinterpret_cast<uint8_t*>(map.pData);
				const size_t row_bc = w * fmt_byte_count;
				// Note(MSDN): The runtime might assign values to RowPitch and DepthPitch 
				// that are larger than anticipated because there might be padding between rows and depth.
				// https://msdn.microsoft.com/en-us/library/windows/desktop/ff476182(v=vs.85).aspx
				for (size_t row = 0; row < h; ++row) {
					std::memcpy(ptr, p_src, row_bc);
					p_src += map.RowPitch;
					ptr += row_bc;
				}
			}

			p_ctx->Unmap(p_tex_staging, index);
		}
	}

	return td;
}