Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize amdilc allocations #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 10 additions & 40 deletions src/amdilc/amdilc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

static HCRYPTPROV mCryptProvider = 0;

static void freeSource(
Source* src);

static void calcSha1(
uint8_t* digest,
const uint8_t* data,
Expand All @@ -33,45 +30,13 @@ static void calcSha1(
CryptDestroyHash(hash);
}

static void freeDestination(
Destination* dst)
{
if (dst->absoluteSrc != NULL) {
freeSource(dst->absoluteSrc);
}
free(dst->absoluteSrc);
}

static void freeSource(
Source* src)
{
for (unsigned i = 0; i < src->srcCount; i++) {
freeSource(&src->srcs[i]);
}
free(src->srcs);
}

static void freeInstruction(
Instruction* instr)
{
for (unsigned i = 0; i < instr->dstCount; i++) {
freeDestination(&instr->dsts[i]);
}
for (unsigned i = 0; i < instr->srcCount; i++) {
freeSource(&instr->srcs[i]);
}
free(instr->dsts);
free(instr->srcs);
free(instr->extras);
}

static void freeKernel(
Kernel* kernel)
{
for (unsigned i = 0; i < kernel->instrCount; i++) {
freeInstruction(&kernel->instrs[i]);
}
free(kernel->instrs);
free(kernel->srcBuffer);
free(kernel->dstBuffer);
free(kernel->extrasBuffer);
}

static bool isShaderDumpEnabled()
Expand Down Expand Up @@ -135,7 +100,10 @@ IlcShader ilcCompileShader(
getShaderName(name, NAME_LEN, code, size);
LOGV("compiling %s...\n", name);

Kernel* kernel = ilcDecodeStream((Token*)code, size / sizeof(Token));
Kernel* kernel = calloc(1, sizeof(Kernel));

ilcDecodeStream(kernel, (Token*)code, size / sizeof(Token));

bool dump = isShaderDumpEnabled();

if (dump) {
Expand All @@ -159,7 +127,9 @@ void ilcDisassembleShader(
const void* code,
unsigned size)
{
Kernel* kernel = ilcDecodeStream((Token*)code, size / sizeof(Token));
Kernel* kernel = calloc(1, sizeof(Kernel));

ilcDecodeStream(kernel, (Token*)code, size / sizeof(Token));

ilcDumpKernel(file, kernel);
freeKernel(kernel);
Expand Down
Loading
Loading