コード例 #1
0
ファイル: memory.cpp プロジェクト: CodeAsm/gameservice
bool cellGcmUtilAllocateMain(uint32_t size, uint32_t alignment, Memory_t *memory)
{
	// error
	assert(memory != 0);

	// warning
	if(memory == 0) return false;
	if(size == 0) return false;

	void *addr = 0;
	addr = my_mspace_memalign(mspMain, alignment, size);
	assert(addr != 0);
	if(addr == 0)
	{
		printf("cellGcmUtilAllocateMain() failed. Cannot allocate memory (size=0x%x)\n", size);
		return false;
	}

	memset(memory, 0, sizeof(Memory_t));
	memory->location = CELL_GCM_LOCATION_MAIN;
	memory->addr = addr;
	memory->size = size;

	int ret = cellGcmAddressToOffset(addr, &memory->offset);
	if(ret != CELL_OK)
	{
		printf("cellGcmUtilAllocateMain() failed. cellGcmAddressToOffset() failed: addr=0x%x\n", reinterpret_cast<uint32_t>(addr));
		cellGcmUtilFree(memory);
		return false;
	}

	return true;
}
コード例 #2
0
ファイル: Shader.cpp プロジェクト: gambiting/Racer-PS3
/*
Binary shader loading. This way should be preferred over text-based
shader loading, as the runtime compiler messes things up ALL THE TIME.

Although vertex shaders can be in system memory, we're going to put
all shader types straight into graphics memory for simplicity. 
*/
void	Shader::LoadBinaryShader(std::string name) {
	name = SYS_APP_HOME + name;

	unsigned int dataSize = 0;
	char* data = NULL;

	//Open the file
	std::ifstream	file(name.c_str(),std::ios::in|std::ios::binary);
	//Oh no!
	if(!file) {
		std::cout << "LoadBinaryShader: Can't find file: " << name << std::endl;
		return;
	}
	//This is the slightly messy default way to determine the size
	//of a file (seek to the end of it, grab the read position, seek
	//back to the start)
	file.seekg(0, std::ios::end);
	dataSize = file.tellg();
	file.seekg(0, std::ios::beg);

	//Allocate some graphics memory for the shader.
	//data = (char*)GCMRenderer::localMemoryAlign(64,dataSize);

	data = (char*)malloc(dataSize);
	//Load the shader straight into graphics memory. What type of data transfer
	//is this? How fast will it be?
	file.read(data,dataSize);
	file.close();	//Done with the data, close the file.

	//Now we have the binary data, we can cast it to a CGprogram
	//data structure. 
	program		= (CGprogram)(void*)data;

	//And initialise it. This will make sure the binary data is in the correct
	//format etc. 
	cellGcmCgInitProgram(program);

	//Lastly, we need to figure out where the ucode of the shader is located
	//and save the offset of it. It's really only fragment shaders that need
	//to know this, but just in case there's some obscure GCM function that
	//uses it, we'll save it even for vertex shaders.
	unsigned int ucodeSize;
	void *ucodePtr;

	cellGcmCgGetUCode(program, &ucodePtr, &ucodeSize);
	ucode = GCMRenderer::localMemoryAlign(64,ucodeSize);
	memcpy(ucode, ucodePtr, ucodeSize);
	cellGcmAddressToOffset(ucode, &offset);
}
コード例 #3
0
ファイル: Shader.cpp プロジェクト: gambiting/Racer-PS3
/*
The 'old' way of compiling shaders is to read in the shader text file,
and run it through the shader compiler. See the GCM tutorial text for
an overview of how this function works, but for now just know that it's
not very good, and the shaders it compiles will probably break.
*/
void	Shader::LoadTextShader(std::string name, ShaderType type) {
	CGCcontext* cgCompiler	= sceCgcNewContext();
	CGCinclude include		= {0,0};

	CGCbin* bin		= sceCgcNewBin();
	CGCbin* output	= sceCgcNewBin();

	std::cout << "Compiling shader: " << name << std::endl;

	if(sceCgcCompileString(cgCompiler, LoadShaderFile(name).c_str(),
		type == VERTEX_SHADER ? "sce_vp_rsx" : "sce_fp_rsx",
		NULL,NULL,bin,0,output,&include) != SCECGC_OK){
			std::cout << "Compiling failed!" << std::endl;
			return;
	}
	else{
		std::cout << "Compiling success!" << std::endl;
	}

	program		= (CGprogram)(void*)sceCgcGetBinData(bin);


	char* outputchars = (char*)sceCgcGetBinData(output);

	std::string outstring = std::string(outputchars);

	std::cout << "Compiling output:" << outstring << std::endl;

	cellGcmCgInitProgram(program);

	unsigned int ucodeSize;
	void *ucodePtr;

	cellGcmCgGetUCode(program, &ucodePtr, &ucodeSize);
	ucode = GCMRenderer::localMemoryAlign(64,ucodeSize);

	memcpy(ucode, ucodePtr, ucodeSize);

	cellGcmAddressToOffset(ucode, &offset);


	sceCgcDeleteContext(cgCompiler);
	sceCgcDeleteBin(bin);
	sceCgcDeleteBin(output);
}